* { box-sizing: border-box; margin: 0; padding: 0; }

/* Dark is the default; light is applied by system preference (auto) or manual override. */
:root {
  --felt: #1a5c3a;
  --felt-dark: #114228;
  --bg: #0d1117;
  --panel: #161d27;
  --panel-2: #1f2937;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #c8686b;
  --red: #e5534b;
  --green: #3fb950;
  --blue: #4493f8;
  --border: #2b3646;
  --border-2: #384657;
  --border-soft: #222b38;
  --me-bg: #1b2536;
  --radius: 12px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef1f5;
    --panel: #ffffff;
    --panel-2: #e9edf3;
    --text: #1a2330;
    --muted: #5a6876;
    --accent: #9e3d3a;
    --red: #c93c37;
    --green: #1a7f37;
    --blue: #0b69da;
    --border: #d6dde5;
    --border-2: #c3ccd6;
    --border-soft: #e5eaef;
    --me-bg: #e5effb;
  }
}

:root[data-theme="light"] {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #e9edf3;
  --text: #1a2330;
  --muted: #5a6876;
  --accent: #9e3d3a;
  --red: #c93c37;
  --green: #1a7f37;
  --blue: #0b69da;
  --border: #d6dde5;
  --border-2: #c3ccd6;
  --border-soft: #e5eaef;
  --me-bg: #e5effb;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 12px 48px;
}

.hidden { display: none !important; }

/* ---------- brand ---------- */
.brand { text-align: center; padding: 28px 0 10px; }
.brand.small { padding: 10px 0 4px; }
.brand h1 {
  display: inline-block;
  font-size: 1.35rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.45em;
  margin-right: -0.45em; /* cancel trailing letter-space so the rule stays centered */
  padding-bottom: 10px;
  border-bottom: 1px solid var(--accent);
}
.brand h1::before {
  content: "";
  display: inline-block;
  width: 1em;
  height: 1em;
  border-radius: 50%;
  background: var(--accent);
  border: 2px dashed rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 2px var(--accent);
  vertical-align: -0.14em;
  margin-right: 0.6em;
}
.brand.small h1 { font-size: 0.9rem; padding-bottom: 6px; }
.brand.small h1::before {
  border-width: 1.5px;
  box-shadow: 0 0 0 1.5px var(--accent);
}

/* ---------- generic ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
}
.card h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 10px; }
.card.center { text-align: center; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }

input, select {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
}
input:focus, select:focus { outline: 2px solid var(--blue); border-color: transparent; }

.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }

.code-input {
  text-transform: uppercase;
  letter-spacing: 6px;
  font-weight: 700;
  text-align: center;
  font-size: 1.2rem;
}

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.settings-grid input, .settings-grid select { padding: 8px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 13px 16px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
  transition: filter 0.1s;
}
.btn:active { filter: brightness(1.25); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: #2e7d4f; color: #fff; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn.ghost { background: transparent; border: 1px solid var(--border-2); color: var(--muted); }
.btn.small { padding: 8px 12px; font-size: 0.9rem; }
/* action buttons keep fixed saturated colors in both themes */
.btn.fold { background: #d64545; color: #fff; }
.btn.call { background: #2ea043; color: #fff; }
.btn.raise { background: #316dca; color: #fff; }
.btn.seat {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--muted);
  padding: 2px 8px;
  font-size: 0.8rem;
  border-radius: 6px;
  flex: none;
}
.row-controls { display: flex; align-items: center; gap: 6px; }
.help-note { margin-top: 10px; line-height: 1.5; }
.help-note b { color: var(--text); }
.btn.kick {
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 2px 9px;
  font-size: 0.8rem;
  border-radius: 6px;
  flex: none;
  margin-left: 8px;
}

.error { color: var(--red); margin-top: 12px; text-align: center; }
.hint { color: var(--muted); font-size: 0.9rem; }
.center { text-align: center; }

.game-code {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 12px;
  color: var(--accent);
  margin: 8px 0;
  padding-left: 12px; /* visually balance letter-spacing */
}

.lobby-list { list-style: none; }
.lobby-list li {
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}
.lobby-list li:last-child { border-bottom: none; }
.host-tag { color: var(--accent); font-size: 0.8rem; }

/* ---------- table ---------- */
.table-top {
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  border: 2px solid #0c3620;
  border-radius: 20px;
  padding: 18px 14px;
  text-align: center;
  margin-top: 8px;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35);
}
.table-meta { display: flex; justify-content: space-between; margin-bottom: 6px; }
.chip-label { font-size: 0.75rem; color: rgba(255, 255, 255, 0.65); letter-spacing: 1px; }
.pot-amount { font-size: 2.6rem; font-weight: 800; color: #fff; text-shadow: 0 2px 6px rgba(0,0,0,0.5); }
.pot-label { font-size: 0.7rem; letter-spacing: 4px; color: #f0c5c2; }
.dealer-prompt {
  margin-top: 10px;
  font-size: 0.95rem;
  color: #ffe0dc;
  min-height: 1.2em;
}

/* players */
.player-list { list-style: none; margin-top: 14px; }
.player-list li {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "who stack" "status bet";
  gap: 2px 8px;
}
.player-list li.actor { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.player-list li.folded { opacity: 0.45; }
.player-list li.me { background: var(--me-bg); }

.p-who { grid-area: who; display: flex; align-items: center; gap: 6px; font-weight: 600; }
.p-stack { grid-area: stack; text-align: right; font-weight: 700; color: var(--accent); }
.p-status { grid-area: status; font-size: 0.8rem; color: var(--muted); }
.p-bet { grid-area: bet; text-align: right; font-size: 0.85rem; color: var(--green); font-weight: 600; }

.badge {
  font-size: 0.62rem;
  font-weight: 800;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.badge.d { background: #fff; color: #111; border: 1px solid rgba(0, 0, 0, 0.3); }
.badge.sb { background: var(--blue); color: #fff; }
.badge.bb { background: var(--accent); color: #fff; }
.dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--green);
}
.dot.off { background: var(--red); }

/* action bar */
.action-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 10px 0 14px;
  border-top: 1px solid var(--border);
  margin-top: 10px;
  z-index: 5;
}
.action-buttons { display: flex; gap: 8px; }
.action-buttons .btn { flex: 1; }

.raise-panel { padding-bottom: 10px; }
.raise-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.raise-row input[type="range"] { flex: 2; accent-color: var(--accent); }
.raise-row input[type="number"] { flex: 1; text-align: center; font-weight: 700; }
.raise-presets { display: flex; gap: 8px; margin-bottom: 10px; }
.raise-presets .btn { flex: 1; }

.wait-note {
  text-align: center;
  color: var(--muted);
  padding: 12px;
  font-size: 0.95rem;
}

/* showdown */
.pot-box {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 12px;
  margin-top: 10px;
}
.pot-box h3 { font-size: 0.95rem; margin-bottom: 8px; }
.pot-box h3 span { color: var(--accent); }
.winner-options { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.winner-options label {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 0.95rem;
  margin: 0;
  cursor: pointer;
}
.winner-options input { width: auto; }
.pot-awarded { color: var(--green); font-size: 0.9rem; }

/* hand over */
#hand-result { margin-bottom: 4px; }
#hand-result p { padding: 4px 0; color: var(--accent); font-weight: 600; }
.rebuy-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); margin-top: 8px; }

/* log */
.log-list { list-style: none; max-height: 180px; overflow-y: auto; font-size: 0.82rem; color: var(--muted); }
.log-list li { padding: 3px 0; border-bottom: 1px solid var(--border-soft); }

/* toast */
.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 50;
  max-width: 90%;
  text-align: center;
}

/* theme toggle */
.theme-btn {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 60;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

/* collapsible cards */
details.card summary {
  cursor: pointer;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  user-select: none;
}
details.card[open] summary { margin-bottom: 12px; }

/* scoreboard */
#scoreboard table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
#scoreboard th, #scoreboard td {
  padding: 7px 4px;
  text-align: right;
  border-bottom: 1px solid var(--border-soft);
}
#scoreboard th:first-child, #scoreboard td:first-child { text-align: left; }
#scoreboard th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#scoreboard tr:last-child td { border-bottom: none; }
.net-pos { color: var(--green); font-weight: 700; }
.net-neg { color: var(--red); font-weight: 700; }

/* turn timer */
.timer-note { text-align: center; color: var(--accent); font-weight: 700; padding-bottom: 8px; }
.countdown { color: var(--accent); font-weight: 700; }

/* tournament level clock */
.level-note {
  font-size: 0.78rem;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 6px;
}
.level-countdown { font-weight: 700; color: #ffe0dc; }

/* join QR */
.qr-box {
  width: 152px;
  margin: 10px auto 6px;
  padding: 8px;
  background: #fff;
  border-radius: 10px;
}
.qr-box:empty { display: none; }
.qr-box svg { display: block; width: 100%; height: auto; }

/* straddle opt-in */
.btn.straddle-btn { margin-top: 10px; border: 1px dashed var(--border-2); background: transparent; color: var(--muted); }
.btn.straddle-btn.on { border-style: solid; border-color: var(--accent); color: var(--accent); background: transparent; }

/* settle up + payouts */
.settle-list { list-style: none; }
.settle-list li { padding: 8px 2px; border-bottom: 1px solid var(--border-soft); }
.settle-list li:last-child { border-bottom: none; }
#league-panel { margin-top: 10px; border-top: 1px solid var(--border-soft); padding-top: 6px; }
#league-panel .btn.wide { margin-top: 10px; }

/* more-options on the create form */
#more-options { margin: 4px 0 2px; }
#more-options summary { cursor: pointer; padding: 6px 0 10px; user-select: none; }
#more-options label { margin-top: 6px; }
.check-label { display: flex; align-items: center; gap: 8px; }
.check-label input { width: auto; margin-top: 14px; transform: scale(1.3); }

/* cheat sheet */
.cheat-list { list-style: none; counter-reset: rank; }
.cheat-list li {
  counter-increment: rank;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.9rem;
}
.cheat-list li::before { content: counter(rank) "."; color: var(--muted); min-width: 1.4em; }
.cheat-list li b { flex: 1; }
.cheat-list li span { color: var(--muted); }
.cheat-list li:last-child { border-bottom: none; }
.cheat-list + .hint { margin-top: 8px; }

/* league leaderboard */
.league-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.league-table th, .league-table td {
  padding: 8px 4px;
  text-align: right;
  border-bottom: 1px solid var(--border-soft);
}
.league-table th:first-child, .league-table td:first-child { text-align: left; }
.league-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.league-table tr:last-child td { border-bottom: none; }
