/* ---------------------------------------------------------------------
   Design tokens
   ------------------------------------------------------------------ */
:root {
  --bg: #0D211E;
  --surface: #15302B;
  --surface-2: #1B3A34;
  --border: #24443D;
  --text: #EAF2EF;
  --text-dim: #9FB8B2;
  --text-faint: #6E8A84;

  --door: #E9A23B;
  --door-dim: #7A5E31;
  --tv: #45C4D6;
  --tv-dim: #2E5A61;
  --positive: #7FD858;
  --negative: #E2545A;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --shadow-card: 0 1px 0 rgba(0,0,0,0.2), 0 8px 24px -12px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(ellipse 900px 500px at 15% -10%, rgba(233,162,59,0.06), transparent 60%),
    radial-gradient(ellipse 900px 500px at 100% 0%, rgba(69,196,214,0.07), transparent 60%);
}

a { color: var(--tv); }

::selection { background: var(--door); color: #201203; }

:focus-visible {
  outline: 2px solid var(--tv);
  outline-offset: 2px;
  border-radius: 4px;
}

button, input {
  font-family: inherit;
  color: inherit;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

/* ---------------------------------------------------------------------
   Header
   ------------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  color: var(--door);
  flex-shrink: 0;
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  padding: 8px 4px;
}
.admin-link:hover { color: var(--tv); }

.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.refresh-btn:hover { background: var(--surface-2); }
.refresh-btn:active { transform: scale(0.97); }
.refresh-btn.spinning svg { animation: spin 0.8s linear infinite; }
.refresh-btn:disabled { opacity: 0.6; cursor: default; }

@keyframes spin { to { transform: rotate(360deg); } }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.status-dot.live { background: var(--positive); box-shadow: 0 0 0 0 rgba(127,216,88,0.6); animation: pulse 2s ease-out infinite; }
.status-dot.cached { background: var(--door); }
.status-dot.error { background: var(--negative); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(127,216,88,0.5); }
  70% { box-shadow: 0 0 0 6px rgba(127,216,88,0); }
  100% { box-shadow: 0 0 0 0 rgba(127,216,88,0); }
}

/* ---------------------------------------------------------------------
   Banner
   ------------------------------------------------------------------ */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(233,162,59,0.1);
  border: 1px solid var(--door-dim);
  color: var(--door);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 20px;
}
.banner strong { color: var(--text); font-weight: 600; }

/* ---------------------------------------------------------------------
   Loading / fatal states
   ------------------------------------------------------------------ */
.loading-state {
  text-align: center;
  color: var(--text-dim);
  padding: 80px 20px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.fatal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  max-width: 480px;
  margin: 40px auto;
}
.fatal-card h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0 0 10px;
}
.fatal-card p { color: var(--text-dim); font-size: 14px; line-height: 1.6; margin: 0 0 8px; }

/* ---------------------------------------------------------------------
   Section shells
   ------------------------------------------------------------------ */
section.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card-head h2 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.card-head .card-note {
  font-size: 12.5px;
  color: var(--text-faint);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 20px;
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------
   Compact match-entry form
   ------------------------------------------------------------------ */
.entry-card { padding-bottom: 18px; }

.entry-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.entry-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.entry-field.grow { flex: 1 1 160px; min-width: 120px; }
.entry-field.score { width: 72px; flex-shrink: 0; }

.entry-field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.entry-field input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 14px;
  color: var(--text);
}
.entry-field input:focus { border-color: var(--tv); }
.entry-field.score input { text-align: center; }

.entry-vs {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 12px;
  padding-bottom: 10px;
  flex-shrink: 0;
}

.entry-submit {
  background: var(--door);
  color: #201203;
  border: none;
  font-weight: 600;
  font-size: 13.5px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.entry-submit:hover { filter: brightness(1.08); }
.entry-submit:active { transform: scale(0.97); }
.entry-submit:disabled { opacity: 0.6; cursor: default; }

.entry-message {
  min-height: 18px;
  font-size: 12.5px;
  margin: 10px 0 0;
  color: var(--text-faint);
}
.entry-message.success { color: var(--positive); }
.entry-message.error { color: var(--negative); }

/* ---------------------------------------------------------------------
   Hero: Door vs TV scoreboard
   ------------------------------------------------------------------ */
.hero {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
}

.hero-caption {
  font-size: 14px;
  color: var(--text-dim);
  margin: 0 0 18px;
  max-width: 60ch;
}
.hero-caption strong { color: var(--text); }

.split-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}
.split-side { display: flex; flex-direction: column; }
.split-side.tv { align-items: flex-end; text-align: right; }
.split-side .side-name {
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
}
.split-side.door .side-name { color: var(--door); }
.split-side.tv .side-name { color: var(--tv); }
.split-side .side-pct {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
}

.split-bar {
  position: relative;
  height: 22px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--tv-dim);
  border: 1px solid var(--border);
}
.split-bar-fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  background: var(--door);
  width: 50%;
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.split-bar-marker {
  position: absolute;
  top: -5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--bg);
  transform: translateX(-50%);
  left: 50%;
  transition: left 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.split-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

/* ---------------------------------------------------------------------
   Leaderboard
   ------------------------------------------------------------------ */
table.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin-bottom: 12px;
}
table.leaderboard th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 500;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--border);
}
table.leaderboard td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.leaderboard tr:last-child td { border-bottom: none; }
table.leaderboard tr:hover td { background: var(--surface-2); }

.rank-cell { font-family: var(--font-mono); color: var(--text-faint); width: 28px; }
.rank-cell.rank-1 { color: var(--door); font-weight: 600; }

.player-cell { font-weight: 600; }

.elo-cell { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; }
.elo-delta { font-size: 11px; margin-left: 6px; font-family: var(--font-mono); }
.elo-delta.up { color: var(--positive); }
.elo-delta.down { color: var(--negative); }

.wl-cell { font-family: var(--font-mono); color: var(--text-dim); white-space: nowrap; }

.form-dots { display: inline-flex; gap: 3px; }
.form-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--border);
}
.form-dot.w { background: var(--positive); }
.form-dot.l { background: var(--negative); }

.streak-badge {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.streak-badge.w { color: var(--positive); background: rgba(127,216,88,0.12); }
.streak-badge.l { color: var(--negative); background: rgba(226,84,90,0.12); }

.suggested-matchup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.suggested-matchup-row:last-child { border-bottom: none; }
.suggested-names {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.suggested-names .vs {
  color: var(--text-faint);
  font-size: 12px;
  margin: 0 4px;
}
.suggested-count {
  color: var(--text-faint);
  font-size: 13px;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------
   Chart
   ------------------------------------------------------------------ */
.chart-wrap { position: relative; height: 260px; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
}
.chart-legend .lg-item {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s ease, color 0.15s ease;
  border-radius: 6px;
  padding: 2px 4px;
  margin: -2px -4px;
}
.chart-legend .lg-swatch { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.chart-legend .lg-item:hover { color: var(--text); }
.chart-legend .lg-item.is-dimmed { opacity: 0.35; }
.chart-legend .lg-item.is-active { color: var(--text); font-weight: 600; }

/* ---------------------------------------------------------------------
   Side-by-side breakdown bars
   ------------------------------------------------------------------ */
.side-row { margin-bottom: 14px; }
.side-row:last-child { margin-bottom: 0; }
.side-row-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}
.side-row-head .name { font-weight: 600; }
.side-bars { display: flex; flex-direction: column; gap: 4px; }
.side-bar-track {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}
.side-bar-label { width: 30px; flex-shrink: 0; }
.side-bar-inner {
  display: block;
  height: 100%;
  border-radius: 999px;
}
.side-bar-inner.door { background: var(--door); }
.side-bar-inner.tv { background: var(--tv); }

.side-bar-outer {
  flex: 0 1 55%;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.side-bar-pct {
  width: 78px;
  text-align: right;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------
   Matchups
   ------------------------------------------------------------------ */
.matchup-list { display: flex; flex-direction: column; gap: 10px; }
.matchup-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.matchup-names { flex: 1; min-width: 0; }
.matchup-names .vs { color: var(--text-faint); font-weight: 400; margin: 0 4px; }
.matchup-bar {
  flex: 1.2;
  display: flex;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--border);
}
.matchup-bar-a { display: block; background: var(--tv); height: 100%; }
.matchup-bar-b { display: block; background: var(--door); height: 100%; }
.matchup-score {
  font-family: var(--font-mono);
  color: var(--text-dim);
  width: 108px;
  text-align: right;
  flex-shrink: 0;
  line-height: 1.35;
}
.matchup-winrate {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
}

/* ---------------------------------------------------------------------
   Fun facts
   ------------------------------------------------------------------ */
.facts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 700px) {
  .facts-grid { grid-template-columns: 1fr; }
}
.fact-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}
.fact-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 8px;
}
.fact-body { font-size: 13.5px; line-height: 1.55; }
.fact-body strong { color: var(--door); }
.fact-empty { color: var(--text-faint); font-size: 13px; }

/* ---------------------------------------------------------------------
   Match history
   ------------------------------------------------------------------ */
.recent-list { display: flex; flex-direction: column; }
.recent-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.recent-row:last-child { border-bottom: none; }
.recent-name { font-weight: 500; }
.recent-name.winner { font-weight: 700; color: var(--text); }
.recent-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 5px;
}
.recent-tag.door { color: var(--door); background: rgba(233,162,59,0.12); }
.recent-tag.tv { color: var(--tv); background: rgba(69,196,214,0.12); }
.recent-score {
  font-family: var(--font-mono);
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
}
.recent-time {
  font-family: var(--font-mono);
  color: var(--text-faint);
  font-size: 11.5px;
  width: 60px;
  text-align: right;
  flex-shrink: 0;
}

/* Win/loss row tinting */
table.admin-table tr.row-win td,
table.admin-table tr.row-loss td {
  padding-left: 12px;
  padding-right: 12px;
}
table.admin-table tr.row-win td { background: rgba(127,216,88,0.10); }
table.admin-table tr.row-loss td { background: rgba(226,84,90,0.10); }
table.admin-table tr.row-win:hover td { background: rgba(127,216,88,0.18); }
table.admin-table tr.row-loss:hover td { background: rgba(226,84,90,0.18); }

table.admin-table tr.row-win td:first-child,
table.admin-table tr.row-loss td:first-child {
  border-radius: 6px 0 0 6px;
}
table.admin-table tr.row-win td:last-child,
table.admin-table tr.row-loss td:last-child {
  border-radius: 0 6px 6px 0;
}

.recent-row.row-win,
.recent-row.row-loss {
  padding: 10px 14px;
  margin: 0 -14px;
  border-radius: 8px;
}
.recent-row.row-win { background: rgba(127,216,88,0.10); }
.recent-row.row-loss { background: rgba(226,84,90,0.10); }

/* ---------------------------------------------------------------------
   Admin table
   ------------------------------------------------------------------ */
.admin-table-wrap { overflow-x: auto; }
table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 640px;
}
table.admin-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 500;
  padding: 0 8px 8px;
  border-bottom: 1px solid var(--border);
}
table.admin-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.admin-table tr:hover td { background: var(--surface-2); }

.admin-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--tv-dim);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
}
.admin-input.num { width: 64px; text-align: center; }

.admin-actions { display: flex; gap: 6px; white-space: nowrap; }
.admin-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.admin-btn:hover { filter: brightness(1.15); }
.admin-btn.primary { background: var(--tv); color: #06232a; border-color: var(--tv); font-weight: 600; }
.admin-btn.danger { color: var(--negative); }
.admin-btn.danger:hover { background: rgba(226,84,90,0.12); }

/* ---------------------------------------------------------------------
   Login page
   ------------------------------------------------------------------ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-mark { width: 32px; height: 32px; color: var(--door); margin-bottom: 4px; }
.login-card h1 {
  font-family: var(--font-display);
  font-size: 19px;
  margin: 0;
}
.login-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 8px; }
.login-card label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-top: 6px;
}
.login-card input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
}
.login-card input:focus { border-color: var(--tv); }
.login-card button {
  margin-top: 14px;
  background: var(--door);
  color: #201203;
  border: none;
  font-weight: 600;
  font-size: 14px;
  padding: 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.login-card button:hover { filter: brightness(1.08); }
.login-error {
  background: rgba(226,84,90,0.12);
  border: 1px solid var(--negative);
  color: var(--negative);
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.login-back {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-faint);
  text-decoration: none;
  margin-top: 8px;
}
.login-back:hover { color: var(--tv); }

/* ---------------------------------------------------------------------
   Footer
   ------------------------------------------------------------------ */
.foot {
  text-align: center;
  color: var(--text-faint);
  font-size: 11.5px;
  margin-top: 30px;
}

/* ---------------------------------------------------------------------
   Tabs
   ------------------------------------------------------------------ */
.tab-bar {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 4px;
  margin-right: 18px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab-btn:hover { color: var(--text-dim); }
.tab-btn.is-active { color: var(--text); border-bottom-color: var(--door); }
.tab-panel[hidden] { display: none; }

/* Match History panel */
.history-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.history-controls label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}
.history-controls select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
}
table.history-table .player-cell.winner { color: var(--text); font-weight: 700; }
.history-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
}
.history-pagination .admin-btn:disabled { opacity: 0.5; cursor: default; }

.recent-elo {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  margin-left: 4px;
}