/* Trade Game Runner. Phone-first, big targets, high contrast. */

:root {
  --bg: #0f1216;
  --surface: #191e25;
  --surface-2: #232a33;
  --border: #303945;
  --text: #f3f0e9;
  --muted: #a5adb7;
  --accent: #f0b03a;
  --accent-ink: #1b1300;
  --ok: #3fb27f;
  --ok-ink: #04140c;
  --warn: #f0b03a;
  --stop: #d11a2a;
  --stop-ink: #ffffff;
  --danger: #e5484d;
  --board-bg: #f7f7f2;
  --board-ink: #13161a;
  --radius: 14px;
  --tabs-h: 66px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

body.theme-light {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #ebe8e0;
  --border: #cfcac0;
  --text: #15181c;
  --muted: #555d67;
  --accent: #e2a21c;
  --accent-ink: #1b1300;
  --ok: #1e8a5a;
  --ok-ink: #ffffff;
  color-scheme: light;
}

/* Era 6 lights-out: almost black, dim red, nothing bright to dazzle. */
body.lights-out {
  --bg: #000000;
  --surface: #080202;
  --surface-2: #120404;
  --border: #3a0d0d;
  --text: #c23a3a;
  --muted: #7e2a2a;
  --accent: #6d1414;
  --accent-ink: #f0bcbc;
  --ok: #5a1a1a;
  --ok-ink: #e8b0b0;
  --stop: #5a0d0d;
  --stop-ink: #f0bcbc;
  --board-bg: #120404;
  --board-ink: #c23a3a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.room-open { overflow: hidden; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; margin-top: 1em; }
p { margin: .4em 0 .8em; }
code { font-size: .9em; }
.muted { color: var(--muted); }
.small-text { font-size: .9rem; }
.center { text-align: center; }

/* ---------- layout ---------- */

.main {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--tabs-h) + var(--safe-b) + 24px);
}
.main.home { padding-bottom: 40px; }

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.top-title { flex: 1; font-weight: 700; font-size: 1rem; line-height: 1.25; min-width: 0; }
.mini-timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.5rem; }
.mini-timer.paused { opacity: .6; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tab {
  appearance: none; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .85rem; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 48px; cursor: pointer;
}
.tab-icon { font-size: 1.35rem; line-height: 1; }
.tab.active { color: var(--accent); }
.tab.active::after { content: ""; display: block; width: 28px; height: 3px; border-radius: 2px; background: var(--accent); margin-top: 2px; }

.screen-title { font-size: 1.6rem; margin: 8px 0 14px; }
.section-title { margin: 24px 0 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
}
details.card > summary { font-weight: 700; cursor: pointer; min-height: 32px; list-style-position: outside; }
details.card[open] > summary { margin-bottom: 10px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.row.wrap { align-items: flex-start; }
.center-row { justify-content: center; }
.grow { flex: 1; }

.bullets { padding-left: 1.2em; margin: .3em 0; }
.bullets li { margin: .35em 0; }
ol { padding-left: 1.4em; }
ol li { margin: .35em 0; }

.note {
  background: var(--surface-2);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0;
}
.note.warn { border-left-color: var(--warn); }

.kicker { text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; font-weight: 800; color: var(--muted); margin: 6px 0; }
.count { font-size: .85rem; color: var(--muted); font-weight: 700; margin-left: 6px; }

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

.btn {
  appearance: none;
  font: inherit; font-weight: 700;
  min-height: 52px; padding: 10px 18px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .tab:focus-visible, .check input:focus-visible + .box { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); width: 100%; margin-top: 12px; }
.btn.big { min-height: 60px; font-size: 1.15rem; width: 100%; }
.btn.huge { min-height: 76px; font-size: 1.35rem; width: 100%; }
.btn.small { min-height: 48px; padding: 8px 14px; font-size: 1rem; }
.btn[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: var(--ok-ink); }
.btn.toggle[aria-pressed="false"] { color: var(--muted); }
.icon-btn { min-height: 44px; min-width: 48px; padding: 4px 10px; font-size: 1.3rem; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.btn.chip { min-height: 48px; border-radius: 999px; padding: 6px 16px; }
.quick { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.quick .btn { flex: 1 1 140px; }
.list-btns { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.list-btn { text-align: left; }
.list-btn.current { border-color: var(--accent); }

.sticky-actions {
  position: sticky;
  bottom: calc(var(--tabs-h) + var(--safe-b) + 8px);
  display: flex; gap: 10px; align-items: center;
  margin-top: 18px; padding: 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  z-index: 10;
}
.sticky-actions > .btn:not(.grow):not(.big) { flex: 0 0 auto; }

/* ---------- checklists ---------- */

.check {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 4px; border-bottom: 1px solid var(--border);
  cursor: pointer; min-height: 48px;
}
.check:last-child { border-bottom: 0; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check .box {
  flex: 0 0 30px; height: 30px; border-radius: 8px;
  border: 2px solid var(--muted);
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.check input:checked + .box { background: var(--ok); border-color: var(--ok); }
.check input:checked + .box::after { content: "✓"; color: var(--ok-ink); font-weight: 900; font-size: 1.1rem; }
.check.done .check-text { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }

/* ---------- home ---------- */

.hero { text-align: center; padding: 32px 0 20px; }
.hero h1 { font-size: 2rem; margin: 6px 0; }
.hero-years { font-weight: 800; letter-spacing: .2em; color: var(--accent); }
.home > .btn.big { margin-bottom: 18px; }
.team-list { list-style: none; padding: 0; margin: 0; }
.team-list li { padding: 6px 0; display: flex; align-items: center; gap: 4px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: 8px; border: 1px solid rgba(255,255,255,.35); vertical-align: -1px; flex: 0 0 auto; }

/* ---------- reading ---------- */

.read-aloud {
  font-size: 1.35rem; line-height: 1.5;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 18px; margin: 10px 0 16px;
}
.headline { font-size: 1.9rem; font-weight: 900; letter-spacing: .01em; margin: 6px 0 10px; }
.whistle-call { font-size: 1.15rem; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); margin: 10px 0; }
.say { font-size: 1.2rem; margin: 6px 0; }
.rule-big { font-size: 1.7rem; font-weight: 900; margin: 8px 0; }
.rule { font-weight: 700; margin-bottom: 8px; }

/* ---------- whistle steps ---------- */

.steps { display: flex; gap: 6px; margin: 8px 0 14px; overflow-x: auto; }
.step-dot {
  appearance: none; font: inherit; flex: 1 0 auto;
  display: flex; flex-direction: column; align-items: center;
  min-height: 52px; min-width: 56px; padding: 4px 6px;
  border-radius: 10px; border: 2px solid var(--border);
  background: var(--surface); color: var(--muted); font-weight: 800; cursor: pointer;
}
.step-dot span { font-size: .7rem; font-weight: 700; }
.step-dot.past { color: var(--text); border-color: var(--ok); }
.step-dot.current { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.step-title { font-size: 1.4rem; margin-top: 6px; }
.go-panel { text-align: center; padding: 30px 0 10px; }
.go-say { font-size: 2.4rem; font-weight: 900; margin: 6px 0 24px; }

/* ---------- team rows (living costs etc.) ---------- */

.team-rows { margin-top: 8px; }
.team-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.team-row:last-child { border-bottom: 0; }
.team-name { font-weight: 700; display: flex; align-items: center; flex-wrap: wrap; flex: 1 1 160px; }
.team-name .muted { flex-basis: 100%; padding-left: 22px; font-weight: 400; }
.btn.opt-WH[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: #fff; }

.counter { display: flex; align-items: center; gap: 8px; }
.count-val { min-width: 84px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }
.counter.full .count-val { color: var(--danger); }

/* ---------- timers ---------- */

.timer-block { text-align: center; padding: 6px 0 4px; }
.big-timer {
  font-size: clamp(4.5rem, 26vw, 9.5rem);
  font-weight: 900; line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.big-timer.small { font-size: clamp(3.5rem, 18vw, 6rem); margin-bottom: 10px; }
.big-timer.urgent, .mini-timer.urgent { color: var(--danger); }
.timer-block.paused .big-timer { opacity: .5; }
.timer-status { font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-size: .85rem; margin-bottom: 10px; }
.timer-block.paused .timer-status { color: var(--warn); }
.timer-controls { display: flex; gap: 8px; justify-content: center; }
.timer-controls .btn { flex: 1; max-width: 170px; }

.sub-timer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface-2); border: 2px solid var(--warn); border-radius: var(--radius);
  padding: 12px 16px; margin: 12px 0;
}
.sub-timer.big { flex-direction: column; text-align: center; }
.sub-label { font-weight: 700; }
.sub-time, .sub-timer [data-live] { font-size: 2.6rem; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; }
.sub-timer [data-live].urgent { color: var(--danger); }

.panel-label { text-transform: uppercase; letter-spacing: .08em; font-weight: 800; font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.next-what { font-size: 1.3rem; font-weight: 800; }
.next-when { font-size: 1.15rem; }
.next-when [data-live] { font-weight: 900; font-variant-numeric: tabular-nums; }

.cue-card { border-radius: var(--radius); padding: 16px; margin: 12px 0; border: 3px solid var(--accent); background: var(--surface); }
.cue-card.action { border-color: var(--danger); }
.cue-kind { font-size: .8rem; font-weight: 900; letter-spacing: .08em; color: var(--muted); }
.cue-say { font-size: 1.6rem; font-weight: 900; margin: 6px 0 10px; }

.time-up { text-align: center; padding: 30px 0; }
.time-up-big { font-size: clamp(3.5rem, 18vw, 6rem); font-weight: 900; color: var(--danger); line-height: 1; margin-bottom: 14px; }

/* ---------- banners and toast ---------- */

.banners { position: sticky; top: 52px; z-index: 15; max-width: 760px; margin: 0 auto; padding: 8px 16px 0; }
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface); border: 2px solid var(--accent); font-weight: 600;
}
.banner.action, .banner.end { border-color: var(--danger); }
.banner.missed { border-color: var(--warn); margin: 12px 0; }
.banner ul { margin: 4px 0 0; padding-left: 1.2em; font-weight: 400; }
.say-tag { display: inline-block; background: var(--accent); color: var(--accent-ink); font-weight: 900; font-size: .75rem; padding: 2px 6px; border-radius: 6px; margin-right: 4px; }

.toast {
  position: fixed; left: 50%; top: 70px; transform: translate(-50%, -20px);
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 100; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- whiteboard ---------- */

.whiteboard {
  background: var(--board-bg); color: var(--board-ink);
  border-radius: 10px; padding: 16px 18px; margin: 10px 0;
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe Print", system-ui, sans-serif;
  border: 6px solid #8c8f94;
}
.wb-title { font-weight: 900; font-size: 1.25rem; margin-bottom: 8px; }
.wb-row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 1.15rem; }
.wb-row span:last-child { font-weight: 800; text-align: right; }
.wb-sep { border-top: 2px dashed currentColor; margin-top: 6px; padding-top: 8px; }
.wb-notice { margin-top: 10px; font-weight: 900; font-size: 1.1rem; }
.board-pop { position: fixed; inset: auto 12px calc(var(--tabs-h) + var(--safe-b) + 12px); z-index: 25; background: var(--surface); padding: 10px; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: 0 10px 40px rgba(0,0,0,.5); max-width: 736px; margin: 0 auto; }

/* ---------- overlays ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column;
}
.stop-press .sp-banner {
  position: sticky; top: 0;
  background: var(--stop); color: var(--stop-ink);
  font-weight: 900; font-size: 1.3rem; letter-spacing: .06em; text-transform: uppercase;
  text-align: center; padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 14px;
  z-index: 2;
}
.sp-body { padding: 14px 16px; max-width: 760px; width: 100%; margin: 0 auto; flex: 1; }
.sp-foot {
  position: sticky; bottom: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px calc(var(--safe-b) + 12px);
  background: var(--surface); border-top: 1px solid var(--border);
}
.sp-foot [data-live] { font-weight: 900; font-variant-numeric: tabular-nums; color: var(--text); }

.blitz-box, .dice-stage { text-align: center; padding: 10px 0 14px; }
.die {
  display: inline-flex; align-items: center; justify-content: center;
  width: 140px; height: 140px; margin: 10px auto;
  border-radius: 26px; background: var(--text); color: var(--bg);
  font-size: 5rem; font-weight: 900; font-variant-numeric: tabular-nums;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,.18);
}
.die.big { width: 180px; height: 180px; font-size: 6.5rem; }
.die.wide { width: auto; min-width: 180px; padding: 0 24px; font-size: 2rem; height: 120px; }
.die.rolling { animation: wobble .12s infinite alternate; }
@keyframes wobble { from { transform: rotate(-8deg) scale(.96); } to { transform: rotate(8deg) scale(1.04); } }
.blitz-result { min-height: 3em; font-size: 1.2rem; margin: 8px 0 14px; }
.blitz-result strong { font-size: 1.8rem; display: block; }
.mapping { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.mapping li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.history { list-style: none; padding: 0; margin: 0 0 10px; }
.history li { padding: 8px 0; border-bottom: 1px solid var(--border); }

/* Room view: big and readable from the back of the hall. */
.room-view { padding: calc(env(safe-area-inset-top, 0px) + 20px) 24px 24px; justify-content: flex-start; }
.room-view > * { max-width: 1100px; width: 100%; margin-left: auto; margin-right: auto; }
.rv-head { text-align: center; margin-bottom: 18px; }
.rv-years { font-size: clamp(2.2rem, 7vw, 4.5rem); font-weight: 900; color: var(--accent); line-height: 1; }
.rv-name { font-size: clamp(1.3rem, 4vw, 2.4rem); font-weight: 700; }
.rv-prices { display: grid; gap: 10px; }
.rv-price { display: flex; justify-content: space-between; gap: 16px; font-size: clamp(1.5rem, 5.5vw, 3.4rem); padding: 6px 14px; background: var(--surface); border-radius: 12px; }
.rv-price strong { font-variant-numeric: tabular-nums; }
.rv-called { text-align: center; font-size: clamp(1.8rem, 6vw, 3.8rem); margin: 16px 0; padding: 10px; border: 4px solid var(--accent); border-radius: 16px; }
.rv-meta { display: grid; gap: 8px; margin-top: 16px; font-size: clamp(1.1rem, 3.6vw, 2rem); }
.rv-meta div { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.rv-notice { margin-top: 16px; text-align: center; font-weight: 900; font-size: clamp(1.2rem, 4vw, 2.4rem); background: var(--surface-2); border-radius: 14px; padding: 12px; }
.rv-exit { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 8px); right: 8px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 1.1rem; opacity: .5; cursor: pointer; }

/* ---------- market ---------- */

.prices { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.price { display: flex; flex-direction: column; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.price span { font-size: .85rem; color: var(--muted); }
.price strong { font-size: 1.3rem; }
.price.called { border: 2px solid var(--accent); }
.money-input { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.money-input input {
  font: inherit; font-weight: 800; font-size: 1.2rem;
  width: 120px; min-height: 52px; padding: 8px 10px;
  border-radius: 10px; border: 2px solid var(--border);
  background: var(--bg); color: var(--text);
}
.money-input.wide input { flex: 1; width: auto; }
.money-input input:focus { outline: 3px solid var(--accent); }
.calc-out { margin-top: 12px; font-size: 1.15rem; line-height: 1.6; }
.calc-out strong { font-size: 1.3rem; }
.big-num { font-size: 1.8rem !important; color: var(--accent); }
.table-scroll { overflow-x: auto; }
.grid, .score-table { border-collapse: collapse; width: 100%; font-size: 1rem; }
.grid th, .grid td, .score-table th, .score-table td { border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: center; }
.grid th[scope="row"], .score-table td:nth-child(2) { text-align: left; white-space: nowrap; }

/* ---------- sync ---------- */

.sync-pill {
  appearance: none; font: inherit; font-size: .8rem; font-weight: 800;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 4px 10px; border-radius: 999px;
  border: 2px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  white-space: nowrap;
}
.sync-pill .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.sync-pill.live .dot { background: var(--ok); }
.sync-pill.wait .dot { background: var(--warn); }
.sync-pill.bad { border-color: var(--danger); }
.sync-pill.bad .dot { background: var(--danger); }
.room-code {
  font-size: clamp(3rem, 16vw, 5rem); font-weight: 900; letter-spacing: .1em;
  text-align: center; font-variant-numeric: tabular-nums; margin: 6px 0;
  color: var(--accent);
}
.peers { list-style: none; padding: 0; margin: 8px 0; }
.peers li { padding: 6px 0; font-weight: 700; }
.code-input { display: flex; align-items: center; gap: 10px; font-weight: 700; margin: 8px 0; }
.code-input input {
  font: inherit; font-size: 2rem; font-weight: 900; letter-spacing: .3em; text-transform: uppercase;
  width: 9ch; min-height: 60px; padding: 6px 12px; text-align: center;
  border-radius: 12px; border: 2px solid var(--border); background: var(--bg); color: var(--text);
}
.code-input input:focus { outline: 3px solid var(--accent); }
.rv-stop { background: var(--stop); color: var(--stop-ink); border-radius: 16px; padding: 14px 18px; margin-bottom: 16px; text-align: center; }
.rv-stop-tag { font-weight: 900; letter-spacing: .08em; font-size: clamp(.9rem, 2.6vw, 1.4rem); }
.rv-stop-title { font-weight: 900; font-size: clamp(1.8rem, 6vw, 3.6rem); line-height: 1.1; margin: 4px 0; }
.rv-stop-news { font-size: clamp(1rem, 3vw, 1.7rem); }
.rv-stale { position: fixed; bottom: 10px; left: 12px; color: var(--danger); opacity: .6; font-size: .9rem; }

@media (min-width: 700px) {
  .headline { font-size: 2.4rem; }
  .read-aloud { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .die.rolling { animation: none; }
  .toast { transition: none; }
}
