:root {
  --bg: #EEF1F8;
  --surface: #FFFFFF;
  --surface-2: #F6F8FD;
  --ink: #141B3A;
  --muted: #59628A;
  --line: #D9DEEC;
  --brand: #2B3FD6;
  --brand-soft: #E3E7FF;
  --on-brand: #FFFFFF;
  --done: #12825A;
  --done-soft: #D7F2E6;
  --today: #C98204;
  --today-soft: #FDEFD3;
  --miss: #C3413A;
  --miss-soft: #FBE1DF;
  --future: #E2E6F2;
  --task: #7A3FD6;
  --task-soft: #EDE3FC;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Figtree", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius-lg: 22px;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D1122;
    --surface: #161C33;
    --surface-2: #1C2440;
    --ink: #E8EBF7;
    --muted: #9CA5C9;
    --line: #29325A;
    --brand: #8C9BFF;
    --brand-soft: #232C5C;
    --on-brand: #0D1122;
    --done: #45CC92;
    --done-soft: #143B2D;
    --today: #F3B33C;
    --today-soft: #3D2F12;
    --miss: #F2766D;
    --miss-soft: #43201F;
    --future: #232B4B;
    --task: #B98BFF;
    --task-soft: #2D2150;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--brand); outline-offset: 2px; border-radius: 8px; }

.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--bg);
  max-width: 640px; margin: 0 auto;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); background: var(--bg); z-index: 10; }
.brand { font-family: var(--display); font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 10px; letter-spacing: -0.01em; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background:
  radial-gradient(circle at 30% 30%, var(--today) 0 3px, transparent 3.5px), var(--brand); }
.chip-btn { border: 1.5px solid var(--brand); background: transparent; color: var(--brand); border-radius: 999px; padding: 6px 14px; font-size: 14px; font-weight: 600; }

main { max-width: 640px; margin: 0 auto; padding: 4px 20px 24px; outline: none; }

/* Today hero */
.eyebrow-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 10px; }
.pill { font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.pill.review { background: var(--today-soft); color: var(--today); }
.pill.done { background: var(--done-soft); color: var(--done); }
.daynum { font-family: var(--display); font-weight: 800; font-size: clamp(56px, 18vw, 88px); line-height: 0.92; letter-spacing: -0.04em; margin: 6px 0 2px; }
.daynum small { font-size: 0.32em; font-weight: 500; letter-spacing: -0.01em; color: var(--muted); margin-left: 6px; }
.date-line { color: var(--muted); font-size: 15px; margin: 0 0 18px; }
.topic-card { background: var(--surface); border-radius: var(--radius-lg); padding: 20px; border: 1px solid var(--line); }
.topic-title { font-family: var(--display); font-weight: 700; font-size: 26px; line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 10px; }
.topic-task { margin: 0 0 16px; color: var(--ink); }
.topic-task code { font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.checks { display: grid; gap: 8px; margin: 0 0 16px; }
.check { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius); border: 1px solid transparent; text-align: left; width: 100%; }
.check .box { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); flex: none; display: grid; place-items: center; transition: background .15s, border-color .15s; }
.check[aria-checked="true"] .box { background: var(--done); border-color: var(--done); }
.check[aria-checked="true"] .box::after { content: ""; width: 10px; height: 6px; border-left: 2.5px solid var(--surface); border-bottom: 2.5px solid var(--surface); transform: rotate(-45deg) translate(1px, -1px); }
.check[aria-checked="true"] span:last-child { color: var(--muted); text-decoration: line-through; }

.btn { border: 0; border-radius: var(--radius); padding: 14px 18px; font-weight: 600; font-size: 16px; width: 100%; }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-done { background: var(--done); color: var(--surface); }
.btn-ghost { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--miss-soft); color: var(--miss); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Timer */
.timer { display: flex; align-items: center; gap: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px 18px; margin-top: 14px; }
.ring { width: 76px; height: 76px; flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; }
.ring .track { stroke: var(--future); }
.ring .bar { stroke: var(--brand); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.timer-body { flex: 1; min-width: 0; }
.timer-body p { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; margin-bottom: 8px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.timer-actions { display: flex; gap: 8px; }
.timer-actions .btn { padding: 9px 14px; font-size: 14px; width: auto; }

/* Course map: the memorable bit */
.section-h { font-family: var(--display); font-weight: 700; font-size: 19px; letter-spacing: -0.01em; margin: 28px 0 4px; }
.section-sub { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.coursemap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; }
.cm-grid { display: grid; grid-template-columns: repeat(16, 1fr); grid-auto-flow: column; grid-template-rows: repeat(7, auto); gap: 4px; }
.cm-cell { aspect-ratio: 1; border-radius: 4px; background: var(--future); border: 0; padding: 0; min-width: 0; }
.cm-cell.done { background: var(--done); }
.cm-cell.miss { background: var(--miss); opacity: .85; }
.cm-cell.today { background: var(--today); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--today); }
.cm-cell.review:not(.done):not(.miss):not(.today) { background: var(--today-soft); }
.cm-phases { display: grid; grid-template-columns: 8fr 6fr 2fr; gap: 4px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.cm-phases span { border-top: 2px solid var(--line); padding-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-family: var(--display); font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--muted); }

.list { display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; width: 100%; text-align: left; }
.row .d { font-family: var(--display); font-weight: 700; min-width: 40px; color: var(--muted); font-size: 14px; }
.row .t { flex: 1; min-width: 0; }
.row .t b { display: block; font-weight: 600; font-size: 15px; }
.row .t span { font-size: 13px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--future); }
.dot.done { background: var(--done); } .dot.miss { background: var(--miss); } .dot.today { background: var(--today); }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 14px; }
.cal-head h2 { font-family: var(--display); font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 12px; }
.cal-dow, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0 8px; font-weight: 600; }
.cal-day { aspect-ratio: 1; border-radius: 12px; border: 0; background: transparent; color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-variant-numeric: tabular-nums; font-weight: 500; padding: 0; }
.cal-day.out { color: var(--muted); opacity: .5; }
.cal-day.in { background: var(--surface-2); }
.cal-day.done { background: var(--done-soft); color: var(--done); }
.cal-day.miss { background: var(--miss-soft); color: var(--miss); }
.cal-day.today { background: var(--today); color: var(--surface); font-weight: 700; }
.cal-day .mini { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .7; }
.cal-day.blank { visibility: hidden; }

/* Roadmap */
.phase-h { font-family: var(--display); font-weight: 800; font-size: 28px; letter-spacing: -0.03em; margin: 22px 0 10px; }
.phase-h span { color: var(--muted); font-weight: 500; font-size: 15px; letter-spacing: 0; margin-left: 8px; }
details.week { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
details.week summary { list-style: none; display: flex; align-items: center; gap: 12px; padding: 14px; cursor: pointer; }
details.week summary::-webkit-details-marker { display: none; }
.wk-num { font-family: var(--display); font-weight: 700; width: 34px; height: 34px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; flex: none; font-size: 15px; }
.wk-num.current { background: var(--today); color: var(--surface); }
.wk-t { flex: 1; min-width: 0; }
.wk-t b { display: block; font-weight: 600; }
.wk-t span { font-size: 13px; color: var(--muted); }
.wk-bar { height: 4px; border-radius: 4px; background: var(--future); margin-top: 6px; overflow: hidden; }
.wk-bar i { display: block; height: 100%; background: var(--done); }
details.week .wk-body { padding: 0 10px 10px; display: grid; gap: 6px; }
details.week .row { border: 0; background: var(--surface-2); }

/* Settings */
.field { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.field label, .field .lbl { display: block; font-weight: 600; margin-bottom: 4px; }
.field p { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.field input[type="date"], .field input[type="time"] { width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.status { font-size: 14px; font-weight: 600; margin: 8px 0 0; }
.status.ok { color: var(--done); } .status.warn { color: var(--today); } .status.bad { color: var(--miss); }
.stack { display: grid; gap: 8px; }

/* Empty / end states */
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius-lg); padding: 22px; }
.empty h3 { font-family: var(--display); margin: 0 0 6px; font-size: 22px; }
.empty p { margin: 0 0 14px; color: var(--muted); }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab { border: 0; background: transparent; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; font-weight: 600; color: var(--muted); }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--brand); }
@media (min-width: 700px) {
  .tabbar { left: 50%; right: auto; transform: translateX(-50%); width: 480px; bottom: 16px; border: 1px solid var(--line); border-radius: 20px; padding-bottom: 0; }
}

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(8, 12, 30, .45); animation: fade .2s ease; }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; background: var(--surface); border-radius: 24px 24px 0 0; padding: 10px 20px calc(20px + env(safe-area-inset-bottom, 0px)); max-height: 85dvh; overflow-y: auto; animation: rise .25s cubic-bezier(.2,.8,.2,1); }
.sheet-grip { width: 40px; height: 5px; border-radius: 5px; background: var(--line); margin: 0 auto 12px; }
@keyframes rise { from { transform: translateY(40px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 40; max-width: calc(100% - 40px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Personal tasks */
.task { display: flex; align-items: stretch; gap: 0; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--task); border-radius: var(--radius); overflow: hidden; }
.task .task-check { width: auto; background: transparent; padding: 12px 6px 12px 14px; border: 0; border-radius: 0; }
.task-main { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: 11px 14px 11px 8px; }
.task-main b { display: block; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.task-main span { font-size: 13px; color: var(--muted); }
.task-main span.late { color: var(--miss); font-weight: 600; }
.task.is-done { border-left-color: var(--done); }
.task.is-done .task-main b { text-decoration: line-through; color: var(--muted); }
.add-btn { margin-top: 10px; border: 1.5px dashed var(--line); background: transparent; color: var(--task); }
.section-h .count { font-family: var(--body); font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 2px 8px; margin-left: 8px; vertical-align: 3px; }
.form { display: grid; gap: 10px; }
.form label { font-weight: 600; font-size: 14px; display: block; margin-bottom: 4px; }
.form input { width: 100%; font: inherit; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.form input:focus { outline: 2px solid var(--brand); outline-offset: 0; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .hint { margin: 0; font-size: 13px; color: var(--muted); }
.form .err { margin: -4px 0 0; font-size: 13px; color: var(--miss); font-weight: 600; }
.cal-day .marks { display: flex; gap: 3px; height: 5px; }
.cal-day .mini.task { background: var(--task); opacity: 1; }
.cal-day.today .mini.task { background: var(--surface); }

/* Plan selector */
.plan-summary { display: grid; grid-template-columns: 1fr 1fr 1.6fr; gap: 10px; margin-bottom: 12px; }
.plan-summary div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.plan-summary b { display: block; font-family: var(--display); font-size: 22px; font-weight: 700; line-height: 1.15; }
.plan-summary span { font-size: 13px; color: var(--muted); }
details.plan { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 8px; }
details.plan > summary { list-style: none; cursor: pointer; padding: 14px 16px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
details.plan > summary::-webkit-details-marker { display: none; }
details.plan > summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-left: 10px; transition: transform .2s; }
details.plan[open] > summary::after { transform: rotate(-135deg); }
details.plan > summary span { margin-left: auto; font-size: 13px; color: var(--brand); background: var(--brand-soft); padding: 3px 10px; border-radius: 999px; }
.plan-body { padding: 0 12px 14px; }
.plan-group { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 14px 4px 6px; }
.plan-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius); background: var(--surface-2); margin-bottom: 6px; cursor: pointer; }
.plan-row .t { flex: 1; min-width: 0; }
.plan-row .t b { display: block; font-weight: 600; font-size: 15px; }
.plan-row .t span { font-size: 13px; color: var(--muted); }
.plan-row:not(.on) .t b { color: var(--muted); }
.switch { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .2s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s; }
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(18px); }
.hint { font-size: 13px; color: var(--muted); }
