:root {
  --bg: #f1f5fc;
  --ink: #0f1f4d;
  --muted: #6b7694;
  --card: #fff;
  --shadow: 0 4px 18px rgba(30, 50, 110, .08);
  --motor: #1d4fd8; --motor-bg: #e6eefc; --motor-chip: #cfdffb;
  --life: #2e8b3d; --life-bg: #eaf6e8; --life-chip: #d3ecd0;
  --cur: #b8650a; --cur-bg: #fff3e0; --cur-chip: #fbdca9;
  --navy: #0e2a6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(#f4f7fd, #eaf0fa);
  color: var(--ink);
  min-height: 100vh;
}
button, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.app { max-width: 480px; margin: 0 auto; padding: 16px 16px 40px; }

.controls { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.pill { background: var(--card); border-radius: 999px; box-shadow: var(--shadow); height: 46px; display: flex; align-items: center; }
.pill.group { flex: 1 1 100%; padding: 0 8px 0 6px; }
.pill.group select { flex: 1; }
.pill .icon { height: 34px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--muted); }
.pill .icon:hover { background: #eef2fb; color: var(--ink); }
.pill select { appearance: none; border: 0; background: none; font-weight: 600; font-size: 17px; padding: 0 22px 0 14px; outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%230f1f4d' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 4px center; }
.weeknav { flex: 1; justify-content: space-between; padding: 0 6px; font-weight: 600; font-size: 15px; }
.weeknav button { width: 38px; height: 38px; font-size: 24px; border-radius: 50%; }
.weeknav button:hover { background: #eef2fb; }

.days { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 14px; }
.day { background: var(--card); border-radius: 18px; padding: 10px 0; text-align: center; box-shadow: var(--shadow); font-weight: 600; font-size: 15px; line-height: 1.3; }
.day small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.day.active { background: var(--navy); color: #fff; }
.day.active small { color: #cdd7f3; }
.day.today:not(.active) { outline: 2px solid #9db8f2; }

.card { background: var(--card); border-radius: 26px; box-shadow: var(--shadow); padding: 16px; }
.day-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 4px 14px; }
.day-head h2 { margin: 0; font-size: 24px; }
.saved { display: flex; gap: 8px; align-items: center; font-size: 15px; transition: opacity .3s; }
.saved .check { width: 28px; height: 28px; border-radius: 50%; background: #2eaa4a; color: #fff; display: grid; place-items: center; font-size: 15px; }
.saved b { display: block; font-weight: 500; line-height: 1.1; }
.saved small { color: var(--muted); font-size: 12px; }
.saved.flash .check { animation: pop .4s; }
@keyframes pop { 50% { transform: scale(1.35); } }

.slots { display: flex; flex-direction: column; gap: 10px; }
.slot { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: stretch; }
.when { text-align: center; padding: 6px 0; border-right: 1px solid #e6eaf4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 14px; }
.when .ico { font-size: 34px; line-height: 1; }
.when b { font-size: 17px; font-weight: 600; margin-top: 4px; }
.when .time { color: var(--muted); font-size: 14px; }

.drop { border-radius: 20px; min-height: 84px; position: relative; transition: box-shadow .15s; }
.drop.over { box-shadow: 0 0 0 3px #8fb0f7; }
.empty { width: 100%; height: 100%; min-height: 84px; border-radius: 20px; border: 2px dashed #c9d3ec; color: var(--muted); font-weight: 600; font-size: 15px; background: #f8faff; }
.empty:hover { background: #eef3ff; }

.act { display: flex; align-items: center; gap: 14px; padding: 14px 20px 14px 16px; border-radius: 20px; border: 1px solid transparent; min-height: 84px; touch-action: none; background: var(--bg-c); border-color: var(--bd-c); }
.act .ico { font-size: 32px; }
.act .txt { flex: 1; min-width: 0; }
.act .name { font-size: 19px; font-weight: 600; margin-bottom: 6px; }
.chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top; display: inline-block; font-size: 13px; font-weight: 600; padding: 3px 12px; border-radius: 999px; background: var(--chip-c); color: var(--fg-c); }
.act .rm { width: 28px; height: 28px; border-radius: 50%; color: var(--muted); font-size: 15px; opacity: .7; }
.act .rm:hover { background: rgba(0,0,0,.07); opacity: 1; }
.handle { width: 28px; height: 40px; color: #9aa3bd; font-size: 20px; line-height: 1; cursor: grab; touch-action: none; letter-spacing: -2px; }
.act.dragging { position: fixed; z-index: 50; pointer-events: none; box-shadow: 0 14px 34px rgba(20,40,100,.28); opacity: .96; transform: rotate(1.5deg); }
.ghost { opacity: .35; }

[data-cat="motor"] { --shadow-c: rgba(40, 80, 170, .09); --hover-bd: #b9cdf3; --bg-c: var(--motor-bg); --bd-c: #cfdcf8; --chip-c: var(--motor-chip); --fg-c: var(--motor); --deep-c: #4d6fa8; }
[data-cat="life"] { --shadow-c: rgba(45, 120, 60, .09); --hover-bd: #b8dcb2; --bg-c: var(--life-bg); --bd-c: #d5ebd1; --chip-c: var(--life-chip); --fg-c: var(--life); --deep-c: #457a50; }
[data-cat="curriculum"] { --shadow-c: rgba(160, 105, 25, .09); --hover-bd: #efd29c; --bg-c: var(--cur-bg); --bd-c: #f6e0b8; --chip-c: var(--cur-chip); --fg-c: var(--cur); --deep-c: #c97430; }
[data-cat="arts"] { --shadow-c: rgba(120, 50, 180, .09); --hover-bd: #d7b8ee; --bg-c: #f6eafc; --bd-c: #e8d3f5; --chip-c: #e9d2f7; --fg-c: #7b2cbf; --deep-c: #7d5aa6; }

/* bottom sheet */
.scrim { position: fixed; inset: 0; background: rgba(15,31,77,.35); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 10; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto; background: #fff; border-radius: 28px 28px 0 0; padding: 10px 16px 28px; z-index: 20; transform: translateY(105%); transition: transform .3s cubic-bezier(.2,.8,.2,1); box-shadow: 0 -8px 30px rgba(20,40,100,.18); max-height: 85vh; display: flex; flex-direction: column; overflow: hidden; }
/* the title bar stays put; only the list scrolls */
.sheet .grab, .sheet .sheet-head { flex: none; }
.sheet-body { overflow-y: auto; min-height: 0; margin: 0 -8px; padding: 0 8px 4px; }
.newskill[hidden] { display: none; }

/* slim, quiet scrollbars */
* { scrollbar-width: thin; scrollbar-color: #c3cde6 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c3cde6; border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #a9b6d8; background-clip: content-box; }
.sheet.on { transform: none; }
.grab { width: 56px; height: 6px; border-radius: 3px; background: #d4d9e6; margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: 0 14px 14px 4px; }
.sheet-head h3 { margin: 0; font-size: 24px; }
.sheet-head small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.sheet-head button { font-size: 22px; width: 38px; height: 38px; border-radius: 50%; }
.sheet-head button:hover { background: #eef2fb; }

.cats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.cat { flex: 1 1 calc(50% - 8px); white-space: nowrap; padding: 12px 14px; border-radius: 999px; font-weight: 600; font-size: 15px; background: var(--bg-c); color: var(--fg-c); display: flex; gap: 6px; justify-content: center; align-items: center; }
.cat.active { background: var(--deep-c); color: #fff; font-weight: 700; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { display: flex; align-items: center; gap: 10px; text-align: left; padding: 12px; border-radius: 16px; background: #fff; border: 1px solid var(--bd-c, #e3e8f4); box-shadow: 0 2px 8px var(--shadow-c, rgba(30,50,110,.05)); transition: transform .1s, background .15s, border-color .15s; }
.opt:hover { background: var(--bg-c); border-color: var(--hover-bd, var(--bd-c)); }
.opt:active { transform: scale(.97); }
.opt .ico { font-size: 28px; }
.opt .name { font-size: 16px; font-weight: 600; margin-bottom: 4px; display: block; }
.opt .chip { font-size: 12px; padding: 2px 10px; }

.err { background: #fde8e8; color: #9b1c1c; border-radius: 12px; padding: 10px 14px; margin-top: 12px; font-size: 14px; }
.card.is-today { box-shadow: 0 0 0 2px #9db8f2, var(--shadow); }

.newskill { display: flex; gap: 8px; margin-top: 14px; }
.newskill input, #groupDlg input, #sectionDlg input, #entryDlg input, #entryDlg textarea { border: 1px solid #d5dcee; border-radius: 12px; padding: 10px 12px; font: inherit; min-width: 0; background: #fff; }
.newskill input:not(.ico-in), .slot-row input[data-f="label"] { flex: 1; }
.ico-in { width: 54px; text-align: center; }
.newskill button { padding: 0 16px; border-radius: 12px; background: var(--navy); color: #fff; font-weight: 600; }

#groupDlg, #sectionDlg, #confirmDlg, #entryDlg { border: 0; border-radius: 24px; padding: 22px; width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(15,31,77,.35); color: var(--ink); }
#groupDlg::backdrop, #sectionDlg::backdrop, #confirmDlg::backdrop, #entryDlg::backdrop { background: rgba(15,31,77,.4); }
#groupDlg h3, #sectionDlg h3, #confirmDlg h3, #entryDlg h3 { margin: 0 0 14px; font-size: 22px; }
#entryDlg textarea { resize: vertical; font: inherit; }
.search { width: 100%; margin-bottom: 12px; padding: 11px 14px; border: 1px solid #d5dcee; border-radius: 12px; font: inherit; background: #fff; }
.grid.single { grid-template-columns: 1fr; }
.grid .trail { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.trail .back { padding: 6px 12px; border-radius: 999px; background: var(--bg-c, #eef2fb); color: var(--ink); font-weight: 600; font-size: 13px; }
.trail .back:hover { background: var(--chip-c, #dfe7f9); }
.drill { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; padding: 14px; border-radius: 16px; border: 1px solid var(--bd-c, #e3e8f4); background: #fff; box-shadow: 0 2px 8px var(--shadow-c, rgba(30,50,110,.05)); transition: background .15s, border-color .15s; }
.drill:hover { background: var(--bg-c); border-color: var(--hover-bd, var(--bd-c)); }
.drill .name { font-size: 16px; font-weight: 600; }
.drill .count { color: var(--fg-c, var(--muted)); opacity: .75; font-size: 13px; white-space: nowrap; }
.drill:hover .count { opacity: 1; }
.crumb { display: block; font-size: 12px; color: var(--muted); line-height: 1.3; margin-bottom: 3px; }
.none-found { grid-column: 1 / -1; color: var(--muted); font-size: 14px; margin: 6px 2px; }
.group-title { flex: 1; padding: 0 16px; font-weight: 700; font-size: 17px; }
.group-title[hidden], .pill select[hidden], .pill .icon[hidden] { display: none; }
.addr { display: flex; align-items: center; border: 1px solid #d5dcee; border-radius: 12px; background: #fff; overflow: hidden; }
.addr-prefix { padding: 0 0 0 12px; color: var(--muted); font-weight: 500; white-space: nowrap; font-size: 14px; }
#groupDlg .addr input { border: 0; flex: 1; min-width: 0; padding-left: 2px; }
.linkbtn { color: #3a62b8; font-weight: 600; text-decoration: underline; font-size: inherit; }
.linkbtn[hidden] { display: none; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.act { cursor: pointer; }
/* who's going: a divider, a small label, then one pill per name */
.act .going { margin-top: 10px; padding-top: 9px; border-top: 1px solid rgba(15, 31, 77, .14); display: flex; flex-direction: column; gap: 8px; }
.going-row { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.going-label { flex-basis: 100%; font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.person { background: rgba(255, 255, 255, .9); border: 1px solid rgba(15, 31, 77, .1); border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 600; color: var(--ink); word-break: break-word; }
.person.staff { background: var(--deep-c); border-color: transparent; color: #fff; }
.person.everyone { background: transparent; border: 1px dashed rgba(15, 31, 77, .3); color: var(--muted); font-weight: 500; }
.going .add-names { font-size: 12px; color: var(--muted); opacity: .8; }
.split { display: block; width: 100%; margin-top: 8px; padding: 7px; border-radius: 14px; border: 1px dashed #c9d3ec; color: var(--muted); font-size: 13px; font-weight: 600; background: none; }
.split:hover { background: #f1f5ff; }
#confirmDlg { width: min(400px, calc(100vw - 32px)); }
.hint { margin: -6px 0 14px; color: var(--muted); font-size: 14px; line-height: 1.4; }
.dlg-actions .primary.danger { background: #b4443f; }
.fld { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.presets button { padding: 7px 12px; border-radius: 999px; background: #eef2fb; font-size: 13px; font-weight: 600; }
.presets button:hover { background: #dfe7f9; }
.slot-rows { display: flex; flex-direction: column; gap: 8px; }
.slot-row { display: flex; gap: 8px; }
.slot-row input[data-f="time_range"] { width: 120px; }
.slot-rows { max-height: 40vh; overflow-y: auto; }
.rm-row { width: 34px; flex: none; border-radius: 10px; color: var(--muted); }
.rm-row:hover { background: #fde8e8; color: #9b1c1c; }
.add-row { margin-top: 10px; padding: 9px 14px; border-radius: 12px; border: 1px dashed #c9d3ec; color: var(--muted); font-weight: 600; width: 100%; }
.add-row:hover { background: #f1f5ff; }
.add-section { display: block; width: 100%; margin-top: 12px; padding: 9px; border-radius: 14px; border: 1px dashed #c9d3ec; color: var(--muted); font-size: 13px; font-weight: 600; background: none; }
.add-section:hover { background: #f1f5ff; }
.when { position: relative; }
.rmslot { position: absolute; top: 0; right: 2px; width: 22px; height: 22px; border-radius: 50%; font-size: 11px; color: var(--muted); opacity: .6; }
.rmslot:hover { background: #fde8e8; color: #9b1c1c; opacity: 1; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.dlg-actions button { padding: 11px 20px; border-radius: 12px; font-weight: 600; background: #eef2fb; }
.dlg-actions .primary { background: var(--navy); color: #fff; }

/* desktop: whole week at once */
@media (min-width: 900px) {
  .app { max-width: 1500px; padding: 24px 32px 48px; }
  .controls { flex-wrap: nowrap; }
  .pill.group { flex: 0 0 340px; }
  .weeknav { flex: 0 0 360px; }
  .days { display: none; }
  .week.multi { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; align-items: start; }
  .week.multi .day-card { padding: 14px; border-radius: 22px; }
  .week.multi .day-head { margin: 0 2px 10px; flex-wrap: wrap; gap: 6px; }
  .week.multi .day-head h2 { font-size: 18px; }
  .week.multi .saved { font-size: 13px; }
  .week.multi .saved .check { width: 22px; height: 22px; font-size: 12px; }
  .week.multi .slot { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .week.multi .act { position: relative; gap: 8px; padding: 10px 36px 10px 10px; }
  .week.multi .act .ico { font-size: 22px; }
  .week.multi .act.dragging { position: fixed; }
  .week.multi .act .rm { position: absolute; top: 9px; right: 9px; width: 22px; height: 22px; }
  .week.multi .handle { position: absolute; bottom: 9px; right: 11px; width: 18px; height: 24px; }
  .week.multi .when { flex-direction: row; justify-content: flex-start; gap: 8px; border: 0; padding: 4px 4px 0; }
  .week.multi .when .ico { font-size: 18px; }
  .week.multi .when b { font-size: 14px; margin: 0; }
  .week.multi .when .time { font-size: 12px; }
  .week.multi .act { padding: 10px 6px 10px 12px; gap: 10px; min-height: 76px; }
  .week.multi .act .ico { font-size: 26px; }
  .week.multi .act .name { font-size: 15px; margin-bottom: 4px; }
  .week.multi .drop, .week.multi .empty { min-height: 76px; }
  .week.multi .slots { gap: 12px; }
  .grid { grid-template-columns: repeat(4, 1fr); }
  .grid.single { grid-template-columns: repeat(3, 1fr); }
  .grid .trail { grid-column: 1 / -1; }
  .cat { flex: 1 1 0; }
  .sheet { max-width: none; margin: 0; padding: 14px 48px 32px; max-height: 88vh; }
  .newskill { max-width: 520px; }
}

@media (max-width: 380px) {
  .slot { grid-template-columns: 78px 1fr; }
  .act .name { font-size: 17px; }
  .grid { grid-template-columns: 1fr; }
}
