/* Qistyna's Maths — "The Atelier"
   Her world: fashion sketching, art, drama. This is her sketchbook, not a
   worksheet: blush sketch-paper, aubergine pencil, velvet-curtain berry,
   brass spotlight gold. The signature is the croquis gown that colours in
   as she practises. Drama appears once — the curtain call. */

@font-face {
  font-family: 'Playfair Display';
  src: url('/fonts/playfair-600.woff2') format('woff2');
  font-weight: 600 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #FBF3F5;          /* blush sketch paper */
  --paper-2: #F4E7EC;        /* tracing-paper shade */
  --card: #FFFFFF;
  --ink: #2B1F2B;            /* aubergine pencil */
  --ink-2: #6E5F6C;
  --ink-3: #A99AA6;
  --velvet: #7C2B57;         /* stage curtain / couture berry — actions */
  --velvet-soft: #F6E2EC;
  --velvet-mid: #A23C72;     /* the wash's leading edge */
  --velvet-deep: #5E1F42;    /* the wash pooling at the hem */
  --gold: #C8952E;           /* brass spotlight, gold thread */
  --gold-soft: #FBEFD6;
  --emerald: #2F7D62;        /* correct */
  --emerald-soft: #E4F1EB;
  --coral: #C4562F;          /* not yet — warm, never harsh */
  --coral-soft: #FBE7DE;
  --rule: #E7D3DB;           /* hairline, like a sketchbook margin */
  --shadow: 0 1px 2px rgba(43,31,43,.06), 0 8px 24px rgba(43,31,43,.07);
  --radius: 20px;
  /* Motion, per Apple's HIG: springs, not linear ramps — things should settle
     like objects, not glide like slides. cubic-bezier first as the floor;
     browsers that support linear() take the real spring curve below. */
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --quick: .28s;
  --display: 'Playfair Display', Georgia, serif;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --math: Georgia, 'Noto Serif', 'Times New Roman', serif;
}

@media (prefers-color-scheme: dark) {
  body { background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2272%22%20height%3D%2272%22%20viewBox%3D%220%200%2072%2072%22%3E%3Cg%20fill%3D%22none%22%20stroke%3D%22%23E9B9CE%22%20stroke-opacity%3D%220.17%22%20stroke-width%3D%221%22%3E%3Cpath%20d%3D%22M-12.4%2C-12.4%20H12.4%20V12.4%20H-12.4%20ZM0%2C-17.53624817342638%20L17.53624817342638%2C0%20L0%2C17.53624817342638%20L-17.53624817342638%2C0%20Z%20M59.6%2C-12.4%20H84.4%20V12.4%20H59.6%20ZM72%2C-17.53624817342638%20L89.53624817342637%2C0%20L72%2C17.53624817342638%20L54.46375182657362%2C0%20Z%20M-12.4%2C59.6%20H12.4%20V84.4%20H-12.4%20ZM0%2C54.46375182657362%20L17.53624817342638%2C72%20L0%2C89.53624817342637%20L-17.53624817342638%2C72%20Z%20M59.6%2C59.6%20H84.4%20V84.4%20H59.6%20ZM72%2C54.46375182657362%20L89.53624817342637%2C72%20L72%2C89.53624817342637%20L54.46375182657362%2C72%20Z%20M23.6%2C23.6%20H48.4%20V48.4%20H23.6%20ZM36%2C18.46375182657362%20L53.53624817342638%2C36%20L36%2C53.53624817342638%20L18.46375182657362%2C36%20Z%22%2F%3E%3Cpath%20d%3D%22M12.4%2C12.4%20L23.6%2C23.6%20M59.6%2C12.4%20L48.4%2C23.6%20M12.4%2C59.6%20L23.6%2C48.4%20M59.6%2C59.6%20L48.4%2C48.4%22%20stroke-opacity%3D%220.10200000000000001%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E"); }
  :root {
    --paper: #1A1219;
    --paper-2: #221722;
    --card: #251A24;
    --ink: #F5E9EF;
    --ink-2: #BCA8B6;
    --ink-3: #806C7B;
    --velvet: #D06398;       /* lifted so it reads on dark */
    --velvet-soft: #3A2032;
    --velvet-mid: #C05C8E;
    --velvet-deep: #7E2F58;
    --gold: #E2B457;
    --gold-soft: #3A2E17;
    --emerald: #52B08C;
    --emerald-soft: #14332A;
    --coral: #E8825A;
    --coral-soft: #3A2318;
    --rule: #3A2A36;
    --shadow: 0 2px 14px rgba(0,0,0,.45);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--ui);
  color: var(--ink);
  background-color: var(--paper);
  /* The ground: an eight-pointed-star (khatam) tessellation — the geometry of
     the Malay/Islamic decorative art Sharifa grows up surrounded by, and ALSO
     her syllabus: tessellation, rotational symmetry, congruence, polygons.
     Kept faint so it reads as embossed paper and never competes with a question. */
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2272%22%20height%3D%2272%22%20viewBox%3D%220%200%2072%2072%22%3E%3Cg%20fill%3D%22none%22%20stroke%3D%22%237C2B57%22%20stroke-opacity%3D%220.13%22%20stroke-width%3D%221%22%3E%3Cpath%20d%3D%22M-12.4%2C-12.4%20H12.4%20V12.4%20H-12.4%20ZM0%2C-17.53624817342638%20L17.53624817342638%2C0%20L0%2C17.53624817342638%20L-17.53624817342638%2C0%20Z%20M59.6%2C-12.4%20H84.4%20V12.4%20H59.6%20ZM72%2C-17.53624817342638%20L89.53624817342637%2C0%20L72%2C17.53624817342638%20L54.46375182657362%2C0%20Z%20M-12.4%2C59.6%20H12.4%20V84.4%20H-12.4%20ZM0%2C54.46375182657362%20L17.53624817342638%2C72%20L0%2C89.53624817342637%20L-17.53624817342638%2C72%20Z%20M59.6%2C59.6%20H84.4%20V84.4%20H59.6%20ZM72%2C54.46375182657362%20L89.53624817342637%2C72%20L72%2C89.53624817342637%20L54.46375182657362%2C72%20Z%20M23.6%2C23.6%20H48.4%20V48.4%20H23.6%20ZM36%2C18.46375182657362%20L53.53624817342638%2C36%20L36%2C53.53624817342638%20L18.46375182657362%2C36%20Z%22%2F%3E%3Cpath%20d%3D%22M12.4%2C12.4%20L23.6%2C23.6%20M59.6%2C12.4%20L48.4%2C23.6%20M12.4%2C59.6%20L23.6%2C48.4%20M59.6%2C59.6%20L48.4%2C48.4%22%20stroke-opacity%3D%220.078%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E");
  background-size: 72px 72px;
  background-attachment: fixed;
  min-height: 100vh; min-height: 100dvh;
  line-height: 1.55;
  padding-bottom: calc(66px + env(safe-area-inset-bottom));
}
#app { max-width: 560px; margin: 0 auto; padding: 18px 16px 26px; }

/* ---- type ---------------------------------------------------------------- */
.eyebrow {
  font-size: .68rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3); display: block; margin-bottom: 10px;
}
.screen-title {
  font-family: var(--display); font-weight: 700;
  font-size: 1.9rem; line-height: 1.1; letter-spacing: -.01em; margin: 2px 0 4px;
}
.screen-sub { color: var(--ink-2); font-size: .93rem; margin-bottom: 16px; }

/* ---- maths --------------------------------------------------------------- */
.math { font-family: var(--math); font-size: 1.1em; }
.mfrac { display:inline-flex; flex-direction:column; align-items:center; vertical-align:middle; margin:0 .16em; line-height:1.15; }
.mfrac > .num { padding: 0 .3em .08em; }
.mfrac > .den { padding: .08em .3em 0; border-top: 1.5px solid currentColor; }
sup { font-size: .72em; }
.mblock { display:block; white-space: pre-wrap; }

/* ---- cards --------------------------------------------------------------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 18px; margin-bottom: 14px;
  position: relative; overflow: hidden;
}

/* ---- THE SIGNATURE: the croquis gown ------------------------------------- */
.atelier {
  display: flex; align-items: center; gap: 18px;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 18px; margin-bottom: 14px;
  position: relative; overflow: hidden;
}
.atelier::before {           /* the spotlight finds her dress form */
  content: ''; position: absolute; left: -30px; top: -60px;
  width: 220px; height: 260px; pointer-events: none;
  background: radial-gradient(ellipse 100px 130px at 50% 55%,
              rgba(200,149,46,.16), rgba(200,149,46,0) 70%);
}
/* @property lets a percentage custom property be TRANSITIONED. Without it the
   mask gradient snaps instead of rising, because gradients aren't interpolable
   on their own. Safari 16.4+/Chrome; older browsers just jump — acceptable. */
@property --reveal {
  syntax: '<percentage>';
  /* MUST inherit: --reveal is set on .gown but consumed by the mask on its
     CHILD .colour. With inherits:false the child silently falls back to
     initial-value (0%), the mask stays fully transparent, and the dress never
     colours in — valid CSS, no error, nothing on screen. */
  inherits: true;
  initial-value: 0%;
}

.gown {
  position: relative; width: 122px; flex-shrink: 0;
  transition: --reveal .9s var(--ease-out);
}
.gown img {
  width: 100%; display: block; border-radius: 12px;
}
/* the uncoloured sketch she's working on */
.gown .ghost { filter: grayscale(1) opacity(.3); }
/* the colour, masked so it climbs from the hem with a soft leading edge */
.gown .colour {
  position: absolute; inset: 0;
  -webkit-mask-image: linear-gradient(to top, #000 calc(var(--reveal) - 15%), transparent var(--reveal));
          mask-image: linear-gradient(to top, #000 calc(var(--reveal) - 15%), transparent var(--reveal));
}
.gown.done {
  box-shadow: 0 0 0 2px var(--gold), 0 6px 20px rgba(200,149,46,.28);
  border-radius: 12px;
}

.atelier-copy { min-width: 0; }
.atelier-count {
  font-family: var(--display); font-weight: 700; font-size: 2.6rem; line-height: 1;
  letter-spacing: -.02em;
}
.atelier-count em { font-style: normal; color: var(--velvet); }
.atelier-line { color: var(--ink-2); font-size: .92rem; margin-top: 4px; }
.streak {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
  font-size: .78rem; font-weight: 700; letter-spacing: .04em;
  color: var(--gold); background: var(--gold-soft);
  padding: 5px 11px; border-radius: 999px;
}

/* ---- buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--ui); font-size: 1.04rem; font-weight: 700;
  padding: 16px 22px; border-radius: 999px; border: none;
  background: linear-gradient(135deg, var(--velvet-mid), var(--velvet));
  color: #fff; width: 100%;
  touch-action: manipulation; letter-spacing: .01em;
  transition: transform .12s cubic-bezier(.34,1.56,.64,1);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn.ghost { background: transparent; color: var(--velvet); border: 1.5px solid var(--rule); }
.btn.small { border-radius: 999px; }
.btn.small { width: auto; padding: 9px 15px; font-size: .86rem; }
@media (prefers-color-scheme: dark) { .btn { color: #23101B; } }

/* ---- question card ------------------------------------------------------- */
.qcard .chapter-tag {
  display:inline-block; font-size:.65rem; font-weight:700; letter-spacing:.14em;
  text-transform:uppercase; color:var(--velvet); background:var(--velvet-soft);
  border-radius:6px; padding:4px 9px; margin-bottom:12px;
}
.qcard .qtext { font-size: 1.06rem; line-height: 1.65; }
.qcard .qtext .math { font-size: 1.2em; }

.qgraph { margin: 14px 0 4px; text-align: center; }
.qgraph svg { max-width: 100%; height: auto; }
.qgraph .svggrid { stroke: var(--rule); stroke-width: 1; }
.qgraph .svgaxis { stroke: var(--ink-2); stroke-width: 1.4; }
.qgraph .svgline { stroke: var(--velvet); stroke-width: 2.4; fill: none; }
.qgraph .svgline2 { stroke: var(--gold); stroke-width: 2.4; fill: none; }
.qgraph .svgpt { fill: var(--ink); }
.qgraph .svgbar { fill: var(--velvet); opacity: .85; }
.qgraph text { fill: var(--ink-2); font-size: 11px; font-family: var(--ui); }

/* ---- answer input -------------------------------------------------------- */
.answer-row { display:flex; gap:8px; align-items:stretch; margin-top:16px; }
.answer-label { align-self:center; color:var(--ink-2); font-family:var(--math); white-space:nowrap; }
input.answer {
  flex:1; min-width:0; font-family:var(--math); font-size:1.15rem;
  padding:13px 14px; color:var(--ink); background:var(--paper);
  border:2px solid var(--rule); border-radius:10px; outline:none;
}
input.answer:focus { border-color: var(--velvet); }
input.answer.wrong { border-color: var(--coral); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.preview { min-height:32px; margin-top:8px; padding:5px 2px; color:var(--ink-2); font-size:.83rem; display:flex; align-items:center; gap:8px; }
.preview .math { color: var(--ink); font-size: 1.25rem; }
.preview:empty { display:none; }

/* ---- typing vs picking ----------------------------------------------------
   These two were the same object in different sizes — bordered cards in a row —
   so the maths KEYBOARD read as multiple-choice OPTIONS. It has to be obvious at
   a glance which one you're looking at, so they now share nothing:

     keyboard → one attached slab of flat, borderless keys, welded to the field
     options  → separate cards, lettered A/B/C/D, with "Pick one" above them   */

/* the field and its keys are ONE control */
.typehere {
  margin-top: 16px;
  border: 2px solid var(--rule); border-radius: 12px;
  background: var(--paper); overflow: hidden;
}
.typehere:focus-within { border-color: var(--velvet); }
.typehere .answer-row { margin: 0; }
.typehere input.answer {
  border: none; border-radius: 0; background: transparent;
  width: 100%; padding: 14px;
}
.typehere input.answer:focus { border: none; box-shadow: none; }

/* the keyboard: a tinted tray, hairline-topped, keys with NO borders of their own */
.keystrip {
  display: flex; gap: 2px; overflow-x: auto; padding: 5px 5px;
  background: var(--paper-2); border-top: 1px solid var(--rule);
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.keystrip::-webkit-scrollbar { display: none; }
.keystrip button {
  font-family: var(--math); font-size: 1.02rem;
  min-width: 38px; height: 36px; padding: 0 8px;
  border: none; border-radius: 7px; background: transparent;
  color: var(--ink-2); flex-shrink: 0;
}
.keystrip button:active { background: var(--velvet); color: #fff; }

/* the options: unmistakably things you choose between */
.choices { display: flex; flex-direction: column; gap: 9px; margin-top: 16px; }
.pick-hint {
  font-size: .66rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 3px;
}
.choices button {
  display: flex; align-items: center; gap: 12px;
  text-align: left; font-size: 1.05rem; font-family: var(--math);
  padding: 15px 14px; border-radius: 12px; border: 2px solid var(--rule);
  background: var(--card); color: var(--ink);
}
.choices .pick {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--ui); font-size: .78rem; font-weight: 700;
  background: var(--velvet-soft); color: var(--velvet);
}
.choices button.sel { border-color:var(--velvet); background:var(--velvet-soft); }
.choices button.right { border-color:var(--emerald); background:var(--emerald-soft); }
.choices button.right .pick { background: var(--emerald); color: #fff; }
.choices button.wrongpick { border-color:var(--coral); background:var(--coral-soft); }
.choices button.wrongpick .pick { background: var(--coral); color: #fff; }

/* grade buttons */
.grades { display:grid; grid-template-columns:repeat(4,1fr); gap:7px; margin-top:14px; }
.grades button { padding:11px 4px 9px; border-radius:11px; border:none; font-weight:700; font-size:.88rem; color:#fff; }
.grades .g-int { display:block; font-weight:400; font-size:.68rem; opacity:.88; margin-top:1px; }
.g0 { background: var(--coral); }
.g1 { background: #B8873C; }
.g2 { background: var(--emerald); }
.g3 { background: var(--velvet); }

/* ---- feedback ------------------------------------------------------------ */
.markwrap { position:absolute; top:10px; right:12px; width:46px; height:46px; pointer-events:none; }
.tickpath {
  stroke: var(--emerald); stroke-width:5; fill:none; stroke-linecap:round; stroke-linejoin:round;
  stroke-dasharray:60; stroke-dashoffset:60; animation: drawtick .4s ease-out forwards;
}
@keyframes drawtick { to { stroke-dashoffset: 0; } }
.feedback { margin-top:14px; padding:13px 14px; border-radius:11px; font-size:.95rem; }
.feedback.good { background:var(--emerald-soft); color:var(--emerald); font-weight:700; }
.feedback.almost { background:var(--gold-soft); color:var(--ink); }
.feedback.notyet { background:var(--coral-soft); color:var(--ink); }

.steps { margin-top:14px; border-top:1px solid var(--rule); padding-top:14px; }
.steps .step { display:flex; gap:11px; margin-bottom:10px; font-size:.95rem; line-height:1.6; }
.steps .stepno {
  flex-shrink:0; width:22px; height:22px; margin-top:2px; border-radius:50%;
  background:var(--velvet-soft); color:var(--velvet);
  font-size:.72rem; font-weight:700; display:flex; align-items:center; justify-content:center;
}
.hintbox { margin-top:10px; padding:12px 13px; background:var(--gold-soft); border-radius:10px; font-size:.92rem; }
.hintbox::before { content: '✦ '; color: var(--gold); font-weight: 700; }

/* ---- chapter list -------------------------------------------------------- */
.chapter-item {
  display:flex; align-items:center; gap:12px; width:100%;
  background:var(--card); border-radius:13px; box-shadow:var(--shadow);
  padding:14px; margin-bottom:9px; border:none; text-align:left;
  color:var(--ink); font-family:var(--ui);
}
.chapter-item .ch-title { font-weight:700; font-size:.95rem; }
.chapter-item .ch-sub { color:var(--ink-2); font-size:.77rem; }
.chapter-item .ch-mastery { margin-left:auto; flex-shrink:0; width:52px; }
.ring { transform: rotate(-90deg); }
.ring .bg { stroke: var(--rule); }
.ring .fg { stroke: var(--velvet); stroke-linecap: round; transition: stroke-dashoffset .4s; }
.ring-label { font-size:.72rem; font-weight:700; fill:var(--ink); transform: rotate(90deg); transform-origin:center; }

/* ---- bars / dashboard ---------------------------------------------------- */
.chart-title { font-size:.68rem; font-weight:700; letter-spacing:.16em; text-transform:uppercase; color:var(--ink-3); margin-bottom:12px; }
.mbar-row { display:flex; align-items:center; gap:9px; margin-bottom:9px; font-size:.82rem; }
.mbar-label { width:112px; flex-shrink:0; color:var(--ink); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.mbar-track { flex:1; height:10px; background:var(--paper-2); border-radius:5px; overflow:hidden; }
.mbar-fill { height:100%; background:var(--velvet); border-radius:5px 0 0 5px; min-width:2px; }
.mbar-fill.need { background: var(--coral); }
.mbar-val { min-width:38px; flex-shrink:0; text-align:right; color:var(--ink-2); font-variant-numeric:tabular-nums; }
.focus-chip { font-size:.62rem; font-weight:700; letter-spacing:.06em; text-transform:uppercase; color:var(--coral); background:var(--coral-soft); padding:3px 8px; border-radius:999px; white-space:nowrap; }

.dotcal { display:grid; grid-template-columns:repeat(15,1fr); gap:4px; }
.dotcal span { aspect-ratio:1; border-radius:4px; background:var(--paper-2); }
.dotcal span.on { background: var(--gold); }
.dotcal span.today { outline:2px solid var(--velvet); }

.daily-chart { display:flex; align-items:flex-end; gap:3px; height:72px; }
.daily-chart .dbar { flex:1; display:flex; flex-direction:column; justify-content:flex-end; height:100%; border-radius:3px 3px 0 0; overflow:hidden; }
.daily-chart .seg-ok { background: var(--emerald); }
.daily-chart .seg-no { background: var(--paper-2); }

.progressbar { height:7px; background:var(--paper-2); border-radius:4px; overflow:hidden; margin:10px 0 4px; }
.progressbar > div { height:100%; background:var(--velvet); border-radius:4px; transition:width .3s; }

/* ---- login --------------------------------------------------------------- */
.login-wrap { max-width: 330px; margin: 12vh auto 0; text-align: center; }
.login-wrap .brand-gown { width: 78px; margin: 0 auto 16px; }
.login-wrap .brand-gown .gown { width: 100%; }
.login-wrap h1 { font-family: var(--display); font-weight:700; font-size:2.15rem; line-height:1.1; margin-bottom:8px; }
.login-wrap p { color: var(--ink-2); font-size:.93rem; margin-bottom:22px; }
.pin-input {
  font-size:1.7rem; letter-spacing:.5em; text-align:center; width:100%; padding:13px;
  font-family:var(--ui); border:2px solid var(--rule); border-radius:12px;
  background:var(--card); color:var(--ink); outline:none;
}
.pin-input:focus-visible { border-color: var(--rule); }  /* the gold ring is the indicator; don't double it */

/* ---- curtain call (the one drama moment) --------------------------------- */
.curtain {
  position: relative; text-align:center; padding: 30px 18px 34px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
/* velvet drapes sweeping in from both sides */
.curtain::before, .curtain::after {
  content:''; position:absolute; top:0; bottom:0; width:34%;
  background: linear-gradient(90deg, var(--velvet), #5E1F41);
  animation: sweep .9s cubic-bezier(.3,.9,.3,1) forwards;
}
.curtain::before { left:0; transform-origin:left; border-radius: 0 60% 60% 0 / 0 50% 50% 0; }
.curtain::after  { right:0; transform-origin:right; border-radius: 60% 0 0 60% / 50% 0 0 50%; transform: scaleX(1); }
@keyframes sweep { from { transform: scaleX(1); } to { transform: scaleX(.12); } }
/* a spotlight pool behind the gown */
.curtain .spot {
  position:absolute; left:50%; top:0; width:220px; height:220px; transform:translateX(-50%);
  background: radial-gradient(circle at 50% 20%, var(--gold-soft), transparent 65%);
  pointer-events:none;
}
.curtain .inner { position: relative; }
.curtain .bow { font-family: var(--display); font-weight:700; font-size:2rem; margin: 6px 0 4px; }
.curtain .score { color: var(--ink-2); font-size:.95rem; margin-bottom: 18px; }
.curtain .gown { width: 110px; margin: 0 auto 10px; }

/* ---- nav ----------------------------------------------------------------- */
nav.tabbar {
  position:fixed; bottom:0; left:0; right:0; z-index:10;
  display:flex; justify-content:space-around;
  background: var(--card); border-top: 1px solid var(--rule);
  padding: 7px 4px calc(7px + env(safe-area-inset-bottom));
}
nav.tabbar button {
  flex:1; max-width:110px; border:none; background:none;
  font-family:var(--ui); font-size:.66rem; font-weight:700; letter-spacing:.05em;
  color:var(--ink-3); padding:3px 2px; border-radius:10px;
}
nav.tabbar button .ico {
  display:block; width:24px; height:24px; margin:0 auto 3px;
  fill:none; stroke:currentColor; stroke-width:1.5;
  stroke-linecap:round; stroke-linejoin:round;
  transition: stroke-width .15s ease;
}
nav.tabbar button.active { color: var(--velvet); }
/* the active tab is inked in harder, the way you'd press down on the line you mean */
nav.tabbar button.active .ico { stroke-width:1.9; }
/* stars are the only gold thing in the app — keep that true here too */
nav.tabbar button.active[data-tab="stars"] { color: var(--gold); }

/* ---- admin --------------------------------------------------------------- */
.admin-field { margin-bottom:12px; }
.admin-field label { display:block; font-size:.66rem; font-weight:700; letter-spacing:.14em; text-transform:uppercase; color:var(--ink-3); margin-bottom:5px; }
.admin-field input[type="date"], .admin-field input[type="text"] {
  width:100%; padding:11px 12px; font-size:1rem; font-family:var(--ui);
  border:2px solid var(--rule); border-radius:10px; background:var(--card); color:var(--ink);
}
.chip-row { display:flex; flex-wrap:wrap; gap:6px; }
.chip { font-size:.78rem; font-weight:600; padding:7px 11px; border-radius:999px; border:1.5px solid var(--rule); background:var(--card); color:var(--ink-2); }
.chip.on { background:var(--velvet-soft); border-color:var(--velvet); color:var(--velvet); }
.doc-item { padding:11px 0; border-bottom:1px solid var(--rule); font-size:.87rem; }
.doc-item .doc-label { font-weight:700; }
.doc-item .doc-sum { color:var(--ink-2); font-size:.81rem; margin:3px 0; }
.doc-find { font-size:.79rem; color:var(--ink-2); padding-left:10px; }

/* ---- misc ---------------------------------------------------------------- */
.toast {
  position:fixed; left:50%; transform:translateX(-50%);
  bottom: calc(86px + env(safe-area-inset-bottom)); z-index:30;
  background:var(--ink); color:var(--paper);
  padding:11px 18px; border-radius:999px; font-size:.87rem;
  box-shadow:var(--shadow); opacity:0; transition:opacity .25s; pointer-events:none;
  max-width:90vw; text-align:center;
}
.toast.show { opacity: 1; }
.offline-dot { display:inline-block; width:8px; height:8px; border-radius:50%; background:var(--coral); margin-left:6px; vertical-align:middle; }
.empty { text-align:center; color:var(--ink-2); padding:34px 12px; }
.empty .big { font-size:2.4rem; margin-bottom:8px; }

/* gold sequins on a correct answer */
.sequin {
  position: fixed; z-index: 40; pointer-events: none;
  color: var(--gold); font-size: 1.05rem; line-height: 1;
  animation: sequin 1.2s cubic-bezier(.2,.7,.3,1) forwards;
}
@keyframes sequin {
  0%   { transform: translate(-50%,-50%) scale(.4) rotate(0); opacity: 0; }
  15%  { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--rot)); opacity: 0; }
}

button { cursor:pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
/* the field already frames itself; a second ring inside the gold one is noise */
.typehere:focus-within { border-color: var(--rule); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---- the sketchbook: illustrations she unlocks by mastering a chapter ------ */
.plates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 380px) { .plates { grid-template-columns: repeat(2, 1fr); } }
.plate { position: relative; margin: 0; }
/* the frame exists to CLIP the unlock sweep. Without it the gold band is just a
   translated pseudo-element and slides straight over the neighbouring dress. */
.plate-frame {
  position: relative; display: block; overflow: hidden; border-radius: 12px;
}
.plate img {
  width: 100%; aspect-ratio: 1; object-fit: cover; display: block;
  border-radius: 12px; background: var(--paper-2);
  /* locked: still visible as a promise, but plainly not yours yet */
  filter: grayscale(1) opacity(.28); transition: filter .5s ease, transform .3s ease;
}
.plate.open img { filter: none; }
.plate.open:active img { transform: scale(.97); }
.plate-lock {
  position: absolute; inset: 0; display: flex;
  flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.plate-pct { font-family: var(--display); font-weight: 700; font-size: 1.3rem; color: var(--ink-2); }
.plate-need { font-size: .6rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.plate figcaption {
  font-size: .62rem; font-weight: 700; letter-spacing: .04em;
  color: var(--ink-3); text-align: center; margin-top: 6px; line-height: 1.3;
}
.plate.open figcaption { color: var(--velvet); }


/* ---- motion ---------------------------------------------------------------
   HIG: motion is purposeful — it says what happened and where it came from.
   Everything here is fast (<.6s), interruptible, and off under Reduce Motion. */
@supports (transition-timing-function: linear(0, 1)) {
  :root {
    --spring: linear(0, .006, .025 2.8%, .101 6.1%, .539 18.9%, .721 25.3%,
                     .849 31.5%, .937 38.1%, .968 41.8%, .991 45.7%, 1.006 50.1%,
                     1.015 55%, 1.017 63.9%, 1.001 100%);
  }
}

/* content arrives — a short stagger, so the eye is led down the screen */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
#app > * { animation: rise .42s var(--ease-out) both; }
#app > *:nth-child(1) { animation-delay: 0s; }
#app > *:nth-child(2) { animation-delay: .05s; }
#app > *:nth-child(3) { animation-delay: .1s; }
#app > *:nth-child(4) { animation-delay: .15s; }
#app > *:nth-child(n+5) { animation-delay: .2s; }

/* THE UNLOCK — the payoff of the whole app. The plate is a locked ghost, then
   the colour floods in, it springs forward, and a bar of gold light sweeps the
   page like a hand smoothing it flat. Fires exactly once per chapter, ever. */
@keyframes unlock-bloom {
  0%   { filter: grayscale(1) opacity(.28); transform: scale(1); }
  35%  { filter: grayscale(0) opacity(1);   transform: scale(1.08); }
  100% { filter: none;                      transform: scale(1); }
}
@keyframes unlock-sweep {
  from { transform: translateX(-110%) skewX(-14deg); opacity: 0; }
  35%  { opacity: 1; }
  to   { transform: translateX(210%) skewX(-14deg); opacity: 0; }
}
@keyframes unlock-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}
/* the colour floods the image... */
.plate.just-unlocked img { animation: unlock-bloom 1.1s var(--spring) both; }
/* ...the plate springs forward (on .plate, so the pop is never cropped)... */
.plate.just-unlocked { animation: unlock-pop 1.1s var(--spring) both; z-index: 2; }
/* ...and a bar of gold light crosses it — INSIDE the frame, which clips it. */
.plate.just-unlocked .plate-frame::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent, rgba(200,149,46,.75), transparent);
  background-size: 55% 100%; background-repeat: no-repeat;
  animation: unlock-sweep 1.1s var(--ease-out) .18s both;
}
.plate.just-unlocked figcaption { animation: rise .5s var(--ease-out) .5s both; }

/* the count ticks up — a small pop, so a number changing is FELT, not just seen */
@keyframes tick-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.22); }
  100% { transform: scale(1); }
}
.atelier-count em.bumped { display: inline-block; animation: tick-pop .5s var(--spring); }

/* the new dress, revealed at the curtain call */
@keyframes plate-reveal {
  from { opacity: 0; transform: scale(.86) rotate(-2.5deg); }
  to   { opacity: 1; transform: none; }
}
.reveal-plate {
  width: 190px; margin: 0 auto 14px; border-radius: 14px; overflow: hidden;
  box-shadow: 0 10px 30px rgba(43,31,43,.22);
  animation: plate-reveal .7s var(--spring) both;
}
.reveal-plate img { width: 100%; display: block; }
.reveal-label {
  font-size: .66rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 10px;
}

/* tab changes cross-fade instead of snapping (Safari 18+, Chrome) */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: vt-out .2s var(--ease-out) both; }
::view-transition-new(root) { animation: vt-in .3s var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }

/* HIG is unambiguous about this one: if she's asked for less motion, she gets
   the outcome with none of the movement — never a degraded or broken version. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .plate.just-unlocked img { filter: none; }
  .plate.just-unlocked .plate-frame::after { display: none; }
}


/* ==========================================================================
   iPad and laptop
   Phone-first is right for Sharifa — but her tutor uses a laptop, and the app
   shouldn't look like a phone app marooned in whitespace on one.

   The bottom tab bar is an iPHONE idiom. On iPad and Mac, Apple uses a sidebar,
   so above the breakpoint the same nav becomes one. Note the min-height: a phone
   in LANDSCAPE is 844px wide and 390 tall — wide enough to trip a width-only
   query, and the last thing it can spare is horizontal room for a sidebar.
   ========================================================================== */

@media (min-width: 820px) and (min-height: 600px) {
  body { padding-bottom: 28px; padding-left: 232px; }
  body.on-login { padding-left: 0; }          /* login has no nav */

  nav.tabbar {
    top: 0; bottom: 0; left: 0; right: auto;
    width: 232px; height: 100vh; height: 100dvh;
    flex-direction: column; justify-content: flex-start; gap: 3px;
    border-top: none; border-right: 1px solid var(--rule);
    padding: 22px 14px;
  }
  nav.tabbar::before {                        /* the wordmark, only where there's room */
    content: "Qistyna's Maths";
    font-family: var(--display); font-weight: 700; font-size: 1.15rem;
    color: var(--ink); padding: 4px 12px 18px; letter-spacing: -.01em;
  }
  nav.tabbar button {
    /* the phone rules set flex:1 to spread tabs across the bar. In a COLUMN that
       makes every item grow to fill the viewport height — a giant pink slab for
       the active tab and the rest flung to the corners. */
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 12px;
    width: 100%; max-width: none; text-align: left;
    font-size: .93rem; letter-spacing: 0;
    padding: 11px 12px; border-radius: 11px;
  }
  nav.tabbar button .ico { margin: 0 0 0 2px; width: 21px; height: 21px; }
  nav.tabbar button.active { background: var(--velvet-soft); }
  nav.tabbar button.active[data-tab="stars"] { background: var(--gold-soft); }

  #app { max-width: 720px; padding: 26px 24px 40px; }

  /* the dress has room to be seen properly */
  .gown { width: 158px; }
  .atelier { gap: 26px; padding: 24px 22px; }
  .atelier-count { font-size: 3rem; }

  .plates { grid-template-columns: repeat(4, 1fr); }
}

/* laptop: use the width instead of padding it away */
@media (min-width: 1180px) and (min-height: 600px) {
  #app { max-width: 1060px; }

  /* Today: hero across the top, then "start" beside "where you need work" */
  #app.tab-today {
    display: grid; grid-template-columns: 1.15fr .85fr;
    gap: 18px; align-items: start;
  }
  #app.tab-today > .atelier { grid-column: 1 / -1; margin-bottom: 0; }
  #app.tab-today > .card:has(.steps) { grid-column: 1 / -1; }   /* how-this-works spans */
  #app.tab-today > .card { margin-bottom: 0; }

  #app.tab-progress { max-width: 1060px; }
  .plates { grid-template-columns: repeat(5, 1fr); }

  /* A question must NOT stretch to 1060px — long lines of maths are hard to
     track, and the answer field ending up a metre wide helps nobody. */
  #app.tab-question { max-width: 660px; }
}

/* pointer devices get hover affordances; touch devices must not (sticky :hover) */
@media (hover: hover) and (pointer: fine) {
  .btn:hover { filter: brightness(1.06); }
  .btn.ghost:hover { background: var(--velvet-soft); }
  nav.tabbar button:hover { color: var(--velvet); }
  .choices button:hover { border-color: var(--velvet); }
  .keystrip button:hover { background: var(--velvet-soft); color: var(--velvet); }
  .plate.open:hover img { transform: scale(1.03); }
  .chapter-row:hover, .fav-row:hover { border-color: var(--velvet); }
}

/* ---- Dress rehearsal ------------------------------------------------------
   The only number in this app that is also a real-world number. Her WA1 was
   18/40 and her WA2 was 12/40, so a rehearsal score stands on the same axis as
   the marks that decide her year — and it gets to look like it matters. */
.rehearsal-card { border: 1.5px solid var(--gold); background: var(--card); }

.exam-clock {
  font-family: var(--math); font-size: .95rem; font-weight: 700;
  color: var(--ink-2); background: var(--paper-2);
  padding: 5px 10px; border-radius: 8px; font-variant-numeric: tabular-nums;
}
.exam-clock.low { color: #fff; background: var(--coral); }

.paper-score {
  font-family: var(--display); line-height: 1; margin: 6px 0 10px;
}
.paper-score em { font-style: normal; font-size: 4.2rem; font-weight: 700; color: var(--velvet); }
.paper-score span { font-size: 1.5rem; color: var(--ink-3); margin-left: 6px; }

/* her real papers, and today's, on one axis */
.papers {
  display: flex; align-items: flex-end; justify-content: center; gap: 18px;
  height: 132px; margin: 22px 0 6px;
}
.paper-bar {
  position: relative; width: 52px; height: 100%;
  display: flex; flex-direction: column; justify-content: flex-end;
  background: var(--paper-2); border-radius: 8px;
}
.paper-bar-fill {
  background: var(--ink-3); border-radius: 8px;
  transition: height .9s var(--ease-out);
}
.paper-bar.now .paper-bar-fill { background: linear-gradient(180deg, var(--velvet-mid), var(--velvet)); }
.paper-bar-n {
  position: absolute; top: -22px; left: 0; right: 0; text-align: center;
  font-family: var(--display); font-weight: 700; font-size: 1rem; color: var(--ink-2);
}
.paper-bar.now .paper-bar-n { color: var(--velvet); }
.paper-bar-l {
  position: absolute; bottom: -22px; left: 0; right: 0; text-align: center;
  font-size: .66rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3);
}
.papers + .chart-title { margin-top: 34px !important; }

/* the badges that are NOT about being right */
.streak.rest  { color: var(--ink-2); background: var(--paper-2); }
.streak.fixed { color: var(--emerald); background: var(--emerald-soft); }
.atelier .streak { margin-right: 6px; }

/* ==========================================================================
   Motion, part two — six moments, each doing a job.
   HIG: purposeful, spring-driven, fast, and OFF under Reduce Motion.
   ========================================================================== */

/* 1. THE WORKING WRITES ITSELF IN.
   It used to appear as a block she could skim past — at exactly the moment she
   should NOT skim, because she just got it wrong. Now each line wipes in
   left-to-right, like a pen. She is never trapped: "Show it all" skips it. */
@keyframes write-in {
  from { opacity: 0; transform: translateY(5px); clip-path: inset(0 100% 0 0); }
  60%  { opacity: 1; }
  to   { opacity: 1; transform: none;            clip-path: inset(0 0 0 0); }
}
.steps .step {
  animation: write-in .5s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * .42s);
}
.steps.instant .step { animation: none; opacity: 1; clip-path: none; transform: none; }
.steps-skip {
  display: block; margin: 10px auto 0; border: none; background: none;
  font-family: var(--ui); font-size: .78rem; font-weight: 700;
  letter-spacing: .06em; color: var(--ink-3); text-decoration: underline;
}

/* the grade buttons are UNAVAILABLE, not merely invisible, while it writes —
   an opacity-0 button is still clickable, and she'd grade a step she never read */
.grades {
  opacity: 0; pointer-events: none; transform: translateY(8px);
  transition: opacity .35s var(--ease-out), transform .45s var(--spring);
}
.grades.in { opacity: 1; pointer-events: auto; transform: none; }

/* 2. THE BRUSH STROKE.
   The colour used to jump to its new level. Now it PAINTS from where she was —
   she watches the set she just did go on, and a brush sweeps the band it filled.
   The difference between a progress bar shaped like a dress and painting one. */
.gown.painting .colour { transition: --reveal 1.15s var(--ease-out); }
.gown .brush {
  position: absolute; inset: 0; pointer-events: none; border-radius: 12px;
  overflow: hidden; opacity: 0;
}
.gown.painting .brush { animation: brush-sweep 1.15s var(--ease-out) .06s both; }
@keyframes brush-sweep {
  0%   { opacity: 0; transform: translateX(-70%) skewX(-12deg); }
  25%  { opacity: .55; }
  75%  { opacity: .35; }
  100% { opacity: 0; transform: translateX(120%) skewX(-12deg); }
}
.gown .brush::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.75), transparent);
}

/* 3. PAGE TURNS. The sketchbook metaphor was sitting there unused: a new
   question is a new page, settling onto the stack. */
@keyframes page-turn {
  from { opacity: 0; transform: perspective(900px) rotateY(-7deg) translateX(22px); }
  to   { opacity: 1; transform: none; }
}
/* #app > * carries the entrance `rise` animation, and an ID beats a class on
   specificity — so a bare `.qcard` rule loses and the card just rises. Match the
   ID too. And .card sets overflow:hidden, which would clip the sheet peeking out
   from underneath, so the question card opts out. */
#app > .qcard {
  animation: page-turn .44s var(--ease-out) both;
  transform-origin: left center;
  overflow: visible;
}
#app > .qcard::before {   /* the sheet underneath — you're partway through a book */
  content: ''; position: absolute; inset: 7px -5px -6px 9px; z-index: -1;
  background: var(--paper-2); border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(43,31,43,.06);
}

/* 5. THE STREAK AS GOLD THREAD. An atelier counts days in thread, not in flames:
   a running stitch, one stitch per day, sewn in as it renders. */
.streak.thread { gap: 8px; }
.thread-svg { display: block; overflow: visible; }
.thread-svg .stitch {
  fill: none; stroke: var(--gold); stroke-width: 2.4; stroke-linecap: round;
  stroke-dasharray: 5 4;
  stroke-dashoffset: var(--len);
  animation: sew 1.1s var(--ease-out) .2s both;
}
@keyframes sew { to { stroke-dashoffset: 0; } }

/* 6. THE DRESS DRAWS ITSELF while we fetch. Dead time becomes the brand. */
.loading-card { display: flex; align-items: center; gap: 18px; }
.gown.drawing { width: 88px; }
.gown.drawing img { filter: grayscale(1) opacity(.26); border-radius: 12px; }
.gown.drawing::after {
  content: ''; position: absolute; inset: 0; border-radius: 12px;
  background: linear-gradient(100deg, transparent 30%, rgba(200,149,46,.35), transparent 70%);
  animation: sketching 1.4s linear infinite;
}
@keyframes sketching {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
  .steps .step { animation: none; opacity: 1; clip-path: none; transform: none; }
  .grades { opacity: 1; pointer-events: auto; transform: none; }
  #app > .qcard { animation: none; }
  .gown .brush, .gown.drawing::after { display: none; }
  .thread-svg .stitch { animation: none; stroke-dashoffset: 0; }
}

/* A plate whose artwork hasn't been painted yet: quiet placeholder, no broken
 * image glyph. The dashed rule reads as "sketched, not yet inked". */
.art-pending {
  background: var(--paper-2);
  border: 1.5px dashed var(--rule);
  border-radius: var(--radius);
  min-height: 120px;
}
