/* ---------------------------------------------------------------------- */
/* Design tokens — Apple (iOS/macOS) dark-mode system palette             */
/* ---------------------------------------------------------------------- */
:root {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --surface-elevated: #3a3a3c;
  --fill: rgba(120, 120, 128, 0.24);
  --fill-secondary: rgba(120, 120, 128, 0.16);

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);

  --text: #ffffff;
  --text-muted: rgba(235, 235, 245, 0.6);
  --text-faint: rgba(235, 235, 245, 0.3);

  --accent: #0a84ff;
  --accent-strong: #409cff;
  --accent-soft: rgba(10, 132, 255, 0.16);

  /* Fixed reference blue — unlike --accent, this never changes with page theme.
     Used for UI that must stay a specific color regardless of context, like the
     tournament ledger button. */
  --blue: #0a84ff;

  --gold: #ffd60a;
  --gold-soft: rgba(255, 214, 10, 0.14);
  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.14);
  --danger: #ff453a;
  --danger-soft: rgba(255, 69, 58, 0.16);

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

/* Cash game pages swap the interactive accent from blue to green. */
body.theme-cashgame {
  --accent: #30d158;
  --accent-strong: #5de585;
  --accent-soft: rgba(48, 209, 88, 0.16);
}

* { box-sizing: border-box; }

::selection { background: var(--accent-soft); color: var(--text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface-elevated); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

html { color-scheme: dark; }

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

/* ---------------------------------------------------------------------- */
/* Header                                                                 */
/* ---------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.5rem;
}

.topbar-inner {
  max-width: 1220px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
}

@media (max-width: 640px) {
  .topbar-actions { justify-content: flex-start; }
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.home-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--fill);
  color: var(--text-muted);
  transition: color 0.12s ease, background 0.12s ease;
}

.home-btn:hover {
  color: var(--accent);
  background: var(--surface-2);
}

.topbar-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: nowrap;
  justify-content: flex-end;
  margin-left: 0.5cm;
}

.topbar-actions button {
  padding: 0.42rem 0.7rem;
  font-size: 0.78rem;
  min-width: 132px;
  text-align: center;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .topbar-actions { flex-wrap: wrap; }
}

.ledger-btn {
  background: var(--fill);
}

/* These three keep their identity color on every page, including cash game
   pages where --accent itself is swapped to green — so they reference fixed
   color tokens instead of --accent. */
.ledger-btn-tournament { color: var(--blue); }
.ledger-btn-cashgame { color: var(--green); }
.ledger-btn-total { color: var(--text); }

.brand-icon {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
}

/* ---------------------------------------------------------------------- */
/* Layout                                                                 */
/* ---------------------------------------------------------------------- */
.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

h1, h2, h3 { margin-top: 0; letter-spacing: -0.01em; font-weight: 700; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.08rem; }
h3 { font-size: 0.95rem; }

.muted { color: var(--text-muted); }

/* ---------------------------------------------------------------------- */
/* Cards — flat grouped surfaces, no gradients, no heavy shadows          */
/* ---------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  margin-bottom: 1.25rem;
}

.header-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.quick-add-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: -0.5rem 0 1rem;
}

.chip-form {
  display: inline-flex;
  align-items: stretch;
  background: var(--fill);
  border-radius: 999px;
  overflow: hidden;
}

.chip-btn {
  background: transparent;
  color: var(--accent);
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.chip-form .chip-btn { border-radius: 0; }

.chip-remove {
  background: transparent;
  color: var(--text-faint);
  padding: 0.35rem 0.65rem 0.35rem 0.25rem;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
}

.chip-remove:hover { color: var(--danger); background: var(--danger-soft); }

.manage-players-link {
  display: inline-block;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-decoration: none;
  margin: -0.4rem 0 1rem;
}

.manage-players-link:hover { color: var(--accent); }

.row-muted { opacity: 0.55; }

.quick-add-more { display: inline-block; vertical-align: top; }

.quick-add-more summary {
  display: inline-block;
  list-style: none;
  cursor: pointer;
  white-space: nowrap;
}

.quick-add-more summary::-webkit-details-marker { display: none; }

.quick-add-more[open] summary { display: none; }

.quick-add-chips-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.bulk-add, .payout-more {
  margin: 0 0 1rem;
}

.bulk-add summary, .payout-more summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.bulk-add summary::-webkit-details-marker, .payout-more summary::-webkit-details-marker { display: none; }

.bulk-add summary::before, .payout-more summary::before {
  content: "\25B8";
  display: inline-block;
  transition: transform 0.15s ease;
}

.bulk-add[open] summary::before, .payout-more[open] summary::before { transform: rotate(90deg); }

.payout-grid-extra { margin-top: 0.5rem; }

@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------- */
/* Forms                                                                  */
/* ---------------------------------------------------------------------- */
.form-row {
  display: flex;
  gap: 0.9rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

/* Labels carry a bottom margin for wrapped-row spacing; buttons need the same
   margin so align-items: flex-end lines their bottom edges up with the inputs. */
.form-row > button {
  margin-bottom: 0.5rem;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.form-row .grow { flex: 1; }

.payout-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

@media (max-width: 600px) {
  .payout-grid { grid-template-columns: repeat(2, 1fr); }
}

input, select, textarea, button {
  font-family: inherit;
}

input, select, textarea {
  font-size: 0.95rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--fill);
  color: var(--text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

textarea {
  width: 100%;
  resize: vertical;
  line-height: 1.4;
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                */
/* ---------------------------------------------------------------------- */
button {
  padding: 0.58rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--accent);
  color: #ffffff;
  transition: opacity 0.12s ease, background 0.12s ease;
}

button:hover { opacity: 0.85; }
button:active { opacity: 0.7; }

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

button.secondary {
  background: var(--fill);
  color: var(--accent);
}

button.danger {
  background: var(--fill);
  color: var(--danger);
}

button.link-danger {
  background: none;
  border: none;
  color: var(--danger);
  padding: 0;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

button.link-danger:hover { opacity: 0.7; }

.timer-btn-primary.is-running {
  background: var(--fill);
  color: var(--gold);
}

/* ---------------------------------------------------------------------- */
/* Tables — grouped list style with hairline separators                  */
/* ---------------------------------------------------------------------- */

/* On narrow screens, scroll the table horizontally instead of letting its
   text overflow/wrap awkwardly inside cramped cells. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 0.6rem;
}

@media (max-width: 640px) {
  .table-scroll table {
    width: max-content;
    min-width: 100%;
  }

  .table-scroll th,
  .table-scroll td {
    white-space: nowrap;
  }
}

th {
  text-align: left;
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, 0.03); }

.positive { color: var(--green); font-weight: 600; }
.negative { color: var(--danger); font-weight: 600; }

/* ---------------------------------------------------------------------- */
/* Badges & flashes                                                       */
/* ---------------------------------------------------------------------- */
.badge {
  display: inline-block;
  background: var(--fill);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.badge-active { background: var(--green-soft); color: var(--green); margin-left: 0; }
.badge-out { background: var(--fill); color: var(--text-muted); margin-left: 0; }

.flash-list { margin-bottom: 1.25rem; }

.flash {
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.flash-success {
  background: var(--green-soft);
  color: var(--green);
}

.flash-error {
  background: var(--danger-soft);
  color: #ff8078;
}

/* ---------------------------------------------------------------------- */
/* Mode select (landing page)                                            */
/* ---------------------------------------------------------------------- */
.mode-select {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-top: 1.5rem;
}

@media (max-width: 600px) {
  .mode-select { grid-template-columns: 1fr; }
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.75rem 1.5rem;
  text-decoration: none;
  color: var(--text);
  transition: background 0.12s ease, transform 0.12s ease;
}

.mode-card:hover { background: var(--surface-2); transform: translateY(-2px); }
.mode-card:active { transform: translateY(0); }

.mode-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 0.4rem;
}

.mode-turnering .mode-icon { background: var(--accent-soft); }
.mode-cashgame .mode-icon { background: var(--green-soft); }

.mode-title { font-size: 1.15rem; font-weight: 700; }
.mode-desc { color: var(--text-muted); font-size: 0.9rem; }

.coming-soon {
  text-align: center;
  padding: 3rem 1.5rem;
}

/* ---------------------------------------------------------------------- */
/* Tournament list — Apple "grouped inset list" pattern                  */
/* ---------------------------------------------------------------------- */
.tournament-list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tournament-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 1.1rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s ease;
}

.tournament-item:last-child { border-bottom: none; }
.tournament-item:hover { background: rgba(255, 255, 255, 0.04); }

.tournament-item.finished { opacity: 0.55; }

.tournament-item-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0;
  text-decoration: none;
  color: var(--text);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tournament-item-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.bulk-checkbox {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.bulk-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.bulk-select-all-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0;
  cursor: pointer;
}

.bulk-select-all-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.pot {
  font-weight: 600;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.chevron {
  color: var(--text-faint);
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
}

.back-link:hover { opacity: 0.75; }

/* ---------------------------------------------------------------------- */
/* Blind timer                                                           */
/* ---------------------------------------------------------------------- */
.timer-card { text-align: center; }

.timer-panel { padding: 0.4rem 0 0.5rem; }

.timer-level {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-strong);
  background: var(--accent-soft);
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  margin-bottom: 1.1rem;
}

.timer-clock {
  font-size: clamp(3.2rem, 9vw, 5.5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 0 30px rgba(10, 132, 255, 0.25);
  margin-bottom: 1.1rem;
}

.timer-clock.warning {
  color: var(--danger);
  text-shadow: 0 0 30px rgba(255, 69, 58, 0.45);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.timer-progress {
  width: min(420px, 90%);
  height: 5px;
  background: var(--fill);
  border-radius: 999px;
  margin: 0 auto 1.6rem;
  overflow: hidden;
}

.timer-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 1s linear;
}

.timer-blinds-row {
  display: flex;
  justify-content: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.blind-box {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.4rem;
  min-width: 96px;
}

.blind-box.hidden { display: none; }

.blind-box-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.blind-box-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

.timer-next {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.timer-controls {
  display: flex;
  justify-content: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.58rem;
  line-height: 0;
}

.icon-btn .icon-compress { display: none; }
.icon-btn.is-fullscreen .icon-expand { display: none; }
.icon-btn.is-fullscreen .icon-compress { display: inline; }

/* Fullscreen mode: the timer card itself becomes the fullscreen element
   (e.g. shown on a TV), so scale everything way up and hide the setup UI. */
.timer-card:fullscreen,
.timer-card:-webkit-full-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  background: var(--bg);
  border: none;
  border-radius: 0;
  padding: 2rem;
}

.timer-card:fullscreen .timer-heading,
.timer-card:-webkit-full-screen .timer-heading,
.timer-card:fullscreen .blind-settings,
.timer-card:-webkit-full-screen .blind-settings {
  display: none;
}

.timer-card:fullscreen .timer-level,
.timer-card:-webkit-full-screen .timer-level {
  font-size: clamp(1.3rem, 2.6vw, 2.2rem);
  padding: 0.5rem 1.6rem;
  margin-bottom: 2rem;
}

.timer-card:fullscreen .timer-clock,
.timer-card:-webkit-full-screen .timer-clock {
  font-size: clamp(7rem, 20vw, 15rem);
  margin-bottom: 2rem;
}

.timer-card:fullscreen .timer-progress,
.timer-card:-webkit-full-screen .timer-progress {
  width: min(700px, 80vw);
  height: 10px;
  margin-bottom: 2.5rem;
}

.timer-card:fullscreen .timer-blinds-row,
.timer-card:-webkit-full-screen .timer-blinds-row {
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.timer-card:fullscreen .blind-box,
.timer-card:-webkit-full-screen .blind-box {
  padding: 1.2rem 2.6rem;
}

.timer-card:fullscreen .blind-box-label,
.timer-card:-webkit-full-screen .blind-box-label {
  font-size: clamp(0.9rem, 1.6vw, 1.3rem);
}

.timer-card:fullscreen .blind-box-value,
.timer-card:-webkit-full-screen .blind-box-value {
  font-size: clamp(2.4rem, 6vw, 4.5rem);
}

.timer-card:fullscreen .timer-next,
.timer-card:-webkit-full-screen .timer-next {
  font-size: clamp(1rem, 2vw, 1.6rem);
  margin-bottom: 2rem;
}

.timer-card:fullscreen .timer-controls,
.timer-card:-webkit-full-screen .timer-controls {
  transform: scale(1.15);
}

/* ---------------------------------------------------------------------- */
/* Blind level editor                                                     */
/* ---------------------------------------------------------------------- */
.blind-settings {
  margin-top: 1.5rem;
  text-align: left;
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
}

.blind-settings summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.blind-settings summary::-webkit-details-marker { display: none; }

.blind-settings summary::before {
  content: "\25B8";
  display: inline-block;
  transition: transform 0.15s ease;
}

.blind-settings[open] summary::before { transform: rotate(90deg); }

.blind-settings h3 {
  margin: 1.4rem 0 0.5rem;
  color: var(--text);
}

.generate-block {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 0.25rem;
  margin: 1rem 0 1.4rem;
}

.generate-block h3 { margin-top: 0; }

.generate-block p.muted {
  font-size: 0.85rem;
  margin-top: 0;
  max-width: 62ch;
}

.blind-table {
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 0.5rem;
}

.blind-row {
  display: grid;
  grid-template-columns: 1.5rem 1fr 1fr 1fr 1fr auto auto;
  gap: 0.4rem;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.blind-row:last-child { border-bottom: none; }

.blind-row-head {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: transparent;
}

.blind-row.current-level {
  background: var(--accent-soft);
}

.blind-row input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  font-size: 0.88rem;
  background: var(--fill);
}

@media (max-width: 600px) {
  .blind-row { grid-template-columns: 1.2rem repeat(4, 1fr) auto auto; font-size: 0.85rem; }
}
