/* ==========================================================================
   BATTLESHIP: Arcade Edition
   Look: 80s arcade cabinet. Pac-Man maze-blue frames and pellets, Street
   Fighter health bars, VS splash and announcer banners, pixel fonts, CRT.
   Sections: tokens · base · CRT/background · top bar · title · game select ·
             fight bar & HUD · boards & cells · effects · clue card ·
             overlays (banner, VS, modals) · responsive
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --black: #000;
  --maze: #2121de;
  --maze-glow: rgba(60, 60, 255, 0.75);
  --yellow: #ffe600;
  --pink: #ff5ccd;
  --cyan: #00f0ff;
  --red: #ff2b2b;
  --orange: #ffa52b;
  --green: #39ff14;
  --dot: #ffb8ae;
  --white: #f4f4ff;
  --muted: #8f9bd6;
  --sea: #04041c;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --crt: "VT323", ui-monospace, monospace;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  font-family: var(--crt);
  font-size: 1.3rem;
  line-height: 1.2;
  color: var(--white);
  background: var(--black);
  -webkit-font-smoothing: none;
}
.hidden { display: none !important; }
h1, h2, h3, h4 { margin: 0; font-family: var(--pixel); font-weight: 400; }
b { color: var(--yellow); font-weight: 400; }
.y { color: var(--yellow); } .r { color: var(--red); } .c { color: var(--cyan); } .w { color: var(--white); }

button {
  font-family: var(--pixel);
  font-size: 0.6rem;
  line-height: 1.4;
  color: var(--white);
  background: var(--black);
  border: 3px solid var(--maze);
  border-radius: 0;
  padding: 0.9em 1.1em;
  cursor: pointer;
  box-shadow: 4px 4px 0 #000, 0 0 10px var(--maze-glow);
  transition: transform 0.05s;
}
@media (hover: hover) { button:hover:not(:disabled) { border-color: var(--yellow); color: var(--yellow); } }
button:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 #000; }
button:disabled { opacity: 0.35; cursor: not-allowed; }
button:not(.cell) { min-height: 36px; } /* comfortable tap target */
button:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
button.primary { background: var(--yellow); border-color: var(--yellow); color: #000; box-shadow: 4px 4px 0 #a08a00; }
@media (hover: hover) { button.primary:hover:not(:disabled) { background: var(--pink); border-color: var(--pink); color: #000; } }
button[aria-pressed="true"] { border-color: var(--cyan); color: var(--cyan); }
button.toggle[aria-pressed="false"] { color: var(--muted); border-color: #333a7a; box-shadow: 3px 3px 0 #000; }

/* ---------- CRT + background ---------- */
.bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(circle, rgba(255, 184, 174, 0.12) 1.5px, transparent 2px) 0 0 / 32px 32px,
    radial-gradient(ellipse at 50% -10%, rgba(33, 33, 222, 0.35), transparent 60%),
    var(--black);
}
.crt-overlay { display: none; }
body.crt .crt-overlay {
  display: block;
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.28) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.6));
  animation: crt-flicker 0.12s infinite;
}
@keyframes crt-flicker { 50% { opacity: 0.93; } }
body.crt h1, body.crt h2, body.crt .timer, body.crt .banner { text-shadow: 0 0 6px currentColor; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.7rem clamp(0.6rem, 3vw, 1.6rem);
  border-bottom: 3px solid var(--maze);
  box-shadow: 0 0 14px var(--maze-glow);
  background: #000;
  position: sticky; top: 0; z-index: 10;
}
.logo-sm { font-family: var(--pixel); font-size: 0.9rem; color: var(--yellow); flex: 1; text-align: center; }
.logo-sm span { color: var(--cyan); }
.toggles { display: flex; gap: 0.4rem; margin-left: auto; }
.toggles button { font-size: 0.5rem; padding: 0.7em 0.8em; }
main { max-width: 1260px; margin: 0 auto; padding: clamp(0.7rem, 2.5vw, 1.6rem); }
.screen { animation: screen-in 0.3s steps(6); }
.screen.pending { visibility: hidden; } /* mode screen waits behind How to Play */
@keyframes screen-in { from { opacity: 0; transform: scale(0.98); } }
.controls { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; margin: 1rem 0; }

/* ---------- Title screen ---------- */
.title-screen { text-align: center; padding-top: clamp(1rem, 5vh, 3rem); }
.title-hi { font-family: var(--pixel); font-size: 0.7rem; display: flex; justify-content: center; gap: 1rem; }
.title-hi span { color: var(--red); }
.title-hi b { color: var(--white); }
.title-logo {
  margin: clamp(1.4rem, 5vh, 3rem) 0 0.6rem;
  font-size: clamp(2.2rem, 9vw, 5.6rem);
  line-height: 1.1;
  display: flex; flex-wrap: wrap; justify-content: center;
}
.title-logo span:first-child { color: var(--yellow); text-shadow: 4px 4px 0 var(--pink), 8px 8px 0 var(--maze); }
.title-logo span:last-child { color: var(--cyan); text-shadow: 4px 4px 0 var(--pink), 8px 8px 0 var(--maze); }
.title-sub { font-family: var(--pixel); font-size: clamp(0.6rem, 2vw, 0.9rem); color: var(--pink); letter-spacing: 0.4em; margin: 1.2rem 0 0; }

/* Pac-Man chomping pellets, chased by a pixel battleship. */
.lane { position: relative; height: 54px; margin: clamp(1.6rem, 6vh, 3.2rem) auto; max-width: 720px; overflow: hidden; border-top: 3px solid var(--maze); border-bottom: 3px solid var(--maze); box-shadow: 0 0 12px var(--maze-glow), inset 0 0 12px var(--maze-glow); }
.pellets { position: absolute; inset: 0; background: radial-gradient(circle, var(--dot) 3px, transparent 3.5px) 0 50% / 36px 100% repeat-x; }
.pac {
  position: absolute; top: 9px; left: -40px; width: 30px; height: 30px; border-radius: 50%;
  background: conic-gradient(from 90deg, transparent 0 45deg, var(--yellow) 45deg 315deg, transparent 315deg);
  animation: chomp 0.25s steps(1) infinite, lane-run 6s linear infinite;
}
@keyframes chomp { 50% { background: conic-gradient(from 90deg, transparent 0 8deg, var(--yellow) 8deg 352deg, transparent 352deg); } }
.sprite-ship {
  position: absolute; top: 15px; left: -160px; width: 84px; height: 18px;
  background: linear-gradient(to bottom, #e8ecf8 0 22%, #a8b0c8 22% 70%, #59607e 70%);
  clip-path: polygon(0 40%, 8% 40%, 8% 20%, 16% 20%, 16% 0, 100% 0, 100% 100%, 16% 100%, 16% 80%, 8% 80%, 8% 60%, 0 60%);
  transform: scaleX(-1);
  animation: lane-run 6s linear infinite;
  animation-delay: 0.6s;
}
@keyframes lane-run { to { left: 105%; } }
.press-start { font-size: clamp(0.8rem, 2.6vw, 1.2rem); padding: 1em 1.6em; border-color: var(--yellow); color: var(--yellow); animation: blink 1s steps(1) infinite; }
.press-start:hover { animation: none; }
@keyframes blink { 50% { opacity: 0; } }
.title-foot { color: var(--muted); margin: 1rem 0 0; }
.credit { font-family: var(--pixel); font-size: 0.6rem; color: var(--white); margin-top: clamp(1.6rem, 6vh, 3rem); }

/* ---------- Game select ---------- */
.screen-title { text-align: center; color: var(--yellow); font-size: clamp(1rem, 3vw, 1.5rem); margin: 0.4rem 0 1.4rem; text-shadow: 3px 3px 0 var(--pink); }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.4rem; }
.mode-card {
  display: flex; flex-direction: column; gap: 0.7rem;
  padding: 1.2rem;
  background: rgba(0, 0, 0, 0.75);
  border: 6px double var(--maze);
  border-radius: 14px;
  box-shadow: 0 0 16px var(--maze-glow), inset 0 0 16px var(--maze-glow);
  transition: transform 0.1s steps(2);
}
.mode-card:hover { transform: translateY(-4px); border-color: var(--yellow); box-shadow: 0 0 22px rgba(255, 230, 0, 0.5), inset 0 0 12px rgba(255, 230, 0, 0.3); }
.mode-card h3 { font-size: 1.1rem; color: var(--yellow); }
.standard-card h3 { color: var(--cyan); }
.card-head { display: flex; gap: 0.5rem; }
.badge { font-family: var(--pixel); font-size: 0.5rem; padding: 0.5em 0.7em; border: 2px solid var(--pink); color: var(--pink); }
.badge.alt { border-color: var(--cyan); color: var(--cyan); }
.desc { margin: 0; font-size: 1.4rem; }
.rules { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: 1.2rem; list-style: square; }
.card-actions { display: flex; gap: 0.6rem; margin-top: auto; }
.card-actions .primary { flex: 1; font-size: 0.8rem; }
/* Decorative mini boards on each card */
.card-art {
  height: 96px; position: relative;
  background:
    linear-gradient(var(--maze) 0 0) 0 0 / 100% 2px no-repeat,
    repeating-linear-gradient(90deg, rgba(33, 33, 222, 0.55) 0 2px, transparent 2px 24px),
    repeating-linear-gradient(0deg, rgba(33, 33, 222, 0.55) 0 2px, transparent 2px 24px),
    var(--sea);
}
.art-arcade::before { content: ""; position: absolute; left: 50px; top: 26px; width: 46px; height: 46px; box-shadow: inset 0 0 0 4px var(--yellow); animation: blink 0.8s steps(1) infinite; }
.art-arcade::after { content: ""; position: absolute; left: 150px; top: 38px; width: 12px; height: 12px; background: var(--red); box-shadow: 24px 0 0 var(--red), 72px -24px 0 var(--dot); }
.art-standard::before {
  content: ""; position: absolute; left: 30px; top: 30px; width: 112px; height: 14px;
  background: linear-gradient(to bottom, #e8ecf8 0 22%, #a8b0c8 22% 70%, #59607e 70%);
  clip-path: polygon(0 40%, 6% 40%, 6% 20%, 12% 20%, 12% 0, 100% 0, 100% 100%, 12% 100%, 12% 80%, 6% 80%, 6% 60%, 0 60%);
}
.art-standard::after { content: ""; position: absolute; left: 186px; top: 58px; width: 12px; height: 12px; background: var(--red); box-shadow: 24px 0 0 var(--red), -48px 0 0 var(--dot), 72px -24px 0 var(--dot); }

/* High-score tables */
.hiscores { max-width: 420px; margin: 1.6rem auto 0; text-align: center; }
.hiscores h4 { color: var(--red); font-size: 0.75rem; margin-bottom: 0.7rem; }
.hiscores ol { list-style: none; margin: 0; padding: 0; font-family: var(--pixel); font-size: 0.65rem; }
.hiscores li { display: grid; grid-template-columns: 3.5em 1fr 1fr; gap: 0.5rem; padding: 0.35rem 0; }
.hiscores li span { color: var(--cyan); text-align: left; }
.hiscores li b { color: var(--white); }
.hiscores li em { font-style: normal; text-align: right; color: var(--yellow); }
.hiscores li.me { animation: blink 0.6s steps(1) 6; }
.hiscores li.me b, .hiscores li.me em { color: var(--pink); }
.hiscores .empty { color: var(--muted); margin: 0; }

/* ---------- Fight bar (Street Fighter HUD) ---------- */
.fight-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 0.9rem; margin-bottom: 0.9rem; }
.fighter { display: flex; flex-direction: column; gap: 0.35rem; }
.fighter.right { align-items: flex-end; }
.fighter-name { font-family: var(--pixel); font-size: 0.6rem; color: var(--white); }
.fighter.left .fighter-name { color: var(--cyan); }
.fighter.right .fighter-name { color: var(--red); }
.hp { position: relative; width: 100%; height: 22px; background: #8a0000; border: 3px solid var(--white); box-shadow: 3px 3px 0 #000; }
.hp i { display: block; height: 100%; width: 100%; background: linear-gradient(to bottom, #fff58a 0 25%, var(--yellow) 25% 65%, #d9a400 65%); transition: width 0.4s steps(10); }
.fighter.right .hp i { margin-left: auto; }
.hp.low i { background: linear-gradient(to bottom, #ffb37a 0 25%, var(--orange) 25% 65%, #c85a00 65%); }
.hp.hurt { animation: hurt 0.4s steps(2); }
@keyframes hurt { 0%, 50% { border-color: var(--red); background: #fff; } }
.fight-mid { text-align: center; min-width: 7.5rem; }
.timer { display: block; font-family: var(--pixel); font-size: clamp(1.3rem, 3.4vw, 2rem); color: var(--yellow); }
.timer.low { color: var(--red); animation: blink 0.5s steps(1) infinite; }
.fight-mid small { font-family: var(--pixel); font-size: 0.5rem; color: var(--muted); }
.turn-pill { display: inline-block; font-family: var(--pixel); font-size: 0.6rem; padding: 0.6em 0.8em; border: 3px solid var(--muted); color: var(--muted); }
.turn-pill.you { border-color: var(--cyan); color: var(--cyan); animation: blink 1.2s steps(1) infinite; }
.turn-pill.enemy { border-color: var(--red); color: var(--red); }
.turn-pill.over { border-color: var(--yellow); color: var(--yellow); }

.comms { text-align: center; font-size: 1.5rem; min-height: 2.6rem; padding: 0.4rem 1rem; border: 3px solid var(--maze); background: #000; box-shadow: 0 0 10px var(--maze-glow); }

.hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; margin-bottom: 1rem; }
.hud-item { text-align: center; padding: 0.5rem; border: 3px solid var(--maze); background: #000; box-shadow: 0 0 8px var(--maze-glow); }
.hud-item span { display: block; font-family: var(--pixel); font-size: 0.5rem; color: var(--red); }
.hud-item strong { display: block; margin-top: 0.4rem; font-family: var(--pixel); font-size: 0.9rem; font-weight: 400; color: var(--white); }
.pips { display: flex !important; justify-content: center; gap: 6px; }
.pips i { width: 14px; height: 14px; background: var(--yellow); box-shadow: 2px 2px 0 #a08a00; }
.pips i.used { background: transparent; box-shadow: inset 0 0 0 2px #6b6100; }
.pips.big { margin-bottom: 0.6rem; }
.pips.big i { width: 18px; height: 18px; }

/* ---------- Boards ---------- */
.boards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.4rem; align-items: start; }
.board-wrap {
  padding: 0.9rem; border-radius: 12px;
  background: rgba(0, 0, 0, 0.8);
  border: 6px double var(--maze);
  box-shadow: 0 0 14px var(--maze-glow), inset 0 0 14px var(--maze-glow);
  display: flex; flex-direction: column; align-items: center; gap: 0.7rem;
}
.board-wrap h3 { font-size: 0.65rem; color: var(--yellow); }
.grid {
  --gap: 3px;
  display: grid;
  grid-template-columns: 1.4em repeat(var(--size), minmax(0, 1fr));
  gap: var(--gap);
  width: 100%;
  user-select: none;
}
.grid.standard { max-width: 440px; }
.grid.arcade { max-width: 340px; }
.label { display: grid; place-items: center; font-family: var(--pixel); font-size: 0.45rem; color: var(--muted); }
.grid.armed { animation: armed 1.6s steps(2) infinite; }
@keyframes armed { 50% { filter: drop-shadow(0 0 6px rgba(255, 230, 0, 0.45)); } }

.cell {
  position: relative; aspect-ratio: 1; padding: 0;
  border: 1px solid rgba(60, 60, 255, 0.5);
  border-radius: 0;
  background: var(--sea);
  box-shadow: none;
  cursor: default;
}
.cell:active:not(:disabled) { transform: none; box-shadow: none; }
.grid.enemy .cell:not(.hit):not(.miss) { cursor: crosshair; }
@media (hover: hover) {
  .grid.enemy .cell:not(.hit):not(.miss):hover { border-color: var(--yellow); background: #14145a; box-shadow: inset 0 0 0 2px var(--yellow); }
}
.grid.enemy .cell:not(.hit):not(.miss):active { border-color: var(--yellow); box-shadow: inset 0 0 0 2px var(--yellow); }
.grid.disabled .cell { pointer-events: none; }

/* Pixel ship hulls: ::before spans adjacent cells with a stepped bow. */
.cell.ship::before {
  content: ""; position: absolute; z-index: 1;
  background: linear-gradient(to bottom, #e8ecf8 0 22%, #a8b0c8 22% 70%, #59607e 70%);
}
.cell.hull-v::before { background: linear-gradient(to right, #e8ecf8 0 22%, #a8b0c8 22% 70%, #59607e 70%); }
.cell.hull-h::before { top: 24%; bottom: 24%; left: calc(-1 * var(--gap) - 1px); right: calc(-1 * var(--gap) - 1px); }
.cell.hull-v::before { left: 24%; right: 24%; top: calc(-1 * var(--gap) - 1px); bottom: calc(-1 * var(--gap) - 1px); }
.cell.hull-h.bow::before { left: 6%; clip-path: polygon(0 40%, 14% 40%, 14% 20%, 28% 20%, 28% 0, 100% 0, 100% 100%, 28% 100%, 28% 80%, 14% 80%, 14% 60%, 0 60%); }
.cell.hull-h.stern::before { right: 12%; }
.cell.hull-v.bow::before { top: 6%; clip-path: polygon(40% 0, 60% 0, 60% 14%, 80% 14%, 80% 28%, 100% 28%, 100% 100%, 0 100%, 0 28%, 20% 28%, 20% 14%, 40% 14%); }
.cell.hull-v.stern::before { bottom: 12%; }
.cell.sunk { background: #2a0010; border-color: rgba(255, 43, 43, 0.6); }
.cell.sunk::before { background: repeating-linear-gradient(45deg, #5a1a24 0 4px, #3a0d16 4px 8px) !important; }

/* Hit = blinking pixel flame. Miss = Pac-Man pellet. */
.cell.hit::after, .cell.miss::after { content: ""; position: absolute; z-index: 2; inset: 0; margin: auto; }
.cell.hit::after {
  width: 52%; height: 52%;
  background: linear-gradient(var(--yellow), var(--yellow)) center / 40% 40% no-repeat, var(--red);
  box-shadow: 0 0 0 2px var(--orange), 0 0 10px var(--red);
  animation: flicker 0.5s steps(1) infinite;
}
@keyframes flicker { 50% { background: linear-gradient(var(--white), var(--white)) center / 40% 40% no-repeat, var(--orange); } }
.cell.sunk.hit::after { width: 40%; height: 40%; background: #7a0f22; box-shadow: 0 0 0 2px #b0213a; animation: none; }
.cell.miss::after { width: 24%; height: 24%; background: var(--dot); box-shadow: 0 0 6px rgba(255, 184, 174, 0.7); }

/* Placement preview */
.cell.preview-ok { background: rgba(57, 255, 20, 0.35); border-color: var(--green); }
.cell.preview-bad { background: rgba(255, 43, 43, 0.4); border-color: var(--red); }

/* Focus zones: gold = yours (enemy board), red = CPU's (your board). */
.cell.zone { border-color: var(--yellow); box-shadow: inset 0 0 0 3px var(--yellow), 0 0 10px rgba(255, 230, 0, 0.6); animation: zone-blink 0.8s steps(1) infinite; }
.grid.mine .cell.zone { border-color: var(--red); box-shadow: inset 0 0 0 3px var(--red), 0 0 10px rgba(255, 43, 43, 0.6); }
@keyframes zone-blink { 50% { box-shadow: inset 0 0 0 3px transparent; } }

/* Hunt Helper heatmap: --heat is 0..1 from AI.probabilityMap. */
.cell.heat { background: linear-gradient(rgba(0, 240, 255, calc(var(--heat) * 0.55)), rgba(0, 240, 255, calc(var(--heat) * 0.55))), var(--sea); }
.cell.best { outline: 2px dashed var(--cyan); outline-offset: -5px; }

/* ---------- Effects ---------- */
.cell.boom { animation: boom 0.4s steps(4); z-index: 3; }
@keyframes boom { 0% { background: #fff; transform: scale(1.3); } 50% { background: var(--yellow); transform: scale(1.15); } }
.cell.splash { animation: splash 0.4s steps(3); }
@keyframes splash { 0% { background: #3a3aff; } }
.cell.sinking { animation: sinking 0.9s steps(6); }
@keyframes sinking { 0%, 33%, 66% { background: var(--red); } 16%, 50%, 83% { background: #fff; } }
body.hitstop .board-wrap *, body.hitstop .board-wrap *::before, body.hitstop .board-wrap *::after { animation-play-state: paused !important; }

.fx { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.fx i { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; background: var(--yellow); animation: spark 0.6s steps(6) forwards; }
.fx i:nth-child(3n) { background: var(--orange); }
.fx i:nth-child(3n + 1) { background: var(--red); }
.fx.sunk i { width: 8px; height: 8px; animation-duration: 0.8s; }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)); opacity: 0; } }
.fx b { position: absolute; inset: 0; border: 3px solid var(--orange); animation: ring 0.5s steps(5) forwards; }
.fx.miss b { border-color: var(--dot); }
.fx.sunk b { border-color: var(--red); border-width: 4px; animation-duration: 0.8s; }
@keyframes ring { from { transform: scale(0.4); opacity: 1; } to { transform: scale(2.6); opacity: 0; } }

.shake-sm { animation: shake-sm 0.25s steps(5); }
@keyframes shake-sm { 25% { transform: translate(-3px, 1px); } 50% { transform: translate(3px, -1px); } 75% { transform: translate(-2px, 0); } }
.shake-lg { animation: shake-lg 0.5s steps(8); }
@keyframes shake-lg {
  12% { transform: translate(-8px, 3px) rotate(-0.4deg); } 25% { transform: translate(7px, -4px) rotate(0.4deg); }
  37% { transform: translate(-6px, 2px); } 50% { transform: translate(5px, -2px); }
  62% { transform: translate(-3px, 1px); } 75% { transform: translate(2px, 0); }
}

.float-text {
  position: fixed; z-index: 60; pointer-events: none; transform: translate(-50%, -50%);
  font-family: var(--pixel); font-size: 0.75rem; color: var(--white); text-shadow: 2px 2px 0 #000;
  animation: rise 0.95s steps(8) forwards;
}
.float-text.score { color: var(--yellow); font-size: 0.85rem; }
.float-text.hit { color: var(--orange); }
.float-text.miss { color: var(--dot); font-size: 0.6rem; }
@keyframes rise { to { transform: translate(-50%, -260%); opacity: 0; } }

/* ---------- Rosters & legend ---------- */
.roster { display: flex; flex-wrap: wrap; gap: 0.4rem 0.6rem; justify-content: center; }
.ship-tag { display: inline-flex; align-items: center; gap: 3px; font-family: var(--pixel); font-size: 0.45rem; padding: 0.5em 0.6em; border: 2px solid #333a7a; }
.ship-tag b { color: var(--white); margin-right: 5px; }
.ship-tag i { width: 7px; height: 7px; background: #a8b0c8; }
.ship-tag i.dmg { background: var(--red); }
.ship-tag.gone { border-color: var(--red); opacity: 0.55; }
.ship-tag.gone b { text-decoration: line-through; color: var(--red); }
.ship-tag.pending { opacity: 0.4; border-style: dashed; }
.legend { display: flex; gap: 1rem; margin: 0; font-size: 1.05rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.swatch { display: inline-block; width: 12px; height: 12px; }
.swatch.gold { box-shadow: inset 0 0 0 3px var(--yellow); }
.swatch.red { box-shadow: inset 0 0 0 3px var(--red); }
.swatch.heat { background: rgba(0, 240, 255, 0.55); }

/* ---------- Clue card ---------- */
.arcade-layout { display: grid; grid-template-columns: minmax(290px, 1.15fr) 1fr 1fr; gap: 1rem; align-items: start; }
.clue-card { padding: 1.1rem; border: 6px double var(--pink); border-radius: 12px; background: rgba(0, 0, 0, 0.85); box-shadow: 0 0 14px rgba(255, 92, 205, 0.55), inset 0 0 14px rgba(255, 92, 205, 0.35); }
.clue-category { font-family: var(--pixel); font-size: 0.55rem; color: var(--pink); }
.clue-text { font-size: 1.65rem; margin: 0.6rem 0 0.8rem; min-height: 2.4em; }
.clue-pattern { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 0.9rem; }
.clue-pattern .tile { width: 1.9em; height: 1.9em; display: grid; place-items: center; font-family: var(--pixel); font-size: 0.65rem; background: var(--white); color: #000; box-shadow: 3px 3px 0 var(--maze); }
.clue-pattern .tile.blank { color: transparent; }
.clue-pattern .tile.gap { background: transparent; box-shadow: none; width: 0.6em; }
.clue-pattern .len { align-self: center; color: var(--muted); margin-left: 6px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.options button { font-family: var(--crt); font-size: 1.35rem; text-align: left; padding: 0.35em 0.6em; line-height: 1.1; }
.options button kbd { font-family: var(--pixel); font-size: 0.5rem; color: #000; background: var(--cyan); padding: 0.25em 0.4em; margin-right: 0.5em; vertical-align: middle; }
.options button.correct { border-color: var(--green); color: var(--green); opacity: 1; }
.options button.wrong { border-color: var(--red); color: var(--red); opacity: 1; animation: shake-sm 0.3s steps(4); }
.feedback { min-height: 1.3em; margin-top: 0.9rem; font-size: 1.3rem; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--dot); }
.ai-feedback { min-height: 1.2em; margin-top: 0.3rem; font-size: 1.2rem; color: var(--muted); }
.ai-feedback:not(:empty)::before { content: "CPU> "; color: var(--red); }
.clue-card .controls { margin-bottom: 0; }

/* ---------- Announcer banner ---------- */
.banner {
  position: fixed; left: 50%; top: 42%; z-index: 70; pointer-events: none;
  transform: translate(-50%, -50%);
  font-family: var(--pixel); font-size: clamp(1.8rem, 7vw, 4.2rem);
  white-space: nowrap; color: var(--yellow);
  text-shadow: 4px 4px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
}
.banner.small { font-size: clamp(0.9rem, 3.4vw, 1.8rem); top: 30%; }
.banner.show { animation: banner var(--dur, 900ms) steps(10) forwards; }
.banner.go { color: var(--yellow); }
.banner.good { color: var(--green); }
.banner.combo { color: var(--cyan); }
.banner.bad { color: var(--red); }
.banner.ko { color: var(--red); font-size: clamp(3rem, 14vw, 8rem); }
@keyframes banner {
  0% { transform: translate(-50%, -50%) scale(2.6); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  85% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.1); opacity: 0; }
}

/* ---------- VS splash ---------- */
.vs { position: fixed; inset: 0; z-index: 80; background: #000; overflow: hidden; cursor: pointer; }
.vs-side { position: absolute; top: 0; bottom: 0; width: 55%; display: grid; place-items: center; }
.vs-side b { font-family: var(--pixel); font-size: clamp(1.4rem, 6vw, 3.6rem); text-shadow: 4px 4px 0 #000; }
.vs-left { left: 0; background: linear-gradient(135deg, #00306a, #0060c0); clip-path: polygon(0 0, 100% 0, 82% 100%, 0 100%); animation: vs-left 0.35s steps(5); }
.vs-left b { color: var(--cyan); margin-right: 18%; }
.vs-right { right: 0; background: linear-gradient(135deg, #8a0010, #e0002a); clip-path: polygon(18% 0, 100% 0, 100% 100%, 0 100%); animation: vs-right 0.35s steps(5); }
.vs-right b { color: var(--white); margin-left: 18%; }
@keyframes vs-left { from { transform: translateX(-100%); } }
@keyframes vs-right { from { transform: translateX(100%); } }
.vs-mid { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-family: var(--pixel); font-size: clamp(2.6rem, 12vw, 7rem); color: var(--yellow); text-shadow: 6px 6px 0 #000, 0 0 30px var(--orange); animation: vs-pop 0.5s steps(5) 0.3s both; }
@keyframes vs-pop { from { transform: translate(-50%, -50%) scale(4); opacity: 0; } }
.vs-sub { position: absolute; left: 0; right: 0; bottom: 18%; text-align: center; font-family: var(--pixel); font-size: clamp(0.7rem, 2.4vw, 1.1rem); color: var(--white); text-shadow: 3px 3px 0 #000; }
.vs-skip { position: absolute; left: 0; right: 0; bottom: 6%; text-align: center; font-family: var(--pixel); font-size: 0.5rem; color: rgba(255, 255, 255, 0.7); animation: blink 1s steps(1) infinite; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 1rem; background: rgba(0, 0, 10, 0.82); overflow-y: auto; }
.modal-box {
  width: min(480px, 100%); padding: 1.6rem 1.4rem 1.2rem; text-align: center;
  background: #000; border: 6px double var(--maze); border-radius: 14px;
  box-shadow: 0 0 24px var(--maze-glow), inset 0 0 16px var(--maze-glow);
  animation: pop 0.3s steps(5);
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.modal-box h2 { font-size: clamp(1.2rem, 5vw, 1.8rem); line-height: 1.3; }
.modal-box p { margin: 0.6rem 0 1rem; font-size: 1.4rem; }
.result-box.win { border-color: var(--green); box-shadow: 0 0 26px rgba(57, 255, 20, 0.45); }
.result-box.win h2 { color: var(--green); }
.result-box.lose { border-color: var(--red); box-shadow: 0 0 26px rgba(255, 43, 43, 0.45); }
.result-box.lose h2 { color: var(--red); }
.result-box.draw { border-color: var(--yellow); }
.result-box.draw h2 { color: var(--yellow); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin: 0 0 0.4rem; }
.stats div { padding: 0.55rem 0.4rem; border: 2px solid #333a7a; }
.stats dt { font-family: var(--pixel); font-size: 0.45rem; color: var(--red); }
.stats dd { margin: 0.45rem 0 0; font-family: var(--pixel); font-size: 0.75rem; color: var(--white); }
.hiscore-entry { margin-top: 1rem; }
.hiscore-entry p { font-family: var(--pixel); font-size: 0.55rem; color: var(--yellow); animation: blink 1s steps(1) infinite; margin: 0 0 0.7rem; }
.entry-row { display: flex; gap: 0.6rem; justify-content: center; }
.entry-row input {
  width: 6.2em; font-family: var(--pixel); font-size: 1rem; text-align: center; text-transform: uppercase; letter-spacing: 0.3em;
  padding: 0.5em 0.2em 0.5em 0.5em; background: #000; color: var(--yellow); border: 3px solid var(--yellow);
}
.entry-row input:focus { outline: 3px solid var(--cyan); }
.result-box .hiscores { margin-top: 1rem; }

/* How to Play */
.help-box { width: min(560px, 100%); }
.help-step { font-family: var(--pixel); font-size: 0.5rem; color: var(--pink); margin-bottom: 0.8rem; }
.help-box h2 { color: var(--yellow); font-size: clamp(1rem, 4vw, 1.4rem); }
.help-art { margin: 1rem auto 0.4rem; display: flex; flex-direction: column; align-items: center; gap: 0.6rem; min-height: 120px; justify-content: center; }
.help-text { font-size: 1.45rem; line-height: 1.25; text-align: left; min-height: 6.2em; }
.help-clue { text-align: left; }
.help-clue p { margin: 0 0 0.4rem; font-size: 1.3rem; }
.dots { display: flex; gap: 8px; justify-content: center; margin-top: 0.8rem; }
.dots i { width: 10px; height: 10px; background: #333a7a; }
.dots i.on { background: var(--yellow); }
.mini { display: inline-grid; grid-template-columns: repeat(var(--n), 22px); gap: 2px; }
.mc { position: relative; width: 22px; height: 22px; background: var(--sea); border: 1px solid rgba(60, 60, 255, 0.6); }
.mc.s { background: #a8b0c8; box-shadow: inset 0 4px 0 #e8ecf8, inset 0 -5px 0 #59607e; }
.mc.h::after { content: ""; position: absolute; inset: 5px; background: linear-gradient(var(--yellow), var(--yellow)) center / 40% 40% no-repeat, var(--red); animation: flicker 0.5s steps(1) infinite; }
.mc.x { background: #5a1a24; box-shadow: none; }
.mc.x::after { animation: none; background: #7a0f22; }
.mc.m::after { content: ""; position: absolute; inset: 7px; background: var(--dot); }
.mc.z { box-shadow: inset 0 0 0 3px var(--yellow), 0 0 8px rgba(255, 230, 0, 0.6); }
.mc.r { box-shadow: inset 0 0 0 3px var(--red), 0 0 8px rgba(255, 43, 43, 0.6); }
.mc.s.r { background: #a8b0c8; }

/* ---------- Stats screen ---------- */
.stats-menu { display: flex; justify-content: center; margin-top: 1rem; }
.stats-menu button { min-width: 180px; color: var(--cyan); border-color: var(--cyan); }
#statsView { min-width: 0; }
.stats-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 960px; margin: 0 auto 1.2rem; }
.stats-tiles .hud-item { min-width: 0; }
.stats-tiles .hud-item strong { overflow-wrap: anywhere; font-size: clamp(0.55rem, 1vw, 0.8rem); }
.stats-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.stats-panel { min-width: 0; }
.stats-panel h3, .stats-recent h3 {
  color: var(--yellow); font-size: 0.72rem; text-align: center; margin: 0 0 0.9rem;
}
.stats-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.4rem 0.8rem; width: 100%; margin: 0; }
.stats-metrics > div {
  min-width: 0; display: flex; justify-content: space-between; align-items: baseline;
  gap: 0.4rem; padding: 0.35rem 0; border-bottom: 1px solid #28286c;
}
.stats-metrics dt { color: var(--cyan); font-family: var(--pixel); font-size: 0.42rem; }
.stats-metrics dd { margin: 0; color: var(--yellow); text-align: right; white-space: nowrap; }
.opponent-table, .stats-recent table {
  width: 100%; border-collapse: collapse; font-family: var(--pixel); font-size: 0.43rem;
}
.opponent-table { width: 100%; margin-top: 0.85rem; }
.opponent-table th, .opponent-table td,
.stats-recent th, .stats-recent td { padding: 0.55rem 0.45rem; border-bottom: 1px solid #28286c; text-align: left; }
.opponent-table thead, .stats-recent thead { color: var(--pink); }
.opponent-table td, .stats-recent td { color: var(--white); }
.opponent-table td:not(:first-child), .opponent-table th:not(:first-child) { text-align: right; }
.stats-recent { min-width: 0; width: 100%; margin-top: 1rem; }
.stats-table-wrap { min-width: 0; width: 100%; overflow-x: auto; }
.stats-recent table { min-width: 590px; }
.stats-recent .stats-result.win { color: var(--green); }
.stats-recent .stats-result.lose { color: var(--red); }
.stats-recent .stats-result.draw { color: var(--yellow); }
.stats-empty {
  margin: 1rem 0; padding: 1.4rem 0.8rem; border: 4px double var(--maze);
  color: var(--yellow); font-family: var(--pixel); font-size: 0.7rem; text-align: center;
}
.stats-actions { margin: 1.2rem 0 0; }
.stats-actions #statsReset { color: var(--red); border-color: var(--red); }

/* ---------- Touch ---------- */
button, .cell { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
main, .modal, .banner, .vs { -webkit-user-select: none; user-select: none; }
.topbar { padding-top: max(0.7rem, env(safe-area-inset-top)); }
main { padding-bottom: max(1.6rem, env(safe-area-inset-bottom)); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .arcade-layout { grid-template-columns: 1fr 1fr; }
  .clue-card { grid-column: 1 / -1; }
}
@media (max-width: 680px) {
  body { font-size: 1.2rem; }
  .arcade-layout, .boards { grid-template-columns: 1fr; }
  .hud { gap: 0.35rem; }
  .hud-item strong { font-size: 0.7rem; }
  .options { grid-template-columns: 1fr 1fr; gap: 0.45rem; }
  .options button { font-size: 1.2rem; min-height: 46px; }
  .clue-card { padding: 0.8rem; border-width: 4px; }
  .clue-text { font-size: 1.4rem; min-height: 0; margin: 0.4rem 0 0.6rem; }
  .feedback { font-size: 1.15rem; margin-top: 0.6rem; }
  .hud { margin-bottom: 0.6rem; }
  .hud-item { padding: 0.35rem 0.2rem; }
  .fight-bar { margin-bottom: 0.5rem; }
  main { padding: 0.5rem 0.4rem max(1.2rem, env(safe-area-inset-bottom)); }
  .grid { grid-template-columns: 1em repeat(var(--size), minmax(0, 1fr)); }
  .comms { font-size: 1.25rem; min-height: 0; padding: 0.3rem 0.6rem; }
  .controls { gap: 0.4rem; margin: 0.6rem 0; }
  .controls button { padding: 0.85em 0.7em; }
  .boards { gap: 0.8rem; }
  .boards.battle .board-wrap:last-child { order: -1; }
  .topbar { padding: max(0.5rem, env(safe-area-inset-top)) 0.5rem 0.5rem; gap: 0.3rem; }
  .topbar button { font-size: 0.4rem; padding: 0.7em 0.45em; box-shadow: 2px 2px 0 #000; }
  .toggles { gap: 0.25rem; }
  .logo-sm { display: none; }
  .board-wrap { padding: 0.45rem 0.3rem; border-width: 4px; }
  .grid { --gap: 2px; }
  .fight-bar { gap: 0.5rem; }
  .fight-mid { min-width: 5.5rem; }
  .hp { height: 16px; }
  .card-actions { flex-direction: column; }
  .help-text { font-size: 1.3rem; }
  .stats-panels { grid-template-columns: 1fr; }
  .stats-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-tiles .hud-item strong { font-size: 0.62rem; }
  .stats-metrics { column-gap: 0.5rem; }
  .stats-metrics dt { font-size: 0.38rem; }
  .stats-actions button { flex: 1 1 130px; }
}
/* Phones held sideways: shrink the HUD so a board fits on screen. */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { position: static; }
  .fight-bar { margin-bottom: 0.4rem; }
  .timer { font-size: 1.1rem; }
  .hp { height: 14px; }
  .hud { margin-bottom: 0.5rem; }
  .hud-item { padding: 0.25rem; }
  .hud-item strong { font-size: 0.7rem; margin-top: 0.2rem; }
  .grid.arcade { max-width: min(340px, calc(100vh - 80px)); }
  .grid.standard { max-width: min(440px, calc(100vh - 40px)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  .press-start { opacity: 1; }
}
