:root {
  color-scheme: dark;
  --bg: #071019;
  --rail: #091725;
  --panel: #102333;
  --panel-soft: #0c1c29;
  --line: #24394a;
  --muted: #91a8ba;
  --text: #edf7ff;
  --accent: #58d6ae;
  --accent-ink: #06231a;
  --blue: #58a9f5;
  --warning: #ffab8b;
  --danger: #ff9aaa;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 78px minmax(0, 1fr); }
.side-rail { position: sticky; top: 0; height: 100vh; padding: 17px 10px 14px; background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; z-index: 10; }
.study-mark { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: #123047; color: var(--accent); text-decoration: none; box-shadow: inset 0 0 0 1px #244a61; }
.study-mark span { font-family: "Material Symbols Rounded"; font-size: 27px; font-weight: normal; font-style: normal; line-height: 1; letter-spacing: normal; text-transform: none; white-space: nowrap; font-feature-settings: "liga"; -webkit-font-feature-settings: "liga"; -webkit-font-smoothing: antialiased; font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24; }
.study-mark:hover { background: #173d58; color: #79e8c5; }
.side-rail nav { margin-top: 27px; display: flex; flex-direction: column; gap: 5px; }
.side-rail nav button { width: 58px; min-height: 56px; padding: 7px 4px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); display: grid; place-items: center; gap: 1px; }
.side-rail nav .nav-icon { font-family: "Material Symbols Rounded"; font-size: 24px; line-height: 1; font-weight: normal; font-style: normal; letter-spacing: normal; text-transform: none; white-space: nowrap; word-wrap: normal; direction: ltr; font-feature-settings: "liga"; -webkit-font-feature-settings: "liga"; -webkit-font-smoothing: antialiased; font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24; transition: color .16s ease, transform .16s ease, font-variation-settings .16s ease; }
.side-rail nav button b { font-size: 12px; font-weight: 600; }
.side-rail nav button:hover { color: var(--text); background: #10283b; }
.side-rail nav button:hover .nav-icon { transform: translateY(-1px); }
.side-rail nav button[aria-pressed="true"] { color: var(--text); background: #163a55; box-shadow: inset 3px 0 var(--blue); }
.side-rail nav button[aria-pressed="true"] .nav-icon { color: var(--blue); font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24; }
.auth-button { width: 56px; margin-top: auto; padding: 8px 4px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.auth-button:hover { color: var(--text); border-color: var(--blue); }
.mobile-header { display: none; }

main { width: min(1050px, 100%); margin: 0 auto; padding: 48px 42px 70px; }
.heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.heading h1 { margin: 4px 0 0; font-size: clamp(28px, 4vw, 39px); line-height: 1.2; letter-spacing: -.045em; }
.eyebrow { margin: 0; color: var(--blue); font-size: 13px; font-weight: 700; letter-spacing: .08em; }
.primary { min-height: 44px; padding: 9px 17px; border: 0; border-radius: 10px; background: var(--blue); color: #061724; font-weight: 750; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.primary:hover { filter: brightness(1.08); }
.secondary { min-height: 42px; padding: 8px 15px; border: 1px solid color-mix(in srgb, var(--blue) 44%, var(--line)); border-radius: 9px; background: color-mix(in srgb, var(--blue) 12%, var(--panel)); color: var(--blue); font-weight: 700; }
.ghost { min-height: 42px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--muted); }
.ghost:hover { border-color: var(--blue); color: var(--text); }
.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }

.signed-out { min-height: calc(100vh - 118px); display: flex; flex-direction: column; justify-content: center; align-items: flex-start; max-width: 680px; }
.signed-out h1 { margin: 13px 0 20px; font-size: clamp(36px, 6vw, 64px); line-height: 1.12; letter-spacing: -.055em; }
.signed-out > p:not(.eyebrow) { max-width: 560px; margin: 0 0 30px; color: var(--muted); font-size: 18px; }
.signed-out .primary { min-height: 50px; padding-inline: 21px; }
.status { min-height: 25px; margin: 22px 0 0; color: var(--muted); font-size: 14px; }

#summary { margin: 30px 0 34px; }
.progress-summary { background: var(--panel-soft); border: 1px solid var(--line); border-radius: 14px; padding: 17px 19px; }
.progress-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.progress-heading span { color: var(--muted); }
.progress-heading strong { font-size: 18px; }
.progress-track { height: 7px; margin-top: 11px; overflow: hidden; border-radius: 10px; background: #172d3d; }
.progress-track i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.summary-meta { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 12px; color: var(--muted); font-size: 14px; }
.summary-meta b { color: var(--text); }
.summary-meta .overdue b { color: var(--warning); }

#toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
#toolbar > strong { margin-inline: 4px; }
#toolbar label { margin: 0; display: inline-flex; align-items: center; gap: 9px; color: var(--muted); }

.agenda-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 13px; }
.agenda-heading h2 { margin: 0; font-size: 19px; }
.agenda-heading span { color: var(--muted); font-size: 14px; }
.timeline-section + .timeline-section { margin-top: 35px; padding-top: 30px; border-top: 1px solid var(--line); }
.timeline-row { display: grid; grid-template-columns: 74px 28px minmax(0, 1fr); min-height: 119px; }
.timeline-label { padding-top: 20px; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.timeline-rail { position: relative; display: flex; justify-content: center; }
.timeline-rail::after { content: ""; position: absolute; width: 1px; top: 35px; bottom: -1px; background: var(--line); }
.timeline-row:last-child .timeline-rail::after { display: none; }
.timeline-rail i { z-index: 1; width: 13px; height: 13px; margin-top: 29px; border: 3px solid var(--bg); border-radius: 50%; background: var(--muted); }
.timeline-row.urgent .timeline-rail i { background: var(--warning); box-shadow: 0 0 0 5px color-mix(in srgb, var(--warning) 14%, transparent); }
.timeline-row.review .timeline-rail i { background: var(--blue); }
.timeline-row.complete .timeline-rail i { background: var(--accent); }
.timeline-card { align-self: start; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 17px; padding: 16px 17px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.timeline-card:hover { border-color: #35536a; }
.timeline-card h3 { margin: 2px 0 1px; font-size: 18px; }
.timeline-card p { margin: 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.task-kind { color: var(--blue); font-size: 13px; font-weight: 750; }
.urgent .task-kind { color: var(--warning); }
.complete .timeline-card { opacity: .62; }
.complete .timeline-card h3 { text-decoration: line-through; }
.card-actions { display: flex; gap: 8px; }
.card-actions button { white-space: nowrap; }

.empty { padding: 38px 22px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); text-align: center; }
.empty strong { display: block; margin-bottom: 4px; color: var(--text); }
.group { margin-bottom: 30px; }
.group > h2 { margin: 0 0 12px; font-size: 19px; }
.group > h2 small { margin-left: 5px; color: var(--muted); font-size: 14px; }
.course-overview { margin-bottom: 18px; padding: 19px 20px; border-left: 3px solid var(--course); border-radius: 0 11px 11px 0; background: var(--panel-soft); }
.course-overview span { color: var(--muted); font-size: 13px; }
.course-overview h2 { margin: 2px 0; }
.course-overview p { margin: 0; color: var(--muted); }
.row { display: flex; gap: 16px; align-items: center; justify-content: space-between; margin: 8px 0; padding: 16px 18px; border: 1px solid var(--line); border-left: 3px solid var(--course, var(--accent)); border-radius: 11px; background: var(--panel); }
.row p { margin: 2px 0; }
.row small { color: var(--muted); }
.row .buttons { display: flex; gap: 8px; flex-shrink: 0; }
.badge { color: var(--accent); font-size: 14px; }
.late { color: var(--warning); }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 7px; }
.day { min-width: 0; padding: 11px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-soft); }
.day.current { border-color: var(--blue); box-shadow: inset 0 2px var(--blue); }
.day h3 { margin: 0 0 10px; font-size: 15px; }
.event { display: block; width: 100%; min-height: 42px; margin: 7px 0; padding: 9px; border: 0; border-left: 3px solid var(--course); border-radius: 7px; background: var(--panel); text-align: left; overflow-wrap: anywhere; }
.event:hover { background: #163044; }
.event small { display: block; color: var(--muted); }

button, input, select { color: inherit; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 9px 13px; }
dialog { width: min(570px, calc(100% - 24px)); max-height: 90vh; padding: 25px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); color: var(--text); }
dialog::backdrop { background: #02070bc7; backdrop-filter: blur(3px); }
dialog h2 { margin-top: 0; }
label { display: block; margin: 13px 0; }
label > input:not([type="checkbox"]):not([type="radio"]), label > select { display: block; width: 100%; margin-top: 5px; }
fieldset { border: 1px solid var(--line); border-radius: 9px; }
.pair, .actions { display: flex; gap: 15px; align-items: center; justify-content: space-between; }
.pair > * { flex: 1; min-width: 0; }
.days, .colors { display: flex; flex-wrap: wrap; gap: 13px 16px; }
.days label, .colors label { margin: 0; }
.check { display: flex; align-items: center; gap: 9px; }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; accent-color: var(--accent); }
.dot { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; }
.stage { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stage input[type="date"] { max-width: 180px; }
.right { display: flex; gap: 12px; }
#form-error, #lesson-error { color: var(--danger); }
.muted, small { color: var(--muted); }

@media (max-width: 900px) {
  .week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .app-shell { display: block; }
  .side-rail { position: fixed; top: auto; bottom: 0; width: 100%; height: 68px; padding: 7px 12px calc(7px + env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--line); flex-direction: row; justify-content: center; }
  .side-rail .study-mark, .side-rail .auth-button { display: none; }
  .signed-out-state .side-rail { display: none; }
  .signed-out-state main { padding-bottom: 35px; }
  .side-rail nav { width: 100%; max-width: 390px; margin: 0; flex-direction: row; justify-content: space-around; gap: 4px; }
  .side-rail nav button { width: 82px; min-height: 51px; }
  .side-rail nav button[aria-pressed="true"] { box-shadow: inset 0 -3px var(--blue); }
  .mobile-header { display: flex; align-items: center; gap: 9px; height: 58px; padding: 0 16px; border-bottom: 1px solid var(--line); }
  .mobile-header a { color: var(--text); text-decoration: none; font-weight: 750; }
  .mobile-header span { color: var(--muted); font-size: 13px; }
  .mobile-header button { min-height: 36px; margin-left: auto; padding: 6px 10px; background: transparent; color: var(--muted); }
  main { padding: 31px 15px 100px; }
  .signed-out { min-height: calc(100vh - 160px); }
  .signed-out h1 { font-size: 38px; }
  .heading { align-items: flex-start; }
  .heading h1 { font-size: 30px; }
  .heading #add { width: 44px; padding-inline: 0; font-size: 0; }
  .heading #add span { font-size: 19px; }
  #summary { margin: 24px 0 28px; }
  .summary-meta { gap: 6px 14px; }
  .timeline-row { grid-template-columns: 52px 20px minmax(0, 1fr); min-height: 128px; }
  .timeline-label { font-size: 12px; }
  .timeline-card { grid-template-columns: 1fr; gap: 12px; }
  .card-actions { justify-content: flex-end; }
  .week { grid-template-columns: 1fr; }
  .row { align-items: flex-start; flex-direction: column; }
  .row .buttons { width: 100%; justify-content: flex-end; }
  .pair { align-items: stretch; flex-direction: column; gap: 0; }
  .stage { flex-wrap: wrap; }
  dialog { padding: 20px; }
}
