/* Pencilwick components — see docs/DESIGN.md (component table) and public/styleguide.html.
   Every colour, radius, shadow and duration comes from tokens.css. */

:root {
  /* derived, theme-aware ink colours (computed from tokens so they follow light/dark) */
  --not-yet: color-mix(in oklab, var(--margin) 78%, var(--ink));
  --input-border: color-mix(in oklab, var(--ink) 34%, var(--sheet));
  --margin-line: color-mix(in srgb, var(--margin) 62%, transparent);
  --scrim: rgb(9 22 18 / 0.46);
}
[data-theme="dark"] {
  --not-yet: color-mix(in oklab, var(--margin) 78%, var(--ink));
  --input-border: color-mix(in oklab, var(--ink) 34%, var(--sheet));
  --margin-line: color-mix(in srgb, var(--margin) 62%, transparent);
  --scrim: rgb(0 0 0 / 0.6);
}

/* ===================================================================== Icons */
.icon {
  width: var(--icon-size, 20px);
  height: var(--icon-size, 20px);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.2em;
  flex-shrink: 0;
}
.icon--sm { --icon-size: 16px; }
.icon--lg { --icon-size: 24px; }
.icon--xl { --icon-size: 32px; stroke-width: 1.5; }

/* ===================================================================== Wordmark */
.wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
  font-family: var(--font-display);
  font-weight: 760;
  font-stretch: 88%;
  font-variation-settings: "opsz" 36;
  font-size: 1.625rem;
  letter-spacing: -0.035em;
  line-height: 1;
}
.wordmark:hover { text-decoration: none; }
.wordmark__mark { width: 1.35em; height: 1.35em; overflow: visible; }
.mark__stem { fill: none; stroke: var(--gum); stroke-width: 2; stroke-linecap: round; }
.mark__twig { stroke-width: 1.4; }
.mark__leaf { fill: var(--gum); }
.mark__bloom { fill: var(--wattle); }
.mark__bloom--deep { fill: color-mix(in oklab, var(--wattle) 82%, var(--wattle-deep)); }

/* ===================================================================== Buttons */
.btn {
  --btn-bg: var(--sheet);
  --btn-fg: var(--ink);
  --btn-border: var(--input-border);
  --btn-hover: var(--sheet-2);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px;
  padding: 0 var(--s-5);
  border: 1px solid var(--btn-border);
  border-radius: var(--r-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: 650 var(--fs-md)/1.15 var(--font-body);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease, transform var(--t-fast) ease;
}
.btn:hover { background: var(--btn-hover); text-decoration: none; }
.btn:active:not(:disabled):not([aria-disabled="true"]) { transform: translateY(1px); }
.btn:focus-visible { border-radius: var(--r-sm); }
.btn .icon { --icon-size: 20px; margin-inline: -2px; }

.btn--primary {
  --btn-bg: var(--gum); --btn-fg: var(--on-gum); --btn-border: var(--gum); --btn-hover: var(--gum-hover);
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 0.16);
}
.btn--primary:hover { --btn-border: var(--gum-hover); }
.btn--secondary { --btn-bg: var(--sheet); --btn-fg: var(--ink); }
.btn--quiet { --btn-bg: transparent; --btn-border: transparent; --btn-fg: var(--gum); --btn-hover: var(--gum-wash); }
.btn--danger { --btn-bg: transparent; --btn-fg: var(--not-yet); --btn-border: color-mix(in oklab, var(--margin) 60%, var(--sheet)); --btn-hover: var(--margin-wash); }
.btn--lg { min-height: 54px; padding: 0 var(--s-6); font-size: var(--fs-lg); border-radius: var(--r-sm); }
.btn--sm { min-height: 36px; padding: 0 var(--s-3); font-size: var(--fs-sm); gap: 6px; }
.btn--sm .icon { --icon-size: 18px; }
.btn--sm::after { content: ""; position: absolute; inset: -4px -2px; } /* keeps a 44px target */
.btn--icon { padding: 0; width: 44px; min-width: 44px; }
.btn--icon.btn--sm { width: 36px; min-width: 36px; }
.btn--round { border-radius: 50%; }
.btn--round:focus-visible { border-radius: 50%; }
.btn--block { width: 100%; }
[data-band="early"] .btn { min-height: 48px; }
[data-band="early"] .btn--icon { width: 48px; min-width: 48px; }

.btn:disabled, .btn[aria-disabled="true"] {
  --btn-bg: var(--sheet-2); --btn-fg: var(--ink-3); --btn-border: var(--line); --btn-hover: var(--sheet-2);
  box-shadow: none; cursor: not-allowed;
}
.btn[aria-busy="true"] { color: transparent; pointer-events: none; }
.btn[aria-busy="true"]::before {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--btn-fg); border-right-color: transparent;
  animation: spin 700ms linear infinite;
}
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

.link-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  color: var(--gum); font-weight: 650; text-decoration: none;
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 0.2em; }

.spinner {
  display: inline-block; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--gum);
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================================================================== Fields */
.field { display: grid; gap: 6px; min-width: 0; }
.field__label { font-weight: 650; font-size: var(--fs-md); color: var(--ink); }
.field__label .optional { font-weight: 400; color: var(--ink-3); }
.field__help { font-size: var(--fs-sm); color: var(--ink-2); max-width: var(--measure); }
.field__error {
  display: flex; gap: 6px; align-items: flex-start;
  font-size: var(--fs-sm); color: var(--not-yet); font-weight: 600;
}
.field__error .icon { --icon-size: 18px; margin-top: 2px; }

.input, .select, .textarea {
  display: block; width: 100%;
  min-height: 44px;
  padding: 9px var(--s-3);
  border: 1px solid var(--input-border);
  border-radius: var(--r-sm);
  background: var(--sheet);
  color: var(--ink);
  font-size: var(--fs-md);
  line-height: 1.5;
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-3); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { border-color: var(--gum); border-radius: var(--r-sm); }
.textarea { min-height: 120px; }
[data-band="early"] :is(.input, .select) { min-height: 52px; }
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--not-yet); border-width: 2px; padding-inline: 11px; }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--sheet-2); color: var(--ink-3); }
.input-group { display: flex; align-items: stretch; }
.input-group > .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }

.check {
  display: flex; align-items: center; gap: var(--s-3); min-height: 44px;
  cursor: pointer; font-size: var(--fs-md);
}
.check input { width: 20px; height: 20px; accent-color: var(--gum); margin: 0; flex: none; }
.check input:focus-visible { box-shadow: var(--focus); }
.check__hint { display: block; font-size: var(--fs-sm); color: var(--ink-2); }

.switch { display: inline-flex; align-items: center; gap: var(--s-3); min-height: 44px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; margin: 0; width: 42px; height: 24px; border-radius: 12px; background: var(--input-border); position: relative; cursor: pointer; transition: background-color var(--t-fast) ease; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--sheet); transition: transform var(--t-med) var(--ease-out); }
.switch input:checked { background: var(--gum); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:focus-visible { box-shadow: var(--focus); border-radius: 12px; }

/* ===================================================================== Exercise-book page */
.page {
  container: page / inline-size;
  --pad-l: calc(var(--margin-x) + var(--s-5));
  --pad-r: var(--s-8);
  /* baseline of a body line inside a --ruled line box (Atkinson ascent .984 / descent .316) */
  --rule-y: calc(var(--ruled) / 2 + var(--fs-md) * 0.334 + 2px);
  position: relative;
  border-radius: var(--r-lg);
  box-shadow: var(--stack);
  background: var(--sheet);
  color: var(--ink);
  min-width: 0;
}
.page__head, .page__body {
  --margin-bg: linear-gradient(90deg, transparent calc(var(--margin-x) - 1px), var(--margin-line) calc(var(--margin-x) - 1px), var(--margin-line) calc(var(--margin-x) + 1px), transparent calc(var(--margin-x) + 1px));
  padding-left: var(--pad-l);
  padding-right: var(--pad-r);
}
.page__head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-3) var(--s-6); flex-wrap: wrap;
  padding-top: var(--s-6); padding-bottom: var(--s-4);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border-bottom: 3px double var(--rule-strong);
  background: var(--margin-bg);
}
.page__title { font-size: var(--fs-2xl); letter-spacing: -0.02em; font-weight: 720; min-width: 0; }
.page__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); color: var(--ink-2); font-size: var(--fs-sm); }
.page__body {
  position: relative;
  padding-top: var(--ruled);
  padding-bottom: var(--ruled);
  line-height: var(--ruled);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  background:
    var(--margin-bg),
    linear-gradient(to bottom, transparent calc(var(--ruled) - 1px), var(--rule) calc(var(--ruled) - 1px)) 0 var(--rule-y) / 100% var(--ruled) repeat-y;
}
.page--plain .page__head { display: none; }
.page--plain .page__body { border-radius: var(--r-lg); }

/* rhythm: everything inside the ruled body sits on the lines */
.page__body :is(p, li, dt, dd, td, th, blockquote, h2, h3, h4, label, .margin-note) { line-height: var(--ruled); }
.page__body > * + *, .page__main > * + * { margin-top: var(--ruled); }
.page__main > :is(h2, h3, h4) + *, .page__body > :is(h2, h3, h4) + *,
.page__body > :has(> .page__main > :is(h2, h3, h4):only-child) + * { margin-top: 0; }
.page__body :is(h2, h3, h4) {
  position: relative;
  top: calc((var(--fs-md) - 1em) * 0.334); /* lift larger type so its baseline sits on the rule */
  font-size: var(--fs-xl);
}
.page__body h3 { font-size: var(--fs-lg); }
.page__body h4 { font-size: var(--fs-md); }
.page__body :is(ul, ol) { padding-left: 1.3em; }
.page__body li + li { margin-top: 0; }
.page__body li::marker { color: var(--ink-3); }
.page__body p { max-width: var(--measure); }
.page__body mjx-container[display="true"] { margin: 0 !important; }

.page__row { position: relative; min-width: 0; }
.page__main { min-width: 0; }
.page__num {
  position: absolute;
  left: calc(-1 * var(--pad-l));
  width: var(--margin-x);
  top: 0;
  padding-right: 4px;
  text-align: center;
  font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg);
  line-height: var(--ruled);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.page__num--done { color: var(--gum); }
.page__margin { min-width: 0; }

@container page (min-width: 760px) {
  /* (a container query can't style the container itself, so the width lives on the rows) */
  .page--notes .page__row { display: grid; grid-template-columns: minmax(0, 1fr) clamp(180px, 27cqi, 270px); column-gap: var(--s-10); }
  .page--notes .page__row > .page__main { grid-column: 1; }
  .page--notes .page__row > .page__margin { grid-column: 2; position: relative; }
  .page--notes .page__margin .margin-note { margin-top: 0; }
}
@container page (max-width: 759px) {
  .page__margin { margin-top: 0; }
  .page__margin:empty { display: none; }
  .page__margin .margin-note { border-left: 2px solid var(--margin-line); padding-left: var(--s-3); }
  .page__margin .margin-note__mark { display: none; }
}
/* narrow sheets: the margin line becomes a 3px red edge and numbers move inline */
@container page (max-width: 599px) {
  .page__head, .page__body {
    --pad-l: var(--s-5);
    --pad-r: var(--s-4);
    --margin-bg: linear-gradient(90deg, var(--margin-line) 3px, transparent 3px);
  }
  .page__title { font-size: var(--fs-xl); }
  .page__row--num { padding-left: 2.25rem; }
  .page__num { left: 0; width: auto; text-align: left; font-size: var(--fs-md); }
}

/* lines to write on (open answers, notes) */
.ruled-lines {
  background: linear-gradient(to bottom, transparent calc(var(--ruled) - 1px), var(--rule) calc(var(--ruled) - 1px)) 0 var(--rule-y, calc(var(--ruled) / 2 + var(--fs-md) * 0.334 + 2px)) / 100% var(--ruled);
  line-height: var(--ruled);
}

/* ===================================================================== Margin notes */
.margin-note {
  --note-ink: var(--ocean);
  position: relative;
  color: var(--note-ink);
  font-size: var(--fs-sm);
  font-style: italic;
  font-weight: 500;
  line-height: var(--ruled);
  max-width: 34ch;
}
.margin-note--gum { --note-ink: var(--gum); }
.margin-note--margin { --note-ink: var(--not-yet); }
.margin-note p + p { margin-top: 0; }
.margin-note strong { font-weight: 700; }
.margin-note__mark {
  position: absolute; left: -30px; top: calc(var(--ruled) / 2 - 9px);
  width: 22px; height: 18px;
  stroke: var(--note-ink); stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round;
}
.margin-note__label { font-style: normal; font-weight: 700; font-family: var(--font-display); letter-spacing: -0.01em; margin-right: 0.35em; }
/* standalone note (outside a page): a short ink stroke on the left */
.margin-note--inline { padding-left: var(--s-4); border-left: 2px solid color-mix(in srgb, var(--note-ink) 55%, transparent); line-height: 1.55; }
.margin-note--inline .margin-note__mark { display: none; }
/* the one write-on moment */
.margin-note.is-writing .margin-note__mark path { stroke-dasharray: 60; stroke-dashoffset: 60; animation: draw 320ms var(--ease-out) forwards; }
.margin-note.is-writing .margin-note__text { animation: write-on 900ms 180ms cubic-bezier(0.45, 0.05, 0.4, 1) both; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes write-on { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* ===================================================================== Steps (worked solution) */
.steps { list-style: none; padding: 0; counter-reset: step; display: grid; gap: var(--s-5); }
.steps > li { counter-increment: step; display: grid; grid-template-columns: 2.25rem minmax(0, 1fr); gap: var(--s-3); }
.steps > li::before {
  content: counter(step);
  display: grid; place-items: center;
  width: 2rem; height: 2rem; border-radius: 50%;
  border: 1.5px solid var(--rule-strong);
  font-family: var(--font-display); font-weight: 700; color: var(--ink-2);
}
.steps__why { margin-top: var(--s-2); }
.page .steps { gap: 0; }

/* ===================================================================== Cards */
.card {
  display: block;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-6);
  color: inherit;
  min-width: 0;
}
.card--stack { border-color: transparent; box-shadow: var(--stack); }
.card--flush { padding: 0; overflow: hidden; }
.card--tint { background: var(--sheet-2); border-color: transparent; }
a.card, button.card { text-decoration: none; text-align: left; width: 100%; transition: border-color var(--t-fast) ease; }
a.card:hover, button.card:hover { border-color: var(--input-border); }
a.card:focus-visible, button.card:focus-visible { border-radius: var(--r-md); }
.card__title { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 680; letter-spacing: -0.01em; line-height: 1.25; }
.card__body { color: var(--ink-2); margin-top: var(--s-2); font-size: var(--fs-sm); }
.card__foot { margin-top: var(--s-5); display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }

/* ===================================================================== Lists (prefer to cards for collections) */
.list { list-style: none; padding: 0; border-top: 1px solid var(--line); }
.list__item {
  display: flex; align-items: center; gap: var(--s-4);
  min-height: 60px; padding: var(--s-3) var(--s-2);
  border-bottom: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
a.list__item:hover, button.list__item:hover { background: var(--sheet-2); }
button.list__item { width: 100%; }
.list__title { font-weight: 650; }
.list__meta { color: var(--ink-2); font-size: var(--fs-sm); }
.list__end { margin-left: auto; display: flex; align-items: center; gap: var(--s-3); color: var(--ink-3); }

/* ===================================================================== Chips, tags, codes, badges */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px;
  border-radius: var(--r-xs);
  background: var(--sheet-2);
  color: var(--ink-2);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.6;
  white-space: nowrap;
}
.tag .icon { --icon-size: 14px; }
.tag--gum { background: var(--gum-wash); color: var(--gum); }
.tag--ocean { background: var(--ocean-wash); color: var(--ocean); }
.tag--wattle { background: var(--wattle-wash); color: var(--ink); }
.tag--wattle::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--wattle); }
.tag--margin { background: var(--margin-wash); color: var(--not-yet); }
.tag--outline { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }

.chip {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 var(--s-3);
  border: 1px solid var(--input-border);
  border-radius: var(--r-xs);
  background: var(--sheet); color: var(--ink);
  font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.chip::after { content: ""; position: absolute; inset: -4px 0; }
.chip:hover { background: var(--sheet-2); }
.chip[aria-pressed="true"], .chip[aria-selected="true"], .chip.is-active { background: var(--gum-wash); border-color: var(--gum); color: var(--gum); }
.chip .icon { --icon-size: 16px; }

.curriculum-code {
  display: inline-flex; align-items: center;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 500; letter-spacing: 0.02em;
  line-height: 1.75;
  color: var(--ink-2);
  text-decoration: none;
  white-space: nowrap;
  background: var(--sheet);
}
a.curriculum-code:hover { border-color: var(--ocean); color: var(--ocean); }

.badge {
  display: inline-grid; place-items: center;
  min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 11px;
  background: var(--wattle); color: #2a1d00;
  font: 700 0.75rem/1 var(--font-display); font-variant-numeric: tabular-nums;
}
.kbd { display: inline-block; padding: 0 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: var(--r-xs); font-family: var(--font-mono); font-size: 0.8em; background: var(--sheet); }

/* ===================================================================== Callouts (markdown "> ") */
.callout {
  --callout-ink: var(--ocean);
  --callout-bg: var(--ocean-wash);
  padding: var(--s-3) var(--s-4);
  border-left: 3px solid var(--callout-ink);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--callout-bg);
  color: var(--ink);
}
.callout > * + * { margin-top: 0.5em; }
.callout--tip { --callout-ink: var(--gum); --callout-bg: var(--gum-wash); }
.callout--key { --callout-ink: var(--wattle); --callout-bg: var(--wattle-wash); }
.callout--warn { --callout-ink: var(--margin); --callout-bg: var(--margin-wash); }
.page__body .callout { padding-block: 0; }

/* ===================================================================== Vocabulary (highlighter) */
.vocab {
  display: inline; padding: 0 1px;
  color: inherit; font: inherit; line-height: inherit;
  background-image: linear-gradient(to top, color-mix(in srgb, var(--wattle) 58%, transparent) 45%, transparent 45%);
  border-radius: 1px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
button.vocab { cursor: help; text-align: inherit; line-height: 1.2; vertical-align: baseline; letter-spacing: inherit; }
button.vocab:hover { background-image: linear-gradient(to top, color-mix(in srgb, var(--wattle) 80%, transparent) 45%, transparent 45%); }
mark { background: none; color: inherit; }
.vocab-pop {
  position: fixed; margin: 0; inset: auto;
  width: min(320px, calc(100vw - 32px));
  padding: var(--s-4);
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--sheet); color: var(--ink);
  box-shadow: var(--lift);
  font-size: var(--fs-sm); line-height: 1.5;
}
.vocab-pop__term { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-md); margin-bottom: 4px; }

/* ===================================================================== Mastery */
.mastery { display: inline-flex; align-items: center; gap: var(--s-2); }
.mastery__bar { display: inline-flex; gap: 3px; }
.mastery__seg { width: 14px; height: 8px; border-radius: 2px; box-shadow: inset 0 0 0 1px var(--line); background: transparent; }
.mastery__seg.is-on { box-shadow: none; }
.mastery[data-level="0"] .is-on { background: var(--m0); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--m0) 70%, var(--ink-3)); }
.mastery[data-level="1"] .is-on { background: var(--m1); }
.mastery[data-level="2"] .is-on { background: var(--m2); }
.mastery[data-level="3"] .is-on { background: var(--m3); }
.mastery--lg .mastery__seg { width: 26px; height: 10px; }
.mastery__label { font-size: var(--fs-sm); color: var(--ink-2); font-weight: 600; }
.mastery.is-levelling .is-on { animation: seg-fill var(--t-slow) var(--ease-out) both; }
.mastery.is-levelling .is-on:nth-child(2) { animation-delay: 80ms; }
.mastery.is-levelling .is-on:nth-child(3) { animation-delay: 160ms; }
.mastery.is-levelling .is-on:nth-child(4) { animation-delay: 240ms; }
@keyframes seg-fill { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); } }

.mastery-legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-5); list-style: none; padding: 0; font-size: var(--fs-sm); color: var(--ink-2); }
.mastery-legend li { display: inline-flex; align-items: center; gap: var(--s-2); }
.mastery-swatch { width: 16px; height: 16px; border-radius: 3px; display: inline-grid; place-items: center; }
.mastery-swatch[data-level="0"] { background: var(--m0); }
.mastery-swatch[data-level="1"] { background: var(--m1); }
.mastery-swatch[data-level="2"] { background: var(--m2); }
.mastery-swatch[data-level="3"] { background: var(--m3); color: var(--on-gum); }
.mastery-swatch[data-level="none"] { background: repeating-linear-gradient(135deg, var(--line) 0 2px, transparent 2px 5px); box-shadow: inset 0 0 0 1px var(--line); }

/* scroll wrappers: contain their width so a wide table never widens the page layout */
.mastery-grid-wrap { overflow-x: auto; max-width: 100%; padding-bottom: var(--s-2); contain: inline-size; }
.mastery-grid { border-collapse: separate; border-spacing: 3px; font-size: var(--fs-sm); }
.mastery-grid th { font-weight: 600; color: var(--ink-2); }
.mastery-grid thead th { vertical-align: bottom; padding: 0 0 6px; height: 96px; }
.mastery-grid thead th span {
  display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg);
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.02em; white-space: nowrap; color: var(--ink-2);
}
.mastery-grid tbody th { text-align: left; padding-right: var(--s-3); white-space: nowrap; color: var(--ink); max-width: 180px; overflow: hidden; text-overflow: ellipsis; position: sticky; left: 0; background: var(--grid-bg, var(--paper)); z-index: 1; }
.card .mastery-grid, .page .mastery-grid, .dialog .mastery-grid { --grid-bg: var(--sheet); }
.mastery-grid td { padding: 0; }
.mg-cell {
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 4px;
  background: var(--m0); color: var(--on-gum);
}
button.mg-cell { cursor: pointer; }
button.mg-cell:hover { outline: 2px solid var(--ink-2); outline-offset: 1px; }
.mg-cell[data-level="1"] { background: var(--m1); }
.mg-cell[data-level="2"] { background: var(--m2); }
.mg-cell[data-level="3"] { background: var(--m3); }
.mg-cell[data-level="none"] { background: repeating-linear-gradient(135deg, var(--line) 0 2px, transparent 2px 5px); box-shadow: inset 0 0 0 1px var(--line); }
.mg-cell .icon { --icon-size: 14px; stroke-width: 2.5; }

/* ===================================================================== Progress ring + bar */
.progress-ring { position: relative; display: inline-grid; place-items: center; width: var(--ring-size, 120px); height: var(--ring-size, 120px); }
.progress-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.progress-ring__track { fill: none; stroke: var(--line); }
.progress-ring__fill { fill: none; stroke: var(--wattle); stroke-linecap: round; transition: stroke-dashoffset var(--t-slow) var(--ease-out); }
.progress-ring.is-done .progress-ring__fill { stroke: var(--wattle); }
.progress-ring__label { position: relative; text-align: center; line-height: 1.05; }
.progress-ring__value { display: block; font-family: var(--font-display); font-weight: 740; font-size: calc(var(--ring-size, 120px) * 0.26); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.progress-ring__unit { display: block; font-size: var(--fs-xs); color: var(--ink-2); margin-top: 2px; }
.progress-ring--sm { --ring-size: 56px; }
.progress-ring--sm .progress-ring__unit { display: none; }

.progress { height: 8px; border-radius: 4px; background: var(--sheet-2); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.progress__fill { height: 100%; width: var(--value, 0%); background: var(--wattle); border-radius: 4px; transition: width var(--t-slow) var(--ease-out); }

/* ===================================================================== Streak */
.streak { display: inline-flex; align-items: center; gap: var(--s-5); }
.streak__count { display: flex; align-items: baseline; gap: 6px; }
.streak__num { font-family: var(--font-display); font-weight: 760; font-size: var(--fs-3xl); letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.streak__unit { color: var(--ink-2); font-size: var(--fs-sm); }
.streak__days { display: flex; gap: 6px; list-style: none; padding: 0; }
.streak__day { display: grid; justify-items: center; gap: 4px; font-size: 0.6875rem; color: var(--ink-3); font-weight: 600; }
.streak__dot { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--input-border); display: grid; place-items: center; }
.streak__day.is-done .streak__dot { background: var(--wattle); border-color: var(--wattle); }
.streak__day.is-today .streak__dot { border-style: dashed; border-color: var(--wattle-deep); }
.streak__day.is-today.is-done .streak__dot { border-style: solid; border-color: var(--wattle); }
.streak__day.is-frozen .streak__dot { background: var(--ocean-wash); border-color: var(--ocean); color: var(--ocean); }
.streak__day.is-frozen .icon { --icon-size: 12px; stroke-width: 2.2; }
.streak__day.is-today { color: var(--ink); }
.streak__copy { font-size: var(--fs-sm); color: var(--ink-2); max-width: 32ch; }

/* ===================================================================== Stats */
.stats { display: flex; flex-wrap: wrap; gap: var(--s-5) 0; }
.stat { display: grid; gap: 2px; padding-right: var(--s-6); margin-right: var(--s-6); border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; margin-right: 0; padding-right: 0; }
.stat__value { font-family: var(--font-display); font-weight: 720; font-size: var(--fs-2xl); letter-spacing: -0.025em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat__value small { font-size: 0.55em; font-weight: 600; color: var(--ink-2); letter-spacing: 0; margin-left: 2px; }
.stat__label { font-size: var(--fs-sm); color: var(--ink-2); }

/* ===================================================================== Avatar */
.avatar {
  --av: var(--gum);
  display: inline-grid; place-items: center; flex: none;
  width: var(--av-size, 40px); height: var(--av-size, 40px);
  border-radius: 50%;
  background: color-mix(in oklab, var(--av) 15%, var(--sheet));
  color: color-mix(in oklab, var(--av) 78%, var(--ink)); /* initials are small bold text: keep 4.5:1 on the tint */
  font-family: var(--font-display); font-weight: 700;
  font-size: calc(var(--av-size, 40px) * 0.4);
  letter-spacing: -0.02em; line-height: 1;
  overflow: hidden; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { --av-size: 32px; }
.avatar--lg { --av-size: 56px; }
.avatar[data-tone="1"] { --av: var(--gum); }
.avatar[data-tone="2"] { --av: var(--ocean); }
.avatar[data-tone="3"] { --av: color-mix(in oklab, var(--wattle-deep) 85%, var(--ink)); }
.avatar[data-tone="4"] { --av: var(--role-parent); }
.avatar[data-tone="5"] { --av: var(--gum-2); }
.avatar[data-tone="6"] { --av: var(--ink-2); }

/* ===================================================================== Tabs + segmented + role switch */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; contain: inline-size; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: 46px; padding: 0 var(--s-3);
  color: var(--ink-2); font-weight: 600; white-space: nowrap; text-decoration: none;
}
.tab:hover { color: var(--ink); }
.tab::after { content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: transparent; }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--ink); }
.tab[aria-selected="true"]::after, .tab[aria-current="page"]::after { background: var(--gum); }
.tab:focus-visible { box-shadow: inset 0 0 0 2px var(--wattle-deep); border-radius: var(--r-xs); }
.tab .badge { height: 20px; min-width: 20px; }
.tab-panel:focus-visible { box-shadow: none; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  border-radius: calc(var(--r-sm) + 2px);
  background: var(--sheet-2);
  box-shadow: inset 0 0 0 1px var(--line);
  max-width: 100%;
}
.segmented__btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  flex: 0 1 auto; min-width: 0;
  min-height: 38px; padding: 4px var(--s-4);
  border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 600; font-size: var(--fs-sm); line-height: 1.15; text-align: center;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}
.segmented__btn::after { content: ""; position: absolute; inset: -3px 0; }
.segmented__btn:hover { color: var(--ink); }
.segmented__btn[aria-checked="true"], .segmented__btn[aria-pressed="true"] {
  background: var(--sheet); color: var(--ink);
  box-shadow: 0 0 0 1px var(--line), 0 1px 0 var(--line);
}
.segmented__btn .icon { --icon-size: 18px; }
.segmented--block { display: flex; }
.segmented--block .segmented__btn { flex: 1 1 0; padding-inline: var(--s-2); }
.segmented--icons .segmented__btn { padding: 0 var(--s-3); }

.role-switch .segmented__btn[aria-checked="true"]::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--role, var(--gum));
}
.role-switch [data-role="student"] { --role: var(--role-student); }
.role-switch [data-role="parent"] { --role: var(--role-parent); }
.role-switch [data-role="teacher"] { --role: var(--role-teacher); }

/* ===================================================================== Dialog */
.dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: min(86vh, 760px);
  padding: 0;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--sheet);
  color: var(--ink);
  box-shadow: var(--lift);
  overflow: hidden;
}
.dialog[open] { display: flex; flex-direction: column; animation: dialog-in var(--t-med) var(--ease-out); }
.dialog::backdrop { background: var(--scrim); }
.dialog[open]::backdrop { animation: fade-in var(--t-med) ease; }
.dialog--wide { width: min(820px, calc(100vw - 32px)); }
.dialog__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); padding: var(--s-6) var(--s-6) 0; }
.dialog__title { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.015em; padding-top: 6px; }
.dialog__close { margin: -4px -10px 0 0; color: var(--ink-2); }
.dialog__body { padding: var(--s-4) var(--s-6) var(--s-6); overflow-y: auto; color: var(--ink-2); }
.dialog__body > * + * { margin-top: var(--s-4); }
.dialog__foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--s-3); padding: var(--s-4) var(--s-6); border-top: 1px solid var(--line); background: var(--paper); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes fade-in { from { opacity: 0; } }
@media (max-width: 559px) {
  .dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92vh; }
  .dialog__foot { flex-direction: column-reverse; align-items: stretch; padding-bottom: calc(var(--s-4) + env(safe-area-inset-bottom)); }
  @keyframes dialog-in { from { transform: translateY(24px); opacity: 0.4; } }
}

/* ===================================================================== Menu (popover) */
.menu {
  position: fixed; inset: auto; margin: 0;
  min-width: 240px; max-width: calc(100vw - 24px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--sheet); color: var(--ink);
  box-shadow: var(--lift);
}
.menu:popover-open { animation: fade-in var(--t-fast) ease; }
.menu.is-measuring { visibility: hidden; }
.menu__item {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; min-height: 44px; padding: 0 var(--s-3);
  border-radius: var(--r-sm);
  color: var(--ink); text-decoration: none; font-weight: 500;
}
.menu__item:hover, .menu__item:focus-visible { background: var(--sheet-2); box-shadow: none; }
.menu__item:focus-visible { outline: 2px solid var(--wattle-deep); outline-offset: -2px; }
.menu__item .icon { color: var(--ink-2); }
.menu__item--danger { color: var(--not-yet); }
.menu__item--danger .icon { color: currentColor; }
.menu__sep { height: 1px; margin: 6px 4px; background: var(--line); border: 0; }
.menu__section { padding: var(--s-2) var(--s-3); }
.menu__heading { font-size: var(--fs-sm); color: var(--ink-2); margin-bottom: 6px; }

/* ===================================================================== Tooltip (ui/tooltip.js) */
.tooltip {
  position: fixed; z-index: 95; left: 0; top: 0;
  padding: 5px 9px; border-radius: var(--r-xs);
  background: var(--ink); color: var(--paper);
  font: 600 var(--fs-xs)/1.3 var(--font-body); white-space: nowrap;
  pointer-events: none; opacity: 0; visibility: hidden;
  transition: opacity var(--t-fast) ease;
}
.tooltip.is-on { opacity: 1; visibility: visible; }

/* ===================================================================== Toast */
.toasts {
  position: fixed; z-index: 90;
  left: 50%; bottom: calc(var(--toast-offset, 24px) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid; gap: var(--s-2); justify-items: center;
  width: min(480px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 48px; padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  background: var(--ink); color: var(--paper);
  box-shadow: var(--lift);
  font-size: var(--fs-sm); font-weight: 600;
  pointer-events: auto;
  animation: toast-in var(--t-med) var(--ease-out);
}
.toast__msg { padding-block: 4px; }
.toast .icon { --icon-size: 20px; }
.toast--success .icon { color: color-mix(in oklab, var(--success) 55%, var(--paper)); }
.toast--error .icon { color: color-mix(in oklab, var(--margin) 60%, var(--paper)); }
.toast--info .icon { color: color-mix(in oklab, var(--wattle) 80%, var(--paper)); }
.toast__action { margin-left: auto; min-height: 36px; padding: 0 var(--s-3); border-radius: var(--r-xs); color: var(--paper); font-weight: 700; text-decoration: underline; text-underline-offset: 0.2em; }
.toast__close { margin-left: auto; width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--r-xs); color: color-mix(in srgb, var(--paper) 80%, transparent); }
.toast__action + .toast__close { margin-left: 0; }
.toast.is-leaving { animation: toast-out var(--t-med) ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ===================================================================== Empty state */
.empty {
  display: grid; justify-items: start; gap: var(--s-3);
  max-width: 44ch;
  padding: var(--s-8) 0;
}
.empty__art { width: 132px; height: auto; margin-bottom: var(--s-2); }
.empty__title { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.015em; }
.empty__body { color: var(--ink-2); }
.empty__action { margin-top: var(--s-2); }
.empty--center { justify-items: center; text-align: center; margin-inline: auto; }
.empty--boxed { max-width: none; padding: var(--s-8); border: 1.5px dashed var(--line); border-radius: var(--r-md); }
.art-sheet { fill: var(--sheet); stroke: var(--rule-strong); stroke-width: 1.5; }
.art-rule { stroke: var(--rule); stroke-width: 1.5; }
.art-margin { stroke: var(--margin-line); stroke-width: 1.5; }
.art-pencil { fill: var(--wattle); }
.art-pencil-tip { fill: var(--sheet-2); stroke: var(--ink-2); stroke-width: 1.2; stroke-linejoin: round; }
.art-pencil-lead { fill: var(--ink-2); }
.art-pencil-end { fill: var(--gum); }
.art-scribble { fill: none; stroke: var(--ink-3); stroke-width: 1.6; stroke-linecap: round; }

/* ===================================================================== Skeleton */
.skeleton { display: grid; gap: var(--s-3); }
.sk {
  display: block; height: 14px; border-radius: var(--r-xs);
  background: linear-gradient(90deg, var(--sheet-2) 0%, color-mix(in oklab, var(--sheet-2) 40%, var(--sheet)) 50%, var(--sheet-2) 100%) 0 0 / 300% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}
.sk--title { height: 34px; width: min(320px, 70%); border-radius: var(--r-sm); }
.sk--line { width: 100%; }
.sk--short { width: 60%; }
.sk--block { height: 160px; border-radius: var(--r-md); }
.sk--circle { width: 40px; height: 40px; border-radius: 50%; }
.sk-page { border-radius: var(--r-lg); box-shadow: var(--stack); background: var(--sheet); padding: var(--s-6) var(--s-6) var(--s-8) calc(var(--margin-x) + var(--s-5)); display: grid; gap: 18px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }

/* ===================================================================== Keypad */
/* max-width uses a percentage so the auto-fill grid has no large intrinsic width */
.keypad { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; width: 100%; max-width: min(520px, 100%); }
.key {
  min-height: 44px; padding: 0 6px;
  border: 1px solid var(--line); border-bottom-width: 3px;
  border-radius: var(--r-xs);
  background: var(--sheet); color: var(--ink);
  font-family: var(--font-body); font-weight: 600; font-size: var(--fs-xl); line-height: 1;
  font-variant-numeric: tabular-nums;
  display: grid; place-items: center; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.key:hover { background: var(--sheet-2); }
.key:active { border-bottom-width: 1px; transform: translateY(2px); }
.key:focus-visible { border-radius: var(--r-xs); }
.key small { font-size: 0.6em; }
.key--wide { grid-column: span 2; font-family: var(--font-body); font-size: var(--fs-sm); }
.key__frac { display: inline-grid; line-height: 0.95; font-size: 0.72em; }
.key__frac span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 3px; }

/* ===================================================================== Answer input */
.answer { display: grid; gap: var(--s-4); min-width: 0; }
.answer > * { min-width: 0; }
.answer__prompt { font-weight: 650; }
.answer__row { display: flex; align-items: flex-start; flex-wrap: wrap; gap: var(--s-3) var(--s-4); }
.answer__line-wrap { flex: 1 1 220px; max-width: 420px; display: flex; align-items: flex-end; gap: var(--s-2); }
.answer__field { position: relative; flex: 1; min-width: 0; display: flex; }
.answer__line {
  flex: 1 1 0; width: 0; min-width: 0; /* no intrinsic width: never pushes the layout wider */
  height: calc(var(--ruled) * 1.75);
  padding: 0 var(--s-2);
  border: 0; border-bottom: 2px solid var(--rule-strong);
  border-radius: var(--r-xs) var(--r-xs) 0 0;
  background: transparent;
  font-family: var(--font-body); font-size: var(--fs-xl); font-weight: 600; color: var(--ink);
  transition: border-color var(--t-fast) ease, background-color var(--t-fast) ease;
}
.answer__line::placeholder { font-weight: 400; font-size: var(--fs-md); }
.answer__line:hover { border-bottom-color: var(--input-border); }
.answer__line:focus-visible { border-bottom-color: var(--gum); background: color-mix(in oklab, var(--gum-wash) 45%, transparent); box-shadow: 0 2px 0 0 var(--gum); border-radius: var(--r-xs) var(--r-xs) 0 0; }
.answer__unit { padding-bottom: 12px; color: var(--ink-2); font-weight: 600; font-size: var(--fs-lg); }
.answer__entry { flex: 1 1 240px; max-width: 420px; display: grid; gap: 6px; min-width: 0; }
.answer__entry .answer__line-wrap { max-width: none; }
.answer__row > .answer__actions { padding-top: calc(var(--ruled) * 1.75 - 44px); }
.answer__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.answer__keypad-toggle[aria-expanded="true"] { background: var(--gum-wash); color: var(--gum); border-color: var(--gum); }
.answer__format { font-size: var(--fs-sm); color: var(--ink-3); }

.answer.is-correct .answer__line { border-bottom-color: var(--success); color: var(--ink); }
.answer.is-incorrect .answer__line { border-bottom-color: var(--not-yet); }
.answer__tick { position: absolute; right: 4px; bottom: 10px; width: 30px; height: 30px; color: var(--success); pointer-events: none; opacity: 0; }
.answer.is-correct .answer__tick { opacity: 1; }
.answer__tick path { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 30; stroke-dashoffset: 0; }
.answer.is-correct .answer__tick path { animation: tick-draw 420ms 60ms var(--ease-out) both; }
@keyframes tick-draw { from { stroke-dashoffset: 30; } }

.feedback { display: grid; gap: var(--s-2); padding-left: var(--s-4); border-left: 3px solid currentColor; }
.feedback__title { display: flex; align-items: center; gap: var(--s-2); font-family: var(--font-display); font-weight: 720; font-size: var(--fs-lg); letter-spacing: -0.01em; }
.feedback__text { color: var(--ink); }
.feedback--correct { color: var(--success); }
.feedback--correct .feedback__title { color: var(--success); }
.feedback--incorrect { color: var(--not-yet); }
.feedback--incorrect .feedback__title { color: var(--not-yet); }
.feedback--neutral { color: var(--ocean); }
.feedback .btn-row { margin-top: var(--s-1); }

/* choice / multi options */
.options { display: grid; gap: var(--s-3); border: 0; padding: 0; min-width: 0; }
.options legend { padding: 0; margin-bottom: var(--s-2); font-weight: 650; }
.option {
  position: relative;
  display: flex; align-items: center; gap: var(--s-4);
  min-height: 60px; padding: var(--s-3) var(--s-4);
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--sheet);
  cursor: pointer;
  transition: border-color var(--t-fast) ease, background-color var(--t-fast) ease;
}
.option:hover { border-color: var(--input-border); }
.option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.option__key {
  flex: none; display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: var(--r-xs);
  border: 1.5px solid var(--input-border);
  font-family: var(--font-display); font-weight: 700; color: var(--ink-2);
}
.option--multi .option__key { border-radius: 6px; }
.option__text { flex: 1; min-width: 0; font-size: var(--fs-md); line-height: 1.45; }
.option__state { flex: none; display: none; align-items: center; gap: 4px; font-size: var(--fs-sm); font-weight: 700; }
.option:has(input:checked) { border-color: var(--gum); background: var(--gum-wash); }
.option:has(input:checked) .option__key { background: var(--gum); border-color: var(--gum); color: var(--on-gum); }
.option:has(input:focus-visible) { box-shadow: var(--focus); }
.options .option.is-right { border-color: var(--success); background: var(--success-wash); }
.options .option.is-right .option__key { background: var(--success); border-color: var(--success); color: var(--sheet); }
.option.is-right .option__state { display: inline-flex; color: var(--success); }
.options .option.is-wrong { border-color: var(--not-yet); background: var(--margin-wash); }
.options .option.is-wrong .option__key { background: transparent; border-color: var(--not-yet); color: var(--not-yet); }
.option.is-wrong .option__state { display: inline-flex; color: var(--not-yet); }
.options.is-locked .option { cursor: default; }
[data-band="early"] .option { min-height: 72px; }

/* order */
.order-list { list-style: none; padding: 0; display: grid; gap: var(--s-2); }
.order-item {
  display: flex; align-items: center; gap: var(--s-2);
  min-height: 56px; padding: var(--s-1) var(--s-1) var(--s-1) var(--s-2);
  border: 1.5px solid var(--line); border-radius: var(--r-sm);
  background: var(--sheet);
  touch-action: none;
}
.order-item__grip { display: grid; place-items: center; width: 32px; height: 44px; color: var(--ink-3); cursor: grab; }
.order-item__pos { font-family: var(--font-display); font-weight: 700; color: var(--ink-3); width: 1.5em; text-align: right; font-variant-numeric: tabular-nums; }
.order-item__text { flex: 1; min-width: 0; padding: var(--s-2) 0; }
.order-item__btns { display: flex; }
.order-item.is-dragging { border-color: var(--gum); box-shadow: var(--lift); position: relative; z-index: 2; cursor: grabbing; }
.order-item.is-picked { border-color: var(--gum); border-style: dashed; background: var(--gum-wash); }
.order-list.is-locked .order-item { touch-action: auto; }
.order-list.is-right .order-item { border-color: var(--success); }

/* open answers */
.answer__textarea {
  width: 100%; min-height: calc(var(--ruled) * 5);
  padding: 0 var(--s-3);
  border: 1px solid var(--input-border); border-radius: var(--r-sm);
  background-color: var(--sheet);
  background-attachment: local;
  font-size: var(--fs-md);
  resize: vertical;
}
.model-answer { padding: var(--s-4); border-radius: var(--r-sm); background: var(--gum-wash); }
.model-answer__title { font-family: var(--font-display); font-weight: 700; margin-bottom: var(--s-2); }

/* ===================================================================== Hint ladder */
.hint-ladder { display: grid; gap: var(--s-3); }
.hint-ladder__list { list-style: none; padding: 0; display: grid; gap: var(--s-3); }
.hint { display: grid; gap: 2px; padding: var(--s-3) var(--s-4); border-left: 3px solid var(--ocean); background: var(--ocean-wash); border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.hint__label { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-sm); color: var(--ocean); }
.hint.is-new { animation: hint-in var(--t-med) var(--ease-out); }
.hint-ladder__working { padding-top: var(--s-2); }
@keyframes hint-in { from { opacity: 0; transform: translateY(-4px); } }

/* ===================================================================== Data table */
.table-wrap { overflow-x: auto; max-width: 100%; contain: inline-size; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: var(--s-3); border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { color: var(--ink-2); font-weight: 650; border-bottom-color: var(--rule-strong); white-space: nowrap; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ===================================================================== Section heading (in-page) */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-4); }
.section-head h2 { font-size: var(--fs-xl); }
