:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #14b8a6;
  --primary-dark: #0f766e;
  --danger: #ef4444;
  --gold: #fbbf24;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* --------------------------- App bar --------------------------- */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: linear-gradient(180deg, var(--primary-dark), #0b5a54);
  box-shadow: var(--shadow);
}

.app-bar h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar-spacer { flex: 1; }

/* ----------------------------- View ---------------------------- */

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 6px 0 0;
  font-weight: 700;
}
.section-title.flush { margin-top: 0; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------------------------- Buttons -------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }

.btn-primary { background: var(--primary); color: #042f2a; }
.btn-primary:hover { background: #2dd4bf; }

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px dashed var(--border);
}
.btn-ghost:hover { background: var(--surface); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.4);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); }

.icon-btn {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.danger { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

/* ----------------------------- Cards --------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.game-card {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
}
.game-card:active { transform: scale(0.99); }
.game-card-main { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.game-card-name { font-size: 1.05rem; font-weight: 700; }
.game-card-meta { font-size: 0.82rem; }
.game-card-players { font-size: 0.85rem; white-space: nowrap; }

.badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-active { background: rgba(20, 184, 166, 0.18); color: #5eead4; }
.badge-done { background: rgba(251, 191, 36, 0.18); color: var(--gold); }

/* ----------------------------- Empty --------------------------- */

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text);
}
.empty p { margin: 6px 0; }

/* ----------------------------- Forms --------------------------- */

.stack { display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 1rem;
  color: var(--text);
  font-family: inherit;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.2);
}
.input::placeholder { color: #64748b; }

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

.error { color: #fca5a5; font-size: 0.9rem; margin: 0; }

/* --------------------------- Standings ------------------------- */

.standings { display: flex; flex-direction: column; gap: 10px; }

.standing-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.standing-rank {
  flex: 0 0 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--muted);
}
.standing-row.reached .standing-rank { background: rgba(251, 191, 36, 0.2); color: var(--gold); }
.standing-body { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.standing-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.standing-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standing-total { font-weight: 700; font-size: 1.1rem; }

.progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  border-radius: 999px;
  transition: width 0.3s ease;
}
.standing-row.reached .progress-bar { background: linear-gradient(90deg, #d97706, var(--gold)); }

/* -------------------------- Winner banner ---------------------- */

.winner-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.18), rgba(20, 184, 166, 0.12));
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: var(--radius);
  padding: 16px;
}
.winner-trophy { font-size: 2.2rem; }
.winner-title { font-size: 1.25rem; font-weight: 800; }
.winner-sub { font-size: 0.85rem; }

/* --------------------------- Add round ------------------------- */

.score-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.score-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.score-input { flex: 0 0 110px; text-align: right; }

/* ------------------------- Rounds history ---------------------- */

.rounds-scroll { overflow-x: auto; }

.round-row {
  display: grid;
  grid-template-columns: 28px repeat(var(--cols, 2), minmax(56px, 1fr)) 38px;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.round-row:last-child { border-bottom: none; }

.round-head {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 700;
}
.round-num { text-align: center; color: var(--muted); font-weight: 700; font-size: 0.85rem; }
.round-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
}
.round-head .round-cell { align-items: flex-end; white-space: nowrap; }
.round-score { font-weight: 700; }
.round-cumulative { font-size: 0.72rem; }
.round-del { display: flex; justify-content: center; }
.round-head .round-del { width: 38px; }
.round-del.icon-btn { width: 32px; height: 32px; font-size: 0.85rem; }

.hint { font-size: 0.75rem; margin: 0; }
