:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --nav-bg: #09090b;
  --nav-text: #fafafa;
  --text: #09090b;
  --text-secondary: #71717a;
  --border: #e4e4e7;
  --border-hover: #d4d4d8;
  --accent: #18181b;
  --accent-hover: #27272a;
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --violet: #7c3aed;
  --violet-hover: #6d28d9;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --red: #dc2626;
  --red-hover: #b91c1c;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06);
  --transition: 150ms ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Navigation ────────────────────────────────────────── */

header {
  background: var(--nav-bg);
  position: sticky;
  top: 0;
  z-index: 100;
}

nav {
  display: flex;
  align-items: center;
  max-width: 1000px;
  margin: 0 auto;
  height: 52px;
  padding: 0 24px;
  gap: 32px;
}

.nav-brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--nav-text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  gap: 2px;
}

.nav-links a {
  color: var(--nav-text);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0.55;
  transition: opacity var(--transition), background var(--transition);
}

.nav-links a:hover { opacity: 0.85; }
.nav-links a.active { opacity: 1; background: rgba(255,255,255,.1); }

.nav-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-username {
  font-size: 13px;
  font-weight: 500;
  color: var(--nav-text);
  opacity: 0.7;
}

.nav-logout {
  font-size: 12px;
  color: var(--nav-text);
  opacity: 0.4;
  text-decoration: none;
  transition: opacity var(--transition);
}

.nav-logout:hover { opacity: 0.8; }

/* ── Layout ────────────────────────────────────────────── */

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section-header select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
}

.section-header select:focus {
  border-color: var(--accent);
}

/* ── Shared components ─────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
}

.btn:hover { background: var(--accent-hover); }

.btn-full { width: 100%; padding: 11px; font-size: 14px; }

.btn-sm { padding: 6px 14px; font-size: 12px; }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--border);
}

.btn-danger:hover { background: #fef2f2; border-color: #fecaca; }

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  background: #f4f4f5;
  color: var(--text-secondary);
}

.pill-admin { background: #ede9fe; color: #6d28d9; }
.pill-manager { background: #fef3c7; color: #b45309; }
.pill-voter { background: #f0fdf4; color: #16a34a; }

.status-msg {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ── Login ─────────────────────────────────────────────── */

.login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 64px);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.login-header p {
  font-size: 13px;
  color: var(--text-secondary);
}

.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--red);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}

.form-field {
  margin-bottom: 16px;
}

.form-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 5px;
}

.form-field input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0,0,0,.06);
}

.login-card .btn { margin-top: 8px; }

/* ── Vote page ─────────────────────────────────────────── */

.instructions-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
  position: relative;
}

.instructions-card .label {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.instructions-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.instructions-card li {
  position: relative;
  padding-left: 16px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.instructions-card li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.instructions-card li:last-child { margin-bottom: 0; }

.vote-counter {
  position: absolute;
  top: 20px;
  right: 24px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: #f4f4f5;
  padding: 4px 12px;
  border-radius: 100px;
}

.sentence-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  margin-bottom: 16px;
}

.sentence-card .label {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.sentence-card p {
  font-size: 16px;
  line-height: 1.7;
  letter-spacing: -0.01em;
}

.audio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.audio-card {
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  transition: border-color var(--transition);
}

.card-a-tint { background: #eff6ff; }
.card-b-tint { background: #f5f3ff; }

.audio-card h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 14px;
  text-align: center;
}

.audio-card audio { display: none; }

/* Waveform player */
.waveform-player {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wave-play {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.wave-play:hover {
  background: #f4f4f5;
  border-color: var(--border-hover);
}

.wave-play svg {
  width: 14px;
  height: 14px;
}

.wave-track {
  flex: 1;
  position: relative;
  height: 40px;
  cursor: pointer;
}

.wave-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.wave-progress {
  display: none;
}

.wave-time {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}

.listen-warning {
  text-align: center;
  font-size: 13px;
  color: var(--red);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 12px;
}

/* Vote buttons */
.vote-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.vote-btn {
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background var(--transition), transform var(--transition);
}

.vote-btn:hover:not(:disabled) {
  background: #3f3f46;
  transform: translateY(-1px);
}

.vote-btn:active:not(:disabled) { transform: translateY(0); }

.vote-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.result-card {
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  margin-top: 16px;
}

.result-card p {
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.6;
}

/* ── Leaderboard ───────────────────────────────────────── */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
}

.table-wrap th,
.table-wrap td {
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.table-wrap thead th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  background: #fafafa;
}

.table-wrap tbody tr:last-child td { border-bottom: none; }

.table-wrap tbody tr:hover { background: #fafafa; }

.lb-rank {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.lb-range {
  font-weight: 600;
  font-size: 12px;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}

.lb-creator { font-weight: 600; }

.lb-model { color: var(--text-secondary); }

.lb-elo {
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.lb-ci {
  color: var(--text-secondary);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.lb-footer {
  text-align: center;
  margin-top: 14px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.6;
}

/* ── History ───────────────────────────────────────────── */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}

.user-badge {
  background: #f4f4f5;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.matchup-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.matchup-models {
  font-weight: 500;
  font-size: 13px;
}

.matchup-models .winner { color: var(--green); font-weight: 600; }

.sentence-preview {
  color: var(--text-secondary);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-time {
  color: var(--text-secondary);
  font-size: 11px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── Admin ─────────────────────────────────────────────── */

.admin-section {
  margin-bottom: 32px;
}

.admin-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
}

.cell-primary { font-weight: 500; }

.cell-actions form { display: inline; }

.table-wrap input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--accent);
}

.add-form {
  padding: 16px 16px 4px;
  border-top: 1px solid var(--border);
}

.add-form h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.inline-form input[type="text"],
.inline-form input[type="password"] {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.inline-form input:focus { border-color: var(--accent); }

.check-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  cursor: pointer;
}

.form-actions {
  padding: 12px 16px 16px;
}

.form-field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.form-field-inline input[type="number"] {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  text-align: center;
  outline: none;
}

.form-field-inline input[type="number"]:focus {
  border-color: var(--accent);
}

/* ── Analytics ──────────────────────────────────────────── */

.analytics-section {
  margin-bottom: 32px;
}

.analytics-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.analytics-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 12px;
}

/* ── Head-to-Head ──────────────────────────────────────── */

.h2h-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 14px;
}

.h2h-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.h2h-filter-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.h2h-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
}

.h2h-select:focus {
  border-color: var(--accent);
}

.h2h-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: auto;
  max-height: 78vh;
}

.h2h-table {
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.h2h-table th,
.h2h-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.h2h-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fafafa;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.h2h-colhead {
  width: 54px;
  min-width: 54px;
  padding: 8px 0;
  text-align: center;
}

.h2h-corner {
  left: 0;
  z-index: 3;
  background: #fafafa;
  text-align: left;
  padding: 8px 14px;
  min-width: 210px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.h2h-rowhead {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
  padding: 6px 14px;
  min-width: 210px;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

.h2h-rrank {
  display: inline-block;
  width: 20px;
  font-weight: 700;
  color: var(--text-secondary);
}

.h2h-rcreator { font-weight: 700; }

.h2h-cell {
  width: 54px;
  min-width: 54px;
  height: 44px;
  text-align: center;
  padding: 2px;
  color: #111827;
  line-height: 1.15;
}

.h2h-pct {
  display: block;
  font-size: 12px;
  font-weight: 700;
}

.h2h-wl {
  display: block;
  font-size: 10px;
  color: rgba(0, 0, 0, 0.55);
}

.h2h-na { color: var(--border-hover); }

.h2h-diag { background: #f4f4f5; }

.h2h-table tbody tr:hover .h2h-rowhead { background: #fafafa; }

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 640px) {
  nav { gap: 16px; padding: 0 16px; }
  .nav-brand { font-size: 14px; }
  .nav-links a { font-size: 12px; padding: 6px 8px; }
  main { padding: 20px 16px 48px; }
  .audio-grid { grid-template-columns: 1fr; }
  .vote-actions { grid-template-columns: 1fr; }
  .history-item { grid-template-columns: 1fr; gap: 4px; }
  .instructions-bar { flex-direction: column; gap: 8px; }
  .inline-form { flex-direction: column; align-items: stretch; }
}
