:root {
  --bg1: #06121f;
  --bg2: #0d2b45;
  --panel: rgba(10, 30, 50, 0.75);
  --line: rgba(90, 160, 220, 0.25);
  --accent: #38bdf8;
  --accent2: #f59e0b;
  --hit: #ef4444;
  --miss: #e2e8f0;
  --ship: #64748b;
  --ship-sunk: #7f1d1d;
  --ok: #22c55e;
  --cell: min(8.2vw, 44px);
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #dbeafe;
  background:
    radial-gradient(ellipse at 20% -10%, rgba(56,189,248,.18), transparent 55%),
    radial-gradient(ellipse at 90% 110%, rgba(245,158,11,.10), transparent 50%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
  min-height: 100vh;
  overflow-x: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 10px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

header { text-align: center; }

h1 {
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  letter-spacing: .35em;
  text-shadow: 0 0 18px rgba(56,189,248,.55);
  margin-bottom: 6px;
}

.banner {
  display: inline-block;
  padding: 5px 22px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: clamp(.72rem, 2.4vw, .95rem);
  border: 1px solid var(--line);
  background: var(--panel);
  transition: all .35s ease;
}
.banner.placement { color: var(--accent); box-shadow: 0 0 14px rgba(56,189,248,.35); }
.banner.player    { color: var(--ok);    box-shadow: 0 0 14px rgba(34,197,94,.45);  animation: pulse 1.4s infinite; }
.banner.enemy     { color: var(--hit);   box-shadow: 0 0 14px rgba(239,68,68,.45);  animation: pulse 1.4s infinite; }
.banner.over      { color: var(--accent2); box-shadow: 0 0 14px rgba(245,158,11,.45); }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

main#boards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 26px;
  width: 100%;
}

.board-wrap { text-align: center; }

.board-wrap h2 {
  font-size: clamp(.85rem, 2.6vw, 1.1rem);
  letter-spacing: .25em;
  text-transform: uppercase;
  color: #93c5fd;
  margin-bottom: 8px;
}

.board-wrap.active-target h2 { color: var(--ok); text-shadow: 0 0 12px rgba(34,197,94,.6); }
.board-wrap.under-fire h2  { color: var(--hit); text-shadow: 0 0 12px rgba(239,68,68,.6); }

.grid-frame {
  position: relative;
  padding: calc(var(--cell) * .72) 0 0 calc(var(--cell) * .72);
  display: inline-block;
}

.labels {
  position: absolute;
  display: grid;
  color: #7dd3fc;
  font-size: calc(var(--cell) * .34);
  font-weight: 600;
  opacity: .8;
}
.col-labels {
  top: 0; left: calc(var(--cell) * .72);
  grid-template-columns: repeat(10, var(--cell));
  width: calc(var(--cell) * 10);
  height: calc(var(--cell) * .72);
}
.row-labels {
  top: calc(var(--cell) * .72); left: 0;
  grid-template-rows: repeat(10, var(--cell));
  height: calc(var(--cell) * 10);
  width: calc(var(--cell) * .72);
}
.labels span { display: flex; align-items: center; justify-content: center; }

.grid {
  display: grid;
  grid-template-columns: repeat(10, var(--cell));
  grid-template-rows: repeat(10, var(--cell));
  gap: 2px;
  background: rgba(3, 12, 24, .85);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5), inset 0 0 40px rgba(14, 60, 100, .35);
}

.cell {
  position: relative;
  background: linear-gradient(145deg, #0e3a5c, #0a2740);
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.cell:nth-child(odd) { background: linear-gradient(145deg, #0d3554, #092238); }

#enemy-grid .cell:not(.hit):not(.miss):hover {
  background: #155e8a;
  transform: scale(1.08);
  z-index: 2;
  box-shadow: 0 0 10px rgba(56,189,248,.7);
}
.grid.locked .cell { cursor: not-allowed; }
.grid.locked .cell:hover { transform: none; box-shadow: none; background: linear-gradient(145deg, #0e3a5c, #0a2740); }

/* placement preview */
.cell.preview-ok   { background: rgba(34,197,94,.55) !important; box-shadow: inset 0 0 8px rgba(34,197,94,.9); }
.cell.preview-bad  { background: rgba(239,68,68,.55) !important; box-shadow: inset 0 0 8px rgba(239,68,68,.9); }

/* ships on player board */
.cell.ship {
  background: linear-gradient(145deg, #8b9bb0, #55677e);
  box-shadow: inset 0 0 6px rgba(0,0,0,.5), 0 0 4px rgba(148,163,184,.4);
}
.cell.ship::after {
  content: "";
  position: absolute; inset: 22%;
  border-radius: 3px;
  background: rgba(15, 35, 55, .55);
}

/* hits & misses */
.cell.hit  { background: #3f1214 !important; cursor: default; }
.cell.miss { background: #0a2740 !important; cursor: default; }

.cell .peg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.cell.hit .peg::before {
  content: "";
  width: 46%; height: 46%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fca5a5, #dc2626 60%, #7f1d1d);
  box-shadow: 0 0 10px rgba(239,68,68,.9);
  animation: pegIn .3s ease;
}
.cell.miss .peg::before {
  content: "";
  width: 30%; height: 30%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #cbd5e1 70%);
  box-shadow: 0 0 6px rgba(226,232,240,.7);
  animation: pegIn .3s ease;
}
@keyframes pegIn { from { transform: scale(0); } to { transform: scale(1); } }

.cell.sunk {
  background: linear-gradient(145deg, #991b1b, #450a0a) !important;
  animation: sunkFlash .6s ease;
}
@keyframes sunkFlash {
  0% { filter: brightness(2.4); }
  100% { filter: brightness(1); }
}

/* transient effects */
.fx {
  position: absolute; inset: -30%;
  pointer-events: none;
  border-radius: 50%;
}
.fx.boom {
  background: radial-gradient(circle, #fff7cc 0%, #fb923c 35%, #ef4444 60%, transparent 72%);
  animation: boom .55s ease-out forwards;
}
@keyframes boom {
  0%   { transform: scale(.2); opacity: 1; }
  70%  { transform: scale(1.6); opacity: .85; }
  100% { transform: scale(2.1); opacity: 0; }
}
.fx.splash {
  border: 3px solid rgba(186, 230, 253, .9);
  animation: splash .55s ease-out forwards;
}
@keyframes splash {
  0%   { transform: scale(.25); opacity: 1; }
  100% { transform: scale(1.7); opacity: 0; }
}

@keyframes shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-5px, 2px); }
  40% { transform: translate(5px, -2px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(4px, 2px); }
}
.grid.shake { animation: shake .45s ease; }

/* fleet status chips */
.fleet-status {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  min-height: 20px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .68rem;
  letter-spacing: .05em;
  color: #94a3b8;
}
.chip .dots { display: flex; gap: 2px; }
.chip .dot {
  width: 9px; height: 9px;
  border-radius: 2px;
  background: #475569;
  border: 1px solid #64748b;
}
.chip .dot.lost { background: var(--hit); border-color: #f87171; }
.chip.dead { color: #f87171; text-decoration: line-through; }

/* message log */
#message-log {
  min-height: 1.6em;
  font-size: clamp(.9rem, 3vw, 1.1rem);
  font-weight: 600;
  color: #e0f2fe;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0,0,0,.6);
  transition: opacity .2s;
}
#message-log.flash { animation: msgFlash .4s ease; }
@keyframes msgFlash { 0% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* controls */
#controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.ctl {
  font: inherit;
  font-weight: 700;
  color: #e0f2fe;
  background: rgba(21, 60, 95, .85);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  letter-spacing: .04em;
  transition: all .15s ease;
  box-shadow: 0 3px 10px rgba(0,0,0,.4);
}
.ctl:hover:not(:disabled) { background: rgba(34, 90, 135, .95); transform: translateY(-2px); }
.ctl:active:not(:disabled) { transform: translateY(0); }
.ctl:disabled { opacity: .35; cursor: not-allowed; }
.ctl.primary {
  background: linear-gradient(145deg, #0ea5e9, #0369a1);
  border-color: #38bdf8;
  box-shadow: 0 0 16px rgba(56,189,248,.45);
}
.ctl.primary:hover:not(:disabled) { background: linear-gradient(145deg, #38bdf8, #0284c7); }
kbd {
  font-size: .65em;
  background: rgba(0,0,0,.4);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.2);
}

/* ship dock */
#ship-dock {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
}
.dock-title { font-size: .8rem; color: #93c5fd; letter-spacing: .1em; text-transform: uppercase; }
#dock-list { display: flex; gap: 12px; flex-wrap: wrap; }
.dock-ship {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px dashed transparent;
  font-size: .75rem;
  color: #cbd5e1;
}
.dock-ship.current { border-color: var(--accent); background: rgba(56,189,248,.12); color: #e0f2fe; }
.dock-ship.placed { opacity: .45; }
.dock-ship.placed .mini { filter: grayscale(.4); }
.mini { display: flex; gap: 2px; }
.mini i {
  width: 12px; height: 12px;
  border-radius: 3px;
  background: linear-gradient(145deg, #9fb2c8, #5b7089);
  box-shadow: inset 0 0 3px rgba(0,0,0,.5);
}
#ship-dock.hidden, #controls.hidden { display: none; }

/* overlay */
#overlay {
  position: fixed; inset: 0;
  background: rgba(2, 8, 18, .82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn .4s ease;
}
#overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#overlay-card {
  text-align: center;
  background: linear-gradient(160deg, #0b2237, #081526);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 40px 48px;
  box-shadow: 0 20px 60px rgba(0,0,0,.7), 0 0 40px rgba(56,189,248,.15);
  animation: popIn .45s cubic-bezier(.2, 1.4, .4, 1);
  max-width: 90vw;
}
@keyframes popIn { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#overlay-title {
  font-size: clamp(2rem, 8vw, 3.2rem);
  font-weight: 800;
  letter-spacing: .12em;
  margin-bottom: 8px;
}
#overlay-title.win  { color: var(--ok);  text-shadow: 0 0 24px rgba(34,197,94,.7); }
#overlay-title.lose { color: var(--hit); text-shadow: 0 0 24px rgba(239,68,68,.7); }
#overlay-sub { color: #93c5fd; margin-bottom: 14px; font-size: 1rem; }
#overlay-stats {
  display: flex;
  gap: 22px;
  justify-content: center;
  margin-bottom: 24px;
  color: #cbd5e1;
  font-size: .9rem;
}
#overlay-stats b { color: #e0f2fe; font-size: 1.25rem; display: block; }

/* phones */
@media (max-width: 720px) {
  :root { --cell: min(8.4vw, 38px); }
  main#boards { gap: 16px; }
  #enemy-wrap { order: -1; }
  .board-wrap h2 { margin-bottom: 4px; }
  #controls { gap: 8px; }
  .ctl { padding: 9px 13px; font-size: .85rem; }
  kbd { display: none; }
}

@media (max-width: 380px) {
  :root { --cell: 8.6vw; }
}
