/* meta.css — menu/meta screens: loadout, upgrade shop, end screens. */

  /* Loadout screen */
  .loadout-screen { padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); }
  .loadout-screen h1 {
    font-family: var(--display-font);
    font-size: clamp(22px, 6vw, 28px); margin-bottom: 20px; text-align: center;
    letter-spacing: 1px;
  }
  .cards { display: flex; flex-direction: column; gap: 12px; margin-bottom: 28px; width: min(320px, 85vw); }
  .card {
    background: var(--panel);
    border: 1px solid var(--edge); border-radius: var(--r-2);
    padding: 14px 20px; text-align: center;
    box-shadow: var(--shadow-1);
  }
  .card .it {
    font-family: var(--display-font);
    font-size: 21px; font-weight: 600; color: var(--gold); letter-spacing: 1px;
  }
  .card .dash { color: var(--gold-3); margin: 4px 0; font-size: 12px; }
  .card .de { font-size: 18px; color: var(--ink); }
  /* .fight-btn / .btn-primary and the arcane variant live in base.css. */
  .fight-btn { width: min(320px, 85vw); }


  /* Upgrade shop (stage 2) */
  .upgrade-screen { padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); text-align: center; }
  .upgrade-screen h1 {
    font-family: var(--display-font);
    font-size: clamp(26px, 7vw, 36px); letter-spacing: 2px; color: var(--arcane-lt);
    text-shadow: 0 0 22px rgba(77, 227, 224, 0.5); margin-bottom: 6px;
  }
  .gold-big { font-size: clamp(18px, 5vw, 24px); color: var(--gold); font-weight: 700; margin-bottom: 22px; }
  .upg-cards { display: flex; flex-direction: column; gap: 14px; width: min(340px, 88vw); margin-bottom: 18px; }
  .upg-card {
    display: flex; flex-direction: column; gap: 6px; align-items: center;
    background: var(--panel);
    border: 1px solid var(--arcane); border-radius: var(--r-2); padding: 14px 18px;
    color: var(--ink); cursor: pointer; box-shadow: var(--glow-arcane);
  }
  .upg-card:active { background: var(--raised); }
  .upg-card.poor { opacity: 0.5; border-color: var(--edge); box-shadow: none; }
  .upg-name { font-size: 20px; font-weight: 700; color: var(--arcane-lt); letter-spacing: 0.5px; }
  .upg-stat { font-size: 15px; color: var(--ink-2); }
  .upg-cost { font-size: 16px; font-weight: 700; color: var(--gold); }
  .upg-hp { font-size: 13px; color: var(--ink-3); margin-bottom: 18px; letter-spacing: 0.5px; }

  /* Skill tree (upgrade phase) — a pan/zoom rune web */
  .tree-screen {
    justify-content: flex-start; align-items: stretch;
    overflow: hidden;
    background: radial-gradient(120% 90% at 50% 38%, #17131f 0%, #100c17 60%, #0b0810 100%);
  }
  .tree-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(env(safe-area-inset-top) + 8px) 16px 6px; flex: 0 0 auto; z-index: 2;
  }
  .tree-title {
    font-family: var(--display-font); font-size: 18px; letter-spacing: 2px; color: var(--ink);
    text-shadow: 0 0 16px rgba(127, 240, 237, 0.35);
  }
  .tree-gold {
    font-size: 13px; font-weight: 700; color: var(--gold); letter-spacing: 0.3px;
    background: var(--gold-1); border: 1px solid var(--gold-2);
    border-radius: var(--r-pill); padding: 3px 10px;
  }
  .tree-topbar .tree-title {
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  /* The forge's two side doors, between the title and the purse: the tree opens
     pages, these two read the build (stats.js) and bind the pages into an order
     (book-order.js). */
  .tree-tools { display: flex; align-items: center; gap: 7px; margin-left: auto; margin-right: 10px; }
  .bo-open {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; letter-spacing: 1px; color: var(--arcane-pale);
    background: rgba(24, 19, 36, 0.82); border: 1px solid var(--edge);
    border-radius: var(--r-pill); padding: 4px 11px 4px 9px; cursor: pointer;
    white-space: nowrap;
    transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  }
  .bo-open:active { background: var(--raised-hi); border-color: var(--arcane-3); }
  .bo-open-icon { width: 20px; height: 14px; fill: #f2ead0; stroke: #10151a; stroke-width: 1.1; }
  .bo-open-icon .bo-open-spine { stroke: #8a7f63; fill: none; }
  .sv-open-icon { width: 14px; height: 14px; fill: var(--arcane-lt); }
  /* On a narrow phone the two pills would crowd the title out; drop to the
     icons, which are the part that is actually aimed at with a thumb. */
  @media (max-width: 390px) {
    .tree-tools .bo-open { font-size: 0; gap: 0; padding: 5px 9px; }
  }

  /* Dev tools (see skilltree.js) — the slider always sits in the topbar; the row
     of tools under it only exists while the slider is on. Deliberately drab, so
     nothing here reads as part of the game. */
  .dev-switch {
    display: inline-flex; align-items: center; gap: 6px; margin-left: auto;
    background: none; border: 0; padding: 4px 2px; cursor: pointer; color: var(--ink-4);
  }
  /* The slider takes the auto margin that pushes everything right, so the two
     door pills sit next to it rather than starting a second gap of their own. */
  .tree-topbar .dev-switch + .tree-tools { margin-left: 10px; }
  .dev-switch-text { font-size: 9px; letter-spacing: 1.4px; text-transform: uppercase; }
  .dev-switch-track {
    width: 26px; height: 14px; border-radius: var(--r-pill); position: relative;
    background: var(--raised); border: 1px solid var(--edge);
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
  }
  .dev-switch-knob {
    position: absolute; top: 1px; left: 1px; width: 10px; height: 10px; border-radius: 50%;
    background: var(--ink-4); transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
  }
  .dev-switch.on { color: var(--arcane-pale); }
  .dev-switch.on .dev-switch-track { background: var(--arcane-3); border-color: var(--arcane); }
  .dev-switch.on .dev-switch-knob { transform: translateX(12px); background: var(--arcane-lt); }

  /* Stays UNDER the topbar's layer (a flex item's z-index counts even when it is
     not positioned), so the gold field hanging off the purse is both drawn and
     tappable over this row. */
  .dev-bar {
    display: flex; align-items: center; gap: 10px; flex: 0 0 auto; z-index: 1;
    padding: 0 16px 6px;
  }
  .dev-btn {
    font-size: 12px; letter-spacing: 0.4px; color: var(--ink-2); cursor: pointer;
    background: rgba(24, 19, 36, 0.82); border: 1px solid var(--edge);
    border-radius: var(--r-pill); padding: 5px 12px;
  }
  .dev-btn:active { background: var(--raised-hi); }
  .dev-btn.armed { color: #ffb4b6; border-color: #7a3338; background: rgba(58, 20, 24, 0.8); }
  .dev-note { font-size: 10px; letter-spacing: 0.4px; color: var(--ink-4); }

  /* The purse while the tools are armed: tappable, and the amount is typed into
     a field that hangs off it (below the topbar, where there is room for it). */
  #tree-gold-slot { position: relative; }
  .tree-gold.dev { cursor: pointer; font-family: inherit; }
  .dev-gold-pop {
    position: absolute; top: 100%; right: 0; margin-top: 6px; z-index: 4;
    display: flex; align-items: center; gap: 6px; padding: 5px 8px;
    font-size: 13px; font-weight: 700; color: var(--gold);
    background: rgba(24, 19, 36, 0.96); border: 1px solid var(--gold-2);
    border-radius: var(--r-1); box-shadow: var(--shadow-2);
  }
  .dev-gold-input {
    width: 84px; font: inherit; color: var(--gold-lt); text-align: right;
    background: transparent; border: 0; border-bottom: 1px solid var(--gold-2); padding: 1px 2px;
    appearance: textfield; -moz-appearance: textfield;
  }
  /* Desktop spinners would eat the field's width; the phone gets a numeric pad. */
  .dev-gold-input::-webkit-outer-spin-button,
  .dev-gold-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
  .dev-gold-ok {
    font-size: 13px; line-height: 1; color: var(--gold-lt); cursor: pointer;
    background: var(--gold-1); border: 1px solid var(--gold-2);
    border-radius: var(--r-pill); padding: 4px 9px;
  }
  .dev-gold-ok:active { background: var(--raised-hi); }

  /* The web is a <canvas>, not an SVG — see the essay above drawTree in
     skilltree.js before changing that back.

     `flex-basis: 0` on purpose: it takes whatever the topbar, the info panel
     and the run button leave over, and never sizes off its own intrinsic
     dimensions. With `auto` the canvas's default 300x150 would feed into the
     layout, and the backing store is kept matched to this box (see
     syncTreeViewport) — the two would chase each other.

     Every colour the web is drawn in lives in TREE_PAINT in skilltree.js now;
     a canvas takes no CSS, so there is nothing to style here but the box. */
  .tree-canvas {
    flex: 1 1 0; min-height: 0; width: 100%; display: block;
    touch-action: none; cursor: grab; -webkit-user-select: none; user-select: none;
  }
  .tree-canvas:active { cursor: grabbing; }

  /* zoom toolbar */
  .tree-zoom {
    position: absolute; right: 12px; top: 84px; z-index: 3;
    display: flex; flex-direction: column; gap: 8px;
  }
  .tz-btn {
    width: 40px; height: 40px; border-radius: var(--r-1); border: 1px solid var(--edge);
    background: rgba(24, 19, 36, 0.82); color: var(--arcane-pale); font-size: 22px; line-height: 1;
    cursor: pointer; backdrop-filter: blur(2px);
    transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  }
  .tz-btn:hover { border-color: var(--arcane-3); }
  .tz-btn:active { background: var(--raised-hi); }

  /* info panel + buy button */
  .tree-info {
    flex: 0 0 auto; z-index: 2; margin: 0 12px 8px; padding: 12px 16px;
    border: 1px solid var(--edge); border-left-width: 4px; border-radius: var(--r-2);
    background: linear-gradient(160deg, rgba(36, 29, 51, 0.95), rgba(20, 16, 30, 0.95));
    box-shadow: var(--shadow-2);
  }
  .tree-info.empty { text-align: center; color: var(--ink-3); }
  .ti-hint { padding: 4px 0 10px; }
  .ti-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
  .ti-rune { display: inline-flex; }
  .ti-name { font-family: var(--display-font); font-size: 19px; letter-spacing: 1px; }
  /* Which arm and which aspect branch this node grew on — the tree is authored
     into named branches now, so a node can say where it belongs. */
  .ti-path { font-size: 11px; color: #7d7690; letter-spacing: 0.6px; margin-bottom: 5px; }
  /* Badge on the five unique thorn caches — sits where the rank pips would be. */
  .ti-unique {
    margin-left: auto; font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase;
    border: 1px solid currentColor; border-radius: 999px; padding: 2px 8px; opacity: 0.9;
  }
  .ti-dots { margin-left: auto; display: inline-flex; gap: 4px; }
  .ti-dots .dot {
    width: 8px; height: 8px; border-radius: 50%; border: 1px solid currentColor;
    opacity: 0.35; display: inline-block;
  }
  .ti-dots .dot.on { background: currentColor; opacity: 1; }
  .ti-blurb { font-size: 14px; color: var(--ink-2); line-height: 1.35; margin-bottom: 6px; }
  .ti-effect { font-size: 13px; color: var(--ink-3); margin-bottom: 12px; }
  .ti-effect b { color: var(--ink); font-weight: 700; }
  .tree-buy { padding: 12px 0; font-size: 17px; letter-spacing: 0.5px; border-radius: var(--r-1); }
  .tree-buy.poor {
    background: var(--raised); color: var(--ink-4); box-shadow: none; cursor: default;
    filter: none; transform: none;
  }
  .tree-run-btn { flex: 0 0 auto; margin: 0 auto 10px; width: min(340px, 88vw); }

  /* Book order screen (upgrade phase) — the whole spell book laid out as three
     open volumes, one per spread. A page is dragged onto another to trade
     places; the leaves themselves are the combat book's (styles in combat.css),
     so only the stage and the carry/drop states belong here. */
  .bo-screen {
    justify-content: flex-start; align-items: stretch;
    background: radial-gradient(120% 90% at 50% 32%, #191320 0%, #110c17 60%, #0b0810 100%);
  }
  .bo-topbar {
    display: flex; align-items: center; gap: 10px;
    padding: calc(env(safe-area-inset-top) + 8px) 16px 4px; flex: 0 0 auto;
  }
  .bo-back {
    font-size: 13px; letter-spacing: 0.5px; color: var(--arcane-pale);
    background: rgba(24, 19, 36, 0.82); border: 1px solid var(--edge);
    border-radius: var(--r-pill); padding: 5px 12px; cursor: pointer;
  }
  .bo-back:active { background: var(--raised-hi); }
  .bo-hint {
    flex: 0 0 auto; text-align: center; color: var(--ink-3);
    font-size: 12px; letter-spacing: 0.4px; padding: 2px 16px 8px;
  }
  /* The stack is scaled to fit whatever height is left over (the svg meets its
     box), so the whole book is always on screen without scrolling. */
  .bo-stage { flex: 1 1 auto; min-height: 0; width: 100%; padding: 0 10px 10px; }
  .bo-foot { pointer-events: none; }
  .bo-canvas {
    width: 100%; height: 100%; display: block;
    touch-action: none; -webkit-user-select: none; user-select: none;
    filter: drop-shadow(0 4px 12px rgba(6, 4, 12, 0.6));
  }
  .bk-page[data-slot] { cursor: grab; }
  /* The carried page: lifted off the stack and floating over every book, so it
     casts a shadow onto them and nothing under the finger can intercept the
     hit-test that finds the page it will be dropped on. */
  /* …and it must be transparent to the hit-test, including the leaf itself:
     combat.css re-enables pointer events on every open page, so switching the
     layer off is not enough on its own. */
  #bo-carry, #bo-carry .bk-page { pointer-events: none; }
  .bo-lift { filter: drop-shadow(0 8px 14px rgba(4, 2, 10, 0.75)); opacity: 0.95; }
  /* The page it would trade with, lit along its own edge. */
  .bo-target .bk-leaf { stroke: var(--gold); stroke-width: 3; }

  /* ===========================================================================
     Werte — the ledger screen (see stats.js). Laid out as a `.frame` like the
     study-phase screens: a capped, centred reading column with a fixed header
     (the three headline figures + the tabs) over one scrolling body.

     The visual grammar is one row type repeated everywhere: LABEL — VALUE on a
     line, a meter under it drawn against that stat's own ceiling, and a quiet
     note explaining where the number came from. Every accent colour is passed
     in from the tree's theme table as --sec (a section) or --c (a spell card),
     so nothing here hard-codes a hue.
     =========================================================================== */
  .sv-screen {
    justify-content: flex-start; align-items: stretch;
    background: radial-gradient(130% 75% at 50% 0%, #1a1425 0%, var(--bg) 58%);
  }
  @media (min-width: 760px) {
    .sv-frame {
      border-left: 1px solid var(--edge-soft);
      border-right: 1px solid var(--edge-soft);
      background: linear-gradient(180deg, rgba(127, 240, 237, 0.02), transparent 45%);
    }
  }
  .sv-frame { text-align: left; }
  .sv-header { flex: 0 0 auto; }
  .sv-top { display: flex; align-items: center; gap: 10px; }
  .sv-back { font-size: 15px; line-height: 1; padding: 7px 12px; }
  .sv-title {
    flex: 1 1 auto; margin: 0; text-align: center;
    font-family: var(--display-font); font-size: 19px; font-weight: 600; letter-spacing: 2px;
    color: var(--ink); text-shadow: 0 0 16px rgba(127, 240, 237, 0.3);
  }

  /* The three figures every other number leans on. They stay put above the
     tabs, so switching between Held and Zauber never loses the frame of
     reference. */
  .sv-hero { display: flex; gap: 8px; margin: 10px 0 9px; }
  .sv-hero-tile {
    flex: 1 1 0; min-width: 0; position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    padding: 7px 6px 6px; border-radius: var(--r-2);
    border: 1px solid var(--edge-soft); background: var(--panel);
    box-shadow: var(--shadow-1);
  }
  .sv-hero-tile::before {
    content: ""; position: absolute; inset: -1px -1px auto; height: 2px;
    border-radius: var(--r-2) var(--r-2) 0 0; background: var(--tile, var(--arcane));
    opacity: 0.85;
  }
  .sv-hero-tile.might    { --tile: #ff7043; }
  .sv-hero-tile.vigor    { --tile: #5ecf8f; }
  .sv-hero-tile.fireball { --tile: #f2a83a; }
  /* The glyph carries its theme's colour on the <g> runeGlyphSvg writes, so the
     tile only has to make room for it. */
  .sv-hero-rune { display: block; line-height: 0; opacity: 0.9; }
  .sv-hero-tile b {
    font-family: var(--display-font); font-size: 22px; line-height: 1.1; font-weight: 700;
    color: var(--tile); font-variant-numeric: tabular-nums;
  }
  .sv-hero-tile .sv-of { font-size: 14px; color: var(--ink-4); }
  .sv-hero-label { font-size: 10.5px; letter-spacing: 0.5px; color: var(--ink-4); text-align: center; }

  .sv-tabs { display: flex; gap: 6px; padding-bottom: 9px; }
  .sv-tab {
    flex: 1 1 0; padding: 7px 4px; cursor: pointer;
    font-size: 12.5px; letter-spacing: 0.6px;
    color: var(--ink-3); background: transparent;
    border: 1px solid var(--edge-soft); border-radius: var(--r-pill);
    transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  }
  .sv-tab:hover { color: var(--ink-2); border-color: var(--edge); }
  .sv-tab.active { border-color: var(--arcane-3); color: var(--ink); background: var(--arcane-2); }

  .sv-body { flex: 1 1 auto; min-height: 0; padding-bottom: 18px; }
  .sv-lead { margin: 0 0 12px; font-size: 12.5px; line-height: 1.45; color: var(--ink-3); }

  /* --- A section: runic heading over a list of rows --- */
  .sv-sec {
    margin-bottom: 12px; padding: 12px 13px 4px;
    border: 1px solid var(--edge-soft); border-left: 3px solid var(--sec, var(--edge));
    border-radius: var(--r-2); background: var(--panel);
    box-shadow: var(--shadow-1);
  }
  .sv-sec-head { display: flex; align-items: baseline; gap: 8px; margin: 0 0 8px; }
  .sv-sec-rune { align-self: center; line-height: 0; }
  .sv-sec-title {
    font-family: var(--display-font); font-size: 17px; font-weight: 600; letter-spacing: 1px;
    color: var(--sec); text-shadow: 0 0 14px rgba(var(--sec-glow), 0.28);
  }
  .sv-sec-sub { font-size: 10.5px; letter-spacing: 0.4px; color: var(--ink-4); }
  .sv-empty { margin: 4px 0 10px; font-size: 13px; color: var(--ink-4); }

  /* --- The row: the one shape the whole screen is built from --- */
  .sv-row { padding: 8px 0; border-top: 1px solid var(--edge-soft); }
  .sv-rows > .sv-row:first-child { border-top: none; }
  .sv-line { display: flex; align-items: baseline; gap: 7px; }
  .sv-label { flex: 1 1 auto; min-width: 0; font-size: 13px; color: var(--ink-2); }
  .sv-value {
    flex: 0 0 auto; font-size: 14.5px; font-weight: 700; color: var(--ink);
    font-variant-numeric: tabular-nums;
  }
  .sv-value.gold { color: var(--gold); }
  .sv-value .sv-of { font-size: 11.5px; font-weight: 400; color: var(--ink-4); }
  /* Called out when a stat has run into the ceiling it is measured against —
     the one thing a stat screen must say out loud, since further nodes of that
     kind are then wasted gold. */
  .sv-flag {
    flex: 0 0 auto; font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
    color: var(--gold); border: 1px solid var(--gold-3); border-radius: var(--r-pill);
    padding: 1px 6px; background: var(--gold-1);
  }
  .sv-flag.soft { color: var(--ink-4); border-color: var(--edge); background: transparent; }
  .sv-bar {
    height: 3px; margin: 6px 0 5px; border-radius: var(--r-pill);
    background: var(--edge-soft); overflow: hidden;
  }
  .sv-bar > i { display: block; height: 100%; border-radius: var(--r-pill); }
  /* A meter that has run into its ceiling is lit rather than recoloured — the
     stat keeps its own hue, it just stops being a suggestion to spend more. */
  .sv-bar.full { background: var(--gold-2); }
  .sv-bar.full > i { filter: brightness(1.25) saturate(1.1); }
  .sv-note { font-size: 11px; line-height: 1.4; color: var(--ink-4); }
  .sv-note b { color: var(--ink-2); font-weight: 700; }

  /* --- A spell card: the page's own colour carries it --- */
  .sv-spell {
    margin-bottom: 12px; padding: 12px 13px 4px;
    border: 1px solid var(--edge-soft); border-radius: var(--r-2);
    background:
      linear-gradient(180deg, rgba(var(--g), 0.07), transparent 42%),
      var(--panel);
    box-shadow: var(--shadow-1);
  }
  .sv-spell.active { border-color: rgba(var(--g), 0.5); box-shadow: var(--shadow-1), 0 0 20px rgba(var(--g), 0.14); }
  .sv-spell.sealed { opacity: 0.72; }
  .sv-spell-head { display: flex; align-items: center; gap: 10px; }
  .sv-spell-rune { flex: 0 0 auto; line-height: 0; filter: drop-shadow(0 0 6px rgba(var(--g), 0.45)); }
  .sv-spell-name { flex: 1 1 auto; min-width: 0; }
  .sv-spell-name h3 {
    margin: 0; font-family: var(--display-font); font-size: 18px; font-weight: 600; letter-spacing: 1px;
    color: var(--c);
  }
  .sv-spell-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
  .sv-pill {
    font-size: 9.5px; letter-spacing: 0.8px; text-transform: uppercase;
    color: var(--ink-4); border: 1px solid var(--edge); border-radius: var(--r-pill); padding: 1px 7px;
  }
  .sv-pill.open { color: var(--c); border-color: rgba(var(--g), 0.55); }
  .sv-pill.sealed { color: var(--ink-3); border-color: var(--edge-hi); background: var(--sunk); }
  .sv-spell-head-num { flex: 0 0 auto; text-align: right; }
  .sv-spell-head-num b {
    display: block; font-family: var(--display-font); font-size: 23px; line-height: 1.1;
    color: var(--c); font-variant-numeric: tabular-nums;
  }
  .sv-spell-head-num span { display: block; font-size: 9.5px; letter-spacing: 0.4px; color: var(--ink-4); }
  .sv-seal {
    margin: 10px 0 0; padding: 7px 9px; border-radius: var(--r-1);
    border: 1px dashed var(--edge-hi); background: var(--sunk);
    font-size: 11px; line-height: 1.45; color: var(--ink-3);
  }
  .sv-seal b { color: var(--ink-2); }
  .sv-spell-blurb { margin: 9px 0 3px; font-size: 12.5px; line-height: 1.45; color: var(--ink-3); }

  /* --- Where the ranks went: one stacked band + its legend --- */
  .sv-band {
    display: flex; height: 10px; margin: 2px 0 12px; border-radius: var(--r-pill);
    overflow: hidden; background: var(--edge-soft);
  }
  .sv-band > i { display: block; height: 100%; }
  .sv-legend { display: flex; flex-direction: column; gap: 6px; padding-bottom: 10px; }
  .sv-leg { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
  .sv-leg-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; }
  .sv-leg-name { flex: 0 0 84px; }
  .sv-leg-bar { flex: 1 1 auto; height: 3px; border-radius: var(--r-pill); background: var(--edge-soft); overflow: hidden; }
  .sv-leg-bar > i { display: block; height: 100%; border-radius: var(--r-pill); }
  .sv-leg-n { flex: 0 0 auto; min-width: 22px; text-align: right; color: var(--ink-3); font-variant-numeric: tabular-nums; }

  /* End screens */
  .end-screen { cursor: pointer; padding: 16px; text-align: center; }
  .end-screen h1 {
    font-family: var(--display-font);
    font-size: clamp(32px, 9vw, 44px); margin-bottom: 12px; letter-spacing: 2px;
  }
  .end-screen h1.victory { color: var(--gold); text-shadow: 0 0 28px rgba(242, 193, 78, 0.45); }
  .end-screen h1.reward { color: var(--gold); text-shadow: 0 0 28px rgba(242, 193, 78, 0.45); }
  .end-screen p { font-size: clamp(15px, 4.5vw, 18px); color: var(--ink-2); margin: 4px 0; }
  /* Capped so the run summary breaks between stats rather than orphaning the
     last one on a line of its own. */
  .end-screen .dim { color: var(--ink-3); font-size: clamp(13px, 3.6vw, 15px); max-width: 300px; margin-inline: auto; }
  .end-screen .end-flavor { color: #b9b3c8; margin: 18px auto 24px; max-width: 320px; }
  .study-btn { width: min(320px, 85vw); }
  .end-screen .hint { margin-top: 24px; color: var(--ink-3); }

  /* --- Reward screen (what used to be the defeat screen) ---
     A run ends with a number the player WON, not one they lost. The multiplier
     is the hero of the layout; everything under it explains that it banks and
     points at the quiz that spends it. */
  .reward-screen {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0; padding: 16px calc(16px + env(safe-area-inset-left)) 16px calc(16px + env(safe-area-inset-right));
  }
  .reward-mult {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    margin: 2px auto 14px; padding: 14px 30px;
    background: var(--gold-1); border: 1px solid var(--gold-3); border-radius: 16px;
    box-shadow: 0 0 34px rgba(242, 193, 78, 0.14) inset;
  }
  .reward-mult.capped {
    border-color: var(--gold-lt);
    box-shadow: 0 0 34px rgba(242, 193, 78, 0.24) inset, 0 0 22px rgba(242, 193, 78, 0.28);
  }
  .reward-mult-num {
    font-family: var(--display-font); font-weight: 700; line-height: 1;
    font-size: clamp(44px, 15vw, 68px); letter-spacing: 1px;
    color: var(--gold-lt); text-shadow: 0 0 26px rgba(242, 193, 78, 0.5);
  }
  .reward-mult-label {
    font-size: clamp(12px, 3.4vw, 14px); letter-spacing: 1.4px; text-transform: uppercase;
    color: var(--ink-3);
  }
  /* Fill toward the ceiling: a nearly full bar is the "go study now" cue. */
  .reward-bar {
    width: min(300px, 82vw); height: 7px; margin: 0 auto 12px;
    background: var(--gold-1); border: 1px solid var(--gold-2);
    border-radius: var(--r-pill); overflow: hidden;
  }
  .reward-bar-fill {
    display: block; height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--gold-lt));
    transition: width 320ms ease-out;
  }
  .reward-bar-fill.capped { box-shadow: 0 0 12px rgba(242, 193, 78, 0.7); }
  .end-screen .reward-bank {
    color: var(--ink-2); font-size: clamp(14px, 4vw, 16px);
    max-width: 300px; margin-inline: auto;
  }
  .end-screen .reward-bank strong { color: var(--gold-lt); }
  .end-screen .reward-bank strong:last-of-type { color: var(--gold); }
  .end-screen .reward-carry {
    color: var(--arcane-pale); font-size: clamp(13px, 3.6vw, 15px);
    margin: 6px auto 0; letter-spacing: 0.3px;
  }
  .reward-screen .coin { color: var(--gold); }
  .reward-screen .study-btn { margin-top: 22px; }
  .reward-screen .dim { margin-top: 16px; }

  /* ---------------------------------------------------------------------------
     The tavern (see src/tavern.js) — the home room. A full-bleed pixel scene
     with the station labels floating over it as chips: the picture is the
     navigation, and the chips are what a thumb actually aims at.
     --------------------------------------------------------------------------- */
  .tavern-screen {
    justify-content: flex-start; align-items: stretch;
    overflow: hidden; background: #100c17;
  }
  .tav-top {
    flex: 0 0 auto; z-index: 2;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: calc(env(safe-area-inset-top) + 8px) 16px 6px;
  }
  .tav-title {
    font-family: var(--display-font); font-size: 18px; letter-spacing: 2px;
    color: var(--ink); text-shadow: 0 0 18px rgba(242, 193, 78, 0.25);
  }
  .tav-gold {
    font-size: 14px; font-weight: 700; color: var(--gold);
    padding: 5px 11px; border-radius: var(--r-pill);
    background: var(--gold-1); border: 1px solid var(--gold-2);
  }
  /* The stage is the positioning context the chips are placed in: their left/top
     come from the room's own art coordinates, scaled by the canvas' CSS scale
     (see placeTavernChips), so a chip always sits over the thing it names. */
  .tav-stage {
    position: relative; flex: 1 1 auto; min-height: 0; width: 100%;
    line-height: 0; overflow: hidden;
  }
  canvas.tav-scene { display: block; image-rendering: pixelated; touch-action: manipulation; }
  .tav-chips {
    position: absolute; inset: 0; pointer-events: none;
    transition: opacity var(--dur) var(--ease);
  }
  /* An order is running in the scene (see layoutBarMeal) — the labels get out of
     the way of the menu rather than sitting on top of it. */
  .tav-chips.hushed { opacity: 0; }
  .tav-chips.hushed .tav-chip { pointer-events: none; }
  .tav-chip {
    position: absolute; transform: translate(-50%, -100%);
    pointer-events: auto; cursor: pointer; white-space: nowrap;
    padding: 5px 11px; border-radius: var(--r-pill);
    font-size: 12px; font-weight: 700; letter-spacing: 0.6px; line-height: 1.1;
    color: var(--arcane-pale);
    background: rgba(18, 14, 26, 0.82); border: 1px solid var(--arcane-3);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
                background var(--dur) var(--ease);
  }
  .tav-chip:active { background: rgba(40, 32, 58, 0.92); color: var(--ink); }
  .tav-chip.on { color: #17121f; background: var(--arcane); border-color: var(--arcane-lt); }
  /* A station that stays in the room is quieter than one that changes the
     screen — the bar serves a meal where it stands, it is not a door. */
  .tav-chip.flavour { color: var(--ink-3); border-color: var(--edge); font-weight: 600; }
  .tav-chip.flavour:active { color: var(--ink-2); }


  /* ===========================================================================
     The study phase's own screens — the Bücherei hub, the grammar shelf and a
     lecture's scorecard.

     They live here rather than in quiz.css because they are meta screens: they
     are what you tap THROUGH, not what you sit in. The session itself — quiz or
     lecture — is in quiz.css, on the frame both of them share.
     =========================================================================== */
  .study-screen, .lectures-screen, .lecdone-screen {
    justify-content: flex-start; align-items: stretch;
    background: radial-gradient(130% 75% at 50% 0%, #1a1425 0%, var(--bg) 58%);
  }
  @media (min-width: 760px) {
    .study-frame, .lec-frame, .lecdone-frame {
      border-left: 1px solid var(--edge-soft);
      border-right: 1px solid var(--edge-soft);
    }
  }

  /* --- The hub ------------------------------------------------------------ */
  /* The hub's head row carries the step back to the tavern, so it centres its
     items rather than sitting them on a shared baseline — a pill button and a
     24 px display title have no baseline worth sharing. */
  .study-top {
    flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
    padding: 6px 0 14px;
  }
  .study-back { flex: 0 0 auto; font-size: 14px; line-height: 1; padding: 5px 11px; }
  .study-title {
    margin: 0; font-family: var(--display-font); font-size: 24px; font-weight: 400;
    letter-spacing: 0.5px; color: var(--ink);
  }
  .study-purse { margin-left: auto; display: flex; gap: 8px; font-size: 12.5px; font-weight: 700; }
  .study-coin {
    color: var(--gold); background: var(--gold-1); border: 1px solid var(--gold-2);
    border-radius: var(--r-pill); padding: 3px 10px;
  }
  .study-gem {
    color: var(--gem); background: var(--gem-1); border: 1px solid var(--gem-2);
    border-radius: var(--r-pill); padding: 3px 10px;
  }

  .study-doors { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding-bottom: 16px; }

  /* A door is a whole card, not a title with a button under it: the entire
     panel is the tap target, because a thumb aiming at a phase should not have
     to find the one row of it that is live. */
  .study-door {
    display: flex; flex-direction: column; gap: 6px; text-align: left;
    padding: 16px 16px 14px; cursor: pointer;
    background: var(--panel); border: 1px solid var(--edge); border-radius: var(--r-3);
    box-shadow: var(--shadow-1);
    transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
  }
  .study-door:active { transform: translateY(1px); border-color: var(--edge-hi); }
  .door-head { display: flex; align-items: center; gap: 9px; }
  .door-name {
    font-family: var(--display-font); font-size: 19px; letter-spacing: 0.4px; color: var(--ink);
  }
  .door-blurb { font-size: 13px; line-height: 1.5; color: var(--ink-3); }
  .door-foot {
    margin-top: 2px; font-size: 12px; font-weight: 700; letter-spacing: 0.3px; color: var(--ink-4);
  }
  .study-history { align-self: center; margin-top: 4px; }

  /* --- The shelf ----------------------------------------------------------- */
  .lec-top {
    flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 4px 0 12px;
  }
  .lec-back { flex: 0 0 auto; }
  .lec-title {
    flex: 1 1 auto; margin: 0; text-align: center;
    font-family: var(--display-font); font-size: 21px; font-weight: 400; color: var(--ink);
  }
  .lec-purse {
    flex: 0 0 auto; font-size: 12.5px; font-weight: 700; color: var(--gem);
    background: var(--gem-1); border: 1px solid var(--gem-2);
    border-radius: var(--r-pill); padding: 3px 10px;
  }

  .lec-list { flex: 1 1 auto; min-height: 0; padding-bottom: 16px; }
  .lec-unit { margin-bottom: 20px; }
  .lec-unit-title {
    margin: 0 0 2px; font-size: 12px; font-weight: 700;
    letter-spacing: 1.1px; text-transform: uppercase; color: var(--arcane-dim);
  }
  .lec-unit-blurb { margin: 0 0 9px; font-size: 12px; color: var(--ink-4); }
  .lec-unit.empty { opacity: 0.45; }
  .lec-soon {
    margin: 0; padding: 10px 12px; font-size: 12.5px; font-style: italic; color: var(--ink-4);
    background: var(--sunk); border: 1px dashed var(--edge); border-radius: var(--r-2);
  }

  .lec-row {
    display: flex; align-items: center; gap: 11px; width: 100%;
    margin-bottom: 7px; padding: 11px 13px; text-align: left; cursor: pointer;
    background: var(--raised); border: 1px solid var(--edge); border-radius: var(--r-2);
    transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
  }
  .lec-row:active { transform: translateY(1px); border-color: var(--edge-hi); }
  /* The mark keeps its width whether or not there is anything in it, so the
     titles of a half-finished unit stay on one left edge. */
  .lec-mark {
    flex: 0 0 16px; text-align: center; font-size: 14px; font-weight: 700; color: var(--ink-4);
  }
  .lec-mark.pass { color: var(--good); }
  .lec-mark.tried { color: var(--ink-4); }
  .lec-row-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .lec-row-title { font-size: 14.5px; color: var(--ink); }
  .lec-row-sub {
    font-size: 11.5px; color: var(--ink-4);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .lec-best { flex: 0 0 auto; font-size: 12.5px; font-weight: 700; color: var(--ink-3); }
  .lec-best.pass { color: var(--good); }
  .lec-best.none { color: var(--ink-4); }

  /* --- The scorecard -------------------------------------------------------- */
  .lecdone-body {
    flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
    justify-content: center; text-align: center; gap: 4px;
  }
  .done-kicker {
    margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 1.4px;
    text-transform: uppercase; color: var(--ink-4);
  }
  .done-title {
    margin: 2px 0 10px; font-family: var(--display-font); font-size: 26px; font-weight: 400;
    letter-spacing: 0.5px; color: var(--ink);
  }
  .done-verdict {
    margin: 0 auto 12px; padding: 5px 16px; border-radius: var(--r-pill);
    font-size: 13px; font-weight: 700; letter-spacing: 0.4px;
  }
  .done-verdict.pass { color: var(--good-ink); background: var(--good-1); border: 1px solid var(--good-2); }
  .done-verdict.fail { color: var(--ink-2); background: var(--sunk); border: 1px solid var(--edge); }
  .done-score { margin: 0 0 6px; font-size: 15px; color: var(--ink-2); }
  .done-score b { font-size: 21px; color: var(--ink); }
  .done-gems { margin: 0; font-size: 16px; font-weight: 700; color: var(--gem); }
  .done-bonus { margin: 6px 0 0; font-size: 13px; color: var(--gem-lt); }
  .done-note {
    margin: 18px auto 0; max-width: 32ch; font-size: 12px; line-height: 1.5; color: var(--ink-4);
  }
  .lecdone-foot {
    flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; align-items: stretch;
    padding: 12px 0 calc(env(safe-area-inset-bottom) + 12px);
  }
  .done-retry { align-self: center; }
