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

:root {
  --bg:        #0e0e0f;
  --bg2:       #161618;
  --bg3:       #1e1e21;
  --border:    #2a2a2e;
  --narrator:  #8b9aa8;
  --scene:     #c4b89a;
  --creature:  #d4a843;
  --outcome:   #e8e0d0;
  --red:       #c0392b;
  --green:     #27ae60;
  --gold:      #c9a227;
  --fate:      #8e44ad;
  --ui-blue:   #4a9fd4;
  /* stat colors */
  --str:       #e8752a;
  --int:       #a855f7;
  --dex:       #2ecc71;
  --stamina:   #c0392b;
  --sanity:    #2980b9;
  --radius:    5px;
  --font:      'Georgia', 'Times New Roman', serif;
  --mono:      'Courier New', monospace;
  /* max width — average mobile */
  --maxw:      480px;
}

html, body {
  background: var(--bg);
  color: var(--scene);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  min-height: 100dvh;
}

.screen { display: none; flex-direction: column; min-height: 100dvh; max-width: var(--maxw); margin: 0 auto; }
.screen.active { display: flex; }

/* ── COLORS ────────────────────────────────────────────────── */
.str-color     { color: var(--str); }
.int-color     { color: var(--int); }
.dex-color     { color: var(--dex); }
.stamina-label { color: var(--stamina); }
.sanity-label  { color: var(--sanity); }
.fate-label    { color: var(--fate); }
.gold-label    { color: var(--gold); }

/* ── START ──────────────────────────────────────────────────── */
#screen-start { align-items: center; justify-content: center; padding: 2rem 1.5rem; text-align: center; }

.start-wrap { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 1rem; align-items: center; }

.tower-title { display: flex; flex-direction: column; }
.title-small { font-size: 0.9rem; letter-spacing: 0.2em; color: var(--narrator); text-transform: uppercase; }
.title-large { font-size: 2.2rem; font-style: italic; color: var(--scene); line-height: 1.1; }
.title-sub   { color: var(--narrator); font-size: 0.8rem; font-style: italic; }

.name-entry { display: flex; flex-direction: column; gap: 0.5rem; width: 100%; }
.name-entry label { color: var(--narrator); font-size: 0.85rem; font-style: italic; }
.name-entry input {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--outcome); font-family: var(--font); font-size: 1rem; padding: 0.65rem 0.9rem; width: 100%; outline: none;
}
.name-entry input:focus { border-color: var(--ui-blue); }

.error-text { color: var(--red); font-size: 0.8rem; }
.hidden { display: none !important; }

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn-primary {
  background: var(--bg3); border: 1px solid var(--ui-blue); border-radius: var(--radius);
  color: var(--ui-blue); cursor: pointer; font-family: var(--font); font-size: 0.9rem;
  padding: 0.65rem 1.2rem; width: 100%; transition: background 0.15s, color 0.15s; margin-top: 0.25rem;
}
.btn-primary:hover  { background: var(--ui-blue); color: var(--bg); }
.btn-primary:active { background: var(--ui-blue); color: var(--bg); }

.btn-secondary {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--narrator); cursor: pointer; font-family: var(--font); font-size: 0.8rem;
  padding: 0.4rem 0.75rem; transition: border-color 0.15s, color 0.15s;
}
.btn-secondary:hover { border-color: var(--scene); color: var(--scene); }

.btn-ghost { background: transparent; border: none; color: var(--narrator); cursor: pointer; font-family: var(--font); font-size: 0.8rem; padding: 0.4rem; text-decoration: underline; }
.btn-ghost:hover { color: var(--scene); }
.btn-ghost-sm { background: transparent; border: none; color: var(--narrator); cursor: pointer; font-family: var(--font); font-size: 0.75rem; padding: 0.3rem; text-decoration: underline; }

.btn-danger { background: transparent; border: 1px solid var(--red); border-radius: var(--radius); color: var(--red); cursor: pointer; font-family: var(--font); font-size: 0.85rem; padding: 0.6rem 1rem; }
.btn-danger:hover { background: var(--red); color: var(--bg); }

.full-width { width: 100%; }

.btn-continue {
  background: var(--bg3); border: 1px solid var(--ui-blue); border-radius: var(--radius);
  color: var(--ui-blue); cursor: pointer; font-family: var(--font); font-size: 0.95rem;
  padding: 0.7rem 2ch; min-width: 60%; width: auto; margin-top: 0.5rem; transition: background 0.15s;
}
.btn-continue:hover { background: var(--ui-blue); color: var(--bg); }

/* ── TITLE BAR ──────────────────────────────────────────────── */
#title-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.4rem 0.75rem; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.title-bar-name { color: var(--narrator); font-size: 0.75rem; font-style: italic; letter-spacing: 0.05em; }
.title-bar-right { display: flex; gap: 0.4rem; align-items: center; }

.btn-help {
  background: var(--fate); border: none; border-radius: var(--radius);
  color: #fff; cursor: pointer; font-family: var(--mono); font-size: 0.65rem;
  font-weight: bold; letter-spacing: 0.05em; padding: 0.2rem 0.45rem;
}
.btn-help:hover { opacity: 0.85; }

.btn-abandon {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--narrator); cursor: pointer; font-size: 0.75rem; padding: 0.18rem 0.45rem; line-height: 1;
}
.btn-abandon:hover { border-color: var(--red); color: var(--red); }

.btn-map {
  background: var(--bg3); border: 1px solid var(--ui-blue); border-radius: var(--radius);
  color: var(--ui-blue); cursor: pointer; font-family: var(--mono); font-size: 0.65rem;
  font-weight: bold; letter-spacing: 0.05em; padding: 0.2rem 0.45rem;
}
.btn-map:hover { background: var(--ui-blue); color: var(--bg); }

/* ── FLOOR INDICATOR ────────────────────────────────────────── */
#floor-map-wrap { padding: 0.35rem 0.75rem; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }

#floor-label { color: var(--narrator); font-size: 0.72rem; letter-spacing: 0.06em; font-family: var(--mono); }

#floor-rooms { display: none; } /* rooms shown in map modal only */

/* ── MAP MODAL ──────────────────────────────────────────────── */
.map-modal-content { display: flex; flex-direction: column; gap: 0.3rem; max-height: 60dvh; overflow-y: auto; }

.map-floor-section { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.map-floor-label { background: var(--bg3); color: var(--narrator); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; padding: 0.25rem 0.5rem; }

.map-room-row {
  display: grid; grid-template-columns: 24px 1fr auto; gap: 0.2rem 0.5rem;
  padding: 0.3rem 0.5rem; border-top: 1px solid var(--border); align-items: center;
}
.map-room-row.current { background: rgba(74,159,212,0.08); }
.map-room-row.visited { opacity: 0.5; }
.map-room-num  { font-family: var(--mono); font-size: 0.7rem; color: var(--narrator); text-align: right; }
.map-room-name { font-size: 0.8rem; color: var(--scene); }
.map-room-name.unknown { color: var(--narrator); font-style: italic; }
.map-room-name.current { color: var(--ui-blue); }
.map-room-tag  { font-size: 0.6rem; color: var(--narrator); font-family: var(--mono); white-space: nowrap; }
.map-room-tag.current-tag { color: var(--ui-blue); }

/* ── EQUIPMENT ──────────────────────────────────────────────── */
#slots { display: flex; gap: 0.35rem; padding: 0.4rem 0.75rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }

.slot { flex: 1; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.3rem 0.4rem; min-width: 0; }
.slot-label { display: block; font-size: 0.55rem; color: var(--narrator); text-transform: uppercase; letter-spacing: 0.08em; }
.slot-name  { display: block; font-size: 0.82rem; color: var(--scene); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-stat  { display: block; font-size: 0.78rem; font-family: var(--mono); }

/* ── LORE BAR ───────────────────────────────────────────────── */
#lore-bar { padding: 0.35rem 0.75rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }

.btn-lore {
  background: transparent; border: 1px dashed var(--border); border-radius: var(--radius);
  color: var(--narrator); cursor: pointer; font-family: var(--font); font-size: 0.75rem;
  font-style: italic; padding: 0.3rem 0.6rem; width: 100%; text-align: center; transition: color 0.15s, border-color 0.15s;
}
.btn-lore:hover { color: var(--gold); border-color: var(--gold); }
.btn-lore:disabled { opacity: 0.4; cursor: default; }

/* ── MAIN TEXT ──────────────────────────────────────────────── */
#main-text { padding: 0.75rem; flex: 1; }

.text-narrator { color: var(--narrator); font-style: italic; font-size: 0.85rem; margin-bottom: 0.6rem; line-height: 1.6; }
.text-scene    { color: var(--scene);    font-size: 0.9rem;  margin-bottom: 0.6rem; line-height: 1.6; }
.text-creature { color: var(--creature); font-size: 0.88rem; font-style: italic; margin-bottom: 0.6rem; line-height: 1.6;
  padding-left: 0.65rem; border-left: 2px solid var(--creature); }
.text-outcome  { color: var(--outcome); font-size: 0.88rem; margin-top: 0.5rem; line-height: 1.6;
  padding: 0.6rem 0.7rem; background: var(--bg2); border-radius: var(--radius); border-left: 2px solid var(--ui-blue); }
.text-outcome.fail { border-left-color: var(--red); }
.text-exit     { color: var(--narrator); font-size: 0.8rem; font-style: italic; margin-top: 0.4rem; line-height: 1.5; }

/* ── LORE PANEL ─────────────────────────────────────────────── */
#lore-panel { margin: 0 0.75rem 0.5rem; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem; }
.text-lore  { color: var(--narrator); font-size: 0.82rem; font-style: italic; line-height: 1.6; margin-bottom: 0.4rem; }

/* ── CHOICE TABLE ───────────────────────────────────────────── */
#choices { padding: 0 0.75rem 0.5rem; flex-shrink: 0; }

#choice-table {
  width: 100%; border-collapse: collapse; font-size: 0.78rem;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}

#choice-table thead tr { background: var(--bg3); }
#choice-table th { color: var(--narrator); font-weight: normal; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.3rem 0.4rem; text-align: left; border-bottom: 1px solid var(--border); }

.choice-row { cursor: pointer; transition: background 0.1s; border-top: 1px solid var(--border); }
.choice-row:hover { background: var(--bg3); }
.choice-row td   { padding: 0.45rem 0.4rem; vertical-align: middle; }

.cell-statval  { font-family: var(--mono); font-size: 0.9rem; color: var(--outcome); font-weight: bold; width: 36px; text-align: center; }
.cell-statname { font-size: 0.78rem; font-weight: bold; width: 72px; }
.cell-dc       { font-family: var(--mono); font-size: 0.9rem; font-weight: bold; color: var(--ui-blue); width: 44px; text-align: right; }
.cell-adj      { width: auto; text-align: left; padding-left: 0.85rem; }  /* flexible: absorbs slack, pushes pass/fail right */
#th-modifier   { padding-left: 0.85rem; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
#th-modifier:hover { color: var(--scene); }
.th-pass, .th-fail { text-align: left !important; }
.choice-row td { padding-top: 0.45rem; padding-bottom: 0.45rem; }
.cell-pass     { color: var(--gold);    font-size: 0.75rem; text-align: left; white-space: nowrap; width: 1%; padding-right: 1.1rem; }
.cell-fail     { color: var(--stamina); font-size: 0.75rem; text-align: left; white-space: nowrap; width: 1%; }

/* ── DICE ───────────────────────────────────────────────────── */
#dice-area { padding: 0.5rem 0.75rem; display: flex; align-items: flex-start; gap: 0.6rem; flex-shrink: 0; position: sticky; bottom: 0; background: var(--bg); z-index: 2; }

#dice-wrap, #boss-dice-wrap { width: 90px; height: 90px; flex-shrink: 0; }

#dice-buttons { display: flex; flex-direction: column; align-items: stretch; gap: 0.4rem; flex: 1; padding-top: 0.1rem; }

.btn-fate-reroll {
  background: var(--bg3); border: 1px solid var(--fate); border-radius: var(--radius);
  color: var(--fate); cursor: pointer; font-family: var(--font); font-size: 0.85rem;
  padding: 0.55rem 2ch; transition: background 0.15s, color 0.15s;
}
.btn-fate-reroll:hover { background: var(--fate); color: var(--bg); }

/* ── Line-art d20: spins in place, number counter-rotates ── */
.dice-svg  { width: 90px; height: 90px; overflow: visible; }
.dice-g    { transform-origin: 0 0; }
.dice-hex  {
  fill: var(--bg2); stroke: var(--fate); stroke-width: 3.5;
  stroke-linejoin: round;
}
.dice-edge { stroke: var(--border); stroke-width: 2; }
.dice-face {
  fill: none; stroke: var(--border); stroke-width: 2.5;
  stroke-linejoin: round;
}
.dice-face.pulsing { animation: face-pulse 0.75s ease-out 3; }
@keyframes face-pulse {
  0%   { stroke-width: 2.5; }
  30%  { stroke-width: 6;   }
  100% { stroke-width: 2.5; }
}
.dice-num  {
  font-family: var(--mono, monospace); font-weight: bold;
  font-size: 34px; fill: var(--scene);
}


@keyframes d20-spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
.d20-spinning { animation: d20-spin 0.12s linear infinite; transform-origin: 50px 50px; }

/* ── ROLL LOG ───────────────────────────────────────────────── */
#roll-log { padding: 0 0.75rem 0.4rem; font-family: var(--mono); font-size: 0.72rem; color: var(--narrator); flex-shrink: 0; }
#roll-log div { line-height: 1.7; }
.roll-pass { color: var(--green); font-weight: bold; }
.roll-fail { color: var(--red);   font-weight: bold; }

/* ── HUD ────────────────────────────────────────────────────── */
#hud { border-top: 1px solid var(--border); padding: 0.4rem 0.75rem; flex-shrink: 0; display: flex; flex-direction: column; gap: 0.3rem; background: var(--bg2); }

.hud-row { display: flex; gap: 0.4rem; align-items: center; }

.hud-stat-block { flex: 3; min-width: 0; }

.hud-label-row { display: flex; align-items: baseline; gap: 0.35rem; margin-bottom: 0.15rem; }
.hud-label { font-size: 0.7rem; font-weight: bold; text-transform: uppercase; letter-spacing: 0.08em; }
.hud-val   { font-family: var(--mono); font-size: 0.8rem; color: var(--outcome); }
.hud-max   { font-family: var(--mono); font-size: 0.7rem; color: var(--narrator); }

.hud-help-btn {
  background: transparent; border: 1px solid var(--border); border-radius: 50%;
  color: var(--narrator); cursor: pointer; font-size: 0.6rem; width: 14px; height: 14px;
  display: flex; align-items: center; justify-content: center; line-height: 1; padding: 0; margin-left: auto;
}
.hud-help-btn:hover { border-color: var(--fate); color: var(--fate); }

.bar-wrap { height: 5px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.bar      { height: 100%; border-radius: 3px; transition: width 0.35s ease; }
.bar-stamina { background: var(--stamina); }
.bar-sanity  { background: var(--sanity);  }

.hud-chip-block { flex: 0 0 auto; display: flex; align-items: center; justify-content: flex-end; }

.hud-chip {
  display: flex; flex-direction: column; align-items: center; gap: 0; padding: 0.2rem 0.4rem;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); min-width: 52px; text-align: center;
}
.chip-fate { border-color: var(--fate); }
.chip-gold { border-color: var(--gold); }

.chip-icon  { font-size: 0.8rem; line-height: 1; }
.chip-label { font-size: 0.55rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--narrator); }
.chip-val   { font-family: var(--mono); font-size: 0.9rem; color: var(--outcome); font-weight: bold; }
.chip-fate .chip-val { color: var(--fate); }
.chip-gold .chip-val { color: var(--gold); }

/* ── OVERLAY ────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.82);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 100;
}

.overlay-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  max-width: var(--maxw); width: 100%; padding: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; max-height: 90dvh; overflow-y: auto;
}
.overlay-wide { max-width: 440px; }

.overlay-title { color: var(--scene); font-size: 1rem; font-style: italic; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.overlay-actions { display: flex; gap: 0.5rem; align-items: center; }
.overlay-actions .btn-primary { margin-top: 0; flex: 1; }

/* ── HELP MODAL ─────────────────────────────────────────────── */
.help-title   { color: var(--scene); font-size: 1rem; font-style: italic; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.help-body    { display: flex; flex-direction: column; gap: 0.75rem; }
.help-section { display: flex; flex-direction: column; gap: 0.25rem; }
.help-heading { font-size: 0.8rem; font-weight: bold; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.1rem; }
.help-body p  { color: var(--narrator); font-size: 0.82rem; line-height: 1.55; }
.help-danger  { color: var(--red) !important; }

/* ── ITEM FOUND ─────────────────────────────────────────────── */
.item-overlay-slots {
  display: flex; gap: 0.3rem; margin-bottom: 0.4rem;
}
.item-overlay-slot {
  flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.4rem 0.5rem; min-width: 0;
}
.item-overlay-slot.will-replace { border-color: var(--gold); }
.item-overlay-slot-label { font-size: 0.6rem; color: var(--narrator); text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 0.15rem; }
.item-overlay-slot-name  { font-size: 0.78rem; color: var(--scene); display: block; line-height: 1.25; overflow-wrap: break-word; }
.item-overlay-slot-stat  { font-size: 0.68rem; color: var(--int); font-family: var(--mono); display: block; margin-top: 0.15rem; }
#item-found-content { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem; }
.item-name    { color: var(--scene); font-size: 1rem; margin-bottom: 0.2rem; }
.item-stat    { font-family: var(--mono); font-size: 1rem; margin-bottom: 0.15rem; }
.item-flavour { color: var(--narrator); font-size: 0.8rem; font-style: italic; }
.item-slot-label { color: var(--narrator); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.35rem; }

#item-reroll-area { display: flex; flex-direction: column; gap: 0.35rem; }

/* ── SHOP HUD ───────────────────────────────────────────────── */
#screen-shop  { padding: 0.75rem; gap: 0.6rem; }

.shop-slots { display: flex; gap: 0.35rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }

.shop-hud-bars { display: flex; flex-direction: column; gap: 0.3rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.shop-hud-row { display: flex; align-items: center; gap: 0.5rem; }
.shop-hud-row .hud-label { min-width: 56px; font-size: 0.72rem; }
.bar-wrap-labeled { flex: 1; display: flex; align-items: center; gap: 0.4rem; }
.bar-wrap-labeled .bar-wrap { flex: 1; }
.bar-label-text { font-family: var(--mono); font-size: 0.72rem; color: var(--outcome); white-space: nowrap; min-width: 44px; text-align: right; }

/* also show bar labels on main HUD */
.bar-labeled-wrap { position: relative; }
.bar-val-overlay { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); font-family: var(--mono); font-size: 0.6rem; color: rgba(255,255,255,0.7); pointer-events: none; }

.page-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.shop-section-title { color: var(--narrator); font-size: 0.75rem; font-style: italic; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.4rem; display: flex; justify-content: space-between; align-items: center; }
.shop-reroll-info { font-size: 0.65rem; color: var(--narrator); opacity: 0.7; }

.shop-section { display: flex; flex-direction: column; }

.restore-grid { display: flex; flex-direction: column; gap: 0.35rem; }

.restore-row { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.45rem 0.6rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.restore-name { font-size: 0.8rem; font-weight: bold; min-width: 55px; }
.restore-rate { font-size: 0.7rem; color: var(--narrator); flex: 1; }
.restore-controls { display: flex; align-items: center; gap: 0.35rem; }
.btn-qty { background: var(--bg3); border: 1px solid var(--border); border-radius: 3px; color: var(--scene); cursor: pointer; font-size: 0.85rem; padding: 0.1rem 0.4rem; line-height: 1; }
.qty-val { font-family: var(--mono); font-size: 0.85rem; min-width: 16px; text-align: center; }
.restore-buy { font-size: 0.72rem; padding: 0.3rem 0.55rem; }

.chip-gold-inline { color: var(--gold); font-family: var(--mono); font-size: 0.85rem; }
.lb-title { color: var(--scene); font-style: italic; font-size: 1rem; }

#shop-item-list { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.4rem; }

.shop-item { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.65rem; display: flex; align-items: center; gap: 0.5rem; }
.shop-item-info { flex: 1; min-width: 0; }
.shop-item-name { color: var(--scene); font-size: 0.95rem; }
.shop-item-stat { font-family: var(--mono); font-size: 0.95rem; }
.shop-item-flav { color: var(--narrator); font-size: 0.75rem; font-style: italic; }
.shop-item-buy  { background: transparent; border: 1px solid var(--gold); border-radius: var(--radius); color: var(--gold); cursor: pointer; font-family: var(--mono); font-size: 0.72rem; padding: 0.3rem 0.55rem; white-space: nowrap; }
.shop-item-buy:hover { background: var(--gold); color: var(--bg); }

/* ── BOSS ───────────────────────────────────────────────────── */
#screen-boss { padding: 0.75rem; gap: 0.6rem; }
.phase-label { color: var(--narrator); font-size: 0.72rem; font-style: italic; text-align: center; border-top: 1px solid var(--border); padding-top: 0.4rem; }

#boss-choice-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
#boss-choice-table thead tr { background: var(--bg3); }
#boss-choice-table th { color: var(--narrator); font-weight: normal; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.3rem 0.4rem; text-align: left; border-bottom: 1px solid var(--border); }



#boss-dice-area { display: flex; align-items: center; gap: 0.6rem; }
#boss-roll-log  { font-family: var(--mono); font-size: 0.72rem; color: var(--narrator); line-height: 1.7; }

/* ── VICTORY / DEAD ─────────────────────────────────────────── */
#screen-victory, #screen-dead { padding: 1rem 0.75rem; gap: 0.75rem; align-items: center; }

#certificate-canvas { max-width: 100%; border: 1px solid var(--border); display: block; }
.score-display { font-family: var(--mono); font-size: 0.85rem; color: var(--ui-blue); text-align: center; }
.spoiler-text  { color: var(--narrator); font-style: italic; font-size: 0.8rem; text-align: center; line-height: 1.5; }

.email-section { display: flex; flex-direction: column; gap: 0.4rem; width: 100%; }
.email-section input { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--outcome); font-family: var(--font); font-size: 0.9rem; padding: 0.55rem 0.75rem; width: 100%; outline: none; }
.email-section input:focus { border-color: var(--ui-blue); }

/* ── LEADERBOARD ────────────────────────────────────────────── */
#screen-leaderboard { padding: 0.75rem; gap: 0.5rem; }

.lb-entry { display: grid; grid-template-columns: 24px 1fr auto; gap: 0.2rem 0.5rem; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.65rem; }
.lb-rank  { color: var(--narrator); font-family: var(--mono); font-size: 0.75rem; }
.lb-name  { color: var(--scene); font-size: 0.85rem; }
.lb-score { color: var(--gold); font-family: var(--mono); font-size: 0.85rem; text-align: right; }
.lb-meta  { color: var(--narrator); font-size: 0.7rem; font-style: italic; grid-column: 2; }
.lb-date  { color: var(--narrator); font-size: 0.65rem; font-family: var(--mono); grid-column: 3; text-align: right; }

#lb-pages { display: flex; justify-content: center; gap: 0.4rem; }
.lb-page-btn { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--narrator); cursor: pointer; font-family: var(--mono); font-size: 0.75rem; padding: 0.25rem 0.5rem; }
.lb-page-btn.active { border-color: var(--ui-blue); color: var(--ui-blue); }

/* ── SCROLLBAR ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── REDUCED MOTION ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.roll-pen-note { color: var(--fail, #c0564f); font-size: 0.8rem; }
.roll-crit-note { color: var(--gold, #d4a94e); font-weight: bold; font-size: 0.85rem; }

#code-entry { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
.class-card-text { color: var(--scene); font-style: italic; margin: 0.8rem 0; line-height: 1.5; }
.class-card-stats { color: var(--narrator); font-size: 0.85rem; margin-bottom: 0.6rem; line-height: 1.7; }
.class-card-attempts { color: var(--gold, #d4a94e); font-size: 0.85rem; }
.unlock-code-box { border: 1px dashed var(--gold, #d4a94e); border-radius: var(--radius); padding: 0.8rem; margin-bottom: 1rem; text-align: center; }
.unlock-code-label { color: var(--narrator); font-size: 0.8rem; margin-bottom: 0.3rem; }
.unlock-code-value { font-family: var(--mono, monospace); font-size: 1.6rem; letter-spacing: 0.35em; color: var(--gold, #d4a94e); }
.unlock-code-note { color: var(--narrator); font-size: 0.72rem; margin-top: 0.4rem; }

.btn-tribute {
  background: var(--bg3); border: 1px solid var(--gold, #d4a94e); border-radius: var(--radius);
  color: var(--gold, #d4a94e); cursor: pointer; font-family: var(--mono); font-size: 0.65rem;
  font-weight: bold; letter-spacing: 0.05em; padding: 0.2rem 0.45rem;
}
.btn-tribute:hover { background: var(--gold, #d4a94e); color: var(--bg); }
.lb-tabs { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.6rem; }
.lb-tab { background: transparent; border: 1px solid var(--border); color: var(--narrator); border-radius: var(--radius); cursor: pointer; font-size: 0.7rem; padding: 0.25rem 0.5rem; font-family: var(--font); }
.lb-tab.active { border-color: var(--gold, #d4a94e); color: var(--gold, #d4a94e); }

/* ── Desktop: wider column, pinned chrome, scrolling middle ── */
@media (min-width: 900px) {
  .screen { max-width: 720px; margin: 0 auto; }
  #screen-game.active { display: flex; flex-direction: column; height: 100vh; }
  #screen-game #main-text { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
  #screen-game #title-bar, #screen-game .hud { flex: 0 0 auto; }
  #screen-game #dice-area, #screen-game #choices { flex: 0 0 auto; }
  #screen-shop.active, #screen-boss.active { display: flex; flex-direction: column; height: 100vh; }
  #screen-shop .shop-scroll, #screen-boss .boss-scroll { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
}

.chain-note { color: var(--narrator); font-size: 0.72rem; line-height: 1.5; margin-top: 0.9rem; border-top: 1px solid var(--border); padding-top: 0.7rem; }
.chain-note .chain-line { color: var(--scene); font-size: 0.72rem; letter-spacing: 0.02em; margin: 0.3rem 0; }
.dc-fatigue { display: inline-block; font-size: 0.7rem; font-weight: bold; }
.dc-fatigue.up    { color: var(--fail, #c0564f); }
.dc-fatigue.down  { color: var(--ui-blue, #7da7c7); }
.dc-fatigue.empty { cursor: default; }
.fatigue-first-notice { color: var(--fail, #c0564f); font-size: 0.78rem; font-style: italic; padding: 0.3rem 0.75rem; }
.chain-list p { text-align: center; margin: 0.15rem 0; }
.chain-list .chain-arrow { color: var(--narrator); font-size: 0.8rem; margin: 0; }
.chain-list .chain-rules { color: var(--narrator); font-size: 0.75rem; margin-top: 0.8rem; text-align: left; line-height: 1.5; }

#certificate-canvas { display: block; margin: 0 auto; }

@media (min-width: 900px) {
  #item-overlay .overlay-box { max-width: 600px; }
}

.shop-fate { color: var(--fate); margin-right: 0.5rem; }

/* class card screen: centered like the start screen, whatever route brought you here */
#screen-class.active { display: flex; align-items: center; justify-content: center; min-height: 100dvh; }
#screen-class .start-wrap { margin: 0 auto; text-align: center; }

/* class modal: starting vs current stats */
.class-stats-heading { font-size: 0.65rem; letter-spacing: 0.12em; color: var(--text-dim, #8a877f); }
.class-stats-divider { border: none; border-top: 1px solid var(--border, #2c2c30); margin: 0.55rem 0; }

/* tribute modal */
.tribute-block { text-align: center; margin: 1.1rem 0; padding: 0.9rem 0; border: 1px solid var(--border, #2c2c30); border-radius: var(--radius, 6px); }
.tribute-label { font-size: 0.65rem; letter-spacing: 0.14em; color: var(--text-dim, #8a877f); margin-bottom: 0.5rem; }
.tribute-qr { border-radius: 4px; background: #fff; padding: 4px; }
.tribute-addr { font-family: monospace; font-size: 0.68rem; word-break: break-all; margin: 0.55rem 1ch 0.45rem; color: var(--text, #d8d5cc); user-select: all; }
.btn-copy { background: var(--bg3, #1c1c20); border: 1px solid var(--border, #2c2c30); border-radius: var(--radius, 6px); color: var(--text, #d8d5cc); cursor: pointer; font-family: var(--font, monospace); font-size: 0.72rem; padding: 0.3rem 1.5ch; }
.btn-copy:hover { border-color: #fff; }
.tribute-portfolio { text-align: center; margin-top: 1.2rem; font-size: 0.8rem; }
.tribute-portfolio a { color: var(--fate, #b39ddb); }
.tribute-url { font-family: monospace; font-size: 0.72rem; opacity: 0.85; }

.shop-stats-line { font-family: var(--mono); font-size: 0.72rem; color: var(--text-dim, #8a877f); padding-top: 0.15rem; letter-spacing: 0.04em; }

/* ── context accents: default / commerce gold / Warden Indigo ───────── */
:root { --warden: rgb(59, 63, 140); }
body[data-accent="gold"] #title-bar { border-bottom: 2px solid var(--gold, #d4a94e); }
body[data-accent="gold"] #floor-label,
body[data-accent="gold"] #shop-floor-label,
body[data-accent="gold"] .shop-section-title { color: var(--gold, #d4a94e); }
body[data-accent="gold"] #screen-shop { border-top: 2px solid var(--gold, #d4a94e); }
body[data-accent="warden"] #title-bar { border-bottom: 2px solid var(--warden); }
body[data-accent="warden"] #floor-label { color: #8a8fd6; }
body[data-accent="warden"] #floor-map-wrap { border-bottom: 1px solid var(--warden); }
body[data-accent="warden"] .choice-table th { color: #8a8fd6; }

.collapse-lines { list-style: none; padding: 0; margin: 0.6rem 0 0; }
.collapse-lines li { padding: 0.3rem 0; border-top: 1px solid var(--border, #2c2c30); font-size: 0.85rem; }
#shop-panel .shop-stats-line { padding: 0.35rem 0 0.5rem; }
#shop-panel { padding: 0.75rem; }
#screen-game #shop-panel:not(.hidden) { flex: 1 1 auto; overflow-y: auto; min-height: 0; }

.map-loading { padding: 1rem; color: var(--narrator); font-style: italic; text-align: center; }
.map-milestone { border-left: 2px solid var(--gold, #d4a94e); background: rgba(212,169,78,0.05); }
.map-milestone .map-room-num { color: var(--gold, #d4a94e); }
.map-room-row.current { background: rgba(255,255,255,0.06); }
