/* T01b — screen-specific styles, ported from legacy styles.css onto design tokens.
   Layout shell, dashboard tiles, question/session, setups, sim, progress, review,
   history. Focus rings are handled by :focus-visible in the base layer. */

@layer screens {
  /* ---- App shell layout ----
     Brand + navigation live in the shell chrome only (styles/components.css:
     .shell-topbar and the desktop .shell-rail logo), so there is no in-flow
     page header any more. */

  .app-main {
    max-width: 800px;
    /* Centred reading column. The desktop rail gutter is applied to <body>
       (components.css), NOT as a margin on .app-main: @layer screens outranks
       @layer components, so the `margin: 0 auto` here would cancel any
       `margin-left` set on .app-main there. */
    margin: 0 auto;
    padding: var(--sp-6) var(--sp-4) calc(72px + env(safe-area-inset-bottom, 0px));
    /* `clip`, not `hidden`: overflow-x: hidden computes overflow-y to auto,
       which turns .app-main into a scroll container and silently kills every
       position: sticky inside it (the simulation's clock bar). */
    overflow-x: clip;
  }

  /* ---- In-flow heading ----
     The page name is the bar's h1 unless the screen renders one itself (§4.3), so
     this class is left for the one
     heading that is content rather than a title: the study screen's
     "Question not found" state. It keeps its own air under the sticky bar. */

  .screen-title {
    max-width: 760px;
    margin: var(--sp-5) auto var(--sp-1);
  }

  .screen-hint {
    max-width: 760px;
    margin: 0 auto var(--sp-6);
  }

  /* ---- Action bar ----
     The bar's own chrome (fixed position, padding, button widths) is shell code in
     components.css; only its alignment is screen-level. One centred cluster of
     actions at every width: @layer screens is declared after @layer components, so
     this beats both the base `justify-content: flex-end` and the ≤480px `stretch`
     rule there, and it does so without touching that file. */

  .action-bar:not(.action-bar--inline) { justify-content: center; }

  @media (min-width: 1024px) {
    .action-bar:not(.action-bar--inline) { justify-content: center; }
  }

  /* Three 160px actions plus their gaps need ~536px of bar. Under that a centred
     row spills off BOTH edges and clips the primary action, so from the fixed bar's
     own mobile breakpoint up to that width the buttons share the row instead — the
     same treatment components.css gives the bar under 480px. */
  @media (max-width: 560px) {
    .action-bar:not(.action-bar--inline) button { flex: 1 1 auto; min-width: 0; }
  }

  /* From 1024px the bar is inline under the card instead (shell.js moves it), and
     as a footer it spans the card it follows — so it takes that card's max-width.
     The 760px question cards need no rule: that is the inline default. */
  .learn-setup + .action-bar--inline { max-width: 760px; }
  .sim-setup + .action-bar--inline { max-width: 760px; }
  .topic-list + .action-bar--inline,
  .review-list + .action-bar--inline { max-width: 760px; }

  /* ---- Dashboard tiles ---- */

  .tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--sp-3);
  }

  .tile {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 64px;
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--ink);
    text-align: center;
    font-weight: 600;
    font-size: var(--fs-body);
    text-decoration: none;
    box-shadow: var(--shadow-1);
    transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
  }

  @media (hover: hover) and (pointer: fine) {
    .tile:hover {
      border-color: var(--accent);
      box-shadow: var(--shadow-2);
      transform: translateY(-1px);
    }
  }

  .tile-title { display: block; }

  /* ---- Session persistence & history ---- */

  .resume-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    max-width: 760px;
    margin: 0 auto var(--sp-5);
    padding: 14px var(--sp-4);
    background: var(--accent-soft);
    border: 1px solid var(--accent-border);
    border-radius: var(--r-sm);
  }

  .resume-banner-title { color: var(--accent-strong); font-size: var(--fs-body); }

  .resume-banner-text { flex: 1 1 100%; margin: 0; color: var(--ink); }

  .history-delta {
    margin: 0 0 10px;
    color: var(--ink);
    font-weight: 600;
  }

  .history-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
  }

  .history-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-1);
    overflow: hidden;
    transition: border-color var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-fast) var(--ease-out);
  }

  @media (hover: hover) and (pointer: fine) {
    .history-item:hover {
      border-color: var(--accent);
      box-shadow: var(--shadow-2);
    }
    .history-row:hover {
      background: var(--surface-2);
    }
  }

  .history-item.is-open {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-2);
  }

  .history-item--active {
    border-color: color-mix(in oklab, var(--accent) 45%, var(--border));
    background: color-mix(in oklab, var(--accent) 4%, var(--surface));
  }

  .history-mode-row {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
  }

  .history-row {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    min-height: 56px;
    padding: var(--sp-3) var(--sp-4);
    font: inherit;
    text-align: left;
    background: transparent;
    color: var(--ink);
    border: none;
    border-radius: 0;
    cursor: pointer;
    box-shadow: none;
    transition: background-color var(--dur-fast) var(--ease-out);
  }

  .history-row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }

  .history-item.is-open .history-row {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }

  .history-row-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .history-mode {
    font-weight: 700;
    font-size: var(--fs-body);
    line-height: 1.3;
    color: var(--ink);
  }

  .history-meta {
    color: var(--muted);
    font-size: var(--fs-sm);
    line-height: 1.3;
  }

  .history-acc {
    margin-left: auto;
    font-family: var(--font-display, inherit);
    font-size: var(--fs-body);
    font-weight: 700;
    color: var(--ink);
    white-space: nowrap;
  }

  .history-chevron {
    flex: none;
    transition: border-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out);
  }

  .history-chevron .icon {
    transition: transform var(--dur-med) var(--ease-out);
  }

  .history-item.is-open .history-chevron .icon,
  .history-row.is-open .history-chevron .icon {
    transform: rotate(180deg);
  }

  .history-row:hover .history-chevron,
  .history-item.is-open .history-chevron,
  .history-row.is-open .history-chevron {
    color: var(--accent);
    border-color: var(--accent);
  }

  .history-detail {
    padding: var(--sp-4);
    background: var(--surface-2);
    animation: history-detail-in 200ms var(--ease-out);
  }

  @keyframes history-detail-in {
    from {
      opacity: 0;
      transform: translateY(-4px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  .history-detail-title { margin: 0 0 6px; font-size: var(--fs-body); }

  .history-detail p { margin: var(--sp-1) 0; }

  .history-questions {
    margin: var(--sp-2) 0 0;
    padding-left: 18px;
  }

  .history-question {
    display: flex;
    gap: 10px;
    align-items: baseline;
    padding: 3px 0;
  }

  .history-q-prompt { flex: 1; color: var(--ink); }
  .history-q-status { color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }

  /* ---- Learn / Practice setup ---- */

  .learn-setup {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    max-width: 760px;
    margin: 0 auto;
    padding: var(--sp-6);
  }

  .filter-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .filter-label {
    font-weight: 600;
    font-size: var(--fs-body);
    color: var(--ink);
  }

  .filter-count { margin: 0; color: var(--muted); font-weight: 600; }
  .filter-empty { margin: 0; color: color-mix(in oklab, var(--danger) 80%, var(--ink)); font-weight: 600; }

  /* ---- Setup controls (T05): segmented + searchable topic filter ---- */

  .seg {
    display: inline-flex;
    background: var(--surface-2);
    border-radius: var(--r-md);
    padding: 4px;
    gap: 4px;
  }
  .seg-option {
    /* 44px on BOTH axes — a "10"/"20" count option was 39px wide (§7.1). */
    min-height: 44px;
    min-width: 44px;
    padding: 0 var(--sp-4);
    border: none;
    border-radius: calc(var(--r-md) - 4px);
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  }
  @media (hover: hover) and (pointer: fine) {
    .seg-option:hover { color: var(--ink); }
  }
  .seg-option.is-active {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-1);
  }

  /* The review categories carry five long labels plus their counts, which no
     phone width fits on one line — so this control stacks into full-width rows. */
  @media (max-width: 560px) {
    .seg--stack { display: flex; flex-direction: column; width: 100%; }
    .seg--stack .seg-option { flex: 1; text-align: left; }
  }

  /* ---- Single-choice picker (the topic filter) ----
     A field, not a pill: it reads as "this is what is selected, tap to change",
     and it costs one line of the card however many topics the bank grows to. */
  .picker-trigger {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    min-height: 44px;
    padding: 0 var(--sp-3);
    font: inherit;
    font-weight: 600;
    text-align: left;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
  }
  @media (hover: hover) and (pointer: fine) {
    .picker-trigger:hover { background: var(--surface-2); }
  }
  .picker-trigger:focus-visible { border-color: var(--accent); }
  .picker-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .picker-trigger .icon { flex: none; color: var(--muted); }

  /* The sheet body is a scroll container, so it clips anything drawn outside a
     child's border box — the focused field's 3px halo included, which made the
     ring read as cut off on three sides. The padding gives it room to draw. */
  .picker-sheet { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-1); }
  .picker-option {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    min-height: 44px;
    padding: 0 var(--sp-2);
    font: inherit;
    font-weight: 600;
    text-align: left;
    color: var(--ink);
    background: transparent;
    border: none;
    border-radius: var(--r-xs);
    cursor: pointer;
  }
  @media (hover: hover) and (pointer: fine) {
    .picker-option:hover { background: var(--surface-2); }
  }
  .picker-option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .picker-option.is-active { color: var(--accent-strong); }
  .picker-option .icon { margin-left: auto; flex: none; }
  .picker-empty { margin: var(--sp-2) 0; color: var(--muted); font-size: var(--fs-sm); }

  .topic-filter { display: flex; flex-direction: column; gap: var(--sp-3); }

  .search-wrap { position: relative; }
  .search-wrap .icon {
    position: absolute; left: var(--sp-3); top: 50%;
    transform: translateY(-50%); color: var(--muted);
  }
  input.search {
    min-height: 44px;
    width: 100%;
    padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-7);
    font: inherit;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink);
  }
  /* Focus on a text field, exactly as the sign-in email field does it: the
     border turns accent and a 3px halo at 20% accent wraps it. One soft edge —
     no outline ring, no gap. Lives here, not in base.css, because this layer
     owns the field's border and would otherwise win over any base-layer focus
     rule. */
  input.search,
  textarea {
    outline: none;
    transition: border-color var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-fast) var(--ease-out);
  }
  input.search:focus,
  textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 20%, transparent);
  }
  @media (forced-colors: active) {
    /* Forced colors drop box-shadow, so the halo is gone there: a real ring. */
    input.search:focus,
    textarea:focus {
      outline: 2px solid CanvasText;
      outline-offset: 0;
    }
  }

  .chip-cloud { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
  .chip.is-active { outline: 2px solid var(--accent); }
  button.chip { cursor: pointer; font: inherit; min-height: 44px; padding: 0 var(--sp-4); }
  /* The tick a picked topic carries (multi-select, not a radio). */
  .chip.is-active .icon { margin-left: var(--sp-2); }

  /* "+N more topics" opens the checkbox sheet over the full list. */
  .chip-more { align-self: center; color: var(--muted); font-size: var(--fs-xs); font-weight: 600; }
  button.chip-more {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 var(--sp-4);
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-full);
    background: transparent;
    font: inherit;
    cursor: pointer;
    transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
  }
  @media (hover: hover) and (pointer: fine) {
    button.chip-more:hover { color: var(--accent-strong); border-color: var(--accent); }
  }

  /* Topic sheet: one tap row per topic (label wraps the checkbox). */
  .topic-sheet {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 55vh;
    overflow-y: auto;
  }
  .topic-sheet-row {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-height: 44px;
    padding: 0 var(--sp-2);
    border-radius: var(--r-xs);
    cursor: pointer;
  }
  @media (hover: hover) and (pointer: fine) {
    .topic-sheet-row:hover { background: var(--surface-2); }
  }
  .topic-sheet-row input { flex: none; width: 18px; height: 18px; accent-color: var(--accent); }
  .topic-sheet-name { color: var(--ink); }

  /* ---- Chips ---- */

  .chip {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 var(--sp-3);
    border-radius: var(--r-full);
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: var(--fs-xs);
    font-weight: 600;
    border: none;
  }
  /* Status labels on soft fills mix toward --ink (the pattern .q-error /
     .speech-status already use): raw --success and --warn are 3.53:1 and
     3.46:1 on their own tint in light; the 80/20 mix restores 4.87 / 4.79 and
     lifts dark too (6.72 / 7.02), because --ink is the readable end there. */
  .chip-easy { background: var(--success-soft); color: color-mix(in oklab, var(--success) 80%, var(--ink)); }
  .chip-medium { background: var(--accent-soft); color: var(--accent-strong); }
  .chip-hard { background: var(--danger-soft); color: var(--danger); }
  .chip-topic {
    background: var(--ink);
    color: var(--surface);
    font-family: var(--font-display);
    font-weight: 800;
    font-size: var(--fs-xs);
    letter-spacing: 0.03em;
    min-height: 28px;
    padding: 2px var(--sp-3);
    box-shadow: var(--shadow-1);
  }

  /* ---- Question / session screen ---- */

  .q-card {
    max-width: 760px;
    margin: 0 auto;
    padding: var(--sp-6);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-2);
  }

  .q-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-top: var(--sp-2);
    flex-wrap: wrap;
  }

  .retry-summary-link {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1-5);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--primary);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    padding: 4px 10px;
    cursor: pointer;
    text-decoration: none;
    min-height: 28px;
    white-space: nowrap;
    touch-action: manipulation;
  }
  @media (hover: hover) {
    .retry-summary-link:hover {
      background: var(--surface-3);
      color: var(--primary-strong);
    }
  }
  .retry-summary-link:active {
    transform: scale(0.97);
  }

  .q-meta {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    color: var(--muted);
    font-size: var(--fs-sm);
    flex-wrap: wrap;
  }

  /* Per-question progress segments. */
  .q-progress {
    display: flex;
    gap: 3px;
    margin: var(--sp-4) 0;
  }
  /* Empty segments: an ink-tinted well instead of --border, which all but
     vanishes against dark --surface (1.3:1). Same base as the heatmap ramp. */
  .q-progress-seg {
    flex: 1;
    min-width: 4px;
    height: 6px;
    border-radius: var(--r-full);
    background: color-mix(in oklab, var(--ink) 12%, var(--surface));
    transition: background var(--dur-med) var(--ease-out);
  }
  .q-progress-seg.is-done { background: var(--accent); }
  /* The "current" halo rides on --surface, not --accent-soft: the halo's job is
     to read on the card in both themes (accent-soft is a 1.16:1 no-op on dark). */
  .q-progress-seg.is-current {
    background: var(--accent-strong);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 30%, var(--surface));
  }
  .q-progress-seg.is-marked { background: var(--marker); }

  .q-text {
    margin: 0 0 var(--sp-5);
    font-size: var(--fs-q);
    font-weight: 600;
    line-height: 1.45;
    text-wrap: pretty;
  }

  /* ---- Question / session screen ---- */

  .question-card {
    max-width: 760px;
    margin: 0 auto;
    padding: var(--sp-6);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-2);
  }

  .q-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin: var(--sp-3) 0 var(--sp-4);
  }

  .q-prompt {
    margin: 0 0 var(--sp-5);
    font-size: var(--fs-q);
    font-weight: 600;
    line-height: 1.5;
  }

  .q-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .q-error {
    margin: 0;
    color: color-mix(in oklab, var(--danger) 80%, var(--ink));
    font-size: var(--fs-sm);
    font-weight: 600;
  }

  /* ---- Session summary: see styles/summary.css ---- */

  /* ---- Weak Topics ---- */

  .weak-topic-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 760px;
    margin: 0 auto var(--sp-5);
  }

  .weak-topic-row {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    padding: var(--sp-3) var(--sp-4);
    font: inherit;
    text-align: left;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    cursor: pointer;
    box-shadow: var(--shadow-1);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
  }

  @media (hover: hover) and (pointer: fine) {
    .weak-topic-row:hover {
      border-color: var(--accent);
      box-shadow: var(--shadow-2);
    }
  }

  .weak-topic-name { flex: 1; font-weight: 600; }
  .weak-topic-accuracy { color: color-mix(in oklab, var(--danger) 80%, var(--ink)); font-weight: 700; white-space: nowrap; }
  .weak-topic-attempts { color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }

  /* ---- Review Mistakes ---- */

  .review-section { margin: 0 auto var(--sp-6); max-width: 760px; }

  .review-section-title { margin: 0 0 10px; font-size: var(--fs-h2); }

  .review-empty { margin: 0; color: var(--muted); }

  .review-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 760px;
    margin: 0 auto;
  }

  .app-main > .filter-control {
    max-width: 760px;
    margin: 0 auto var(--sp-4);
  }

  .review-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--sp-4);
    width: 100%;
    padding: var(--sp-3) var(--sp-4);
    font: inherit;
    text-align: left;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    cursor: pointer;
    box-shadow: var(--shadow-1);
    transition: border-color 140ms var(--ease-out), box-shadow 140ms var(--ease-out);
  }

  @media (hover: hover) and (pointer: fine) {
    .review-row:hover {
      border-color: var(--accent);
      box-shadow: var(--shadow-2);
    }

    .review-row:hover .review-row-icon {
      color: var(--accent);
      border-color: var(--accent);
      background: var(--accent-soft);
      transform: translateX(2px);
    }
  }

  .review-row-icon {
    flex-shrink: 0;
    align-self: center;
    color: var(--muted);
    transition: color 140ms var(--ease-out), background 140ms var(--ease-out), border-color 140ms var(--ease-out), transform 140ms var(--ease-out);
  }

  .review-row-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    flex: 1;
    min-width: 0;
    text-align: left;
  }

  .review-row-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2);
  }

  .review-prompt {
    line-height: 1.4;
    font-weight: 600;
    color: var(--ink);
    text-align: left;
    text-wrap: pretty;
  }

  .review-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    text-align: left;
  }

  .review-topic { color: var(--muted); font-size: var(--fs-sm); font-weight: 500; }
  .review-count { color: var(--accent-strong); font-size: var(--fs-xs); font-weight: 700; }

  /* ---- Progress dashboard ---- */

  .progress-section { margin: 0 auto var(--sp-6); max-width: 760px; }
  .progress-section-title { margin: 0 0 10px; font-size: var(--fs-h2); }
  .progress-empty { margin: 0; color: var(--muted); }

  .stat-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: var(--sp-2) 0;
    border-bottom: 1px solid var(--border);
  }

  .stat-label { color: var(--ink); font-weight: 600; }
  .stat-value { color: var(--muted); }

  /* Link text on the Progress card: --accent is 3.27:1 on --surface, the
     strong step is 5.84:1 and keeps the accent hue. */
  .stat-link {
    color: var(--accent-strong);
    font-weight: 700;
    text-decoration: none;
  }
  @media (hover: hover) and (pointer: fine) {
    .stat-link:hover { color: var(--accent-strong); text-decoration: underline; }
  }

  .ptable {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    overflow: hidden;
  }

  .ptable-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
  }

  .ptable-row + .ptable-row { border-top: 1px solid var(--border); }
  .ptable-header { background: var(--surface-2); font-weight: 700; }

  .ptable-cell {
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--fs-sm);
    overflow-wrap: anywhere;
  }

  /* ---- Knowledge Check Simulation ---- */

  /* Setup: the paper format as one row per section. */
  .sim-setup { max-width: 760px; }
  .sim-setup-lede { margin: 0 0 var(--sp-4); color: var(--muted); }
  .sim-format {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 0 var(--sp-2);
  }
  .sim-format-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
  }
  .sim-format-title { font-weight: 600; font-size: var(--fs-sm); }
  .sim-format-meta { color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }

  /* Run: sticky bar under the shell topbar — clock · question map · autosave.
     z-index stays below --z-topbar (40) so the topbar paints over it. */
  .sim-topbar {
    --sim-bar-bg: color-mix(in oklab, var(--surface) 92%, transparent);
    position: sticky;
    top: var(--topbar-h);
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-3);
    margin: 0 0 var(--sp-4);
    padding: var(--sp-2) var(--sp-3);
    background: var(--sim-bar-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-1);
  }

  .sim-timer {
    padding: 4px 12px;
    border-radius: var(--r-full);
    background: var(--surface-2);
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
    transition: background var(--dur-med) var(--ease-out), color var(--dur-med) var(--ease-out);
  }
  .sim-timer.is-warn { background: var(--warn-soft); color: color-mix(in oklab, var(--warn) 80%, var(--ink)); }
  .sim-timer.is-danger {
    background: var(--danger-soft);
    color: var(--danger);
    animation: sim-pulse 1s var(--ease-inout) infinite;
  }
  @keyframes sim-pulse {
    /* Floor 0.82: at the old 0.72 the dark danger label dipped to 2.98:1 on
       its own tint mid-pulse; 0.82 keeps it above 3:1 at every frame. */
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.045); opacity: 0.82; }
  }
  /* base.css already neutralises animations under reduced motion; the explicit
     guard keeps the danger state readable as a colour change only. */
  @media (prefers-reduced-motion: reduce) {
    .sim-timer.is-danger { animation: none; }
  }

  /* Question map: one 28px chip per question of the current section.
     A 44px chip is impossible here — a section is ~20-30 questions and the map
     lives in the sticky bar (30 × 50px pitch = 1500px). This is the deliberate
     §7.1 exception: WCAG 2.2 AA (2.2.1) needs 24px and is met, the hit area is
     grown to the full 34px pitch (chip 28 + gap 6) so no two targets overlap,
     and every chip has an equivalent ≥44px path (Prev/Next + the marked/finish
     buttons in the action bar). */
  .sim-map {
    display: flex;
    flex: 1 1 200px;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }
  .sim-map-btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 28px; height: 28px;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-xs);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: var(--fs-xs);
    font-weight: 700;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
  }
  .sim-map-btn::before {
    content: "";
    position: absolute;
    inset: -3px;
  }
  @media (hover: hover) and (pointer: fine) {
    .sim-map-btn:hover { border-color: var(--accent); }
  }
  .sim-map-btn.is-answered {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent-strong);
  }
  .sim-map-btn.is-answered .icon {
    position: absolute;
    top: -5px; right: -5px;
    padding: 1px;
    border-radius: var(--r-full);
    background: var(--surface);
    color: var(--success);
  }
  /* Marked: a warn dot, so a chip can be answered AND flagged. */
  .sim-map-btn.is-marked::after {
    content: "";
    position: absolute;
    bottom: -4px; right: -4px;
    width: 8px; height: 8px;
    border-radius: var(--r-full);
    background: var(--warn);
    box-shadow: 0 0 0 2px var(--surface);
  }
  .sim-map-btn.is-current { outline: 2px solid var(--accent); outline-offset: 1px; }

  /* The map wrapper exists on every width; the arrows are the phone line's
     affordance and stay out of the layout until the media query below. */
  .sim-map-wrap { display: flex; flex: 1 1 200px; min-width: 0; }
  .sim-map-arrow { display: none; }

  /* Autosave: hidden until a write flashes it. The label is real text on the
     cream topbar, so it takes the same 80/20 ink mix as the other status words. */
  .sim-saved {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    color: color-mix(in oklab, var(--success) 80%, var(--ink));
    font-size: var(--fs-xs);
    font-weight: 700;
    opacity: 0;
    /* A status flash, never a target: at rest it is transparent but still covers
       the right end of the phone strip, where it ate the taps meant for the
       arrow and the last chip. */
    pointer-events: none;
  }
  .sim-saved.is-on { animation: saved-flash 1.2s var(--ease-out); }
  @keyframes saved-flash {
    0% { opacity: 0; transform: translateY(2px); }
    12% { opacity: 1; transform: none; }
    70% { opacity: 1; }
    100% { opacity: 0; }
  }

  /* Phone: the run bar is one compact line — clock, then the question numbers in
     a scrollable row that holds the current chip in view. The ends fade into an
     arrow, and only where there is more to scroll, so the first question shows
     just the right one. From here up the chips wrap and the arrows never appear. */
  @media (max-width: 639px) {
    .sim-topbar { flex-wrap: nowrap; gap: var(--sp-2); padding: var(--sp-2); }
    .sim-timer { flex: 0 0 auto; padding: 2px 9px; font-size: 1.0625rem; }
    .sim-map-wrap { display: flex; align-items: stretch; gap: 2px; flex: 1 1 auto; min-width: 0; }
    .sim-map {
      flex: 1 1 auto;
      min-width: 0;
      flex-wrap: nowrap;
      overflow-x: auto;
      scrollbar-width: none;
      /* The answered check is drawn above and the marked dot below the chip, and
         a scroll container clips them, so the line keeps that much air. */
      padding: 6px 2px;
      /* The chips dissolve at the end that has more to scroll, so the edge reads
         as "continues" rather than "ends here". */
      -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 14px), transparent);
      mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 14px), transparent);
    }
    .sim-map-wrap.has-more-prev .sim-map {
      -webkit-mask-image: linear-gradient(to right, transparent, #000 14px, #000 calc(100% - 14px), transparent);
      mask-image: linear-gradient(to right, transparent, #000 14px, #000 calc(100% - 14px), transparent);
    }
    .sim-map::-webkit-scrollbar { display: none; }
    .sim-map-btn { flex: 0 0 28px; }
    /* The arrows sit beside the row, never on top of it: a chip under an arrow
       could not be tapped, and the button stole the drag that scrolls the line.
       They appear only where there is more to scroll. */
    .sim-map-arrow {
      display: none;
      flex: 0 0 30px;
      place-items: center;
      padding: 0;
      border: 0;
      background: transparent;
      color: var(--muted);
      cursor: pointer;
    }
    .sim-map-wrap.has-more-prev .sim-map-arrow--prev,
    .sim-map-wrap.has-more-next .sim-map-arrow--next { display: grid; }
    /* The autosave flash has no room on this line: pinned to the right corner it
       sat on top of the arrow, and its class outlives the animation, so the
       arrow stayed hidden after the first answer. On a phone the answered chip
       tinting + check IS the save confirmation, and the sr-only region still
       announces it, so the corner flash is dropped here. */
    .sim-saved { display: none; }
  }

  .sim-q-index { color: var(--muted); font-size: var(--fs-sm); font-weight: 600; }

  /* Review summary card: headline score, then one row per section. */
  .sim-score-card {
    max-width: 760px;
    margin: 0 auto var(--sp-4);
    padding: var(--sp-4) var(--sp-5) var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-1);
  }
  .sim-score-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--sp-3);
  }
  .sim-score-total {
    margin: 0;
    font-family: var(--font-display);
    font-size: var(--fs-h1);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.01em;
  }
  .sim-score-bonus {
    padding: 2px 10px;
    border-radius: var(--r-full);
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: var(--fs-sm);
    font-weight: 700;
  }
  .sim-score-meta {
    margin: 2px 0 var(--sp-4);
    color: var(--muted);
    font-size: var(--fs-sm);
  }
  .sim-score-rows { display: flex; flex-direction: column; gap: var(--sp-3); }
  /* [name + n/m][pts] with the pts/max bar under the text. */
  .sim-score-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--sp-1) var(--sp-3);
  }
  .sim-score-mid { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .sim-score-name { color: var(--ink); font-weight: 600; font-size: var(--fs-sm); }
  .sim-score-sub { color: var(--muted); font-size: var(--fs-sm); }
  .sim-score-meta { color: var(--ink); font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; grid-column: 3; }
  .sim-score-bar {
    grid-column: 2 / -1;
    height: 6px;
    border-radius: var(--r-full);
    /* Unfilled track must survive dark: --surface-2 is 1.17:1 on the card. */
    background: color-mix(in oklab, var(--ink) 12%, var(--surface));
    overflow: hidden;
  }
  .sim-score-bar-fill {
    display: block;
    height: 100%;
    border-radius: var(--r-full);
    background: var(--accent);
    transition: width var(--dur-med) var(--ease-out);
  }

  /* Review is grouped: the summary card, then one block per section. The block is
     a flex column, so `gap` is the question-to-question rhythm; the head's own top
     margin is what separates one section from the next. */
  .sim-section-block {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
  }

  /* Multiple Choice ......... 18 / 24 pts */
  .sim-section-head {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    margin: var(--sp-5) 0 var(--sp-1);
  }
  .sim-section-name {
    font-family: var(--font-display);
    font-size: var(--fs-h2);
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--ink);
  }
  /* Pushed to the end of the row; a long section name never squeezes the read-out. */
  .sim-section-meta {
    margin-left: auto;
    color: var(--muted);
    font-size: var(--fs-sm);
    font-weight: 600;
    white-space: nowrap;
  }
  /* On the run screen the same row sits under the sticky clock bar, which already
     carries a bottom margin — the section spacing must not double up there. */
  .sim-topbar + .sim-section-head { margin-top: 0; }

  /* One card per question: header (label + status), answer, verdict, sources. */
  .sim-q-card {
    max-width: 760px;
    /* No bottom margin inside a section block: the flex gap is the rhythm. */
    margin: 0 auto;
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-1);
  }
  .sim-q-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    margin-bottom: var(--sp-3);
  }
  .sim-q-label {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    color: var(--muted);
    font-size: var(--fs-sm);
    font-weight: 600;
  }
  /* The format name lives on the section head, not on every question card, so
     it is stated once per block. */
  .sim-q-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: var(--r-full);
    background: var(--surface-2);
    color: var(--muted);
    font-size: var(--fs-xs);
    font-weight: 700;
  }
  .sim-q-status.is-correct { background: var(--success-soft); color: color-mix(in oklab, var(--success) 80%, var(--ink)); }
  .sim-q-status.is-partial { background: var(--warn-soft); color: color-mix(in oklab, var(--warn) 80%, var(--ink)); }
  .sim-q-status.is-incorrect { background: var(--danger-soft); color: var(--danger); }

  .sim-q-text {
    margin: 0 0 var(--sp-4);
    font-size: var(--fs-q);
    font-weight: 600;
    line-height: 1.45;
    text-wrap: pretty;
  }

  .sim-q-answer {
    margin: 0 0 var(--sp-3);
    padding: var(--sp-3);
    background: var(--surface-2);
    border-radius: var(--r-sm);
  }
  .sim-q-answer-label {
    display: block;
    margin-bottom: var(--sp-1);
    color: var(--muted);
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .sim-q-answer-text {
    margin: 0;
    color: var(--ink);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  .sim-q-card .choices {
    margin-bottom: var(--sp-3);
  }

  .sim-q-ungraded { margin: var(--sp-2) 0; color: var(--muted); font-size: var(--fs-sm); }

  .sim-q-ask {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-3);
    margin: var(--sp-3) 0 var(--sp-2);
  }
  .sim-q-ask-note { color: var(--muted); font-size: var(--fs-sm); font-weight: 600; }

  .sim-q-list { margin: var(--sp-2) 0; padding-left: var(--sp-5); }

  /* ---- Knowledge Check Simulation AI check ---- */

  .sim-checking {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 36px var(--sp-5);
    text-align: center;
  }

  .spinner-lg { width: 28px; height: 28px; border-width: 3px; }

  .sim-checking-status { color: var(--muted); font-size: var(--fs-body); margin: 0; }

  .ai-check-block {
    margin: 10px 0;
    padding: 10px var(--sp-3);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface-2);
  }

  .ai-check-block p { margin: var(--sp-1) 0; }

  .ai-check-loading { display: flex; align-items: center; gap: var(--sp-2); }

  .ai-check-badge {
    display: inline-block;
    font-size: var(--fs-sm);
    font-weight: 700;
    padding: 2px var(--sp-2);
    border-radius: var(--r-full);
    margin-bottom: var(--sp-1);
  }

  .ai-check-got_it { background: var(--success-soft); color: color-mix(in oklab, var(--success) 80%, var(--ink)); }
  .ai-check-partial { background: var(--warn-soft); color: color-mix(in oklab, var(--warn) 80%, var(--ink)); }
  .ai-check-didnt_know { background: var(--danger-soft); color: color-mix(in oklab, var(--danger) 80%, var(--ink)); }

  .ai-check-feedback { font-style: italic; }
  .ai-check-fallback { color: var(--muted); font-size: var(--fs-sm); }

  /* ---- Responsive (screen-level) ---- */

  @media (max-width: 520px) {
    /* The tab bar clearance lives in the footer's own bottom padding, so the
       column keeps a normal rhythm here; session screens (focus mode) still
       need room for the fixed action bar. */
    .app-main { padding: var(--sp-4) var(--sp-3) var(--sp-5); }
    body.focus-mode .app-main { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
    .question-card { padding: var(--sp-4); }
    .sim-score-card { padding: var(--sp-4); }
    .sim-q-card { padding: var(--sp-3) var(--sp-4); }
    .tile-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    /* The dashboard card grid collapses in the narrow block below, which is
       declared after `.card-grid` and therefore actually wins. */
    .ptable-cell { padding: 6px var(--sp-2); font-size: var(--fs-xs); }
    .stat-row { flex-direction: column; gap: 2px; }
  }

  @media (max-width: 380px) {
    .question-card { padding: 14px var(--sp-3); }
    .ptable-cell { padding: 5px 6px; }
  }

  /* ---- Decision dashboard (T03) ---- */

.hero {
  padding: clamp(var(--sp-7), 4vw, var(--sp-8)) 0 clamp(var(--sp-7), 4vw, var(--sp-8));
}
.hero-title {
  margin: 0 0 var(--sp-5);
  font-size: clamp(1.85rem, 3.8vw + 0.8rem, 3.15rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.hero-tagline {
  display: block;
}
.hero-mark {
  position: relative;
  white-space: nowrap;
}
.hero-marker {
  position: absolute;
  left: 0;
  bottom: -0.12em;
  width: 100%;
  height: 0.32em;
  color: var(--marker);
  /* The 6-unit stroke of the path reaches y 14.55 in a 12-unit viewBox, so the
     root svg's default hidden overflow cuts its bottom (and both end caps). */
  overflow: visible;
}
.hero-sub {
  margin: 0;
  font-size: clamp(1.025rem, 0.8vw + 0.85rem, 1.15rem);
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 580px;
}
.resume-strip { margin: 0 0 var(--sp-4); }
.resume-strip-btn { display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 52px; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--accent-border); background: var(--accent-soft); border-radius: var(--r-md); color: var(--ink); font-weight: 600; font-size: var(--fs-body); cursor: pointer; }
.resume-strip-btn .badge { margin-left: auto; }
.card-grid { container-type: inline-size; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.mode-card { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: var(--sp-3); min-height: 132px; padding: var(--sp-4); border-radius: var(--r-lg); text-decoration: none; color: var(--ink); transition: transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out); }
@media (hover: hover) and (pointer: fine) {
  .mode-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
}
.mode-card:active { transform: scale(.985); }
.mode-card--learn { grid-column: auto; background: var(--accent-soft); }
.mode-card--practice { background: var(--tint-blue); }
.mode-card--quiz { background: var(--tint-yellow); }
.mode-card--podcasts,
.mode-card--podcast { background: color-mix(in oklab, var(--success-soft) 85%, var(--surface)); }
/* Sim keeps the row layout: icon tile, text, chevron pushed to the end. */
.mode-card--sim { grid-column: 1 / -1; display: flex; flex-direction: row; align-items: center; gap: var(--sp-3); min-height: 72px; background: var(--surface); border: 1px solid var(--border); }
/* Text block owns column 1; `min-width: 0` keeps a long title from sliding
   under the illustration in column 2. */
.mode-card-text { grid-column: 1; grid-row: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--sp-1); }
.mode-card h2 { margin: 0; font-size: var(--fs-h1); font-weight: 800; }
.mode-card p { margin: 0; color: var(--ink-soft); font-size: var(--fs-sm); }
/* Illustration is a static grid item (was absolute, sitting on top of the
   arrow icon): right column, bottom-aligned, never clickable. */
.mode-card .illo { grid-column: 2; grid-row: 1 / span 2; width: 96px; height: 72px; justify-self: end; align-self: end; pointer-events: none; }
.mode-card--sim .illo { display: none; }
.icon-tile { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: var(--r-xs); background: var(--accent-soft); color: var(--accent-strong); flex: none; }
.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 0 var(--sp-2); border-radius: var(--r-full); background: var(--surface-2); color: var(--ink-soft); font-size: var(--fs-xs); font-weight: 600; }
.badge-warn { background: var(--warn-soft); color: color-mix(in oklab, var(--warn) 80%, var(--ink)); }
.mode-card > .badge { position: absolute; top: var(--sp-3); right: var(--sp-3); }
.section-title { margin: 0 0 var(--sp-3); font-size: var(--fs-h2); font-weight: 700; }
.section-title.has-subtitle,
.section-title:has(+ .section-subtitle) { margin-bottom: 4px; }
.section-subtitle {
  margin: 0 0 var(--sp-3);
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.4;
}
/* One column on a phone: a tile carries a number, a two-line topic name, a due
   badge and a chevron, and two columns squeeze the name into three lines. From
   the desktop gutter up there is room for two again. */
.topic-grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-3); margin-bottom: var(--sp-5); }
@media (min-width: 1024px) {
  .topic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* The grid is capped at six tiles and the toggle continues it, so the grid
   gives back most of its bottom air to that button. */
.topic-grid:has(+ .topic-grid-more) { margin-bottom: var(--sp-2); }
.topic-grid-more { width: 100%; }
.topic-chip { position: relative; display: flex; align-items: center; gap: var(--sp-2); min-width: 0; min-height: 64px; padding: var(--sp-3) var(--sp-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); text-decoration: none; color: var(--ink); }
.topic-num { position: relative; flex-shrink: 0; font-family: var(--font-display); font-weight: 800; font-size: var(--fs-h1); }
.topic-bar { position: absolute; left: 0; right: 0; bottom: -4px; height: 3px; border-radius: 2px; background: var(--marker); }
.topic-label { color: var(--muted); font-size: var(--fs-sm); line-height: 1.2; }
.topic-chip > .badge { margin-left: auto; flex-shrink: 0; }
/* Chip affordance is the shared white circle (--sm), tinted to the chip ink. */
.topic-chip > .icon-circle { margin-left: auto; color: var(--ink-soft); flex-shrink: 0; }
.topic-chip > .badge + .icon-circle { margin-left: 0; }
/* Card affordance: text in row 1, arrow circle in row 2 under it. The arrow used
   to be absolutely positioned in the same corner as the illustration, so it was
   invisible; the circle is a normal grid item now. */
.mode-card > .icon-circle { grid-column: 1; grid-row: 2; justify-self: start; align-self: start; margin-top: var(--sp-2); color: var(--ink); }
.mode-card--sim > .icon-circle { grid-column: auto; grid-row: auto; margin: 0 0 0 auto; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-6); }
.list-row { display: flex; align-items: center; gap: var(--sp-3); min-height: 56px; padding: var(--sp-2) var(--sp-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); text-decoration: none; color: var(--ink); }
.list-title { font-weight: 600; }
.list-row > .badge { margin-left: auto; }
/* The chevron is the end-of-row affordance on every row, so it needs
   `margin-left: auto` itself: only the badge had it, which left a row without a
   badge ("Progress") hugging its title. Mirrors `.topic-chip`. Scoped to `.list`
   (dashboard-only) so the column-flow `.review-row` keeps its own placement. */
.list > .list-row > .icon-circle { margin-left: auto; }
.list > .list-row > .badge + .icon-circle { margin-left: 0; }
.list-row > .icon-circle:last-child { color: var(--muted); }

/* ---- "How it works" section (dashboard tail) ----
   No band background: the section sits on the page and the two steps are tiles
   in the same language as the cards above. Typography first — an oversized
   numeral, one sentence, one drawing, one link. */
.how { margin: var(--sp-7) 0 0; }
.how-eyebrow { margin: 0 0 var(--sp-2); color: var(--accent-strong); }
.how-title { margin: 0 0 var(--sp-2); font-family: var(--font-display); font-size: var(--fs-h1); font-weight: 800; letter-spacing: -0.02em; }
.how-lede { margin: 0 0 var(--sp-4); max-width: 52ch; color: var(--muted); }
.how-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-3); margin: 0 0 var(--sp-4); padding: 0; list-style: none; }
.how-steps > li { display: flex; }
.how-step { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-2); width: 100%; height: 100%; padding: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); text-decoration: none; color: var(--ink); box-sizing: border-box; transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
.how-num { font-family: var(--font-display); font-size: 2rem; font-weight: 800; line-height: 1; letter-spacing: -0.03em; color: var(--accent); }
.how-step h3 { margin: 0; font-size: var(--fs-h2); font-weight: 800; }
.how-step p { margin: 0; color: var(--muted); font-size: var(--fs-sm); line-height: 1.5; }
.how-art { width: 64px; height: 48px; margin-top: auto; }
.how-go { display: inline-flex; align-items: center; gap: 6px; color: var(--accent-strong); font-size: var(--fs-sm); font-weight: 700; }
@media (hover: hover) and (pointer: fine) {
  .how-step:hover { border-color: var(--accent-border); box-shadow: var(--shadow-1); }
  .how-step--static:hover { border-color: var(--border); box-shadow: none; }
  .how-step:hover .how-go { text-decoration: underline; }
}
.how-foot { margin: 0; color: var(--muted); font-size: var(--fs-xs); }
@media (max-width: 767px) {
  .how-steps { grid-template-columns: 1fr; }
}

/* ---- Dashboard, narrow screens ----
   Declared after the base `.card-grid` / `.mode-card` rules above on purpose:
   an `@media` block earlier in this layer loses the same-specificity tie to
   them, so the two-up grid used to survive down to 390px and left Practice and
   Quick Quiz a ~37px text column (subtitle broken to one word per line).
   One card per row all the way to the 640px container query that turns the grid
   two-up again — below it the 96px illustration always squeezes the text column
   too far. Under 480px the card itself tightens as well. */

@media (max-width: 639px) {
  .card-grid { grid-template-columns: 1fr; }
}

@media (max-width: 479px) {
  .mode-card { min-height: 112px; }
  .mode-card .illo { width: 72px; height: 54px; }
  .mode-card h2 { font-size: 1.55rem; }
  .mode-card p { font-size: var(--fs-sm); }
  /* No `.mode-card-text { min-width: 0 }` here: the wrapper already declares it
     above, which is what keeps a long title out of the illustration column. */
  /* Columns stay one-up here (see `.topic-grid` above); only the tile tightens. */
  .topic-grid { gap: var(--sp-2); }
  .topic-chip { padding: var(--sp-2) 10px; min-height: 56px; gap: 6px; }
  .topic-num { font-size: 1.35rem; }
  .topic-label { font-size: var(--fs-xs); line-height: 1.15; }
  .topic-chip > .badge { padding: 0 5px; font-size: 11px; min-height: 20px; }
  .topic-chip > .icon-circle { width: 24px; height: 24px; }
}

@container (min-width: 640px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .mode-card--learn { grid-column: auto; }
  .topic-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

.screen-dashboard .mode-card, .screen-dashboard .topic-chip, .screen-dashboard .list-row { animation: rise-in 320ms var(--ease-out) backwards; }
.screen-dashboard .card-grid > *:nth-child(2) { animation-delay: 40ms; }
.screen-dashboard .card-grid > *:nth-child(3) { animation-delay: 80ms; }
.screen-dashboard .card-grid > *:nth-child(4) { animation-delay: 120ms; }
.screen-dashboard .card-grid > *:nth-child(5) { animation-delay: 160ms; }
.screen-dashboard .topic-grid > *:nth-child(2) { animation-delay: 40ms; }
.screen-dashboard .topic-grid > *:nth-child(3) { animation-delay: 80ms; }
.screen-dashboard .topic-grid > *:nth-child(4) { animation-delay: 120ms; }
.screen-dashboard .topic-grid > *:nth-child(5) { animation-delay: 160ms; }
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- 404 Not Found screen ---- */

.not-found-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--topbar-h) - var(--sp-12));
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
}

.not-found-card {
  width: 100%;
  max-width: 540px;
  padding: var(--sp-7) var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
  animation: rise-in 300ms var(--ease-out);
}

.not-found-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 2px dashed var(--border-strong);
  color: var(--accent);
  margin-bottom: var(--sp-1);
}

.not-found-status {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--accent);
}

.not-found-title {
  margin: 0;
  font-size: var(--fs-xl);
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.not-found-desc {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-base);
  line-height: 1.5;
  max-width: 420px;
}

.not-found-path {
  display: inline-block;
  padding: 2px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  font-family: var(--font-mono, monospace);
  font-size: 0.9em;
  color: var(--ink);
  word-break: break-all;
}

.not-found-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
  width: 100%;
}

.not-found-suggestions {
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
  width: 100%;
}

.not-found-suggestions-label {
  display: block;
  margin-bottom: var(--sp-3);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.not-found-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: center;
}

.not-found-link-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-decoration: none;
  transition: background 140ms var(--ease-out), border-color 140ms var(--ease-out), color 140ms var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .not-found-link-chip:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
  }
}

/* Touch active feedback for screens on mobile */
@media (hover: none), (pointer: coarse) {
  .tile:active,
  .history-row:active,
  .mode-card:active,
  .weak-topic-row:active,
  .review-row:active,
  .not-found-link-chip:active {
    transform: scale(0.985);
    transition: transform 80ms var(--ease-out);
  }
}
}

/* ---- Forced colors (high contrast) ----
   Unlayered, so it outranks @layer screens. Every card/row whose only edge in
   our theme is a fill or a shadow gets a CanvasText border back; the accent
   state marks (.chip.is-active outline, .sim-map-btn.is-current) keep working
   as Highlight edges instead. */
@media (forced-colors: active) {
  .mode-card, .list-row, .topic-chip, .tile, .history-item, .history-row, .review-row,
  .weak-topic-row, .session-review-row, .q-card, .question-card, .sim-q-card,
  .sim-score-card, .card, .panel, .sim-format-row, .not-found-card, .not-found-link-chip,
  .podcast-header-card, .podcast-player-dock, .podcast-search-bar, .podcast-transcript-wrap, .podcast-turn, .podcast-episode-card {
    border: 1px solid CanvasText;
  }
  .chip.is-active, .sim-map-btn.is-current { outline: 2px solid CanvasText; }
  .sim-map-btn.is-answered { border-color: Highlight; }
  .q-progress-seg, .mastery-seg, .hm-cell, .sim-score-bar {
    outline: 1px solid CanvasText;
  }
  .topic-bar, .hero-marker { background: CanvasText; color: CanvasText; }
}
