/* Domination web — clean, game-like, mobile-first. Mirrors the iOS
   look: light background, white cards, rounded blocks, white dot on
   scored blocks (dark dot only on the shared block),
   tally-mark score bar. */

:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --border: #e3e3e8;
  --empty-cell: #e5e5ea;
  --accent: #2973ed;
  --danger: #d92d20;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px 40px;
}

h1 { font-size: 1.4rem; margin: 0 0 8px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error-text { color: var(--danger); font-size: 0.9rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---- top bar ---- */
#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; letter-spacing: 0.2px; }
.brand-blocks { display: inline-flex; gap: 3px; }
.brand-blocks i { width: 12px; height: 12px; border-radius: 3px; display: block; }
.brand-blocks i:nth-child(1) { background: rgb(230, 61, 69); }
.brand-blocks i:nth-child(2) { background: rgb(41, 115, 237); }
.brand-blocks i:nth-child(3) { background: rgb(46, 179, 97); }
.brand-blocks i:nth-child(4) { background: rgb(250, 166, 26); }
.profile-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--card);
  border-radius: 999px; padding: 6px 12px; cursor: pointer; font: inherit;
}
.elo-pill { background: var(--bg); border-radius: 999px; padding: 2px 8px; font-weight: 700; font-size: 0.85rem; }

/* ---- cards & controls ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.view > .btn { margin-top: 4px; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: #fff; border-color: #f2b8b2; color: var(--danger); }
.btn.big { width: 100%; font-size: 1.05rem; padding: 13px 16px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn.back { margin-bottom: 4px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1 1 160px; }

input[type="text"], input[type="password"], select {
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  min-height: 44px;
  width: 100%;
}
.field { display: block; margin: 10px 0; }
.field > span { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 5px; }
.check { display: flex; gap: 9px; align-items: flex-start; margin: 12px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); }
.code-input { text-transform: uppercase; letter-spacing: 4px; font-weight: 800; font-size: 1.2rem; text-align: center; }

.spinner {
  width: 34px; height: 34px; margin: 12px auto;
  border: 4px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- home ---- */
.profile-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.home-name { font-size: 1.5rem; font-weight: 800; }
.elo-big { text-align: right; }
.elo-big span { font-size: 1.9rem; font-weight: 800; }
.elo-big small { display: block; color: var(--muted); font-weight: 700; letter-spacing: 1px; }
.rules-list { margin: 6px 0; padding-left: 20px; line-height: 1.45; }
.rules-list li { margin: 5px 0; }
.home-nav { display: flex; gap: 10px; }
.home-nav .btn { flex: 1; }

/* ---- lobby ---- */
.room-code {
  font-size: 3rem; font-weight: 900; letter-spacing: 10px;
  margin: 6px 0 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.player-list { list-style: none; margin: 0; padding: 0; }
.player-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
}
.player-list li + li { margin-top: 4px; background: #fafafa; }
.player-dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.player-name { font-weight: 700; }
.player-elo { color: var(--muted); font-size: 0.85rem; }
.badge {
  font-size: 0.72rem; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
}
.badge.host { background: #fff4e0; color: #8a5a00; border-color: #f3d9a4; }
.badge.warn { background: #fdeceb; color: var(--danger); border-color: #f2b8b2; }
.ask-card { border-color: #f3d9a4; background: #fffaf0; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 44px; height: 44px; border-radius: 12px; border: 3px solid transparent;
  cursor: pointer; padding: 0; position: relative;
}
.swatch.selected { border-color: var(--text); }
.swatch:disabled { opacity: 0.25; cursor: default; }

/* ---- game ---- */
.game-banner {
  text-align: center; font-weight: 800; font-size: 1.1rem;
  padding: 10px; border-radius: var(--radius); background: var(--card);
  border: 1px solid var(--border); margin: 12px 0 8px;
}
.game-banner.my-turn { border-color: var(--accent); color: var(--accent); }
.clocks { display: flex; gap: 10px; justify-content: center; margin: 4px 0 8px; }
.clock {
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.05rem;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 14px;
}
.clock.low { color: var(--danger); border-color: #f2b8b2; }

.scorebar {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px; margin: 8px 0;
}
.score-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 10px;
}
.score-row.turn { background: var(--turn-bg, #f0f4ff); }
.score-row .who { width: 96px; flex: none; }
.score-row .who .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-row .who .el { color: var(--muted); font-size: 0.75rem; }
.score-row .pts { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.tally { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; min-height: 26px; }

#board-wrap { display: flex; justify-content: center; margin: 10px 0; }
#board {
  display: grid;
  gap: 4px;
  width: min(94vw, 560px);
  aspect-ratio: 1;
}
.cell {
  border: none;
  border-radius: 18%;
  background: var(--empty-cell);
  padding: 0;
  position: relative;
  cursor: default;
  min-width: 0; min-height: 0;
}
.cell.playable { cursor: pointer; }
.cell.playable:active { filter: brightness(0.94); }
.cell .dot {
  position: absolute; inset: 0; margin: auto;
  width: 30%; height: 30%; border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}
/* Shared tile (in two fours): same dot, near-black. The tile
   itself keeps the player colour. */
.cell .dot.dead { background: rgba(18, 18, 20, 0.95); }
.cell.last-move { box-shadow: inset 0 0 0 3px rgba(28, 28, 30, 0.75); }
.cell.pending { opacity: 0.55; }

.reconnect-banner {
  text-align: center; font-weight: 700; color: #8a5a00;
  background: #fff4e0; border: 1px solid #f3d9a4;
  border-radius: 10px; padding: 9px; margin: 8px 0;
}

.game-over h2 { font-size: 1.5rem; }
.over-elo { font-weight: 700; font-size: 1.05rem; }
.over-row { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; background: #fafafa; margin-top: 5px; }
.over-row.winner { outline: 2px solid var(--accent); }
.opponent-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.opponent-actions select { width: auto; flex: 1 1 140px; min-height: 40px; }

/* ---- settings / announcements ---- */
.account-id { word-break: break-all; font-size: 0.82rem; background: var(--bg); padding: 9px 10px; border-radius: 8px; flex: 1; }
.danger-zone { border-color: #f2b8b2; }
.announcement { padding: 12px 0; border-bottom: 1px solid var(--border); }
.announcement:last-child { border-bottom: none; }
.announcement .tag {
  display: inline-block; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.4px;
  padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border);
  text-transform: uppercase;
}
.announcement .tag.update { background: #eaf1fe; color: var(--accent); border-color: #c7dbfb; }
.announcement h3 { margin: 6px 0 3px; font-size: 1rem; }
.announcement .when { color: var(--muted); font-size: 0.8rem; }
.announcement p { white-space: pre-wrap; }

/* ---- toasts & modal ---- */
#toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(92vw, 480px); pointer-events: none;
}
.toast {
  background: rgba(28, 28, 30, 0.94); color: #fff;
  padding: 11px 16px; border-radius: 12px; font-size: 0.95rem;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25); text-align: center;
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  max-width: 420px; width: 100%;
}
.modal h2 { margin-top: 0; }
.modal .row { justify-content: flex-end; margin-top: 14px; }
.rules-modal { max-height: 86vh; overflow-y: auto; }
.rules-modal .rules-list { margin: 4px 0 2px; }
