/* ============================================================================
   Components: off by heart
   ----------------------------------------------------------------------------
   Reads tokens.css and type.css and defines nothing of its own. If you find a
   raw hex value, a font stack or a pixel size below, it is a bug: it belongs in
   one of those two files where it can be changed once.
   ============================================================================ */

* { box-sizing: border-box; }

/* Several rules below set `display`, which beats the browser's own
   `[hidden] { display: none }` because an author rule always wins over the user
   agent stylesheet. Without this, hiding something with `hidden` does nothing. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior-y: none;
}

button, input, textarea, select { font: inherit; color: inherit; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 20;
  background: var(--action); color: var(--action-ink);
  padding: var(--space-3) var(--space-4);
  border-radius: 0 0 var(--radius-sm) 0;
  font-weight: var(--weight-semi);
}
.skip:focus { left: 0; }

:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 2px;
  border-radius: var(--space-1);
}

/* ---------------------------------------------------------------- app bar */

.bar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  min-height: var(--bar-height);
  padding: max(env(safe-area-inset-top), var(--space-1)) var(--space-2) var(--space-1);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.bar-back { grid-column: 1; }
.bar-title { grid-column: 2; }
.bar-menu { grid-column: 3; }

/* Columns are pinned above so that hiding the back button, which removes it
   from the grid, does not slide the title into its place. */
.bar-title {
  text-align: center;
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  font-size: var(--text-md);
  letter-spacing: var(--tracking-tight);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* The wordmark in the bar is sized by height, so it sits on the same optical
   line as a text title on the screens that use one. */
.bar .wordmark, .bar .wordmark-themed {
  display: block; height: 19px; width: auto; margin: 0 auto;
}

.bar button {
  width: var(--tap); height: var(--tap);
  border: 0; background: none; cursor: pointer;
  border-radius: var(--radius-pill);
  display: grid; place-items: center; color: var(--ink);
}
.bar button:active { background: var(--surface-sunk); }

.bar-back::before, .bar-menu::before {
  content: ''; width: 11px; height: 11px;
  border-left: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg); margin-left: 4px;
}
.bar-menu::before {
  width: 18px; height: 14px; margin: 0; transform: none; border: 0;
  border-top: 2px solid currentColor; border-bottom: 2px solid currentColor;
  background: linear-gradient(currentColor, currentColor) 0 50% / 100% 2px no-repeat;
}

/* ---------------------------------------------------------------- layout */

main { display: block; }
main:focus { outline: none; }

.wrap {
  max-width: var(--width-page);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) calc(var(--space-8) + env(safe-area-inset-bottom));
}
.wrap.narrow { max-width: var(--width-read); }

.stack > * + * { margin-top: var(--space-3); }
.stack-lg > * + * { margin-top: var(--space-6); }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-3); margin-bottom: var(--space-3);
}
.section-head h2 {
  font-family: var(--font-body);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semi);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ink-faint);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}
.pad-lg { padding: var(--space-6); }

.empty {
  text-align: center; padding: var(--space-8) var(--space-5); color: var(--ink-faint);
}

.spinner { display: grid; place-items: center; padding: var(--space-8) 0; color: var(--ink-faint); }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding: 0 var(--space-5);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--action); color: var(--action-ink);
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  cursor: pointer; text-decoration: none;
  transition: background var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--action-hover); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: var(--action); }
.btn.block { display: flex; width: 100%; }
.btn.quiet {
  background: var(--surface); color: var(--ink); border-color: var(--line-strong);
}
.btn.quiet:hover { background: var(--surface-sunk); }
.btn.plain {
  background: none; color: var(--accent); border-color: transparent;
  min-height: 40px; padding: 0 var(--space-1);
  font-family: var(--font-body); font-weight: var(--weight-semi);
}
.btn.plain:hover { background: none; text-decoration: underline; }
.btn.danger { background: none; color: var(--wrong); border-color: var(--line-strong); }
.btn.danger:hover { background: var(--wrong-soft); }
.btn.small {
  min-height: 38px; padding: 0 var(--space-3); font-size: var(--text-md);
}

.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-3); }

/* ---------------------------------------------------------------- forms */

label.field { display: block; }
label.field > span {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  color: var(--ink-soft);
  margin-bottom: var(--space-2);
}

input[type="text"], input[type="password"], textarea, select {
  width: 100%; min-height: var(--tap);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  -webkit-appearance: none; appearance: none;
}
textarea { min-height: 96px; resize: vertical; line-height: var(--leading-body); }
input:focus, textarea:focus, select:focus {
  border-color: var(--action); outline: none; box-shadow: var(--focus);
}

.notice {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--wrong-soft); color: var(--wrong);
  font-size: var(--text-md);
}
.notice.good { background: var(--right-soft); color: var(--right); }

/* ---------------------------------------------------------------- sign in */

/* Always dark, as the brand board draws it. The container paints its own
   background rather than relying on body, because the dark tokens are scoped to
   this element and body's colour comes from :root. */
.signin {
  min-height: 100dvh; display: grid; place-items: center; padding: var(--space-6);
  background: var(--bg); color: var(--ink);
}
.signin-inner { width: 100%; max-width: 23rem; }
.signin header { text-align: center; margin-bottom: var(--space-7); }
/* Sized against the form beneath it rather than the viewport, so the lockup and
   the fields read as one column. */
.signin .wordmark { width: min(78%, 17rem); margin: 0 auto; }
.signin .tagline {
  margin-top: var(--space-5);
  font-size: var(--text-lg);
  color: var(--ink-soft);
  line-height: var(--leading-snug);
  text-wrap: balance;
}

.phrase-input {
  text-align: center; letter-spacing: 0.04em;
  font-family: var(--font-display); font-weight: var(--weight-medium);
}

/* ---------------------------------------------------------------- subjects */

.subjects { display: grid; gap: var(--space-3); }

.subject {
  display: flex; align-items: center; gap: var(--space-4);
  width: 100%; text-align: left; cursor: pointer; color: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: var(--space-4);
  transition: border-color var(--dur-fast) var(--ease);
}
.subject:hover { border-color: var(--line-strong); }
.subject:active { background: var(--surface-sunk); }

/* The supplied subject badge. It brings its own colours and its own corner
   radius, so this only sizes it. */
.badge { display: block; flex: none; width: 46px; height: 46px; }
.badge svg { display: block; width: 100%; height: 100%; }

.subject .grow { flex: 1; min-width: 0; }
.subject .name {
  font-family: var(--font-display); font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
}
.subject .meta { font-size: var(--text-sm); color: var(--ink-faint); }
.chev { color: var(--ink-faint); display: grid; place-items: center; }

/* ---------------------------------------------------------------- topics */

.topics { display: grid; gap: var(--space-2); }

.topic {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center;
  gap: var(--space-4);
  width: 100%; text-align: left; cursor: pointer; color: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
}
.topic:active { background: var(--surface-sunk); }
.topic[disabled] { cursor: default; opacity: 0.5; }
.topic .code {
  display: grid; place-items: center; width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--tint) 16%, transparent);
  color: var(--tint);
  font-family: var(--font-display); font-weight: var(--weight-bold);
  font-size: var(--text-md);
}
.topic .name { font-weight: var(--weight-medium); }
.topic .meta { font-size: var(--text-xs); color: var(--ink-faint); }

.ring { width: 34px; height: 34px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 4; }
.ring .track { stroke: var(--line); }
.ring .fill {
  stroke: var(--tint); stroke-linecap: round;
  transition: stroke-dashoffset var(--dur-slow) var(--ease);
}

/* ---------------------------------------------------------------- topic home */

.hero .code {
  display: inline-block; padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--tint) 16%, transparent);
  color: var(--tint);
  font-family: var(--font-display); font-weight: var(--weight-bold);
  font-size: var(--text-xs); letter-spacing: 0.04em;
}
.hero h1 { margin-top: var(--space-3); }

.tiles { display: grid; gap: var(--space-2); grid-template-columns: 1fr 1fr; }
.tile {
  display: block; text-align: left; cursor: pointer; color: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: var(--space-4);
}
.tile:active { background: var(--surface-sunk); }
.tile:disabled { opacity: 0.5; cursor: default; }
.tile .big {
  font-family: var(--font-display); font-size: var(--text-2xl);
  font-weight: var(--weight-bold); letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
}
.tile .label { font-size: var(--text-md); color: var(--ink-soft); font-weight: var(--weight-medium); }
.tile .meta { font-size: var(--text-xs); color: var(--ink-faint); margin-top: 2px; }

.episode-row {
  display: grid; grid-template-columns: 30px 1fr auto; align-items: center;
  gap: var(--space-3);
  width: 100%; text-align: left; cursor: pointer; color: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
}
.episode-row:active { background: var(--surface-sunk); }
.episode-row .n {
  display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: var(--radius-pill); border: 1.5px solid var(--line-strong);
  font-family: var(--font-display); font-size: var(--text-sm);
  font-weight: var(--weight-bold); color: var(--ink-soft);
}
.episode-row.done .n {
  background: var(--action); border-color: var(--action); color: var(--action-ink);
}
.episode-row .title { font-weight: var(--weight-medium); }
.episode-row .meta { font-size: var(--text-xs); color: var(--ink-faint); }

/* ---------------------------------------------------------------- episode */

.steps { display: flex; gap: var(--space-1); margin-bottom: var(--space-5); }
.steps span { height: 4px; flex: 1; border-radius: var(--radius-pill); background: var(--line); }
.steps span.on { background: var(--action); }

.intention {
  display: flex; gap: var(--space-4); align-items: flex-start;
  background: var(--accent-soft); border-radius: var(--radius-md);
  padding: var(--space-5);
  font-size: var(--text-lg); font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  color: var(--ink);
}
.icon { flex: none; width: 26px; height: 26px; color: var(--accent); }

.numbered { margin: 0; padding-left: 1.3em; }
.numbered li { margin-bottom: var(--space-3); }

/* Answer-then-reveal blocks. */
.reveal {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: var(--space-4); background: var(--surface);
}
.reveal + .reveal { margin-top: var(--space-2); }
.reveal .q { font-weight: var(--weight-medium); }
.reveal .a {
  margin-top: var(--space-3); padding-top: var(--space-3);
  border-top: 1px dashed var(--line-strong);
  color: var(--right); font-weight: var(--weight-medium);
}

/* ---------------------------------------------------------------- flashcards */

.deck { display: grid; gap: var(--space-4); }
.flash {
  min-height: 46dvh; display: grid; align-content: center; gap: var(--space-5);
  text-align: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: var(--space-6);
}
.flash .q {
  font-family: var(--font-display); font-size: var(--text-xl);
  font-weight: var(--weight-bold); line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
}
.flash .a { font-size: var(--text-base); color: var(--right); font-weight: var(--weight-medium); }
.flash .n {
  font-size: var(--text-2xs); color: var(--ink-faint);
  letter-spacing: var(--tracking-wide); text-transform: uppercase;
  font-weight: var(--weight-semi);
}

.progress-line {
  height: 4px; border-radius: var(--radius-pill);
  background: var(--line); overflow: hidden;
}
.progress-line i {
  display: block; height: 100%; background: var(--action);
  transition: width var(--dur) var(--ease);
}

/* ---------------------------------------------------------------- questions */

.q-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: var(--space-5);
}
.q-card + .q-card { margin-top: var(--space-4); }
.q-head {
  display: flex; justify-content: space-between; gap: var(--space-4);
  align-items: baseline; margin-bottom: var(--space-3);
}
.q-num {
  font-size: var(--text-2xs); font-weight: var(--weight-semi);
  color: var(--ink-faint); letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}
.q-marks { font-size: var(--text-xs); color: var(--ink-faint); white-space: nowrap; }
.q-stem { font-weight: var(--weight-medium); margin-bottom: var(--space-4); }

.choices { display: grid; gap: var(--space-2); }
.choice {
  display: flex; align-items: center; gap: var(--space-3); cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4); background: var(--surface);
}
.choice input { width: 22px; height: 22px; flex: none; accent-color: var(--action); margin: 0; }
.choice:has(input:checked) { border-color: var(--action); background: var(--accent-soft); }

.gap-line { line-height: 2.4; }
.gap-line input {
  display: inline-block; width: 8.5em; min-height: 40px;
  margin: 0 3px; text-align: center; vertical-align: baseline;
}
.bank { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.bank .word {
  border: 1px dashed var(--line-strong); border-radius: var(--radius-pill);
  padding: 5px var(--space-3); font-size: var(--text-md);
  color: var(--ink-soft); background: var(--surface); cursor: pointer;
}
.bank .word.used { opacity: 0.4; }

.match-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); align-items: center;
}
.match-row + .match-row { margin-top: var(--space-2); }
.match-row .left { font-weight: var(--weight-medium); }

/* ---------------------------------------------------------------- diagrams */

/* A labelling task is a diagram of numbered pins plus a list of labels
   underneath, the same shape as the worksheet. Dropdowns on the diagram itself
   were tried first and are unworkable on a phone: at 375px they cover the cell
   they are asking about. */

.diagram { position: relative; max-width: 420px; margin: 0 auto var(--space-4); }
.diagram svg { width: 100%; height: auto; display: block; }

.pin {
  display: grid; place-items: center; width: 27px; height: 27px; flex: none;
  border-radius: var(--radius-pill);
  border: 2px solid var(--accent); background: var(--surface);
  font-family: var(--font-display); font-size: var(--text-xs);
  font-weight: var(--weight-bold); color: var(--accent);
}
.diagram .pin {
  position: absolute; transform: translate(-50%, -50%); box-shadow: var(--shadow-2);
}
.pin.locked { border-color: var(--right); color: var(--right); }
.pin.right { border-color: var(--right); color: var(--right); background: var(--right-soft); }
.pin.wrong { border-color: var(--wrong); color: var(--wrong); background: var(--wrong-soft); }

.label-list { display: grid; gap: var(--space-2); }
.label-row { display: flex; align-items: center; gap: var(--space-3); }
.label-row select { flex: 1; min-width: 0; }
.label-row .fixed {
  flex: 1; padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  border: 1px solid var(--right); color: var(--right);
  font-weight: var(--weight-medium); font-size: var(--text-md);
}
.label-row.right select { border-color: var(--right); }
.label-row.wrong select { border-color: var(--wrong); }

/* ---------------------------------------------------------------- tables */

.table-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin: 0 -4px; padding: 0 4px;
}
table { border-collapse: collapse; width: 100%; font-size: var(--text-md); }
th, td {
  text-align: left; padding: var(--space-3);
  border-bottom: 1px solid var(--line); vertical-align: middle;
}
th {
  font-size: var(--text-2xs); text-transform: uppercase;
  letter-spacing: var(--tracking-wide); color: var(--ink-faint);
  font-weight: var(--weight-semi);
}
td.tick, th.tick { text-align: center; width: 5.5rem; }
td.tick input { width: 24px; height: 24px; accent-color: var(--action); }
tr.right td { background: var(--right-soft); }
tr.wrong td { background: var(--wrong-soft); }

/* ---------------------------------------------------------------- feedback */

.score {
  text-align: center; padding: var(--space-6) var(--space-5);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.score .big {
  font-family: var(--font-display); font-size: var(--text-4xl);
  font-weight: var(--weight-bold); letter-spacing: -0.03em; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score .of { color: var(--ink-faint); font-weight: var(--weight-medium); font-size: var(--text-xl); }
.score .band {
  margin-top: var(--space-3); font-family: var(--font-display);
  font-weight: var(--weight-bold); letter-spacing: var(--tracking-tight);
}
.score .band-line { color: var(--ink-soft); font-size: var(--text-md); margin-top: var(--space-1); }

.verdict {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-size: var(--text-2xs); font-weight: var(--weight-bold);
  letter-spacing: 0.03em; text-transform: uppercase;
}
.verdict.right { color: var(--right); }
.verdict.wrong { color: var(--wrong); }
.verdict.partial { color: var(--part); }

.q-card.right { border-left: 3px solid var(--right); }
.q-card.wrong { border-left: 3px solid var(--wrong); }
.q-card.partial { border-left: 3px solid var(--part); }

.points { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-2); }
.points li {
  display: grid; grid-template-columns: 20px 1fr; gap: var(--space-3);
  font-size: var(--text-md); align-items: start;
}
.points .mark { font-weight: var(--weight-bold); line-height: 1.5; }
.points .got .mark { color: var(--right); }
.points .missed .mark { color: var(--wrong); }
.points .tip {
  display: block; color: var(--ink-faint); font-size: var(--text-sm); margin-top: 2px;
}

.given {
  margin-top: var(--space-3); padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm); background: var(--surface-sunk);
  font-size: var(--text-md); white-space: pre-wrap;
}
.given .who, .model .who {
  display: block; font-size: var(--text-2xs); text-transform: uppercase;
  letter-spacing: var(--tracking-wide); color: var(--ink-faint);
  margin-bottom: var(--space-1); font-weight: var(--weight-semi);
}
.model {
  margin-top: var(--space-2); padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm); background: var(--right-soft);
  color: var(--right); font-size: var(--text-md);
}
.model .who { color: inherit; opacity: 0.8; }

.next { display: grid; gap: var(--space-2); list-style: none; padding: 0; margin: 0; }
.next li { display: grid; grid-template-columns: 22px 1fr; gap: var(--space-2); }
.next .n {
  font-family: var(--font-display); font-weight: var(--weight-bold); color: var(--accent);
}

/* ---------------------------------------------------------------- teacher */

.tabs {
  display: flex; gap: var(--space-1); background: var(--surface-sunk);
  padding: var(--space-1); border-radius: var(--radius-sm); margin-bottom: var(--space-5);
}
.tabs button {
  flex: 1; min-height: 38px; border: 0; border-radius: var(--radius-sm) ;
  background: none; cursor: pointer;
  font-size: var(--text-md); font-weight: var(--weight-medium); color: var(--ink-soft);
}
.tabs button[aria-selected="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-1); font-weight: var(--weight-semi);
}

.pupil-row {
  display: grid; grid-template-columns: 1fr auto; gap: var(--space-3);
  align-items: center; padding: var(--space-3) 0; border-bottom: 1px solid var(--line);
}
.pupil-row:last-child { border-bottom: 0; }
.pupil-row .who { font-weight: var(--weight-medium); }
.pupil-row .meta { font-size: var(--text-xs); color: var(--ink-faint); }

.phrase-out {
  font-family: var(--font-display); font-size: var(--text-xl);
  font-weight: var(--weight-bold); letter-spacing: 0.01em; text-align: center;
  padding: var(--space-4); border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent);
}

.locked-note {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  background: var(--surface-sunk); font-size: var(--text-sm); color: var(--ink-soft);
}

.editable {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--space-4);
}
.editable + .editable { margin-top: var(--space-2); }
.editable .row { display: grid; gap: var(--space-2); }
.editable .num {
  font-family: var(--font-display); font-size: var(--text-xs);
  font-weight: var(--weight-bold); color: var(--ink-faint);
}

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: var(--space-3) var(--space-5); border-radius: var(--radius-pill);
  font-size: var(--text-md); font-weight: var(--weight-medium);
  z-index: 30; max-width: calc(100vw - 40px); text-align: center;
  box-shadow: var(--shadow-2);
}

/* ---------------------------------------------------------------- wider screens */

@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
}

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