:root {
  --bg: #f4f6f8; --fg: #1b2430; --muted: #66707d; --card: #ffffff; --line: #d6dce3;
  --sea: #dbeafe; --sea-line: #93b4e0; --ship: #334155; --hit: #dc2626; --miss: #64748b; --mark: #b8c4d1;
  --accent: #1d4ed8; --accent-fg: #fff; --ok: #15803d; --warn: #b45309; --preview: #86efac; --bad: #fca5a5;
  --cell: clamp(26px, 8.4vw, 40px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c; --fg: #e6ebf0; --muted: #94a0ad; --card: #161e27; --line: #2a3541;
    --sea: #12263f; --sea-line: #2a4a70; --ship: #cbd5e1; --hit: #f87171; --miss: #94a3b8; --mark: #34445a;
    --accent: #3b82f6; --preview: #166534; --bad: #7f1d1d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 16px; padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
main { max-width: 960px; margin: 0 auto; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 20px 0 8px; }
p { margin: 8px 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 12px 0; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--fg);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; min-height: 40px; text-decoration: none; display: inline-block;
}
button:disabled { opacity: .45; cursor: default; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.active { outline: 2px solid var(--accent); }
input[type=text] { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); width: 100%; }
.status { font-weight: 600; min-height: 1.5em; }
.status.mine { color: var(--ok); }
.status.wait { color: var(--warn); }
.hidden { display: none !important; }

/* Boards */
.boards { display: flex; flex-wrap: wrap; gap: 24px; justify-content: center; }
.board-wrap { flex: 0 0 auto; }
.board-title { text-align: center; font-weight: 600; margin-bottom: 6px; }
.grid {
  display: grid; grid-template-columns: var(--cell) repeat(10, var(--cell));
  grid-auto-rows: var(--cell); gap: 0; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.lbl { display: flex; align-items: center; justify-content: center; font-size: .8rem; color: var(--muted); }
.cell {
  background: var(--sea); border: 1px solid var(--sea-line); position: relative; margin: 0 0 -1px -1px;
}
.cell.ship { background: var(--ship); }
.cell.sunk { background: var(--hit); }
.cell.hit::after { content: ""; position: absolute; inset: 22%; background:
  linear-gradient(45deg, transparent 42%, var(--hit) 42%, var(--hit) 58%, transparent 58%),
  linear-gradient(-45deg, transparent 42%, var(--hit) 42%, var(--hit) 58%, transparent 58%); }
.cell.ship.hit::after, .cell.sunk.hit::after { --hit: #fff; }
.cell.miss::after { content: ""; position: absolute; inset: 38%; border-radius: 50%; background: var(--miss); }
.cell.mark::after { content: ""; position: absolute; inset: 42%; border-radius: 50%; background: var(--mark); }
.cell.preview { background: var(--preview); }
.cell.preview.bad { background: var(--bad); }
.cell.last { box-shadow: inset 0 0 0 2px var(--accent); }
.grid.clickable .cell:not(.hit):not(.miss):not(.mark) { cursor: crosshair; }
.grid.editing .cell { cursor: pointer; }

/* Palette */
.palette { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.palette button { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
.mini { display: inline-flex; gap: 1px; }
.mini i { width: 12px; height: 12px; background: var(--ship); display: inline-block; }
.fleet { display: flex; flex-wrap: wrap; gap: 6px 12px; justify-content: center; margin-top: 8px; min-height: 16px; }
.fleet .mini i { width: 9px; height: 9px; }
.fleet .dead i { background: var(--mark); }
.share { display: flex; gap: 8px; align-items: center; }
.share input { flex: 1; min-width: 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.lang-toggle { font-size: .9rem; }
.rules ol, .rules ul { padding-left: 22px; }
.rules li { margin: 4px 0; }
kbd { border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: .85em; }
