/* D1 Sports Explorer Beta — light + dark tokens */

:root {
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --accent: #1a4fdb;
  --accent2: #5b8cff;
  --good: #3ecf8e;
  --wrap: min(72rem, calc(100% - 2rem));
  --radius: 0.75rem;
  --radius-lg: 1.1rem;
  --pill: 999px;
  --chart-h: min(68vh, 640px);

  --bg: #0b1020;
  --bg2: #121a33;
  --card: #161f3d;
  --text: #eef2ff;
  --muted: #9aa6c8;
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --header: rgba(11, 16, 32, 0.88);
  --panel: linear-gradient(180deg, rgba(22, 31, 61, 0.96), rgba(18, 26, 51, 0.98));
  --tip: rgba(11, 16, 32, 0.97);
  --logo-disc: #fff;
  --logo-ring: rgba(255, 255, 255, 0.4);
  --logo-label: rgba(238, 242, 255, 0.92);
  --grid: rgba(255, 255, 255, 0.07);
  --tick: #9aa6c8;
  --seg: rgba(0, 0, 0, 0.28);
  --sun: none;
  --moon: inline;
  --link-hover: #fff;
  --glow: rgba(26, 79, 219, 0.2);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --bg2: #fff;
  --card: #fff;
  --text: #0f172a;
  --muted: #5b6b8c;
  --accent2: #1a4fdb;
  --border: rgba(15, 23, 42, 0.12);
  --shadow: 0 14px 40px rgba(15, 35, 80, 0.1);
  --header: rgba(244, 246, 251, 0.92);
  --panel: linear-gradient(180deg, #fff, #f7f9fc);
  --tip: rgba(255, 255, 255, 0.98);
  --logo-ring: rgba(15, 23, 42, 0.22);
  --logo-label: rgba(15, 23, 42, 0.9);
  --grid: rgba(15, 23, 42, 0.08);
  --tick: #5b6b8c;
  --seg: rgba(15, 23, 42, 0.05);
  --sun: inline;
  --moon: none;
  --link-hover: #0d2f99;
  --glow: rgba(26, 79, 219, 0.08);
  --good: #0d9f6e;
}

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

html { color-scheme: dark; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1000px 500px at 8% -8%, var(--glow), transparent 55%),
    var(--bg);
  line-height: 1.5;
}

.wrap { width: var(--wrap); margin-inline: auto; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
a { color: var(--accent2); }
a:hover { color: var(--link-hover); }

.skip-link {
  position: absolute; left: -999px; top: 0.5rem; z-index: 50;
  padding: 0.5rem 0.75rem; background: var(--accent); color: #fff; border-radius: 0.4rem;
}
.skip-link:focus { left: 0.5rem; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid var(--border);
  background: var(--header);
  backdrop-filter: blur(12px);
}
.top-inner {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 0.75rem; padding: 0.85rem 0;
}
.brand { display: flex; gap: 0.75rem; align-items: center; min-width: min(100%, 16rem); }
.brand-mark {
  width: 2.6rem; height: 2.6rem; border-radius: var(--radius);
  display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(145deg, var(--accent), #0d2f99); color: #fff;
}
.brand-row { display: flex; align-items: center; gap: 0.5rem; }
.brand h1 { margin: 0; font-family: var(--display); font-size: 1.25rem; }
.tagline { margin: 0.15rem 0 0; font-size: 0.85rem; color: var(--muted); }
.badge-beta {
  font-size: 0.65rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0.2rem 0.45rem; border-radius: var(--pill);
  background: rgba(240, 180, 41, 0.2); color: #f0b429; border: 1px solid rgba(240, 180, 41, 0.4);
}
.top-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.icon-sun { display: var(--sun); }
.icon-moon { display: var(--moon); }

/* Buttons */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center;
  gap: 0.35rem; padding: 0.5rem 0.85rem; border-radius: var(--radius);
  border: 1px solid transparent; background: var(--accent); color: #fff;
  font: inherit; font-weight: 600; font-size: 0.875rem; cursor: pointer; text-decoration: none;
}
.btn.ghost {
  background: transparent; border-color: var(--border); color: var(--text);
}
.btn.ghost:hover { border-color: var(--accent2); background: rgba(26, 79, 219, 0.12); }
.btn.sm { padding: 0.35rem 0.65rem; font-size: 0.75rem; }
.btn.icon {
  width: 2.25rem; height: 2.25rem; padding: 0;
  background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn.ghost.is-on { background: rgba(26, 79, 219, 0.28); border-color: var(--accent2); color: #fff; }

/* Top filter toolbar */
.toolbar {
  margin: 0.75rem 0 0.85rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
  position: relative;
  z-index: 12;
}
.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.55rem;
}
.tb-field {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  min-width: 7.5rem;
}
.tb-field.tb-search { flex: 1 1 9rem; min-width: 8rem; max-width: 14rem; }
.tb-field .label,
.tb-dd > summary .label { margin-bottom: 0; }
.tb-field select,
.tb-field input[type="search"] {
  width: 100%;
  min-height: 2.25rem;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
}
.tb-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.75rem;
  align-items: center;
  padding-bottom: 0.35rem;
  min-height: 2.25rem;
}
.tb-clear { align-self: flex-end; margin-bottom: 0.1rem; }

/* Dropdown panels (sports / years / titles) */
.tb-dd {
  position: relative;
  min-width: 7.5rem;
}
.tb-dd > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  user-select: none;
}
.tb-dd > summary::-webkit-details-marker { display: none; }
.tb-dd > summary::after {
  content: "";
  position: absolute;
  right: 0.55rem;
  bottom: 0.72rem;
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
  opacity: 0.85;
}
.tb-value {
  display: flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.4rem 1.5rem 0.4rem 0.55rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 11rem;
}
.tb-dd[open] > summary .tb-value {
  border-color: var(--accent2);
  background: rgba(26, 79, 219, 0.12);
}
.tb-dd.is-muted { opacity: 0.55; }
.tb-dd.is-muted:hover,
.tb-dd.is-muted:focus-within,
.tb-dd.is-muted[open] { opacity: 1; }
.tb-panel {
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  z-index: 30;
  min-width: min(22rem, 92vw);
  max-width: min(28rem, 94vw);
  padding: 0.75rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
}
.tb-panel-range { min-width: min(18rem, 90vw); }
.tb-dd.dual .tb-panel { min-width: min(16rem, 90vw); }

.play-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.65rem;
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

/* Orange play control — stands out from ghost filters */
.btn.btn-play {
  --play: #f08a18;
  --play-deep: #d96f00;
  --play-glow: rgba(240, 138, 24, 0.45);
  background: linear-gradient(180deg, #ff9f2e 0%, var(--play) 55%, var(--play-deep) 100%);
  border: 1px solid #c45f00;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 4px 14px var(--play-glow);
  gap: 0.4rem;
  padding-inline: 0.9rem;
}
.btn.btn-play:hover,
.btn.btn-play:focus-visible {
  background: linear-gradient(180deg, #ffb04a 0%, #ff961f 50%, #e87800 100%);
  border-color: #a84f00;
  color: #fff;
  outline: none;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.3) inset,
    0 6px 18px rgba(240, 138, 24, 0.55);
}
.btn.btn-play:active {
  transform: translateY(1px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.15) inset,
    0 2px 8px var(--play-glow);
}
.btn.btn-play.is-playing {
  background: linear-gradient(180deg, #ff7a2e 0%, #e85d10 55%, #c44a00 100%);
  border-color: #9a3a00;
  animation: play-pulse 1.4s ease-in-out infinite;
}
@keyframes play-pulse {
  0%, 100% { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 4px 14px var(--play-glow); }
  50% { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 0 0 3px rgba(240, 138, 24, 0.35), 0 6px 20px rgba(240, 138, 24, 0.55); }
}

.play-year-banner {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--play, #f08a18);
}
/* Smooth year fill while playing (updated every frame) */
.dual-fill.is-playing-fill {
  transition: none; /* rAF drives continuous position */
}
.dual-fill {
  transition: left 0.12s linear, width 0.12s linear;
}

/* Chart */
.chart-card {
  margin: 0 0 1.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.chart-bar {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 0.65rem; margin-bottom: 0.65rem;
}
.stats { margin: 0; font-size: 0.9rem; font-weight: 500; }
.chart-bar-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.canvas-wrap { position: relative; height: var(--chart-h); min-height: 300px; }
.canvas-wrap canvas { width: 100% !important; height: 100% !important; cursor: grab; touch-action: none; }
.hint { margin: 0.65rem 0 0; font-size: 0.75rem; text-align: center; line-height: 1.45; }

/* Tip */
.tip {
  position: absolute; z-index: 10; min-width: 12rem; max-width: min(20rem, 90vw);
  padding: 0.75rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--tip); box-shadow: var(--shadow); font-size: 0.875rem;
}
.tip-head { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 0.4rem; }
.tip-logo { width: 1.75rem; height: 1.75rem; object-fit: contain; border-radius: 50%; background: #fff; padding: 2px; }
.tip h3 { margin: 0; font-family: var(--display); font-size: 1.05rem; }
.tip dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.7rem; }
.tip dt { color: var(--muted); }
.tip dd { margin: 0; font-weight: 600; }
.tip table { width: 100%; margin-top: 0.4rem; font-size: 0.75rem; border-collapse: collapse; }
.tip td { padding: 0.1rem 0; }
.tip td.num { text-align: right; font-weight: 600; padding-left: 0.6rem; }
.tip-close {
  position: absolute; top: 0.3rem; right: 0.35rem; width: 1.5rem; height: 1.5rem;
  border: none; border-radius: 50%; background: rgba(128, 128, 128, 0.15);
  color: var(--text); cursor: pointer; font-size: 1rem;
}

.toggle { display: inline-flex; gap: 0.4rem; align-items: center; font-size: 0.8rem; cursor: pointer; }
.toggle input { accent-color: var(--accent); }

.active-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem;
  margin-top: 0.55rem; padding: 0.4rem 0.55rem; border-radius: var(--radius);
  border: 1px solid rgba(26, 79, 219, 0.3); background: rgba(26, 79, 219, 0.1);
}
.active-bar[hidden] { display: none !important; }
.active-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; flex: 1; }
.active-chips span {
  font-size: 0.7rem; font-weight: 600; padding: 0.2rem 0.5rem;
  border-radius: var(--pill); background: rgba(128, 128, 128, 0.12); border: 1px solid var(--border);
}

/* Dual range */
.dual-range {
  position: relative; height: 2.25rem; display: flex; align-items: center;
  touch-action: none; cursor: pointer;
}
.dual-track {
  position: absolute; left: 0; right: 0; height: 0.4rem; border-radius: var(--pill);
  background: rgba(128, 128, 128, 0.2); pointer-events: none;
}
.dual-fill {
  position: absolute; top: 0; bottom: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent2)); pointer-events: none;
}
.dual-thumb {
  position: absolute; left: 0; top: 0; width: 100%; margin: 0; height: 2.25rem;
  background: transparent; pointer-events: none; appearance: none; -webkit-appearance: none;
  outline: none;
}
.dual-thumb::-webkit-slider-runnable-track { height: 0.4rem; background: transparent; }
.dual-thumb::-moz-range-track { height: 0.4rem; background: transparent; border: none; }
.dual-thumb::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; width: 1.45rem; height: 1.45rem;
  border-radius: 50%; border: 2px solid #fff; background: var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35); cursor: grab;
  margin-top: calc((0.4rem - 1.45rem) / 2); touch-action: none;
}
.dual-thumb::-moz-range-thumb {
  pointer-events: auto; width: 1.45rem; height: 1.45rem; border-radius: 50%;
  border: 2px solid #fff; background: var(--accent); cursor: grab;
}
.dual-thumb:active::-webkit-slider-thumb,
.dual-thumb:active::-moz-range-thumb { cursor: grabbing; transform: scale(1.08); }
.dual-thumb-end { z-index: 5; }
.dual-ends { display: flex; justify-content: space-between; gap: 0.5rem; margin-top: 0.25rem; }

/* Sports chips inside dropdown */
.presets { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.55rem; }
.sport-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; max-height: 12rem; overflow: auto; }
.sport-chip {
  appearance: none; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font: inherit; font-size: 0.75rem; font-weight: 600;
  padding: 0.35rem 0.6rem; border-radius: var(--pill); cursor: pointer;
}
.sport-chip.is-on { background: rgba(26, 79, 219, 0.32); border-color: var(--accent2); color: #fff; }

@media (max-width: 720px) {
  .tb-field { min-width: calc(50% - 0.4rem); flex: 1 1 calc(50% - 0.4rem); }
  .tb-field.tb-search { max-width: none; flex: 1 1 100%; }
  .tb-dd { min-width: calc(50% - 0.4rem); flex: 1 1 calc(50% - 0.4rem); }
  .tb-value { max-width: none; }
  .tb-panel { left: 0; right: auto; }
  .tb-toggles { width: 100%; }
}

/* Footer / drawer */
.foot { border-top: 1px solid var(--border); padding: 1.25rem 0 2rem; text-align: center; }
.foot p { margin: 0.25rem 0; }
.drawer {
  border: none; padding: 0; max-width: min(32rem, calc(100vw - 1.5rem));
  width: 100%; border-radius: var(--radius-lg); background: var(--card); color: var(--text);
  box-shadow: var(--shadow);
}
.drawer::backdrop { background: rgba(4, 8, 20, 0.65); }
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.85rem 1rem; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-family: var(--display); font-size: 1.1rem; }
.drawer-body { padding: 0.85rem 1rem 1.1rem; max-height: min(70vh, 32rem); overflow: auto; }
.drawer-body h3 { margin: 1rem 0 0.35rem; color: var(--accent2); font-size: 0.95rem; }
.drawer-body p { margin: 0 0 0.55rem; color: var(--muted); font-size: 0.875rem; }
.drawer-body code { font-size: 0.85em; background: var(--bg); padding: 0.1em 0.3em; border-radius: 0.25em; }

/* Share drawer */
.share-drawer { max-width: min(36rem, calc(100vw - 1.5rem)); }
.share-link-row {
  display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-bottom: 0.35rem;
}
.share-url {
  flex: 1 1 12rem; min-width: 0; padding: 0.5rem 0.65rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; font-size: 0.75rem;
}
.share-stories {
  display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.4rem 0 0.85rem;
}
.share-story {
  appearance: none; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font: inherit; font-size: 0.75rem; font-weight: 600;
  padding: 0.4rem 0.65rem; border-radius: var(--pill); cursor: pointer;
}
.share-story:hover, .share-story:focus-visible {
  border-color: var(--accent2); background: rgba(26, 79, 219, 0.14); outline: none;
}
.share-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.35rem 0; }
.share-preview-wrap { margin-top: 0.75rem; }
.share-preview {
  display: block; width: 100%; max-height: 16rem; object-fit: contain;
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg);
}
.share-export-busy { opacity: 0.7; pointer-events: none; }

@media (max-width: 640px) {
  :root { --chart-h: min(52vh, 420px); }
  .brand h1 { font-size: 1.05rem; }
}
