:root {
  --ocean-deep: #050a12;
  --ocean-mid: #0f2438;
  --chart-blue: #1a3a5c;
  --phosphor: #4ade80;
  --phosphor-dim: #22c55e;
  --brass: #c9a227;
  --brass-dark: #8b6914;
  --hull: #8b9da8;
  --hull-deck: #b8c8d4;
  --hit: #ef4444;
  --miss: #64748b;
  --foam: #e2e8f0;
  --mist: #94a3b8;
  --glow: rgba(74, 222, 128, 0.35);
  --radius: 12px;
  --font-display: "Russo One", sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "Share Tech Mono", monospace;
  --chrome-h: 220px;
  --board-gap: 8px;
  --board-fleet-h: 0px;
  --board-max: 760px;
}

.phase-battle,
.phase-over {
  --board-gap: 4px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--foam);
  background: var(--ocean-deep);
}

/* ── Thematic background ── */
.sea {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(180deg, rgba(5, 10, 18, 0.72) 0%, rgba(5, 10, 18, 0.5) 45%, rgba(5, 10, 18, 0.78) 100%),
    url("assets/sea-battle-bg.jpg") center / cover no-repeat;
  pointer-events: none;
  overflow: hidden;
}

.sea-grid {
  position: absolute;
  inset: 0;
  opacity: 0.15;
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(74, 222, 128, 0.045) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(74, 222, 128, 0.045) 40px);
  mask-image: radial-gradient(ellipse 85% 75% at 50% 45%, black 20%, transparent 75%);
}

.sea-waves {
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background:
    repeating-linear-gradient(
      -3deg,
      transparent,
      transparent 80px,
      rgba(74, 222, 128, 0.15) 81px,
      transparent 82px
    );
  animation: wave-drift 18s ease-in-out infinite;
}

.sea-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(0, 0, 0, 0.55) 100%);
}

@keyframes wave-drift {
  0%, 100% { transform: translateY(0) translateX(0); }
  50% { transform: translateY(-12px) translateX(8px); }
}

/* ── App shell ── */
.app {
  position: relative;
  z-index: 1;
  width: min(1680px, 100%);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: 10px 16px calc(6px + env(safe-area-inset-bottom));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
.game-header {
  flex-shrink: 0;
  text-align: center;
  margin-bottom: 6px;
}

.header-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  position: relative;
}

.brand {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 2.8vw, 2.5rem);
  letter-spacing: 0.12em;
  line-height: 1;
  margin: 0;
  color: var(--foam);
  text-transform: uppercase;
  text-shadow: 0 0 24px rgba(74, 222, 128, 0.25);
}

.phase-battle .brand,
.phase-over .brand {
  display: none;
}

.brand.sm {
  font-size: 1.4rem;
  display: block;
  letter-spacing: 0.1em;
}

.radar-deco {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(74, 222, 128, 0.35);
  background: radial-gradient(circle, rgba(74, 222, 128, 0.08) 0%, transparent 70%);
  position: relative;
  overflow: hidden;
}

.radar-sweep {
  position: absolute;
  inset: 0;
  background: conic-gradient(from 0deg, transparent 0deg, rgba(74, 222, 128, 0.35) 40deg, transparent 80deg);
  animation: radar-spin 4s linear infinite;
}

@keyframes radar-spin {
  to { transform: rotate(360deg); }
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.turn-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.turn-badge.your-turn {
  color: var(--ocean-deep);
  background: var(--phosphor);
  border-color: var(--phosphor);
  box-shadow: 0 0 16px rgba(74, 222, 128, 0.45);
  animation: pulse-once 0.5s ease-out;
}

.turn-badge.enemy-turn {
  color: var(--mist);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
}

@keyframes pulse-once {
  0% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

#status {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0;
  color: var(--foam);
}

.lead {
  margin: 2px 0 0;
  color: var(--mist);
  font-size: 0.78rem;
}

/* ── Match HUD — icon row ── */
.match-hud {
  flex-shrink: 0;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: rgba(15, 36, 56, 0.88);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(201, 162, 39, 0.12);
}

.hud-edit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  overflow: hidden;
}

.hud-cluster {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(201, 162, 39, 0.2);
  border-radius: 10px;
  flex-shrink: 0;
}

.hud-cluster--comfort {
  margin-left: auto;
  background: transparent;
  border: none;
  padding: 0;
}

.hud-pic {
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--mist);
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.hud-pic svg {
  width: 22px;
  height: 22px;
}

.hud-pic:hover:not(:disabled) {
  color: var(--foam);
  background: rgba(255, 255, 255, 0.06);
}

.hud-pic.active {
  color: var(--ocean-deep);
  background: var(--phosphor);
  box-shadow: 0 0 12px rgba(74, 222, 128, 0.35);
}

.hud-pic:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.hud-badge {
  position: absolute;
  bottom: 1px;
  right: 1px;
  font: 600 8px/1 var(--font-mono);
  padding: 1px 3px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--foam);
  pointer-events: none;
}

.hud-pic.active .hud-badge {
  background: var(--ocean-deep);
  color: var(--phosphor);
}

.hud-toggle .icon-off {
  display: none;
}

.hud-toggle:not(.active) .icon-on {
  display: none;
}

.hud-toggle:not(.active) .icon-off {
  display: block;
}

.hud-toggle:not(.active) {
  color: var(--mist);
  opacity: 0.55;
}

.hud-summary {
  display: none;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.hud-chip {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(201, 162, 39, 0.25);
  color: var(--mist);
}

.match-hud--readonly .hud-edit .hud-cluster:not(.hud-cluster--comfort) {
  opacity: 0.45;
  pointer-events: none;
}

.match-hud--readonly .hud-edit {
  justify-content: center;
}

.match-hud--readonly .hud-summary {
  display: flex;
}

.phase-battle .match-hud--readonly .hud-edit .hud-cluster:not(.hud-cluster--comfort),
.phase-over .match-hud--readonly .hud-edit .hud-cluster:not(.hud-cluster--comfort) {
  display: none;
}

.phase-battle .match-hud,
.phase-over .match-hud {
  padding: 4px 8px;
  margin-bottom: 2px;
}

.phase-battle .lead,
.phase-over .lead {
  display: none;
}

.phase-battle .hud-summary,
.phase-over .hud-summary {
  display: none !important;
}

.phase-place .hud-summary {
  display: none !important;
}

.phase-over .match-hud {
  display: none;
}

.hud-cluster.locked {
  opacity: 0.4;
  pointer-events: none;
}

/* ── Fleet bar above board (battle) ── */
.board-fleet {
  width: 100%;
  flex-shrink: 0;
  margin-bottom: 4px;
  padding: 6px 10px 8px;
  background: rgba(10, 24, 40, 0.78);
  border: 1px solid rgba(201, 162, 39, 0.28);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.board-fleet-title {
  font-family: var(--font-display);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  color: var(--brass);
  text-align: center;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.board-fleet-ships {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.fleet-status-ship {
  display: inline-flex;
  gap: 2px;
  position: relative;
  flex-shrink: 0;
}

.fleet-status-ship .pip {
  display: block;
  width: 13px;
  height: 13px;
  border-radius: 3px;
  background: rgba(139, 157, 168, 0.28);
  border: 1.5px solid var(--hull);
  box-sizing: border-box;
}

.fleet-status-ship .pip.hit {
  background: var(--hit);
  border-color: #dc2626;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.fleet-status-ship.sunk {
  opacity: 0.38;
}

.fleet-status-ship.sunk::after {
  content: "";
  position: absolute;
  inset: -2px -1px;
  background: linear-gradient(
    145deg,
    transparent 44%,
    rgba(239, 68, 68, 0.75) 46%,
    rgba(239, 68, 68, 0.75) 54%,
    transparent 56%
  );
  pointer-events: none;
}

.fleet-status-ship.sunk .pip {
  background: rgba(239, 68, 68, 0.35);
  border-color: rgba(220, 38, 38, 0.7);
}

.fleet-status-ship.sunk .pip.hit {
  background: #ef4444;
}

.phase-place .board-fleet {
  display: none !important;
}

@media (max-width: 900px) {
  .board-fleet {
    margin-bottom: 6px;
    padding: 6px 10px 8px;
  }

  .board-fleet-title {
    margin-bottom: 6px;
    font-size: 0.75rem;
  }

  .board-fleet-ships {
    gap: 8px;
  }

  .fleet-status-ship .pip {
    width: 11px;
    height: 11px;
  }
}

/* ── Battle deck layout ── */
.battle-deck {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 20px;
  overflow: hidden;
}

.side-deck {
  flex-shrink: 0;
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: rgba(15, 36, 56, 0.6);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: var(--radius);
  overflow: hidden;
}

.phase-battle .side-deck,
.phase-over .side-deck {
  display: none;
}

.side-title {
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--brass);
  margin: 0;
  text-transform: uppercase;
}

.orient-hint {
  margin: auto 0 0;
  font-size: 0.72rem;
  color: var(--mist);
}

.orient-icon {
  font-family: var(--font-mono);
  color: var(--phosphor);
  font-size: 1rem;
}

.orient-mini {
  font-family: var(--font-mono);
  opacity: 0.7;
  margin-left: 4px;
}

.game-stage {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(16px, 3vw, 48px);
  align-items: stretch;
  justify-items: stretch;
  overflow: hidden;
}

/* ── Boards ── */
.board-tabs {
  display: none;
  grid-column: 1 / -1;
  gap: 6px;
  justify-content: center;
}

.board-tab {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(201, 162, 39, 0.3);
  background: rgba(0, 0, 0, 0.3);
  color: var(--mist);
  cursor: pointer;
}

.board-tab.active {
  color: var(--ocean-deep);
  background: var(--phosphor);
  border-color: var(--phosphor);
}

.board-wrap {
  min-height: 0;
  height: 100%;
  width: 100%;
  max-width: var(--board-max);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
}

.board-slot {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}

.board-wrap h2,
.board-wrap .board-label {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  font-weight: 400;
  margin: 0 0 6px;
  text-align: center;
  color: var(--brass);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  align-self: center;
}

.phase-battle .board-wrap .board-label,
.phase-over .board-wrap .board-label {
  display: none;
}

.board-icon {
  color: var(--phosphor);
  font-size: 0.9rem;
}

.score-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.score-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(100, 116, 139, 0.5);
  border: 1px solid rgba(100, 116, 139, 0.6);
}

.score-dot.sunk {
  background: var(--hit);
  border-color: var(--hit);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.board-frame {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr;
  gap: 3px;
  width: min(100cqmin, var(--board-max));
  max-width: 100%;
  aspect-ratio: 1;
  height: auto;
  margin-inline: auto;
  padding: 10px;
  background: linear-gradient(145deg, #1a2a3a, #0d1824);
  border: 3px solid var(--brass-dark);
  border-radius: 16px;
  box-shadow:
    inset 0 0 0 1px var(--brass),
    0 12px 40px rgba(0, 0, 0, 0.55),
    0 0 30px rgba(74, 222, 128, 0.06);
  position: relative;
  flex-shrink: 0;
  min-height: 0;
  min-width: 0;
}

@supports not (width: 1cqmin) {
  .board-frame {
    width: min(
      100%,
      calc(100dvh - var(--chrome-h) - var(--board-fleet-h, 0px) - var(--board-gap) - 16px),
      var(--board-max)
    );
  }
}

.board-wrap--enemy .board-frame::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 10px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  background: conic-gradient(from 0deg, transparent, rgba(74, 222, 128, 0.08), transparent);
  animation: radar-spin 6s linear infinite;
}

.phase-battle .board-wrap--enemy:not(.enemy-turn-pause) .board-frame::before {
  opacity: 1;
}

.board-coords--top {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(var(--board-size, 10), 1fr);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: rgba(74, 222, 128, 0.65);
  text-align: center;
  padding: 0 4px;
}

.board-coords--left {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-rows: repeat(var(--board-size, 10), 1fr);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: rgba(74, 222, 128, 0.65);
  align-items: center;
  justify-items: end;
  padding-right: 4px;
  min-width: 1.1rem;
}

.board {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(var(--board-size, 10), 1fr);
  gap: 2px;
  aspect-ratio: 1;
  width: 100%;
  padding: 4px;
  background: linear-gradient(145deg, #0d1f33, #152a42);
  border-radius: 8px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

.board.locked {
  pointer-events: none;
  opacity: 0.88;
}

.board.enemy:not(.locked) {
  cursor: crosshair;
}

.board.fog-of-war .cell {
  background: linear-gradient(160deg, #0a1828, #0d1a2a);
  opacity: 0.55;
}

.board.fog-of-war .cell:nth-child(4n) {
  background: linear-gradient(160deg, #0c1c2e, #0f2035);
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 3px;
  background: linear-gradient(160deg, #1e4060, #152d48);
  border: 1px solid rgba(74, 222, 128, 0.1);
  padding: 0;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}

.cell:nth-child(even) {
  filter: brightness(1.04);
}

.cell:focus-visible {
  outline: 2px solid var(--phosphor);
  outline-offset: 1px;
}

.board:not(.locked) .cell:hover,
.board.placing .cell.preview-ok {
  background: rgba(74, 222, 128, 0.2);
  border-color: rgba(74, 222, 128, 0.4);
  box-shadow: inset 0 0 10px rgba(74, 222, 128, 0.25);
}

.board.placing .cell.preview-bad {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.5);
}

.board.enemy:not(.locked) .cell:hover {
  transform: scale(1.06);
  z-index: 1;
}

.cell.ship {
  background: linear-gradient(180deg, #c5d4de 0%, #7a8f9c 55%, #4e5f6a 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 2px 4px rgba(0, 0, 0, 0.35);
  opacity: 1 !important;
  filter: none !important;
}

.cell.ship::before {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: 35%;
  height: 2px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 1px;
}

.phase-battle .board-wrap--player .cell.ship:not(.hit):not(.sunk) {
  outline: 1px solid rgba(74, 222, 128, 0.35);
}

.cell.hit {
  background: var(--hit) !important;
  animation: flash-hit 0.35s ease-out;
  opacity: 1 !important;
  filter: none !important;
}

.cell.hit::after {
  content: "";
  position: absolute;
  inset: 20%;
  border-radius: 50%;
  background: #2a1010;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
}

.cell.miss {
  background: rgba(15, 35, 55, 0.95) !important;
  animation: splash 0.4s ease-out;
  opacity: 1 !important;
  filter: none !important;
}

.cell.miss.auto::after {
  opacity: 0.45;
  background: var(--mist);
  inset: 32%;
}

.cell.miss.auto {
  background: rgba(20, 45, 65, 0.65) !important;
}

.cell.miss::after {
  content: "";
  position: absolute;
  inset: 26%;
  border-radius: 50%;
  background: var(--miss);
  box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.4);
}

.cell.sunk {
  background: linear-gradient(145deg, #ff5a4a 0%, #e11d1d 45%, #991b1b 100%) !important;
  filter: saturate(1.35) brightness(1.15) !important;
  box-shadow:
    inset 0 0 0 1px rgba(255, 220, 120, 0.45),
    0 0 14px rgba(255, 70, 50, 0.75),
    0 0 28px rgba(255, 40, 30, 0.35);
  animation: sunk-flash 0.5s ease-out;
}

@keyframes sunk-flash {
  0% { box-shadow: 0 0 24px rgba(255, 120, 60, 0.95); transform: scale(1.08); }
  100% { box-shadow: inset 0 0 0 1px rgba(255, 220, 120, 0.45), 0 0 14px rgba(255, 70, 50, 0.75); transform: scale(1); }
}

.cell.sunk::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 2px;
  background: #fff;
  opacity: 0.95;
  transform: rotate(45deg);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}

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

@keyframes flash-hit {
  0% { transform: scale(1.12); box-shadow: 0 0 14px var(--glow); }
  100% { transform: scale(1); }
}

@keyframes splash {
  0% { box-shadow: 0 0 0 0 rgba(148, 163, 184, 0.5); }
  100% { box-shadow: 0 0 0 6px rgba(148, 163, 184, 0); }
}

.board.sunk-shake {
  animation: shake 0.2s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* ── Fleet bar (side deck) ── */
.fleet-bar {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.fleet-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid transparent;
  font-size: 0.72rem;
  color: var(--mist);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
}

.fleet-chip.active {
  border-color: var(--phosphor);
  background: rgba(74, 222, 128, 0.12);
  color: var(--foam);
}

.fleet-chip.placed {
  opacity: 0.4;
  cursor: default;
}

.ship-pips {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.ship-pips span {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--hull-deck);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}

/* ── Footer / toolbar ── */
.game-footer {
  flex-shrink: 0;
  margin-top: 8px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.btn {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
  letter-spacing: 0.02em;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(180deg, var(--phosphor), var(--phosphor-dim));
  color: var(--ocean-deep);
  box-shadow: 0 4px 16px rgba(74, 222, 128, 0.35);
}

.btn.primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(74, 222, 128, 0.45);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--foam);
  border: 1px solid rgba(201, 162, 39, 0.3);
}

.btn.ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(201, 162, 39, 0.5);
}

.hidden {
  display: none !important;
}

/* ── Toast & overlays ── */
.toast {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 8px 16px;
  border-radius: 4px;
  background: rgba(10, 24, 40, 0.95);
  border: 1px solid rgba(74, 222, 128, 0.3);
  border-left: 3px solid var(--phosphor);
  color: var(--foam);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.25s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.ai-overlay {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(10, 24, 40, 0.9);
  border: 1px solid rgba(74, 222, 128, 0.3);
  color: var(--foam);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  pointer-events: none;
}

.radar-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--phosphor);
  animation: blink 0.8s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(4, 10, 18, 0.8);
  backdrop-filter: blur(8px);
  padding: 1rem;
}

.modal-card {
  position: relative;
  width: min(380px, 100%);
  text-align: center;
  padding: 1.75rem 1.5rem;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #1a2f45, #0a1628);
  border: 2px solid var(--brass-dark);
  box-shadow: inset 0 0 0 1px var(--brass), 0 24px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.modal-stamp {
  position: absolute;
  top: 12px;
  right: 12px;
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: var(--hit);
  border: 2px solid var(--hit);
  padding: 4px 8px;
  border-radius: 4px;
  transform: rotate(12deg);
  opacity: 0.85;
}

.modal-stamp.lose {
  color: var(--miss);
  border-color: var(--miss);
}

.modal-card h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  letter-spacing: 0.08em;
  margin: 0 0 0.5rem;
  color: var(--foam);
}

.modal-card p {
  color: var(--mist);
  margin: 0 0 0.75rem;
}

.modal-stats {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  color: rgba(148, 163, 184, 0.9);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}

.no-animations .cell.hit,
.no-animations .cell.miss,
.no-animations .cell.sunk,
.no-animations .board.sunk-shake,
.no-animations .turn-badge.your-turn,
.no-animations .toast,
.no-animations .sea-waves,
.no-animations .radar-sweep {
  animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .sea-waves,
  .radar-sweep,
  .board-wrap--enemy .board-frame::before {
    animation: none !important;
  }
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
}

.btn-icon svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ── Mobile ── */
@media (max-width: 900px) {
  .app {
    padding: 6px 10px calc(4px + env(safe-area-inset-bottom));
    padding-left: calc(10px + env(safe-area-inset-left));
    padding-right: calc(10px + env(safe-area-inset-right));
  }

  .brand,
  .radar-deco,
  .lead {
    display: none;
  }

  .game-header {
    margin-bottom: 2px;
  }

  #status {
    font-size: 0.85rem;
  }

  .match-hud {
    padding: 4px 6px;
    margin-bottom: 4px;
  }

  .hud-pic {
    width: 36px;
    height: 36px;
  }

  .hud-pic svg {
    width: 20px;
    height: 20px;
  }

  .hud-cluster--comfort {
    margin-left: 0;
  }

  .side-deck {
    display: none !important;
  }

  .battle-deck {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .game-stage {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    gap: 4px;
    min-height: 0;
    overflow: hidden;
  }

  .board-tabs {
    display: flex;
    grid-row: 1;
  }

  .board-wrap h2,
  .board-wrap .board-label {
    display: none;
  }

  .phase-place .board-wrap--enemy {
    display: none !important;
  }

  .phase-place .board-wrap--player {
    display: flex;
    grid-row: 2;
    min-height: 0;
    height: 100%;
    justify-content: flex-start;
    align-items: stretch;
  }

  .phase-battle .board-wrap {
    display: none;
  }

  .phase-battle .board-wrap.is-active {
    display: flex;
    grid-row: 2;
    min-height: 0;
    height: 100%;
    max-width: none;
    justify-content: flex-start;
    align-items: stretch;
  }

  .phase-over .board-wrap {
    display: none;
  }

  .phase-over .board-wrap.is-active {
    display: flex;
    grid-row: 2;
    min-height: 0;
    height: 100%;
    justify-content: flex-start;
    align-items: stretch;
  }

  .board-frame {
    padding: 6px;
    border-width: 2px;
  }

  .board-coords--top,
  .board-coords--left {
    font-size: 0.55rem;
  }

  .fleet-bar {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    overflow: visible;
    max-height: none;
    margin-bottom: 4px;
  }

  .fleet-chip {
    padding: 4px 6px;
    min-width: 0;
  }

  .fleet-chip .chip-label {
    display: none;
  }

  .ship-pips span {
    width: 6px;
    height: 10px;
    border-radius: 1px;
  }

  .btn-label {
    display: none;
  }

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

  .toolbar {
    gap: 6px;
    padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, var(--ocean-deep) 45%);
  }

  .btn {
    font-size: 0.78rem;
    padding: 8px 14px;
  }
}

@media (min-width: 901px) {
  .board-wrap {
    max-width: none;
  }

  .game-footer > .fleet-bar {
    display: none;
  }
}

.game-footer > .fleet-bar {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-bottom: 6px;
}
