/* ── Морской бой 80s — retro arcade theme ────────────────────────── */

:root {
  --bg: #0a0e27;
  --surface: #16213e;
  --border: #1f4068;
  --text: #e0f7ff;
  --miss: #4a6fa5;
  --hit: #ff2e63;
  --sunk: #ffd93d;
  --ship: #37d67a;

  --font-title: 'Press Start 2P', monospace;
  --font-body: 'VT323', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.4;
  text-transform: uppercase;
  overflow-x: hidden;
}

button { font-family: var(--font-body); text-transform: uppercase; }

/* ── Scanline overlay (arcade CRT feel) ───────────────────────────── */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 500;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.035) 0px,
    rgba(255, 255, 255, 0.035) 1px,
    transparent 2px,
    transparent 4px
  );
  mix-blend-mode: overlay;
}
.scanlines::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(10, 14, 39, 0) 60%, rgba(10, 14, 39, 0.55) 100%);
}

/* ── Scene shell ───────────────────────────────────────────────────── */
.scene {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 22px 90px;
  position: relative;
}

.scene.shake { animation: shake 320ms ease; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(5px, -4px); }
  60% { transform: translate(-4px, 4px); }
  80% { transform: translate(4px, -2px); }
}

/* ── Header ────────────────────────────────────────────────────────── */
.title-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.title {
  font-family: var(--font-title);
  font-size: 28px;
  color: var(--ship);
  margin: 6px 0 0;
  text-shadow: 0 0 6px rgba(55, 214, 122, 0.7), 0 0 14px rgba(55, 214, 122, 0.35);
  letter-spacing: 2px;
}

.status-bar {
  font-family: var(--font-title);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 10px 18px;
  border-radius: 4px;
  min-width: 280px;
  box-shadow: 0 0 10px rgba(31, 64, 104, 0.6) inset;
  transition: background-color 200ms ease, color 200ms ease;
}
.status-bar.flash { background: var(--ship); color: var(--bg); }
.status-bar.flash-enemy { background: var(--hit); color: var(--bg); }

/* ── Boards row (desktop: side by side + palette) ─────────────────── */
.boards-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 22px;
  align-items: start;
  justify-content: center;
}

.board-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.board-title {
  font-family: var(--font-title);
  font-size: 14px;
  margin: 0;
  color: var(--text);
  letter-spacing: 1px;
}
.board-own .board-title { color: var(--ship); }
.board-enemy .board-title { color: var(--hit); }

.board {
  display: grid;
  grid-template-columns: 22px repeat(10, minmax(24px, 42px));
  grid-template-rows: 22px repeat(10, minmax(24px, 42px));
  gap: 2px;
  background: var(--border);
  padding: 4px;
  border: 3px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 0 18px rgba(31, 64, 104, 0.55);
  user-select: none;
}

.cell-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--miss);
}

.cell {
  background: var(--surface);
  position: relative;
  border-radius: 2px;
  transition: background-color 180ms ease, box-shadow 180ms ease, transform 150ms ease;
}

.cell.water { background: var(--surface); }

.board-enemy .cell.targetable:hover {
  background: #1d3a63;
  box-shadow: 0 0 0 2px var(--hit) inset, 0 0 8px var(--hit);
  cursor: crosshair;
}

.cell.ship { background: var(--ship); box-shadow: 0 0 8px rgba(55, 214, 122, 0.6) inset; }
.cell.preview-ok { background: rgba(55, 214, 122, 0.55); box-shadow: 0 0 0 2px var(--ship) inset; }
.cell.preview-bad { background: rgba(255, 46, 99, 0.55); box-shadow: 0 0 0 2px var(--hit) inset; }

.cell.miss::after {
  content: "";
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: var(--miss);
  box-shadow: 0 0 6px var(--miss);
}

.cell.hit { background: var(--hit); animation: flash-hit 250ms ease; }
.cell.hit::after {
  content: "\2716";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--bg);
  font-family: var(--font-title);
}

.cell.sunk { background: var(--sunk); box-shadow: 0 0 12px var(--sunk); animation: flash-sunk 350ms ease; }
.cell.sunk::after {
  content: "\2716";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--bg);
  font-family: var(--font-title);
}

.cell.shake-cell { animation: cell-shake 220ms ease; }
.cell.reject { animation: reject-blink 220ms ease 2; }

@keyframes flash-hit {
  0% { box-shadow: 0 0 0 0 var(--hit); }
  50% { box-shadow: 0 0 22px 6px var(--hit); }
  100% { box-shadow: 0 0 8px 2px var(--hit); }
}
@keyframes flash-sunk {
  0% { box-shadow: 0 0 0 0 var(--sunk); }
  50% { box-shadow: 0 0 26px 8px var(--sunk); }
  100% { box-shadow: 0 0 12px 2px var(--sunk); }
}
@keyframes cell-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
@keyframes reject-blink {
  0%, 100% { background: var(--surface); }
  50% { background: var(--hit); }
}

/* muzzle flash */
.cell .flash-fx {
  position: absolute;
  inset: -20%;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--hit) 40%, transparent 75%);
  opacity: 0;
  pointer-events: none;
}
.cell .flash-fx.play {
  animation: muzzle-flash 250ms ease-out;
}
@keyframes muzzle-flash {
  0% { opacity: 1; transform: scale(0.3); }
  100% { opacity: 0; transform: scale(1.6); }
}

/* ── Ship palette (placement phase) ───────────────────────────────── */
.ship-palette {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 14px;
  min-width: 190px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ship-palette.hidden { display: none; }

.palette-title {
  font-family: var(--font-title);
  font-size: 12px;
  margin: 0 0 4px;
  color: var(--ship);
}

.palette-list { display: flex; flex-direction: column; gap: 8px; }

.palette-ship {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 2px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  background: var(--bg);
  transition: border-color 150ms ease, background-color 150ms ease;
}
.palette-ship:hover { border-color: var(--miss); }
.palette-ship.selected { border-color: var(--ship); background: rgba(55, 214, 122, 0.12); }
.palette-ship.placed { opacity: 0.35; pointer-events: none; }

.palette-ship .blocks { display: flex; gap: 2px; }
.palette-ship .blocks span {
  width: 12px; height: 12px; background: var(--ship); border-radius: 2px; display: inline-block;
}
.palette-ship.vertical .blocks { flex-direction: column; }

.palette-hint {
  font-size: 15px;
  color: var(--miss);
  line-height: 1.3;
  margin: 4px 0 0;
}

/* ── Controls row ──────────────────────────────────────────────────── */
.controls-row {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 18px;
  align-items: start;
}

.button-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
}

.btn {
  font-family: var(--font-body);
  font-size: 18px;
  text-transform: uppercase;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background-color 180ms ease, transform 150ms ease, box-shadow 180ms ease;
}
.btn:hover { background: #1d3a63; box-shadow: 0 0 8px rgba(31, 64, 104, 0.8); }
.btn:active { transform: scale(0.96); }
.btn.hidden { display: none; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-primary { border-color: var(--ship); color: var(--ship); }
.btn-primary:hover { background: rgba(55, 214, 122, 0.15); }

.btn-accent { border-color: var(--hit); color: var(--hit); }
.btn-accent:hover { background: rgba(255, 46, 99, 0.15); }

.btn-icon { padding: 10px 14px; }

.log-panel {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  max-height: 220px;
  overflow: hidden;
}

.log-toggle {
  display: none;
  width: 100%;
  background: var(--border);
  color: var(--text);
  border: none;
  font-family: var(--font-title);
  font-size: 12px;
  padding: 10px;
  cursor: pointer;
  justify-content: space-between;
  align-items: center;
}

.log-body { overflow-y: auto; padding: 10px 12px; }

.log-list { display: flex; flex-direction: column; gap: 4px; font-size: 17px; }
.log-list .log-you { color: var(--ship); }
.log-list .log-enemy { color: var(--hit); }
.log-list .log-sunk { color: var(--sunk); }

/* ── Welcome overlay ───────────────────────────────────────────────── */
.welcome-overlay, .gameover-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 39, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
  padding: 20px;
}
.welcome-overlay.hidden, .gameover-overlay.hidden { display: none; }

.welcome-box, .gameover-box {
  background: var(--surface);
  border: 3px solid var(--ship);
  border-radius: 6px;
  padding: 32px 28px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 30px rgba(55, 214, 122, 0.4);
}

.gameover-box { border-color: var(--sunk); box-shadow: 0 0 30px rgba(255, 217, 61, 0.45); }

.welcome-title, .gameover-title {
  font-family: var(--font-title);
  font-size: 24px;
  color: var(--ship);
  margin: 0 0 18px;
  text-shadow: 0 0 8px rgba(55, 214, 122, 0.6);
}
.gameover-title { color: var(--sunk); text-shadow: 0 0 8px rgba(255, 217, 61, 0.6); }
.gameover-title.lose { color: var(--hit); text-shadow: 0 0 8px rgba(255, 46, 99, 0.6); }

.welcome-demo {
  display: grid;
  grid-template-columns: repeat(10, 14px);
  grid-template-rows: repeat(10, 14px);
  gap: 2px;
  justify-content: center;
  margin: 0 auto 18px;
  background: var(--border);
  padding: 4px;
  border-radius: 3px;
  width: max-content;
}
.welcome-demo .cell { width: 14px; height: 14px; }

.blink-start {
  font-family: var(--font-title);
  font-size: 14px;
  color: var(--hit);
  animation: blink 1s steps(1) infinite;
  margin: 0 0 14px;
}
@keyframes blink { 50% { opacity: 0.15; } }

.welcome-hint { font-size: 16px; color: var(--text); margin: 0 0 6px; line-height: 1.35; }
.welcome-record { font-size: 16px; color: var(--sunk); min-height: 20px; margin: 0 0 14px; }

.welcome-buttons, .gameover-box .btn { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.gameover-stats {
  font-size: 18px;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 20px;
  text-align: left;
  display: inline-block;
}

/* ── Toast ─────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--hit);
  color: var(--bg);
  font-family: var(--font-title);
  font-size: 12px;
  padding: 12px 20px;
  border-radius: 4px;
  z-index: 700;
  box-shadow: 0 0 16px rgba(255, 46, 99, 0.7);
  transition: opacity 200ms ease, transform 200ms ease;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(10px); pointer-events: none; }

/* ── Responsive < 768px ────────────────────────────────────────────── */
@media (max-width: 767px) {
  .scene { padding: 12px 10px 130px; gap: 12px; }

  .title { font-size: 18px; }
  .status-bar { font-size: 11px; min-width: 0; width: 100%; }

  .boards-row {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 14px;
  }
  .board-enemy { order: 1; }
  .board-own { order: 2; }
  .ship-palette { order: 3; width: 100%; }

  .board {
    grid-template-columns: 18px repeat(10, minmax(0, 1fr));
    grid-template-rows: 18px repeat(10, minmax(0, 1fr));
    width: 100%;
    max-width: 380px;
  }

  .controls-row {
    grid-template-columns: 1fr;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 2px solid var(--border);
    z-index: 400;
    margin: 0;
  }

  .button-panel { justify-content: center; }
  .btn { flex: 1 1 auto; font-size: 15px; padding: 10px 8px; }

  .log-panel { max-height: none; order: 2; }
  .log-toggle { display: flex; }
  .log-body { display: none; max-height: 160px; }
  .log-panel.open .log-body { display: block; }
}
