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

:root {
  --bg-primary: #121212;
  --bg-secondary: #1e1e1e;
  --bg-card: #2a2a2a;
  --cell-bg: #3a3a3a;
  --cell-hover: #4a4a4a;
  /* ---- Highlighter palette (Design §2.5) ----
     Six marker colours. Yellow/pink/green are RESERVED for the three words
     (DOG/HOG/BOG) so game state always reads at a glance; blue/purple/red
     are the non-word accents and are drawn at random. */
  --neon-yellow: #f2ff00; /* DOG */
  --neon-pink: #ff3ea5;   /* HOG */
  --neon-green: #39ff7a;  /* BOG */
  --neon-blue: #00c8ff;
  --neon-purple: #c77dff; /* lightened from #b026ff so purple text clears
                             4.5:1 on this near-black background */
  --neon-red: #ff6b7f;    /* reddish pink, likewise lifted for text use */
  /* DOG as page text: on this near-black the neon already clears AA. */
  --yellow-text: var(--neon-yellow);

  /* Accent drawn once per page load from blue/purple/red — script.js sets
     data-accent on <html>, which lands here. */
  --accent: var(--neon-blue);
  /* Colour of the current grid glow; script.js redraws it every time the
     board enters .battle-complete, so no two battle-complete flashes match. */
  --glow-color: var(--accent);

  /* --gold* kept as aliases of the accent so the ~40 existing usages
     (borders, buttons, focus rings, keyframes) inherit the highlighter
     palette without renaming every rule. */
  --gold: var(--accent);
  --gold-light: var(--accent);
  --gold-title: var(--accent);
  --gold-text: var(--accent);
  /* Ink for text sitting ON a neon fill — near-black reads on all six.
     Fills behind this ink are softened to a 33% tint with white (see the
     title tokens and filled controls); the raw neon stays on borders,
     halos and text accents. */
  --on-gold: #121212;
  --green: var(--neon-green);
  /* Success messages read as green, but the neon marker itself glares as
     page text. This deeper green stays clearly green at 8.91:1 on the board's
     near-black background. */
  --green-text: #2ecc71;
  --green-glow: rgba(57, 255, 122, 0.4);
  /* HOG pink (Design §2.5). Text ink on a pink fill reuses --on-gold. */
  --pink: var(--neon-pink);
  --pink-glow: rgba(255, 62, 165, 0.4);
  --pink-text: var(--neon-pink); /* already 8.4:1 on --bg-primary */
  --blue: var(--neon-blue);
  --blue-glow: rgba(0, 200, 255, 0.3);
  --red: var(--neon-red);
  --text-primary: #f5efe0;
  --text-secondary: #b8a88a;
  /* Border around missed/solution tiles: white on the dark board, black on
     the light theme's paper. */
  --missed-border: #ffffff;
  --board-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --cell-size: 36px;
  --cell-gap: 2px;
  --board-padding: 12px;
  --radius: 8px;
}

:root[data-theme="light"] {
  --bg-primary: #f4f4f8;
  --bg-secondary: #fafafe;
  --bg-card: #ffffff;
  --cell-bg: #efeff5;
  --cell-hover: #e4e4ee;
  /* ---- Highlighter palette, light theme ----
     Fills and borders keep the fluorescent marker hues so light mode reads
     like highlighter on paper. Text that sits on the page background drops
     to the -ink companion of each accent, which is where the AA contrast
     is actually earned. */
  --neon-yellow: #f2ff00; /* DOG */
  --neon-pink: #ff3ea5;   /* HOG */
  --neon-green: #39ff7a;  /* BOG */
  --neon-blue: #00c8ff;
  --neon-purple: #b026ff;
  --neon-red: #ff3b5c;

  --ink-blue: #00698f;   /* 4.6:1 on --bg-primary */
  --ink-purple: #7b1fa2; /* 6.6:1 */
  --ink-red: #c62828;    /* 5.6:1 */
  /* DOG as page text: fluorescent yellow is ~1.4:1 on this background, so
     light mode needs a real ink — dark olive reads as the same hue. */
  --yellow-text: #6f6f00; /* 4.96:1 */
  --accent: var(--neon-blue);
  --accent-ink: var(--ink-blue);
  --glow-color: var(--accent);

  /* --gold* aliased to the accent: neon for borders/fills, ink for text.
     Text and title deliberately point at --accent-ink, not --accent — a
     fluorescent hex on a near-white page is roughly 1.4:1 and fails AA. */
  --gold: var(--accent);
  --gold-light: var(--accent);
  --gold-title: var(--accent-ink);
  --gold-text: var(--accent-ink);
  /* Ink for text sitting ON a neon fill: dark ink on a light background is
     ~6.6:1 for every one of the six markers. */
  --on-gold: #1a1a2e;
  --green: var(--neon-green);
  /* Light mode needs a real ink: fluorescent green on paper is ~1.2:1. This
     dark green reads as the same hue at 6.50:1. */
  --green-text: #166534;
  --green-glow: rgba(57, 255, 122, 0.35);
  --pink: var(--neon-pink);
  --pink-glow: rgba(255, 62, 165, 0.35);
  --pink-text: var(--ink-red); /* HOG text on the page needs an ink, not a neon */
  --blue: var(--neon-blue);
  --blue-glow: rgba(0, 200, 255, 0.3);
  --red: var(--neon-red);
  --text-primary: #1a1a2e;
  --text-secondary: #5a5a6e;
  --missed-border: #000000;
  --board-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

/* The accent draw. script.js sets data-accent on <html> once per page load
   from {blue, purple, red} — the three marker colours NOT reserved for the
   words. Scoping the ink swap to the light theme keeps the dark theme
   simple: its neon accents are already readable as text. */
:root[data-accent="purple"] { --accent: var(--neon-purple); }
:root[data-accent="red"]    { --accent: var(--neon-red); }

:root[data-theme="light"][data-accent="purple"] { --accent-ink: var(--ink-purple); }
:root[data-theme="light"][data-accent="red"]    { --accent-ink: var(--ink-red); }

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 12px;
}

header {
  text-align: center;
  padding: 12px 0 8px;
  flex-shrink: 0;
}

h1 {
  font-size: 2rem;
  letter-spacing: 4px;
  margin-bottom: 10px;
  font-weight: 800;
}

.all-gold {
  color: var(--gold-title, var(--gold));
  text-shadow: 0 0 12px rgba(212, 168, 67, 0.5);
}

/* Title tokens — soft highlighter blocks: black lettering on a 33% tint of
   the word's marker colour (mixed with white). The tint keeps the black
   lettering readable in both themes; a true 33% opacity over the dark page
   would leave too little contrast behind black text. Only the three letters
   sit on the block; the plural "s" stays unhighlighted and inherits the page
   text colour. */
.t-dog,
.t-hog,
.t-bog {
  color: #000;
  padding: 0 0.1em;
  border-radius: 0.12em;
}

.t-dog {
  background: var(--neon-yellow);
  background: color-mix(in srgb, var(--neon-yellow) 33%, #fff);
}

.t-hog {
  background: var(--neon-pink);
  background: color-mix(in srgb, var(--neon-pink) 33%, #fff);
}

.t-bog {
  background: var(--neon-green);
  background: color-mix(in srgb, var(--neon-green) 33%, #fff);
}

/* Generic show/hide switch used by JS for panels and buttons. Specific
   #id.hidden rules below win over it where they exist. */
.hidden {
  display: none;
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold-text, var(--gold));
}

.controls-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 2px solid var(--gold);
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  transition: border-color 0.2s;
  position: relative;
  padding: 0;
}

#theme-btn::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: linear-gradient(to right, #e8e8f0 50%, #1b2d40 50%);
  transition: opacity 0.15s;
}

[data-theme="light"] #theme-btn::before {
  background: linear-gradient(to right,
    rgba(232,232,240,1) 0%, rgba(232,232,240,1) 50%,
    rgba(27,45,64,0.2) 50%, rgba(27,45,64,0.2) 100%);
}

[data-theme="dark"] #theme-btn::before {
  background: linear-gradient(to right,
    rgba(232,232,240,0.2) 0%, rgba(232,232,240,0.2) 50%,
    rgba(27,45,64,1) 50%, rgba(27,45,64,1) 100%);
}

.icon-btn:hover,
.icon-btn:focus-visible {
  border-color: var(--gold-light);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

#zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#zoom-controls .icon-btn {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
}

#zoom-value {
  min-width: 4ch;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

#new-game-btn {
  padding: 8px 20px;
  border: 2px solid var(--gold);
  background: transparent;
  color: var(--gold-text, var(--gold));
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}

#new-game-btn:hover,
#new-game-btn:focus-visible {
  background: var(--gold);
  background: color-mix(in srgb, var(--gold) 33%, #fff);
  color: var(--on-gold);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 0;
}

#board-container {
  width: 100%;
  flex: 0 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

#board {
  display: inline-grid;
  gap: var(--cell-gap);
  padding: var(--board-padding);
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid rgba(212, 168, 67, 0.15);
  box-shadow: var(--board-shadow);
  position: relative;
  outline: none;
}

#board:focus-visible {
  border-color: var(--gold);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.55);
  font-weight: 700;
  background: var(--cell-bg);
  color: var(--text-primary);
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: background 0.12s, transform 0.1s, box-shadow 0.12s;
  position: relative;
}

.cell:hover {
  background: var(--cell-hover);
}

.cell:active {
  transform: scale(0.92);
}

.cell.kbd-cursor {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.cell.start {
  background: var(--blue);
  box-shadow: 0 0 10px var(--blue-glow);
  transform: scale(1.05);
  z-index: 2;
}

.cell.preview {
  background: rgba(33, 150, 243, 0.35);
  box-shadow: inset 0 0 6px var(--blue);
}

.cell.found:not(.start):not(.preview) {
  background: var(--found-color, var(--gold));
  background: color-mix(in srgb, var(--found-color, var(--gold)) 33%, #fff);
  /* Ink sits on a 33% tint, so --on-gold stays readable on all three word
     colours in both themes. Crossing tiles keep the same ink — only the
     background changes — so shared letters stay readable. */
  color: var(--on-gold);
  /* Halo in the cell's own colour — no extra glow token needed. */
  box-shadow: 0 0 8px var(--found-color, var(--gold));
  animation: foundPulse 0.4s ease-out;
}

/* A crossing (a cell shared by two words) is filled by script.js with a cool
   tone whose hue comes from the sum of the overlapping word colours, plus a
   small stable jitter. Keeping the whole crossing family cool separates shared
   tiles from the yellow/pink/green word fills. Its ink is unchanged, so the
   letter reads exactly like every other found cell. */

/* Missed DOG/HOG (Design §2.2, revealed by End Search): the same 33% word
   tint as a found tile, so the ink stays readable, but a solid border and the
   missing halo mark it as lost rather than found. Tinting only the fill (not
   the whole cell) keeps the ink and the solution border at full strength. */
.cell.missed:not(.start):not(.preview) {
  background: var(--found-color, var(--gold));
  background: color-mix(in srgb, var(--found-color, var(--gold)) 33%, #fff);
  color: var(--on-gold);
  border: 2px solid var(--missed-border);
  cursor: default;
}

/* The grid glow. --glow-color is rewritten by script.js every time the board
   enters .battle-complete, drawing fresh from the three non-word markers
   (blue/purple/red) at 0.75 alpha — the alpha is load-bearing: an opaque
   fill would bury the cells under the flash instead of washing over them. */
@keyframes boardFlash {
  0%, 100% { background: var(--bg-card); }
  50% { background: var(--glow-color); }
}

@keyframes buttonFlash {
  0%, 100% {
    background: var(--gold);
    background: color-mix(in srgb, var(--gold) 33%, #fff);
    color: var(--on-gold);
  }
  50% { background: transparent; color: var(--gold-text, var(--gold)); }
}

#board.battle-complete {
  animation: boardFlash 2s ease-in-out infinite;
}

#next-battle-btn.battle-complete {
  animation: buttonFlash 2s ease-in-out infinite;
}

#board.battle-complete .cell {
  pointer-events: none;
  cursor: default;
}

#board.battle-complete .cell:not(.found):not(.missed):hover {
  background: var(--cell-bg);
}

/* A found cell is already claimed — its 33% word tint (above) is the signal,
   so this only changes the cursor. The old 0.5 opacity would wash the fill
   out and drop the ink under AA. */
.cell.found.inactive {
  cursor: default;
}

@keyframes foundPulse {
  0% { transform: scale(1.3); }
  50% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* Battle-1 help pulse: the placed word lights up in G→O→D order and loops
   until the player interacts with the board. Delay per class staggers the
   wave so the direction of the word reads at a glance. */
@keyframes cellHint {
  0%, 100% {
    background: var(--cell-bg);
    box-shadow: inset 0 0 0 2px rgba(212, 168, 67, 0.35);
  }
  50% {
    background: rgba(212, 168, 67, 0.45);
    box-shadow: inset 0 0 0 3px rgba(212, 168, 67, 0.95), 0 0 10px rgba(212, 168, 67, 0.65);
  }
}

.cell.hint-0 { animation: cellHint 1s ease-in-out 0s infinite; }
.cell.hint-1 { animation: cellHint 1s ease-in-out 0.3s infinite; }
.cell.hint-2 { animation: cellHint 1s ease-in-out 0.6s infinite; }

/* The instruction line sizes to its own text instead of a fixed 32px box: the
   standing instruction wraps to two lines at 320px wide, and to more than that
   when the player raises their browser text size. A fixed height made the
   wrapped text spill over the winner-call row and the board. min-height keeps
   the row from collapsing around a short message; adjustCellSize() measures the
   row's real height, so a taller line costs the board a little room instead. */
#message {
  min-height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 8px;
  color: var(--gold-text, var(--gold));
  transition: opacity 0.2s;
  text-align: center;
  overflow-wrap: anywhere;
}

#message.success {
  color: var(--green-text);
}

#message.error {
  color: var(--red);
}

#message.complete {
  color: var(--text-primary);
  font-size: 1.1rem;
  animation: battleUp 0.5s ease-out;
}

#message.complete .letter {
  display: inline-block;
  animation: letterGlow 2.4s ease-in-out infinite;
}

@keyframes letterGlow {
  0%, 82% { color: var(--text-primary); }
  88%, 100% { color: var(--gold-text, var(--gold)); }
}

@keyframes battleUp {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* Action row: End Search is present from the first second of a battle and
   Next Battle replaces it after resolve, so the row never changes height —
   revealing a button can't reflow (and jump) the vertically centered board. */
#action-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-shrink: 0;
}

/* Battle-1 onboarding: "Need help?" lives in the action row rather than
   floating over it. It is display:none while unused, and it is shorter than
   the End Search pill beside it, so its reveal changes only the row's width —
   never its height — and the board stays put (the jump bug class fixed for
   #action-row must not come back through this button). */
#message-wrap {
  flex-shrink: 0;
}

#help-btn {
  /* Kill platform-native button rendering (GTK/mac themes restyle the box
     between idle/hover/active states — a different size/shape on click). */
  appearance: none;
  -webkit-appearance: none;
  /* Default = tinted accent pill (the state visible when clicked); hover and
     focus-visible only brighten the fill — never change geometry. */
  padding: 8px 20px;
  border: 2px solid var(--gold);
  background: var(--gold);
  background: color-mix(in srgb, var(--gold) 33%, #fff);
  color: var(--on-gold);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

#help-btn:hover,
#help-btn:focus-visible {
  background: var(--gold-light);
  background: color-mix(in srgb, var(--gold-light) 33%, #fff);
  border-color: var(--gold-light);
  color: var(--on-gold);
}

/* Shared pill for End Search / Next Battle: same geometry so swapping one for
   the other can't resize the row. */
#end-battle-btn,
#next-battle-btn {
  appearance: none;
  -webkit-appearance: none;
  /* Match the neighbouring action-row pills (#help-btn) exactly, so the End
     Battle button reads as the same control size instead of a larger one. */
  padding: 8px 20px;
  border: 2px solid var(--gold);
  background: var(--gold);
  background: color-mix(in srgb, var(--gold) 33%, #fff);
  color: var(--on-gold);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

#end-battle-btn:hover,
#end-battle-btn:focus-visible,
#next-battle-btn:hover,
#next-battle-btn:focus-visible {
  background: transparent;
  color: var(--gold-text, var(--gold));
}

/* Winner call (Design §2.3): outline = available, filled = currently called.
   Each side wears its own board colour — DOG neon yellow, HOG neon pink — so
   the call reads the same as the words on the grid. Wraps rather than
   overflowing: label + two pills + the "(No tie)" note is wider than a 320 px
   viewport once the player's text size is increased. adjustCellSize() sums the
   row's real height, so a wrapped row simply leaves the board a little less
   room instead of pushing content off-screen. */
#call-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-shrink: 0;
  max-width: 100%;
}

/* The ID selector above outranks the generic .hidden class, so the retired
   call row needs its own display switch. */
#call-row.hidden {
  display: none;
}

.call-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-secondary);
}

.no-tie-note {
  font-size: 0.7rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.call-btn {
  appearance: none;
  -webkit-appearance: none;
  min-width: 64px;
  padding: 8px 20px;
  border: 2px solid var(--gold);
  background: transparent;
  color: var(--gold-text, var(--gold));
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.call-dog {
  border-color: var(--yellow-text);
  color: var(--yellow-text);
}

.call-hog {
  border-color: var(--pink);
  color: var(--pink-text);
}

.call-btn:hover,
.call-btn:focus-visible {
  background: var(--bg-card);
}

.call-btn.call-active {
  background: var(--gold);
  background: color-mix(in srgb, var(--gold) 33%, #fff);
  border-color: var(--gold);
  color: var(--on-gold);
}

.call-dog.call-active {
  background: var(--neon-yellow);
  background: color-mix(in srgb, var(--neon-yellow) 33%, #fff);
  border-color: var(--neon-yellow);
  color: var(--on-gold);
}

.call-hog.call-active {
  background: var(--pink);
  background: color-mix(in srgb, var(--pink) 33%, #fff);
  border-color: var(--pink);
  color: var(--on-gold);
}

/* Settlement breakdown (Design §2.2): a compact ledger under the board.
   Hidden with the generic .hidden until resolveBattle() fills it. */
#result-panel {
  width: min(100%, 420px);
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  font-size: 0.88rem;
  flex-shrink: 0;
}

.result-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
}

.result-label {
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.75rem;
  align-self: center;
}

.result-value {
  color: var(--text-primary);
  font-weight: 700;
  text-align: right;
}

/* Pause: freeze all CSS animation while YouTube pauses the game */
body.is-paused #board,
body.is-paused #next-battle-btn,
body.is-paused #message.complete .letter,
body.is-paused .cell {
  animation-play-state: paused !important;
}

body.is-paused .cell {
  pointer-events: none;
}

/* Loading screen */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

#loading-screen.hidden {
  display: none;
}

.loading-box {
  text-align: center;
}

.loading-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 6px;
  margin-bottom: 24px;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
  border: 4px solid var(--bg-card);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-text {
  font-size: 0.9rem;
  letter-spacing: 2px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.2s;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 28px 32px 24px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  min-width: 260px;
}

:root[data-theme="light"] .modal-box {
  background: #ffffff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.modal-btn {
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--gold);
  transition: all 0.2s;
  letter-spacing: 1px;
}

.modal-cancel {
  background: transparent;
  color: var(--gold-text, var(--gold));
}

.modal-cancel:hover,
.modal-cancel:focus-visible {
  background: var(--gold);
  background: color-mix(in srgb, var(--gold) 33%, #fff);
  color: var(--on-gold);
}

.modal-confirm {
  background: var(--gold);
  background: color-mix(in srgb, var(--gold) 33%, #fff);
  color: var(--on-gold);
}

.modal-confirm:hover,
.modal-confirm:focus-visible {
  background: var(--gold-light);
  background: color-mix(in srgb, var(--gold-light) 33%, #fff);
  border-color: var(--gold-light);
}

/* War ending (Design §2.8): a full-screen takeover after battle 200. Same
   card language as the modal, sized to hold the whole-run ledger. */
.final-overlay {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.final-overlay.hidden,
.final-screen.hidden {
  display: none;
}

.final-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 560px;
  margin: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

:root[data-theme="light"] .final-screen {
  background: #ffffff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.final-title {
  margin: 0;
  font-size: 1.25rem;
  text-align: center;
  color: var(--text-primary);
}

.final-screen .result-panel {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  font-size: 0.92rem;
}

.final-screen .call-row {
  flex-wrap: wrap;
}

.final-btn {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 24px;
  border: 2px solid var(--gold);
  background: var(--gold);
  background: color-mix(in srgb, var(--gold) 33%, #fff);
  color: var(--on-gold);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.final-btn:hover,
.final-btn:focus-visible {
  background: transparent;
  color: var(--gold);
}

/* Short/landscape viewports (e.g. 16:9 phones) */
@media (max-height: 560px) {
  header {
    padding: 6px 0 4px;
  }

  h1 {
    font-size: 1.3rem;
    letter-spacing: 2px;
    margin-bottom: 6px;
  }

  .stats-row {
    gap: 16px;
    margin-bottom: 6px;
  }

  .stat-label {
    font-size: 0.6rem;
    letter-spacing: 1px;
  }

  .stat-value {
    font-size: 1rem;
  }

  .controls-row {
    gap: 10px;
  }

  #new-game-btn {
    padding: 5px 14px;
    font-size: 0.75rem;
  }

  .icon-btn {
    width: 30px;
    height: 30px;
  }

  #message {
    min-height: 24px;
    font-size: 0.85rem;
    margin-top: 4px;
  }

  #action-row {
    margin-top: 4px;
  }

  #end-battle-btn,
  #next-battle-btn {
    padding: 5px 14px;
    font-size: 0.75rem;
  }

  #help-btn {
    padding: 5px 14px;
    font-size: 0.75rem;
  }

  #call-row {
    margin-top: 4px;
    gap: 6px;
  }

  .call-btn {
    min-width: 56px;
    padding: 5px 14px;
    font-size: 0.75rem;
  }

  #result-panel {
    margin-top: 2px;
    padding: 4px 8px;
    font-size: 0.8rem;
  }

  .result-line {
    padding: 0;
  }

  .result-label {
    font-size: 0.68rem;
  }

  .loading-title {
    font-size: 1.4rem;
    margin-bottom: 16px;
  }
}

/* Narrow viewports (e.g. 9:16 phones) */
@media (max-width: 480px) {
  #app {
    padding: 0 6px;
  }

  h1 {
    font-size: 1.5rem;
    letter-spacing: 2px;
  }

  .stats-row {
    gap: 14px;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  #board {
    padding: 8px;
  }
}
