:root {
  --bg: #eef3f7; --card: #ffffff; --ink: #14212b; --muted: #5b6b78; --line: #d3dde5;
  --navy: #0b3a5b; --accent: #1b6ca8; --accent-ink: #fff;
  --water: #cfe3f1; --water-2: #bcd7ea; --ship: #6b7b88; --hit: #d64545; --miss: #ffffff;
  --sunk: #7a1f1f; --good: #1f8a4c; --warn: #b8741a; --sel: #f2b705;
  --cell: min(8.2vw, 36px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1620; --card: #16222e; --ink: #e6eef5; --muted: #93a5b4; --line: #2a3b4a;
    --navy: #0a2b44; --accent: #4aa3e0; --accent-ink: #06121b;
    --water: #1d3b52; --water-2: #234861; --ship: #8fa1b0; --miss: #e6eef5;
    --sunk: #9b3030; --good: #4cc47f; --warn: #e0a24a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
header#top { background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.2rem; }
#nav { display: flex; gap: 12px; align-items: center; font-size: .92rem; }
#nav a, #nav button { color: #fff; }
main { max-width: 980px; margin: 0 auto; padding: 16px; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
button, .btn { font: inherit; padding: 7px 14px; border-radius: 7px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; text-decoration: none; display: inline-block; }
button.secondary, .btn.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; border-color: var(--hit); color: var(--hit); }
#nav button { background: transparent; border-color: rgba(255,255,255,.5); color: #fff; padding: 4px 10px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, .cell:focus-visible { outline: 3px solid var(--sel); outline-offset: 1px; }
input[type=text], input[type=password], select { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--ink); min-width: 0; }
label { display: block; margin: 8px 0 3px; font-size: .9rem; color: var(--muted); }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; color: var(--ink); }
.form { max-width: 360px; }
.err { color: var(--hit); margin: 8px 0 0; min-height: 1.2em; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid var(--line); }
.badge.turn { background: var(--good); border-color: var(--good); color: #fff; }
.badge.wait { color: var(--muted); }
.badge.alert { background: var(--warn); border-color: var(--warn); color: #fff; }
.game-link { font-weight: 600; color: var(--accent); text-decoration: none; }
.empty { color: var(--muted); font-style: italic; margin: 4px 0; }

/* boards */
.boards { display: flex; gap: 28px; flex-wrap: wrap; justify-content: center; }
.boardwrap h3 { text-align: center; }
.board { display: grid; grid-template-columns: calc(var(--cell) * .7) repeat(10, var(--cell)); grid-template-rows: calc(var(--cell) * .7) repeat(10, var(--cell)); user-select: none; touch-action: manipulation; }
.lbl { display: flex; align-items: center; justify-content: center; font-size: .72rem; color: var(--muted); }
.cell { position: relative; background: var(--water); border: 1px solid var(--water-2); display: flex; align-items: center; justify-content: center; }
.cell.ship { background: var(--ship); border-color: var(--ship); }
.cell.clickable { cursor: crosshair; }
.cell.clickable:hover { background: var(--water-2); }
.cell.preview { background: var(--good); opacity: .75; }
.cell.preview.bad { background: var(--hit); }
.cell.selected { outline: 3px solid var(--sel); outline-offset: -3px; }
.cell .peg { width: 38%; height: 38%; border-radius: 50%; }
.cell.miss .peg { background: var(--miss); border: 1px solid var(--ship); }
.cell.hit .peg { background: var(--hit); width: 55%; height: 55%; }
.cell.hit { background: color-mix(in srgb, var(--hit) 25%, var(--water)); }
.cell.ship.hit { background: var(--sunk); }
.cell.sunk { background: var(--sunk); border-color: var(--sunk); }
.cell.sunk .peg { background: #fff; width: 30%; height: 30%; }
.cell.reveal { background: color-mix(in srgb, var(--ship) 55%, var(--water)); }
.cell.reveal.hit { background: var(--sunk); }
.status { font-size: 1.1rem; font-weight: 600; text-align: center; margin: 4px 0 14px; }
.status.mine { color: var(--good); }
.shiplist { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.chip { font-size: .8rem; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); }
.chip.dead { text-decoration: line-through; color: var(--muted); background: color-mix(in srgb, var(--hit) 15%, transparent); }
.chip.sel { border-color: var(--sel); box-shadow: 0 0 0 2px var(--sel); }
.chip.placed { border-color: var(--good); }
button.chip { background: var(--card); color: var(--ink); cursor: pointer; padding: 4px 10px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 12px 0; }
#toast { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); background: #14212b; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; z-index: 10; }
#toast.show { opacity: 1; }
.log { max-height: 180px; overflow: auto; font-size: .88rem; margin: 0; padding-left: 18px; }
@media (max-width: 520px) { :root { --cell: 7.6vw; } main { padding: 10px; } .boards { gap: 16px; } }

/* fire bar sits between the boards on narrow screens, below them on wide ones */
.boards .fire-bar { flex: 1 1 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 2px 0; }
.fire-bar > button { min-width: 220px; padding: 11px 20px; font-size: 1.05rem; }
.b-enemy { order: 1; } .fire-bar { order: 2; } .b-own { order: 3; }
@media (min-width: 900px) { .b-own { order: 2; } .fire-bar { order: 3; } }
.queued-note { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; font-size: .9rem; }
.queued-note button { padding: 3px 10px; }
.cell.queued { outline: 3px dashed var(--sel); outline-offset: -3px; }
