:root {
  --sea-0: #06243f;
  --sea-1: #0c3760;
  --sea-2: #114b80;
  --ink: #eaf3fb;
  --muted: #9db8d2;
  --accent: #2f9bff;
  --accent-2: #1d7fe0;
  --gold: #ffcc4d;
  --hit: #ff5b4d;
  --miss: #5b7fa3;
  --ship: #cfe0f0;
  --sunk: #b5302a;
  --ok: #36d18a;
  --line: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--ink);
  background: var(--sea-0);
  overscroll-behavior: none;
  user-select: none;
}
#app { height: 100%; }

.screen {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 12px);
}
.sea {
  background:
    radial-gradient(120% 80% at 50% -10%, var(--sea-2), transparent 60%),
    linear-gradient(180deg, var(--sea-1), var(--sea-0) 75%);
}

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 14px; padding: 14px 18px;
  font-size: 16px; font-weight: 700; color: #fff;
  background: var(--accent-2); cursor: pointer;
  transition: transform .06s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn-primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 18px rgba(31,127,224,.35); }
.btn-ghost { background: rgba(255,255,255,.08); border: 1px solid var(--line); }
.btn-link { background: transparent; color: var(--muted); font-weight: 600; box-shadow: none; }
.wide { width: 100%; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.08); color: var(--ink); font-size: 22px;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn.sm { width: 32px; height: 32px; font-size: 16px; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 0 12px; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: .2px; }
.code-pill {
  font-size: 13px; font-weight: 700; letter-spacing: 2px;
  background: rgba(255,255,255,.1); border: 1px solid var(--line);
  padding: 3px 8px; border-radius: 8px; color: var(--gold);
}
.spacer { flex: 1; }

/* ---------- home ---------- */
.home-brand { text-align: center; margin-top: 12vh; }
.home-emoji { font-size: 64px; line-height: 1; }
.home-brand h1 { margin: 12px 0 2px; font-size: 32px; letter-spacing: .5px; }
.home-sub { margin: 0; color: var(--muted); }
.home-stats { display: flex; justify-content: center; gap: 22px; margin: 22px 0 8px; }
.home-stats .stat { text-align: center; }
.home-stats .stat b { display: block; font-size: 22px; color: var(--gold); }
.home-stats .stat span { font-size: 12px; color: var(--muted); }
.home-menu { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.home-foot { text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0 0; }

/* ---------- lobby ---------- */
.lobby-body { display: flex; flex-direction: column; gap: 14px; }
.lobby-card {
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0,0,0,.25); color: var(--ink);
  font-size: 22px; font-weight: 800; letter-spacing: 6px; text-align: center;
  padding: 10px; text-transform: uppercase;
}
.join-row input::placeholder { letter-spacing: 4px; color: var(--muted); }
.lobby-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.rooms-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rooms-list li {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,.2); border-radius: 12px; padding: 10px 12px;
}
.rooms-list .r-host { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rooms-list .r-code { color: var(--gold); font-weight: 700; letter-spacing: 2px; font-size: 13px; }
.rooms-list .r-join { padding: 8px 14px; font-size: 14px; }
.rooms-list .empty { justify-content: center; color: var(--muted); }

/* ---------- room ---------- */
.room-banner {
  text-align: center; font-weight: 700; font-size: 15px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px; margin-bottom: 10px;
}
.room-banner.hot { background: rgba(47,155,255,.22); border-color: var(--accent); color: #fff; }
.room-banner.win { background: rgba(54,209,138,.2); border-color: var(--ok); }
.room-banner.lose { background: rgba(255,91,77,.18); border-color: var(--hit); }
.phase { display: flex; flex-direction: column; gap: 12px; flex: 1; }

/* waiting */
.wait-card { text-align: center; margin-top: 8vh; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wait-spin { font-size: 56px; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
.wait-title { font-size: 20px; font-weight: 800; margin: 6px 0 0; }
.wait-sub { color: var(--muted); margin: 0; }
.big-code {
  font-size: 40px; font-weight: 900; letter-spacing: 10px; color: var(--gold);
  background: rgba(0,0,0,.25); border-radius: 14px; padding: 12px 18px 12px 28px;
}

/* ---------- board ---------- */
.board-wrap { display: flex; justify-content: center; }
.board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
  width: min(92vw, 360px);
  aspect-ratio: 1 / 1;
  background: rgba(0,0,0,.28);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
}
.board.mini { width: min(58vw, 220px); }
.cell {
  background: rgba(255,255,255,.06);
  border-radius: 3px;
  position: relative;
  display: grid; place-items: center;
  font-size: 12px; line-height: 1;
}
.board.enemy .cell { cursor: pointer; }
.board.enemy .cell:active { background: rgba(47,155,255,.3); }
.cell.ship { background: var(--ship); }
.cell.hit { background: var(--hit); }
.cell.hit::after, .cell.sunk::after { content: "✕"; color: #fff; font-weight: 900; font-size: 14px; }
.cell.sunk { background: var(--sunk); }
.cell.miss { background: rgba(255,255,255,.05); }
.cell.miss::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--miss); }
.cell.preview { outline: 2px solid var(--accent); outline-offset: -2px; background: rgba(47,155,255,.25); }
.cell.invalid { outline: 2px solid var(--hit); outline-offset: -2px; background: rgba(255,91,77,.25); }

.board-section { display: flex; flex-direction: column; gap: 6px; }
.board-label { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); padding: 0 2px; }
.ships-left { font-weight: 700; color: var(--ink); }

/* ---------- setup ---------- */
.setup-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.opp-chip { font-size: 13px; color: var(--muted); font-weight: 600; }
.ship-palette { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pal-ship {
  display: flex; align-items: center; gap: 3px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; cursor: pointer;
}
.pal-ship.sel { outline: 2px solid var(--accent); background: rgba(47,155,255,.18); }
.pal-ship.done { opacity: .35; }
.pal-ship .deck { width: 12px; height: 12px; background: var(--ship); border-radius: 2px; }
.pal-ship .cnt { font-size: 12px; color: var(--muted); margin-left: 4px; font-weight: 700; }
.setup-actions { display: flex; gap: 8px; }
.setup-actions .btn { flex: 1; padding: 11px 6px; font-size: 14px; }

/* ---------- finished ---------- */
.finish-panel { text-align: center; display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.finish-title { font-size: 26px; font-weight: 900; }
.finish-title.win { color: var(--ok); }
.finish-title.lose { color: var(--hit); }
.finish-sub { color: var(--muted); }

/* ---------- overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 20; padding: 20px;
}
.overlay-card {
  width: 100%; max-width: 420px; max-height: 80vh; overflow: auto;
  background: var(--sea-1); border: 1px solid var(--line); border-radius: 18px; padding: 16px;
}
.overlay-head { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: 18px; margin-bottom: 12px; }
.stats-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.stats-list li {
  display: flex; align-items: center; gap: 10px; padding: 10px 8px;
  border-bottom: 1px solid var(--line);
}
.stats-list li::before {
  counter-increment: rank; content: counter(rank);
  width: 26px; text-align: center; font-weight: 800; color: var(--gold);
}
.stats-list .s-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-list .s-win { color: var(--ok); font-weight: 700; }
.stats-list .empty { justify-content: center; color: var(--muted); }
