/* Dark is the default; light only when the visitor picks it. */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --track: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --hover: rgba(255, 255, 255, 0.06);
  --series-1: #3987e5; /* McDavid this season */
  --series-2: #d95926; /* Gretzky 1985-86 */
  --series-3: #199e70; /* McDavid 2022-23 */
  --good: #0ca30c;
  --critical: #e66767;
  --tag-nhl: #e3b341;
  --tag-edm: #3987e5;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --track: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.05);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #006300;
  --critical: #d03b3b;
  --tag-nhl: #8a5a00;
  --tag-edm: #2a78d6;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 960px; margin: 0 auto; padding: 16px 20px 40px; }
h1 { font-size: 30px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0; }
p { margin: 0; }
.secondary { color: var(--text-secondary); }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.sub { color: var(--text-secondary); margin-top: 6px; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.brand { font-weight: 800; font-size: 18px; letter-spacing: 0.02em; }
.brand .vs { color: var(--text-muted); font-weight: 500; font-size: 14px; margin: 0 2px; }
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-1); color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text-primary); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:root[data-theme="dark"] .icon-moon, :root[data-theme="light"] .icon-sun { display: none; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.feedback-btn { font-size: 18px; }
.link-btn.inline { padding: 0; font-size: inherit; font-weight: 600; }

/* Feedback dialog */
dialog#feedback {
  width: min(480px, calc(100vw - 24px)); padding: 0; margin: auto;
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface-1); color: var(--text-primary);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
#feedback-form { padding: 20px; } /* padding here, so a click on the dialog itself means the backdrop */
dialog#feedback::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { font-size: 18px; }
.small-btn { width: 32px; height: 32px; font-size: 14px; }
.type-picker { flex-wrap: wrap; margin-bottom: 4px; }
.type-picker label { position: relative; }
.type-picker input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.type-picker span { display: block; padding: 6px 12px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer; }
.type-picker input:checked + span { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border); }
.type-picker input:focus-visible + span { outline: 2px solid var(--series-1); outline-offset: 1px; }
.field-label { display: block; font-size: 13px; color: var(--text-secondary); margin: 14px 0 6px; }
#feedback textarea, #feedback input[type="email"] {
  width: 100%; padding: 10px 12px; border-radius: 10px; resize: vertical;
  border: 1px solid var(--border); background: var(--page); color: var(--text-primary);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
#feedback textarea:focus, #feedback input[type="email"]:focus { outline: 2px solid var(--series-1); outline-offset: 0; border-color: transparent; }
#feedback ::placeholder { color: var(--text-muted); }
.field-hint { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.turnstile { margin-top: 16px; min-height: 65px; }
.form-error { margin: 10px 0 0; font-size: 14px; color: var(--critical); }
.form-done { text-align: center; padding: 16px 0 4px; }
.form-done p { margin: 4px 0; }
.done-icon { font-size: 40px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn { height: 40px; padding: 0 18px; border-radius: 10px; font: 600 14px system-ui, -apple-system, sans-serif; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn.ghost:hover { color: var(--text-primary); background: var(--hover); }
.btn.primary { background: var(--series-1); color: #fff; border: 0; }
.btn.primary:disabled { opacity: 0.45; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
header { margin-bottom: 20px; }

/* Hero */
.hero { margin-bottom: 12px; }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.hero-number { font-size: 80px; font-weight: 750; line-height: 1; letter-spacing: -0.02em; }
.hero-number .of { font-size: 28px; font-weight: 500; color: var(--text-muted); margin-left: 8px; letter-spacing: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  border: 1px solid currentColor;
}
.pill.good { color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.pill.critical { color: var(--critical); background: color-mix(in srgb, var(--critical) 12%, transparent); }
.pill.even { color: var(--text-secondary); }

.progress { position: relative; height: 10px; border-radius: 999px; background: var(--track); margin: 22px 0 10px; }
.progress-fill { height: 100%; width: 0; border-radius: 999px; background: var(--series-1); transition: width 0.6s ease; }
.progress-tick {
  position: absolute; top: -5px; width: 4px; height: 20px; margin-left: -2px;
  border-radius: 2px; background: var(--series-2);
  box-shadow: 0 0 0 2px var(--surface-1);
}
.progress-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.progress-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch.s1 { background: var(--series-1); }
.swatch.s2 { background: var(--series-2); }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.tile { padding: 16px; }
.tile-label { font-size: 13px; color: var(--text-secondary); }
.tile-value { font-size: 28px; font-weight: 700; margin: 2px 0; line-height: 1.25; }
.tile-note { font-size: 13px; color: var(--text-secondary); }
.status.good { color: var(--good); }
.status.critical { color: var(--critical); }

/* Chart card */
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.segmented { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--page); border: 1px solid var(--border); }
.segmented button {
  border: 0; background: transparent; color: var(--text-secondary);
  font: 600 13px system-ui, -apple-system, sans-serif;
  padding: 6px 12px; border-radius: 7px; cursor: pointer;
}
.segmented button:hover { color: var(--text-primary); }
.segmented button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border); }
.chart-wrap { position: relative; height: 380px; }

/* Record book */
.records { margin-top: 12px; }
.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--series-1); cursor: pointer; }
.section-label { font-size: 12px; font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 20px 0 6px; }
.records .card-head + .section-label { margin-top: 4px; }
.rec {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--grid);
}
.rec:first-child { border-top: 0; }
.rec-what { font-weight: 600; }
.rec-provenance { display: block; font-size: 12px; font-weight: 400; color: var(--text-muted); }
.rec-info { text-decoration: none; }
.records a, footer a { color: inherit; }
.rec-val { font-size: 18px; font-weight: 700; text-align: right; }
.rec-prev { grid-column: 2; font-size: 13px; color: var(--text-secondary); }
.rec-when { font-size: 12px; color: var(--text-muted); text-align: right; white-space: nowrap; }
.tag {
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em;
  padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap;
}
.tag.nhl { color: var(--tag-nhl); }
.tag.edm { color: var(--tag-edm); }
.tag.tie { color: var(--text-secondary); border-style: dashed; }
.empty { color: var(--text-muted); font-size: 14px; padding: 8px 0; }
.link-btn { border: 0; background: none; padding: 6px 0; color: var(--series-1); font: 600 13px system-ui, -apple-system, sans-serif; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.next {
  margin-top: 10px; border-radius: 10px; padding: 10px 14px;
  background: color-mix(in srgb, var(--series-1) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--series-1) 35%, transparent);
}
.next p { margin: 4px 0; font-size: 14px; color: var(--text-secondary); }
.next b { color: var(--text-primary); }
.season-bar { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 10px 0; font-size: 14px; }
.season-bar .track { grid-column: 1 / -1; height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.season-bar .fill { height: 100%; border-radius: 999px; background: var(--series-1); }
.season-bar.done .fill { background: var(--good); }
footer .footnote { flex-basis: 100%; margin: 0; }
footer .footnote:empty { display: none; }
footer details.footnote { margin-top: 4px; }

details { margin-top: 16px; border-top: 1px solid var(--grid); padding-top: 12px; }
summary { cursor: pointer; color: var(--text-secondary); font-size: 14px; }
summary:hover { color: var(--text-primary); }
.table-wrap { overflow-x: auto; margin-top: 8px; max-height: 420px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:nth-child(2), td:nth-child(2), th:nth-child(3), td:nth-child(3) { text-align: left; }
th { color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }

footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin-top: 20px; }

button:focus-visible, summary:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

@media (max-width: 720px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  main { padding: 12px 14px 32px; }
  h1 { font-size: 24px; }
  .hero-number { font-size: 60px; }
  .tile-value { font-size: 22px; }
  .card { padding: 16px; }
  .chart-wrap { height: 300px; }
  .card-head { flex-direction: column; }
  .controls { justify-content: flex-start; }
  .rec { grid-template-columns: 1fr auto; row-gap: 4px; }
  .rec .tag { grid-column: 1 / -1; justify-self: start; }
  .rec-what { grid-column: 1; }
  .rec-val { grid-column: 2; }
  .rec-prev, .rec-when { grid-column: 1 / -1; text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  .progress-fill { transition: none; }
}
