/* ─────────────────────────────────────────────────────────────
   Martabak Math Lab: quiet and minimal, lighter and a little fun.
   One blue for actions, a pastel for each unit, soft shadows instead of hard lines,
   faint maths doodles in the corners. Change the colours here and the whole site follows.
   ───────────────────────────────────────────────────────────── */
:root {
  --bg: #fbfcff;
  --surface: #ffffff;
  --line: #e7ebf4;          /* faint dividers, used sparingly */
  --line-2: #d6dcea;        /* field outlines */
  --ink: #1e2742;
  --ink-2: #56607a;
  --ink-3: #8b93a8;

  --primary: #4f7cff;
  --primary-deep: #3a66ea;
  --primary-wash: #edf2ff;

  --right: #1d9a68;
  --right-wash: #e3f6ed;
  --wrong: #e0553d;
  --wrong-wash: #fdece8;
  --highlight: #fff1a8;
  --highlight-ink: #6b5300;
  --amber: #b7791f;

  /* one pastel per unit: peach, mint, lilac, sky, butter, rose, aqua, and blue for the final */
  --t1: #ffe8db; --t1-ink: #b4572f;
  --t2: #dcf5e8; --t2-ink: #23845a;
  --t3: #ece6ff; --t3-ink: #6a4fd1;
  --t4: #ddeeff; --t4-ink: #2f72c4;
  --t5: #fff3cc; --t5-ink: #9a6b00;
  --t6: #ffe4ec; --t6-ink: #c0416f;
  --t7: #d9f4f2; --t7-ink: #1f8580;
  --t8: #e3e9ff; --t8-ink: #3a66ea;

  --shadow-sm: 0 1px 2px rgba(30, 39, 66, .05), 0 2px 10px rgba(30, 39, 66, .05);
  --shadow-md: 0 2px 4px rgba(30, 39, 66, .05), 0 10px 28px rgba(30, 39, 66, .09);

  --round: "Nunito", ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;
  --sans: "Atkinson Hyperlegible Next", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  /* kept for older code; headings now use the rounded face */
  --serif: var(--round);

  --step--1: 0.875rem;  /* 14 */
  --step-0: 1.0625rem;  /* 17 body */
  --step-1: 1.3125rem;  /* 21 */
  --step-2: 1.75rem;    /* 28 */
  --step-3: 2.5rem;     /* 40 */
  --step-4: 3.5rem;     /* 56 */

  --r-sm: 12px;
  --r: 16px;
  --r-lg: 20px;
  --radius: var(--r-sm);
  --wrap: 1120px;
  --bounce: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body {
  margin: 0;
  background-color: var(--bg);
  color: var(--ink);
  font: 400 var(--step-0)/1.55 var(--sans);
  /* a faint outline doodle in the corner: π and Σ (about 10% opacity) */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='170' viewBox='0 0 240 170' fill='none' stroke='%231e2742' stroke-opacity='.1' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 52 Q30 36 52 38 H118 M48 40 Q48 100 34 130 M88 40 Q86 104 104 128 Q112 134 120 124'/%3E%3Cpath d='M210 40 H158 L190 85 L158 130 H212'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left -24px bottom 16px;
  background-attachment: fixed;
}
a { color: var(--primary-deep); text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; font-family: var(--round); font-weight: 800; letter-spacing: -0.01em; }
p { margin: 0 0 .75rem; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid rgba(79, 124, 255, .45); outline-offset: 3px; border-radius: 8px; }
.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.quiet { color: var(--ink-3); }
.small { font-size: var(--step--1); }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 1rem; }
.center { text-align: center; }

.display { font-family: var(--round); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
h1.display { font-size: var(--step-4); }
h2.display { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); font-weight: 800; }

/* ─────────── Top bar ─────────── */
#site-header {
  width: 100%; display: flex; align-items: center; gap: 1.5rem;
  max-width: var(--wrap); margin: 0 auto; padding: 1.25rem 2rem;
}
.wordmark {
  display: inline-flex; align-items: center; gap: .55rem;
  font-family: var(--round); font-weight: 800; font-size: 1.3rem; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.wordmark::before {
  content: ""; width: 32px; height: 32px; flex: none; margin-top: -4px;
  background: url("../img/logo.svg") center / contain no-repeat;
}
.crumbs { display: flex; gap: .5rem; align-items: baseline; color: var(--ink-3); min-width: 0; flex: 0 1 auto; overflow: hidden; }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { color: var(--primary-deep); }
.crumbs a, .crumbs span { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs > :nth-child(-n+4), .crumbs > :last-child { flex-shrink: 0; }
.crumbs .sep { flex: none; color: var(--line-2); }
.account { margin-left: auto; flex: none; white-space: nowrap; display: flex; gap: 1.25rem; align-items: center; font-size: var(--step--1); color: var(--ink-2); }
.account a { text-decoration: none; font-weight: 700; }
.linklike { background: none; border: 0; padding: 0; color: var(--ink-2); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.linklike:hover { color: var(--primary-deep); }

main { max-width: var(--wrap); margin: 0 auto; padding: 1.5rem 2rem 5rem; }

/* ─────────── Buttons and fields ─────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .55rem 1.25rem; border-radius: 14px;
  border: 0; background: var(--primary); color: #fff;
  font-family: var(--round); font-weight: 800; font-size: 1rem; text-decoration: none; cursor: pointer; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(58, 102, 234, .25), 0 4px 12px rgba(79, 124, 255, .22);
  transition: background-color .15s ease, transform .15s var(--bounce), box-shadow .15s ease;
}
.btn:hover { background: var(--primary-deep); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.secondary { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line); }
.btn.secondary:hover { background: var(--primary-wash); color: var(--primary-deep); }
.btn.pen { background: var(--primary); }
.btn.danger { background: var(--surface); color: var(--wrong); box-shadow: inset 0 0 0 1px #f4c7bd; }
.btn.danger:hover { background: var(--wrong-wash); }
.btn.small { min-height: 34px; padding: .3rem .85rem; font-size: var(--step--1); border-radius: 11px; }
.btn.large { min-height: 56px; padding: .8rem 1.9rem; font-size: 1.2rem; border-radius: 16px; }

label { display: block; font-weight: 700; font-size: var(--step--1); margin-bottom: .35rem; }
.help { font-weight: 400; color: var(--ink-3); font-size: var(--step--1); }
.field { margin-bottom: 1rem; }
input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
  width: 100%; background: var(--surface); border: 1.5px solid var(--line-2); border-radius: var(--r-sm); padding: .65rem .85rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 124, 255, .15); }
textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
textarea.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .85rem; min-height: 260px; }

kbd {
  display: inline-block; min-width: 1.6em; padding: .05em .4em; border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: 6px; background: var(--surface); font: 700 .8em/1.4 var(--sans); color: var(--ink-2); text-align: center;
}

.card { background: var(--surface); border-radius: var(--r-lg); padding: 1.5rem; box-shadow: var(--shadow-sm); }

.tag { display: inline-block; padding: .12rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 700; background: #eef1f7; color: var(--ink-2); }
.tag.right { background: var(--right-wash); color: var(--right); }
.tag.wrong { background: var(--wrong-wash); color: var(--wrong); }
.tag.hint { background: var(--highlight); color: var(--highlight-ink); }
.tag.pen { background: var(--primary-wash); color: var(--primary-deep); }

/* ─────────── Front page ─────────── */
.front { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }
.front-main {
  max-width: var(--wrap); width: 100%; margin: 0 auto; padding: 2rem 2rem 3rem;
  display: grid; grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); gap: 4rem; align-items: center;
}
.front h1 { font-size: clamp(2.6rem, 4.3vw, 3.7rem); max-width: 11em; text-wrap: balance; }
.front .lede { font-size: var(--step-1); color: var(--ink-2); max-width: 32ch; margin: 1.25rem 0 2.25rem; line-height: 1.45; }
.signin { max-width: 360px; padding: 1.5rem; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-md); }
.signin input { font-size: var(--step-1); padding: .7rem .9rem; }
.signin .btn { width: 100%; margin-top: .25rem; }
.front-status { min-height: 1.5rem; margin-top: 1rem; font-size: var(--step--1); color: var(--ink-2); }
.front-status:empty { display: none; }
.front-status .error { color: var(--wrong); }
.front-foot { max-width: var(--wrap); width: 100%; margin: 0 auto; padding: 0 2rem 1.75rem; font-size: var(--step--1); color: var(--ink-3); }

/* The mascot: the martabak logo on a soft circle (sign-in, results and paused screens only) */
.mascot { display: grid; place-items: center; width: 100%; max-width: 340px; aspect-ratio: 1; margin: 0 auto; border-radius: 50%; background: #fff2e2; }
.mascot img { width: 64%; height: auto; display: block; }
.mascot.small { width: 112px; margin: 0; }
@media (prefers-reduced-motion: no-preference) {
  .mascot img { animation: pop .6s var(--bounce) .1s both; }
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ─────────── Choose a unit: 8 pastel tiles ─────────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; margin: 1rem 0 2rem; }
.page-head p { margin: 0; color: var(--ink-2); }

.unit-sheet { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; }
.unit-cell {
  --tint: var(--t1); --tint-ink: var(--t1-ink);
  position: relative; display: flex; flex-direction: column; min-height: 214px; padding: 1.3rem 1.4rem 1.4rem;
  color: var(--ink); text-decoration: none; border-radius: var(--r-lg); background: var(--tint); overflow: hidden;
  transition: transform .15s var(--bounce), box-shadow .15s ease;
}
.unit-cell[data-unit="2"], .unit-head[data-unit="2"] { --tint: var(--t2); --tint-ink: var(--t2-ink); }
.unit-cell[data-unit="3"], .unit-head[data-unit="3"] { --tint: var(--t3); --tint-ink: var(--t3-ink); }
.unit-cell[data-unit="4"], .unit-head[data-unit="4"] { --tint: var(--t4); --tint-ink: var(--t4-ink); }
.unit-cell[data-unit="5"], .unit-head[data-unit="5"] { --tint: var(--t5); --tint-ink: var(--t5-ink); }
.unit-cell[data-unit="6"], .unit-head[data-unit="6"] { --tint: var(--t6); --tint-ink: var(--t6-ink); }
.unit-cell[data-unit="7"], .unit-head[data-unit="7"] { --tint: var(--t7); --tint-ink: var(--t7-ink); }
.unit-cell[data-unit="8"], .unit-head[data-unit="8"] { --tint: var(--t8); --tint-ink: var(--t8-ink); }
.unit-cell:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.unit-cell:active { transform: translateY(-1px) scale(.99); }
.unit-cell:focus-visible { outline-offset: 3px; border-radius: var(--r-lg); }
.unit-num { font-family: var(--round); font-weight: 900; font-size: 4.75rem; line-height: .9; color: var(--tint-ink); font-variant-numeric: tabular-nums; }
.unit-name { margin-top: auto; font-family: var(--round); font-weight: 800; font-size: 1.08rem; line-height: 1.3; }
.unit-progress { margin-top: .3rem; font-size: var(--step--1); color: var(--ink-2); }
.unit-bar { position: absolute; left: 1.4rem; bottom: .8rem; height: 4px; border-radius: 4px; background: var(--tint-ink); max-width: calc(100% - 2.8rem); opacity: .75; }
.unit-cell.final .unit-num { font-size: 4.5rem; }

/* ─────────── One unit: its practice tests ─────────── */
.unit-head {
  --tint: var(--t1); --tint-ink: var(--t1-ink);
  display: grid; grid-template-columns: auto 1fr; gap: 1.75rem; align-items: center;
  margin: 1rem 0 2rem; padding: 1.75rem 2rem; border-radius: var(--r-lg); background: var(--tint);
}
.unit-head .unit-num { font-size: 6rem; }
.unit-head h1 { font-size: var(--step-3); }
.unit-head p { margin: .5rem 0 0; color: var(--ink-2); max-width: 60ch; }

.test-list { display: grid; gap: .7rem; }
.test-row {
  display: grid; grid-template-columns: 2.6rem minmax(0, 1fr) 11rem 9rem 8.5rem; gap: 1.25rem; align-items: center;
  padding: 1.15rem 1.4rem; border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm);
}
/* handed in: green with a tick; every answer right: gold with a star */
.test-row.done { background: #e9f8f0; box-shadow: inset 0 0 0 1.5px #c3ebd6; }
.test-row.perfect { background: #fff6d6; box-shadow: inset 0 0 0 1.5px #f3dc8c; }
.medal { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--line-2); }
.medal svg { width: 1.45rem; height: 1.45rem; }
.medal path { fill: none; stroke: #fff; stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; }
.test-row.done .medal { background: var(--right); box-shadow: none; }
.test-row.perfect .medal { background: #e3a008; box-shadow: 0 2px 8px rgba(227, 160, 8, .35); }
.test-row.perfect .medal path { fill: #fff; stroke-width: 1.2; }
.test-row h3 { font-size: 1.15rem; }
.test-row .desc { margin: .2rem 0 0; color: var(--ink-2); font-size: var(--step--1); }
.test-row .facts { color: var(--ink-2); font-size: var(--step--1); line-height: 1.4; }
.test-row .score { font-family: var(--round); font-weight: 900; font-size: var(--step-2); line-height: 1; }
.test-row .action { text-align: right; }
.empty { padding: 3rem 0; color: var(--ink-2); max-width: 46ch; }

/* ─────────── Taking a test ─────────── */
.test-shell { max-width: 820px; margin: 0 auto; }
.test-top {
  display: flex; align-items: center; justify-content: space-between; gap: 1.5rem;
  padding-bottom: 1rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line);
}
.test-top h1 { font-size: 1.6rem; }
.timer {
  font-family: var(--round); font-variant-numeric: tabular-nums; font-weight: 900; font-size: var(--step-2); letter-spacing: .01em;
  color: var(--ink); min-width: 5.5ch; text-align: right;
}
.timer.over { color: var(--amber); }
.over-banner {
  margin: -.25rem 0 1.25rem; padding: .8rem 1.1rem; border-radius: var(--r);
  background: var(--highlight); color: var(--highlight-ink); font-size: var(--step--1);
}
.over-banner .linklike { color: var(--highlight-ink); font-weight: 700; }
.timer-label { font-size: var(--step--1); color: var(--ink-3); text-align: right; }

.q-nav { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 2rem; }
.q-nav button {
  width: 36px; height: 36px; border-radius: 11px; border: 0; background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--line);
  font-family: var(--round); font-weight: 800; font-size: var(--step--1); color: var(--ink-3); cursor: pointer;
  transition: transform .15s var(--bounce), background-color .15s ease;
}
.q-nav button:hover { transform: translateY(-2px); }
.q-nav button.answered { background: var(--primary); box-shadow: none; color: #fff; }
.q-nav button.current { outline: 3px solid rgba(79, 124, 255, .4); outline-offset: 2px; }

.q-count { color: var(--ink-3); font-size: var(--step--1); display: flex; justify-content: space-between; }
.prompt { font-size: 1.5rem; line-height: 1.45; margin: .5rem 0 1.75rem; white-space: pre-wrap; max-width: 34em; }
.options { display: grid; gap: .6rem; }
.option {
  display: grid; grid-template-columns: 2.1rem 1fr; gap: .9rem; align-items: center;
  padding: .9rem 1.1rem; border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow-sm), inset 0 0 0 1.5px var(--line);
  font-size: var(--step-1); font-weight: 400; cursor: pointer; margin: 0;
  transition: box-shadow .15s ease, background-color .15s ease, transform .15s var(--bounce);
}
.option:hover { box-shadow: var(--shadow-md), inset 0 0 0 1.5px var(--line-2); transform: translateY(-1px); }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option .key {
  display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: 10px; background: #f1f4fa;
  font-family: var(--round); font-size: var(--step--1); font-weight: 800; color: var(--ink-2);
}
.option.chosen { background: var(--primary-wash); box-shadow: inset 0 0 0 2px var(--primary); }
.option.chosen .key { background: var(--primary); color: #fff; }
.option:has(input:focus-visible) { outline: 3px solid rgba(79, 124, 255, .45); outline-offset: 2px; }
.short-answer { font-size: var(--step-1) !important; padding: .8rem 1rem !important; max-width: 420px; }

.hints { margin-top: 2rem; }
.hint { margin: .6rem 0 0; font-size: var(--step-0); line-height: 1.6; }
.hint mark { background: linear-gradient(transparent 12%, var(--highlight) 12%, var(--highlight) 88%, transparent 88%); color: var(--ink); padding: 0 .15em; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.hint b { color: var(--highlight-ink); margin-right: .35rem; }
.hint-btn {
  margin-top: .9rem; background: #fffbe6; border: 0; box-shadow: inset 0 0 0 1.5px #f1df8a; color: var(--highlight-ink); border-radius: 999px;
  padding: .45rem 1rem; font-family: var(--round); font-weight: 800; font-size: var(--step--1); cursor: pointer;
  transition: background-color .15s ease, transform .15s var(--bounce);
}
.hint-btn:hover { background: var(--highlight); transform: translateY(-1px); }

.test-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line);
}
.keys-help { font-size: var(--step--1); color: var(--ink-3); display: flex; gap: 1.1rem; flex-wrap: wrap; }

.intro { max-width: 640px; }
.intro h1 { font-size: var(--step-3); margin: .5rem 0 1rem; }
.intro dl { display: grid; grid-template-columns: 9rem 1fr; gap: .7rem 1rem; margin: 1.75rem 0 2rem; padding: 1.4rem 1.5rem; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.intro dt { color: var(--ink-3); }
.intro dd { margin: 0; }
.intro .ready { font-family: var(--round); font-weight: 800; color: var(--primary-deep); margin: 0 0 .9rem; }

.overlay { position: fixed; inset: 0; background: rgba(30, 39, 66, .3); display: grid; place-items: center; z-index: 50; }
.overlay .card { max-width: 380px; text-align: center; }
.problems { background: var(--wrong-wash); color: var(--wrong); border-radius: var(--r-sm); padding: .75rem 1rem .75rem 2rem; margin: 0 0 1rem; }

/* ─────────── Results ─────────── */
.result-head {
  display: grid; grid-template-columns: auto auto 1fr; gap: 2rem; align-items: center;
  padding: 1.75rem 2rem; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.big-score { font-family: var(--round); font-weight: 900; font-size: 6.5rem; line-height: .85; letter-spacing: -0.03em; }
.big-score small { font-size: .4em; color: var(--ink-3); margin-left: .08em; }
.result-head h1 { font-size: var(--step-2); margin-bottom: .35rem; }
.cheer { font-family: var(--round); font-weight: 800; color: var(--primary-deep); margin: 0 0 .35rem; }
.result-facts { display: flex; gap: .5rem 1.5rem; flex-wrap: wrap; color: var(--ink-2); font-size: var(--step--1); margin-top: .5rem; }
.review { margin-top: 1.5rem; }
.review-item { display: grid; grid-template-columns: 3rem 1fr; gap: 1rem; padding: 1.5rem 0; border-bottom: 1px solid var(--line); }
.review-mark { padding-top: .15rem; }
.review-mark svg { width: 34px; height: 34px; display: block; }
.review-mark circle { opacity: .14; }
.review-mark.right { color: var(--right); }
.review-mark.wrong { color: var(--wrong); }
.review-mark path { fill: none; stroke: currentColor; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
@media (prefers-reduced-motion: no-preference) {
  .review-mark.right path { stroke-dasharray: 30; stroke-dashoffset: 30; animation: draw .45s ease-out forwards; animation-delay: calc(.25s + var(--i, 0) * .08s); }
}
.review-item .prompt { font-size: var(--step-1); margin: 0 0 .9rem; }
.answer-line { display: grid; grid-template-columns: 9rem 1fr; gap: .75rem; margin-top: .3rem; }
.answer-line .k { color: var(--ink-3); font-size: var(--step--1); padding-top: .15rem; }
.answer-line .correct { color: var(--right); font-weight: 700; }
.explain { margin-top: .9rem; padding: .8rem 1rem; border-radius: var(--r-sm); background: var(--primary-wash); color: var(--ink-2); white-space: pre-wrap; }
.review-item .pts { color: var(--ink-3); font-size: var(--step--1); float: right; margin-left: 1rem; }

/* Confetti when a test is handed in (skipped for reduced motion) */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; overflow: hidden; }
.confetti i {
  position: absolute; top: -16px; width: 10px; height: 14px; border-radius: 3px;
  animation: fall var(--t, .9s) cubic-bezier(.25, .6, .4, 1) var(--d, 0s) forwards;
}
.confetti i.round { border-radius: 50%; width: 11px; height: 11px; }
@keyframes fall {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--x, 0), 70vh) rotate(var(--r, 300deg)); opacity: 0; }
}

/* ─────────── Tutor tools ─────────── */
.tabs { display: inline-flex; gap: .25rem; margin: 1rem 0 1.5rem; padding: .3rem; background: #eef1f8; border-radius: 14px; }
.tabs button {
  background: none; border: none; font-family: var(--round); font-weight: 800; color: var(--ink-2); padding: .5rem 1rem; cursor: pointer; border-radius: 11px;
}
.tabs button.active { color: var(--ink); background: var(--surface); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .65rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--ink-3); font-weight: 700; font-size: var(--step--1); }
.table-wrap { overflow-x: auto; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

.q-edit .q-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .9rem; }
.q-edit .q-head h3 { margin-right: auto; }
.q-edit select, .q-edit .points { width: auto; }
.q-edit .points { width: 5.5rem; }
.opt-row { display: flex; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.opt-row input[type=radio] { width: 20px; height: 20px; accent-color: var(--right); flex: none; }
.opt-row .letter { font-weight: 700; color: var(--ink-3); width: 1.2rem; }
.preview .hint { margin-top: .3rem; }
.sticky-save {
  position: sticky; bottom: 0; background: rgba(251, 252, 255, .94); backdrop-filter: blur(6px);
  padding: .85rem 0; margin-top: 1.5rem; display: flex; gap: .75rem; justify-content: flex-end; border-top: 1px solid var(--line);
}
.pending {
  margin: 0 0 1.25rem; padding: 1rem 1.25rem; border-radius: var(--r);
  background: var(--primary-wash); font-size: var(--step--1);
}

/* ─────────── Toast and "Are you sure?" ─────────── */
.toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translate(-50%, 12px); opacity: 0;
  background: var(--ink); color: #fff; padding: .75rem 1.2rem; border-radius: 14px; z-index: 60;
  transition: opacity .2s ease, transform .2s var(--bounce); max-width: 90vw; font-size: var(--step--1); box-shadow: var(--shadow-md);
}
.toast.bad { background: var(--wrong); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

dialog.confirm {
  border: 0; border-radius: var(--r-lg); padding: 1.6rem; max-width: 420px; width: calc(100% - 2rem);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(30, 39, 66, .25);
}
dialog.confirm::backdrop { background: rgba(30, 39, 66, .3); }
dialog.confirm p { font-size: var(--step-0); margin: 0 0 1.25rem; }

/* ─────────── Inside questions: maths, tables, graphs ─────────── */
.prompt .katex, .hint .katex { font-size: 1.12em; }
.option .katex { font-size: 1.3em; }
.prompt-text { display: block; }
.q-table { width: auto; border-collapse: separate; border-spacing: 0; margin: .75rem 0; font-size: var(--step-0); white-space: normal; border-radius: var(--r-sm); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line-2); }
.q-table th, .q-table td { border: 0; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); padding: .45rem .95rem; text-align: center; font-variant-numeric: tabular-nums; }
.q-table tr > :last-child { border-right: 0; }
.q-table tr:last-child > * { border-bottom: 0; }
.q-table th { background: #f2f5fb; color: var(--ink); font-size: var(--step--1); font-weight: 700; text-align: left; }

.q-graph { display: block; width: min(100%, 420px); height: auto; margin: .25rem 0 1.5rem; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line); }
.q-graph .g-grid { stroke: #edf0f6; stroke-width: 1; }
.q-graph .g-axis { stroke: var(--ink-3); stroke-width: 1.5; }
.q-graph .g-tick { fill: var(--ink-3); font: 11px var(--sans); }
.q-graph .g-curve { fill: none; stroke: var(--primary); stroke-width: 2.75; stroke-linejoin: round; stroke-linecap: round; }
.q-graph .g-arrow { fill: var(--primary); }
.q-graph .g-dot { fill: var(--primary); }
.q-graph .g-dot-open { fill: var(--surface); stroke: var(--primary); stroke-width: 2.25; }
.q-graph .g-label { fill: var(--ink); font: 600 12px var(--sans); }
.q-graph .g-region { fill: var(--primary); fill-opacity: .14; }
.q-graph .g-curve.dashed { stroke-dasharray: 9 7; stroke-linecap: butt; }
.q-graph .g-title { fill: var(--ink-2); font: 600 11px var(--sans); }
.q-graph .g-curve.alt { stroke: var(--ink); stroke-dasharray: 7 5; }
.q-graph .g-arrow.alt { fill: var(--ink); }
.q-graph .g-tick, .q-graph .g-label { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }

/* ─────────── Elo and the leaderboard ─────────── */
.board { list-style: none; margin: 0; padding: .35rem; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.board-row {
  position: relative; display: grid; grid-template-columns: 4rem 1fr auto auto; align-items: center; gap: 1.25rem;
  padding: 1rem 1.25rem 1.15rem; border-radius: var(--r);
}
.board-row + .board-row { margin-top: .2rem; }
.board-row.me { background: #fff8d9; }
.board-rank {
  display: grid; place-items: center; width: 3rem; height: 3rem; border-radius: 50%; background: #f1f4fa;
  font-family: var(--round); font-weight: 900; font-size: 1.45rem; color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.board-row.lead .board-rank { background: var(--primary); color: #fff; }
.board-who { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.board-name { font-family: var(--round); font-weight: 800; font-size: var(--step-1); }
.board-you { margin-left: .6rem; padding: .08rem .55rem; border-radius: 999px; background: var(--highlight); color: var(--highlight-ink); font-family: var(--sans); font-weight: 700; font-size: .78rem; vertical-align: .2em; }
.board-facts { font-size: var(--step--1); color: var(--ink-3); }
.board-elo { font-family: var(--round); font-weight: 900; font-size: 2.2rem; line-height: 1; font-variant-numeric: tabular-nums; text-align: right; }
.board-elo small { font-family: var(--sans); font-weight: 400; font-size: var(--step--1); color: var(--ink-3); margin-left: .35rem; }
.board-reset { font-size: var(--step--1); }
.board-bar { position: absolute; left: 6.5rem; bottom: .45rem; height: 4px; border-radius: 4px; background: #e8ecf5; max-width: calc(100% - 8rem); }
.board-row.lead .board-bar { background: var(--primary); opacity: .7; }

.elo-rules { margin-top: 2.5rem; max-width: 760px; }
.elo-rules h2 { margin-bottom: 1rem; }
.elo-rules dl { display: grid; grid-template-columns: 11rem 1fr; gap: .6rem 1.5rem; margin: 0; }
.elo-rules dt { font-family: var(--round); font-weight: 800; font-size: 1.1rem; line-height: 1.4; color: var(--primary-deep); }
.elo-rules dd { margin: 0; color: var(--ink-2); padding-top: .1rem; }

.elo-line { margin: .9rem 0 0; font-size: var(--step--1); color: var(--ink-2); max-width: 62ch; }
.elo-gain { color: var(--right); font-family: var(--round); font-weight: 900; font-size: 1.05rem; }
.tag.late { background: var(--highlight); color: var(--highlight-ink); margin-left: .5rem; vertical-align: .1em; }
.unit-elo { margin: -1.25rem 0 1.5rem; color: var(--ink-2); }
.unit-elo:empty { display: none; }
.unit-elo b { font-family: var(--round); font-weight: 900; font-size: var(--step-1); color: var(--ink); }

/* ─────────── Smaller screens (built for a laptop, works on a phone) ─────────── */
@media (max-width: 900px) {
  .front-main { grid-template-columns: 1fr; gap: 2rem; }
  .front-main .mascot { max-width: 220px; margin: 0; }
  .unit-sheet { grid-template-columns: repeat(2, 1fr); }
  .unit-cell { min-height: 170px; }
  .test-row { grid-template-columns: 2.6rem 1fr auto auto; }
  .test-row .facts { display: none; }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .result-head { grid-template-columns: auto 1fr; }
  .result-head .mascot { display: none; }
}
@media (max-width: 560px) {
  #site-header, main, .front-main, .front-foot { padding-left: 1.1rem; padding-right: 1.1rem; }
  .crumbs, .account .who { display: none; }
  .unit-sheet { gap: .75rem; }
  .page-head { flex-direction: column; align-items: flex-start; gap: .5rem; }
  h1.display { font-size: 2.6rem; }
  .unit-num { font-size: 3.5rem; }
  .unit-head { grid-template-columns: 1fr; padding: 1.25rem; gap: .5rem; }
  .unit-head .unit-num { font-size: 4rem; }
  .big-score { font-size: 4.5rem; }
  .result-head { grid-template-columns: 1fr; gap: 1rem; padding: 1.25rem; }
  .answer-line { grid-template-columns: 1fr; gap: 0; }
  .keys-help { display: none; }
  .test-row { grid-template-columns: 2.2rem 1fr; gap: .75rem 1rem; padding: 1rem; }
  .test-row > :nth-child(4), .test-row > .action { grid-column: 2; text-align: left; }
  .medal { width: 2.2rem; height: 2.2rem; }
  .board-row { grid-template-columns: 2.75rem 1fr auto; padding: .9rem 1rem 1rem; }
  .board-rank { width: 2.4rem; height: 2.4rem; font-size: 1.15rem; }
  .board-elo { font-size: var(--step-2); }
  .board-reset { grid-column: 2; justify-self: start; }
  .board-bar { left: 1rem; max-width: calc(100% - 2rem); }
  .elo-rules dl { grid-template-columns: 1fr; }
  .elo-rules dd { padding: 0 0 .5rem; }
  body { background-size: 150px auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .unit-cell:hover, .btn:hover, .option:hover { transform: none; }
}

/* ─────────── Home ─────────── */
.home-head { margin: 1rem 0 2rem; }
.home-head h1 { margin-bottom: .4rem; }
.home-elo { margin: 0; color: var(--ink-2); font-size: var(--step-1); min-height: 1.6em; }
.home-elo b { font-family: var(--round); font-weight: 900; color: var(--ink); }
.home-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); grid-template-rows: auto auto; gap: 1.1rem 1.25rem; align-items: stretch; }
.home-courses { grid-row: span 2; display: flex; flex-direction: column; gap: .9rem; }
.home-label { font-size: 1.05rem; color: var(--ink-2); margin: 0; }

.course-card {
  flex: 1; display: flex; flex-direction: column; gap: .35rem; min-height: 230px; padding: 1.75rem 2rem 1.7rem;
  border-radius: var(--r-lg); background: var(--primary-wash); color: var(--ink); text-decoration: none; position: relative; overflow: hidden;
  transition: transform .15s var(--bounce), box-shadow .15s ease;
}
.course-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
/* Math 1 gets a soft warm tint so the two courses are easy to tell apart */
.course-card[data-course="math-1"] { background: #fff1e0; }
.course-card[data-course="math-1"] .course-bar { background: rgba(255, 154, 46, .2); }
.course-card[data-course="math-1"] .course-bar span { background: #f08a24; }
.course-name { font-family: var(--round); font-weight: 900; font-size: var(--step-3); line-height: 1.05; letter-spacing: -0.02em; }
.course-about { color: var(--ink-2); }
.unit-chips { display: flex; gap: .45rem; flex-wrap: wrap; margin: auto 0 .9rem; padding-top: 1.25rem; position: relative; z-index: 1; }
.unit-chip {
  --tint: var(--t1); --tint-ink: var(--t1-ink);
  display: grid; place-items: center; width: 2.35rem; height: 2.35rem; border-radius: 11px;
  font-family: var(--round); font-weight: 900; font-size: 1.05rem; background: var(--tint); color: var(--tint-ink);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .6);
}
.unit-chip[data-unit="2"] { --tint: var(--t2); --tint-ink: var(--t2-ink); }
.unit-chip[data-unit="3"] { --tint: var(--t3); --tint-ink: var(--t3-ink); }
.unit-chip[data-unit="4"] { --tint: var(--t4); --tint-ink: var(--t4-ink); }
.unit-chip[data-unit="5"] { --tint: var(--t5); --tint-ink: var(--t5-ink); }
.unit-chip[data-unit="6"] { --tint: var(--t6); --tint-ink: var(--t6-ink); }
.unit-chip[data-unit="7"] { --tint: var(--t7); --tint-ink: var(--t7-ink); }
.unit-chip[data-unit="8"] { --tint: #fff; --tint-ink: var(--t8-ink); }
.unit-chip.no-tests { opacity: .45; }
.unit-chip.all { background: var(--tint-ink); color: #fff; }
.course-progress { font-size: var(--step--1); color: var(--ink-2); position: relative; z-index: 1; }
.course-bar { display: block; height: 6px; border-radius: 6px; background: rgba(79, 124, 255, .15); margin-top: .5rem; max-width: 360px; position: relative; z-index: 1; overflow: hidden; }
.course-bar span { display: block; height: 100%; border-radius: 6px; background: var(--primary); }

.home-tile {
  display: flex; flex-direction: column; gap: .6rem; padding: 1.4rem 1.5rem; border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--shadow-sm); color: var(--ink); text-decoration: none;
  transition: transform .15s var(--bounce), box-shadow .15s ease;
}
.home-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.home-tile h2 { font-size: 1.45rem; }
.home-courses + .home-tile { margin-top: calc(1.05rem * 1.55 + .9rem); }
.tile-more { margin-top: auto; padding-top: .4rem; font-weight: 700; font-size: var(--step--1); color: var(--primary-deep); }
.mini-board { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.mini-board li { counter-increment: rank; display: grid; grid-template-columns: 1.6rem 1fr auto; align-items: center; gap: .5rem; padding: .35rem .5rem; border-radius: 10px; }
.mini-board li::before { content: counter(rank); font-family: var(--round); font-weight: 900; color: var(--ink-3); }
.mini-board li.me { background: #fff8d9; }
.mini-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-elo { font-family: var(--round); font-weight: 900; font-variant-numeric: tabular-nums; }
.note-date { display: inline-block; padding: .12rem .6rem; border-radius: 999px; background: var(--primary-wash); color: var(--primary-deep); font-size: .8rem; font-weight: 700; }
.note-title { font-family: var(--round); font-weight: 800; font-size: 1.05rem; margin: .45rem 0 .25rem; }

/* ─────────── Patch notes ─────────── */
.notes { list-style: none; margin: 0; padding: 0; max-width: 760px; }
.note { display: grid; grid-template-columns: 8.5rem 1fr; gap: 1.25rem; padding: 1.4rem 0; border-bottom: 1px solid var(--line); }
.note:last-child { border-bottom: 0; }
.note .note-date { justify-self: start; align-self: start; margin-top: .2rem; }
.note h2 { font-size: 1.35rem; margin-bottom: .4rem; }
.note ul { margin: 0; padding-left: 1.15rem; color: var(--ink-2); }
.note ul li + li { margin-top: .25rem; }

@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; }
  .home-courses { grid-row: auto; }
  .home-courses + .home-tile { margin-top: 0; }
  .course-card { min-height: 260px; }
}
@media (max-width: 560px) {
  .course-card { padding: 1.5rem; }
  .course-name { font-size: 2rem; }
  .note { grid-template-columns: 1fr; gap: .5rem; }
}

/* ─────────── Pause ─────────── */
.timer-box { display: flex; align-items: center; gap: 1rem; }
.pause-btn { gap: .45rem; }
.pause-icon { width: 10px; height: 12px; border-left: 3.5px solid currentColor; border-right: 3.5px solid currentColor; border-radius: 1px; }
.test-shell.is-paused { filter: blur(10px); pointer-events: none; user-select: none; }
.paused-screen {
  position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 1.5rem;
  background: rgba(251, 252, 255, .86); backdrop-filter: blur(6px);
}
.paused-card { max-width: 460px; text-align: center; padding: 2.25rem 2rem 2rem; background: var(--surface); border-radius: 24px; box-shadow: var(--shadow-md); }
.paused-card .mascot { margin: 0 auto .75rem; width: 96px; }
.paused-card h2 { font-size: var(--step-3); margin-bottom: .5rem; }
.paused-card .row { justify-content: center; margin-top: 1.25rem; }
.paused-card b { font-family: var(--round); font-weight: 900; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ─────────── Congratulations (straight after handing in) ─────────── */
.congrats { max-width: 860px; margin: 0 auto; text-align: center; padding: 1rem 0 2rem; }
.congrats .mascot { width: 150px; margin: 0 auto 1rem; }
.congrats .cheer { margin: 0 0 .25rem; }
.congrats h1 { font-size: clamp(2.4rem, 4.5vw, 3.4rem); }
.congrats-test { margin: .5rem 0 2.25rem; }
.congrats-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; text-align: left; }
.stat {
  display: flex; flex-direction: column; gap: .2rem; padding: 1.35rem 1.5rem 1.4rem;
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.stat.elo { background: var(--right-wash); box-shadow: none; }
.stat-label { font-family: var(--round); font-weight: 800; color: var(--ink-2); font-size: .95rem; }
.stat-value { font-family: var(--round); font-weight: 900; font-size: 3rem; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-value small { font-size: .45em; color: var(--ink-3); font-weight: 800; letter-spacing: 0; }
.stat.elo .stat-value { color: var(--right); }
.stat-note { font-size: var(--step--1); color: var(--ink-2); line-height: 1.4; }
.stat-note.over, .stat-note .over { color: var(--amber); }
.congrats-actions { justify-content: center; margin-top: 2.25rem; }
@media (max-width: 760px) {
  .congrats-stats { grid-template-columns: 1fr; }
  .congrats .mascot { width: 110px; }
}

/* Tutor tools → Logins: the row being edited */
table.logins tr.editing td { vertical-align: top; background: var(--primary-wash); }
table.logins tr.editing input[type="text"], table.logins tr.editing select { width: 100%; max-width: 15rem; }
