/* app/styles/worksheet.css — builder chrome (screen only).
 *
 * Line 1 pulls print.css in FOR SCREEN so the live preview is styled by the
 * exact same rules that will print. print.css is also linked separately with
 * media="print" in worksheet.html; that copy carries @page and the
 * print-only overrides.
 *
 * Everything this file defines itself lives inside @media screen, so the
 * builder UI contributes ZERO declarations to the print cascade — in
 * particular the preview's scale transform simply does not exist when the
 * page is printed.
 */

@import url("print.css") screen;

@media screen {

  /* ---------------------------------------------------------------- tokens */
  :root {
    /* Page geometry comes from print.css's --page-* block (imported above),
       which is the same set of numbers the @page rule uses. The only two
       numbers the PREVIEW adds are the gap drawn between sheets and the
       strip of space under each one that carries its "Page n of N" label —
       neither of which exists on paper. --page-pitch (one sheet plus its
       gutter) is the stride the fragmentainer, the paper layer and
       worksheet.js all step by. */
    --sheet-gutter: 18mm;
    --sheet-labelh: 9mm;
    --page-pitch: calc(var(--page-w) + var(--sheet-gutter));

    --accent: #4f46e5;
    --accent-dark: #4338ca;
    --accent-soft: #eef2ff;
    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-2: #cbd5e1;
    --pane-bg: #f1f5f9;
    --warn: #b45309;
    --warn-bg: #fef3c7;
    --danger: #dc2626;
    --rail-w: 320px;
    --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  }

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

  html, body { height: 100%; }

  body {
    margin: 0;
    display: flex;
    flex-direction: column;
    font-family: var(--ui);
    font-size: 13.5px;
    color: var(--ink);
    background: #fff;
    -webkit-font-smoothing: antialiased;
  }

  .sr-only {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  /* ====================================================== row 1: options
     Everything that describes the SHEET, on one 40px line. The whole point
     of the two-bar layout is preview area, so nothing in here may wrap:
     .optbar is a nowrap flex row that CLIPS its own overflow, and
     reflowOptbar() in app/worksheet.js watches for that overflow and moves
     whole .optbar__grp nodes into .optbar__pop (which is a sibling of the
     bar, precisely so the bar's overflow:hidden cannot clip the menu). */
  .optbar {
    flex: none;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px;
    height: 40px;
    padding: 0 10px;
    border-bottom: 1px solid var(--line);
    background: #fff;
    overflow: hidden;
    position: relative;
    z-index: 5;
  }

  .optbar__grp {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }

  .optbar__grp--title {
    flex: 0 1 210px;
    min-width: 110px;
  }
  .optbar__grp--title input {
    height: 28px;
    padding: 0 8px;
    font-size: 13px;
    font-weight: 600;
  }

  .optbar__lbl {
    flex: none;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
  }

  .optbar select {
    width: auto;
    height: 28px;
    padding: 0 6px;
    font-size: 12.5px;
  }

  .optbar .seg { padding: 1px; }
  .optbar .seg button { padding: 3px 9px; font-size: 12px; }

  .optbar .check { font-size: 12px; white-space: nowrap; gap: 6px; }
  .optbar .check input { width: 14px; height: 14px; }

  .optbar .seed-row input {
    height: 28px;
    width: 92px;
    font-size: 12px;
    letter-spacing: 0.04em;
  }
  .optbar .seed-row button { height: 28px; width: 28px; font-size: 14px; }

  .optbar__spacer { flex: 1 1 0; min-width: 0; }

  .optbar__actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .optbar .btn {
    flex: 0 0 auto;
    font-size: 12.5px;
    padding: 5px 10px;
  }
  .optbar .btn:disabled { opacity: 0.55; cursor: default; }

  /* ----------------------------------------------------- overflow popover */
  .optbar__more { flex: 0 0 auto; }
  .optbar__more[hidden] { display: none; }

  .optbar__morebtn {
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    height: 28px;
    padding: 0 9px;
    border: 1px solid var(--line-2);
    border-radius: 8px;
    background: #fff;
    color: var(--ink-2);
    cursor: pointer;
    white-space: nowrap;
  }
  .optbar__morebtn:hover { background: #f8fafc; color: var(--ink); }
  .optbar__morebtn[aria-expanded="true"] {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-dark);
  }
  .optbar__moren {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
  }
  .optbar__morebtn[aria-expanded="true"] .optbar__moren { color: var(--accent-dark); }

  /* position: fixed, placed by JS under the More button — it must escape
     .optbar's overflow:hidden, so it is a SIBLING of the bar, not a child. */
  .optbar__pop {
    position: fixed;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    min-width: 210px;
    max-width: min(300px, calc(100vw - 20px));
    padding: 12px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 34px rgba(15, 23, 42, 0.18);
  }
  .optbar__pop[hidden] { display: none; }
  .optbar__pop .optbar__grp {
    flex: 0 0 auto;
    justify-content: space-between;
    gap: 10px;
  }
  .optbar__pop .seed-row { flex: 0 1 auto; }
  .optbar__pop select { flex: 0 1 auto; min-width: 0; }

  /* ==================================================== row 2: worksheets
     Chrome's tab strip: rounded tops, the active tab white and joined to the
     pane below it, the rest translucent on the grey rail. */
  .tabstrip {
    flex: none;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 33px;
    padding: 4px 10px 0;
    background: var(--pane-bg);
    border-bottom: 1px solid var(--line);
    position: relative;
    z-index: 4;
  }

  .wstabs {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    flex: 0 1 auto;
    min-width: 0;
    height: 29px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .wstabs::-webkit-scrollbar { height: 0; }

  .wstab {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    position: relative;
    height: 27px;
    min-width: 104px;
    max-width: 220px;
    padding: 0 6px 0 11px;
    border: 0;
    border-radius: 9px 9px 0 0;
    font-size: 12.5px;
    color: var(--ink-2);
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
  }
  .wstab__label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }

  .wstab__n {
    flex: 0 0 auto;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.07);
    font-size: 11px;
    line-height: 16px;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
  }
  .wstab__n:empty { display: none; }

  /* The thin divider Chrome draws between inactive tabs. */
  .wstab + .wstab::before {
    content: "";
    position: absolute;
    left: -2px;
    top: 8px;
    bottom: 8px;
    width: 1px;
    background: var(--line-2);
  }
  .wstab:hover { background: rgba(255, 255, 255, 0.6); }
  .wstab:hover::before, .wstab:hover + .wstab::before { background: transparent; }

  .wstab.is-on {
    background: #fff;
    color: var(--ink);
    font-weight: 650;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.14);
  }
  .wstab.is-on .wstab__n { background: var(--accent-soft); color: var(--accent-dark); }
  .wstab.is-on::before, .wstab.is-on + .wstab::before { background: transparent; }
  .wstab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

  .wstab__x {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font: inherit;
    font-size: 14px;
    line-height: 1;
    color: var(--muted);
    background: none;
    cursor: pointer;
  }
  .wstab__x:hover { background: #e2e8f0; color: var(--danger); }
  .wstab.is-on .wstab__x:hover { background: var(--accent-soft); }

  .wstab__rename {
    font: inherit;
    font-size: 12.5px;
    width: 130px;
    min-width: 0;
    height: 20px;
    padding: 0 4px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: #fff;
    color: var(--ink);
  }

  .tabstrip__btn {
    flex: 0 0 auto;
    align-self: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font: inherit;
    font-size: 15px;
    line-height: 1;
    color: var(--ink-2);
    background: none;
    cursor: pointer;
  }
  .tabstrip__btn:hover { background: rgba(255, 255, 255, 0.85); color: var(--accent); }
  .tabstrip__btn:disabled { opacity: 0.35; cursor: default; background: none; }

  .tabstrip__spacer { flex: 1 1 0; min-width: 0; }

  .tabstrip__link {
    flex: 0 0 auto;
    align-self: center;
    padding: 4px 8px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 550;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
  }
  .tabstrip__link:hover { background: rgba(255, 255, 255, 0.85); color: var(--accent); }

  /* ----------------------------------------------------------- two panes */
  .builder {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
  }

  .rail {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 14px 40px;
    border-right: 1px solid var(--line);
    background: #fff;
  }

  .rail__sec {
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
  }
  .rail__sec:last-child { border-bottom: 0; }

  .rail__sec h2 {
    margin: 0 0 9px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .rail__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 9px;
  }
  .rail__head h2 { margin: 0; }

  /* ---------------------------------------------------------------- fields */
  .field { display: block; margin-bottom: 10px; }
  .field:last-child { margin-bottom: 0; }

  .field__label {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 550;
    color: var(--ink-2);
  }

  .field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
  }
  .field-row .field__label { margin-bottom: 0; }

  input[type="text"],
  input[type="number"],
  select {
    width: 100%;
    font: inherit;
    font-size: 13px;
    color: var(--ink);
    padding: 6px 8px;
    border: 1px solid var(--line-2);
    border-radius: 7px;
    background: #fff;
  }

  input[type="text"]:focus-visible,
  input[type="number"]:focus-visible,
  select:focus-visible,
  button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
  }

  input.is-bad,
  input.is-bad:focus-visible {
    border-color: var(--danger);
    outline-color: var(--danger);
    background: #fef2f2;
  }

  .check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--ink-2);
    cursor: pointer;
  }
  .check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

  .hint {
    margin: 6px 0 0;
    font-size: 11.5px;
    color: var(--muted);
  }

  /* --------------------------------------------------------- segmented set */
  .seg {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--line-2);
    border-radius: 8px;
    background: #f8fafc;
  }

  .seg button {
    font: inherit;
    font-size: 12.5px;
    font-weight: 550;
    color: var(--ink-2);
    padding: 4px 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
  }
  .seg button:hover { color: var(--ink); }
  .seg button.is-on {
    background: #fff;
    color: var(--accent);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
  }

  /* ----------------------------------------------------------------- chips */
  .chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 11.5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }
  .chip.is-warn { background: var(--warn-bg); color: var(--warn); }
  .chip.is-empty { background: #f1f5f9; color: var(--muted); }

  .warn {
    margin: 9px 0 0;
    padding: 7px 9px;
    border-radius: 7px;
    background: var(--warn-bg);
    color: var(--warn);
    font-size: 11.5px;
    line-height: 1.35;
  }

  /* ------------------------------------------------------------ skill tree */
  .tree { margin: 0 -4px; }

  .lvl, .tpc { border-radius: 8px; }

  .lvl > summary,
  .tpc > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .lvl > summary::-webkit-details-marker,
  .tpc > summary::-webkit-details-marker { display: none; }

  .lvl > summary::before,
  .tpc > summary::before {
    content: "";
    flex: none;
    width: 0;
    height: 0;
    border-left: 4.5px solid currentColor;
    border-top: 3.5px solid transparent;
    border-bottom: 3.5px solid transparent;
    opacity: 0.55;
    transition: transform 0.12s ease;
  }
  .lvl[open] > summary::before,
  .tpc[open] > summary::before { transform: rotate(90deg); }

  .lvl > summary {
    padding: 6px 4px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .lvl > summary:hover { color: var(--ink-2); }

  .lvl__count {
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    color: var(--accent);
  }
  .lvl__count:empty { display: none; }

  .tpc { margin: 0 0 2px 6px; }

  .tpc > summary {
    padding: 5px 4px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-2);
  }
  .tpc > summary:hover { color: var(--ink); }

  .tpc__ref {
    margin-left: auto;
    padding: 1px 6px;
    border-radius: 4px;
    background: #f1f5f9;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    color: var(--muted);
  }

  /* Whole-chapter switch. It sits inside the <summary>, after the disclosure
     triangle and before the topic name; worksheet.js stops its click from
     reaching the summary so ticking it never collapses the topic. */
  .tpc__cb {
    flex: none;
    width: 14px;
    height: 14px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
  }

  .tpc.is-chapter > summary { color: var(--accent-dark); }
  .tpc.is-chapter > summary .tpc__name { font-weight: 700; }

  .skills { padding: 1px 0 6px 12px; }

  .skill {
    padding: 2px 0;
    border-left: 2px solid transparent;
    padding-left: 6px;
  }
  .skill.is-on { border-left-color: var(--accent); }

  .skill__row {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    padding: 3px 0;
    cursor: pointer;
  }

  .skill__cb {
    flex: none;
    width: 14px;
    height: 14px;
    margin: 1px 0 0;
    accent-color: var(--accent);
  }

  .skill__title {
    flex: 1 1 auto;
    font-size: 12.5px;
    line-height: 1.3;
    color: var(--ink-2);
  }
  .skill.is-on .skill__title { color: var(--ink); font-weight: 550; }

  .skill__info {
    flex: none;
    width: 14px;
    height: 14px;
    margin-top: 1px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #475569;
    font-size: 9.5px;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
    cursor: help;
  }

  .skill__opts {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0 5px 21px;
  }
  .skill__opts[hidden] { display: none; }

  /* ---------------------------------------------------- per-tier counters
     One small counter per tier the skill supports, plus Mix — so a single
     skill can contribute e.g. 5 × T1 + 5 × T2 + 5 × T3. */
  .tiercounts {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 6px;
    min-width: 0;
  }

  .tc {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px 2px 7px;
    border: 1px solid var(--line-2);
    border-radius: 7px;
    background: #fff;
    cursor: default;
  }
  .tc.is-nonzero {
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  .tc__lbl {
    font-size: 10.5px;
    font-weight: 700;
    color: var(--ink-2);
    letter-spacing: .02em;
  }
  .tc.is-nonzero .tc__lbl { color: var(--accent-dark); }

  .tc__n {
    width: 40px;
    height: 24px;
    padding: 0 2px;
    border: 0;
    background: transparent;
    text-align: center;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
  }
  .tc__n:focus { outline: none; }
  .tc:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
  }

  /* --------------------------------------------------- whole-chapter row
     One TOTAL per tier for the entire topic, spread over its learning
     outcomes so every LO appears at least once. Deliberately built from the
     same .tiercounts / .tc / .tc__lbl / .tc__n parts as the per-skill
     steppers — it is the same kind of control, one level up. */
  .chapter {
    margin: 2px 0 6px 22px;
    padding: 8px 9px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--accent-soft);
  }
  .chapter[hidden] { display: none; }

  .chapter .tc { background: #fff; }

  /* A tier total too small to reach every LO. Amber, and never on its own —
     the .chapter__warn sentence below says the same thing in words. */
  .chapter .tc.is-short,
  .chapter .tc.is-short.is-nonzero {
    border-color: var(--warn);
    background: var(--warn-bg);
  }
  .chapter .tc.is-short .tc__lbl { color: var(--warn); }

  .chapter__hint { color: var(--ink-2); }

  .chapter__warn {
    margin: 7px 0 0;
    padding: 6px 8px;
    border-radius: 6px;
    background: var(--warn-bg);
    color: var(--warn);
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.35;
  }
  /* Empty is the resting state: the node stays in the DOM so role="status"
     is already a live region when the text arrives. Generated content does
     not defeat :empty. */
  .chapter__warn:empty { display: none; }
  .chapter__warn::before { content: "\26A0\FE0E\00A0\00A0"; }

  /* --------------------------------------------------- LOs under a chapter
     The rows stay visible — they ARE the chapter's list of learning outcomes
     — but the chapter owns allocation, so the steppers go and the checkboxes
     lock. Each LO instead shows what it was given. */
  .tpc.is-chapter .skill__opts { display: none; }
  .tpc.is-chapter .skill__row { cursor: default; }
  .skill__cb:disabled { cursor: default; }

  .skill.is-locked .skill__title { color: var(--muted); }
  .skill.is-locked.is-alloc { border-left-color: var(--accent); }
  .skill.is-locked.is-alloc .skill__title { color: var(--ink-2); font-weight: 550; }

  .skill__alloc {
    padding: 0 0 3px 21px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .02em;
    color: var(--accent-dark);
    font-variant-numeric: tabular-nums;
  }
  .skill__alloc:empty { display: none; }
  .skill.is-locked:not(.is-alloc) .skill__alloc { color: var(--muted); font-weight: 550; }

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

  /* The two print-dialog settings CSS genuinely cannot pin down. Paper size
     is the printer's, not the document's: pick Letter and Chromium shrinks
     the whole A4 sheet to 94% and every measurement on it with it. Headers
     and footers are on by default and stamp the date, title, URL and page
     number into the margins — they do not move the worksheet, but they are
     not in the preview either. Everything else (margins, scale) the @page
     rule already wins outright, measured. */
  .print-note {
    margin: 0;
    font-size: 11px;
    line-height: 1.45;
    color: var(--muted);
  }
  .print-note strong { color: var(--ink-2); font-weight: 650; }

  .btn {
    flex: 1 1 auto;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 10px;
    border: 1px solid var(--line-2);
    border-radius: 8px;
    background: #fff;
    color: var(--ink-2);
    cursor: pointer;
    white-space: nowrap;
  }
  .btn:hover { background: #f8fafc; color: var(--ink); }

  .btn--primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
  }
  .btn--primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }

  /* Word export. Green so the two download buttons are told apart at a glance
     rather than by reading them. #15803d on white is 4.5:1 (AA) and the same
     green already used by .btn.is-done. */
  .btn--docx {
    border-color: #15803d;
    background: #15803d;
    color: #fff;
  }
  .btn--docx:hover { background: #126734; border-color: #126734; color: #fff; }

  .btn.is-done {
    border-color: #16a34a;
    background: #f0fdf4;
    color: #15803d;
  }

  .seed-row { display: flex; gap: 6px; }

  .seed-row input {
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .seed-row button {
    flex: none;
    width: 34px;
    font: inherit;
    font-size: 15px;
    line-height: 1;
    border: 1px solid var(--line-2);
    border-radius: 7px;
    background: #fff;
    color: var(--ink-2);
    cursor: pointer;
  }
  .seed-row button:hover { background: var(--accent-soft); color: var(--accent-dark); }

  /* --------------------------------------------------------------- recents */
  .recents { list-style: none; margin: 0; padding: 0; }

  .recents__empty {
    margin: 0;
    font-size: 11.5px;
    color: var(--muted);
  }

  .recent__btn {
    display: block;
    width: 100%;
    text-align: left;
    font: inherit;
    padding: 6px 8px;
    margin-bottom: 2px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    cursor: pointer;
  }
  .recent__btn:hover { background: #f8fafc; }

  .recent__title {
    display: block;
    font-size: 12.5px;
    font-weight: 550;
    color: var(--ink-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .recent__meta {
    display: block;
    margin-top: 1px;
    font-size: 11px;
    color: var(--muted);
  }

  /* ---------------------------------------------------- preview + scaler */
  .preview-pane {
    overflow: auto;
    /* Reserve the scrollbar gutter permanently. Without it the fit-to-width
       scale and the scrollbar can chase each other: smaller scale -> shorter
       sheet -> scrollbar disappears -> pane wider -> bigger scale -> ... */
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
    padding: 24px;
    background: var(--pane-bg);
  }

  /* ------------------------------------------------- the paginated preview
     The preview used to be one continuous 210mm-wide strip with cut guides
     ruled across it every 271mm. That model was a LIE: nothing in it broke.
     A question straddling a guide printed whole on the next page (pushing
     everything after it down by up to a full question), and with two columns
     the strip balanced the whole sheet into two full-height columns — so the
     preview read 1..12 down the left while the printer put 1..5 | 6..10 on
     page one. Measured on a 24-question two-column sheet: 22 of 24 questions
     printed on a different page, or at a different height, than previewed.

     What replaced it: .ws-flow is a multi-column fragmentainer exactly one
     page's CONTENT BOX in size (--page-cw x --page-ch) with column-fill:auto,
     so Chromium fills it, overflows into a second column, and so on. A
     multicol column and a printed page box are the same kind of thing to the
     fragmentation engine — same break-inside/break-after handling, same
     orphans/widows, and the same treatment of the line boxes that carry
     .ws-questions.cols-2's two-up question rows (print.css).
     So column k IS printed page k+1, laid out by the very engine that will
     print it. Verified against headless PDFs over 12 configurations / 49
     printed pages: page counts identical, every question and every answer-key
     entry on the predicted page, within-page position agreeing to 0.26mm
     typical / 0.60mm worst, and each previewed sheet pixel-aligned with its
     printed page to within one 96dpi pixel.

     The columns run left to right, which is why the preview is now a strip of
     discrete A4 sheets read across rather than a scroll read down.
     .sheet-papers draws the paper under them; the flow itself is transparent.

     --sheet-scale and --sheet-pages are set inline on .sheet-frame by
     app/worksheet.js. A custom property is inert on its own, so nothing here
     can leak into the print cascade. */

  .sheet-frame {
    width: calc((var(--sheet-pages, 1) * var(--page-pitch) - var(--sheet-gutter)) * var(--sheet-scale, 1));
    height: calc((var(--page-h) + var(--sheet-labelh)) * var(--sheet-scale, 1));
    margin: 0 auto;
  }

  .sheet-scaler {
    position: relative;
    width: calc(var(--sheet-pages, 1) * var(--page-pitch) - var(--sheet-gutter));
    height: calc(var(--page-h) + var(--sheet-labelh));
    transform: scale(var(--sheet-scale, 1));
    transform-origin: top left;
  }

  /* The sheets of paper, and their labels. A sibling layer rather than a
     background on .print-root, so each sheet gets its own real box-shadow —
     and so the print DOM stays exactly the worksheet, nothing else.
     .screen-only keeps the whole layer out of the print cascade. */
  .sheet-papers {
    position: absolute;
    inset: 0;
    pointer-events: none;
  }

  .sheet-paper {
    position: absolute;
    top: 0;
    width: var(--page-w);
    height: var(--page-h);
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08), 0 10px 30px rgba(15, 23, 42, 0.13);
  }

  .sheet-paper__label {
    position: absolute;
    top: var(--page-h);
    width: var(--page-w);
    padding-top: 2.6mm;
    font-family: var(--ui);
    font-size: 3.1mm;
    font-weight: 550;
    line-height: 1;
    text-align: center;
    color: var(--muted);
  }

  /* The real print DOM. It spans the whole strip so the overflow columns sit
     inside it; the paper and its shadow are the layer above.

     The page margin is PADDING here, not a margin on .ws-flow. A top margin
     on the flow collapses straight out through .print-root and .sheet-scaler
     (neither establishes a block formatting context), which drops the whole
     preview flush against the top edge of the paper — 13mm, half an inch,
     high on every page, and invisible to any check that measures positions
     relative to the flow rather than to the sheet. Padding cannot collapse.
     box-sizing is border-box, so 297mm - 2 x 13mm leaves the content box
     exactly --page-ch tall: the fragmentainer fits its sheet to the pixel. */
  .print-root {
    position: relative;
    width: calc(var(--sheet-pages, 1) * var(--page-pitch) - var(--sheet-gutter));
    height: var(--page-h);
    padding: var(--page-my) var(--page-mx);
    background: none;
  }

  /* (0,2,0) — must stay at or above .print-root div (0,1,1) in print.css,
     which would otherwise zero this box. Same trap as .ws-questions .ws-q;
     see print.css. column-gap is derived so column k lands --page-mx inside
     sheet k: 186mm column + 42mm gap = 228mm = one 210mm sheet + 18mm gutter. */
  .print-root .ws-flow {
    width: var(--page-cw);
    height: var(--page-ch);
    margin: 0;
    column-width: var(--page-cw);
    column-gap: calc(var(--page-pitch) - var(--page-cw));
    column-fill: auto;
  }

  /* A forced PAGE break means nothing to a multicol that is not itself inside
     a paged context — Chromium simply ignores it. Left unpaired, the answer
     key and version B kept flowing straight on from the questions in the
     preview while the printer gave each a fresh sheet, and every page after
     that point was off by one. These two selectors are (0,3,0) and (0,2,0),
     above print.css's (0,2,0)/(0,1,0), so break-before: column replaces
     break-before: page for screen only; print keeps the page break. */
  .print-root .ws-version + .ws-version,
  .print-root .ws-key {
    break-before: column;
  }

  /* Belt and braces: if a print run somehow evaluates these screen rules,
     the transform is dropped and the fragmentainer collapses to a plain
     block. (html.printing is set on beforeprint.) */
  html.printing .sheet-scaler { transform: none !important; }
  html.printing .sheet-frame { width: auto !important; height: auto !important; }
  html.printing .print-root { width: auto !important; height: auto !important; padding: 0 !important; }
  html.printing .print-root .ws-flow {
    columns: auto !important;
    column-fill: balance !important;
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
  }

  /* ------------------------------------------------- preview placeholders */
  .ws-empty, .ws-error {
    padding: 34mm 0;
    text-align: center;
  }

  .ws-empty__title, .ws-error__title {
    margin: 0 0 5px;
    font-family: var(--ui);
    font-size: 15px;
    font-weight: 600;
    color: var(--ink-2);
  }

  .ws-empty__body, .ws-error__body {
    margin: 0;
    font-family: var(--ui);
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--muted);
  }

  .ws-error__title { color: var(--danger); }
  .ws-error__body { font-family: var(--mono); font-size: 11.5px; }

  /* ----------------------------------------------------------------- toast */
  .toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    z-index: 50;
    max-width: min(520px, calc(100vw - 32px));
    padding: 9px 14px;
    border-radius: 9px;
    background: rgba(15, 23, 42, 0.94);
    color: #fff;
    font-size: 12.5px;
    line-height: 1.35;
    box-shadow: 0 6px 24px rgba(15, 23, 42, 0.3);
  }
  .toast[hidden] { display: none; }

  /* --------------------------------------------------------- narrow screens */
  @media (max-width: 1100px) {
    :root { --rail-w: 280px; }
  }

  @media (max-width: 900px) {
    .builder { grid-template-columns: 1fr; }
    .rail { border-right: 0; border-bottom: 1px solid var(--line); max-height: 55vh; }
    .preview-pane { padding: 14px; }
    .tabstrip__link { display: none; }
  }
}

/* ---- syllabus level pills + stream filter in the rail (worksheet.js) ---- */
.builder-ui .skill__levels { display: inline-flex; flex-wrap: wrap; gap: 3px; margin-left: 6px; vertical-align: middle; }
.builder-ui .lvl-pill { display: inline-block; padding: 0 6px; border-radius: 999px; font-size: 9.5px; font-weight: 700;
  line-height: 1.6; letter-spacing: .02em; white-space: nowrap; background: #f1f5f9; color: var(--muted); border: 1px solid #e2e8f0; }
.builder-ui .lvl-pill.lvl-g3-pure { background: #eef2ff; color: #4338ca; border-color: #c7d2fe; }
.builder-ui .lvl-pill.lvl-g3-scchem { background: #f0fdfa; color: #0f766e; border-color: #99f6e4; }
.builder-ui .lvl-pill.lvl-g2-scchem { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
.builder-ui .lvl-pill.lvl-g3-scphy, .builder-ui .lvl-pill.lvl-g3-scbio { background: #f0fdfa; color: #0f766e; border-color: #99f6e4; }
.builder-ui .lvl-pill.lvl-g2-scphy, .builder-ui .lvl-pill.lvl-g2-scbio { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
.builder-ui .stream-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin: 0 0 8px; }
.builder-ui .stream-filter__lbl { font-size: 11px; color: var(--muted); margin-right: 2px; }
.builder-ui .stream-btn { border: 1px solid #e2e8f0; background: #fff; border-radius: 999px; padding: 2px 9px; font-size: 11px;
  font-weight: 600; color: var(--ink-2); cursor: pointer; line-height: 1.5; }
.builder-ui .stream-btn:hover { border-color: var(--accent); }
.builder-ui .stream-btn.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.builder-ui .stream-btn.is-on.lvl-g3-scchem { background: #0f766e; border-color: #0f766e; }
.builder-ui .stream-btn.is-on.lvl-g2-scchem { background: var(--warn); border-color: var(--warn); }
.builder-ui .stream-btn.is-on.lvl-g3-scphy, .builder-ui .stream-btn.is-on.lvl-g3-scbio { background: #0f766e; border-color: #0f766e; }
.builder-ui .stream-btn.is-on.lvl-g2-scphy, .builder-ui .stream-btn.is-on.lvl-g2-scbio { background: var(--warn); border-color: var(--warn); }
.builder-ui .stream-filter__note { flex-basis: 100%; font-size: 11px; color: var(--muted); }
.builder-ui .tpc__cb:disabled { opacity: .35; cursor: not-allowed; }
