/* SINK THE SHIPS - Copyright (c) 2026 Jan-Maurice Dahlmanns - MIT License (see LICENSE) */

:root {
  --bg: #061523;
  --bg2: #0a1d30;
  --panel: #0c2236;
  --panel2: #10293f;
  --line: #1a3b57;
  --line2: #255179;
  --text: #dbe9f5;
  --muted: #7f9ab3;
  --water: #0f3150;
  --water2: #0b2741;
  --water-hi: #174469;
  --p1: #39c2ef;
  --p2: #f3b23c;
  --hit: #ff4d3d;
  --miss: #a9cbe6;
  --hull: #8ea2b5;
  --hull-dark: #566b7f;
  --ok: #3ccf8e;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
}
/* faint chart grid behind everything */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(57, 194, 239, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57, 194, 239, .045) 1px, transparent 1px);
  background-size: 44px 44px;
}
a { color: var(--p1); }
h1, h2, h3 { line-height: 1.2; }
.noscript { text-align: center; padding: 40px 16px; }

.app { min-height: 100vh; min-height: 100dvh; }
.screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.flip { transform: rotate(180deg); }

/* ------------------------------------------------------------------ controls */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid var(--line2);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: #143552; border-color: #2f6795; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--p1); border-color: var(--p1); color: #03111c; }
.btn.primary:hover { background: #63d1f6; border-color: #63d1f6; }
.btn.primary:disabled:hover { background: var(--p1); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(57, 194, 239, .08); }
.btn.danger { background: transparent; border-color: #8f302b; color: #ff8a80; }
.btn.danger:hover { background: rgba(255, 77, 61, .12); }
.btn.small { min-height: 34px; padding: 5px 11px; font-size: .86rem; gap: 6px; }
.btn.wide { width: 100%; }
.btn.big { flex-direction: column; align-items: flex-start; gap: 0; min-height: 60px; padding: 10px 18px; text-align: left; }
.btn.big span { font-size: 1.05rem; }
.btn.big small { font-weight: 400; font-size: .82rem; opacity: .75; }
.btn .ico, .icon-btn .ico { width: 18px; height: 18px; flex: none; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 1px solid var(--line2);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { border-color: #2f6795; background: #143552; }

kbd {
  font-family: var(--mono);
  font-size: .76em;
  line-height: 1.3;
  padding: 0 5px;
  border: 1px solid var(--line2);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .25);
  color: var(--muted);
  white-space: nowrap;
}
.btn.primary kbd { color: inherit; border-color: rgba(0, 0, 0, .3); background: rgba(0, 0, 0, .08); }

:focus { outline: none; }
.kbd .btn:focus, .kbd .icon-btn:focus, .kbd .shipbtn:focus, .kbd a:focus { outline: 2px solid #fff; outline-offset: 2px; }
.kbd .choice:focus-within, .kbd .check:focus-within { outline: 2px solid #fff; outline-offset: 2px; }
input:focus-visible, select:focus-visible { outline: 2px solid var(--p1); outline-offset: 1px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.eyebrow { margin: 0; font-size: .74rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); font-size: .88rem; }
.center { text-align: center; }
.pn.p1 { color: var(--p1); }
.pn.p2 { color: var(--p2); }

/* ------------------------------------------------------------------ title */

.title { align-items: center; justify-content: center; gap: 4px; padding: 28px 16px 18px; text-align: center; }
.title-art { width: min(360px, 82vw); height: auto; overflow: hidden; }
.ta-hull { fill: #20405d; }
.ta-deck { fill: #2c5577; }
.ta-line { fill: none; stroke: #4b7aa2; stroke-width: 3; stroke-linecap: round; }
.ta-wave { fill: none; stroke: var(--p1); stroke-width: 2.5; opacity: .75; animation: wave 4s linear infinite; }
.ta-wave.two { opacity: .35; animation-duration: 6.5s; }
@keyframes wave { to { transform: translateX(-60px); } }
.logo { display: flex; flex-direction: column; margin: 4px 0 0; line-height: .95; font-weight: 900; letter-spacing: .14em; }
.logo span:first-child { font-size: clamp(46px, 9vw, 86px); color: #fff; }
.logo span:last-child { font-size: clamp(19px, 3.8vw, 33px); letter-spacing: .34em; color: var(--p1); margin-left: .34em; }
.tagline { margin: 8px 0 20px; color: var(--muted); }
.menu { display: flex; flex-direction: column; gap: 10px; width: min(380px, 100%); }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu.row { flex-direction: row; flex-wrap: wrap; justify-content: center; width: auto; }
.foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin-top: auto; padding-top: 26px; font-size: .8rem; color: var(--muted); }
.foot a { color: var(--muted); }
.foot a:hover { color: var(--text); }

/* ------------------------------------------------------------------ setup & gate */

.setup, .gate { align-items: center; justify-content: center; padding: 24px 16px; }
.setup form { width: min(640px, 100%); }
.setup h2 { margin: 0 0 16px; font-size: 1.5rem; letter-spacing: .04em; }
fieldset { margin: 0 0 18px; padding: 0; border: 0; min-width: 0; }
legend { margin-bottom: 8px; padding: 0; font-size: .74rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.choices { display: grid; gap: 8px; }
.choice, .check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg2);
  cursor: pointer;
}
.check + .check { margin-top: 8px; }
.choice:has(input:checked) { border-color: var(--p1); background: rgba(57, 194, 239, .08); }
.choice > span, .check > span { display: flex; flex-direction: column; gap: 2px; }
.choice small, .check small { color: var(--muted); font-size: .84rem; }
.choice em { display: inline-flex; align-items: center; gap: 4px; font-style: normal; font-size: .8rem; color: var(--ok); }
.choice em .ico { width: 14px; height: 14px; }
input[type="radio"], input[type="checkbox"] { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--p1); }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .84rem; font-weight: 700; color: var(--muted); }
.field.p1 > span { color: var(--p1); }
.field.p2 > span { color: var(--p2); }
input[type="text"], select {
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line2);
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text);
  font: inherit;
}
.field.p1 input:focus { border-color: var(--p1); }
.field.p2 input:focus { border-color: var(--p2); outline-color: var(--p2); }
input[type="range"] { width: 180px; max-width: 50%; accent-color: var(--p1); }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.note { color: var(--p2); font-size: .88rem; }

.gate { --accent: var(--p1); }
.gate.p2 { --accent: var(--p2); }
.gate-card { display: flex; flex-direction: column; align-items: center; gap: 6px; width: min(480px, 100%); text-align: center; border-top: 3px solid var(--accent); }
.gate-card h2 { margin: 2px 0; font-size: 1.45rem; }
.gate-card p { margin: 4px 0; }
.gate-icon .ico { width: 54px; height: 54px; color: var(--accent); }
.gate .menu { margin-top: 12px; }
.gate .btn.primary, .place .btn.primary { border-color: var(--accent); background: var(--accent); }
.gate .btn.primary:hover, .place .btn.primary:not(:disabled):hover { filter: brightness(1.12); }
.ok { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); }
.ok .ico { width: 18px; height: 18px; }

/* ------------------------------------------------------------------ top bar */

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(6, 21, 35, .9);
}
.bar h2 { flex: 1; min-width: 0; margin: 0; overflow: hidden; font-size: 1rem; font-weight: 700; letter-spacing: .05em; white-space: nowrap; text-overflow: ellipsis; }
.bar .lvl { margin-left: 6px; font-size: .85em; color: var(--p1); }
.bar-note { display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; color: var(--muted); white-space: nowrap; }
.bar-note .ico { width: 18px; height: 18px; }
.bar-note.warn { font-weight: 700; color: var(--p2); }
.place.p2 .bar-note.warn { color: var(--p1); }

/* ------------------------------------------------------------------ boards */

.board {
  --gap: 2px;
  position: relative;
  display: grid;
  grid-template-columns: .62fr repeat(10, 1fr);
  grid-template-rows: .62fr repeat(10, 1fr);
  gap: var(--gap);
  width: var(--gs, 360px);
  height: var(--gs, 360px);
  font-size: max(9px, calc(var(--gs, 360px) / 30));
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.board .lab { display: grid; place-items: center; font-family: var(--mono); font-weight: 600; color: var(--muted); }
.board .cell { position: relative; border-radius: 2px; background: var(--water); }
.board .cell.miss { background: var(--water2); }

/* hulls: ships, placement preview */
.cell.ship::before, .cell.ghost::before {
  content: '';
  position: absolute;
  z-index: 1;
  background: var(--hull);
}
/* each segment reaches over the gap to the next one, so a hull reads as one piece */
.cell.h::before { top: 19%; bottom: 19%; left: 0; right: calc(var(--gap) * -1); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .16), inset 0 -2px 0 rgba(0, 0, 0, .25); }
.cell.v::before { left: 19%; right: 19%; top: 0; bottom: calc(var(--gap) * -1); box-shadow: inset 2px 0 0 rgba(255, 255, 255, .16), inset -2px 0 0 rgba(0, 0, 0, .25); }
.cell.h.bow::before { left: 7%; border-radius: 50% 0 0 50%; }
.cell.h.stern::before { right: 9%; border-radius: 0 22% 22% 0; }
.cell.v.bow::before { top: 7%; border-radius: 50% 50% 0 0; }
.cell.v.stern::before { bottom: 9%; border-radius: 0 0 22% 22%; }
.cell.ship.sunk::before { background: #6a2724; box-shadow: none; }
.cell.ship.lifted::before { opacity: .3; }
.cell.ghost::before { z-index: 2; background: color-mix(in srgb, var(--accent, var(--p1)) 60%, transparent); box-shadow: none; }
.cell.ghost.bad::before { background: rgba(255, 77, 61, .55); }

/* shot markers */
.cell.miss::after, .cell.hit::after { content: ''; position: absolute; z-index: 3; border-radius: 50%; }
.cell.miss::after { inset: 33%; border: max(1.5px, calc(var(--gs, 360px) / 240)) solid var(--miss); opacity: .8; }
.cell.hit::after { inset: 25%; background: var(--hit); box-shadow: 0 0 0 2px rgba(255, 77, 61, .25), 0 0 10px 2px rgba(255, 77, 61, .55); }
.cell.ship.sunk.hit::after { inset: 32%; background: #e04a3c; box-shadow: none; }

.cell.last { outline: 2px dashed rgba(255, 255, 255, .6); outline-offset: -2px; z-index: 4; }
.cell.cursor { outline: 2px solid var(--accent, var(--p1)); outline-offset: -1px; z-index: 5; }

.board.place .cell { cursor: pointer; }
@media (hover: hover) {
  .board.place .cell:hover { background: var(--water-hi); }
  .station.active .board.target .cell:not(.miss):not(.hit):hover { background: var(--water-hi); outline: 2px solid var(--accent); outline-offset: -1px; z-index: 5; }
}
.station.active .board.target .cell:not(.miss):not(.hit) { cursor: crosshair; }

/* effects */
.fx { position: absolute; inset: 0; z-index: 6; border-radius: 50%; pointer-events: none; }
.fx-miss { border: 2px solid var(--miss); animation: fx-ripple .8s ease-out forwards; }
.fx-hit { background: #ffd27a; box-shadow: 0 0 14px 6px #ff5a2a; animation: fx-blast .7s ease-out forwards; }
.fx-sunk { background: #ffb347; box-shadow: 0 0 22px 10px #ff3d2e; animation: fx-blast 1.1s ease-out forwards; }
@keyframes fx-ripple { from { transform: scale(.2); opacity: 1; } to { transform: scale(2.2); opacity: 0; } }
@keyframes fx-blast { 0% { transform: scale(.2); opacity: 1; } 40% { opacity: .95; } 100% { transform: scale(2); opacity: 0; } }
.board.shake { animation: shake .5s ease-out; }
@keyframes shake {
  20% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, 1px); }
  80% { transform: translate(2px, -1px); }
}
.reduced .fx { display: none; }
.reduced .board.shake, .reduced .ta-wave { animation: none; }
@media (prefers-reduced-motion: reduce) { .ta-wave { animation: none; } }

/* fleet status (public: afloat / sunk) */
.fleet-mini { display: inline-flex; flex-wrap: nowrap; align-items: center; gap: 6px; }
.fm { position: relative; display: inline-flex; gap: 1px; }
.fm i { width: 8px; height: 8px; border-radius: 1px; background: var(--hull); }
.fm.sunk i { background: var(--hit); opacity: .45; }
.fm.sunk::after { content: ''; position: absolute; left: -2px; right: -2px; top: 50%; height: 2px; background: #ff8a80; transform: translateY(-50%) rotate(-10deg); }

/* ------------------------------------------------------------------ placement */

.place { --accent: var(--p1); }
.place.p2 { --accent: var(--p2); }
.place-body {
  --gs: max(240px, min(calc(100vw - 400px), calc(100vh - 120px), 620px));
  --gs: max(240px, min(calc(100vw - 400px), calc(100dvh - 120px), 620px));
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 16px;
}
.dock { display: flex; flex-direction: column; gap: 12px; width: 320px; padding: 16px; }
.dock h3 { margin: 0; font-size: .74rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.shiplist { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.shipbtn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.shipbtn:hover { border-color: var(--line2); }
.shipbtn.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.shipbtn .sname { flex: 1; font-weight: 600; }
.shipbtn .state { display: inline-grid; width: 18px; color: var(--ok); }
.shipbtn .state .ico { width: 18px; height: 18px; }
.pips { display: inline-flex; gap: 2px; }
.pips i { width: 12px; height: 10px; border-radius: 2px; background: var(--hull); }
.shipbtn.placed .pips i { background: var(--hull-dark); }
.shipbtn.sel .pips i { background: var(--accent); }
.dock-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.hint { margin: 0; font-size: .84rem; color: var(--muted); }

@media (max-width: 860px), (orientation: portrait) {
  .place-body {
    --gs: max(240px, min(calc(100vw - 32px), calc(100vh - 360px), 560px));
    --gs: max(240px, min(calc(100vw - 32px), calc(100dvh - 360px), 560px));
    flex-direction: column;
    justify-content: flex-start;
  }
  .dock { gap: 10px; width: min(100%, var(--gs) + 120px); padding: 12px; }
  .dock h3 { display: none; }
  .shiplist { gap: 4px; }
  .shipbtn { padding: 5px 10px; }
  .dock-actions { flex-wrap: nowrap; }
  .dock-actions .btn { flex: 1 1 auto; padding: 5px 8px; }
}

/* ------------------------------------------------------------------ battle */

.battle { height: 100vh; height: 100dvh; overflow: hidden; }
.arena { flex: 1; min-height: 0; display: grid; align-content: center; justify-content: center; gap: 12px; padding: 12px 16px 16px; }
.announce {
  grid-area: ann;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px 14px;
  min-height: 40px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  text-align: center;
  font-size: .95rem;
}
.announce #annTurn { color: var(--muted); }
.announce #annTurn:empty, .announce #annResult:empty { display: none; }
.coord { font-family: var(--mono); color: #fff; }
.t-miss, .t-hit, .t-sunk { font-style: normal; }
.t-miss { color: var(--miss); }
.t-hit { font-weight: 700; color: var(--hit); }
.t-sunk { font-weight: 800; letter-spacing: .03em; text-transform: uppercase; color: #ff7a6b; }

.station {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(var(--gs) + 22px);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  transition: border-color .2s, box-shadow .2s;
}
.station.p1 { --accent: var(--p1); grid-area: s1; }
.station.p2 { --accent: var(--p2); grid-area: s2; }
.station.own { --accent: var(--hull); grid-area: own; }
.station.target { --accent: var(--p1); grid-area: target; }
.station-head { display: flex; align-items: center; gap: 10px; min-height: 26px; min-width: 0; }
.pname { flex: none; max-width: 45%; overflow: hidden; font-weight: 800; letter-spacing: .04em; white-space: nowrap; text-overflow: ellipsis; color: var(--accent, var(--text)); }
.pstats { flex: 1; min-width: 0; overflow: hidden; font-size: .8rem; text-align: center; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); }
.station-head .fleet-mini { flex: 1; justify-content: flex-end; }
.turn-tag {
  flex: none;
  padding: 2px 9px;
  border: 1px solid var(--line2);
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.station.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 28px -8px var(--accent); }
.station.active .turn-tag { border-color: var(--accent); background: var(--accent); color: #03111c; }
.station.waiting .board-wrap { opacity: .62; filter: saturate(.7); }
.station.peeking .board-wrap { opacity: 1; filter: none; }
.station.own.under-fire { border-color: rgba(255, 77, 61, .7); box-shadow: 0 0 26px -10px var(--hit); }
.board-wrap { position: relative; transition: opacity .2s; }
.station-foot { display: flex; align-items: center; gap: 8px; min-height: 34px; }
.station-foot .fleet-mini { flex: 1; }
.fleet-label { flex: none; font-size: .7rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.peek-btn { flex: none; margin-left: auto; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
.station.peeking .peek-btn { border-color: var(--accent); background: var(--accent); color: #03111c; }
.peek-layer { position: absolute; inset: 0; z-index: 8; border-radius: 6px; background: var(--panel); }
.peek-layer[hidden] { display: none; }
.peek-layer .board { --accent: var(--hull); }
.peek-label {
  position: absolute;
  top: -32px;
  left: 50%;
  z-index: 9;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #03111c;
  font-size: .76rem;
  font-weight: 800;
  white-space: nowrap;
  transform: translateX(-50%);
}
.peek-label .ico { width: 16px; height: 16px; }

/* vs computer: own waters left, enemy waters right */
.battle.cpu .arena {
  --gs: min(calc(50vw - 50px), calc(100vh - 200px), 620px);
  --gs: min(calc(50vw - 50px), calc(100dvh - 200px), 620px);
  grid-template-columns: auto auto;
  grid-template-areas: "ann ann" "own target";
}
/* splitscreen side by side */
.battle.split .arena {
  --gs: min(calc(50vw - 50px), calc(100vh - 240px), 620px);
  --gs: min(calc(50vw - 50px), calc(100dvh - 240px), 620px);
  grid-template-columns: auto auto;
  grid-template-areas: "ann ann" "s1 s2";
}

/* portrait / narrow: stacked */
@media (orientation: portrait), (max-width: 760px) {
  .battle .arena { gap: 8px; padding: 8px; }
  .battle.cpu .arena {
    --gs: max(200px, min(calc(100vw - 40px), calc(50vh - 120px), 560px));
    --gs: max(200px, min(calc(100vw - 40px), calc(50dvh - 120px), 560px));
    grid-template-columns: auto;
    grid-template-areas: "ann" "target" "own";
  }
  .battle.split .arena {
    --gs: max(200px, min(calc(100vw - 40px), calc(50vh - 158px), 560px));
    --gs: max(200px, min(calc(100vw - 40px), calc(50dvh - 158px), 560px));
    grid-template-columns: auto;
    grid-template-areas: "s2" "ann" "s1";
  }
  .battle .station { gap: 6px; padding: 8px; width: calc(var(--gs) + 18px); }
  .battle .fleet-label { display: none; }
  .announce { min-height: 34px; padding: 5px 10px; font-size: .88rem; }
  .bar { min-height: 48px; padding: 5px 10px; }
}

/* tabletop: player 2 sits on the other side of the device */
.battle.split.tabletop .arena {
  --gs: max(200px, min(calc(100vw - 40px), calc(50vh - 158px), 560px));
  --gs: max(200px, min(calc(100vw - 40px), calc(50dvh - 158px), 560px));
  grid-template-columns: auto;
  grid-template-areas: "s2" "ann" "s1";
  gap: 8px;
  padding: 8px;
}
.battle.split.tabletop .station.p2 { transform: rotate(180deg); }
.battle.split.tabletop .fleet-label { display: none; }
@media (orientation: landscape) {
  .battle.split.tabletop .arena {
    --gs: max(200px, min(calc(100vw - 330px), calc(50vh - 92px), 560px));
    --gs: max(200px, min(calc(100vw - 330px), calc(50dvh - 92px), 560px));
  }
  .battle.split.tabletop .station {
    display: grid;
    grid-template-columns: auto minmax(180px, 250px);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "board head" "board ." "board foot";
    gap: 6px 14px;
    width: auto;
    padding: 8px;
  }
  .battle.split.tabletop .station-head { grid-area: head; flex-direction: column; align-items: flex-start; gap: 4px; }
  .battle.split.tabletop .pname { max-width: 100%; }
  .battle.split.tabletop .pstats { flex: none; text-align: left; }
  .battle.split.tabletop .board-wrap { grid-area: board; }
  .battle.split.tabletop .station-foot { grid-area: foot; flex-wrap: wrap; }
  .battle.split.tabletop .peek-btn { margin-left: 0; }
  .battle.split.tabletop .peek-label { top: auto; bottom: 4px; }
}

/* ------------------------------------------------------------------ result */

.over { align-items: center; gap: 18px; padding: 24px 16px; }
.over-head { text-align: center; }
.over-head h2 { margin: 4px 0; font-size: clamp(32px, 6vw, 54px); letter-spacing: .08em; text-transform: uppercase; }
.over-head p { margin: 0; color: var(--muted); }
.over.won h2 { color: var(--ok); }
.over.lost h2 { color: var(--hit); }
.reveal { --gs: min(calc(50vw - 60px), 420px); display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; }
.reveal .station { width: calc(var(--gs) + 22px); }
.reveal .station.winner { border-color: var(--ok); }
.reveal .pstats { margin: 0; text-align: left; }
@media (max-width: 760px) { .reveal { --gs: min(calc(100vw - 56px), 420px); } }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--ok); color: #03111c; font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; vertical-align: middle; }

/* ------------------------------------------------------------------ modals */

.modal-back { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(2, 9, 16, .8); }
.modal {
  width: min(620px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line2);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.modal.small { width: min(400px, 100%); }
.modal h2 { margin: 0 0 12px; font-size: 1.35rem; letter-spacing: .04em; }
.modal h3 { margin: 18px 0 6px; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.modal p { margin: 8px 0; }
.modal ul { margin: 6px 0; padding-left: 20px; }
.modal li { margin: 4px 0; }
.modal .menu { width: 100%; }
.modal .actions { margin-top: 20px; }
table.keys, table.stats { width: 100%; border-collapse: collapse; font-size: .88rem; }
.keys th, .keys td, .stats th, .stats td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.keys th, .stats thead th { font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.keys td:first-child { font-weight: 600; }
.keys .ico { width: 16px; height: 16px; vertical-align: -3px; }
.stats td { text-align: right; font-variant-numeric: tabular-nums; }
.stats thead th:not(:first-child) { text-align: right; }
.stats tbody th { font-weight: 600; }
.stats tr.beaten th { color: var(--ok); }
.stats th .ico { width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px; }
.progress { margin-bottom: 14px; }
.progress .meter { height: 10px; overflow: hidden; border: 1px solid var(--line); border-radius: 999px; background: var(--bg2); }
.progress .meter span { display: block; height: 100%; background: var(--ok); }
.progress p { margin: 8px 0 0; font-size: .9rem; color: var(--muted); }
.progress b { color: var(--text); }
.form { display: flex; flex-direction: column; gap: 8px; }
.form .check + .check { margin-top: 0; }
.form .field { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg2); }
.form .field > span { font-size: inherit; color: var(--text); }
.danger-zone { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.danger-zone small { flex: 1; min-width: 180px; color: var(--muted); }
pre.license { max-height: 220px; overflow: auto; margin: 6px 0 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); color: var(--muted); font: .74rem/1.45 var(--mono); white-space: pre-wrap; }
.legal { font-size: .88rem; }

@media (pointer: coarse) {
  .peek-btn kbd, .shipbtn kbd, .dock-actions kbd { display: none; }
}
@media (max-width: 520px) {
  .menu-grid, .names { grid-template-columns: 1fr; }
  .peek-btn kbd { display: none; }
  .fleet-mini { gap: 4px; }
  .fm i { width: 6px; height: 6px; }
  .station-head { gap: 6px; }
  .turn-tag { padding: 2px 7px; letter-spacing: .08em; }
  .modal { padding: 18px 16px; }
}
