/* Sea Battle, calm harbour: pale sea squares in a deep navy frame, slate ships, coral hits. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #f0ede6;
  --card: #fffdf8;
  --ink: #1f2228;
  --muted: #737780;
  --line: #ded9ce;
  --sea: #d7e9ef;
  --sea-2: #cbe1e9;
  --grid: rgba(35, 80, 104, .16);
  --frame: #21445a;
  --ship: #5f707c;
  --ship-hi: #8795a0;
  --ship-lo: #46545e;
  --hit: #e4573d;
  --hit-lo: #b13a25;
  --sunk: #a9412f;
  --miss: rgba(33, 68, 90, .5);
  --water: rgba(33, 68, 90, .2);
  --gold: #ffc94d;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #ffc94d;
  --tut-accent-ink: #1f2228;
  --tut-bubble: #fffdf8;
  --tut-ink: #1f2228;
  --tut-muted: #737780;
  --tut-dim: rgba(16, 34, 46, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- bar ---------- */
.app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 1000px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
}
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 60px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; padding: 12px 2px; }
.back:hover, .back:focus-visible { color: var(--ink); }
.bar-actions { display: flex; gap: 8px; }

.btn {
  min-height: 44px; min-width: 44px; padding: 0 18px; border-radius: 22px;
  border: 0; background: var(--card); color: var(--ink);
  font-weight: 650; cursor: pointer; box-shadow: 0 1px 2px rgba(31, 34, 40, .1), 0 0 0 1px var(--line);
  transition: transform .12s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.icon { padding: 0; width: 44px; font-size: 22px; line-height: 1; letter-spacing: .04em; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--card); box-shadow: none; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled, .row:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .cell:focus-visible, .seg button:focus-visible, .row:focus-visible, .link:focus-visible, .chip:focus-visible, .mini-btn:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}

/* ---------- game ---------- */
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px; padding-bottom: 12px;
}
.turn {
  justify-self: center; display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 16px; border-radius: 999px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line); font-weight: 650; font-size: 16px; min-height: 40px;
}
.turn.thinking #turn-text::after { content: ''; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.flag { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.flag.you { background: radial-gradient(circle at 35% 30%, #ff9a84, var(--hit) 60%); }
.flag.cpu { background: radial-gradient(circle at 35% 30%, #93a2ad, var(--ship) 60%); }
.flag.none { background: var(--line); }
.toast {
  justify-self: center; min-height: 24px; font-size: 15px; color: var(--muted); text-align: center;
  opacity: 0; transform: translateY(4px); transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }
.toast.good { color: var(--hit-lo); font-weight: 650; }

/* ---------- the two seas ---------- */
/* Portrait: the big sea on top, the small one under it. b = big side, the small one is 0.42 b. */
.stage {
  min-height: 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  --b: min(100%, 560px);
}
@supports (container-type: size) {
  .stage { container-type: size; --b: min(100cqw, (100cqh - 70px) / 1.42, 560px); }
}
.sea { display: flex; flex-direction: column; gap: 5px; }
.sea.big { width: var(--b); }
.sea.mini { width: calc(var(--b) * .42); }
.sea-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; padding: 0 2px; }
.sea-title { font-size: 13px; font-weight: 650; color: var(--muted); white-space: nowrap; }
.frame {
  position: relative; display: block; width: 100%; aspect-ratio: 1;
  padding: 2.4%; border-radius: 12px; border: 0;
  background: linear-gradient(160deg, #2b5770, var(--frame));
  box-shadow: 0 5px 0 #152d3b, 0 12px 24px rgba(31, 34, 40, .18);
}
.sea.mini .frame { border-radius: 8px; padding: 3%; box-shadow: 0 3px 0 #152d3b, 0 8px 16px rgba(31, 34, 40, .14); }
.mini-btn { cursor: pointer; transition: transform .15s; }
.mini-btn:active { transform: scale(.97); }
@media (hover: hover) { .mini-btn:hover { transform: translateY(-2px); } }
.grid {
  position: relative; display: grid; width: 100%; height: 100%;
  grid-template-columns: repeat(10, minmax(0, 1fr)); grid-template-rows: repeat(10, minmax(0, 1fr));
  background: linear-gradient(160deg, var(--sea), var(--sea-2));
  border-radius: 4px; overflow: hidden;
}
.ships { position: absolute; inset: 2.4%; pointer-events: none; }
.sea.mini .ships { inset: 3%; }

.cell {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 0;
  border: 0; padding: 0; margin: 0; background: transparent;
  box-shadow: inset -1px -1px 0 var(--grid);
}
.grid .cell:nth-child(10n) { box-shadow: inset 0 -1px 0 var(--grid); }
.grid .cell:nth-child(n+91) { box-shadow: inset -1px 0 0 var(--grid); }
.grid .cell:nth-child(100) { box-shadow: none; }
button.cell.aim { cursor: crosshair; }
@media (hover: hover) { button.cell.aim:hover { background: rgba(255, 255, 255, .45); } }
button.cell.aim:active { background: rgba(255, 201, 77, .45); }
.cell::before { content: ''; border-radius: 50%; }
.cell.miss::before { width: 26%; height: 26%; background: var(--miss); }
.cell.water::before { width: 16%; height: 16%; background: var(--water); }
.cell.hit::before, .cell.sunk::before {
  width: 58%; height: 58%; z-index: 2;
  background: radial-gradient(circle at 38% 34%, #ffb19f, var(--hit) 55%, var(--hit-lo));
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .55);
}
.cell.sunk { background: rgba(169, 65, 47, .28); }
.cell.sunk::before { width: 44%; height: 44%; box-shadow: none; background: radial-gradient(circle at 38% 34%, #e98f7c, var(--sunk) 60%); }
.cell.last::after {
  content: ''; position: absolute; inset: 8%; border-radius: 50%; z-index: 3; pointer-events: none;
  box-shadow: 0 0 0 2px var(--gold); animation: ping 1.2s ease-out 2;
}
.sea.mini .cell.last::after { inset: -10%; box-shadow: 0 0 0 1.5px var(--gold); }
@keyframes ping { 0% { transform: scale(.6); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }
.cell.splash::before { animation: splash .35s ease-out; }
@keyframes splash { from { transform: scale(2.2); opacity: .2; } to { transform: scale(1); opacity: 1; } }
.sea.mini .cell { box-shadow: none; }

/* Ships (your fleet, and enemy ships once sunk). Positioned in % of the grid. */
.ship {
  position: absolute; border-radius: 999px; z-index: 1;
  background: linear-gradient(180deg, var(--ship-hi), var(--ship) 45%, var(--ship-lo));
  box-shadow: inset 0 0 0 1.5px rgba(0, 0, 0, .18), 0 2px 3px rgba(0, 0, 0, .22);
  transition: left .18s, top .18s, width .18s, height .18s, box-shadow .15s;
}
.ship.v { background: linear-gradient(90deg, var(--ship-hi), var(--ship) 45%, var(--ship-lo)); }
.ship.enemy { background: none; box-shadow: inset 0 0 0 2px var(--sunk); }
.ship.ghost { background: none; box-shadow: inset 0 0 0 2px rgba(33, 68, 90, .45); border: 0; }
.ship.down { opacity: .55; }
.ship.picked { box-shadow: 0 0 0 3px var(--gold), 0 4px 8px rgba(0, 0, 0, .3); }
.sea.mini .ship { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18); }

/* Enemy ships still afloat, as small hulls. */
.strip { display: inline-flex; align-items: center; gap: 4px; }
.strip i { display: block; height: 7px; border-radius: 4px; background: var(--ship); }
.strip i.gone { background: var(--line); }
.chip {
  min-height: 30px; padding: 0 10px; border-radius: 15px; border: 0; cursor: pointer;
  background: var(--card); box-shadow: 0 0 0 1px var(--line); font-size: 13px; font-weight: 650; white-space: nowrap;
}
.chip:active { transform: scale(.96); }

/* Wide screens: the seas side by side. */
@media (min-aspect-ratio: 5/4) {
  .stage { flex-direction: row; align-items: center; gap: 22px; --b: min(100%, 520px); }
  @supports (container-type: size) {
    .stage { --b: min(100cqh - 30px, (100cqw - 22px) / 1.42, 560px); }
  }
  .sea.mini { align-self: center; }
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(31, 34, 40, .36);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(240, 237, 230, .5); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet, .card {
  background: var(--card); color: var(--ink);
  width: 100%; max-width: 440px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  overflow: auto; overscroll-behavior: contain;
  border-radius: 24px; padding: 8px 20px 20px;
  box-shadow: 0 20px 50px rgba(31, 34, 40, .22);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .overlay { align-items: center; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.row {
  display: block; width: 100%; text-align: left; min-height: 50px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; font-weight: 600; cursor: pointer;
}
.group { padding: 12px 0 4px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--bg); }
.seg button {
  flex: 1 1 0; min-height: 44px; border: 0; border-radius: 12px; background: transparent;
  font-weight: 600; cursor: pointer; color: var(--muted); transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(31, 34, 40, .16); }
.menu-sheet .row:first-of-type { border-top: 1px solid var(--line); }
.menu-sheet #menu-help { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet .btn.wide { margin-top: 16px; }

.over-card { max-width: 340px; text-align: center; padding: 24px 22px 14px; }
.over-mark { display: flex; justify-content: center; margin: 4px 0 14px; }
.over-mark .hull { display: block; width: 120px; height: 22px; border-radius: 999px; background: linear-gradient(180deg, var(--ship-hi), var(--ship) 45%, var(--ship-lo)); }
.over-mark .hull.lost { background: linear-gradient(180deg, #ef9b88, var(--hit) 50%, var(--hit-lo)); }
.over-title { font-size: 28px; font-weight: 800; }
.over-sub { color: var(--muted); margin: 4px 0 20px; }
.link { display: block; margin: 8px auto 0; min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }

.help-sheet { max-width: 560px; }
.help-body { padding-bottom: 6px; }
.help-body h3 { font-size: 16px; margin: 18px 0 4px; }
.help-body p, .help-body li { font-size: 15px; margin: 4px 0; }
.help-body ul { padding-left: 20px; }
.fine { font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- small and landscape screens ---------- */
@media (max-width: 380px) {
  .app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .btn { padding: 0 14px; }
  .back { font-size: 13px; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 480px) {
  .bar { min-height: 50px; }
  .game { gap: 6px; padding-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* ---------- online (a table with a friend: tables.js) ---------- */
/* a short notice (connection lost, the table was updated, the friend left) floats just under the turn pill,
   over the seas' top edge, so the board never moves */
.turn { position: relative; }
.turn .net-note { position: absolute; left: 50%; top: calc(100% + 4px); transform: translateX(-50%); z-index: 6; width: max-content; max-width: min(88vw, 360px);
  padding: 4px 12px; border-radius: 12px; background: var(--ink); color: var(--card); font-size: 12.5px; font-weight: 700; line-height: 1.3; text-align: center;
  white-space: normal; box-shadow: 0 4px 14px rgba(31, 34, 40, .3); pointer-events: none; animation: fade .25s ease-out; }
.turn .net-note[hidden] { display: none; }
/* Ready: sends your fleet (only while you arrange it) */
.btn.ready { justify-self: center; min-width: min(100%, 220px); min-height: 48px; font-size: 17px; }
body.is-online #btn-new { display: none; }
/* one divider above the online rows (moved from How to play) */
.menu-sheet #menu-online, .menu-sheet #menu-leave { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet #menu-help { margin-top: 0; border-top: 0; }
.over-card #over-leave { margin-top: 8px; }
