/* ============================================================
   Морской бой — оформление
   Тёмная «ночная вахта»: глубокий синий, бирюзовый акцент, коралловые попадания.
   ============================================================ */

:root {
  --bg: #071019;
  --bg-2: #0a1a27;
  --panel: rgba(13, 30, 44, 0.82);
  --panel-2: rgba(9, 23, 35, 0.9);
  --line: rgba(120, 190, 220, 0.16);
  --line-strong: rgba(120, 190, 220, 0.32);
  --text: #e8f2f8;
  --muted: #8ba6b8;
  --muted-2: #647f92;
  --accent: #3ddc97;
  --accent-soft: rgba(61, 220, 151, 0.14);
  --blue: #47a8ff;
  --blue-soft: rgba(71, 168, 255, 0.14);
  --hit: #ff7a45;
  --hit-soft: rgba(255, 122, 69, 0.22);
  --danger: #ff5c7a;
  --gold: #ffcf5c;
  --water: #0b2233;
  --water-2: #0d283c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 700px at 15% -10%, #10304a 0%, transparent 60%),
              radial-gradient(900px 600px at 100% 0%, #123a3a 0%, transparent 55%),
              linear-gradient(180deg, #071019 0%, #061019 40%, #05101a 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.bg-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(90, 170, 210, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(90, 170, 210, 0.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 50% 0%, rgba(0, 0, 0, 0.75), transparent 75%);
  z-index: 0;
}

/* ------------------------------------------------------------------ шапка */

.topbar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(14px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(6, 16, 25, 0.6);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; }
.brand:hover { text-decoration: none; }
.brand__mark {
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  border-radius: 12px;
  font-size: 22px;
  background: linear-gradient(145deg, rgba(61, 220, 151, 0.2), rgba(71, 168, 255, 0.12));
  border: 1px solid rgba(61, 220, 151, 0.35);
  box-shadow: 0 0 24px rgba(61, 220, 151, 0.15);
}
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__title { font-weight: 700; letter-spacing: 0.2px; font-size: 17px; }
.brand__sub { font-size: 11px; text-transform: uppercase; letter-spacing: 1.6px; color: var(--muted-2); }

.topbar__right { display: flex; align-items: center; gap: 10px; }

.online {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--muted);
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 26, 39, 0.6);
}
.online.is-offline { color: var(--danger); }
.online.is-offline .online__dot { background: var(--danger); box-shadow: 0 0 10px var(--danger); animation: none; }
.online__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse-dot 2.4s infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.nick {
  font: inherit; font-size: 13px;
  color: var(--text);
  max-width: 150px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(10, 26, 39, 0.6);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.nick:hover { border-color: var(--line-strong); background: rgba(16, 38, 56, 0.8); }
.nick { display: inline-flex; align-items: center; gap: 7px; }
.nick__sso {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--accent);
  border: 1px solid rgba(61, 220, 151, 0.4);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 2px 4px;
  line-height: 1;
}

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 17px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(10, 26, 39, 0.6);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}
.icon-btn:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.icon-btn.is-off { opacity: 0.5; }

/* ------------------------------------------------------------------- main */

.main {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 34px) clamp(12px, 4vw, 40px) 40px;
}

.screen { animation: screen-in 0.28s ease both; }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.footer {
  position: relative; z-index: 1;
  display: flex; flex-wrap: wrap; gap: 8px 24px;
  justify-content: space-between;
  padding: 16px clamp(14px, 4vw, 40px);
  border-top: 1px solid var(--line);
  color: var(--muted-2);
  font-size: 12px;
}
.footer a { color: var(--muted); }

/* Экран боя занимает весь кадр: подвал и лишние отступы убираем. */
body.in-game .footer { display: none; }
body.in-game .main { padding-top: clamp(10px, 2vw, 20px); padding-bottom: 18px; }
body.in-game .game-top { margin-bottom: 12px; }

/* ---------------------------------------------------------------- лобби */

.lobby__hero { text-align: center; padding: clamp(8px, 2vw, 22px) 0 clamp(20px, 3vw, 34px); }
.lobby__hero h1 {
  margin: 0 0 10px;
  font-size: clamp(28px, 4.4vw, 46px);
  letter-spacing: -0.5px;
  font-weight: 800;
}
.lobby__hero h1 span {
  background: linear-gradient(100deg, var(--accent), var(--blue));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lobby__hero p { margin: 0 auto; max-width: 640px; color: var(--muted); font-size: clamp(14px, 1.6vw, 16px); line-height: 1.55; }

.game-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; max-width: 860px; margin: 0 auto; }

.game-card {
  position: relative;
  overflow: hidden;
  padding: clamp(20px, 3vw, 30px);
  border-radius: calc(var(--radius) + 6px);
  border: 1px solid var(--line);
  background:
    radial-gradient(600px 300px at 100% 0%, rgba(61, 220, 151, 0.1), transparent 60%),
    linear-gradient(160deg, rgba(16, 38, 56, 0.92), rgba(8, 21, 33, 0.95));
  box-shadow: var(--shadow);
}
.game-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(80, 170, 210, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(80, 170, 210, 0.07) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(120deg, transparent 40%, #000 100%);
  pointer-events: none;
}

.game-card__top { position: relative; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.game-card h2 { margin: 0 0 6px; font-size: clamp(22px, 2.6vw, 28px); letter-spacing: -0.3px; }
.game-card p { margin: 0; color: var(--muted); line-height: 1.55; max-width: 520px; }
.game-card__badge {
  font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(61, 220, 151, 0.35);
  background: var(--accent-soft);
  padding: 6px 10px; border-radius: 999px;
}

.fleet-preview { position: relative; display: flex; gap: 6px; flex-wrap: wrap; margin: 18px 0 22px; }
.fleet-preview i {
  display: block;
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(180deg, #7fa7bd, #527c93);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.fleet-preview i[data-len="5"] { width: 72px; }
.fleet-preview i[data-len="4"] { width: 58px; }
.fleet-preview i[data-len="3"] { width: 42px; }
.fleet-preview i[data-len="2"] { width: 28px; }
.fleet-preview i[data-len="1"] { width: 14px; }

.actions { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.actions__row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(16, 38, 56, 0.7);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: rgba(160, 220, 240, 0.45); }
.btn:active:not(:disabled) { transform: translateY(0) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary {
  border-color: transparent;
  color: #04241a;
  background: linear-gradient(135deg, #52e6a6, #35c5cd);
  box-shadow: 0 10px 26px rgba(61, 220, 151, 0.25);
}
.btn--primary:hover:not(:disabled) { box-shadow: 0 12px 30px rgba(61, 220, 151, 0.35); }
.btn--ghost { background: transparent; }
.btn--danger { border-color: rgba(255, 92, 122, 0.45); color: #ffb3c1; background: rgba(255, 92, 122, 0.08); }
.btn--danger:hover:not(:disabled) { background: rgba(255, 92, 122, 0.16); }
.btn--sm { padding: 8px 12px; font-size: 13px; border-radius: 9px; }
.btn--wide { width: 100%; }

.chips { display: inline-flex; gap: 6px; padding: 4px; border-radius: 12px; border: 1px solid var(--line); background: rgba(7, 18, 28, 0.6); }
.chip {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--muted);
  padding: 8px 13px;
  border: 0; border-radius: 9px;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.chip:hover { color: var(--text); }
.chip.is-active { color: #04241a; background: linear-gradient(135deg, #52e6a6, #35c5cd); }
.chip--level.is-active { color: #04241a; }

.lobby__note {
  max-width: 860px; margin: 20px auto 0;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

/* -------------------------------------------------------------- панели */

.panel {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
  backdrop-filter: blur(6px);
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.3px;
  color: var(--muted);
  text-transform: uppercase;
}
.panel__head strong { color: var(--text); font-size: 14px; letter-spacing: 0; text-transform: none; }

/* --------------------------------------------------------------- доска */

.board-shell {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  grid-template-rows: 16px minmax(0, 1fr);
  gap: 4px;
  width: 100%;
  max-width: var(--board-max, 520px);
  margin: 0 auto;
  user-select: none;
}
.board-shell--plain { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 0; }

.board-cols, .board-rows { position: relative; font-size: 10px; color: var(--muted-2); }
.board-cols { grid-column: 2; display: grid; grid-template-columns: repeat(10, 1fr); }
.board-cols span, .board-rows span { display: grid; place-items: center; }
.board-rows { grid-row: 2; display: grid; grid-template-rows: repeat(10, 1fr); }

.board-shell .board { grid-row: 2; grid-column: 2; }
.board-shell--plain .board { grid-row: 1; grid-column: 1; }

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(120% 120% at 30% 0%, #103148 0%, var(--water) 55%, #081b29 100%);
  box-shadow: inset 0 0 0 1px var(--line-strong), inset 0 0 40px rgba(0, 0, 0, 0.35), 0 12px 30px rgba(0, 0, 0, 0.28);
  touch-action: manipulation;
}
.board::after {
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(120, 190, 220, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 190, 220, 0.06) 1px, transparent 1px);
  background-size: calc(100% / var(--board-size, 10)) calc(100% / var(--board-size, 10));
  pointer-events: none;
}

.board__ships { position: absolute; inset: 0; z-index: 0; pointer-events: none; }

.ship {
  position: absolute;
  border-radius: 6px;
  background: linear-gradient(180deg, #8fb4c9 0%, #5c8aa2 55%, #3f6a80 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: background 0.3s, filter 0.3s;
}
.ship--sunk {
  background: linear-gradient(180deg, #8a3f35 0%, #5c2a25 60%, #40201d 100%);
  box-shadow: inset 0 1px 0 rgba(255, 180, 160, 0.25), 0 0 18px rgba(255, 90, 60, 0.25);
}
.ship--preview {
  background: linear-gradient(180deg, rgba(61, 220, 151, 0.55), rgba(61, 220, 151, 0.3));
  box-shadow: 0 0 0 2px rgba(61, 220, 151, 0.7), 0 0 22px rgba(61, 220, 151, 0.35);
}
.ship--preview-bad {
  background: linear-gradient(180deg, rgba(255, 92, 122, 0.5), rgba(255, 92, 122, 0.25));
  box-shadow: 0 0 0 2px rgba(255, 92, 122, 0.7);
}

.cell {
  position: relative;
  z-index: 1;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(120, 190, 220, 0.11);
  cursor: default;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.board--shootable .cell:not(.cell--shot):hover { background: rgba(71, 168, 255, 0.14); }
.board--shootable .cell:not(.cell--shot) { cursor: crosshair; }

.cell--miss::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 18%; height: 18%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #7e9db2;
  box-shadow: 0 0 8px rgba(126, 157, 178, 0.6);
  animation: marker-in 0.22s ease both;
}
.cell--revealed::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 12%; height: 12%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(126, 157, 178, 0.45);
  animation: marker-in 0.22s ease both;
}
.cell--hit::before,
.cell--hit::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 56%; height: 14%;
  border-radius: 3px;
  background: var(--hit);
  box-shadow: 0 0 12px rgba(255, 122, 69, 0.65);
}
.cell--hit::before { transform: translate(-50%, -50%) rotate(45deg); }
.cell--hit::after { transform: translate(-50%, -50%) rotate(-45deg); }
.cell--hit { animation: hit-flash 0.5s ease both; }

.cell--sunk { background: rgba(255, 92, 70, 0.16); }
.cell--sunk::before, .cell--sunk::after { background: #ff5126; }

.cell--last { animation: last-shot 0.9s ease both; }
.cell--last::marker { content: none; }

.cell--preview-ok { background: rgba(61, 220, 151, 0.22); box-shadow: inset 0 0 0 1px rgba(61, 220, 151, 0.55); }
.cell--preview-bad { background: rgba(255, 92, 122, 0.22); box-shadow: inset 0 0 0 1px rgba(255, 92, 122, 0.6); }

@keyframes marker-in { from { opacity: 0; transform: translate(-50%, -50%) scale(0.4); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes hit-flash {
  0% { background: rgba(255, 122, 69, 0.55); }
  100% { background: transparent; }
}
@keyframes last-shot {
  0% { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85); }
  100% { box-shadow: inset 0 0 0 1px rgba(120, 190, 220, 0.11); }
}

.board--disabled { pointer-events: none; }
/* При расстановке палец водит корабль, а не прокручивает страницу. */
.board--placing { touch-action: none; }
.board-host { min-width: 0; }

/* ------------------------------------------------------------ расстановка */

.placement { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.placement .board-shell { --board-max: min(100%, 640px, calc(100dvh - 320px)); }

.fleet-dock { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.dock-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(8, 22, 34, 0.65);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, opacity 0.2s;
}
.dock-item:hover { border-color: var(--line-strong); }
.dock-item.is-selected { border-color: rgba(61, 220, 151, 0.7); background: var(--accent-soft); box-shadow: 0 0 18px rgba(61, 220, 151, 0.12); }
.dock-item.is-placed { opacity: 0.36; cursor: default; }
.dock-item__ship { display: flex; gap: 2px; }
.dock-item__ship i {
  width: 12px; height: 12px;
  border-radius: 3px;
  background: linear-gradient(180deg, #9cc0d3, #5d8aa0);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.dock-item__len { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.controls { display: grid; gap: 8px; margin: 14px 0; }
.controls .btn { justify-content: flex-start; }
.hint { color: var(--muted-2); font-size: 12px; line-height: 1.5; margin: 10px 0 0; }
.hint b { color: var(--muted); font-weight: 600; }
.hint-inline { color: var(--muted); font-size: 13px; }

.waiting-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: rgba(6, 16, 25, 0.72);
  backdrop-filter: blur(3px);
  z-index: 5;
  text-align: center;
  padding: 20px;
}
.waiting-overlay__inner { display: grid; gap: 12px; justify-items: center; }
.spinner {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(61, 220, 151, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.waiting-overlay__title { font-weight: 700; font-size: 16px; }
.waiting-overlay__sub { color: var(--muted); font-size: 13px; }

.game-top {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.game-top__title { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.game-top__title small { color: var(--muted-2); font-weight: 500; font-size: 12px; }
.room-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 3px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px dashed rgba(61, 220, 151, 0.4);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
}

/* --------------------------------------------------------------- бой */

.battle { display: grid; gap: 16px; }
.battle-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.8fr) 300px;
  gap: 18px;
  align-items: start;
}

.turn-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(10, 26, 39, 0.75);
  font-weight: 600;
  font-size: 15px;
  transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
}
.turn-banner__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.turn-banner--you {
  border-color: rgba(61, 220, 151, 0.5);
  background: linear-gradient(100deg, rgba(61, 220, 151, 0.16), rgba(10, 26, 39, 0.75));
  box-shadow: 0 0 30px rgba(61, 220, 151, 0.12);
}
.turn-banner--you .turn-banner__dot { background: var(--accent); box-shadow: 0 0 12px var(--accent); animation: pulse-dot 1.6s infinite; }
.turn-banner--enemy { border-color: rgba(255, 122, 69, 0.35); }
.turn-banner--enemy .turn-banner__dot { background: var(--hit); box-shadow: 0 0 10px var(--hit); }
.turn-banner--over { border-color: var(--line-strong); }
.turn-banner small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; margin-top: 2px; }

.player-card { display: flex; align-items: center; gap: 10px; }
.player-card__avatar {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 700;
  background: linear-gradient(145deg, rgba(71, 168, 255, 0.25), rgba(61, 220, 151, 0.12));
  border: 1px solid var(--line-strong);
}
.player-card__name { font-weight: 600; font-size: 14px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-card__status { font-size: 11px; color: var(--muted-2); }
.player-card__status.is-online { color: var(--accent); }
.player-card__status.is-offline { color: var(--danger); }

.own-panel .board-shell { --board-max: 100%; }
.own-panel { opacity: 0.94; }

/* Бой должен целиком помещаться в экран: доски ограничены и по высоте. */
@media (min-width: 721px) {
  .battle .board-shell { --board-max: min(100%, 560px, calc(100dvh - 310px)); }
  .battle .side-panel { max-height: calc(100dvh - 150px); overflow: auto; }
}

.ships-left { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.ships-left i {
  display: block; height: 8px; border-radius: 3px;
  background: linear-gradient(180deg, #9cc0d3, #5d8aa0);
}
.ships-left i[data-len="5"] { width: 42px; }
.ships-left i[data-len="4"] { width: 34px; }
.ships-left i[data-len="3"] { width: 25px; }
.ships-left i[data-len="2"] { width: 17px; }
.ships-left i[data-len="1"] { width: 9px; }
.ships-left i.is-sunk { background: #4a2b28; box-shadow: inset 0 0 0 1px rgba(255, 122, 69, 0.25); }

.side-panel { display: grid; gap: 14px; grid-auto-rows: min-content; }
.log { display: grid; gap: 6px; max-height: 190px; overflow-y: auto; padding-right: 4px; }
.log__row {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(8, 22, 34, 0.55);
  animation: screen-in 0.25s ease both;
}
.log__row b { font-weight: 600; }
.log__row span { color: var(--muted-2); font-size: 12px; }
.log__row--hit { background: rgba(255, 122, 69, 0.12); }
.log__row--sunk { background: rgba(255, 71, 40, 0.16); }
.log__row--miss { background: rgba(71, 168, 255, 0.07); }
.log__who { color: var(--muted); }
.log__empty { color: var(--muted-2); font-size: 13px; }

.chat { display: grid; gap: 8px; }
.chat__log { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; padding-right: 4px; }
.chat__msg { font-size: 13px; line-height: 1.4; padding: 7px 9px; border-radius: 9px; background: rgba(8, 22, 34, 0.6); max-width: 92%; }
.chat__msg b { display: block; font-size: 11px; color: var(--muted-2); font-weight: 600; margin-bottom: 2px; }
.chat__msg--mine { align-self: flex-end; background: rgba(61, 220, 151, 0.12); }
.chat__form { display: flex; gap: 8px; }
.chat__form input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 13px;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(6, 16, 25, 0.7);
}
.chat__form input:focus { outline: none; border-color: rgba(61, 220, 151, 0.55); }
.chat__form button { padding: 10px 14px; }

/* ------------------------------------------------------------- результат */

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 11, 18, 0.72);
  backdrop-filter: blur(6px);
  animation: fade-in 0.3s ease both;
}
.result-card {
  width: min(520px, 100%);
  border-radius: 22px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(170deg, rgba(17, 40, 60, 0.98), rgba(7, 19, 30, 0.98));
  box-shadow: var(--shadow);
  padding: clamp(22px, 4vw, 34px);
  text-align: center;
  animation: card-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
@keyframes card-in { from { opacity: 0; transform: translateY(18px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.result-card__emoji { font-size: 44px; line-height: 1; }
.result-card h2 { margin: 10px 0 6px; font-size: clamp(24px, 3.4vw, 32px); }
.result-card__reason { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.result-card--win h2 { color: var(--accent); }
.result-card--lose h2 { color: #ff9aae; }

.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 20px; }
.stats-table th, .stats-table td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--line); }
.stats-table th { color: var(--muted-2); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
.stats-table td:first-child, .stats-table th:first-child { text-align: left; color: var(--muted); }
.stats-table td b { font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.result-note { margin: 12px 0 0; font-size: 12px; color: var(--muted-2); min-height: 16px; }

/* ---------------------------------------------------------------- тосты */

.toasts {
  position: fixed;
  left: 50%; bottom: 22px;
  transform: translateX(-50%);
  z-index: 60;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
  width: min(92vw, 460px);
}
.toast {
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(12, 30, 44, 0.96);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in 0.25s ease both;
  text-align: center;
}
.toast--error { border-color: rgba(255, 92, 122, 0.5); color: #ffc2cd; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------------- модалки */

.modals { position: relative; z-index: 50; }
.modal-backdrop {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(4, 11, 18, 0.7);
  backdrop-filter: blur(5px);
  animation: fade-in 0.2s ease both;
}
.modal {
  width: min(460px, 100%);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  border-radius: 18px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(170deg, rgba(17, 40, 60, 0.99), rgba(7, 19, 30, 0.99));
  box-shadow: var(--shadow);
  padding: 22px;
  animation: card-in 0.25s ease both;
}
.modal h3 { margin: 0 0 6px; font-size: 19px; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.8px; }
.field input {
  font: inherit; font-size: 15px;
  color: var(--text);
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(6, 16, 25, 0.75);
  letter-spacing: 0.5px;
}
.field input:focus { outline: none; border-color: rgba(61, 220, 151, 0.6); box-shadow: 0 0 0 3px rgba(61, 220, 151, 0.12); }
.field--code input { text-transform: uppercase; letter-spacing: 6px; font-family: ui-monospace, Menlo, monospace; text-align: center; font-size: 20px; }

.queue { display: grid; justify-items: center; gap: 12px; padding: 8px 0 4px; }
.queue__text { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }
.modal__text { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; text-align: center; }

.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0 14px;
  color: var(--muted-2); font-size: 12px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.account {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 22, 34, 0.6);
}
.account__avatar {
  width: 42px; height: 42px;
  flex: 0 0 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  font-size: 17px; font-weight: 700;
  color: var(--accent);
  background: linear-gradient(145deg, rgba(61, 220, 151, 0.18), rgba(71, 168, 255, 0.12));
  border: 1px solid rgba(61, 220, 151, 0.35);
}
.account__info { display: grid; gap: 2px; min-width: 0; }
.account__info b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account__info span { color: var(--muted-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account__hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.lobby-settings {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  margin: 2px 0 16px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: rgba(8, 22, 34, 0.45);
}
.lobby-settings__text { display: grid; gap: 3px; min-width: 0; }
.lobby-settings__text b { font-size: 13px; color: var(--text); }
.lobby-settings__text span { font-size: 12px; color: var(--muted-2); }

/* ------------------------------------------------- настройки поля и флота */

.battle-settings { display: grid; gap: 16px; }
.battle-settings__body { display: grid; gap: 16px; }
.settings-label {
  margin-bottom: 7px;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.6px; text-transform: uppercase;
  color: var(--muted-2);
}
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.settings-label-row .settings-label { margin-bottom: 0; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 22, 34, 0.55);
}
.settings-row__label { font-size: 13px; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper__btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(8, 22, 34, 0.8);
  color: var(--text);
  font: inherit; font-size: 16px; line-height: 1;
  cursor: pointer;
}
.stepper__btn:hover:not(:disabled) { border-color: var(--line-strong); background: rgba(16, 38, 56, 0.9); }
.stepper__btn:disabled { opacity: 0.35; cursor: default; }
.stepper__value {
  min-width: 28px;
  text-align: center;
  font-size: 14px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ship-editor { display: grid; gap: 6px; }
.ship-editor__row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 5px 10px;
  border-radius: 10px;
  background: rgba(8, 22, 34, 0.45);
}
.ship-editor__row.is-empty { opacity: 0.55; }
.ship-editor__name { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.settings-summary {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(61, 220, 151, 0.06);
  font-size: 12px; line-height: 1.55;
  color: var(--muted);
}
.settings-summary b { color: var(--text); }
.settings-error { min-height: 16px; font-size: 12px; color: var(--muted-2); }
.settings-error.is-error { color: var(--danger); }

/* ---------------------------------------------------- статистика игрока */

.career {
  margin: 0 0 14px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 22, 34, 0.55);
}
.career__head {
  margin-bottom: 9px;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.6px; text-transform: uppercase;
  color: var(--muted-2);
}
.career__empty { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); }
.career__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}
.career__cell {
  display: grid; gap: 2px;
  padding: 7px 6px;
  border-radius: 9px;
  background: rgba(6, 16, 25, 0.6);
  text-align: center;
}
.career__cell b { font-size: 17px; line-height: 1.1; }
.career__cell span { font-size: 10px; color: var(--muted-2); }
.career__cell--win b { color: var(--accent); }
.career__cell--lose b { color: #ff9aae; }
.career__side {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 5px 0 0;
  font-size: 12px; color: var(--muted);
  border-top: 1px solid rgba(120, 190, 220, 0.08);
}
.career__side + .career__side { margin-top: 4px; }
.career__side b { color: var(--text); font-weight: 600; }

.big-code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: clamp(28px, 6vw, 40px);
  letter-spacing: 8px;
  text-align: center;
  color: var(--accent);
  padding: 16px;
  border-radius: 14px;
  border: 1px dashed rgba(61, 220, 151, 0.45);
  background: rgba(61, 220, 151, 0.07);
  margin: 4px 0 14px;
}

/* ------------------------------------------------------------- адаптив */

@media (max-width: 1120px) {
  .battle-grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.85fr); }
  .battle-grid .side-panel { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .placement { grid-template-columns: minmax(0, 1fr); }
  .fleet-dock { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board-shell { --board-max: min(94vw, 520px); }
}

@media (max-width: 720px) {
  .battle-grid { grid-template-columns: minmax(0, 1fr); }
  .battle-grid .side-panel { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 10px 14px; }
  .brand__sub { display: none; }
  .brand__title { font-size: 15px; }
  .brand__mark { width: 36px; height: 36px; font-size: 19px; }
  .online { padding: 6px 10px; font-size: 12px; }
  .nick { max-width: 110px; padding: 7px 11px; }
  .icon-btn { width: 34px; height: 34px; }
  .main { padding-bottom: 28px; }
  .footer { flex-direction: column; gap: 6px; }
  .game-card { padding: 18px; }
  .actions .btn { flex: 1 1 auto; }
  .result-card { padding: 22px 18px; }
  .chat__log { max-height: 140px; }
  .panel { padding: 13px; }
  .log { max-height: 150px; }
}

@media (max-width: 420px) {
  .fleet-dock { gap: 6px; }
  .dock-item { padding: 7px 8px; }
  .dock-item__ship i { width: 10px; height: 10px; }
  .turn-banner { padding: 10px 12px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
