/* ── tokens ─────────────────────────────────────────────────────────────── */
:root {
  --ink-900: #0b1219;
  --ink-800: #121b24;
  --ink-750: #17222d;
  --ink-700: #1c2836;
  --ink-600: #27394b;
  --line:    #31465c;
  --text:    #dee7f0;
  --muted:   #8ca0b6;
  --dim:     #64798f;
  --brass:   #d9a441;
  --brass-d: #a97c26;
  --blood:   #c33a4a;
  --sage:    #6f9b6d;
  --paper:   #ece2cb;

  --f-display: 'Big Shoulders Display', 'Arial Narrow', sans-serif;
  --f-body: 'IBM Plex Sans', system-ui, sans-serif;
  --f-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --rail: 268px;
  --r-sm: 4px;
  --r-md: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--f-body);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 70% -10%, #1d2c3b 0%, transparent 60%),
    var(--ink-900);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

.screen { display: none; height: 100%; position: relative; }
body[data-screen="home"] #screen-home { display: block; }
body[data-screen="game"] #screen-game { display: grid; grid-template-rows: auto 1fr auto; }

button, input, select { font: inherit; color: inherit; }

/* ── buttons & fields ───────────────────────────────────────────────────── */
.btn {
  --bg: var(--ink-700);
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: .62rem 1rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-weight: 500;
  letter-spacing: .01em;
  transition: background .14s, border-color .14s, transform .06s;
}
.btn:hover:not(:disabled) { background: var(--ink-600); border-color: #3d5670; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, var(--brass) 0%, var(--brass-d) 100%);
  border-color: #8a6415; color: #21170a; font-weight: 600;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(180deg, var(--brass) 0%, var(--brass-d) 100%); }
.btn-danger { border-color: #6d2530; color: #f0a8b0; }
.btn-danger:hover:not(:disabled) { background: #3a1a20; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: .38rem .7rem; font-size: .85rem; }
.btn.is-on { background: var(--brass); border-color: var(--brass-d); color: #1d1407; font-weight: 600; }

.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  width: 34px; height: 34px; border-radius: var(--r-sm); cursor: pointer; font-size: 1.05rem;
}
.icon-btn:hover { background: var(--ink-700); color: var(--text); }

.music-toggle { font-size: 1.15rem; }
#btn-music-home {
  position: absolute; top: 1.1rem; right: 1.1rem;
  background: var(--ink-750); border: 1px solid var(--line);
}

.field { display: block; margin-bottom: .85rem; }
.field > span { display: block; font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: .34rem; }
.field input, select {
  width: 100%; padding: .62rem .75rem; background: var(--ink-900);
  border: 1px solid var(--line); border-radius: var(--r-sm); outline: none;
}
.field input:focus-visible, select:focus-visible, .btn:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--brass); outline-offset: 2px;
}
.code-input {
  font-family: var(--f-mono); font-size: 1.6rem; letter-spacing: .45em;
  text-transform: uppercase; text-align: center;
}
.error-line { color: #f28b96; font-size: .86rem; min-height: 1.2em; margin: .6rem 0 0; }

/* ── home ───────────────────────────────────────────────────────────────── */
.home-grid {
  height: 100%; display: grid; grid-template-columns: 1.15fr .85fr;
  align-items: center; gap: 4rem; max-width: 1080px; margin: 0 auto; padding: 2rem 1.5rem;
}
.eyebrow { font-size: .7rem; letter-spacing: .3em; text-transform: uppercase; color: var(--brass); margin: 0 0 1rem; }
.wordmark {
  font-family: var(--f-display); font-weight: 900; line-height: .82;
  font-size: clamp(3.4rem, 9vw, 6.6rem); margin: 0; text-transform: uppercase;
  display: flex; flex-direction: column;
}
.wordmark span { color: var(--muted); font-weight: 500; font-size: .38em; letter-spacing: .06em; }
.wordmark span:nth-child(2) { margin-left: 1.6em; }
.wordmark em {
  font-style: normal; color: var(--paper);
  text-shadow: 0 2px 0 #000, 0 0 40px rgba(217,164,65,.18);
}
.tagline { color: var(--brass); font-family: var(--f-display); font-weight: 700; font-size: 1.5rem; letter-spacing: .04em; margin: 1.1rem 0 0; }
.facts { list-style: none; display: flex; gap: 1.8rem; padding: 0; margin: 2rem 0 0; color: var(--muted); font-size: .84rem; }
.facts b { display: block; font-family: var(--f-display); font-size: 1.9rem; color: var(--text); font-weight: 700; line-height: 1; }

.home-panel {
  background: linear-gradient(180deg, var(--ink-750), var(--ink-800));
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 1.6rem; box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.rule { display: flex; align-items: center; gap: .8rem; color: var(--dim); font-size: .74rem; text-transform: uppercase; letter-spacing: .16em; margin: 1.2rem 0; }
.rule::before, .rule::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ── topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .5rem .8rem;
  border-bottom: 1px solid var(--line); background: var(--ink-800);
}
.room-chip { display: flex; align-items: baseline; gap: .5rem; }
.room-label { font-size: .64rem; letter-spacing: .18em; text-transform: uppercase; color: var(--dim); }
.room-code {
  font-family: var(--f-mono); font-weight: 600; font-size: 1.15rem; letter-spacing: .3em;
  color: var(--brass); background: none; border: none; cursor: pointer; padding: 0;
}
.room-code:hover { color: #f0c470; }

.phase-track { display: flex; gap: 0; list-style: none; margin: 0 auto; padding: 0; position: relative; }
.phase-track li.phase-item {
  font-family: var(--f-display); font-weight: 700; text-transform: uppercase;
  font-size: .92rem; letter-spacing: .06em; color: var(--dim);
  padding: .3rem .85rem; position: relative; white-space: nowrap;
  transition: color .35s ease;
}
.phase-track li.phase-item + li.phase-item::before {
  content: ""; position: absolute; left: 0; top: 50%; width: 1px; height: 12px;
  background: var(--line); transform: translateY(-50%);
}
.phase-track li.phase-item.done { color: var(--muted); }
.phase-track li.phase-item.now { color: #1d1407; }
.phase-track li.phase-item .phase-label { position: relative; z-index: 1; }
/* The glow is a single persistent element that slides under the active
   phase (translateX + width, both driven from real layout in app.js) rather
   than being destroyed and recreated — that's what makes it a visible
   transition instead of a jump cut. */
.phase-track li.phase-glow {
  position: absolute; left: 0; top: 0; bottom: 0; padding: 0; margin: 0;
  background: var(--brass); border-radius: 3px; z-index: 0;
  transition: transform .45s cubic-bezier(.22, .61, .36, 1), width .45s cubic-bezier(.22, .61, .36, 1);
}
.phase-track li.phase-glow.pulse { animation: phaseGlowPulse .5s ease-out; }
@keyframes phaseGlowPulse {
  0%   { box-shadow: 0 0 0 6px color-mix(in srgb, var(--brass) 35%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brass) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .phase-track li.phase-glow { transition: none; }
  .phase-track li.phase-glow.pulse { animation: none; }
  .phase-track li.phase-item { transition: none; }
}
.topbar-right { display: flex; gap: .4rem; align-items: center; }
.only-mobile { display: none; }

/* ── stage ──────────────────────────────────────────────────────────────── */
.stage {
  display: grid; grid-template-columns: var(--rail) 1fr var(--rail);
  min-height: 0; position: relative;
}
.rail {
  background: var(--ink-800); border-right: 1px solid var(--line);
  overflow-y: auto; padding: .8rem; display: flex; flex-direction: column; gap: .8rem;
}
.rail-right { border-right: none; border-left: 1px solid var(--line); }
.board-wrap { position: relative; min-width: 0; }
#board { position: absolute; inset: 0; touch-action: none; }
.board-svg { width: 100%; height: 100%; display: block; cursor: grab; }
.board-svg:active { cursor: grabbing; }
.board-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(11,18,25,.9); border: 1px solid var(--line); border-radius: 999px;
  padding: .4rem 1rem; font-size: .84rem; color: var(--text); pointer-events: none;
  max-width: 90%; text-align: center; backdrop-filter: blur(6px);
}
.board-hint:empty { display: none; }

/* ── board svg pieces ───────────────────────────────────────────────────── */
.tile { cursor: default; }
.hex-edge { fill: none; stroke: rgba(6,11,16,.55); stroke-width: 3; pointer-events: none; }
.owner-ring { fill: none; stroke-width: 9; opacity: .95; pointer-events: none; }
.unit-count {
  font-family: var(--f-display); font-weight: 900; font-size: 40px; fill: #0d141b;
  paint-order: stroke; stroke: rgba(255,255,255,.5); stroke-width: 2px;
}
.tile.hl-pick, .tile.hl-target, .tile.hl-move { cursor: pointer; }
.tile.hl-pick .hex-edge   { stroke: var(--brass); stroke-width: 9; }
.tile.hl-target .hex-edge { stroke: var(--blood); stroke-width: 10; }
.tile.hl-move .hex-edge   { stroke: var(--sage); stroke-width: 9; }
.tile.is-selected .hex-edge { stroke: #fff; stroke-width: 11; }
.tile.hl-pick, .tile.hl-target, .tile.hl-move { animation: pulse 1.9s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .74; } }
@media (prefers-reduced-motion: reduce) { .tile { animation: none !important; } }

/* Ghost chip flown across the board during a move or attack (see board.js
   _flyChip). Lives in its own layer above all tiles so it's never mistaken
   for a real, clickable unit-chip. */
.flight-chip { pointer-events: none; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
.clash-spark { pointer-events: none; }
.clash-spark circle { filter: drop-shadow(0 0 8px rgba(255,255,255,.8)); }

/* ── panels ─────────────────────────────────────────────────────────────── */
.panel { background: var(--ink-750); border: 1px solid var(--line); border-radius: var(--r-md); }
.panel-head {
  font-family: var(--f-display); text-transform: uppercase; letter-spacing: .12em;
  font-size: .82rem; font-weight: 700; color: var(--muted);
  padding: .55rem .7rem; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.panel-body { padding: .7rem; display: flex; flex-direction: column; gap: .6rem; }

.player-row {
  display: grid; grid-template-columns: 10px 1fr auto; gap: .55rem; align-items: center;
  padding: .5rem .6rem; border-radius: var(--r-sm); border: 1px solid transparent;
}
.player-row.is-turn { background: rgba(217,164,65,.1); border-color: var(--brass-d); }
.player-row.is-dead { opacity: .42; }
.player-row.is-dead .p-name { text-decoration: line-through; }
.swatch { width: 10px; height: 26px; border-radius: 2px; }
.p-name { font-weight: 600; font-size: .92rem; display: flex; align-items: center; gap: .35rem; }
.p-name small { color: var(--dim); font-weight: 400; font-size: .72rem; }
.p-stats { display: flex; gap: .55rem; font-family: var(--f-mono); font-size: .78rem; color: var(--muted); }
.offline { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); display: inline-block; }
.online { background: var(--sage); }

.res-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.res-cell {
  background: var(--ink-900); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: .45rem .2rem; text-align: center;
}
.res-cell .n { font-family: var(--f-display); font-weight: 700; font-size: 1.45rem; line-height: 1; }
.res-cell .l { font-size: .6rem; text-transform: uppercase; letter-spacing: .1em; color: var(--dim); }
.res-glyph { font-size: 1rem; }
.res-img { vertical-align: middle; }
.capacity { font-family: var(--f-mono); font-size: .74rem; color: var(--muted); }
.capacity.full { color: var(--blood); }

.card {
  border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: var(--r-sm);
  background: var(--ink-800); padding: .5rem .6rem; cursor: pointer; text-align: left; width: 100%;
}
.card:hover { background: var(--ink-700); }
.card[data-color="red"]    { --c: var(--blood); }
.card[data-color="blue"]   { --c: #4d84c4; }
.card[data-color="orange"] { --c: #d98a3a; }
.card[data-color="yellow"] { --c: var(--brass); }
.card h4 { margin: 0 0 .2rem; font-family: var(--f-display); font-size: 1.02rem; letter-spacing: .04em; text-transform: uppercase; }
.card p { margin: 0; font-size: .78rem; color: var(--muted); line-height: 1.35; }
.card-type { font-size: .6rem; letter-spacing: .14em; text-transform: uppercase; color: var(--c); }

.rules-inplay { display: flex; flex-direction: column; gap: .45rem; }
.rule-slot { border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: var(--r-sm); padding: .45rem .6rem; background: var(--ink-800); }
.rule-slot[data-color="red"] { --c: var(--blood); }
.rule-slot[data-color="blue"] { --c: #4d84c4; }
.rule-slot b { font-family: var(--f-display); text-transform: uppercase; letter-spacing: .04em; font-size: .95rem; }
.rule-slot p { margin: .15rem 0 0; font-size: .76rem; color: var(--muted); line-height: 1.35; }

.action-stack { display: flex; flex-direction: column; gap: .45rem; }
.hint { font-size: .8rem; color: var(--muted); line-height: 1.4; margin: 0; }
.tally { font-family: var(--f-mono); font-size: .78rem; color: var(--brass); }
.chip-row { display: flex; flex-wrap: wrap; gap: .35rem; }

/* ── dispatch / log ─────────────────────────────────────────────────────── */
.dispatch { border-top: 1px solid var(--line); background: var(--ink-800); display: grid; grid-template-rows: 1fr auto; max-height: 168px; }
.dispatch-log { overflow-y: auto; padding: .5rem .8rem; display: flex; flex-direction: column; gap: .18rem; font-size: .84rem; }
.dispatch-log div { color: var(--muted); line-height: 1.4; }
.dispatch-log .tone-good { color: var(--sage); }
.dispatch-log .tone-warn { color: var(--brass); }
.dispatch-log .tone-bad { color: #ef8b96; }
.dispatch-log .tone-chat { color: var(--text); }
.dispatch-log .who { font-weight: 600; }
.dispatch-form { display: flex; gap: .4rem; padding: .5rem .8rem; border-top: 1px solid var(--ink-700); }
.dispatch-form input { flex: 1; padding: .45rem .6rem; background: var(--ink-900); border: 1px solid var(--line); border-radius: var(--r-sm); outline: none; }

/* ── toasts & modal ─────────────────────────────────────────────────────── */
.toasts { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: .4rem; pointer-events: none; }
.toast {
  background: var(--ink-700); border: 1px solid var(--line); border-left: 3px solid var(--blood);
  padding: .55rem .9rem; border-radius: var(--r-sm); font-size: .86rem; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: toastIn .18s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,10,14,.72); z-index: 70;
  display: grid; place-items: center; padding: 1rem; backdrop-filter: blur(3px);
}
.modal {
  background: var(--ink-750); border: 1px solid var(--line); border-radius: var(--r-md);
  width: min(440px, 100%); max-height: 86vh; overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,.65);
}
.modal-head { padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-family: var(--f-display); text-transform: uppercase; letter-spacing: .08em; font-size: 1.3rem; }
.modal-head p { margin: .3rem 0 0; color: var(--muted); font-size: .86rem; }
.modal-body { padding: 1.1rem; display: flex; flex-direction: column; gap: .8rem; }
.modal-foot { padding: .8rem 1.1rem; border-top: 1px solid var(--line); display: flex; gap: .5rem; justify-content: flex-end; }

.stepper { display: flex; align-items: center; gap: .8rem; justify-content: center; }
.stepper output { font-family: var(--f-display); font-size: 2.6rem; font-weight: 700; min-width: 2.4ch; text-align: center; }
.stepper .btn { width: 44px; }
input[type=range] { width: 100%; accent-color: var(--brass); }

.vote-tally { display: flex; gap: .5rem; align-items: center; font-family: var(--f-mono); font-size: .84rem; }
.vote-bar { flex: 1; height: 7px; background: var(--ink-900); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.vote-bar i { display: block; height: 100%; background: var(--sage); }

.setup-banner {
  background: rgba(217,164,65,.12); border: 1px solid var(--brass-d);
  border-radius: var(--r-sm); padding: .6rem .7rem; font-size: .86rem;
}
.win-banner { text-align: center; padding: 1.4rem .8rem; }
.win-banner h2 { font-family: var(--f-display); font-size: 2.4rem; margin: .2rem 0; text-transform: uppercase; color: var(--brass); }

.lobby-list { display: flex; flex-direction: column; gap: .4rem; }
.color-picker { display: flex; gap: .35rem; flex-wrap: wrap; }
.color-dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.color-dot.is-mine { border-color: #fff; }
.color-dot:disabled { opacity: .3; cursor: not-allowed; }

/* ── responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1020px) {
  .home-grid { grid-template-columns: 1fr; gap: 2rem; align-content: center; overflow-y: auto; }
  .stage { grid-template-columns: 1fr; }
  .rail {
    position: absolute; inset: auto 0 0 0; height: 58%; z-index: 30;
    border: 1px solid var(--line); border-radius: var(--r-md) var(--r-md) 0 0;
    transform: translateY(101%); transition: transform .22s ease;
    box-shadow: 0 -18px 40px rgba(0,0,0,.5);
  }
  body[data-panel="left"] #rail-left, body[data-panel="right"] #rail-right { transform: none; }
  .only-mobile { display: inline-block; }
  .phase-track { order: 9; width: 100%; overflow-x: auto; justify-content: flex-start; }
  .phase-track li.phase-item { font-size: .8rem; padding: .25rem .6rem; }
  .topbar { flex-wrap: wrap; }
  .dispatch { max-height: 118px; }
}

/* --- computer opponents ------------------------------------------------- */
.bot-row { display: flex; gap: .5rem; margin-top: .35rem; }
.bot-row .btn { flex: 1; }
small.is-bot {
  color: var(--brass);
  border: 1px solid color-mix(in srgb, var(--brass) 45%, transparent);
  border-radius: 3px; padding: 0 .3em; letter-spacing: .04em;
}
