:root {
  --bg: #0b1a2e;
  --panel: #12263f;
  --water: #1c4a7a;
  --water2: #215890;
  --grid: #0e2f52;
  --ship: #8a9bb0;
  --hit: #ff4d3d;
  --miss: #cfe3ff;
  --sunk: #5a1d1d;
  --accent: #36c2ff;
  --text: #e8f1ff;
  --cell: min(8.2vw, 38px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; min-height: 100vh; color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(ellipse at top, #16365c, var(--bg) 70%);
  user-select: none; -webkit-user-select: none;
}
header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; flex-wrap: wrap;
}
h1 { margin: 0; font-size: 1.5rem; letter-spacing: 1px; }
h2 { margin: 6px 0; font-size: 1rem; text-transform: uppercase; letter-spacing: 2px; opacity: .8; text-align: center; }
.status {
  flex: 1; text-align: center; font-weight: 600; padding: 8px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid #244a74; min-width: 200px; transition: background .3s;
}
.status.player { background: #0f4d3a; border-color: #2bd18f; }
.status.enemy { background: #4d1f1f; border-color: #ff6b5b; }
.icon-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); }
main { max-width: 1000px; margin: 0 auto; padding: 0 10px 30px; }
.panel { background: var(--panel); border-radius: 12px; padding: 12px; margin-bottom: 12px; border: 1px solid #244a74; }
.setup-controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.btn {
  background: #1e3d61; color: var(--text); border: 1px solid #36628f; border-radius: 8px;
  padding: 10px 14px; font-size: .95rem; cursor: pointer; font-weight: 600; transition: transform .1s, background .2s;
}
.btn:hover:not(:disabled) { background: #28527f; }
.btn:active:not(:disabled) { transform: scale(.96); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: #1a8fd0; border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: #22a3ec; }
.hint { text-align: center; font-size: .85rem; opacity: .75; margin: 10px 0; }
kbd { background: #0b1a2e; padding: 1px 6px; border-radius: 4px; border: 1px solid #36628f; }
.dock { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; min-height: 40px; }
.dock-ship {
  display: flex; gap: 2px; padding: 4px; border-radius: 6px; cursor: grab; touch-action: none;
  border: 2px solid transparent; flex-direction: column; align-items: center;
}
.dock-ship .cells { display: flex; gap: 2px; }
.dock-ship .cells span { width: calc(var(--cell) * .75); height: calc(var(--cell) * .75); background: var(--ship); border-radius: 4px; }
.dock-ship small { font-size: .75rem; opacity: .8; }
.dock-ship.selected { border-color: var(--accent); background: #1a3a5e; }

.boards { display: flex; gap: 24px; justify-content: center; flex-wrap: wrap; }
.board-wrap { display: flex; flex-direction: column; align-items: center; }
.board {
  display: grid; grid-template-columns: repeat(11, var(--cell)); grid-template-rows: repeat(11, var(--cell));
  gap: 2px; padding: 4px; background: var(--grid); border-radius: 8px; touch-action: none;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.label { display: flex; align-items: center; justify-content: center; font-size: .7rem; opacity: .6; }
.cell {
  position: relative; background: linear-gradient(135deg, var(--water), var(--water2));
  border-radius: 3px; display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.board.enemy.active .cell:not(.hit):not(.miss) { cursor: crosshair; }
.board.enemy.active .cell:not(.hit):not(.miss):hover { background: #2f76b8; box-shadow: inset 0 0 0 2px var(--accent); }
.board.enemy:not(.active) { opacity: .85; }
.cell.ship { background: var(--ship); }
.cell.ship.h-start { border-radius: 40% 3px 3px 40%; }
.cell.ship.h-end { border-radius: 3px 40% 40% 3px; }
.cell.ship.v-start { border-radius: 40% 40% 3px 3px; }
.cell.ship.v-end { border-radius: 3px 3px 40% 40%; }
.cell.preview-ok { background: #2bd18f !important; opacity: .8; }
.cell.preview-bad { background: #d14b3b !important; opacity: .8; }
.cell.miss::after {
  content: ''; width: 28%; height: 28%; border-radius: 50%; background: var(--miss);
  animation: pop .35s ease-out;
}
.cell.miss::before {
  content: ''; position: absolute; inset: 20%; border-radius: 50%; border: 2px solid var(--miss);
  animation: ripple .6s ease-out forwards;
}
.cell.hit::after {
  content: '✹'; color: #ffd24d; font-size: calc(var(--cell) * .7); line-height: 1;
  text-shadow: 0 0 8px #ff7b00; animation: boom .45s ease-out;
}
.cell.hit { background: var(--hit); animation: shake .3s; }
.cell.sunk { background: var(--sunk) !important; }
.cell.sunk::after { content: '✖'; color: #ff8a80; text-shadow: none; font-size: calc(var(--cell) * .55); }
.cell.last { box-shadow: inset 0 0 0 2px #ffd24d; }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes ripple { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }
@keyframes boom { 0% { transform: scale(0) rotate(0); } 60% { transform: scale(1.5) rotate(40deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes shake { 0%,100% { transform: translate(0); } 25% { transform: translate(-2px,1px); } 75% { transform: translate(2px,-1px); } }

.fleet-status { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; max-width: calc(var(--cell) * 11); }
.fleet-status span { font-size: .75rem; padding: 3px 8px; border-radius: 999px; background: #1e3d61; }
.fleet-status span.dead { background: var(--sunk); text-decoration: line-through; opacity: .7; }

.drag-ghost { position: fixed; pointer-events: none; z-index: 50; display: flex; gap: 2px; opacity: .85; }
.drag-ghost.v { flex-direction: column; }
.drag-ghost span { width: var(--cell); height: var(--cell); background: var(--ship); border-radius: 4px; }

.overlay { position: fixed; inset: 0; background: rgba(0,10,25,.75); display: flex; align-items: center; justify-content: center; z-index: 100; animation: fade .3s; }
.overlay.hidden { display: none; }
.modal { background: var(--panel); padding: 30px 40px; border-radius: 16px; text-align: center; border: 1px solid var(--accent); animation: pop .35s; max-width: 90vw; }
.modal h2 { font-size: 2rem; opacity: 1; text-transform: none; letter-spacing: 0; }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); background: #5a1d1d; border: 1px solid var(--hit); padding: 8px 18px; border-radius: 999px; font-weight: 700; z-index: 60; animation: toast 1.6s forwards; pointer-events: none; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -10px); } 15%,80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

@media (max-width: 820px) {
  :root { --cell: min(8.3vw, 34px); }
  h1 { font-size: 1.2rem; }
  .status { order: 3; flex-basis: 100%; }
  .boards { gap: 14px; }
}
