/* ==========================================================================
   Battleship — styles
   ========================================================================== */

:root {
  --bg: #061226;
  --bg-2: #0b2147;
  --panel: rgba(12, 32, 64, 0.72);
  --panel-border: rgba(120, 190, 255, 0.14);
  --line: rgba(140, 200, 255, 0.13);
  --text: #e8f2ff;
  --muted: #8ea7c7;
  --accent: #39cfff;
  --accent-2: #22e3a6;
  --danger: #ff4d5e;
  --warn: #ffb547;
  --water-1: #0f3a70;
  --water-2: #0a2a55;
  --radius: 18px;
  --label: 20px;
  /* two panels side by side must fit: 2 × (board + label + panel chrome) + gap + page padding */
  --board: min(420px, calc(48vw - 90px), max(260px, calc(100vh - 210px)));
  --cell: calc(var(--board) / 10);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

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

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(57, 207, 255, 0.16), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(34, 227, 166, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 70%);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, select { font: inherit; color: inherit; }
button { touch-action: manipulation; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 2px 14px;
}

.logo {
  display: flex; align-items: center; gap: 10px;
  margin: 0;
  font-size: clamp(1.25rem, 2.6vw, 1.7rem);
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff, #9fd8ff);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.logo-mark { width: 1.3em; height: 1.3em; color: var(--accent); filter: drop-shadow(0 0 10px rgba(57, 207, 255, .5)); }

.controls { display: flex; align-items: center; gap: 8px; }

.select-wrap { position: relative; }
.select-wrap::after {
  content: ""; position: absolute; right: 12px; top: 50%; width: 7px; height: 7px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
select {
  appearance: none; -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 32px 8px 12px;
  cursor: pointer;
}
select:focus-visible, .btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select option { background: #0b2147; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .ico-off { display: none; }
.icon-btn[aria-pressed="false"] .ico-on { display: none; }
.icon-btn[aria-pressed="false"] .ico-off { display: block; color: var(--muted); }
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .2s, opacity .2s;
  user-select: none;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn kbd {
  font: 600 .7rem/1 var(--font);
  padding: 3px 5px; border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, .2);
  color: var(--muted);
}
.btn-primary {
  border: 0;
  color: #04233a;
  background: linear-gradient(180deg, #6fe3ff, #22b7f0);
  box-shadow: 0 6px 20px rgba(57, 207, 255, .35), inset 0 1px 0 rgba(255, 255, 255, .6);
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #8beaff, #3cc3f5); }
.btn-lg { width: 100%; padding: 14px 18px; font-size: 1.05rem; letter-spacing: .04em; }
.btn-primary.ready { animation: ready-pulse 1.6s ease-in-out infinite; }

@keyframes ready-pulse {
  0%, 100% { box-shadow: 0 6px 20px rgba(57, 207, 255, .35), 0 0 0 0 rgba(57, 207, 255, .5); }
  50%      { box-shadow: 0 6px 20px rgba(57, 207, 255, .35), 0 0 0 10px rgba(57, 207, 255, 0); }
}

/* ---------- Status ---------- */

.statusbar {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  margin-bottom: 14px;
}

.status {
  --c: var(--accent);
  display: inline-flex; align-items: center; gap: 10px;
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  box-shadow: 0 0 24px color-mix(in srgb, var(--c) 22%, transparent);
  font-weight: 700;
  letter-spacing: .02em;
  transition: border-color .3s, box-shadow .3s;
}
.status[data-turn="setup"]  { --c: var(--accent-2); }
.status[data-turn="player"] { --c: var(--accent); }
.status[data-turn="ai"]     { --c: var(--danger); }
.status[data-turn="win"]    { --c: #ffd257; }
.status[data-turn="lose"]   { --c: var(--danger); }

.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 0 var(--c);
  animation: dot-pulse 1.4s ease-out infinite;
}
.status[data-turn="ai"] .status-dot { animation-duration: .7s; }

@keyframes dot-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 70%, transparent); }
  100% { box-shadow: 0 0 0 10px transparent; }
}

.status-text.flip { animation: text-in .35s ease-out; }
@keyframes text-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.log {
  margin: 0;
  min-height: 1.3em;
  color: var(--muted);
  font-size: .92rem;
  text-align: center;
}
.log b { color: var(--text); }
.log .hit { color: #ff8a7a; }
.log .miss { color: #9fd8ff; }
.log .sunk { color: #ffd257; }

/* ---------- Layout ---------- */

.arena {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(16px, 3vw, 36px);
  flex-wrap: wrap;
}

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px 18px 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .05);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.panel-title {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 10px;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}
.tag { width: 8px; height: 8px; border-radius: 2px; }
.tag-blue { background: var(--accent); }
.tag-green { background: var(--accent-2); }
.tag-red { background: var(--danger); }

.app[data-phase="setup"] .panel-enemy { display: none; }
.app:not([data-phase="setup"]) .panel-setup { display: none; }
.app[data-phase="setup"] .fleet { display: none; }

/* ---------- Boards ---------- */

.board-frame {
  display: grid;
  grid-template-columns: var(--label) var(--board);
  grid-template-rows: var(--label) var(--board);
  grid-template-areas: ". top" "left board";
}

.labels {
  display: grid;
  color: var(--muted);
  font-size: max(9px, calc(var(--board) / 34));
  font-weight: 700;
  user-select: none;
}
.labels span { display: grid; place-items: center; }
.labels-top  { grid-area: top;  grid-template-columns: repeat(10, 1fr); }
.labels-left { grid-area: left; grid-template-rows: repeat(10, 1fr); }

.board {
  grid-area: board;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: var(--board);
  height: var(--board);
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 30% 0%, rgba(120, 200, 255, .18), transparent 60%),
    linear-gradient(160deg, var(--water-1), var(--water-2));
  box-shadow: 0 0 0 1px rgba(140, 200, 255, .22), 0 10px 30px rgba(0, 0, 0, .35);
  user-select: none;
  -webkit-user-select: none;
  transition: box-shadow .3s;
}

/* moving light on the water */
.board::before {
  content: "";
  position: absolute; inset: -50%;
  z-index: 0;
  background:
    repeating-linear-gradient(115deg, rgba(255, 255, 255, .035) 0 2px, transparent 2px 22px),
    repeating-linear-gradient(65deg, rgba(255, 255, 255, .025) 0 2px, transparent 2px 30px);
  animation: waves 18s linear infinite;
  pointer-events: none;
}
@keyframes waves { to { transform: translate(60px, 30px); } }

.board-enemy {
  background:
    radial-gradient(120% 80% at 70% 0%, rgba(255, 120, 140, .12), transparent 60%),
    linear-gradient(160deg, #13366a, #0b2550);
}

.board.active {
  box-shadow: 0 0 0 2px var(--accent), 0 0 34px rgba(57, 207, 255, .35), 0 10px 30px rgba(0, 0, 0, .35);
}
.board.under-fire {
  box-shadow: 0 0 0 2px var(--danger), 0 0 34px rgba(255, 77, 94, .3), 0 10px 30px rgba(0, 0, 0, .35);
}

.cell {
  position: relative;
  margin: 0; padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  border-radius: 0;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
.cell:nth-child(10n) { border-right: 0; }
.cell:nth-child(n + 91) { border-bottom: 0; }

.board-enemy .cell { cursor: not-allowed; }
.board-enemy.active .cell:not(.shot) { cursor: crosshair; }
.board-enemy .cell:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); z-index: 4; }

/* targeting reticle (hover + firing) */
@media (hover: hover) {
  .board-enemy.active .cell:not(.shot):hover { background: rgba(57, 207, 255, .14); }
  .board-enemy.active .cell:not(.shot):hover::after {
    content: "";
    position: absolute; inset: 14%;
    z-index: 4;
    border: 2px solid var(--accent);
    border-radius: 50%;
    background:
      linear-gradient(var(--accent), var(--accent)) center / 2px 100% no-repeat,
      linear-gradient(var(--accent), var(--accent)) center / 100% 2px no-repeat;
    opacity: .75;
    pointer-events: none;
  }
}
.cell.targeting::after,
.cell.incoming::after {
  content: "";
  position: absolute; inset: 14%;
  z-index: 4;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background:
    linear-gradient(var(--accent), var(--accent)) center / 2px 100% no-repeat,
    linear-gradient(var(--accent), var(--accent)) center / 100% 2px no-repeat;
  opacity: .9;
  pointer-events: none;
}
.cell.targeting::after, .cell.incoming::after { animation: lock-on .3s ease-in-out infinite alternate; }
.cell.incoming::after { border-color: var(--danger); --accent: var(--danger); }

@keyframes lock-on {
  from { transform: scale(1.35) rotate(0deg); opacity: .4; }
  to   { transform: scale(.9) rotate(45deg); opacity: 1; }
}

/* placement preview */
.cell.preview-ok::before,
.cell.preview-bad::before {
  content: "";
  position: absolute; inset: 2px;
  z-index: 2;
  border-radius: 6px;
  pointer-events: none;
}
.cell.preview-ok::before  { background: rgba(34, 227, 166, .28); box-shadow: inset 0 0 0 2px rgba(34, 227, 166, .8); }
.cell.preview-bad::before { background: rgba(255, 77, 94, .3);  box-shadow: inset 0 0 0 2px rgba(255, 77, 94, .85); }

/* ---------- Ships ---------- */

.ship {
  --len: 3;
  --bow: calc(var(--cell) * .95);
  --stern: calc(var(--cell) * .28);
  position: relative;
  z-index: 1;
  margin: 12%;
  margin: calc(var(--cell) * .1);
  border-radius: var(--bow) var(--stern) var(--stern) var(--bow) / 50% 40% 40% 50%;
  background: linear-gradient(180deg, #d8e3f0 0%, #9fb0c6 38%, #6d7f98 70%, #4f5f78 100%);
  box-shadow:
    0 4px 10px rgba(0, 0, 0, .45),
    inset 0 1px 0 rgba(255, 255, 255, .7),
    inset 0 -2px 0 rgba(0, 0, 0, .25);
  pointer-events: none;
  transition: filter .4s, opacity .3s;
}
.ship.v {
  border-radius: 50% 50% 40% 40% / var(--bow) var(--bow) var(--stern) var(--stern);
  background: linear-gradient(90deg, #d8e3f0 0%, #9fb0c6 38%, #6d7f98 70%, #4f5f78 100%);
}
/* deck strip */
.ship::before {
  content: "";
  position: absolute;
  inset: 34% 12% 34% 18%;
  border-radius: 999px;
  background: rgba(40, 56, 80, .45);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .3);
}
.ship.v::before { inset: 18% 34% 12% 34%; }
/* turrets / hatches — one per segment */
.ship::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle, #33455f 0 17%, rgba(255, 255, 255, .35) 18% 21%, transparent 22%) 0 0 / calc(100% / var(--len)) 100% repeat-x;
}
.ship.v::after { background-size: 100% calc(100% / var(--len)); background-repeat: repeat-y; }

.board-player .ship.draggable { pointer-events: auto; cursor: grab; touch-action: none; }
.board-player .ship.draggable:hover { filter: brightness(1.12); }
.ship.lifted { opacity: .25; }
.ship.drop { animation: ship-drop .32s cubic-bezier(.3, 1.6, .5, 1); }
.ship.nope { animation: nope .35s; }

@keyframes ship-drop {
  0%   { transform: scale(1.12); filter: brightness(1.4); }
  100% { transform: scale(1); filter: none; }
}
@keyframes nope {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); } 40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(3px); }
}

.ship.sunk {
  filter: grayscale(.4) sepia(.7) hue-rotate(-35deg) saturate(2.2) brightness(.55);
  animation: sink 1.2s ease-out both;
}
@keyframes sink {
  0%   { transform: none; filter: none; }
  30%  { transform: rotate(-2deg) scale(1.03); }
  100% { transform: rotate(1deg) scale(.96); }
}
.board-enemy .ship.sunk { animation: reveal .6s ease-out both; }
@keyframes reveal {
  from { opacity: 0; transform: scale(1.25); }
  to   { opacity: 1; transform: scale(.96); }
}
.ship.revealed {
  opacity: .55;
  outline: 2px dashed rgba(255, 210, 87, .8);
  outline-offset: 1px;
  animation: reveal .6s ease-out both;
}

/* drag ghost */
.ship.ghost {
  position: fixed;
  left: 0; top: 0;
  z-index: 1000;
  margin: 0;
  opacity: .92;
  pointer-events: none;
  box-shadow: 0 16px 30px rgba(0, 0, 0, .55), 0 0 0 2px rgba(34, 227, 166, .7);
  will-change: transform;
}
.ship.ghost.bad { box-shadow: 0 16px 30px rgba(0, 0, 0, .55), 0 0 0 2px rgba(255, 77, 94, .85); }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

/* ---------- Shot markers ---------- */

.mark {
  position: absolute; inset: 0;
  z-index: 3;
  pointer-events: none;
}
.mark::before, .mark::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* miss: splash ripple + buoy dot */
.mark.miss::before {
  width: 28%; height: 28%;
  background: radial-gradient(circle at 35% 35%, #fff, #b9e3ff 55%, #6cb6e6);
  box-shadow: 0 0 6px rgba(185, 227, 255, .6);
  animation: drop-in .35s ease-out both;
}
.mark.miss::after {
  width: 90%; height: 90%;
  border: 2px solid rgba(200, 235, 255, .9);
  animation: ripple .8s ease-out forwards;
}
@keyframes drop-in {
  0%   { transform: translate(-50%, -50%) scale(2.2); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: .9; }
}
@keyframes ripple {
  0%   { transform: translate(-50%, -50%) scale(.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

/* hit: explosion burst + burning core */
.mark.hit::before {
  width: 62%; height: 62%;
  background: radial-gradient(circle, #fff6c4 0 14%, #ffb23c 34%, #ff4d3d 60%, rgba(255, 60, 40, 0) 72%);
  filter: drop-shadow(0 0 6px rgba(255, 90, 50, .9));
  animation: ignite .45s ease-out both, flicker 1.1s ease-in-out .45s infinite alternate;
}
.mark.hit::after {
  width: 150%; height: 150%;
  background: radial-gradient(circle, rgba(255, 240, 180, .95) 0 12%, rgba(255, 150, 50, .8) 30%, rgba(255, 60, 40, .35) 52%, transparent 70%);
  animation: burst .6s ease-out forwards;
}
@keyframes ignite {
  0%   { transform: translate(-50%, -50%) scale(.2); }
  60%  { transform: translate(-50%, -50%) scale(1.25); }
  100% { transform: translate(-50%, -50%) scale(1); }
}
@keyframes flicker {
  0%   { transform: translate(-50%, -50%) scale(.92); opacity: .85; }
  100% { transform: translate(-50%, -50%) scale(1.06); opacity: 1; }
}
@keyframes burst {
  0%   { transform: translate(-50%, -50%) scale(.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
}

.cell.sunk .mark.hit::before {
  width: 46%; height: 46%;
  background: radial-gradient(circle, #ffcf8a 0 12%, #ff6a3d 36%, #9e1b1b 64%, rgba(120, 20, 20, 0) 74%);
  filter: drop-shadow(0 0 4px rgba(255, 70, 40, .7));
}
.board-enemy .cell.hit { background: rgba(255, 77, 94, .12); }
.board-enemy .cell.sunk { background: rgba(255, 77, 94, .06); }

.cell.last { box-shadow: inset 0 0 0 2px rgba(255, 210, 87, .85); }

/* board shake on impact */
.board.shake { animation: shake .45s cubic-bezier(.36, .07, .19, .97); }
.board.shake-big { animation: shake-big .7s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  10%, 90% { transform: translate(-1px, 0); }
  20%, 80% { transform: translate(2px, 1px); }
  30%, 50%, 70% { transform: translate(-3px, -1px); }
  40%, 60% { transform: translate(3px, 1px); }
}
@keyframes shake-big {
  10%, 90% { transform: translate(-2px, 1px) rotate(-.3deg); }
  20%, 80% { transform: translate(4px, -1px) rotate(.3deg); }
  30%, 50%, 70% { transform: translate(-6px, 2px) rotate(-.5deg); }
  40%, 60% { transform: translate(6px, -2px) rotate(.5deg); }
}

/* ---------- Fleet status ---------- */

.fleet {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px 14px;
  max-width: calc(var(--board) + var(--label));
}
.fleet-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: .85rem;
  font-weight: 600;
  transition: opacity .3s;
}
.fleet-name { white-space: nowrap; }
.pips { display: flex; gap: 3px; }
.pips i {
  width: 11px; height: 11px;
  border-radius: 3px;
  background: rgba(160, 190, 225, .45);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .25);
  transition: background .3s;
}
.pips i.hit { background: #ff6a4d; box-shadow: 0 0 6px rgba(255, 106, 77, .7); }
.fleet-item.sunk { opacity: .55; }
.fleet-item.sunk .fleet-name { text-decoration: line-through; text-decoration-color: var(--danger); text-decoration-thickness: 2px; }
.fleet-item.sunk .pips i { background: #8a2430; box-shadow: none; }
.fleet-item.just-sunk { animation: fleet-flash .9s ease-out; }
@keyframes fleet-flash { 0%, 40% { color: #ffd257; transform: scale(1.06); } 100% { transform: none; } }

/* ---------- Setup panel ---------- */

.panel-setup {
  width: calc(var(--board) + var(--label) + 36px);
  display: flex; flex-direction: column; gap: 14px;
}
.panel-setup .panel-title { margin-bottom: 0; }
.hint { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.45; }
.hint strong { color: var(--text); }

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

.dock-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 10px 8px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, .04);
  cursor: grab;
  touch-action: none;
  transition: background .15s, border-color .15s, opacity .2s;
}
.dock-item:hover { background: rgba(255, 255, 255, .08); }
.dock-item.selected { border-color: var(--accent-2); background: rgba(34, 227, 166, .1); box-shadow: 0 0 18px rgba(34, 227, 166, .15); }
.dock-item.placed { opacity: .45; cursor: pointer; }
.dock-item.placed .dock-ship { filter: grayscale(.7); }
.dock-item.dragging { opacity: .35; }

.dock-meta { display: flex; flex-direction: column; line-height: 1.2; }
.dock-name { font-weight: 700; font-size: .92rem; }
.dock-len { font-size: .75rem; color: var(--muted); }
.dock-item.placed .dock-len::after { content: " · placed ✓"; color: var(--accent-2); }

.dock-ship {
  flex: none;
  width: calc(var(--cell) * var(--len) * .8);
  height: calc(var(--cell) * .8);
  margin: 0;
  --bow: calc(var(--cell) * .75);
  --stern: calc(var(--cell) * .22);
}

.setup-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.setup-actions .btn { flex: 1 1 auto; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%; top: 18%;
  z-index: 50;
  padding: 12px 22px;
  border-radius: 14px;
  font-weight: 800;
  font-size: clamp(1rem, 2.6vw, 1.35rem);
  letter-spacing: .03em;
  text-align: center;
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  background: rgba(8, 24, 48, .92);
  border: 1px solid rgba(255, 255, 255, .15);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
  opacity: 0;
  transform: translate(-50%, -12px) scale(.94);
  pointer-events: none;
  transition: opacity .25s, transform .25s cubic-bezier(.3, 1.5, .5, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast.good { border-color: rgba(255, 210, 87, .7); color: #ffe39a; box-shadow: 0 16px 40px rgba(0, 0, 0, .5), 0 0 30px rgba(255, 210, 87, .25); }
.toast.bad  { border-color: rgba(255, 77, 94, .7); color: #ffb3ba; box-shadow: 0 16px 40px rgba(0, 0, 0, .5), 0 0 30px rgba(255, 77, 94, .25); }
.toast.info { color: var(--text); }

/* ---------- Modal ---------- */

.modal {
  position: fixed; inset: 0;
  z-index: 100;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(3, 10, 22, .66);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in .3s ease-out;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(420px, 100%);
  padding: 28px 24px 22px;
  border-radius: 22px;
  text-align: center;
  background: linear-gradient(180deg, #123063, #0a1d3f);
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
  animation: pop-in .45s cubic-bezier(.3, 1.5, .5, 1);
}
.modal-card h2 { margin: 6px 0 4px; font-size: 2rem; letter-spacing: .06em; text-transform: uppercase; }
.modal-card p { margin: 0 0 16px; color: var(--muted); }
.modal.win h2 { color: #ffd257; text-shadow: 0 0 24px rgba(255, 210, 87, .45); }
.modal.lose h2 { color: #ff7a86; text-shadow: 0 0 24px rgba(255, 77, 94, .4); }
.modal-emblem { font-size: 3.4rem; line-height: 1; animation: bob 2.4s ease-in-out infinite; }

.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin: 0 0 20px;
}
.stats div { padding: 10px 6px; border-radius: 12px; background: rgba(255, 255, 255, .06); }
.stats dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.stats dd { margin: 4px 0 0; font-size: 1.35rem; font-weight: 800; }

.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; padding: 12px; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(20px) scale(.9); } }
@keyframes bob { 50% { transform: translateY(-6px); } }

/* ---------- Confetti ---------- */

.confetti { position: fixed; inset: 0; z-index: 120; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px;
  width: 9px; height: 14px;
  border-radius: 2px;
  animation: confetti-fall var(--d, 3s) cubic-bezier(.2, .6, .4, 1) var(--delay, 0s) forwards;
}
@keyframes confetti-fall {
  to { transform: translate(var(--x, 0), 110vh) rotate(var(--r, 720deg)); opacity: .8; }
}

/* ---------- Responsive ---------- */

@media (max-width: 760px) {
  :root {
    --label: 16px;
    --board: min(440px, calc(100vw - 64px));
  }
  .app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .topbar { padding-bottom: 10px; }
  .logo { letter-spacing: .1em; }
  .btn { padding: 8px 12px; }
  .icon-btn { width: 38px; height: 38px; }
  .panel { padding: 12px 12px 14px; }
  .arena { gap: 14px; }
  .panel-setup { width: calc(var(--board) + var(--label) + 26px); }

  /* In battle the enemy grid comes first; your own grid shrinks next to the fleet list */
  .app:not([data-phase="setup"]) .panel-enemy { order: -1; }
  .app:not([data-phase="setup"]) .panel-player {
    --board: calc((100vw - 64px) * .6);
    --cell: calc(var(--board) / 10);
    width: calc(100vw - 20px);
    max-width: 480px;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    column-gap: 12px;
  }
  .app:not([data-phase="setup"]) .panel-player .panel-title { grid-column: 1 / -1; }
  .app:not([data-phase="setup"]) .panel-player .fleet {
    margin-top: var(--label);
    grid-template-columns: 1fr;
    gap: 7px;
  }
  .fleet { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 5px 12px; }
  .fleet-item { font-size: .78rem; }
  .app:not([data-phase="setup"]) .panel-player .fleet-item { flex-direction: column; align-items: flex-start; gap: 3px; }
  .pips i { width: 9px; height: 9px; }
  .toast { top: 12%; white-space: normal; }
}

@media (max-width: 380px) {
  .logo span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
