:root {
  --bg0: #020b14;
  --bg1: #072238;
  --panel: rgba(9, 28, 46, 0.78);
  --panel-edge: rgba(140, 205, 255, 0.22);
  --line: rgba(150, 215, 255, 0.13);
  --text: #e6f3ff;
  --muted: #8fb3cc;
  --brass: #ffb627;
  --brass-2: #ffd77a;
  --sonar: #39d0ff;
  --danger: #ff4d3d;
  --ok: #48f0a0;
  --n: 10;
  --cell: clamp(14px, min(calc(33vw / var(--n)), calc(54vh / var(--n))), 42px);
  --lab: max(18px, calc(var(--cell) * 0.62));
  --radius: 16px;
  --font-head: 'Russo One', 'Arial Black', system-ui, sans-serif;
  --font: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg0);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; }
kbd {
  font: 600 0.85em var(--font);
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.06);
}

/* ---------- Океан на фоне ---------- */

.ocean {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(57, 208, 255, 0.18), transparent 60%),
    linear-gradient(180deg, #06263f 0%, #041a2c 45%, #020b14 100%);
}
.ocean::before {
  content: '';
  position: absolute;
  inset: -512px;
  background-image: var(--tex-water);
  background-size: 512px;
  opacity: 0.35;
  mix-blend-mode: soft-light;
  animation: drift 90s linear infinite;
}
.ocean-caustics {
  position: absolute;
  inset: -512px;
  background-image: var(--tex-caustic-a);
  background-size: 512px;
  opacity: 0.09;
  animation: drift 60s linear infinite reverse;
}
.ocean-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.65) 100%);
}
@keyframes drift { to { transform: translate(512px, 512px); } }

/* ---------- Шапка ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px max(16px, env(safe-area-inset-left));
  max-width: 1200px;
  margin: 0 auto;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-head);
  font-size: 18px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.logo-anchor {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--brass-2), #b07405);
  box-shadow: 0 0 18px rgba(255, 182, 39, 0.45), inset 0 -3px 6px rgba(0, 0, 0, 0.35);
  font-size: 19px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.room-pill, .net {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--muted);
}
.room-pill b { color: var(--brass); letter-spacing: 0.12em; }
.net i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.net.off i { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  cursor: pointer;
  font-size: 17px;
  transition: transform 0.15s;
}
.icon-btn:hover { transform: scale(1.08); }

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

/* ---------- Карточки и кнопки ---------- */

.card {
  position: relative;
  background:
    var(--tex-grain),
    linear-gradient(180deg, rgba(20, 50, 78, 0.85), rgba(8, 24, 40, 0.92));
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
}

.btn {
  position: relative;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  background: linear-gradient(180deg, rgba(60, 100, 140, 0.55), rgba(25, 50, 75, 0.7));
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, filter 0.2s;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 4px 12px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  border-color: rgba(255, 215, 122, 0.7);
  background: linear-gradient(180deg, #ffd77a, #f0a10c 55%, #c47d00);
  color: #2a1700;
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 6px 18px rgba(240, 161, 12, 0.35);
}
.btn-primary:not(:disabled):hover { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 8px 26px rgba(240, 161, 12, 0.55); }
.btn-big { padding: 14px 22px; font-size: 18px; font-family: var(--font-head); letter-spacing: 0.04em; font-weight: 400; }
.btn-small { padding: 6px 12px; font-size: 13px; }

.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  background: rgba(2, 12, 22, 0.6);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input:focus { border-color: var(--sonar); box-shadow: 0 0 0 3px rgba(57, 208, 255, 0.2); }

/* ---------- Главный экран ---------- */

#home { display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 10px; }
.hero { position: relative; width: min(520px, 90vw); height: 150px; overflow: hidden; }
.hero-ship {
  position: absolute;
  left: 50%;
  top: 30px;
  width: min(360px, 70vw);
  transform: translateX(-50%);
  animation: bob 4s ease-in-out infinite;
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.5));
}
.hero-ship svg { display: block; width: 100%; height: auto; }
@keyframes bob {
  0%, 100% { transform: translateX(-50%) translateY(0) rotate(-1deg); }
  50% { transform: translateX(-50%) translateY(6px) rotate(1deg); }
}
.hero-waves i {
  position: absolute;
  left: -50%;
  width: 200%;
  height: 40px;
  bottom: 0;
  background: radial-gradient(ellipse 30px 10px at 30px 0, transparent 70%, rgba(57, 208, 255, 0.25) 72%, transparent 80%) repeat-x;
  background-size: 60px 20px;
  animation: waves 6s linear infinite;
}
.hero-waves i:nth-child(2) { bottom: 14px; opacity: 0.6; animation-duration: 9s; animation-direction: reverse; }
.hero-waves i:nth-child(3) { bottom: 28px; opacity: 0.3; animation-duration: 12s; }
@keyframes waves { to { transform: translateX(60px); } }

.title {
  margin: 6px 0 4px;
  font-family: var(--font-head);
  font-weight: 400;
  font-size: clamp(38px, 8vw, 76px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #ffffff 0%, #cfe9ff 40%, #6aaedb 52%, #e6f5ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 #0b2a44) drop-shadow(0 0 24px rgba(57, 208, 255, 0.35));
}
.subtitle { color: var(--muted); margin: 0 0 26px; font-size: 17px; max-width: 520px; }
.home-card { width: min(420px, 100%); padding: 24px; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.field-label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.rules { margin: 8px 0 0; padding: 14px 0 0 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; line-height: 1.7; }

/* ---------- Экран игры ---------- */

.banner {
  width: fit-content;
  max-width: 100%;
  margin: 4px auto 14px;
  padding: 12px 28px;
  border-radius: 999px;
  font-family: var(--font-head);
  font-size: clamp(17px, 2.4vw, 24px);
  letter-spacing: 0.03em;
  text-align: center;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  transition: background 0.3s, box-shadow 0.3s, color 0.3s;
}
.banner.pop { animation: pop 0.45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(0.85); opacity: 0.4; } }
.banner.mine {
  color: #2a1700;
  border-color: var(--brass-2);
  background: linear-gradient(180deg, #ffd77a, #f0a10c);
  box-shadow: 0 0 30px rgba(255, 182, 39, 0.5);
  animation: glow 1.6s ease-in-out infinite;
}
.banner.mine.pop { animation: pop 0.45s cubic-bezier(.2, 1.6, .4, 1), glow 1.6s ease-in-out 0.45s infinite; }
@keyframes glow { 50% { box-shadow: 0 0 46px rgba(255, 182, 39, 0.8); } }
.banner.theirs { color: var(--sonar); border-color: rgba(57, 208, 255, 0.4); }
.banner.win { color: #2a1700; background: linear-gradient(180deg, #fff1b8, #ffc740); cursor: pointer; }
.banner.lose { color: #ffd3cf; background: linear-gradient(180deg, #7a1d16, #3d0d09); border-color: #b23a2e; cursor: pointer; }

.opp-off {
  margin: -6px auto 12px;
  width: fit-content;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  color: #ffd3cf;
  background: rgba(255, 77, 61, 0.15);
  border: 1px solid rgba(255, 77, 61, 0.4);
}

.invite { max-width: 640px; margin: 0 auto 18px; padding: 16px 18px; }
.invite-title { font-family: var(--font-head); margin-bottom: 10px; color: var(--brass-2); }
.invite-row { display: flex; gap: 8px; }
.invite-link { font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.invite-hint { margin-top: 10px; font-size: 13px; line-height: 1.5; color: #ffd9a0; }

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

.panel {
  position: relative;
  padding: 16px 18px 18px;
  border-radius: 20px;
  background:
    var(--tex-grain),
    linear-gradient(160deg, rgba(56, 74, 92, 0.55), rgba(16, 28, 40, 0.85) 40%, rgba(10, 20, 30, 0.92));
  border: 1px solid rgba(170, 200, 225, 0.25);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.12), inset 0 0 0 4px rgba(0, 0, 0, 0.18);
  transition: box-shadow 0.4s, border-color 0.4s;
}
/* Заклёпки по углам */
.panel::before, .panel::after {
  content: '';
  position: absolute;
  top: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #dfe8ef, #5a6772 70%);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
}
.panel::before { left: 8px; }
.panel::after { right: 8px; }
.panel.active { border-color: rgba(255, 215, 122, 0.7); box-shadow: 0 0 0 1px rgba(255, 182, 39, 0.4), 0 0 40px rgba(255, 182, 39, 0.25), 0 24px 60px rgba(0, 0, 0, 0.5); }
#panel-me.active { border-color: rgba(255, 77, 61, 0.55); box-shadow: 0 0 0 1px rgba(255, 77, 61, 0.3), 0 0 40px rgba(255, 77, 61, 0.18), 0 24px 60px rgba(0, 0, 0, 0.5); }

.panel-head { position: relative; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 4px 10px; }
.who { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; min-width: 0; }
.who span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-caption { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #4a5a68; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.off { background: var(--danger); animation: blink 1s infinite; }

.bubble {
  position: absolute;
  right: 0;
  top: -46px;
  max-width: 260px;
  padding: 8px 12px;
  border-radius: 14px 14px 4px 14px;
  background: #f4fbff;
  color: #0b2236;
  font-size: 15px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  z-index: 5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bubble.pop { animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }

/* ---------- Поле ---------- */

.board {
  display: grid;
  grid-template-columns: var(--lab) calc(var(--cell) * var(--n));
  grid-template-rows: var(--lab) calc(var(--cell) * var(--n));
  user-select: none;
  -webkit-user-select: none;
}
.labels { display: flex; color: var(--muted); font-size: max(9px, calc(var(--cell) * 0.36)); font-weight: 500; }
.labels span { display: grid; place-items: center; transition: color 0.15s, text-shadow 0.15s; }
.labels-top span { width: var(--cell); }
.labels-left { flex-direction: column; }
.labels-left span { height: var(--cell); }
.labels span.hl { color: var(--brass-2); text-shadow: 0 0 8px rgba(255, 182, 39, 0.7); }

.field {
  position: relative;
  width: calc(var(--cell) * var(--n));
  height: calc(var(--cell) * var(--n));
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(150, 215, 255, 0.25), inset 0 0 30px rgba(0, 0, 0, 0.6);
}
.water { position: absolute; inset: 0; background-image: var(--tex-water); background-size: 256px; }
.water::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(120, 220, 255, 0.18), transparent 60%), radial-gradient(ellipse at center, transparent 50%, rgba(0, 10, 25, 0.55));
}
.caustic {
  position: absolute;
  inset: -256px;
  background-size: 256px;
  mix-blend-mode: screen;
  pointer-events: none;
}
.caustic.a { background-image: var(--tex-caustic-a); opacity: 0.35; animation: drift-sm 22s linear infinite; }
.caustic.b { background-image: var(--tex-caustic-b); opacity: 0.25; animation: drift-sm 31s linear infinite reverse; }
@keyframes drift-sm { to { transform: translate(256px, 256px); } }

.board-enemy .water { filter: hue-rotate(-12deg) saturate(0.85) brightness(0.85); }

.ships { position: absolute; inset: 0; pointer-events: none; }
.ship {
  position: absolute;
  left: calc(var(--c) * var(--cell));
  top: calc(var(--r) * var(--cell));
  width: calc(var(--w) * var(--cell));
  height: calc(var(--h) * var(--cell));
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.5));
  animation: sway 5s ease-in-out infinite;
  transition: left 0.6s cubic-bezier(.4, 0, .2, 1), top 0.6s cubic-bezier(.4, 0, .2, 1);
}
.ship svg { display: block; width: 100%; height: 100%; }
.ship.enter { animation: drop-in 0.35s cubic-bezier(.2, 1.4, .4, 1), sway 5s ease-in-out 0.35s infinite; }
@keyframes drop-in { from { transform: scale(1.35); opacity: 0; } }
@keyframes sway { 50% { transform: translateY(1px) scale(1.01); } }
.ship.sunk { animation: none; filter: grayscale(0.6) sepia(0.6) brightness(0.62) contrast(1.15) drop-shadow(0 0 4px rgba(255, 60, 20, 0.45)); }
.ship.sunk.enter { animation: sink 1.2s ease-out; }
@keyframes sink { from { filter: none; opacity: 1; transform: scale(1.06); } }
.ship.ghost { opacity: 0.55; filter: saturate(0.6) drop-shadow(0 0 6px rgba(255, 215, 122, 0.6)); animation: none; }

.cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n), var(--cell));
  grid-template-rows: repeat(var(--n), var(--cell));
}
.cell {
  position: relative;
  box-shadow: inset -1px -1px 0 var(--line);
  transition: background-color 0.15s;
}

.radar {
  position: absolute;
  inset: -50%;
  pointer-events: none;
  background: conic-gradient(from 0deg, transparent 0deg 300deg, rgba(57, 208, 255, 0.05) 330deg, rgba(57, 208, 255, 0.22) 360deg);
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 0.6s;
  animation: spin 7s linear infinite;
}
.board-enemy.radar-on .radar { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

.panel.empty .field::after {
  content: 'Ожидание соперника';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-head);
  color: rgba(230, 243, 255, 0.75);
  background: rgba(2, 12, 22, 0.5);
  letter-spacing: 0.05em;
  animation: blink 2.4s ease-in-out infinite;
}

/* Прицел */
.board-enemy.armed .cell.free { cursor: crosshair; }
.board-enemy.armed .cell.free:hover {
  background: rgba(255, 182, 39, 0.16);
  box-shadow: inset 0 0 0 2px var(--brass);
}
.board-enemy.armed .cell.free:hover::before,
.board-enemy.armed .cell.free:hover::after { content: ''; position: absolute; pointer-events: none; }
.board-enemy.armed .cell.free:hover::before {
  inset: 18%;
  border: 2px solid var(--brass-2);
  border-radius: 50%;
  animation: aim 0.9s ease-in-out infinite;
}
.board-enemy.armed .cell.free:hover::after {
  inset: 0;
  background:
    linear-gradient(var(--brass-2), var(--brass-2)) center / 2px 34% no-repeat,
    linear-gradient(var(--brass-2), var(--brass-2)) center / 34% 2px no-repeat;
}
@keyframes aim { 50% { transform: scale(0.8); } }
.board-enemy:not(.armed) .cells { cursor: default; }

/* Расстановка */
.board-me.placing .cell { cursor: pointer; }
.cell.pv-ok { background: rgba(72, 240, 160, 0.32); box-shadow: inset 0 0 0 1px rgba(72, 240, 160, 0.8); }
.cell.pv-bad { background: rgba(255, 77, 61, 0.35); box-shadow: inset 0 0 0 1px rgba(255, 77, 61, 0.9); }

/* ---------- Отметки выстрелов ---------- */

.mk { position: absolute; pointer-events: none; }

.splash {
  left: 50%;
  top: 50%;
  width: 28%;
  height: 28%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffff, #9fdcff 60%, #3a8fc0);
  box-shadow: 0 0 6px rgba(160, 225, 255, 0.8);
}
.splash::after {
  content: '';
  position: absolute;
  inset: -60%;
  border-radius: 50%;
  border: 1.5px solid rgba(180, 235, 255, 0.5);
  animation: ripple 2.6s ease-out infinite;
}
@keyframes ripple { from { transform: scale(0.4); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
.cell.fresh .splash { animation: plop 0.4s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes plop { from { transform: translate(-50%, -50%) scale(0); } }
.cell .mk.spot {
  left: 50%;
  top: 50%;
  width: 14%;
  height: 14%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(170, 220, 250, 0.55);
  animation: none;
  box-shadow: none;
}
.cell.fresh .mk.spot { animation: fade-in 0.6s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translate(-50%, -50%) scale(2.5); } }

.cell.hit, .cell.sunk { background: radial-gradient(circle, rgba(255, 110, 40, 0.35), rgba(120, 20, 0, 0.15) 70%); }
.cell.sunk { background: radial-gradient(circle, rgba(60, 10, 0, 0.55), rgba(10, 0, 0, 0.35)); }

.fire { inset: 0; }
.fire i {
  position: absolute;
  left: 50%;
  bottom: 30%;
  width: 34%;
  height: 34%;
  margin-left: -17%;
  border-radius: 50% 0 50% 50%;
  transform: rotate(-45deg);
  background: radial-gradient(circle at 60% 40%, #fff6c8 0%, #ffd23f 30%, #ff7a1a 60%, rgba(220, 40, 0, 0.0) 80%);
  filter: blur(0.4px);
  mix-blend-mode: screen;
  animation: flicker 0.6s ease-in-out infinite alternate;
  transform-origin: 50% 100%;
}
.fire i:nth-child(2) { width: 26%; height: 26%; margin-left: -25%; bottom: 26%; animation-delay: -0.2s; animation-duration: 0.45s; }
.fire i:nth-child(3) { width: 24%; height: 24%; margin-left: -2%; bottom: 24%; animation-delay: -0.35s; animation-duration: 0.52s; }
@keyframes flicker {
  0% { transform: rotate(-45deg) scale(1); opacity: 0.95; }
  50% { transform: rotate(-40deg) scale(1.18) translate(-1px, -1px); opacity: 1; }
  100% { transform: rotate(-50deg) scale(0.88); opacity: 0.8; }
}
.cell.fresh .fire { animation: ignite 0.4s ease-out; }
@keyframes ignite { from { transform: scale(2); opacity: 0; } }
.cell.sunk .fire i { filter: blur(0.6px) saturate(0.8); opacity: 0.6; transform-origin: 50% 100%; }
.cell.sunk .fire i:nth-child(1) { width: 22%; height: 22%; margin-left: -11%; }

.smoke { inset: 0; }
.smoke i {
  position: absolute;
  left: 40%;
  top: 30%;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(70, 70, 76, 0.75), rgba(40, 40, 44, 0));
  animation: smoke 2.2s ease-out infinite;
}
.smoke i:nth-child(2) { left: 52%; animation-delay: -1.1s; }
@keyframes smoke {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  20% { opacity: 0.9; }
  100% { transform: translate(6px, calc(var(--cell) * -0.9)) scale(2.2); opacity: 0; }
}
.cell.sunk .smoke i { background: radial-gradient(circle, rgba(30, 30, 34, 0.85), rgba(20, 20, 24, 0)); }

/* ---------- Флот и док ---------- */

.fleet { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 12px 4px 0; min-height: 18px; }
.fl { width: calc(var(--len) * 16px); height: 16px; display: inline-block; position: relative; transition: opacity 0.4s; }
.fl svg { width: 100%; height: 100%; display: block; }
.fl.dead { opacity: 0.35; filter: grayscale(1); }
.fl.dead::after {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  height: 2px;
  background: var(--danger);
  transform: rotate(-8deg);
  box-shadow: 0 0 4px var(--danger);
}
.fl-count { margin-left: auto; font-size: 13px; color: var(--muted); font-weight: 500; }

.placement { margin-top: 14px; }
.dock { display: flex; flex-wrap: wrap; gap: 8px; }
.dock-ship {
  width: calc(var(--len) * 30px + 14px);
  height: 44px;
  padding: 6px 7px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: rgba(2, 14, 26, 0.55);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, opacity 0.3s, box-shadow 0.2s;
}
.dock-ship svg { width: 100%; height: 100%; display: block; }
.dock-ship:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--sonar); }
.dock-ship.selected { border-color: var(--brass); box-shadow: 0 0 0 2px rgba(255, 182, 39, 0.35), 0 0 18px rgba(255, 182, 39, 0.35); }
.dock-ship.placed { opacity: 0.18; cursor: default; }
.dock-hint { margin: 10px 2px; font-size: 13px; color: var(--muted); line-height: 1.5; max-width: calc(var(--cell) * var(--n) + var(--lab)); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions #ready-btn { margin-left: auto; }

.waiting { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--muted); font-size: 14px; flex-wrap: wrap; }
.waiting .btn { margin-left: auto; }
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(57, 208, 255, 0.25);
  border-top-color: var(--sonar);
  animation: spin 0.8s linear infinite;
}

/* ---------- Чат ---------- */

.chat { max-width: 860px; margin: 22px auto 0; padding: 12px; }
.chat-log { max-height: 140px; min-height: 40px; overflow-y: auto; padding: 4px 6px 8px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.chat-log:empty::before { content: 'Чат с соперником'; color: var(--muted); opacity: 0.6; }
.msg b { margin-right: 6px; }
.msg.mine b { color: var(--brass-2); }
.msg.theirs b { color: var(--sonar); }
.msg span { word-break: break-word; }
.chat-form { display: flex; gap: 8px; align-items: center; }
.chat-form .input { padding: 9px 12px; }
.emojis { display: flex; gap: 2px; }
.emoji { background: none; border: 0; font-size: 19px; cursor: pointer; padding: 4px; border-radius: 8px; transition: transform 0.12s, background 0.12s; }
.emoji:hover { transform: scale(1.2); background: rgba(255, 255, 255, 0.07); }

/* ---------- Оверлеи ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(2, 12, 24, 0.55), rgba(0, 0, 0, 0.82));
  animation: fade 0.4s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.result { width: min(460px, 100%); padding: 30px 26px 24px; text-align: center; animation: rise 0.5s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes rise { from { transform: translateY(30px) scale(0.92); opacity: 0; } }
.result-icon { font-size: 62px; line-height: 1; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5)); }
.result.win .result-icon { animation: trophy 1.6s ease-in-out infinite; }
@keyframes trophy { 50% { transform: translateY(-6px) rotate(-4deg); } }
.result-title { margin: 12px 0 6px; font-family: var(--font-head); font-weight: 400; font-size: 42px; letter-spacing: 0.03em; }
.result.win .result-title { background: linear-gradient(180deg, #fff6d2, #ffc23a 60%, #d68a00); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result.lose .result-title { color: #ff8a7d; }
.result-sub { margin: 0 0 18px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 20px; }
.stat { padding: 10px 4px; border-radius: 12px; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); }
.stat b { display: block; font-family: var(--font-head); font-weight: 400; font-size: 22px; color: var(--brass-2); }
.stat span { font-size: 11px; color: var(--muted); }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.rematch-note { min-height: 20px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.rematch-note.hot { color: var(--brass-2); animation: blink 1.2s infinite; }

#fx { position: fixed; inset: 0; z-index: 30; pointer-events: none; }

.float-text {
  position: fixed;
  z-index: 35;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-family: var(--font-head);
  font-size: 22px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6), 0 0 12px currentColor;
  animation: float-up 1.4s ease-out forwards;
}
.float-text.miss { color: #bfe9ff; font-size: 18px; }
.float-text.hit { color: #ffb24a; }
.float-text.sunk { color: #ff5a45; font-size: 28px; }
@keyframes float-up {
  0% { transform: translate(-50%, -30%) scale(0.6); opacity: 0; }
  15% { transform: translate(-50%, -80%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -200%) scale(1); opacity: 0; }
}

.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(8, 26, 42, 0.95);
  border: 1px solid var(--panel-edge);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 15px;
  animation: rise 0.35s cubic-bezier(.2, 1.3, .4, 1);
  transition: opacity 0.4s, transform 0.4s;
}
.toast.good { border-color: rgba(255, 215, 122, 0.6); color: var(--brass-2); }
.toast.bad { border-color: rgba(255, 77, 61, 0.6); color: #ffb3aa; }
.toast.out { opacity: 0; transform: translateY(10px); }

/* ---------- Мобильные ---------- */

@media (max-width: 860px) {
  :root {
    --cell: min(calc((100vw - 32px - 36px - 22px) / var(--n)), 38px);
    --lab: 22px;
  }
  .panel { padding: 14px 12px 14px; }
  .topbar { padding: 10px 16px; }
  .logo span:last-child { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .emojis { display: none; }
  .bubble { top: -40px; max-width: 70vw; }
  .dock-ship { width: calc(var(--len) * 24px + 12px); height: 38px; }
}

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

/* ---------- Настройки правил ---------- */

.settings { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.setting > span { color: var(--text); }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: rgba(2, 12, 22, 0.6); border: 1px solid var(--panel-edge); }
.seg button {
  border: 0;
  background: none;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: linear-gradient(180deg, #ffd77a, #f0a10c); color: #2a1700; font-weight: 700; }
.rules:empty { display: none; }

/* ---------- Таймер, правила партии, сдача ---------- */

.banner { display: flex; align-items: center; gap: 14px; }
.timer {
  font-family: var(--font-head);
  font-size: 0.8em;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
  min-width: 64px;
  text-align: center;
}
.timer.urgent { background: var(--danger); color: #fff; animation: blink 0.8s infinite; }

.game-meta { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; margin: -4px auto 16px; }
.rules-line { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.rules-line span {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: rgba(2, 12, 22, 0.45);
}
.btn-ghost { background: rgba(255, 77, 61, 0.1); border-color: rgba(255, 77, 61, 0.4); color: #ffb3aa; box-shadow: none; }

/* Последний выстрел по полю */
.cell.last::before {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: 3px;
  box-shadow: 0 0 0 2px rgba(255, 215, 122, 0.9), 0 0 12px rgba(255, 182, 39, 0.7);
  animation: last-pulse 1.4s ease-in-out infinite;
  pointer-events: none;
  z-index: 1;
}
@keyframes last-pulse { 50% { opacity: 0.35; } }

.typing { font-size: 13px; color: var(--sonar); padding: 0 6px 6px; animation: blink 1.2s infinite; }

/* Панель по ширине поля: док и кнопки переносятся, а не растягивают её */
.panel > .placement, .panel > .fleet, .panel > .waiting, .panel > .panel-head { max-width: calc(var(--cell) * var(--n) + var(--lab)); }

/* ---------- Морской бой 2.0 ---------- */

/* Отметки бледнеют по мере устаревания разведки */
.cell > .mk { opacity: var(--life, 1); transition: opacity 0.5s; }
.cell.hit, .cell.old { opacity: 1; }
.cell .mk.old-hit {
  inset: 22%;
  background:
    linear-gradient(45deg, transparent 42%, rgba(255, 90, 60, 0.75) 42% 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, rgba(255, 90, 60, 0.75) 42% 58%, transparent 58%);
}

.v2-actions { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: -4px auto 16px; }
.v2-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.v2-buttons .btn small { font-size: 11px; opacity: 0.75; margin-left: 4px; }
.v2-buttons .btn.on {
  border-color: var(--brass-2);
  box-shadow: 0 0 0 2px rgba(255, 182, 39, 0.45), 0 0 18px rgba(255, 182, 39, 0.35);
  color: var(--brass-2);
}
.v2-hint { font-size: 13px; color: var(--muted); text-align: center; }

/* Засвет 5-палубника */
.zone {
  position: absolute;
  z-index: 3;
  left: calc(var(--c) * var(--cell));
  top: calc(var(--r) * var(--cell));
  width: calc(var(--s) * var(--cell));
  height: calc(var(--s) * var(--cell));
  border: 2px dashed rgba(255, 77, 61, 0.95);
  border-radius: 6px;
  background: rgba(255, 77, 61, 0.14);
  box-shadow: 0 0 24px rgba(255, 77, 61, 0.45), inset 0 0 24px rgba(255, 77, 61, 0.3);
  pointer-events: none;
  animation: zone-pulse 1.2s ease-in-out infinite;
}
@keyframes zone-pulse { 50% { background: rgba(255, 77, 61, 0.26); } }

/* Бомба: прицел на 3×3 */
.board-enemy.bombing .cells { cursor: crosshair; }
.board-enemy.bombing .cell:hover::before, .board-enemy.bombing .cell:hover::after { display: none; }
.board-enemy .cell.pv-ok { background: rgba(255, 120, 40, 0.38); box-shadow: inset 0 0 0 1px rgba(255, 160, 60, 0.9); }

/* Маневр */
.board-me.steering .cell { cursor: pointer; }
.ship.picked { filter: drop-shadow(0 0 6px rgba(255, 215, 122, 0.95)) drop-shadow(0 0 2px #ffd77a); }
.cell.mv-ok { background: rgba(72, 240, 160, 0.4); box-shadow: inset 0 0 0 2px rgba(72, 240, 160, 0.95); cursor: pointer; animation: last-pulse 1s ease-in-out infinite; }
.cell.mv-bad { background: rgba(255, 77, 61, 0.3); box-shadow: inset 0 0 0 1px rgba(255, 77, 61, 0.8); }

/* На поле 20×20 мелкие отметки чуть крупнее */
.mode-v2 .splash { width: 36%; height: 36%; }
.mode-v2 .fl { width: calc(var(--len) * 12px); height: 12px; }
