:root {
  color-scheme: light;
  --page-plane:      #f9f9f7;
  --surface-1:       #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --gridline:        #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --success-text:    #006300;
  --danger-text:     #b3261e;

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page-plane:      #0d0d0d;
    --surface-1:       #1a1a19;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --gridline:        #2c2c2a;
    --baseline:        #383835;
    --border:          rgba(255, 255, 255, 0.10);
    --success-text:    #0ca30c;
    --danger-text:     #e66767;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 14px;
}

.admin-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-status {
  font-size: 0.85rem;
  color: var(--success-text);
  font-weight: 600;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface-1);
  color: var(--text-primary);
}

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

.btn-primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #ffffff;
}
.btn-primary:hover { filter: brightness(0.92); }

.btn-ghost { background: transparent; }

.btn-icon {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 6px;
  font-weight: 700;
  line-height: 1;
}
.btn-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.date-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.date-picker-row input[type="date"] {
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-primary);
}

table.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

table.leaderboard th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
}

table.leaderboard td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--gridline);
}

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

.col-rank { width: 36px; color: var(--text-muted); }
.col-total { width: 90px; text-align: right; font-weight: 600; }
.col-actions { width: 140px; text-align: right; }
.col-remove { width: 40px; text-align: right; }

.btn-remove {
  color: var(--danger-text);
  border-color: var(--border);
}

.player-name {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.dose-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.today-count {
  min-width: 1.4em;
  text-align: center;
  color: var(--text-secondary);
}

.totals-heading {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 20px 0 10px;
}

.totals-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stat-tile {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page-plane);
}

.stat-tile .stat-name {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.stat-tile .stat-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
}

.add-player-form {
  display: flex;
  gap: 10px;
}

.add-player-form input {
  flex: 1;
  font: inherit;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-primary);
}

.form-error {
  color: var(--danger-text);
  font-size: 0.85rem;
  margin: 10px 0 0;
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.chart-wrap {
  position: relative;
}

.page-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 8px;
}

.hidden { display: none !important; }

dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  background: var(--surface-1);
  color: var(--text-primary);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

#admin-login-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 260px;
}

#admin-login-form label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

#admin-login-form input {
  font: inherit;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-primary);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
