/* Reflex Lab. Colours are the replay viewer's tokens (web/viewer.html :root),
   verbatim; typography is Unbounded throughout. */
:root {
  --bg-primary: #0B0B0C;
  --bg-secondary: #101012;
  --bg-panel: #141416;
  --bg-card: #1C1C1F;
  --bg-hover: #26262A;
  --border: #26262A;
  --text-primary: #F5F5F5;
  --text-secondary: #A1A1A6;
  --text-muted: #6E6E73;
  --blue-team: #4a9eff;
  --blue-team-dim: #2a5a99;
  --red-team: #ff5252;
  --red-team-dim: #992a2a;
  --accent-green: #4ade80;
  --accent-yellow: #facc15;
  --grass-light: #93C756;
  --grass-dark: #84BC46;
  --river: #37BEDC;
  --river-edge: #2AA5C2;
  --bridge-deck: #B4813F;
  --bridge-seam: #8A5F2B;
  --lane-path: #CFC08F;
  --arena-surround: #2E4A1C;

  --font: 'Unbounded', system-ui, sans-serif;
  --radius: 12px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button { font-family: inherit; }
/* The animated square field (bg.js), behind everything. */
#bgfx { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; pointer-events: none; display: block; }
.top, .lab, .foot { position: relative; z-index: 1; }
a { color: var(--blue-team); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* ---- header ----------------------------------------------------------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(16, 16, 18, .78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background:
    linear-gradient(135deg, var(--blue-team) 0 48%, transparent 48% 52%, var(--red-team) 52% 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
h1 { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; margin: 0; line-height: 1.1; }
.tag { margin: 2px 0 0; font-size: 11px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-links { display: flex; gap: 6px; flex-shrink: 0; }
.link-btn {
  background: none; border: 1px solid transparent; color: var(--text-secondary);
  font-size: 12px; padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.link-btn:hover { color: var(--text-primary); border-color: var(--border); text-decoration: none; }

/* ---- layout ------------------------------------------------------------ */
.lab {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(300px, 1fr) minmax(320px, 380px);
  gap: 20px;
  padding: 20px 24px;
  min-height: 0;
  align-items: start;
}
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}
.panel-title, .stage-title { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 12px; }
.stage-text { color: var(--text-secondary); margin: 0 0 14px; font-size: 12px; }
.fine { color: var(--text-muted); font-size: 11px; margin: 10px 0 0; }

/* ---- matchup picker ---------------------------------------------------- */
.picker { margin-bottom: 14px; }
.picker-label { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .08em; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.red { background: var(--red-team); } .dot.blue { background: var(--blue-team); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.tile {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 8px; cursor: pointer; color: var(--text-primary); text-align: left;
  font-size: 11px; line-height: 1.25; transition: border-color .15s, background .15s, transform .15s var(--ease);
  min-width: 0;
}
.tile:hover { background: var(--bg-hover); }
.tile:active { transform: scale(.97); }
.tile .sym {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 11px; color: #fff;
}
.tile.atk .sym { background: radial-gradient(circle at 35% 35%, var(--red-team), #661a1a); }
.tile.def .sym { background: radial-gradient(circle at 35% 35%, var(--blue-team), #1a3a66); }
.tile.def .sym.bldg, .tray-symbol.bldg { border-radius: 6px; }
.tile .nm { font-size: 10px; line-height: 1.2; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .cost { margin-left: auto; color: var(--text-muted); font-size: 10px; flex-shrink: 0; }
.tile[aria-checked="true"].atk { border-color: var(--red-team); background: rgba(255,82,82,.08); }
.tile[aria-checked="true"].def { border-color: var(--blue-team); background: rgba(74,158,255,.08); }
.tile[aria-disabled="true"] { opacity: .35; cursor: not-allowed; }
.tile:focus-visible, .btn:focus-visible, .seg-btn:focus-visible, .tray-card:focus-visible { outline: 2px solid var(--blue-team); outline-offset: 2px; }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 16px 0 0; }
.facts > div { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 8px; min-width: 0; }
.facts dt { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .07em; }
.facts dd { margin: 3px 0 0; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
#factD0 { color: var(--red-team); }
#factBest { color: var(--accent-green); }

/* ---- board -------------------------------------------------------------- */
.board-col { display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: 0; }
.board-wrap {
  position: relative; width: 100%;
  height: calc(100vh - 190px); min-height: 480px; max-height: 900px;
}
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.board-banner {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  background: rgba(11,11,12,.86); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 16px; font-size: 12px; font-weight: 600; white-space: nowrap;
  backdrop-filter: blur(6px); pointer-events: none;
  animation: pop .25s var(--ease);
}
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: 88px; font-weight: 800; color: #fff; text-shadow: 0 6px 30px rgba(0,0,0,.5);
}
.countdown span { animation: count 1s var(--ease) both; }

/* What to press next, in the middle of the board. */
.board-cta {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(340px, calc(100% - 32px)); text-align: center;
  background: rgba(14, 14, 16, .88); border: 1px solid rgba(255,255,255,.10); border-radius: 18px;
  padding: 20px 20px 16px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  animation: cta-in .35s var(--ease);
}
@keyframes cta-in { from { opacity: 0; transform: translate(-50%, calc(-50% + 10px)) scale(.97); } }
.cta-kicker { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--blue-team); font-weight: 600; }
.cta-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; margin: 6px 0 8px; }
.cta-sub { font-size: 12px; color: var(--text-secondary); margin: 0 0 16px; line-height: 1.5; }
.cta-sub:empty { display: none; }
.board-cta .btn.big { width: 100%; }
.board-cta .btn.ghost { margin-top: 6px; font-size: 11px; }
.demo-skip {
  align-self: center;
  background: rgba(11,11,12,.8); color: var(--text-secondary); border: 1px solid var(--border);
  border-radius: 999px; font-size: 11px; font-weight: 600; padding: 7px 14px; cursor: pointer;
}
.demo-skip:hover { color: var(--text-primary); }
.demo-hand {
  position: fixed; left: 0; top: 0; z-index: 55; pointer-events: none;
  margin: -4px 0 0 -12px; filter: drop-shadow(0 6px 12px rgba(0,0,0,.45));
}
.demo-hand svg { display: block; transition: transform .12s var(--ease); transform-origin: 35% 10%; }
.demo-hand.down svg { transform: scale(.86); }

.board-bar { width: 100%; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.board-bar .btn { min-width: 112px; }
@keyframes count { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } to { transform: scale(.8); opacity: 0; } }
@keyframes pop { from { transform: translateX(-50%) scale(.9); opacity: 0; } }

.tray { width: 100%; display: flex; justify-content: center; align-items: center; gap: 12px; }
.tray-card {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px 10px 10px;
  background: var(--bg-card); border: 1px solid var(--blue-team-dim); border-radius: 14px;
  cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none;
  box-shadow: 0 6px 20px rgba(0,0,0,.35); transition: transform .15s var(--ease), opacity .2s, border-color .2s;
}
.tray-card:hover { transform: translateY(-2px); border-color: var(--blue-team); }
.tray-card.ready { animation: nudge 1.6s var(--ease) infinite; }
/* Dimmed by its contents, never by opacity on the card: the animated
   background must not show through a solid card. */
.tray-card.used { cursor: default; animation: none; transform: none; border-color: var(--border); }
.tray-card.used > * { opacity: .38; }
.tray-card.dragging { animation: none; border-style: dashed; }
.tray-card.dragging > * { opacity: .25; }
.tray-card.pressed { transform: scale(.95); border-color: var(--blue-team); border-style: solid; }
.tray-card.pressed > * { opacity: 1; }
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.tray-symbol {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 16px; color: #fff;
  background: radial-gradient(circle at 35% 35%, var(--blue-team), #1a3a66);
}
.tray-text { display: flex; flex-direction: column; }
.tray-name { font-weight: 700; font-size: 13px; }
.tray-hint { font-size: 11px; color: var(--text-secondary); }

.drag-avatar {
  position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none;
  width: 46px; height: 46px; border-radius: 50%; margin: -23px 0 0 -23px;
  display: grid; place-items: center; font-weight: 800; font-size: 17px; color: #fff;
  background: radial-gradient(circle at 35% 35%, var(--blue-team), #1a3a66);
  box-shadow: 0 10px 30px rgba(0,0,0,.5), 0 0 0 2px rgba(255,255,255,.2);
  transition: opacity .12s;
}
.drag-avatar.bldg { border-radius: 10px; }
.drag-avatar.over-board { opacity: 0; }

/* ---- controls ------------------------------------------------------------- */
.control-panel { display: flex; flex-direction: column; gap: 16px; }
.stepper { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0; padding: 0; }
.stepper li {
  display: flex; align-items: center; gap: 7px; font-size: 10px; color: var(--text-muted);
  padding: 7px 8px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg-card);
  white-space: nowrap; overflow: hidden;
}
.stepper li span {
  width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10px; font-weight: 700; background: var(--bg-hover); color: var(--text-secondary); flex-shrink: 0;
}
.stepper li.active { color: var(--text-primary); border-color: var(--blue-team-dim); }
.stepper li.active span { background: var(--blue-team); color: #0B0B0C; }
.stepper li.done span { background: var(--accent-green); color: #0B0B0C; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-primary);
  font-size: 12px; font-weight: 600; padding: 9px 14px; border-radius: 10px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .12s var(--ease), opacity .15s;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--blue-team); border-color: var(--blue-team); color: #0B0B0C; }
.btn.primary:hover { background: #6bb0ff; }
.btn.ghost { background: none; color: var(--text-secondary); }
.btn.ghost:hover { color: var(--text-primary); }
.btn.big { font-size: 14px; padding: 13px 26px; border-radius: 12px; }
.btn:disabled { color: var(--text-muted); cursor: default; transform: none; }
.btn:disabled:hover { background: var(--bg-card); }
.btn.primary:disabled { background: #1f3552; border-color: #1f3552; color: rgba(245,245,245,.45); }

.seg { display: inline-flex; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg-btn { background: none; border: 0; color: var(--text-secondary); font-size: 11px; font-weight: 600; padding: 6px 10px; border-radius: 7px; cursor: pointer; }
.seg-btn.active { background: var(--bg-hover); color: var(--text-primary); }

.rounds { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.round {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 9px; padding: 7px 4px;
  text-align: center; font-size: 10px; color: var(--text-muted); min-width: 0;
}
.round b { display: block; font-size: 13px; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.round.current { border-color: var(--blue-team); }
.rounds.pick .round { cursor: pointer; }
.rounds.pick .round.current { background: rgba(74,158,255,.08); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 14px; }
.stats > div { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.stat-label { display: block; font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .07em; }
.stat-num { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.guess { font-size: 12px; color: var(--text-secondary); margin: 12px 0 0; min-height: 38px; }
.guess b { color: var(--text-primary); }

.verdict { font-size: 15px; font-weight: 700; line-height: 1.4; margin: 0 0 12px; min-height: 42px; opacity: 0; transform: translateY(6px); transition: opacity .6s var(--ease), transform .6s var(--ease); }
.verdict.shown { opacity: 1; transform: none; }
.verdict .you { color: var(--accent-yellow); } .verdict .ai { color: var(--blue-team); }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.compare figure { margin: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.compare figcaption { font-size: 10px; color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .07em; }
.compare canvas { width: 100%; aspect-ratio: 20 / 26; display: block; border-radius: 6px; }
.cmp-score { font-size: 12px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }

.chart-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.chart-head { font-size: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .07em; margin-bottom: 8px; }
#chart { width: 100%; height: 170px; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 8px; font-size: 10px; color: var(--text-secondary); }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 6px; }
.legend i.dash { border-top-style: dashed; }

/* ---- footer --------------------------------------------------------------- */
.foot { padding: 18px 24px 28px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 11px; }
.foot p { max-width: 900px; margin: 0 0 6px; }
.credits { color: var(--text-muted); opacity: .8; }

/* ---- overlays ------------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(5,5,6,.72); backdrop-filter: blur(8px);
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; } }
.intro-card {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 20px;
  padding: 30px; box-shadow: 0 30px 80px rgba(0,0,0,.6);
  animation: rise .35s var(--ease);
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: .14em; color: var(--blue-team); margin: 0 0 10px; font-weight: 600; }
.intro-card h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.25; margin: 0 0 20px; }
.intro-steps { list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 12px; }
.intro-steps li { display: flex; gap: 14px; align-items: flex-start; color: var(--text-secondary); font-size: 12px; }
.intro-steps b { color: var(--text-primary); }
.intro-steps .n {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0; display: grid; place-items: center;
  background: var(--bg-card); border: 1px solid var(--border); font-weight: 700; color: var(--text-primary);
}
.about p { color: var(--text-secondary); font-size: 12px; margin: 0 0 12px; }
.about b { color: var(--text-primary); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--bg-card); border: 1px solid var(--blue-team-dim); border-radius: 12px;
  padding: 11px 16px; font-size: 12px; font-weight: 600; box-shadow: 0 12px 40px rgba(0,0,0,.5);
  animation: rise .3s var(--ease); max-width: calc(100vw - 32px);
}

/* ---- narrower screens --------------------------------------------------- */
@media (max-width: 1100px) {
  .lab { grid-template-columns: minmax(280px, 1fr) minmax(300px, 380px); }
  .matchup-panel { grid-column: 1 / -1; }
  .matchup-panel .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .matchup-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
  .matchup-panel .panel-title { grid-column: 1 / -1; }
  .facts, .fine#factNote { grid-column: 1 / -1; }
}
.matchup-summary { display: none; }
@media (max-width: 760px) {
  body { font-size: 12px; }
  .top { padding: 12px 16px; }
  .tag { display: none; }
  .lab { grid-template-columns: 1fr; padding: 12px 16px; gap: 12px; }
  /* Phone order: what to do now, the matchup (one line until tapped), the
     board, then the curve. The control panel dissolves so its parts can be
     placed around the board. */
  .control-panel { display: contents; }
  .stepper { order: 1; }
  .stage { order: 2; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px; padding: 16px; }
  .matchup-panel { display: block; order: 3; padding: 12px 14px; }
  .board-col { order: 4; }
  .chart-box { order: 5; }
  .matchup-summary {
    display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px;
    background: none; border: 0; color: var(--text-primary); font-size: 12px; font-weight: 700; padding: 0; cursor: pointer;
  }
  .matchup-summary .chev { color: var(--blue-team); font-size: 11px; font-weight: 600; }
  .matchup-panel:not(.open) > :not(.matchup-summary) { display: none; }
  .matchup-panel.open .matchup-summary { margin-bottom: 12px; }
  .matchup-panel .panel-title { display: none; }
  .matchup-panel .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board-wrap { height: auto; aspect-ratio: 20 / 36; min-height: 0; max-height: none; }
  .tray { position: sticky; bottom: 10px; z-index: 5; }
  .intro-card { padding: 22px; }
  .intro-card h2 { font-size: 18px; }
  .foot { padding: 16px; }
}
