:root {
  --bg: #060B08;
  --bg-card: #0E1612;
  --border: #1F2A26;
  --border-bright: #2D3F37;
  --text: #F5F7F2;
  --text-muted: #8AA395;
  --green: #00A86B;
  --green-bright: #1FCB89;
  --gold: #F4C430;
  --orange-irish: #FF8C42;
  --water: #0B1E1A;
  --water-grid: #163029;
  --hit: #FF5A4A;
  --miss: #5C6B66;
  --sunk: #B23A2C;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 20% -10%, rgba(0, 168, 107, 0.10), transparent 45%),
    radial-gradient(ellipse at 110% 110%, rgba(244, 196, 48, 0.06), transparent 45%),
    var(--bg);
}

/* ─── Header ─── */
.bs-header {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  padding-top: max(12px, env(safe-area-inset-top));
  z-index: 5;
  pointer-events: none;
}
.bs-header > * { pointer-events: auto; }
.bs-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
  font-size: 14px;
  background: rgba(12, 26, 20, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
}
.bs-brand img { width: 22px; }
.bs-brand strong { color: var(--green-bright); font-weight: 800; }
.bs-header-right { display: flex; gap: 6px; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(12, 26, 20, 0.85);
  backdrop-filter: blur(8px);
  color: var(--text-muted); font-size: 16px;
  cursor: pointer; text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}
.btn-icon:hover { color: var(--text); border-color: var(--border-bright); }

/* ─── Screens ─── */
.screen {
  display: none;
  min-height: 100vh;
  padding: 80px 20px 40px;
  align-items: center;
  justify-content: center;
}
.screen.active { display: flex; }

/* ─── Title ─── */
.title-card {
  max-width: 520px; width: 100%; text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 28px;
}
.title-card h1 {
  font-size: clamp(36px, 6vw, 56px); font-weight: 900; letter-spacing: -0.02em;
  margin: 0 0 10px;
}
.title-card h1 .green { color: var(--green-bright); }
.title-tag {
  margin: 0 0 24px; color: var(--text-muted); font-size: 15px;
}
.title-buttons { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.title-difficulty {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
}
.diff-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); font: inherit;
  padding: 5px 14px; border-radius: 999px; cursor: pointer;
  transition: all 0.15s;
}
.diff-btn.active { background: rgba(0, 168, 107, 0.18); border-color: rgba(0, 168, 107, 0.5); color: var(--green-bright); }
.diff-btn:hover:not(.active) { color: var(--text); border-color: var(--border-bright); }

/* ─── Buttons ─── */
.btn {
  font: inherit; font-weight: 700; font-size: 14px;
  padding: 11px 22px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary {
  background: var(--green); color: #002618;
  box-shadow: 0 4px 16px rgba(0, 168, 107, 0.25);
}
.btn-primary:hover { background: var(--green-bright); }
.btn-primary:disabled { background: #1A2925; color: #4A6058; cursor: not-allowed; box-shadow: none; }
.btn-secondary {
  background: rgba(0, 168, 107, 0.10); color: var(--green-bright);
  border-color: rgba(0, 168, 107, 0.35);
}
.btn-secondary:hover { background: rgba(0, 168, 107, 0.20); }
.btn-ghost {
  background: transparent; color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-bright); }
.btn-confirm { width: 100%; padding: 14px; font-size: 15px; }

/* ─── Card screens ─── */
.screen-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px 24px;
  width: 100%; max-width: 540px;
  position: relative;
}
.screen-card.narrow { max-width: 380px; text-align: center; }
.screen-card h2 { margin: 0 0 14px; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.btn-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-muted); font-size: 18px; cursor: pointer;
  transition: all 0.15s;
}
.btn-close:hover { color: var(--text); border-color: var(--border-bright); }

.howto-list {
  margin: 12px 0 16px; padding-left: 18px;
  color: var(--text-muted); font-size: 14px; line-height: 1.6;
}
.howto-list li { margin-bottom: 8px; }
.howto-list strong { color: var(--text); }
.howto-list .hit { color: var(--hit); font-size: 16px; }
.howto-list .miss { color: var(--miss); font-size: 16px; }
.howto-tip {
  background: rgba(0, 168, 107, 0.07);
  border: 1px solid rgba(0, 168, 107, 0.22);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px; color: var(--text-muted);
}
.kbd {
  display: inline-block; padding: 1px 6px; margin: 0 2px;
  border: 1px solid var(--border-bright); border-radius: 5px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px; color: var(--green-bright);
  background: rgba(0,168,107,0.05);
}

/* ─── Placement screen ─── */
.bs-place-wrap {
  display: grid; grid-template-columns: 280px 1fr;
  gap: 28px; max-width: 920px; width: 100%;
  align-items: start;
}
.bs-side h2 { margin: 0 0 8px; font-size: 22px; font-weight: 800; }
.bs-hint {
  margin: 0 0 14px; color: var(--text-muted); font-size: 13px; line-height: 1.5;
}
.ship-list {
  list-style: none; padding: 0; margin: 0 0 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.ship-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.ship-item.placed { opacity: 0.45; cursor: default; }
.ship-item.placed::after { content: '✓'; color: var(--green-bright); margin-left: 8px; }
.ship-item.selected { border-color: var(--green); background: rgba(0,168,107,0.12); }
.ship-item:not(.placed):hover { border-color: var(--border-bright); }
.ship-item .ship-name { font-weight: 700; font-size: 14px; }
.ship-item .ship-cells {
  display: flex; gap: 2px;
}
.ship-item .ship-cells span {
  width: 12px; height: 12px;
  background: linear-gradient(135deg, var(--green) 0%, var(--green-bright) 100%);
  border-radius: 2px;
}
.place-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.place-actions .btn { flex: 1 1 auto; padding: 8px 10px; font-size: 13px; }

/* ─── Boards ─── */
.bs-board-wrap, .bs-board-block { display: flex; flex-direction: column; align-items: center; }
.bs-board-label {
  font-size: 11px; font-weight: 800; letter-spacing: 0.16em;
  color: var(--text-muted); text-transform: uppercase;
  margin-bottom: 8px;
}
.bs-board {
  display: grid;
  grid-template-columns: repeat(10, var(--cell-size, 36px));
  grid-template-rows: repeat(10, var(--cell-size, 36px));
  gap: 2px;
  padding: 6px;
  background: var(--water);
  border: 1px solid var(--border);
  border-radius: 8px;
  position: relative;
}
.bs-cell {
  background: var(--water-grid);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  transition: background 0.12s, transform 0.12s;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cell-size, 36px) * 0.45);
  font-weight: 700;
}
/* Snappy taps on mobile: no 300ms delay, no gray flash */
html, body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.bs-cell { touch-action: manipulation; }
.bs-cell.hover-valid { background: rgba(0, 168, 107, 0.5); }
.bs-cell.hover-invalid { background: rgba(255, 90, 74, 0.45); }
.bs-cell.ship {
  background: linear-gradient(135deg, #1A4338 0%, #0E2A24 100%);
  border: 1px solid rgba(0, 168, 107, 0.5);
}
.bs-cell.ship.preview { border: 1px dashed rgba(0,168,107,0.7); }
.bs-cell.miss::after {
  content: ''; position: absolute;
  width: 30%; height: 30%; border-radius: 50%;
  background: var(--miss);
  opacity: 0.7;
}
.bs-cell.hit {
  background: linear-gradient(135deg, #5A1812 0%, #2A0A07 100%);
  animation: hitFlash 0.4s ease-out;
}
.bs-cell.hit::after {
  content: '✕'; color: var(--hit); font-weight: 900;
  text-shadow: 0 0 10px rgba(255, 90, 74, 0.7);
}
.bs-cell.sunk {
  background: linear-gradient(135deg, #7A2218 0%, #3A0F08 100%);
  border: 1px solid var(--sunk);
}
.bs-cell.sunk::after {
  content: '✕'; color: #FF8B7A; font-weight: 900;
}
@keyframes hitFlash {
  0% { transform: scale(1.3); box-shadow: 0 0 18px rgba(255, 90, 74, 0.8); }
  100% { transform: scale(1); box-shadow: none; }
}
.bs-board[data-role="enemy"] .bs-cell:hover:not(.miss):not(.hit):not(.sunk) {
  background: rgba(244, 196, 48, 0.25);
  cursor: crosshair;
}
.bs-board[data-role="enemy"]:not(.active) .bs-cell { cursor: not-allowed; pointer-events: none; }

/* ─── Battle screen ─── */
.bs-battle-wrap {
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 920px;
  gap: 16px;
}
.bs-status-bar {
  width: 100%; max-width: 760px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.bs-turn { font-weight: 700; font-size: 14px; color: var(--green-bright); }
.bs-turn.enemy { color: var(--orange-irish); }
.bs-counts { display: flex; gap: 14px; font-size: 13px; font-weight: 600; }
.bs-count { display: inline-flex; align-items: center; gap: 6px; }
.bs-count .dot { width: 8px; height: 8px; border-radius: 50%; }
.bs-count.player .dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.bs-count.enemy .dot { background: var(--orange-irish); box-shadow: 0 0 6px var(--orange-irish); }

.bs-boards {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 22px; width: 100%; max-width: 820px;
  justify-items: center;
}
/* ─── Fleet status (under each board during battle) ─── */
.fleet-status {
  list-style: none; padding: 0;
  margin: 10px 0 0;
  display: flex; flex-direction: column; gap: 4px;
  width: 100%;
  max-width: calc(var(--cell-size, 36px) * 10 + 20px);
}
.fleet-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  transition: opacity 0.15s, border-color 0.15s, background 0.15s;
}
.fleet-row.sunk {
  background: rgba(178, 58, 44, 0.18);
  border-color: rgba(178, 58, 44, 0.4);
  opacity: 0.85;
}
.fleet-row.sunk .fleet-name { text-decoration: line-through; color: var(--sunk); }
.fleet-row .fleet-name { font-weight: 600; flex: 1; min-width: 0; }
.fleet-row .fleet-cells {
  display: flex; gap: 2px;
  flex-shrink: 0;
}
.fleet-row .fleet-cell {
  width: 10px; height: 10px;
  border-radius: 2px;
  background: linear-gradient(135deg, var(--green) 0%, var(--green-bright) 100%);
}
.fleet-row .fleet-cell.hit { background: var(--hit); }
.fleet-row .fleet-cell.unknown {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
}
.fleet-row .fleet-cell.sunk { background: var(--sunk); }
.fleet-row .fleet-state {
  font-size: 11px; color: var(--text-muted);
  min-width: 40px; text-align: right; flex-shrink: 0;
}
.fleet-row.sunk .fleet-state { color: var(--sunk); font-weight: 700; }

.bs-log {
  width: 100%; max-width: 760px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  color: var(--text-muted);
  max-height: 130px; overflow-y: auto;
  line-height: 1.6;
}
.bs-log .log-hit { color: var(--hit); }
.bs-log .log-miss { color: var(--text-muted); }
.bs-log .log-sunk { color: var(--gold); font-weight: 700; }
.bs-log .log-you { color: var(--green-bright); }
.bs-log .log-enemy { color: var(--orange-irish); }

/* ─── Result ─── */
.result-card { text-align: center; }
.result-icon { font-size: 48px; margin-bottom: 4px; }
.result-detail { color: var(--text-muted); font-size: 14px; margin: 0 0 16px; }
.result-stats {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px;
  background: rgba(0, 168, 107, 0.06);
  border-radius: 10px;
  font-size: 13px;
}
.result-stats div { display: flex; flex-direction: column; gap: 2px; }
.result-stats div strong { font-size: 18px; color: var(--green-bright); font-weight: 800; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

/* ─── Rate modal ─── */
.rate-card { padding-top: 36px; }
.rate-sub { margin: 4px 0 14px; color: var(--text-muted); font-size: 13px; }
.rate-stars { display: flex; justify-content: center; gap: 6px; margin: 6px 0 16px; }
.star-btn {
  background: none; border: none; cursor: pointer;
  font-size: 32px; line-height: 1;
  color: rgba(244, 196, 48, 0.22);
  padding: 4px 6px; border-radius: 6px;
  transition: color 0.12s, transform 0.12s;
}
.star-btn:hover { color: rgba(244, 196, 48, 0.65); transform: scale(1.08); }
.star-btn.lit { color: var(--gold); text-shadow: 0 0 14px rgba(244, 196, 48, 0.5); }
.rate-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; text-align: left; }
.rate-form input, .rate-form textarea {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text); font: inherit; font-size: 14px;
  resize: vertical; outline: none;
  transition: border-color 0.15s;
}
.rate-form input:focus, .rate-form textarea:focus { border-color: var(--green); }
.rate-status {
  min-height: 18px; font-size: 12px; margin-bottom: 6px;
  color: var(--text-muted); text-align: center;
}
.rate-status.error { color: var(--orange-irish); }
.rate-status.success { color: var(--green-bright); }
.rate-signup {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 12px; color: var(--text-muted); line-height: 1.4;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 10px; background: rgba(0,168,107,0.05);
  cursor: pointer; user-select: none; text-align: left;
}
.rate-signup input[type="checkbox"] { margin-top: 2px; accent-color: var(--green); }
.rate-signup small { display: block; opacity: 0.75; font-size: 11px; }

/* ─── High Score modal ─── */
.hs-card { padding-top: 28px; text-align: center; }
.hs-trophy { font-size: 44px; margin-bottom: 4px; }
.hs-card h2 { margin-bottom: 6px; }
.hs-sub { margin: 0 0 18px; color: var(--text-muted); font-size: 13px; }
.hs-score-display {
  background: linear-gradient(135deg, rgba(244,196,48,0.10) 0%, rgba(255,140,66,0.10) 100%);
  border: 1px solid rgba(244,196,48,0.3);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.hs-score-num {
  font-size: 36px; font-weight: 900;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--gold);
  letter-spacing: -0.02em;
  text-shadow: 0 0 20px rgba(244,196,48,0.4);
}
.hs-rank { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.hs-rank.high { color: var(--green-bright); font-weight: 700; }
.hs-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; text-align: left; }
.hs-form input {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  color: var(--text); font: inherit; font-size: 14px; outline: none;
}
.hs-form input:focus { border-color: var(--gold); }
.hs-disclaimer { margin: 4px 0 8px; font-size: 11px; color: var(--text-muted); line-height: 1.4; }
.hs-status { min-height: 18px; font-size: 12px; margin-bottom: 6px; color: var(--text-muted); text-align: center; }
.hs-status.error { color: var(--orange-irish); }
.hs-status.success { color: var(--green-bright); }

/* ─── Leaderboard ─── */
.lb-card { padding-top: 36px; max-width: 480px; }
.lb-sub { margin: 0 0 16px; color: var(--text-muted); font-size: 13px; }
.lb-list { list-style: none; padding: 0; margin: 0; }
.lb-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 6px;
}
.lb-list li.you { background: rgba(0, 168, 107, 0.12); border-color: rgba(0, 168, 107, 0.4); }
.lb-list li.lb-empty { justify-content: center; color: var(--text-muted); font-size: 13px; }
.lb-rank {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #182921;
  font-weight: 800; font-size: 14px; color: var(--text-muted); flex-shrink: 0;
}
.lb-rank.gold { background: linear-gradient(135deg, #F4C430 0%, #D9A410 100%); color: #2A1F00; box-shadow: 0 0 14px rgba(244,196,48,0.4); }
.lb-rank.silver { background: linear-gradient(135deg, #C0C8C4 0%, #94A097 100%); color: #1A1F1B; }
.lb-rank.bronze { background: linear-gradient(135deg, #C58E5C 0%, #8E6238 100%); color: #1F1208; }
.lb-name { flex: 1; min-width: 0; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-family: 'JetBrains Mono', ui-monospace, monospace; font-weight: 800; font-size: 15px; color: var(--gold); font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* ─── Responsive ─── */
:root { --cell-size: 36px; }
@media (max-width: 900px) {
  :root { --cell-size: 32px; }
  .bs-place-wrap { grid-template-columns: 1fr; gap: 18px; }
  .bs-side { order: 2; }
  .bs-board-wrap { order: 1; }
}
@media (max-width: 720px) {
  :root { --cell-size: 30px; }
  .bs-boards { grid-template-columns: 1fr; gap: 16px; }
}
@media (max-width: 380px) {
  :root { --cell-size: 26px; }
  .screen { padding: 70px 12px 30px; }
  .title-card { padding: 28px 18px; }
}

/* ─── Clear Back-to-Games button ─── */
.btn-back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 14px; height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(184, 255, 64, 0.45);
  background: linear-gradient(135deg, rgba(184,255,64,0.18) 0%, rgba(91,192,32,0.18) 100%);
  color: var(--acid, #B8FF40);
  font-size: 13px; font-weight: 700; letter-spacing: 0.04em;
  text-decoration: none; cursor: pointer;
  transition: all 0.15s;
}
.btn-back:hover {
  background: linear-gradient(135deg, rgba(184,255,64,0.28) 0%, rgba(91,192,32,0.28) 100%);
  color: #fff;
  border-color: rgba(184, 255, 64, 0.7);
}
.btn-back .ba-arrow { font-size: 16px; line-height: 1; }
@media (max-width: 540px) {
  .btn-back { padding: 0 10px; font-size: 12px; }
}
