/* ===================== Theme tokens ===================== */
:root {
  --bg:        #0b0e14;
  --bg-grad-a: #0e1320;
  --bg-grad-b: #0b0e14;
  --panel:     #141a26;
  --panel-2:   #1b2230;
  --line:      #283042;
  --text:      #e6ebf5;
  --muted:     #8b94a8;
  --p1:        #38bdf8;   /* Player 1 — sky */
  --p2:        #fb923c;   /* Player 2 — amber */
  --good:      #34d399;
  --radius:    16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(56,189,248,.10), transparent 60%),
    radial-gradient(1000px 500px at 0% 0%, rgba(251,146,60,.08), transparent 55%),
    linear-gradient(180deg, var(--bg-grad-a), var(--bg-grad-b));
  background-attachment: fixed;
  min-height: 100dvh;
}

[hidden], .hidden { display: none !important; }

/* ===================== Top bar ===================== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  backdrop-filter: blur(10px);
  background: rgba(11,14,20,.6);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .5px; }
.logo { color: var(--p1); letter-spacing: -3px; }
.net-status { font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; }
.net-status.online  { color: var(--good); background: rgba(52,211,153,.12); }
.net-status.offline { color: #f87171; background: rgba(248,113,113,.12); }

/* ===================== Layout ===================== */
.view { padding: 18px 16px 60px; }
.container { max-width: 1040px; margin: 0 auto; }
.container.narrow { max-width: 560px; }

.hero { text-align: center; margin: 18px 0 22px; }
.hero h1 { font-size: clamp(26px, 6vw, 40px); margin: 0 0 8px; line-height: 1.05; }
.grad { background: linear-gradient(90deg, var(--p1), var(--p2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); margin: 0 auto; max-width: 540px; font-size: 15px; }

.section-title { font-size: 20px; margin: 14px 0 16px; }
.back-btn {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 10px; cursor: pointer; font-size: 13px; margin-bottom: 12px;
}
.back-btn:hover { color: var(--text); border-color: #3a445c; }

/* ===================== Name bar ===================== */
.name-bar {
  display: flex; align-items: center; gap: 12px; justify-content: center;
  background: var(--panel); border: 1px solid var(--line);
  padding: 12px 14px; border-radius: var(--radius); max-width: 420px; margin: 0 auto 26px;
}
.name-bar label { color: var(--muted); font-size: 13px; font-weight: 700; }
.name-bar input { flex: 1; }

input[type="text"] {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; outline: none; width: 100%;
}
input[type="text"]:focus { border-color: var(--p1); box-shadow: 0 0 0 3px rgba(56,189,248,.18); }

/* ===================== Game cards ===================== */
.cards {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.game-card {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; cursor: pointer;
  position: relative; transition: transform .12s ease, border-color .12s ease, background .12s ease;
  color: var(--text); font-family: inherit;
}
.game-card.active:hover { transform: translateY(-2px); border-color: var(--p1); background: var(--panel-2); }
.game-card.locked { opacity: .6; cursor: not-allowed; }
.card-icon {
  width: 52px; height: 52px; flex: 0 0 52px; border-radius: 12px;
  display: grid; place-items: center; font-size: 22px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line);
}
.squares-icon { color: var(--p1); }
.card-title { font-weight: 800; font-size: 16px; }
.card-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card-badge { position: absolute; top: 12px; right: 12px; font-size: 10.5px; font-weight: 800; padding: 3px 8px; border-radius: 999px; }
.card-badge.live { color: var(--good); background: rgba(52,211,153,.14); }
.card-badge.soon { color: var(--muted); background: rgba(139,148,168,.14); }

/* ===================== Lobby ===================== */
.lobby-grid { display: grid; gap: 14px; }
.lobby-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.lobby-card h3 { margin: 0 0 4px; font-size: 16px; }
.lobby-card p  { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 800; }
.or-line { display: flex; align-items: center; text-align: center; color: var(--muted); margin: 18px 0; }
.or-line::before, .or-line::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.or-line span { padding: 0 14px; font-size: 12px; }

.code-wrap { margin-top: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; text-align: center; }
.code-label { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
.code-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 10px 0 8px; }
.code-box { font-size: 34px; font-weight: 900; letter-spacing: 8px; color: var(--p1); }
.wait-text { color: var(--muted); font-size: 13px; }

/* ===================== Buttons ===================== */
.btn {
  font-family: inherit; font-weight: 800; font-size: 14px;
  border-radius: 12px; padding: 12px 16px; cursor: pointer; border: 1px solid transparent;
  transition: filter .12s ease, background .12s ease, border-color .12s ease;
}
.btn.primary { background: linear-gradient(90deg, var(--p1), #6366f1); color: #04121f; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--panel); }
.btn.small { padding: 8px 12px; font-size: 13px; background: var(--panel-2); color: var(--text); border-color: var(--line); }
.btn.full { width: 100%; }

/* ===================== Game UI ===================== */
.game-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.game-head .back-btn { margin-bottom: 0; }
.room-pill { font-size: 12.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 7px 12px; border-radius: 999px; }
.room-pill span { color: var(--text); font-weight: 800; letter-spacing: 1px; }

.scoreboard {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px;
}
.chip { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; padding: 6px 8px; border-radius: 12px; transition: background .15s ease; }
.chip:nth-child(3) { justify-content: flex-end; }
.chip.active { background: rgba(255,255,255,.04); }
.swatch { width: 14px; height: 14px; border-radius: 4px; flex: 0 0 14px; box-shadow: 0 0 0 2px rgba(255,255,255,.06); }
.p1c { background: var(--p1); }
.p2c { background: var(--p2); }
.cname { font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cscore { font-weight: 900; font-size: 20px; margin-left: auto; }
.chip:nth-child(3) .cscore { margin-left: 0; margin-right: auto; }
.vs { color: var(--muted); font-size: 11px; font-weight: 800; }

.status {
  text-align: center; font-weight: 800; font-size: 15px; margin-bottom: 12px;
  color: var(--muted); min-height: 22px;
}
.status.your-turn { color: var(--p1); }

/* Board */
.board-host {
  width: 100%; max-width: min(94vw, 540px); margin: 0 auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 10px; box-shadow: 0 18px 40px rgba(0,0,0,.35);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.board-host.my-turn { cursor: pointer; }
.board-svg { display: block; width: 100%; height: auto; }
.dot { transition: fill .15s ease; }
.drawn-line { transition: stroke .08s ease; }
.box-initial { font-weight: 800; font-size: 21px; }

/* Overlay */
.overlay { margin: 18px auto 0; max-width: min(94vw, 540px); }
.overlay-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; text-align: center;
}
.winner-text { font-size: 22px; font-weight: 900; margin-bottom: 16px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0b0e14; color: var(--text); border: 1px solid var(--line);
  padding: 11px 16px; border-radius: 12px; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); z-index: 50; max-width: 90vw; text-align: center;
}

@media (max-width: 380px) {
  .cscore { font-size: 17px; }
  .cname { font-size: 12.5px; }
}

/* ===================== Sea Battle (Battleship) ===================== */
.bs-controls { margin: 4px 0 12px; }
.place-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.ship-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.ship-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); font-size: 12px; color: var(--muted);
}
.ship-item.current { border-color: var(--p1); color: var(--p1); }
.ship-item.placed { opacity: .45; }
.ship-item.placed .sname { text-decoration: line-through; }
.ship-dots { display: flex; gap: 2px; }
.ship-dots i { width: 8px; height: 8px; border-radius: 2px; background: currentColor; display: inline-block; opacity: .8; }

.bs-boards { display: flex; flex-direction: column; gap: 16px; }
.bs-boards[data-phase="placing"] .bs-board.enemy { display: none; }
.bs-board .bs-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 700; }

.bs-grid {
  display: grid; grid-template-columns: repeat(11, 1fr); gap: 2px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px;
}
.bs-cell {
  aspect-ratio: 1 / 1; border-radius: 4px; background: #0e131e;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.bs-cell.lbl { background: transparent; color: var(--muted); font-weight: 800; font-size: 11px; }
.bs-cell.water { background: #0e131e; }
.bs-cell.ship { background: #33405c; }            /* your own ships */
.bs-cell.miss::after { content: ''; width: 28%; height: 28%; border-radius: 50%; background: var(--muted); opacity: .55; }
.bs-cell.hit { background: #5f1414; }
.bs-cell.hit::after { content: ''; width: 46%; height: 46%; border-radius: 50%; background: #f87171; }
.bs-cell.sunk { background: #4a2406; }
.bs-cell.sunk::after { content: ''; width: 46%; height: 46%; border-radius: 50%; background: var(--p2); }
.bs-cell.preview-ok { background: rgba(56,189,248,.32); }
.bs-cell.preview-bad { background: rgba(248,113,113,.32); }
.bs-cell.fireable { cursor: pointer; }
.bs-cell.fireable:hover { outline: 2px solid var(--p1); outline-offset: -2px; }

.bs-log {
  margin-top: 14px; max-height: 120px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 12.5px;
}
.bs-log .empty { color: var(--muted); }
.bs-log .row { padding: 2px 0; color: var(--muted); }
.bs-log .row.you { color: var(--p1); }
.bs-log .row.foe { color: var(--p2); }
.bs-log .row.event { color: var(--text); font-weight: 700; }
.bs-stats { color: var(--muted); font-size: 13px; margin-bottom: 16px; line-height: 1.6; }

/* Mode picker + LAN lobby */
.bs-section { margin-top: 6px; }
.mode-cards { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 440px) { .mode-cards { grid-template-columns: 1fr; } }
.mode-card {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; cursor: pointer; color: var(--text); font-family: inherit;
  transition: border-color .12s ease, background .12s ease;
}
.mode-card:hover { border-color: var(--p1); background: var(--panel-2); }
.mode-icon {
  font-size: 26px; width: 48px; height: 48px; flex: 0 0 48px;
  display: grid; place-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
.mode-title { font-weight: 800; font-size: 15px; }
.mode-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
