/* =============================================================================
   COMPONENTS

   Built only from tokens and `.mat`. Not one literal colour, radius or duration
   below — which is what makes a theme change instant and total.

   EVERY INTERACTIVE PRIMITIVE SHIPS EIGHT STATES: default, hover, focus, active,
   disabled, loading, error, selected. Not all eight apply to everything — a
   badge is not focusable — but where one applies and is missing, that is a
   defect rather than a simplification. The three primitives here used to cover
   five between them.

   Two conventions worth knowing before editing:

     `--control-border` IS THE STRUCTURAL EDGE. `--border` separates things and
     may be as quiet as it likes; the visible boundary of an input or a button
     has to clear 3:1 under WCAG 1.4.11, and only `--control-border` is
     contrast-locked to that. The glass rim (`--glass-edge-alpha`) is
     decoration and must never be the only edge a control has.

     LOADING IS NOT DISABLED. They look similar and mean opposite things — one
     says "you may not", the other says "not yet". Rendering an in-flight action
     as disabled tells a screen reader the control is unavailable, and leaves the
     person with no way to know anything is happening.
   ========================================================================== */

@layer eduai.reset {
  /* A FIELDSET IS A GROUPING, NOT A BOX. The browser default draws a groove border
     with the legend notched into it, and inside a glass sheet that reads as a second
     dialog - which is exactly what the note under `.fieldset` in app.css forbids. The
     default has never been wanted anywhere here: `.answer-choices` flattens it by hand
     and `.fieldset` replaces it with a border of its own. Both still win, because
     app.css is unlayered and outranks every `@layer eduai.*` rule.

     Measured in a browser: border 1.6px to 0, padding 5.25px/11.25px to 0, margin 2px
     to 0. */
  fieldset {
    margin: 0;
    padding: 0;
    border: 0;
  }

  legend {
    padding: 0;
  }

  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--seed-font-body);
    font-size: var(--text-base);
    line-height: var(--leading-body);
    -webkit-font-smoothing: antialiased;
  }
}

@layer eduai.components {
  h1,
  h2,
  h3,
  h4 {
    font-family: var(--seed-font-display);
    line-height: var(--leading-tight);
    font-weight: var(--weight-strong);
    text-wrap: balance;
    margin: 0;
  }
  h1 {
    font-size: var(--text-3xl);
    letter-spacing: var(--tracking-tight);
  }
  h2 {
    font-size: var(--text-2xl);
    letter-spacing: var(--tracking-tight);
  }
  h3 {
    font-size: var(--text-xl);
    letter-spacing: var(--tracking-snug);
  }
  h4 {
    font-size: var(--text-lg);
    line-height: var(--leading-snug);
  }

  /* Keyboard focus is never optional, and it reads `--focus-ring` rather than
     `--brand`: the brand is a FILL, chosen to carry a label, and a ring has a
     different obligation — 3:1 against whichever surface it lands on. The
     runtime picks a step that clears that against the worst of them. */
  :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
    border-radius: var(--r-xs);
  }

  /* -----------------------------------------------------------------------
     Label / eyebrow
     -------------------------------------------------------------------- */
  .label {
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    letter-spacing: var(--tracking-normal);
    color: var(--text-tertiary);
  }

  /* A HEADING IS NOT AN EYEBROW. `.label` is the 12px eyebrow role and well over a
     hundred non-heading elements use it correctly - but a large number of card
     titles are written `<h3 className="label">` inside a `.mat`, which is the slot
     the prototype fills with a 20px title in primary text. The element-plus-class
     selector reclaims exactly those and leaves every other `.label` alone. No
     margin here: `.stack` owns the gap and adding one would double it. */
  h1.label,
  h2.label,
  h3.label,
  h4.label {
    font-size: var(--text-lg);
    /* The body's leading, as the prototype's panel heading has it. */
    line-height: var(--leading-body);
    /* Load-bearing for h4 only: `app.css` sets h1-h3 strong from a later layer,
       and h4 is not in that list. */
    font-weight: var(--weight-strong);
    letter-spacing: var(--tracking-xl);
    color: var(--text);
  }

  /* -----------------------------------------------------------------------
     Button
     -------------------------------------------------------------------- */
  .btn {
    --btn-bg: transparent;
    --btn-fg: var(--text);
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    /* `padding-block: 0` with a min-height is what pins a button to exactly the
       control height. Padding plus a line box overshot it, and a bordered variant
       overshot by two more, so a primary and a secondary standing side by side
       measured 34.85 and 36.45 rather than the one height they share. */
    padding: 0 var(--space-4);
    min-height: var(--control-md);
    border: 0;
    border-radius: var(--r-sm);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font: inherit;
    font-weight: var(--weight-medium);
    font-size: var(--text-sm);
    cursor: pointer;
    white-space: nowrap;
    /* The prototype has ONE duration and gives it to hover and press alike;
       `--dur-base` is now that value. At the fast step these read as a flick
       rather than as a settle. */
    transition:
      background-color var(--dur-base) var(--ease-out),
      transform var(--dur-slow) var(--ease-spring),
      box-shadow var(--dur-base) var(--ease-out);
  }

  /* THE SHOWCASE'S BUTTON, as far as CSS can carry it: hover swells to 1.04, press sinks to
     0.97, and both ride a spring rather than an ease. Its own spring is stiffness 150 and
     damping 6 and takes about a second to stop; this reuses the system's `--ease-spring`
     and 420ms, because nothing in this product moves for a second. Hover-capable pointers
     only - on touch a hover state sticks after the tap. */
  @media (hover: hover) {
    .btn:hover:not(:disabled):not([aria-disabled="true"]):not([aria-busy="true"]) {
      transform: scale(1.04);
    }
  }

  .btn--sm {
    min-height: var(--control-sm);
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
  }
  .btn--lg {
    min-height: var(--control-lg);
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-base);
  }

  /* 4 — active */
  .btn:active:not(:disabled):not([aria-busy="true"]) {
    transform: scale(0.97);
  }

  /* 5 — disabled. `[aria-disabled]` too: a control that must stay focusable so
     a screen reader can find it and be told why is marked, not removed. */
  .btn:disabled,
  .btn[aria-disabled="true"] {
    opacity: var(--opacity-disabled);
    cursor: not-allowed;
    transform: none;
  }

  /* 6 — loading. Distinct from disabled: the control keeps its colour and its
     focus, and says that something is in flight. */
  .btn[aria-busy="true"] {
    cursor: progress;
    color: transparent;
  }
  .btn[aria-busy="true"]::after {
    content: "";
    position: absolute;
    inset: 50% auto auto 50%;
    width: var(--icon-sm);
    height: var(--icon-sm);
    margin: calc(var(--icon-sm) / -2) 0 0 calc(var(--icon-sm) / -2);
    border: var(--spinner-stroke) solid currentColor;
    border-top-color: transparent;
    border-radius: var(--r-circle);
    color: var(--btn-fg);
    /* Reads --dur-indicator, which does NOT scale with --motion-scale. Reduced
       motion means replace the animation, not delete the feedback. */
    animation: eduai-spin var(--dur-indicator) linear infinite;
  }

  /* 8 — selected */
  .btn[aria-pressed="true"] {
    --btn-bg: var(--brand-subtle);
    --btn-fg: var(--brand-strong);
  }

  /* The contact shadow is the material's own first layer, read from the tokens rather
     than retyped: `--solid-shadow-1-alpha` is a knob a tenant can take to 0 for a flat
     theme, and a literal alpha here ignored them. It is also mode-aware — 0.05 in light
     against 0.2 in dark — which one number cannot be. */
  .btn--primary {
    --btn-bg: var(--brand);
    --btn-fg: var(--text-on-brand);
    box-shadow: 0 var(--solid-shadow-1-y) var(--solid-shadow-1-blur)
      rgb(var(--shadow-rgb) / var(--solid-shadow-1-alpha));
  }
  .btn--primary:hover:not(:disabled):not([aria-disabled="true"]) {
    --btn-bg: var(--brand-hover);
  }
  .btn--primary:active:not(:disabled) {
    --btn-bg: var(--brand-active);
  }

  .btn--secondary {
    --btn-bg: var(--surface-2);
    /* The structural edge, not the decorative one. */
    border: 1px solid var(--control-border);
  }
  .btn--secondary:hover:not(:disabled):not([aria-disabled="true"]) {
    --btn-bg: var(--surface-3);
  }
  .btn--secondary:active:not(:disabled) {
    --btn-bg: var(--surface-3);
  }

  .btn--ghost {
    --btn-fg: var(--text-secondary);
  }
  .btn--ghost:hover:not(:disabled):not([aria-disabled="true"]) {
    --btn-bg: var(--surface-2);
    --btn-fg: var(--text);
  }
  .btn--ghost:active:not(:disabled) {
    --btn-bg: var(--surface-3);
  }

  /* `--text-on-danger` is chosen per mode by measurement — white in light,
     near-black in dark. Hard-coding white measured 3.33:1 in dark mode. */
  .btn--danger {
    --btn-bg: var(--danger);
    --btn-fg: var(--text-on-danger);
  }
  .btn--danger:hover:not(:disabled):not([aria-disabled="true"]) {
    --btn-bg: var(--danger-hover);
  }
  .btn--danger:active:not(:disabled) {
    --btn-bg: var(--danger-active);
  }

  /* On glass, a secondary button is itself a small piece of glass rather than a
     solid chip — the two materials must not appear on the same surface. The
     border stays `--control-border` regardless, because a rim alone measured
     1.02:1 against the surface behind it. */
  /* ⚠ NOT A GLASS-TINT MIX ANY MORE. These fills were written when the dark
     tint was a near-black, so mixing it in DARKENED the surface. The tint is
     white in both modes now (see `runtime.ts`), and the same mix would light a
     hover up to a pale block. The prototype never used the tint for these: every
     fill and hover in it is `--surface-2`, an opaque plane, and that is a fixed
     pair the contrast lock already knows about. */
  /* ⚠ liqui's BUTTON (owner, 2026-10-03). A glass-family button is liqui's control
     surface: a 12px radius and the catch-light rim on every variant, and the secondary
     variant is a pane of liqui glass - the tint gradient over a frosted sample - rather
     than an opaque fill. Primary and danger stay solid fills: liqui's accent variant is a
     95%-dense tint that reads as solid anyway, and a translucent fill under white label
     text is where this palette measured below AA in the prototype (2.96:1). */
  [data-family="glass"] .btn {
    border-radius: var(--lq-control-radius);
  }
  [data-family="glass"] :is(.btn--primary, .btn--danger) {
    box-shadow: var(--lq-control-shine);
  }
  [data-family="glass"] .btn--secondary {
    --btn-bg: transparent;
    --lq-control-tier: var(--lq-control-tier-base);
    background-image: linear-gradient(
      135deg,
      color-mix(in srgb, var(--lq-tint) calc(var(--lq-control-tier) * 100%), transparent),
      color-mix(in srgb, var(--lq-tint-deep) calc(var(--lq-control-tier) * 100%), transparent)
    ),
    var(--lq-control-wash);
    backdrop-filter: var(--lq-control-filter);
    box-shadow: var(--lq-control-shine);
  }
  [data-family="glass"] .btn--secondary:hover:not(:disabled):not([aria-disabled="true"]) {
    --btn-bg: transparent;
    --lq-control-tier: min(1, calc(var(--lq-control-tier-base) + 0.25));
  }
  [data-family="glass"] .btn--secondary:active:not(:disabled):not([aria-disabled="true"]) {
    --btn-bg: transparent;
    --lq-control-tier: min(1, calc(var(--lq-control-tier-base) + 0.4));
  }
  [data-family="glass"] .btn--ghost:hover:not(:disabled) {
    --btn-bg: var(--surface-2);
  }

  /* An icon-only control still has to be a target. 2.5.8 asks for 24px; touch
     wants 44. This takes the comfortable size and lets a dense context opt down
     through `--seed-density` rather than by hand. */
  .icon-btn {
    display: inline-grid;
    place-items: center;
    width: var(--control-md);
    height: var(--control-md);
    min-width: var(--target-min);
    min-height: var(--target-min);
    padding: 0;
    border: 0;
    border-radius: var(--r-pill);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out);
  }
  .icon-btn:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
  }
  .icon-btn:active:not(:disabled) {
    background: var(--surface-3);
  }
  .icon-btn:disabled {
    opacity: var(--opacity-disabled);
    cursor: not-allowed;
  }

  /* -----------------------------------------------------------------------
     Field
     -------------------------------------------------------------------- */
  .field {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    min-height: var(--control-md);
    border-radius: var(--r-sm);
    /* Was `--border`, which measured 1.02:1 against the surface in the default
       theme — a text input with no perceivable boundary. */
    border: 1px solid var(--control-border);
    background: var(--surface-1);
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
    transition:
      border-color var(--dur-fast) var(--ease-out),
      box-shadow var(--dur-fast) var(--ease-out);
  }
  /* An input and a select are one line centred in a fixed control height, which
     is what `padding-block: 0` plus the min-height gives - with the padding they
     measured 36.45 against a 34px token. A textarea keeps its padding, because
     its text starts at the top edge rather than centring in the box. */
  input.field,
  select.field {
    padding-block: 0;
  }

  /* Its own token rather than `--text-tertiary`: the placeholder is neutral grey
     on purpose, and the tertiary tier is tinted, shared with borders and captions,
     and remapped to secondary inside a `.mat`. See tokens.css. */
  .field::placeholder {
    color: var(--field-placeholder);
  }
  .field:hover:not(:disabled):not([readonly]) {
    border-color: var(--text-tertiary);
  }

  /* 3 — focus.
     NO `outline: none`. The previous rule removed the outline and replaced it
     with a 1px border in `--brand` plus a 22% glow; against the field's own
     background that border measured 1.32:1, so keyboard focus was effectively
     invisible in the default theme. The outline is the indicator; the glow is
     reinforcement on top of it. */
  .field:focus-visible {
    border-color: var(--field-focus-ring);
    box-shadow: 0 0 0 var(--focus-glow-spread)
      color-mix(in oklab, var(--field-focus-ring) 22%, transparent);
  }

  /* 5 — disabled, and 5b — read-only, which is not the same thing. A read-only
     field still holds a value somebody may need to read, so it stays legible. */
  .field:disabled {
    opacity: var(--opacity-disabled);
    cursor: not-allowed;
    background: var(--surface-2);
  }
  .field[readonly] {
    background: var(--surface-2);
    border-color: var(--border);
  }

  /* 7 — error. The border alone is colour-only signalling; the field also gets a
     thicker edge so the state survives a monochrome or colour-blind read. */
  .field[aria-invalid="true"] {
    border-color: var(--danger);
    /* ds-allow-hardcode: exactly double the 1px control border above, and the DOUBLING
       is the signal - a token would name the result and lose the relationship, and the
       line below subtracts the same 1px back out of the padding so the field does not
       change size when it goes invalid. */
    border-width: 2px; /* ds-allow-hardcode */
    padding: calc(var(--space-2) - 1px) calc(var(--space-3) - 1px);
  }
  .field[aria-invalid="true"]:focus-visible {
    box-shadow: 0 0 0 var(--focus-glow-spread)
      color-mix(in oklab, var(--danger) 25%, transparent);
  }

  /* ⚠ liqui's CONTROL GLASS (owner, 2026-10-03). In the glass family every text field and
     select is a pane of liqui glass: the tint gradient over a frosted sample, liqui's 12px
     control radius and its catch-light rim, as in the approved prototype.

     ONE DELIBERATE DEPARTURE: THE BORDER STAYS. liqui's fields have no border - the rim
     alone marks the edge. This product's fields keep `--control-border`, because a field's
     boundary has to hold 3:1 against what is around it (WCAG 1.4.11) and the comment on
     `.field` above records the 1.02:1 input this product once shipped. The focus and error
     states below still colour that border, so all eight states keep working unchanged.

     Disabled and read-only fields keep their opaque fill - they are deliberately not
     inviting input. The sidebar's menu filter keeps its own pane (app.css), by the owner's
     earlier decision for that one control. */
  [data-family="glass"] .field:not(:disabled):not([readonly]):not(.shell__sidebar .field) {
    --lq-control-tier: var(--lq-control-tier-base);
    background-color: color-mix(
      in oklab,
      var(--surface-1) calc(var(--a11y-reduce-transparency) * 100%),
      transparent
    );
    background-image: linear-gradient(
      135deg,
      color-mix(in srgb, var(--lq-tint) calc(var(--lq-control-tier) * 100%), transparent),
      color-mix(in srgb, var(--lq-tint-deep) calc(var(--lq-control-tier) * 100%), transparent)
    ),
    var(--lq-control-wash);
    backdrop-filter: var(--lq-control-filter);
    border-radius: var(--lq-control-radius);
    box-shadow: var(--lq-control-shine);
  }
  [data-family="glass"] .field:not(:disabled):not([readonly]):not(.shell__sidebar .field):focus-visible {
    box-shadow:
      var(--lq-control-shine),
      0 0 0 var(--focus-glow-spread) color-mix(in oklab, var(--field-focus-ring) 22%, transparent);
  }
  [data-family="glass"] .field[aria-invalid="true"]:not(:disabled):not([readonly]):not(.shell__sidebar .field):focus-visible {
    box-shadow:
      var(--lq-control-shine),
      0 0 0 var(--focus-glow-spread) color-mix(in oklab, var(--danger) 25%, transparent);
  }

  /* The control glass, composed once. Declared on the root so a field anywhere - inside a
     dialog, on a card, on the page - reads the same values; the tier attribute on `<html>`
     switches them, exactly as it switches the panels in material.css.

     ⚠ THE TINT GRADIENT IS NOT ONE OF THEM. A custom property that references another is
     resolved where it is DECLARED, so a gradient composed here would freeze the root's
     `--lq-control-tier` and a hovered button could never thicken. The gradient is written
     in each control's own rule instead; only the inputs to it live here. */
  [data-family="glass"] {
    --lq-control-radius: calc(var(--r-anchor) * 0.75);
    --lq-control-tier-base: 0.5125;
    --lq-control-wash: linear-gradient(transparent, transparent);
    --lq-control-shine:
      inset 0 1px 1px var(--lq-rim-hi),
      inset 1px 0 1px var(--lq-rim-spread) color-mix(in srgb, var(--lq-rim-hi) 60%, transparent),
      inset -1px -1px 1px var(--lq-rim-lo);
    --lq-control-filter:
      blur(calc(var(--glass-blur) * (1 - var(--a11y-reduce-transparency) * 0.999)))
      saturate(var(--glass-saturate));
  }
  /* liqui's frost: twice the blur, never under 10px. */
  [data-family="glass"][data-tier="frost"] {
    --lq-control-filter:
      blur(calc(max(var(--glass-blur) * 2, var(--lq-frost-floor)) * (1 - var(--a11y-reduce-transparency) * 0.999)))
      saturate(var(--glass-saturate));
  }
  /* liqui's clear: no sample at all, so the tint runs at full strength over its wash. */
  [data-family="glass"][data-tier="clear"] {
    --lq-control-filter: none;
    --lq-control-tier-base: 1;
    --lq-control-wash: linear-gradient(135deg, var(--lq-wash), var(--lq-wash-deep));
  }

  /* -----------------------------------------------------------------------
     Badge
     -------------------------------------------------------------------- */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--chip-pad-y) var(--space-2);
    border-radius: var(--r-pill);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    background: var(--surface-2);
    color: var(--text-secondary);
    white-space: nowrap;
  }
  /* The TEXT is `-strong`, the FILL is `-subtle`. Pairing an accent with its own
     subtle tint reads well and fails to be readable — the compiler measures
     `-strong` against the flattened fill and picks a step that clears 4.5. */
  .badge--success {
    background: var(--success-subtle);
    color: var(--success-strong);
  }
  .badge--warning {
    background: var(--warning-subtle);
    color: var(--warning-strong);
  }
  .badge--danger {
    background: var(--danger-subtle);
    color: var(--danger-strong);
  }
  .badge--info {
    background: var(--info-subtle);
    color: var(--info-strong);
  }
  .badge--brand {
    background: var(--brand-subtle);
    color: var(--brand-strong);
  }

  /* A dot carries state at a glance where a word would be noise. It is never the
     ONLY carrier — every badge that uses one also has its label. */
  .badge__dot {
    width: var(--dot-size);
    height: var(--dot-size);
    border-radius: var(--r-circle);
    background: currentColor;
    flex: none;
  }

  /* -----------------------------------------------------------------------
     Navigation
     -------------------------------------------------------------------- */
  .nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-3);
    min-height: var(--control-md);
    border-radius: var(--r-sm);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--weight-body);
    text-decoration: none;
    cursor: pointer;
    transition:
      background-color var(--dur-base) var(--ease-out),
      color var(--dur-base) var(--ease-out);
  }
  .nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
  }
  .nav-item:active {
    background: var(--surface-3);
  }
  /* The current page is marked by fill AND weight AND a leading rule, so it does
     not rely on hue alone. */
  /* THE LABEL IS TEXT, NOT BRAND, and the accent rail is why. The rail is a
     solid `--brand` stripe painted inside this element's own box, so a label in
     a neighbouring shade of the same hue is measured against it: the render gate
     samples the worst background pixel in the box and found brand-on-brand at
     1.57 against a 4.5 threshold. The rail already carries the state in a second
     channel, so the label does not need to say it in colour as well. */
  /* THE RAIL SITS BESIDE THE ROW, NOT INSIDE IT.
     As an inset shadow it was painted within this element's own box, so the label
     was measured against a solid brand stripe and the pair failed the render gate
     twice - once at 1.57 when the label was brand-coloured, and again at 3.35
     when the row got shorter and the stripe took a larger share of the box. Drawn
     as a pseudo-element in the gutter it is the same mark in the same place, and
     the row's background is the row's background again. */
  /* A NEUTRAL FILL, NOT A BRAND ONE. The prototype marks the current row with
     `--surface-2` and lets the rail beside it carry the colour, which is both
     what it looks like and the reading that survives measurement: text on
     `--surface-2` is a fixed, known pair, where text on a brand mix depends on
     how much brand the mix resolved to. */
  .nav-item[aria-current="page"] {
    position: relative;
    background: var(--surface-2);
    color: var(--text);
    font-weight: var(--weight-strong);
  }
  .nav-item[aria-current="page"] svg {
    color: var(--brand);
  }
  .nav-item[aria-current="page"]::before {
    content: "";
    position: absolute;
    inset-inline-start: calc(var(--rail-nav-gap) * -1);
    inset-block: var(--space-2);
    inline-size: var(--rail-w);
    border-radius: var(--r-pill);
    background: var(--brand);
  }
  [data-family="glass"] .nav-item:hover {
    background: var(--surface-2);
  }
  /* The glass arm no longer needs its own fill: `--surface-2` is the same mark
     in both families, and it was the brand mix that made this rule necessary. */

  /* -----------------------------------------------------------------------
     Table
     -------------------------------------------------------------------- */
  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
  }
  .table th {
    text-align: left;
    padding: var(--space-2) var(--space-3);
    /* No size, no tracking, no transform: `.table` above already sets 13px, which
       is what the prototype's header inherits from its own table. */
    font-weight: var(--weight-medium);
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border);
  }
  .table td {
    padding: var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
  }
  .table td:first-child {
    color: var(--text);
    font-weight: var(--weight-medium);
  }
  .table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: var(--seed-font-mono);
  }
  .table tbody tr:last-child td {
    border-bottom: 0;
  }
  .table tbody tr[aria-selected="true"] {
    background: var(--brand-subtle);
  }

  /* -----------------------------------------------------------------------
     Progress / meter
     -------------------------------------------------------------------- */
  .meter {
    height: var(--meter-track);
    border-radius: var(--r-pill);
    background: var(--surface-3);
    overflow: hidden;
  }
  .meter__fill {
    height: 100%;
    border-radius: inherit;
    background: var(--brand);
    transition: width var(--dur-slow) var(--ease-out);
  }
  [data-family="glass"] .meter {
    background: var(--surface-2);
    box-shadow: inset 0 0 0 1px rgb(var(--light-rgb) / calc(var(--glass-edge-alpha) * 0.6));
  }

  /* -----------------------------------------------------------------------
     Avatar
     -------------------------------------------------------------------- */
  .avatar {
    display: inline-grid;
    place-items: center;
    width: var(--avatar-md);
    height: var(--avatar-md);
    border-radius: var(--r-pill);
    background: var(--brand-subtle);
    /* `-strong`, not `--brand`. Initials in the accent on its own subtle tint
       measured 3.64:1 in light mode — the same trap the badge rules close. */
    color: var(--brand-strong);
    font-size: var(--text-xs);
    font-weight: var(--weight-strong);
    flex: none;
  }

  /* -----------------------------------------------------------------------
     Divider
     -------------------------------------------------------------------- */
  .rule {
    height: 1px;
    background: var(--border);
    border: 0;
    margin: 0;
  }
  [data-family="glass"] .rule {
    background: rgb(var(--light-rgb) / calc(var(--glass-edge-alpha) * 0.9));
  }

  /* -----------------------------------------------------------------------
     Feedback primitives

     A spinner and a skeleton are the two things every async screen needs and
     neither existed as a token-driven primitive, so each screen invented one.
     -------------------------------------------------------------------- */

  @keyframes eduai-spin {
    to {
      transform: rotate(1turn);
    }
  }
  @keyframes eduai-pulse {
    50% {
      opacity: 0.45;
    }
  }

  .spinner {
    display: inline-block;
    width: var(--icon-md);
    height: var(--icon-md);
    border: var(--spinner-stroke) solid var(--border-strong);
    border-top-color: var(--brand);
    border-radius: var(--r-circle);
    /* Deliberately not `--motion-scale`. See the note on --dur-indicator. */
    animation: eduai-spin var(--dur-indicator) linear infinite;
  }
  .spinner--sm {
    width: var(--icon-sm);
    height: var(--icon-sm);
  }

  /* Under reduced motion the spinner stops turning and pulses instead — still
     unmistakably "working", with no rotation. Removing the feedback entirely,
     which is what freezing it does, is the failure this avoids.

     Which is also why the period is a multiple of `--dur-indicator` and not of any other
     duration token: this is the query that sets `--motion-scale` to 0, and every other
     `--dur-*` would resolve to 0s here and freeze the replacement too. `--ease-in-out`
     rather than the bare keyword, which is a different curve. */
  @media (prefers-reduced-motion: reduce) {
    .spinner {
      animation: eduai-pulse calc(var(--dur-indicator) * 1.5) var(--ease-in-out) infinite;
    }
    .btn[aria-busy="true"]::after {
      animation: eduai-pulse calc(var(--dur-indicator) * 1.5) var(--ease-in-out) infinite;
    }
  }

  .skeleton {
    border-radius: var(--r-sm);
    background: var(--surface-2);
    /* Slower than the spinner's pulse on purpose — a placeholder breathes, it does not
       report progress — but off the same non-scaling indicator duration. */
    animation: eduai-pulse calc(var(--dur-indicator) * 2) var(--ease-in-out) infinite;
  }
  @media (prefers-reduced-motion: reduce) {
    .skeleton {
      animation: none;
      opacity: 0.7;
    }
  }

  /* An empty state owns its viewport rather than floating under the header, and
     it says WHY it is empty. */
  .empty {
    display: grid;
    justify-items: center;
    gap: var(--space-3);
    padding: var(--space-8) var(--space-5);
    text-align: center;
    color: var(--text-secondary);
    max-width: var(--measure-narrow);
    margin-inline: auto;
  }
  .empty__title {
    font-size: var(--text-lg);
    font-weight: var(--weight-strong);
    color: var(--text);
  }

  /* -----------------------------------------------------------------------
     Switch and check

     Both carry `aria-checked`/`aria-pressed` as the source of truth, so the
     visual state and the announced state cannot diverge.
     -------------------------------------------------------------------- */
  .switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: var(--switch-track-w);
    height: var(--target-min);
    padding: 0;
    border: 1px solid var(--control-border);
    border-radius: var(--r-pill);
    background: var(--surface-3);
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease-out);
  }
  .switch::after {
    content: "";
    width: var(--switch-thumb);
    height: var(--switch-thumb);
    margin-inline-start: var(--switch-inset);
    border-radius: var(--r-circle);
    background: var(--surface-1);
    /* Same contact shadow as the primary button, at three times the alpha: the thumb sits
       ON the track it has to be told apart from — a filled one, once checked — rather
       than on the page, so it carries the heavier of the two. Three, not the five that
       would reproduce the old literal 0.25 exactly: the knob runs to 0.3, so five clamps
       at fully opaque across the top half of its range, and a tenant raising contact
       opacity would move every other shadow in the product and not this one. */
    box-shadow: 0 var(--solid-shadow-1-y) var(--solid-shadow-1-blur)
      rgb(var(--shadow-rgb) / calc(var(--solid-shadow-1-alpha) * 3));
    transition: translate var(--dur-fast) var(--ease-out);
  }
  /* THE SHOWCASE'S KNOB: a lens, not a white disc. The driver reads the optics below, builds a
     displacement map at the knob's own 18px and hands the element `--glass-lens`; the values are
     the showcase switch's (26px knob, 7px bezel, 50px slab, refraction 1.3 = 72px) scaled by
     18/26. On the solid family and wherever the driver has not reached, `--glass-lens` is empty
     and the knob is the frosted disc the showcase itself falls back to. */
  [data-family="glass"] .switch {
    --glass-refract: 50px;
    --glass-bezel: 5px;
    --glass-profile: convex;
    --glass-thickness: 35px;
    --glass-dispersion: 0;
  }
  [data-family="glass"] .switch::after {
    /* A veil, not the disc it was: the showcase knob has no fill at all, but a control whose
       thumb is invisible where nothing refracts has no visible state, so a fifth of the surface
       colour stays. Reduce-transparency takes it back to fully opaque. */
    background: color-mix(in oklab, var(--surface-1) calc(22% + var(--a11y-reduce-transparency) * 78%), transparent);
    backdrop-filter: blur(3px) saturate(1.3) var(--glass-lens, );
    box-shadow:
      inset 0 0 0 1px rgb(var(--light-rgb) / 0.3),
      0 1px 4px rgb(var(--shadow-rgb) / 0.3);
  }
  .switch[aria-checked="true"] {
    background: var(--brand);
    border-color: var(--brand);
  }
  .switch[aria-checked="true"]::after {
    translate: var(--switch-travel) 0;
  }
  .switch:disabled {
    opacity: var(--opacity-disabled);
    cursor: not-allowed;
  }

  /* -----------------------------------------------------------------------
     Layout helpers
     -------------------------------------------------------------------- */
  .stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  .row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }
  .row--between {
    justify-content: space-between;
  }
  /* 20px. Every panel and every counted tile in the prototype is `var(--s5)`; at
     16 the content sat noticeably tighter to the rim than the reference. */
  .pad {
    padding: var(--space-5);
  }
  /* 24px - the prototype's most generous inset, which it gives the sheet. */
  .pad-lg {
    padding: var(--space-6);
  }
  .muted {
    color: var(--text-secondary);
  }
  .tiny {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
  }
  /* ⚠ PUTS BACK WHAT `.tiny` TAKES AWAY, AND IT HAS TO LIVE HERE. `.tiny` is a TEXT
     utility that also sets a colour; `.btn` sets `color: var(--btn-fg)` above, at the
     same specificity and earlier in the file, so on `class="btn tiny"` — 66 call sites —
     the utility won and the button lost the foreground its own variant chose. On a ghost
     that is invisible, both being quiet text. On a FILLED variant it is tertiary grey on
     a brand or danger fill: the contrast gate measures 1.32:1 in dark and 1.57:1 in
     light, against a 4.5 threshold at this size, twelve failures across the four themes.
     The worst call site is the attendance register's SELECTED status, which is the one
     control telling a teacher what they just marked.

     `--btn-fg` rather than a literal, so each variant keeps its own answer: the ghost's
     label moves from `--text-tertiary` to the `--text-secondary` every full-size ghost
     button already uses, which is agreement rather than a new decision.

     ⚠ AND NOT IN `app.css`, WHICH IS WHERE IT WAS FIRST WRITTEN AND WHERE IT LOOKED LIKE
       IT WORKED. The app loads that file so the screens were fixed — but the contrast
       gate renders tokens, material and components ALONE, and `theme-system/` is
       generated from these three. A fix a layer too high repairs the product and leaves
       both the gate and the standalone studio broken, which is the shape of a fix that
       comes back. */
  .btn.tiny {
    color: var(--btn-fg);
  }
  .mono {
    font-family: var(--seed-font-mono);
    font-variant-numeric: tabular-nums;
  }
  .grow {
    flex: 1;
    min-width: 0;
  }
  .prose-measure {
    max-width: var(--measure-prose);
  }

  /* -----------------------------------------------------------------------
     Forced colours

     Same reasoning as in material.css: every boundary here is a border or a
     shadow that high contrast mode discards or repaints. The controls need a
     real edge in a system colour, and the focus ring has to survive.
     -------------------------------------------------------------------- */
  @media (forced-colors: active) {
    .btn,
    .field,
    .switch,
    .icon-btn {
      border: 1px solid ButtonText;
      forced-color-adjust: none;
      background: ButtonFace;
      color: ButtonText;
    }
    .btn--primary {
      background: Highlight;
      color: HighlightText;
      border-color: Highlight;
    }
    .badge {
      border: 1px solid CanvasText;
      background: Canvas;
      color: CanvasText;
    }
    .nav-item[aria-current="page"] {
      background: Highlight;
      color: HighlightText;
      box-shadow: none;
    }
    .meter__fill,
    .switch[aria-checked="true"] {
      background: Highlight;
    }
    :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
      outline-color: Highlight;
    }
  }
}
