/* Study Hub — design tokens
   Layout: phone = large-title screens over a bottom tab bar; desktop (≥900px) = left sidebar + centred 760px column.
   Palette: warm stone neutrals, one muted slate accent for progress, brass for rewards. Subject colours are low-saturation tints. */
:root {
  --bg: #f4f3f1;
  --surface: #ffffff;
  --surface-2: #f8f7f5;
  --sunken: #eceae6;
  --line: #e4e1dc;
  --line-strong: #d3cfc8;
  --ink: #1d1b19;
  --ink-2: #45413c;
  --muted: #69635b;
  --faint: #a59e95;
  --gold-ink: #85651f;
  --accent: #46606b;
  --accent-soft: #e6ecee;
  --gold: #a6812f;
  --gold-soft: #f3ecdc;
  --good: #3b7a55;
  --good-soft: #e5f0e8;
  --bad: #ad4a40;
  --bad-soft: #f6e6e3;
  --on-ink: #ffffff;
  --scrim: rgb(29 27 25 / 0.32);
  --subj-s: 26%;
  --subj-l: 36%;
  --subj-tint-l: 93%;
  --shadow-1: 0 1px 2px rgb(29 27 25 / 0.05);
  --shadow-2: 0 10px 30px rgb(29 27 25 / 0.10), 0 2px 6px rgb(29 27 25 / 0.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --tabbar-h: 58px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --surface: #1c1a18;
    --surface-2: #232120;
    --sunken: #0d0c0b;
    --line: #2f2c29;
    --line-strong: #3d3935;
    --ink: #f3f1ee;
    --ink-2: #d4cfc8;
    --muted: #9c958c;
    --faint: #6f6962;
    --gold-ink: #d2b06a;
    --accent: #93b2bd;
    --accent-soft: #22292c;
    --gold: #d2b06a;
    --gold-soft: #2d2719;
    --good: #7cbb94;
    --good-soft: #1b2a21;
    --bad: #e3958b;
    --bad-soft: #33201d;
    --on-ink: #121110;
    --scrim: rgb(0 0 0 / 0.55);
    --subj-s: 24%;
    --subj-l: 70%;
    --subj-tint-l: 19%;
    --shadow-1: none;
    --shadow-2: 0 12px 34px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  overflow-wrap: break-word;
}
[tabindex="-1"]:focus { outline: none; }
img { max-width: 100%; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 18px; height: 18px; }
svg.i.xs { width: 14px; height: 14px; stroke-width: 2; }

/* ---------- Shell ---------- */
.shell { min-height: 100dvh; }
.main {
  padding: calc(env(safe-area-inset-top, 0px) + 12px) max(16px, env(safe-area-inset-right, 0px)) calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 28px) max(16px, env(safe-area-inset-left, 0px));
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.view { animation: viewIn 220ms var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 4px) max(8px, env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(18px);
  backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 48px; padding: 4px 0 2px; border: 0; background: none;
  color: var(--faint); font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em; text-decoration: none;
}
.tab[aria-current="page"] { color: var(--ink); }
.tab svg.i { width: 24px; height: 24px; }

.sidebar { display: none; }
@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 248px 1fr; }
  .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100dvh;
    padding: 28px 14px 20px max(14px, env(safe-area-inset-left, 0px));
    border-right: 1px solid var(--line); background: var(--surface-2);
  }
  .brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 22px; font: 700 17px/1.2 var(--font-display); letter-spacing: -0.01em; }
  .brand-mark { width: 30px; height: 30px; border-radius: 8px; display: block; }
  .side-link {
    display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px;
    color: var(--ink-2); text-decoration: none; font-weight: 550; font-size: 15px;
  }
  .side-link:hover { background: var(--sunken); }
  .side-link[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); outline: 1px solid var(--line); }
  .side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 13px; }
  .main { padding: 36px 48px 64px; max-width: 900px; }
}

/* ---------- Typography & headers ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 8px 2px 18px; }
.head h1 { margin: 0; font: 700 32px/1.12 var(--font-display); letter-spacing: -0.025em; text-wrap: balance; }
.head .sub { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.back {
  display: inline-flex; align-items: center; gap: 2px; margin: -4px 0 0 -8px; padding: 10px 8px;
  border: 0; background: none; color: var(--accent); font-size: 16px; font-weight: 500; text-decoration: none;
}
.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 28px 4px 8px; font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
}
.section-title a, .section-title button { text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 500; color: var(--accent); background: none; border: 0; padding: 12px 8px; margin: -12px -8px; text-decoration: none; }
h2.h { margin: 0; font: 650 19px/1.25 var(--font-display); letter-spacing: -0.015em; }
p { margin: 0; }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow-1); }
.card + .card { margin-top: 12px; }
.stack { display: grid; gap: 12px; }
.row-gap { display: flex; flex-wrap: wrap; gap: 8px; }
.grid-2 + .field { margin-top: 14px; }
.head > .tile { align-self: flex-start; margin-top: 6px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 420px) { .grid-2.collapse { grid-template-columns: 1fr; } }

/* Inset grouped list */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-1); }
.item {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 11px 16px;
  border: 0; background: none; text-align: left; text-decoration: none; color: inherit; position: relative;
}
.item + .item::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
.item.has-tile + .item.has-tile::before { left: 64px; }
button.item:active, a.item:active { background: var(--sunken); }
@media (hover: hover) { button.item:hover, a.item:hover { background: var(--surface-2); } }
.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 560; line-height: 1.3; }
.item-sub { color: var(--muted); font-size: 13.5px; line-height: 1.35; margin-top: 2px; }
.item .chev { color: var(--faint); }
.item-end { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; flex: none; }

.tile {
  width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center;
  font: 650 15px/1 var(--font-display);
  background: hsl(var(--h, 30) var(--subj-s) var(--subj-tint-l)); color: hsl(var(--h, 30) var(--subj-s) var(--subj-l));
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: hsl(var(--h, 30) calc(var(--subj-s) + 10%) var(--subj-l)); flex: none; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 13px; border: 1px solid transparent;
  font-weight: 600; font-size: 15.5px; text-decoration: none; white-space: nowrap;
  transition: transform 120ms var(--ease), background 120ms, opacity 120ms;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn.primary { background: var(--ink); color: var(--on-ink); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn.soft { background: var(--sunken); color: var(--ink); }
.btn.ghost { background: none; color: var(--accent); padding: 0 10px; }
.btn.danger { background: none; color: var(--bad); border-color: var(--line-strong); }
.btn.block { width: 100%; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--sunken); color: var(--ink-2); flex: none;
}

.field { display: grid; gap: 6px; }
.field + .field { margin-top: 14px; }
.label { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.hint { font-size: 13px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 16px; /* 16px stops iOS zoom */
  -webkit-appearance: none; appearance: none;
}
.select {
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 21px, calc(100% - 14px) 21px; background-size: 5px 5px; background-repeat: no-repeat;
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search .input { padding-left: 40px; background: var(--surface); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; border-radius: 11px; background: var(--sunken); margin-bottom: 16px; }
.seg button { min-height: 38px; border: 0; border-radius: 8px; background: none; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line-strong); transition: background 160ms; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgb(0 0 0 / 0.2); transition: transform 180ms var(--ease); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 13px; border-radius: 99px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 14px; font-weight: 550; color: var(--ink-2);
}
.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px; background: var(--sunken); color: var(--muted); font-size: 11.5px; font-weight: 650; letter-spacing: 0.02em; }
.tag.gold { background: var(--gold-soft); color: var(--gold); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }

.stars { display: inline-flex; gap: 2px; color: var(--line-strong); }
.stars .on { color: var(--gold); }
.stars svg { width: 14px; height: 14px; fill: currentColor; stroke: none; }

/* ---------- Today ---------- */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.ring { position: relative; width: 84px; height: 84px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--sunken); }
.ring .fill { stroke: var(--accent); transition: stroke-dashoffset 600ms var(--ease); }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1; }
.ring-label b { display: block; font: 700 26px/1 var(--font-display); letter-spacing: -0.02em; }
.ring-label small { display: block; font-size: 10.5px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-top: 3px; }
.stat-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 2px; }
.stat b { display: block; font: 650 20px/1.15 var(--font-display); letter-spacing: -0.01em; }
.stat span { font-size: 12.5px; color: var(--muted); }
.xpbar { height: 6px; border-radius: 99px; background: var(--sunken); overflow: hidden; margin-top: 12px; }
.xpbar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 600ms var(--ease); }

.feature { display: flex; align-items: center; gap: 16px; }
.feature .badge-ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold); flex: none; }
.feature .badge-ic.done { background: var(--good-soft); color: var(--good); }

/* ---------- Topic ---------- */
.notes { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.notes li { position: relative; padding-left: 18px; line-height: 1.55; color: var(--ink-2); }
.notes li::before { content: ""; position: absolute; left: 2px; top: 0.7em; width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); }
.kw { display: grid; gap: 2px; padding: 12px 0; }
.kw + .kw { border-top: 1px solid var(--line); }
.kw dt { font-weight: 650; }
.kw dd { margin: 0; color: var(--muted); font-size: 15px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.actions .btn.primary { grid-column: 1 / -1; }
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 14px; }

/* ---------- Full-screen stage (quiz, flashcards, speed) ---------- */
.stage {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  background: var(--bg); animation: stageIn 260ms var(--ease);
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
@keyframes stageIn { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
.stage-top { display: flex; align-items: center; gap: 14px; padding: 12px 16px; max-width: 720px; width: 100%; margin: 0 auto; }
.stage-top .progress { flex: 1; height: 8px; border-radius: 99px; background: var(--sunken); overflow: hidden; }
.stage-top .progress i { display: block; height: 100%; background: var(--ink); border-radius: inherit; transition: width 300ms var(--ease); }
.stage-top .count { font-size: 14px; font-weight: 600; color: var(--muted); min-width: 44px; text-align: right; }
.stage-body { flex: 1; overflow-y: auto; padding: 12px 16px 24px; max-width: 720px; width: 100%; margin: 0 auto; }
.stage-foot { padding: 12px 16px 16px; max-width: 720px; width: 100%; margin: 0 auto; }
.q-eyebrow { font-size: 13px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 8px 0 10px; }
.q-text { font: 650 22px/1.35 var(--font-display); letter-spacing: -0.015em; margin: 0 0 22px; text-wrap: pretty; }
.options { display: grid; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 58px; padding: 12px 16px;
  border-radius: 16px; border: 1.5px solid var(--line-strong); background: var(--surface); text-align: left; font-size: 16.5px; line-height: 1.35;
  transition: border-color 120ms, background 120ms, transform 120ms var(--ease);
}
.opt:active { transform: scale(0.99); }
.opt .key { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--sunken); font-size: 13px; font-weight: 700; color: var(--muted); }
.opt.correct { border-color: var(--good); background: var(--good-soft); }
.opt.correct .key { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .key { background: var(--bad); color: #fff; }
.opt.dim { opacity: 0.55; }
.options.locked .opt { pointer-events: none; }
.explain { margin-top: 16px; padding: 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); animation: viewIn 220ms var(--ease); }
.explain h3 { margin: 0 0 4px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.explain.good h3 { color: var(--good); }
.explain.bad h3 { color: var(--bad); }
.explain p { color: var(--ink-2); line-height: 1.55; }
.xp-pop { position: fixed; left: 50%; top: 22%; transform: translateX(-50%); z-index: 70; padding: 8px 14px; border-radius: 99px; background: var(--gold-soft); color: var(--gold); font-weight: 700; pointer-events: none; animation: pop 900ms var(--ease) forwards; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 8px); } 20% { opacity: 1; transform: translate(-50%, 0); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -16px); } }

.result { text-align: center; padding-top: 24px; }
.result .ring { width: 148px; height: 148px; margin: 0 auto 18px; }
.result .ring-label b { font-size: 40px; }
.result h2 { margin: 0 0 6px; font: 700 26px/1.2 var(--font-display); letter-spacing: -0.02em; }
.result .stars svg { width: 26px; height: 26px; }
.reward-list { display: grid; gap: 10px; margin: 22px 0 0; text-align: left; }

.flash {
  perspective: 1200px; margin: 12px auto 0; max-width: 520px; height: min(52vh, 360px);
}
.flash:focus-visible { outline: none; }
.flash:focus-visible .flash-face { outline: 2px solid var(--accent); outline-offset: 3px; }
.flash-inner { position: relative; width: 100%; height: 100%; transition: transform 500ms var(--ease); transform-style: preserve-3d; cursor: pointer; }
.flash.flipped .flash:focus-visible { outline: none; }
.flash:focus-visible .flash-face { outline: 2px solid var(--accent); outline-offset: 3px; }
.flash-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 28px; text-align: center;
  border-radius: 24px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.flash-face.back { transform: rotateY(180deg); }
.flash-face .term { font: 700 28px/1.2 var(--font-display); letter-spacing: -0.02em; }
.flash-face .def { font-size: 19px; line-height: 1.5; color: var(--ink-2); }
.flash-face .tap { position: absolute; bottom: 16px; left: 0; right: 0; font-size: 13px; color: var(--faint); }

.timer { font: 700 15px/1 var(--font-display); font-variant-numeric: tabular-nums; padding: 8px 12px; border-radius: 99px; background: var(--sunken); }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.flash-ok { animation: okFlash 380ms ease; }
.flash-no { animation: noFlash 380ms ease; }
@keyframes okFlash { 30% { background: var(--good-soft); } }
@keyframes noFlash { 30% { background: var(--bad-soft); } }

/* ---------- Sheet (forms) ---------- */
.scrim { position: fixed; inset: 0; z-index: 60; background: var(--scrim); animation: fade 200ms ease; display: flex; align-items: flex-end; justify-content: center; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px max(18px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 20px) max(18px, env(safe-area-inset-left, 0px));
  animation: sheetUp 300ms var(--ease); box-shadow: var(--shadow-2);
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0.6; } }
.sheet .grab { width: 38px; height: 5px; border-radius: 99px; background: var(--line-strong); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.sheet-head h2 { margin: 0; font: 700 20px/1.25 var(--font-display); letter-spacing: -0.015em; }
.sheet-foot { display: grid; gap: 10px; margin-top: 22px; }
@media (min-width: 700px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 22px; padding-bottom: 22px; }
  .sheet .grab { display: none; }
}
.prose { white-space: pre-wrap; line-height: 1.6; color: var(--ink-2); font-size: 15px; }

/* ---------- Tutor ---------- */
.tutor { display: flex; flex-direction: column; min-height: calc(100dvh - var(--tabbar-h) - env(safe-area-inset-bottom, 0px) - env(safe-area-inset-top, 0px) - 44px); }
@media (min-width: 900px) { .tutor { min-height: calc(100dvh - 100px); } }
.tutor-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tutor-bar .select { width: auto; min-height: 38px; padding: 6px 34px 6px 12px; border-radius: 99px; font-size: 14.5px; font-weight: 600; background-position: calc(100% - 17px) 16px, calc(100% - 12px) 16px; max-width: 100%; }
.chat { flex: 1; display: flex; flex-direction: column; gap: 12px; padding-bottom: 12px; }
.msg { max-width: 86%; padding: 11px 14px; border-radius: 18px; line-height: 1.5; font-size: 15.5px; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--ink); color: var(--on-ink); border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.bot p + p, .msg.bot p + ul, .msg.bot ul + p, .msg.bot p + ol, .msg.bot ol + p { margin-top: 8px; }
.msg ul, .msg ol { margin: 0; padding-left: 20px; }
.msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; background: var(--sunken); padding: 1px 5px; border-radius: 5px; }
.msg pre { margin: 8px 0 0; padding: 10px; background: var(--sunken); border-radius: 10px; overflow-x: auto; font-size: 13.5px; }
.msg img { display: block; max-width: 220px; border-radius: 12px; margin-bottom: 8px; }
.msg.err { background: var(--bad-soft); color: var(--bad); border: 0; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite both; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.starter { display: grid; gap: 10px; margin-top: 8px; }
.starter-intro { text-align: center; padding: 18px 8px 8px; }
.starter-intro .badge-ic { width: 56px; height: 56px; border-radius: 18px; margin: 0 auto 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.starter-intro .badge-ic svg.i { width: 28px; height: 28px; }
.composer {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 8px);
  display: flex; align-items: flex-end; gap: 8px; padding: 8px; border-radius: 22px;
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow-2);
}
@media (min-width: 900px) { .composer { bottom: 20px; } }
.composer textarea { flex: 1; min-height: 40px; max-height: 160px; padding: 9px 6px; border: 0; background: none; resize: none; font-size: 16px; line-height: 1.4; outline: none; }
.composer .send { background: var(--ink); color: var(--on-ink); }
.composer .send[disabled] { opacity: 0.3; }
.attach-preview { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; padding: 8px 10px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow-2); }
.attach-preview img { width: 54px; height: 54px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

/* ---------- Progress ---------- */
.heat { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin: 16px auto 0; max-width: 300px; }
.heat i { aspect-ratio: 1; border-radius: 7px; background: var(--sunken); }
.heat i.l1 { background: color-mix(in srgb, var(--accent) 35%, var(--sunken)); }
.heat i.l2 { background: color-mix(in srgb, var(--accent) 65%, var(--sunken)); }
.heat i.l3 { background: var(--accent); }
.heat i.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.heat-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin: 8px auto 0; max-width: 300px; font-size: 11px; color: var(--muted); text-align: center; }
.badges { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 600px) { .badges { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.badge { padding: 16px 10px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); text-align: center; }
.badge .medal { width: 44px; height: 44px; margin: 0 auto 8px; border-radius: 50%; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold); }
.badge b { display: block; font-size: 13.5px; line-height: 1.25; }
.badge span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.3; }
.badge.locked .medal { background: var(--sunken); color: var(--faint); }
.badge.locked b { color: var(--muted); }
.bar { height: 6px; border-radius: 99px; background: var(--sunken); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; border-radius: inherit; background: hsl(var(--h, 30) calc(var(--subj-s) + 10%) var(--subj-l)); }

/* ---------- Homework ---------- */
.check {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line-strong); background: none; flex: none; position: relative;
  display: grid; place-items: center; color: transparent; padding: 0;
}
.check::after { content: ""; position: absolute; inset: -9px; }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.due { font-size: 13px; font-weight: 600; }
.due.over { color: var(--bad); }
.due.soon { color: var(--gold-ink); }
.done-title { text-decoration: line-through; color: var(--muted); }

/* ---------- Empty, loading, toast ---------- */
.empty { text-align: center; padding: 30px 18px; color: var(--muted); }
.empty .badge-ic { width: 52px; height: 52px; border-radius: 16px; margin: 0 auto 12px; display: grid; place-items: center; background: var(--sunken); color: var(--muted); }
.empty h3 { margin: 0 0 4px; color: var(--ink); font-size: 17px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line-strong); border-top-color: var(--ink); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.toasts { position: fixed; z-index: 90; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 84px); display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 420px; padding: 11px 16px; border-radius: 16px;
  background: var(--ink); color: var(--on-ink); font-size: 14.5px; font-weight: 550; box-shadow: var(--shadow-2);
  animation: toastIn 320ms var(--ease);
}
.toast.gold svg { color: var(--gold); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
@media (min-width: 900px) { .toasts { bottom: 28px; left: 248px; } }
body:has(.stage) .toasts { bottom: 96px; left: 0; }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; color: var(--ink-2); margin-bottom: 14px; }

/* ---------- Sign in ---------- */
.signin { min-height: 100dvh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.signin-card { width: 100%; max-width: 380px; text-align: center; }
.app-icon { width: 76px; height: 76px; border-radius: 20px; margin: 0 auto 18px; display: block; box-shadow: var(--shadow-2); }
.app-icon svg.i { width: 38px; height: 38px; stroke-width: 1.6; }
.signin h1 { margin: 0 0 6px; font: 700 28px/1.2 var(--font-display); letter-spacing: -0.02em; }
.signin form { margin-top: 26px; display: grid; gap: 12px; text-align: left; }
.form-error { color: var(--bad); font-size: 14px; min-height: 20px; }

canvas.confetti { position: fixed; inset: 0; z-index: 80; pointer-events: none; }

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