:root {
  --bg: #0b1d2a;
  --bg-alt: #0f2a3d;
  --panel: #112d42;
  --sea: #1b4b6b;
  --sea-hover: #256789;
  --grid-line: #0a1b27;
  --text: #e6f1f7;
  --muted: #9fb9c9;
  --accent: #f4c95d;
  --ship: #5a6b7a;
  --ship-own: #8fa4b3;
  --hit: #e04e4e;
  --miss: #cfd8dc;
  --sunk: #8a1d1d;
  --ok: #4ecb7f;
  --danger: #e04e4e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #15394f 0%, var(--bg) 60%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

header {
  text-align: center;
  padding: 24px 12px 8px;
}

header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

#status-bar {
  background: var(--panel);
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  border: 1px solid #1c3e57;
}

#phase-indicator {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 4px;
}

#message {
  color: var(--muted);
  font-size: 0.95rem;
}

.controls {
  background: var(--panel);
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  border: 1px solid #1c3e57;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.hidden { display: none !important; }

#fleet-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ship-chip {
  background: var(--bg-alt);
  border: 2px solid transparent;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ship-chip:hover:not(.placed) {
  border-color: var(--accent);
}

.ship-chip.selected {
  border-color: var(--accent);
  background: #173c55;
  box-shadow: 0 0 0 2px rgba(244, 201, 93, 0.25);
}

.ship-chip.placed {
  opacity: 0.4;
  cursor: not-allowed;
  text-decoration: line-through;
}

.ship-chip .cells {
  display: inline-flex;
  gap: 2px;
}

.ship-chip .cells span {
  width: 10px;
  height: 10px;
  background: var(--ship-own);
  display: inline-block;
  border-radius: 2px;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  background: var(--sea);
  color: var(--text);
  border: 1px solid #2a6282;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.05s ease;
}

button:hover:not(:disabled) { background: var(--sea-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#start-btn:enabled {
  background: var(--ok);
  border-color: #3aa866;
  color: #0b2615;
}

#score {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  font-size: 0.95rem;
}

#boards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 820px) {
  #boards { grid-template-columns: 1fr; }
}

.board-wrapper h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  color: var(--muted);
  text-align: center;
}

.board {
  display: grid;
  grid-template-columns: 24px repeat(10, 1fr);
  grid-template-rows: 24px repeat(10, 1fr);
  gap: 2px;
  background: var(--grid-line);
  padding: 6px;
  border-radius: 8px;
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  user-select: none;
}

.board .label {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.cell {
  background: var(--sea);
  border-radius: 3px;
  position: relative;
  transition: background 0.1s ease;
  cursor: default;
}

.board.interactive .cell:not(.revealed) {
  cursor: crosshair;
}

.board.interactive .cell:not(.revealed):hover {
  background: var(--sea-hover);
}

.cell.ship-own {
  background: var(--ship-own);
}

.cell.preview-valid {
  background: #3c7b5a !important;
}

.cell.preview-invalid {
  background: #8a3a3a !important;
}

.cell.hit::after,
.cell.miss::after,
.cell.sunk::after {
  content: "";
  position: absolute;
  inset: 20%;
  border-radius: 50%;
}

.cell.hit { background: #5c2a2a; }
.cell.hit::after { background: var(--hit); box-shadow: 0 0 8px rgba(224, 78, 78, 0.8); }

.cell.miss { background: #2b3a45; }
.cell.miss::after { background: var(--miss); }

.cell.sunk { background: var(--sunk); }
.cell.sunk::after { background: #3c0a0a; box-shadow: inset 0 0 4px #000; }

.cell.last-shot { outline: 2px solid var(--accent); }

#legend {
  margin-top: 16px;
  padding: 12px;
  background: var(--panel);
  border-radius: 10px;
  border: 1px solid #1c3e57;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  align-items: center;
  font-size: 0.9rem;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}
.swatch.ship { background: var(--ship-own); }
.swatch.hit { background: var(--hit); }
.swatch.miss { background: var(--miss); }
.swatch.sunk { background: var(--sunk); }

kbd {
  background: #1c3e57;
  border: 1px solid #2a6282;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, monospace;
  font-size: 0.85em;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 16px;
  margin-top: 24px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--panel);
  padding: 32px 40px;
  border-radius: 12px;
  border: 1px solid #2a6282;
  text-align: center;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
  margin-top: 0;
  font-size: 2rem;
  color: var(--accent);
}

.modal-content button {
  margin-top: 12px;
  font-size: 1rem;
  padding: 10px 20px;
}
