:root {
  --sea: #0f2b46;
  --sea-line: #1d4468;
  --ship: #6b7a8d;
  --hit: #d8452f;
  --sunk: #7a1c10;
  --miss: #9fb6c9;
  --accent: #35b0a7;
  --text: #e8eef4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1rem;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #081726;
  color: var(--text);
}

header { text-align: center; margin-bottom: 1rem; }
h1 { margin: 0 0 .25rem; font-size: 1.6rem; letter-spacing: .04em; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
h3 { font-size: .9rem; margin: .8rem 0 .35rem; }

.status {
  margin: 0;
  font-weight: 600;
  color: var(--accent);
  min-height: 1.4em;
}

main {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel {
  background: #0d2236;
  border: 1px solid var(--sea-line);
  border-radius: 8px;
  padding: .85rem;
}

.hint { margin: .25rem 0 .6rem; font-size: .82rem; color: #9fb6c9; }
kbd {
  background: #1d4468; border-radius: 3px; padding: 0 .3em; font-size: .85em;
}

.ship-list { list-style: none; margin: 0 0 .6rem; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.ship-list button {
  background: #16354f;
  border: 1px solid var(--sea-line);
  color: var(--text);
  padding: .4rem .6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: .82rem;
}
.ship-list button.selected { border-color: var(--accent); background: #1c4b57; }
.ship-list button.placed { opacity: .55; text-decoration: line-through; }

.controls { display: flex; flex-wrap: wrap; gap: .4rem; }
.controls button, .overlay-card button {
  background: #16354f;
  border: 1px solid var(--sea-line);
  color: var(--text);
  padding: .45rem .8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
}
.controls button:hover:not(:disabled), .ship-list button:hover { border-color: var(--accent); }
.controls button:disabled { opacity: .45; cursor: not-allowed; }
#start-btn:not(:disabled), #again-btn { background: var(--accent); color: #04202c; font-weight: 700; border-color: var(--accent); }

.boards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.board-wrap { min-width: 0; }

.board {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: 2px;
  background: var(--sea-line);
  border: 2px solid var(--sea-line);
  border-radius: 4px;
  aspect-ratio: 1 / 1;
  width: 100%;
}

.cell {
  background: var(--sea);
  border: 0;
  padding: 0;
  margin: 0;
  cursor: default;
  position: relative;
  display: block;
  font: inherit;
  font-size: clamp(.5rem, 2vw, .8rem);
  line-height: 1;
  color: #04202c;
  font-weight: 700;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
}

/* Markers are painted out of flow so no glyph can widen a cell or its track. */
.cell::after {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.cell:focus { outline: none; }
.cell:focus-visible { box-shadow: inset 0 0 0 2px #fff; }

.board.enemy .cell:not(.hit):not(.miss):not(.sunk) { cursor: crosshair; }
.board.enemy .cell:not(.hit):not(.miss):not(.sunk):hover { background: #1b3d5e; }

.cell.ship { background: var(--ship); }
.cell.miss { background: var(--miss); }
.cell.miss::after { content: "•"; color: #38566d; font-size: 1.4em; line-height: 1; }
.cell.hit { background: var(--hit); }
.cell.hit::after { content: "✕"; color: #fff; }
.cell.sunk { background: var(--sunk); }
.cell.sunk::after { content: "✕"; color: #ffd9d2; }
.cell.preview { background: #2b7f76; }
.cell.preview-bad { background: #7b3030; }
.cell.last-shot { box-shadow: inset 0 0 0 2px var(--accent); }

.legend { display: flex; flex-wrap: wrap; gap: .8rem; font-size: .8rem; }
.legend span { display: flex; align-items: center; gap: .3rem; }
.sw { width: .8rem; height: .8rem; border-radius: 2px; display: inline-block; }
.sw.ship { background: var(--ship); }
.sw.hit { background: var(--hit); }
.sw.miss { background: var(--miss); }
.sw.sunk { background: var(--sunk); }

.fleets { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.fleet-status { list-style: none; margin: 0; padding: 0; font-size: .82rem; }
.fleet-status li { display: flex; justify-content: space-between; padding: .12rem 0; }
.fleet-status li.sunk { color: #ff9c8a; text-decoration: line-through; }

.log {
  list-style: none;
  margin: 0;
  padding: .4rem .6rem;
  font-size: .8rem;
  max-height: 140px;
  overflow-y: auto;
  background: #081c2e;
  border-radius: 6px;
}
.log li { padding: .1rem 0; border-bottom: 1px solid #12314a; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 16, 27, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10;
}
.hidden { display: none !important; }
.overlay-card {
  background: #0d2236;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
  max-width: 320px;
}
.overlay-card h2 { font-size: 1.4rem; }

@media (max-width: 760px) {
  .boards { grid-template-columns: 1fr; }
  .fleets { grid-template-columns: 1fr; }
}
