/* Mage Tower Battle. Cream paper panels with a thick ink line, after the
   journal's mockups; the 3D view behind. The overlay's colour roles are the
   custom properties render2d.js reads (crates/core/src/draw.rs PALETTE). */
:root {
  --paper: #fff8ec;
  --ink: #2b2140;
  --muted: #6b5f80;
  --accent: #6b46c1;
  --shade: rgba(27, 22, 38, 0.55);
  --panel: #fff8ec;
  --band: rgba(155, 125, 235, 0.35);
  --guide: #6b46c1;
  --drawn: #2b2140;
  --good: #2f9e7a;
  --bad: #d9604a;
  --gold: #e8b23a;
  --cell_open: #9cc874;
  --cell_scenery: #4f7f45;
  --cell_route: #d8bb8c;
  --cell_tower: #6b46c1;
  --cell_entry: #d9604a;
  --glass: #7fd6f5;
  --ivory: #f4ecd6;
  --lava: #ff6a1f;
  --bait: #e8c56a;
  --sub: #b9aedc;
  --ghost_ok: rgba(255, 224, 138, 0.8);
  --ghost_bad: rgba(217, 96, 74, 0.8);
  --note0: #e06a3a;
  --note1: #2f9e7a;
  --note2: #d6a028;
  --note3: #e05f9a;
  --destruction: #e06a3a;
  --alteration: #3fae8c;
  --conjuration: #6b46c1;
  --illusion: #ff6fa8;
  --restoration: #e8b23a;
  --dial: #f4ecdf;
  --clear: transparent;
  --ring_pay: rgba(224, 69, 58, 0.25);
  --ring_mod: rgba(74, 95, 209, 0.25);
  --ring_trig: rgba(232, 194, 26, 0.32);
  --line: 3px;
  --radius: 16px;
  /* a button's text stays dark on gold, and a chip's background follows
     the theme, so neither is ever light on light (T6) */
  --on-button: #2b2140;
  --chip-bg: #e9e0ff;
  --row-bg: rgba(255, 255, 255, 0.35);
  --card-bg: #ffffff;
  --on-bg: #fff1c9;
  --note-bg: #fffbe0;
  --track: #e6dcc9;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Rounded", system-ui, sans-serif;
  /* the HUD over the 3D view, after Ape Race's menus (T34): dark and see-
     through in either theme, so it sits over the scene without hiding it */
  --glass-bg: rgba(28, 20, 44, 0.84);
  --glass-ink: #f6ecd9;
  --glass-muted: #cbbbe6;
  --glass-line: rgba(255, 214, 140, 0.28);
  --glass-gold: #ffcf4d;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #2a2238; --panel: #2a2238; --ink: #f2ecff; --muted: #b9aedc; --drawn: #f2ecff; --shade: rgba(10, 8, 18, 0.6); --chip-bg: #4a3d66; --row-bg: rgba(255, 255, 255, 0.06); --dial: #3a3050; --card-bg: #342a48; --on-bg: #4a3d22; --note-bg: #3a3328; --track: #4a3d66; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #1b1626; color: var(--ink); font: 16px/1.4 var(--font); overflow: hidden; }
#stage { position: relative; aspect-ratio: 16 / 9; width: min(100vw, calc(100vh * 16 / 9)); margin: auto; top: 50%; transform: translateY(-50%); overflow: hidden; }
#gl, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { touch-action: none; cursor: crosshair; }
#labels, #panels, #toasts { position: absolute; inset: 0; pointer-events: none; }
#panels > * { pointer-events: auto; }
#message:not(:empty) { position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%); background: var(--bad); color: #fff; padding: 6px 14px; border-radius: 999px; border: var(--line) solid var(--ink); font-weight: 700; z-index: 5; }
#mute { position: absolute; right: 10px; top: 10px; z-index: 6; font-size: 12px; padding: 3px 10px; }
#glossary-button { position: absolute; right: 100px; top: 10px; z-index: 6; font-size: 12px; padding: 3px 10px; }
/* the glossary opens over any screen (T8) */
#panels > .panel-glossary { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); width: min(760px, 92%); max-height: 84%; overflow: auto; z-index: 4; }
.panel-glossary .row-detail { font-size: 14px; }

.panel { background: var(--panel); border: var(--line) solid var(--ink); border-radius: var(--radius); box-shadow: 0 5px 0 rgba(43, 33, 64, 0.4); padding: 14px 16px; }
.panel h2 { margin: 0 0 6px; font-size: 22px; }
.panel p { margin: 0 0 10px; }
.actions, .chips, .chain, .row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.act { font: 700 15px var(--font); color: var(--on-button); background: var(--gold); border: var(--line) solid var(--ink); border-radius: 12px; padding: 5px 12px; box-shadow: 0 3px 0 var(--ink); cursor: pointer; }
.act:disabled { background: #e6dcc9; opacity: 0.6; cursor: default; }
.act:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.chips .act, .chain .act { background: var(--chip-bg); color: var(--ink); }
.rows { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.row { display: flex; align-items: center; gap: 8px; border: 2px solid var(--ink); border-radius: 12px; padding: 6px 8px; background: var(--row-bg); border-left-width: 8px; }
.row-text { display: grid; flex: 1; min-width: 0; }
.row-label { font-weight: 700; }
.row-detail { font-size: 13px; color: var(--muted); }
.chip { font: 700 11px var(--font); text-transform: uppercase; letter-spacing: 0.06em; border: 2px solid var(--ink); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.bar { display: block; height: 9px; width: 90px; border: 2px solid var(--ink); border-radius: 6px; background: #e6dcc9; overflow: hidden; }
.bar i { display: block; height: 100%; background: #8fc7ff; }
.bar { position: relative; }
.bar b.held { position: absolute; top: 0; right: 0; bottom: 0; background: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.5) 0 3px, rgba(255, 255, 255, 0.15) 3px 6px); border-left: 1px solid rgba(255, 255, 255, 0.7); }
.school-destruction { border-left-color: var(--destruction); }
.school-alteration { border-left-color: var(--alteration); }
.school-conjuration { border-left-color: var(--conjuration); }
.school-illusion { border-left-color: var(--illusion); }
.school-restoration { border-left-color: var(--restoration); }
[data-term] { text-decoration: underline dotted; cursor: help; }

/* outside a match: panels flow in a centred column or grid */
body:not([data-screen="play"]) #panels { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 14px; padding: 40px; overflow: auto; background: rgba(27, 22, 38, 0.45); }
body:not([data-screen="play"]) .panel-center { width: min(640px, 100%); max-height: 86%; overflow: auto; }
body:not([data-screen="play"]) .panel-card { width: 280px; }
body:not([data-screen="play"]) .panel-bottom { background: transparent; border: none; box-shadow: none; color: #fff; text-align: center; width: 100%; }

/* in a match: panels sit around the 3D view */
body[data-screen="play"] .panel-hud { position: absolute; left: 12px; right: 120px; top: 10px; display: flex; gap: 10px; padding: 6px 10px; background: transparent; border: none; box-shadow: none; }
.hud-item { background: var(--paper); border: var(--line) solid var(--ink); border-radius: 14px; padding: 4px 12px; box-shadow: 0 3px 0 rgba(43, 33, 64, 0.35); display: grid; }
.hud-item.timer { background: var(--accent); color: #fff; }
.hud-label { font: 600 11px var(--font); text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.8; }
.hud-value { font: 800 20px var(--font); }
body[data-screen="play"] .panel-side { position: absolute; right: 12px; top: 84px; bottom: 70px; width: min(400px, 40%); overflow: auto; }
body[data-screen="play"] .panel-center { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(620px, 80%); max-height: 84%; overflow: auto; }
body[data-screen="play"] .panel-bottom { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(720px, 70%); }
body[data-screen="play"] .panel-corner { position: absolute; right: 12px; bottom: 12px; background: transparent; border: none; box-shadow: none; padding: 0; }
body[data-screen="play"] .panel-corner .actions { justify-content: flex-end; }
body[data-overlay="on"] .panel-side { display: none; }
body[data-screen="play"] .panel-jobs { position: absolute; left: 12px; top: 84px; width: min(280px, 24%); max-height: 50%; overflow: auto; padding: 8px 12px; }
body[data-overlay="on"] .panel-jobs { display: none; }
body[data-screen="play"] .panel-rising { position: absolute; right: 12px; top: 84px; width: min(300px, 24%); max-height: 60%; overflow: auto; padding: 8px 12px; }
body[data-screen="play"] .panel-hint { position: absolute; left: 12px; top: 84px; width: min(300px, 26%); font-size: 13px; padding: 8px 12px; opacity: 0.92; pointer-events: none; }
body[data-phase="battle"] #gl { cursor: grab; }
/* the map's own panel sits left of the map, so it stays usable while the map is open (T3) */
body[data-screen="play"] .panel-map { position: absolute; left: 12px; top: 84px; bottom: 70px; width: min(320px, 25%); overflow: auto; }
body[data-busy="drawing"] .panel-bottom, body[data-busy="interview"] .panel-bottom { top: 12px; bottom: auto; }
body[data-busy="sealing"] .panel-bottom, body[data-busy="sorting"] .panel-bottom { top: 44px; bottom: auto; left: auto; right: 12px; transform: none; width: 300px; font-size: 13px; padding: 8px 10px; }

.label3d { position: absolute; transform: translate(-50%, -100%); font: 800 14px var(--font); white-space: nowrap; }
.label3d.station { background: var(--paper); border: var(--line) solid var(--ink); border-radius: 12px; padding: 2px 10px; }
.label3d.seat { transform: none; background: var(--paper); border: var(--line) solid var(--ink); border-radius: 12px; padding: 2px 10px; }
.label3d.dmg { color: #fff; font-size: 18px; -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke; text-shadow: 0 2px 0 var(--ink); }
.label3d.dmg.strong { color: #ffd166; font-size: 23px; }
.label3d.dmg.weak { color: #c9d6e3; font-size: 15px; }
#toasts { display: grid; justify-content: center; align-content: start; gap: 6px; padding-top: 80px; }
.toast { background: var(--paper); border: var(--line) solid var(--ink); border-radius: 999px; padding: 4px 14px; font-weight: 700; box-shadow: 0 3px 0 rgba(43, 33, 64, 0.35); }

/* online: text boxes in a panel, and the pasted-code box */
.field { display: block; margin: 0 0 10px; font-weight: bold; }
.field input { display: block; width: 100%; box-sizing: border-box; margin-top: 4px; padding: 6px 8px; font: inherit; border: var(--line) solid var(--ink); border-radius: var(--radius); background: var(--paper, #fff); color: var(--ink); }
#ask { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(640px, 92%); z-index: 5; }
#ask textarea { display: block; width: 100%; box-sizing: border-box; min-height: 64px; font: 12px ui-monospace, monospace; margin: 0 0 10px; }
#ask .actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* spell piece cards (T10): the one a book just taught, and the glossary's */
.card { --school: var(--accent); display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: start; background: var(--paper); color: var(--ink); border: var(--line) solid var(--ink); border-left: 10px solid var(--school); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 4px 0 rgba(43, 33, 64, 0.35); }
.card.school-destruction { --school: var(--destruction); }
.card.school-alteration { --school: var(--alteration); }
.card.school-conjuration { --school: var(--conjuration); }
.card.school-illusion { --school: var(--illusion); }
.card.school-restoration { --school: var(--restoration); }
.card-icon { width: 96px; height: 96px; background: var(--chip-bg); border: 2px solid var(--ink); border-radius: 14px; }
.card-icon path { fill: none; stroke: var(--school); stroke-width: 80; stroke-linecap: round; stroke-linejoin: round; }
.card-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font: 700 12px var(--font); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.card-name { margin: 2px 0 4px; font: 800 26px/1.15 var(--font); }
.card-text { margin: 0 0 4px; font-size: 16px; }
.card-facts { margin: 0; font-size: 14px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; margin-top: 8px; }
#card { position: absolute; left: 50%; top: 84px; transform: translateX(-50%); width: min(560px, 70%); z-index: 3; pointer-events: none; }
#card:not(:empty) { animation: card-in 0.25s ease-out; }
#card .card { box-shadow: 0 8px 0 rgba(43, 33, 64, 0.45); }
#card .card-name { font-size: 34px; }
@keyframes card-in { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }

/* the title (T11), after Ape Race's: the name over a live battle, the menu
   on the left, the controls on the right, the version in the corner */
body[data-screen="title"] #panels { display: grid; grid-template-columns: minmax(220px, 300px) minmax(280px, 420px); grid-template-rows: auto auto; justify-content: center; align-content: center; column-gap: 24px; row-gap: 18px; background: linear-gradient(rgba(27, 22, 38, 0.15), rgba(27, 22, 38, 0.5)); }
body[data-screen="title"] .panel-logo { grid-column: 1 / -1; background: transparent; border: none; box-shadow: none; text-align: center; padding: 0; }
body[data-screen="title"] .panel-logo h2 { font: italic 900 clamp(44px, 8vw, 96px)/1 var(--font); color: var(--gold); letter-spacing: 0.02em; text-shadow: 0 5px 0 #7a4a12, 0 10px 18px rgba(0, 0, 0, 0.45); margin: 0; animation: logo-in 0.9s cubic-bezier(0.2, 1.4, 0.4, 1) both, logo-bob 6s ease-in-out 0.9s infinite; }
body[data-screen="title"] .panel-logo p { color: #fff8ec; font-size: 20px; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); margin-top: 10px; animation: fade-up 0.8s 0.4s both; }
body[data-screen="title"] .panel-menu, body[data-screen="title"] .panel-controls { background: rgba(27, 22, 38, 0.72); color: #fff8ec; border-color: rgba(255, 248, 236, 0.35); backdrop-filter: blur(4px); animation: fade-up 0.7s 0.6s both; }
body[data-screen="title"] .panel-menu .actions { flex-direction: column; align-items: stretch; gap: 10px; }
body[data-screen="title"] .panel-menu .act { font-size: 18px; padding: 9px 14px; }
body[data-screen="title"] .panel-controls h2 { font-size: 14px; letter-spacing: 0.12em; text-transform: uppercase; }
body[data-screen="title"] .panel-controls .row { background: transparent; border: none; padding: 2px 0; }
body[data-screen="title"] .panel-controls .row-text { display: flex; justify-content: space-between; gap: 12px; }
body[data-screen="title"] .panel-controls .row-detail { color: #fff8ec; font-weight: 700; font-size: 14px; }
body[data-screen="title"] .panel-controls p { font-size: 13px; opacity: 0.85; margin-top: 10px; }
body[data-screen="title"] .panel-version { position: absolute; right: 10px; bottom: 8px; background: transparent; border: none; box-shadow: none; padding: 0; }
body[data-screen="title"] .panel-version .act { font-size: 12px; padding: 2px 8px; background: rgba(27, 22, 38, 0.6); color: #fff8ec; box-shadow: none; }
.badge { display: inline-block; margin-left: 8px; padding: 0 7px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 800; vertical-align: middle; animation: badge-pulse 1.6s ease-in-out infinite; }
.row-list { margin: 4px 0 0 18px; padding: 0; }
.row-list li { margin: 2px 0; }
@keyframes logo-in { from { opacity: 0; transform: translateY(-30px) scale(0.85) rotate(-3deg); } to { opacity: 1; transform: none; } }
@keyframes logo-bob { 0%, 100% { transform: none; } 50% { transform: translateY(-6px) rotate(-1deg); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes badge-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) { body[data-screen="title"] * { animation: none !important; } }

/* a mana cost: a drop of mana and its number (T13) */
.mana { display: inline-flex; align-items: center; gap: 4px; font: 800 14px var(--font); color: var(--ink); white-space: nowrap; }
.mana::before { content: ""; width: 12px; height: 12px; background: linear-gradient(135deg, #b9e3ff, #3d8bfd 60%, #2456b8); border: 2px solid var(--ink); border-radius: 50% 0 50% 50%; transform: rotate(-45deg); flex: none; }
.panel-mana { margin: 4px 0 8px; }
.panel-mana .mana { font-size: 22px; }
.panel-mana .mana::before { width: 18px; height: 18px; }
#card .mana { font-size: 18px; }

/* office hours (T15, T32), after its mockup: one panel, three columns */
body[data-screen="play"] .panel-office { position: absolute; left: 12px; right: 12px; top: 84px; bottom: 70px; display: grid; grid-template-columns: 24% minmax(0, 1fr) 37%; gap: 14px; }
.panel-office .col { overflow: auto; min-height: 0; }
.panel-office .col-roster h2 { font-size: 24px; }
.panel-office .col-who, .panel-builder .col-sum { border: var(--line) solid var(--ink); border-radius: 14px; background: var(--card-bg); padding: 12px 14px; }
.panel-office .col-who h2 { font-size: 26px; }
body[data-screen="play"][data-station="office"] .panel-jobs { display: none; }
/* a panel that fills the room hides the stations' labels behind it */
body[data-station="office"] #labels, body[data-station="lab"] #labels { display: none; }

/* the spell builder (T17), after the wireframe and Galactic Survivors' rigs:
   blue modifiers, red payloads, yellow triggers */
body[data-screen="play"] .panel-builder { position: absolute; left: 12px; right: 12px; top: 84px; bottom: 70px; overflow: auto; }
.lane { display: grid; gap: 10px; margin: 8px 0 10px; padding: 10px; border-radius: 14px; background: var(--row-bg); border: 2px solid rgba(43, 33, 64, 0.25); overflow-x: auto; }
.lane-row { display: flex; align-items: center; gap: 10px; min-height: 120px; }
.set { display: flex; align-items: center; gap: 6px; padding-right: 10px; border-right: 4px solid var(--ink); }
.set.open { border-right: none; }
.mods { display: grid; gap: 4px; }
.slot { width: 104px; min-height: 52px; border: 4px solid; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; font: 800 12px var(--font); padding: 4px; background: var(--paper); color: var(--ink); box-shadow: 0 3px 0 rgba(43, 33, 64, 0.3); }
.slot.pay { min-height: 112px; border-color: #e0453a; }
.slot.mod { border-color: #4a5fd1; }
.slot.trig { min-height: 86px; border-color: #e8c21a; }
.slot.empty { border-style: dashed; background: transparent; box-shadow: none; color: var(--muted); }
.slot.spell { border-color: #e0453a; background: var(--chip-bg); min-height: 112px; }
.slot.spell b { font-size: 14px; margin-top: 4px; }
.slot.filled:hover { transform: translateY(-2px); }
.slot-icon { width: 40px; height: 40px; }
.slot-icon path, .act-icon path { fill: none; stroke: currentColor; stroke-width: 90; stroke-linecap: round; stroke-linejoin: round; }
/* the icon takes the school's colour; the text stays ink, so it reads */
.slot.filled, .tile { color: var(--ink); }
.school-destruction .slot-icon { color: var(--destruction); }
.school-alteration .slot-icon { color: var(--alteration); }
.school-conjuration .slot-icon { color: var(--conjuration); }
.school-illusion .slot-icon { color: var(--illusion); }
.school-restoration .slot-icon { color: var(--restoration); }
.slot-name { color: var(--ink); }
.branch-from { writing-mode: vertical-rl; transform: rotate(180deg); font: 800 11px var(--font); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 4px; border-left: 4px dashed #e8c21a; }
.tray { display: grid; gap: 8px; margin-top: 10px; }
.tray h3 { margin: 4px 0; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.tiles { display: flex; flex-wrap: wrap; gap: 6px; }
.tile { display: inline-flex; flex-direction: column; align-items: center; width: 100px; padding: 4px; background: var(--paper); border-width: 3px; }
.tile.pay { border-color: #e0453a; } .tile.mod { border-color: #4a5fd1; } .tile.trig { border-color: #e8c21a; } .tile.branch { border-color: var(--muted); }
/* spells on yourself (T28): small icons by the HUD, their text on hover */
body[data-screen="play"] .panel-self { position: absolute; left: 12px; top: 70px; display: flex; gap: 4px; padding: 0; background: transparent; border: none; box-shadow: none; }
.panel-self .act { padding: 2px 4px; font-size: 11px; display: inline-flex; align-items: center; gap: 2px; background: var(--chip-bg); color: var(--ink); }
.act-icon { width: 22px; height: 22px; color: var(--restoration); }

/* blocks the core lays out (T32): headings, notes, meters, tables, boards */
.panel h3 { margin: 12px 0 6px; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.panel .muted { color: var(--muted); font-size: 14px; }
.panel .small { color: var(--muted); font-size: 12px; margin-top: 6px; }
.note { background: var(--note-bg); border: 2px dashed var(--ink); border-radius: 10px; padding: 6px 10px; font-size: 13px; margin: 8px 0; }
.note b { color: var(--bad); }
.keys { font-size: 14px; }
kbd { font: 800 13px var(--font); color: var(--ink); border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 6px; padding: 0 6px; background: var(--card-bg); }
.meters { display: grid; grid-template-columns: minmax(90px, auto) minmax(60px, 1fr) 52px; gap: 5px 8px; align-items: center; font-size: 14px; }
.m-value { text-align: right; }
.track { position: relative; display: block; height: 12px; border: 2px solid var(--ink); border-radius: 6px; background: var(--track); overflow: hidden; }
.track i { position: absolute; left: 0; top: 0; bottom: 0; background: #8fc7ff; }
.track.centre::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; border-left: 2px solid var(--ink); }
.tone-mana { background: #8fc7ff !important; }
.tone-good { background: #7fd6a8 !important; }
.tone-gold { background: var(--gold) !important; }
.tone-destruction { background: var(--destruction) !important; }
.tone-alteration { background: var(--alteration) !important; }
.tone-conjuration { background: var(--conjuration) !important; }
.tone-illusion { background: var(--illusion) !important; }
.tone-restoration { background: var(--restoration) !important; }
.chip.tone-good { background: #d6f2e6 !important; color: #2b2140; }
.table { border-collapse: collapse; width: 100%; font-size: 14px; }
.table td, .table th { padding: 4px 6px; text-align: left; border-bottom: 1px solid rgba(43, 33, 64, 0.15); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.big { font: 900 26px var(--font); margin: 2px 0 6px; }
.big small { font-size: 15px; color: var(--good); margin-left: 6px; }
.chip-row { display: flex; gap: 6px; margin: 6px 0; }

/* buttons in groups: a chosen one is gold, the rest soft */
.seg, .tabs, .soft { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.seg .act, .tabs .act, .soft .act, .chips .act { background: var(--chip-bg); color: var(--ink); }
.act.on, .seg .act.on, .tabs .act.on, .chips .act.on { background: var(--gold); color: var(--on-button); }
.steps, .adds { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.steps .act { background: var(--card-bg); color: var(--ink); border-color: #e0453a; box-shadow: 0 3px 0 rgba(43, 33, 64, 0.3); display: inline-flex; align-items: center; gap: 6px; }
.adds .act { background: transparent; color: var(--ink); border-style: dashed; box-shadow: none; font-size: 13px; padding: 3px 9px; }
.act .mana { margin-left: 6px; color: inherit; }
/* the spell's card stays light in either theme, so its words stay dark */
.slot.spell .mana { color: #2b2140; }
.num { font-style: normal; background: var(--ink); color: var(--paper); border-radius: 50%; width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }

/* a row that is one button: press to pick, drag to a seat */
.row.on { background: var(--on-bg); box-shadow: 0 0 0 3px var(--gold); }
.row.dim { opacity: 0.6; }
.row:has(.row-press) { padding: 0; }
.act.row-press { display: flex; align-items: center; gap: 8px; width: 100%; background: transparent; border: none; box-shadow: none; padding: 6px 8px; text-align: left; font: inherit; color: var(--ink); border-radius: 10px; cursor: grab; touch-action: none; }
.act.row-press.on { background: transparent; }
.act.row-press .row-label { font-weight: 800; }
body[data-dragging="on"] { cursor: grabbing; }
.sw { width: 22px; height: 22px; border: 2px solid var(--ink); border-radius: 5px; flex: none; }
.sw-glass { background: var(--glass); } .sw-ivory { background: var(--ivory); } .sw-lava { background: var(--lava); } .sw-bait { background: var(--bait); } .sw-sub { background: var(--sub); }

/* the field as boxes (T32, T33): route, walls, the tower, a disc per seat */
.board { position: relative; width: 100%; background: var(--cell_open); border: var(--line) solid var(--ink); border-radius: 14px; overflow: hidden; }
.bi { position: absolute; }
.bi-route { background: var(--cell_route); }
.bi-scenery { background: var(--cell_scenery); }
.bi-entry { background: var(--cell_entry); }
.bi-tower { background: var(--cell_tower); border: 2px solid var(--ink); border-radius: 6px; }
.bi.act { padding: 0; border: 3px solid var(--ink); border-radius: 50%; box-shadow: none; font: 800 12px var(--font); background: var(--paper); color: var(--muted); display: flex; align-items: center; justify-content: center; touch-action: none; }
.bi.act:disabled { opacity: 1; cursor: default; }
.bi.act.taken { background: var(--accent); color: #fff; cursor: grab; }
.bi.act.given { background: var(--sub); color: #2b2140; cursor: grab; }
.bi.act.on { background: var(--gold); color: #2b2140; box-shadow: 0 0 0 3px var(--gold); }
.bi.act:hover { transform: scale(1.12); }

/* the map table (T23, T32, T33), after its mockup */
body[data-screen="play"] .panel-map { width: calc(27.5% - 24px); }
.panel-map .row { padding: 0; border-left-width: 2px; background: var(--card-bg); }
.panel-map .row .chip { margin-left: auto; }
body[data-screen="play"] .panel-route { position: absolute; right: 12px; top: 84px; width: calc(27.5% - 24px); max-height: calc(100% - 154px); overflow: auto; font-size: 14px; }
body[data-busy="sealing"] .panel-route, body[data-busy="sorting"] .panel-route { display: none; }

/* the builder (T17, T32), after its mockup: the lane, then the tray beside this spell */
body[data-screen="play"] .panel-builder { display: grid; grid-template-columns: minmax(0, 1fr) 290px; grid-template-areas: "head head" "lane lane" "tray sum"; align-content: start; gap: 8px 14px; }
.panel-builder .col-head { grid-area: head; }
.panel-builder .col-head p { margin: 0; }
.panel-builder .col-lane { grid-area: lane; min-width: 0; }
.panel-builder .col-tray { grid-area: tray; min-width: 0; }
.panel-builder .col-sum { grid-area: sum; align-self: start; }
.panel-builder .col-sum h2 { font-size: 24px; margin: 0; }
.panel-builder .col-sum h3 { margin-top: 0; }
.panel-builder .col-sum .panel-mana .mana { font-size: 28px; }
.lane { margin: 0; padding: 12px; background: repeating-linear-gradient(90deg, rgba(43, 33, 64, 0.04) 0 40px, transparent 40px 80px), var(--row-bg); }
.lane-row { gap: 18px; min-height: 0; }
.set { position: relative; gap: 18px; padding: 22px 0 0; border-right: none; }
.set-label { position: absolute; top: 0; left: 0; font: 800 12px var(--font); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.mods { gap: 6px; }
.slot { position: relative; width: 120px; min-height: 66px; gap: 2px; background: var(--card-bg); }
.slot small { font: 800 10px var(--font); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.slot-name { font: 800 15px/1.15 var(--font); }
.slot-does { font: 600 11px/1.2 var(--font); color: var(--ink); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.slot.pay { width: 140px; min-height: 150px; }
.slot.pay .slot-icon { width: 64px; height: 64px; }
.slot.trig { width: 126px; min-height: 120px; }
.slot.spell { width: 136px; min-height: 110px; background: #fff0ee; color: #2b2140; }
.slot.spell small { color: #6b5f80; }
.slot.spell b { font: 800 16px/1.15 var(--font); }
.slot.empty { background: transparent; }
.slot.empty .slot-name { font-size: 15px; color: var(--muted); }
/* the wire between one slot and the next */
.set > .slot::before, .set > .mods::before, .lane-row > .set::before { content: ""; position: absolute; left: -18px; top: 50%; width: 18px; height: 4px; background: var(--ink); }
.set > .mods { position: relative; }
.set > .slot:first-of-type::before { display: none; }
.lane-row > .set::before { top: calc(50% + 11px); }
.lane-row > .slot.spell + .set::before, .lane-row > .set + .set::before { display: block; }
.lane-row > .set:first-child::before, .lane-row > .branch-from + .set::before { display: none; }
.tray { margin-top: 0; gap: 6px; }
.tray .tabs { margin: 0; }
.tile { width: 128px; min-height: 92px; justify-content: center; gap: 2px; border-radius: 12px; font-size: 14px; touch-action: none; cursor: grab; }
.tile .slot-icon { width: 36px; height: 36px; }
.tile.unread { display: inline-flex; align-items: center; justify-content: center; opacity: 0.45; border: 3px dashed var(--muted); color: var(--muted); font: 800 13px var(--font); cursor: default; }
.tile.unread.pay { border-color: #e0453a; } .tile.unread.mod { border-color: #4a5fd1; } .tile.unread.trig { border-color: #e8c21a; }

/* the seal and the sorting game (T20, T22, T32): the panel sits where the
   core says, and the overlay draws the dial or the falling book over it */
body[data-busy="sealing"] #overlay, body[data-busy="sorting"] #overlay { z-index: 2; pointer-events: none; }
body[data-busy="sealing"] .panel-jobs, body[data-busy="sorting"] .panel-jobs, body[data-busy="sealing"] .panel-self, body[data-busy="sorting"] .panel-self { display: none; }
body[data-screen="play"] .panel-seal, body[data-screen="play"] .panel-sort { position: absolute; box-shadow: 0 5px 0 rgba(43, 33, 64, 0.4), 0 0 0 200vmax var(--shade); }
.panel-seal .col-head p, .panel-sort .col-head p { margin: 0; }
.panel-seal .col-side { position: absolute; left: 58%; right: 30px; top: 96px; bottom: 16px; overflow: auto; }
.panel-seal .col-side .rows { margin-top: 0; }
.panel-seal .row-label { font-size: 17px; }
.panel-seal .row .chip { margin-left: auto; }
.panel-sort .col-pile { position: absolute; left: 34px; top: 108px; width: 210px; }
.pile b { font-size: 13px; }
.pile-books { margin-top: 4px; }
.pile-book { display: inline-block; width: 36px; height: 26px; border: 2px solid var(--ink); border-radius: 4px; margin: 2px; transform: rotate(-8deg); }
.pile-book:nth-child(odd) { transform: rotate(5deg); }
.panel-sort .col-found { position: absolute; right: 30px; top: 108px; width: 290px; font-size: 14px; }
.progress-top { display: flex; justify-content: space-between; font-size: 14px; }
.progress .track { height: 16px; border-width: 3px; border-radius: 8px; margin-top: 2px; }
.panel-sort .col-shelves { position: absolute; left: 30px; right: 30px; bottom: 26px; height: 210px; }
.shelves { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 12px; height: 100%; }
.act.shelf { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; border: 4px solid var(--ink); border-radius: 12px; color: #fff; font: 800 18px var(--font); padding: 8px; box-shadow: 0 4px 0 var(--ink); }
.act.shelf:active { transform: translateY(2px); }
.spines { display: flex; gap: 3px; align-items: flex-end; height: 90px; }
.spine { width: 14px; border: 2px solid var(--ink); border-radius: 3px; }
.shelf kbd { margin-top: 2px; }
.pile-book.school-destruction, .shelf.school-destruction .spine { background: var(--destruction); }
.pile-book.school-alteration, .shelf.school-alteration .spine { background: var(--alteration); }
.pile-book.school-conjuration, .shelf.school-conjuration .spine { background: var(--conjuration); }
.pile-book.school-illusion, .shelf.school-illusion .spine { background: var(--illusion); }
.pile-book.school-restoration, .shelf.school-restoration .spine { background: var(--restoration); }
.act.shelf.school-destruction { background: color-mix(in srgb, var(--destruction) 78%, #000); }
.act.shelf.school-alteration { background: color-mix(in srgb, var(--alteration) 72%, #000); }
.act.shelf.school-conjuration { background: color-mix(in srgb, var(--conjuration) 80%, #000); }
.act.shelf.school-illusion { background: color-mix(in srgb, var(--illusion) 70%, #000); }
.act.shelf.school-restoration { background: color-mix(in srgb, var(--restoration) 68%, #000); }
body[data-screen="play"] .panel-golem-card { position: absolute; right: 16px; top: 250px; width: 280px; font-size: 13px; z-index: 1; }
.panel-golem-card h2 { font-size: 17px; }

/* the HUD over the 3D view (T34): dark see-through cards, gold for what
   matters, the same in light and dark themes */
body[data-screen="play"] .hud-item, body[data-screen="play"] .hud-item.timer { background: var(--glass-bg); color: var(--glass-ink); border: 1px solid var(--glass-line); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); backdrop-filter: blur(3px); }
body[data-screen="play"] .hud-item .hud-label { color: var(--glass-muted); opacity: 1; }
body[data-screen="play"] .hud-item.timer .hud-value { color: var(--glass-gold); }
body[data-screen="play"] .hud-item .bar { border: 1px solid var(--glass-line); background: rgba(255, 255, 255, 0.14); }
body[data-screen="play"] .hud-item .bar i { background: linear-gradient(90deg, #6ad7ff, #a98bff); }
.label3d.station, .label3d.seat { background: var(--glass-bg); color: var(--glass-gold); border: 1px solid var(--glass-line); border-radius: 999px; padding: 3px 12px 4px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }
body[data-phase="prep"][data-busy=""] .panel-bottom, body[data-screen="play"] .panel-hint { background: var(--glass-bg); color: var(--glass-ink); border: 1px solid var(--glass-line); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); backdrop-filter: blur(3px); }

/* every tile says what it does (T38) */
.slot-facts { font: 700 11px/1.2 var(--font); color: var(--muted); }
.tile { width: 176px; min-height: 120px; align-items: flex-start; text-align: left; padding: 8px 10px; }
.tile .slot-does { -webkit-line-clamp: 2; }
.slot { width: 150px; }
.slot.pay { width: 170px; }
.slot.trig { width: 150px; }
.steps-list { margin: 4px 0 8px; padding-left: 20px; font-size: 13.5px; }
.steps-list li { margin-bottom: 4px; }

/* the book pile (T39): books on the floor to drag to their shelves */
.panel-sort .col-pile { width: 56%; }
.panel-sort .col-pile .board { background: radial-gradient(ellipse at 50% 60%, #c48a55, #a86d40 70%); }
.bi-book.act { border-radius: 8px; color: #fff; font: 800 13px var(--font); box-shadow: 0 4px 0 rgba(43, 33, 64, 0.35); cursor: grab; }
.bi-book.act.on { box-shadow: 0 0 0 4px var(--gold), 0 10px 14px rgba(0, 0, 0, 0.3); color: #fff; }
.bi-book.school-destruction { background: color-mix(in srgb, var(--destruction) 85%, #000); }
.bi-book.school-alteration { background: color-mix(in srgb, var(--alteration) 75%, #000); }
.bi-book.school-conjuration { background: color-mix(in srgb, var(--conjuration) 85%, #000); }
.bi-book.school-illusion { background: color-mix(in srgb, var(--illusion) 70%, #000); }
.bi-book.school-restoration { background: color-mix(in srgb, var(--restoration) 62%, #000); }
body[data-dragging="on"] .act.shelf { box-shadow: 0 0 0 4px var(--gold), 0 4px 0 var(--ink); }

/* the journey (T45): the overlay draws the run inside the panel's box */
body[data-busy="journey"] #overlay { z-index: 2; pointer-events: none; }
body[data-busy="journey"] .panel-jobs, body[data-busy="journey"] .panel-self { display: none; }
body[data-screen="play"] .panel-journey { position: absolute; background: linear-gradient(#ffb37a, #ffe2b0); box-shadow: 0 5px 0 rgba(43, 33, 64, 0.4), 0 0 0 200vmax var(--shade); color: #2b2140; }
.panel-journey h2 { font-size: 24px; margin: 0; }
.panel-journey p { margin: 2px 0 6px; color: #4a3d5c; }
.panel-journey kbd { color: #2b2140; }

/* the invasion book (T40, T44): your students, the road to each rival */
body[data-screen="play"] .panel-raid { position: absolute; left: 12px; right: 12px; top: 84px; bottom: 70px; display: grid; grid-template-columns: 30% minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "list road road" "list home spells"; grid-template-rows: auto minmax(0, 1fr); gap: 12px 14px; }
.panel-raid .col { min-height: 0; overflow: auto; }
.panel-raid .col-list { grid-area: list; }
.panel-raid .col-road { grid-area: road; }
.panel-raid .col-home { grid-area: home; border: var(--line) solid var(--ink); border-radius: 14px; background: var(--card-bg); padding: 10px 12px; }
.panel-raid .col-spells { grid-area: spells; border: var(--line) solid var(--ink); border-radius: 14px; background: var(--card-bg); padding: 10px 12px; }
.panel-raid .col-road .board { background: linear-gradient(#bfe3ff, #e4f2ff 55%, #9cc874 55%, #86b862); }
.bi-rival.act { border-radius: 12px; background: var(--paper); color: #2b2140; font: 700 13px/1.25 var(--font); text-align: left; padding: 6px 10px; justify-content: flex-start; }
.bi-rival.act.on { box-shadow: 0 0 0 4px var(--gold); }
.bi-rival.act:hover { transform: none; }
.bi-walker { border: 3px solid var(--ink); border-radius: 50%; color: #fff; font: 800 12px var(--font); display: flex; align-items: center; justify-content: center; }
.bi-walker.school-destruction { background: var(--destruction); } .bi-walker.school-alteration { background: var(--alteration); } .bi-walker.school-conjuration { background: var(--conjuration); } .bi-walker.school-illusion { background: var(--illusion); } .bi-walker.school-restoration { background: #a67e22; }
.panel-raid .col-road .bi-tower { color: #fff; font: 800 13px var(--font); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; }

/* office hours' tree (T41), after Vagrancy's BT lab */
.col-deploy .board { background: #fbf6ee; }
.bi[class*="bi-node"] { border: 2.5px solid var(--ink); border-radius: 5px; background: #fff; color: #2b2140; font: 700 11.5px/1.15 var(--font); display: flex; align-items: center; padding: 2px 6px; overflow: hidden; }
.bi-node-first { background: #fff1c9; } .bi-node-seq { background: #e9e0ff; } .bi-node-ask { border-radius: 999px; background: #eef3ff; }
.bi.ran { box-shadow: 0 0 0 3px var(--good); } .bi.running { box-shadow: 0 0 0 3px var(--gold); } .bi.failed { box-shadow: 0 0 0 3px var(--bad); }
.bi-edge { background: var(--ink); }

/* the battle's raiders and the tree being watched (T41, T44) */
body[data-screen="play"] .panel-raiders { position: absolute; left: 12px; top: 196px; width: min(300px, 26%); max-height: 46%; overflow: auto; background: var(--glass-bg); color: var(--glass-ink); border: 1px solid var(--glass-line); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); padding: 8px 12px; font-size: 13px; }
body[data-screen="play"] .panel-mind { position: absolute; right: 12px; top: 84px; width: min(320px, 28%); max-height: 56%; overflow: auto; background: var(--glass-bg); color: var(--glass-ink); border: 1px solid var(--glass-line); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); padding: 8px 12px; font-size: 13px; }
.panel-raiders h3, .panel-mind h3 { color: var(--glass-muted); margin: 4px 0; }
.panel-raiders .row { background: rgba(255, 255, 255, 0.06); border-color: var(--glass-line); color: var(--glass-ink); }
.panel-raiders .row-detail, .panel-mind p { color: var(--glass-muted); }
.panel-raiders .row.school-foe { border-left-color: #ff6f6f; }
.tree-line { font: 700 13px/1.5 var(--font); color: var(--glass-muted); }
.tree-mark { display: inline-block; width: 1.2em; }
.tree-line.ran { color: #9fe39a; } .tree-line.running { color: var(--glass-gold); } .tree-line.failed { color: #ff9a8a; }
.label3d.foe { background: var(--glass-bg); color: #ff9a8a; border: 1px solid rgba(255, 120, 110, 0.5); border-radius: 999px; padding: 2px 10px; font-size: 12px; }
body[data-view="all"] .panel-mind { display: none; }
.bi-note { background: var(--paper); border: 2px dashed var(--ink); border-radius: 10px; color: #2b2140; font: 700 14px var(--font); display: flex; align-items: center; justify-content: center; text-align: center; padding: 6px; }
.bi-dot { background: #d8bb8c; border: 2px solid rgba(43, 33, 64, 0.35); border-radius: 50%; }
.bi-roof { background: var(--cell_tower); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
/* a gold chip keeps dark words in either theme (R8.13) */
.chip.tone-gold { color: #2b2140; }

/* round 10: instructions on hover (T49), the lesson's card (T48) */
.help { display: inline-grid; place-items: center; width: 1.3em; height: 1.3em; margin-left: 0.4em; border-radius: 50%; border: 1px solid currentColor; font-size: 0.7em; vertical-align: middle; cursor: help; opacity: 0.75; }
.help:hover, .help:focus { opacity: 1; }
.lesson { margin-top: 10px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--glass-line, var(--ink)); background: rgba(255, 215, 120, 0.12); }
.lesson h3 { margin: 0 0 4px; font-size: 0.95em; }
/* what you are dragging, in your hand under the pointer (T53) */
.in-hand { position: fixed; left: 0; top: 0; margin: 0; z-index: 50; pointer-events: none; transform: translate(-50%, -60%) rotate(-6deg) scale(1.06); box-shadow: 0 14px 28px rgba(0, 0, 0, 0.45); opacity: 0.95; }
body[data-dragging="on"] .board .act.on { opacity: 0.35; }
/* the rehearsal's chip (T48) */
.hud-item .hud-note { font-size: 0.72em; opacity: 0.85; }
.hud-item .hud-note.tone-good { color: #7ff0b0; opacity: 1; }
.hud-item .hud-note.tone-bad { color: #ff9a8a; opacity: 1; }
.hud-item.rehearsal.stale .hud-value { opacity: 0.55; }
