:root,
html[data-theme="light"] {
  color-scheme: light;
  --accent: #0185f8;
  --accent-soft: #2a9bff;
  --accent-dim: rgba(1, 133, 248, 0.1);
  --background: #fafafa;
  --surface: #ffffff;
  --chip-bg: #f4f4f5;
  --border: rgba(0, 0, 0, 0.08);
  --text: #0a0a0a;
  --text-secondary: #71717a;
  /* Heatmap gutters + race track — light zinc, not asphalt */
  --map-bg: #e4e4e7;
  --map-line: #e4e4e7;
  --track-lane: rgba(0, 0, 0, 0.08);
  --track-tick: rgba(0, 0, 0, 0.06);
  --finish-edge: rgba(0, 0, 0, 0.18);
  --empty-muted: #71717a;
  --capsule-bg: #ffffff;
  --capsule-border: rgba(0, 0, 0, 0.12);
  --capsule-text: #0a0a0a;
  --capsule-accent: #16a34a;
  --owner-bg: #e4e4e7;
  --owner-fg: #27272a;
  --owner-border: rgba(0, 0, 0, 0.14);
  --chg-pos: #16a34a;
  --chg-neg: #dc2626;
  --leader-bg: #15803d;
  --leader-border: #4ade80;
  --leader-text: #ecfdf5;
  --leader-owner-bg: rgba(0, 0, 0, 0.28);
  --leader-owner-border: rgba(255, 255, 255, 0.28);
  --green: #16a34a;
  --red: #dc2626;
  --player: #0185f8;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.12);
  --backdrop: rgba(15, 15, 18, 0.45);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --accent: #0185f8;
  --accent-soft: #3aa6ff;
  --accent-dim: rgba(1, 133, 248, 0.12);
  --background: #09090b;
  --surface: #111113;
  --chip-bg: #18181b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --map-bg: #050506;
  --map-line: #050506;
  --track-lane: rgba(255, 255, 255, 0.07);
  --track-tick: rgba(255, 255, 255, 0.05);
  --finish-edge: rgba(255, 255, 255, 0.25);
  --empty-muted: rgba(255, 255, 255, 0.55);
  --capsule-bg: #1a1a1e;
  --capsule-border: rgba(255, 255, 255, 0.12);
  --capsule-text: #ffffff;
  --capsule-accent: #22c55e;
  --owner-bg: #3f3f46;
  --owner-fg: #f4f4f5;
  --owner-border: rgba(255, 255, 255, 0.18);
  --chg-pos: #4ade80;
  --chg-neg: #f87171;
  --leader-bg: #15803d;
  --leader-border: #4ade80;
  --leader-text: #ecfdf5;
  --leader-owner-bg: rgba(0, 0, 0, 0.28);
  --leader-owner-border: rgba(255, 255, 255, 0.28);
  --green: #34d399;
  --red: #f87171;
  --player: #0185f8;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  --backdrop: rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  transition: background-color 220ms ease, color 220ms ease;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  -webkit-text-size-adjust: 100%;
}

.site-vignette,
.site-grain {
  display: none;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1280px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0 3rem;
  padding-left: max(0px, env(safe-area-inset-left));
  padding-right: max(0px, env(safe-area-inset-right));
  padding-bottom: max(3rem, calc(2rem + env(safe-area-inset-bottom)));
}

/* —— Nav —— */
.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.mark {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 700;
}

.brand {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.vs-inline {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.85em;
}

.nav-sub {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.nav-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.status-pill {
  max-width: 280px;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* —— Buttons —— */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 0.95rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
  touch-action: manipulation;
}

.btn:hover {
  border-color: rgba(1, 133, 248, 0.55);
}

.btn.ghost {
  background: transparent;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn.sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 64px;
  height: 34px;
  padding: 0 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}

.theme-knob {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.75rem;
  transition: transform 220ms ease;
}

html[data-theme="dark"] .theme-knob {
  transform: translateX(28px);
}

.auto {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

/* —— Matchup: broadcast scoreboard —— */
.matchup {
  margin-bottom: 1.5rem;
  padding: 1.15rem 1.5rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  background: var(--surface);
}

.sb-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.sb-comp {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.sb-comp strong {
  color: var(--text);
  font-weight: 700;
}

.sb-sep {
  margin: 0 0.35rem;
  opacity: 0.5;
}

.sb-main {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.25rem;
  align-items: center;
}

.match-side {
  text-align: center;
  padding: 0.25rem 0.5rem;
  min-width: 0;
}

.match-name {
  margin: 0 0 0.4rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--player);
  letter-spacing: 0.04em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.crown {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  color: var(--green);
  background: rgba(52, 211, 153, 0.12);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.crown[hidden] {
  display: none !important;
}

.match-avg {
  margin: 0;
  font-size: clamp(2.1rem, 4.6vw, 3rem);
  font-weight: 900;
  letter-spacing: -0.05em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  border-radius: 0.55rem;
  padding: 0.08em 0.18em;
}

.match-side.leading .match-avg {
  color: var(--green);
}

/* Terminal-style tick flash when a score moves on refresh */
@keyframes tick-up {
  0% { background-color: rgba(52, 211, 153, 0.2); }
  100% { background-color: transparent; }
}

@keyframes tick-down {
  0% { background-color: rgba(248, 113, 113, 0.2); }
  100% { background-color: transparent; }
}

.match-avg.tick-up {
  animation: tick-up 700ms ease-out;
}

.match-avg.tick-down {
  animation: tick-down 700ms ease-out;
}

.sb-core {
  text-align: center;
  padding: 0.3rem 1.1rem;
}

.sb-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.55rem;
  font-variant-numeric: tabular-nums;
}

.sb-w {
  font-size: 2.35rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text);
}

.sb-dash {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.sb-cap {
  margin: 0.35rem 0 0;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* Segmented Mon–Fri week tracker */
.sb-days {
  display: flex;
  gap: 0.45rem;
  justify-content: center;
  margin-top: 1.15rem;
}

.sb-day {
  flex: 0 1 92px;
  text-align: center;
  min-width: 0;
}

.sb-day .seg {
  height: 7px;
  border-radius: 999px;
  background: var(--chip-bg);
}

.sb-day.done .seg {
  background: var(--accent);
}

.sb-day.today .seg {
  background: linear-gradient(90deg, var(--accent) 60%, var(--chip-bg) 60%);
}

.sb-day .lbl {
  margin-top: 0.32rem;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
}

.sb-day.today .lbl {
  color: var(--accent-soft);
  font-weight: 700;
}

/* Weekend/draft state replaces the day tracker */
.draft-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.65rem;
  background: var(--chip-bg);
  font-size: 0.76rem;
  color: var(--text-secondary);
  text-align: center;
}

.draft-badge {
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent-soft);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.season-lead {
  margin: 0;
  font-size: 0.8rem;
  color: var(--accent-soft);
  font-weight: 600;
  min-height: 1.2em;
}

/* Skeleton shimmer while first data loads */
.skel {
  color: transparent !important;
  background: linear-gradient(
    90deg,
    var(--chip-bg) 25%,
    var(--border) 50%,
    var(--chip-bg) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
  border-radius: 0.45rem;
  min-width: 2.5ch;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* Live freshness pill (replaces the manual Refresh button) */
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.live-pill:disabled {
  opacity: 0.6;
  cursor: wait;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: live-pulse 2.4s ease-out infinite;
}

@keyframes live-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

.timers {
  margin-top: 0.85rem;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.3rem 1.6rem;
}

.timer {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.timer strong {
  color: var(--text);
  font-weight: 600;
}

/* Locked view: title + heatmap only */
.panel:not(.unlocked) .panel-meta,
.panel:not(.unlocked) .roster,
.panel:not(.unlocked) .pick-line,
.panel:not(.unlocked) .bw {
  display: none;
}

/* —— Grids —— */
.grids {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* mobile breakpoints live near end of file */

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.panel-titles h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--player);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.confirm-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.2;
  max-width: 100%;
  text-align: center;
  background: color-mix(in srgb, #16a34a 18%, transparent);
  color: #16a34a;
  border: 1px solid color-mix(in srgb, #16a34a 45%, transparent);
}

.confirm-badge.late {
  background: color-mix(in srgb, #dc2626 16%, transparent);
  color: #dc2626;
  border-color: color-mix(in srgb, #dc2626 45%, transparent);
  text-transform: none;
  letter-spacing: 0.01em;
}

.confirm-badge.pending {
  background: color-mix(in srgb, var(--text-secondary) 14%, transparent);
  color: var(--text-secondary);
  border-color: color-mix(in srgb, var(--text-secondary) 35%, transparent);
  text-transform: none;
  letter-spacing: 0.01em;
}

html[data-theme="dark"] .confirm-badge.late {
  color: #f87171;
  background: color-mix(in srgb, #f87171 16%, transparent);
  border-color: color-mix(in srgb, #f87171 40%, transparent);
}

.confirm-badge[hidden] {
  display: none !important;
}

.sb-cap-short {
  display: none;
}

.panel-meta {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.panel-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.panel.unlocked .unlock-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.heat-wrap {
  position: relative;
}

.heatmap {
  width: 100%;
  height: min(42vh, 420px);
  min-height: 280px;
  border-radius: 1rem;
  overflow: hidden;
  background: var(--map-bg);
  border: 1px solid var(--border);
}

.draft-veil {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  text-align: center;
  border-radius: 1rem;
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--map-bg) 92%, transparent),
      color-mix(in srgb, var(--map-bg) 97%, transparent)
    );
  border: 1px solid var(--border);
}

.draft-veil p {
  margin: 0;
  max-width: 16rem;
  font-size: 0.92rem;
  line-height: 1.45;
  font-weight: 550;
  color: var(--text-secondary);
}

.draft-veil[hidden] {
  display: none !important;
}

.panel.draft-secret:not(.unlocked) .heatmap {
  visibility: hidden;
}

/* —— Weekly draft race (asphalt lanes, matches heatmap surface) —— */
.ti-race {
  margin: 1.5rem 0 1.25rem;
}

.ti-race-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  overflow: hidden;
  color: var(--text);
  font-family: Inter, Arial, Helvetica, sans-serif;
}

.ti-race-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  padding: 0.7rem 0.85rem 0.55rem;
  background: transparent;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.ti-race-top .ti-race-title-row {
  flex: 1 1 auto;
  min-width: 0;
}

.ti-race-top .ti-mode {
  margin-top: 0;
}

.ti-race-title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.ti-bull {
  display: inline-flex;
  flex-shrink: 0;
}

.ti-race-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ti-fs {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.2rem;
  display: inline-flex;
  border-radius: 3px;
}

.ti-fs:hover {
  color: var(--text);
  background: var(--accent-dim);
}

.ti-mode {
  display: inline-flex;
  flex-wrap: wrap;
  max-width: 100%;
  margin-top: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
  background: transparent;
}

.ti-mode-btn.replay-tab {
  border-left: 1px solid var(--border);
}

.ti-mode-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.28rem 0.75rem;
  cursor: pointer;
}

.ti-mode-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ti-mode-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.ti-track {
  position: relative;
  height: auto;
  min-height: 160px;
  overflow: hidden;
  /* Same deep surface as the heatmaps — reads as one product */
  background: var(--map-bg);
}

.ti-track::before,
.ti-track::after {
  display: none;
}

.ti-gridlines {
  position: absolute;
  inset: 0 34px 0 0;
  z-index: 0;
  pointer-events: none;
  /* Highway-style: dashed lane stripes + soft distance ticks */
  background-image:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 36px,
      var(--track-lane) 36px,
      var(--track-lane) 37px,
      transparent 37px,
      transparent 38px
    ),
    repeating-linear-gradient(
      to right,
      transparent 0,
      transparent 64px,
      var(--track-tick) 64px,
      var(--track-tick) 65px
    );
}

.ti-finish {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 34px;
  z-index: 2;
  border-left: 1px solid var(--finish-edge);
  background: repeating-conic-gradient(#111 0% 25%, #f2f2f2 0% 50%) 50% / 12px 12px;
}

.ti-runners {
  position: absolute;
  inset: 0.4rem 34px 0.4rem 0.4rem;
  z-index: 1;
}

.ti-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--empty-muted);
  font-size: 0.85rem;
  padding: 1rem;
  text-align: center;
}

.ti-capsule {
  position: absolute;
  top: 0;
  left: 0;
  height: auto;
  min-width: 120px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 0.45rem;
  row-gap: 1px;
  align-items: center;
  align-content: center;
  padding: 0.28rem 0.5rem;
  border-radius: 0.4rem;
  color: var(--capsule-text);
  background: var(--capsule-bg);
  border: 1px solid var(--capsule-border);
  box-shadow: none;
  transition: left 480ms ease, top 480ms ease;
  z-index: 1;
  cursor: default;
  overflow: visible;
  box-sizing: border-box;
}

.ti-capsule.leader {
  background: var(--leader-bg);
  border-color: var(--leader-border);
  color: var(--leader-text);
  box-shadow: none;
  z-index: 3;
}

.ti-sym {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.ti-px {
  font-size: 0.68rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

.ti-owners {
  display: inline-flex;
  gap: 0.18rem;
}

.ti-owner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 0.2rem;
  border-radius: 3px;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
  background: var(--owner-bg);
  color: var(--owner-fg);
  border: 1px solid var(--owner-border);
}

.ti-capsule.leader .ti-owner {
  background: var(--leader-owner-bg);
  color: #fff;
  border-color: var(--leader-owner-border);
}

.ti-chg {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--chg-pos);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  min-height: 0.85rem;
}

.ti-capsule.leader .ti-chg {
  color: var(--leader-text);
}

.ti-tri {
  width: 0;
  height: 0;
  flex-shrink: 0;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-bottom: 5px solid currentColor;
}

.ti-tri.down {
  border-bottom: 0;
  border-top: 5px solid currentColor;
  color: var(--chg-neg);
}

.ti-chg.neg {
  color: var(--chg-neg);
}

.ti-race-note {
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.ti-race:fullscreen .ti-race-frame,
.ti-race:-webkit-full-screen .ti-race-frame {
  height: 100%;
  border-radius: 0;
}

.ti-race:fullscreen .ti-track,
.ti-race:-webkit-full-screen .ti-track {
  height: calc(100vh - 88px);
  min-height: 0;
}

.roster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.25rem 0.4rem 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
}

.chip button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 0.1rem;
}

.chip button:hover {
  color: var(--accent-soft);
}

.add-form {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.add-form input {
  width: 7.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  text-transform: uppercase;
}

.add-form input:focus {
  outline: 2px solid rgba(1, 133, 248, 0.45);
  outline-offset: 1px;
}

.add-error {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--red);
}

.pick-line,
.bw {
  margin: 0.45rem 0 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.bw:empty,
.pick-line:empty {
  display: none;
}

/* —— History —— */
/* —— History hub: Results | Insights | Leaderboard —— */
.hub {
  margin-top: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  padding: 0.85rem 1rem 1rem;
  min-width: 0;
  overflow-x: hidden;
}

.insights-body,
#leaderboardPane {
  min-width: 0;
}

.hub-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-bottom: 0.65rem;
  margin-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.hub-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease;
}

.hub-tab:hover {
  color: var(--text);
}

.hub-tab.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.hub-pane[hidden] {
  display: none !important;
}

.recent {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.recent li {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.recent .recent-week {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.hist-side {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.hist-side.win {
  color: var(--green);
  font-weight: 800;
}

.hist-sep {
  margin: 0 0.3rem;
  color: var(--text-secondary);
}

.hist-tb {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.72em;
  letter-spacing: 0.02em;
}

.insights-sub {
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.chev {
  color: var(--text-secondary);
  font-weight: 500;
}

.insights-panel {
  padding: 0 0 1.25rem;
}

.insights-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.insights-controls select {
  margin-left: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 0.5rem;
  padding: 0.35rem 0.5rem;
  font: inherit;
}

.hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.season-board {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  margin-bottom: 0.85rem;
}

.season-board-head h4 {
  margin: 0 0 0.2rem;
  font-size: 0.95rem;
}

.season-board-head .hint {
  margin: 0 0 0.75rem;
}

.season-board-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.season-board-row {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr) auto auto;
  grid-template-areas: "rank name s1 s2";
  gap: 0.65rem 0.85rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: var(--background);
}

.season-board-rank {
  grid-area: rank;
  font-weight: 800;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.season-board-name {
  grid-area: name;
  min-width: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.season-board-row .season-board-stat:nth-child(3) {
  grid-area: s1;
}

.season-board-row .season-board-stat:nth-child(4) {
  grid-area: s2;
}

.season-board-row.leading {
  border-color: color-mix(in srgb, var(--green) 45%, var(--border));
}

.season-board-stat {
  text-align: right;
  min-width: 4.5rem;
}

.season-board-stat strong {
  display: block;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.season-board-stat small {
  color: var(--text-secondary);
  font-size: 0.68rem;
}

.season-board-history {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0.65rem 0 0;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.season-board-history li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
}

.season-board-history strong {
  color: var(--text);
  font-weight: 600;
  text-align: right;
  min-width: 0;
}


.insights-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.insight-card {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  background: var(--surface);
  min-width: 0;
}

.insight-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-inline: -0.15rem;
}

.insight-card h4 {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
}

.insight-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.insight-stats strong {
  display: block;
  margin-top: 0.15rem;
  color: var(--text);
  font-size: 1rem;
}

.insight-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  table-layout: fixed;
}

.insight-table th,
.insight-table td {
  text-align: left;
  padding: 0.35rem 0.2rem;
  border-top: 1px solid var(--border);
  overflow-wrap: anywhere;
  vertical-align: top;
}

.pos {
  color: var(--green);
}

.neg {
  color: var(--red);
}

/* —— Dialog —— */
dialog {
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(360px, calc(100% - 2rem));
  box-shadow: var(--shadow);
  margin: auto;
}

dialog::backdrop {
  background: var(--backdrop);
}

.dialog-form {
  padding: 1.25rem;
}

.dialog-form h3 {
  margin: 0 0 0.35rem;
}

.dialog-form input {
  width: 100%;
  margin-top: 0.85rem;
  border: 1px solid var(--border);
  background: var(--background);
  border-radius: 0.65rem;
  padding: 0.7rem 0.85rem;
  font: inherit;
  color: var(--text);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.error {
  color: var(--red);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

/* —— Tooltips (only on .tip elements) —— */
.tip {
  position: relative;
  cursor: help;
  border-bottom: 1px dotted color-mix(in srgb, var(--text-secondary) 55%, transparent);
}

.tip[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
  width: max-content;
  max-width: min(260px, 70vw);
  padding: 0.55rem 0.7rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0;
  text-transform: none;
  text-align: left;
  white-space: normal;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
  z-index: 40;
}

.tip:hover[data-tip]::after,
.tip:focus-visible[data-tip]::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Header score tooltip: multi-line week math. Open BELOW the score so the
   tall breakdown isn't clipped by the top of the viewport. */
.match-avg.tip[data-tip]::after {
  white-space: pre-line;
  max-width: min(340px, 82vw);
  bottom: auto;
  top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-4px);
}

.match-avg.tip:hover[data-tip]::after,
.match-avg.tip:focus-visible[data-tip]::after {
  transform: translateX(-50%) translateY(0);
}

.match-side.t .tip[data-tip]::after,
.panel[data-player="T"] .tip[data-tip]::after {
  left: 0;
  transform: translateX(0) translateY(4px);
}

.match-side.t .match-avg.tip[data-tip]::after {
  transform: translateX(0) translateY(-4px);
}

.match-side.t .tip:hover[data-tip]::after,
.panel[data-player="T"] .tip:hover[data-tip]::after {
  transform: translateX(0) translateY(0);
}

.match-side.j .tip[data-tip]::after,
.panel[data-player="J"] .tip[data-tip]::after,
.nav-actions .tip[data-tip]::after {
  left: auto;
  right: 0;
  transform: translateX(0) translateY(4px);
}

.match-side.j .match-avg.tip[data-tip]::after {
  transform: translateX(0) translateY(-4px);
}

.match-side.j .tip:hover[data-tip]::after,
.panel[data-player="J"] .tip:hover[data-tip]::after,
.nav-actions .tip:hover[data-tip]::after {
  transform: translateX(0) translateY(0);
}

/* Tap-to-show tooltip (touch devices replace hover) */
.tap-tip {
  position: fixed;
  z-index: 9999;
  max-width: min(300px, calc(100vw - 16px));
  padding: 0.55rem 0.7rem;
  border-radius: 0.65rem;
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  white-space: pre-line;
  overflow-wrap: anywhere;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition:
    opacity 130ms ease,
    transform 130ms ease;
  pointer-events: none;
}

.tap-tip.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .tip[data-tip]::after {
    transition: none;
  }

  .tap-tip {
    transition: none;
  }

  .live-dot {
    animation: none;
  }

  .skel {
    animation: none;
  }

  .match-avg.tick-up,
  .match-avg.tick-down {
    animation: none;
  }

  html,
  body,
  .btn,
  .theme-knob,
  .ti-capsule {
    transition: none !important;
  }
}

/* —— Responsive: tablet —— */
@media (max-width: 900px) {
  .grids {
    grid-template-columns: 1fr;
  }

  .matchup {
    padding: 1rem 1.1rem;
  }

  .sb-main {
    gap: 0.75rem;
  }

  .insights-grid {
    grid-template-columns: 1fr;
  }
}

/* —— Responsive: phone —— */
@media (max-width: 640px) {
  .shell {
    width: calc(100% - 1.25rem);
    padding-top: 0.85rem;
  }

  .nav {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
    margin-bottom: 1rem;
    padding-bottom: 0.9rem;
  }

  .nav-brand {
    min-width: 0;
    width: 100%;
  }

  .brand {
    font-size: 1rem;
  }

  .nav-sub {
    font-size: 0.72rem;
    line-height: 1.35;
  }

  .nav-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.45rem;
  }

  .status-pill {
    max-width: none;
    flex: 1 1 140px;
    white-space: normal;
    border-radius: 0.75rem;
  }

  .btn.ghost {
    padding-inline: 0.75rem;
  }

  .auto {
    font-size: 0.75rem;
  }

  .matchup {
    padding: 0.95rem 0.85rem 1rem;
  }

  /* Two equal team columns, season record full-width underneath */
  .sb-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "t j"
      "core core";
    gap: 0.85rem 0.65rem;
    align-items: stretch;
  }

  .match-side {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .match-side.t {
    grid-area: t;
  }

  .match-side.j {
    grid-area: j;
  }

  .sb-core {
    grid-area: core;
    padding: 0.45rem 0.25rem 0;
    border-top: 1px solid var(--border);
  }

  .match-name {
    flex-direction: column;
    gap: 0.28rem;
    margin-bottom: 0.35rem;
  }

  .match-avg {
    margin-top: auto;
    font-size: clamp(1.7rem, 9vw, 2.2rem);
  }

  .confirm-badge {
    font-size: 0.58rem;
    padding: 0.18rem 0.4rem;
    border-radius: 0.45rem;
    white-space: normal;
    justify-content: center;
  }

  .sb-w {
    font-size: 1.85rem;
  }

  .sb-dash {
    font-size: 1rem;
  }

  .sb-cap {
    font-size: 0.58rem;
    letter-spacing: 0.12em;
  }

  .sb-cap-full {
    display: none;
  }

  .sb-cap-short {
    display: inline;
  }

  .sb-days {
    gap: 0.3rem;
  }

  .sb-day {
    flex-basis: 56px;
  }

  .sb-head {
    justify-content: center;
    text-align: center;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
  }

  .sb-comp {
    line-height: 1.4;
  }

  .sb-sep {
    margin: 0 0.25rem;
  }

  .timers.sb-foot {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem 0.85rem;
  }

  .heatmap {
    height: min(40vh, 300px);
    min-height: 210px;
    border-radius: 0.85rem;
  }

  .panel-head {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .panel-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .roster {
    flex-direction: column;
    align-items: stretch;
  }

  .add-form {
    width: 100%;
  }

  .add-form input {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .ti-race {
    margin: 1.1rem 0 1rem;
  }

  .ti-race-frame {
    border-radius: 0.85rem;
  }

  .ti-race-top {
    padding: 0.6rem 0.7rem 0.5rem;
  }

  .ti-race-title {
    font-size: 0.8rem;
    white-space: normal;
    line-height: 1.25;
  }

  .ti-finish {
    width: 26px;
  }

  .ti-runners {
    inset: 0.3rem 26px 0.3rem 0.3rem;
  }

  .ti-gridlines {
    inset: 0 26px 0 0;
  }

  .ti-capsule {
    min-width: 110px;
    padding: 0.24rem 0.4rem;
  }

  .ti-sym {
    font-size: 0.68rem;
  }

  .ti-px,
  .ti-chg {
    font-size: 0.58rem;
  }

  .ti-race-note {
    font-size: 0.7rem;
    line-height: 1.35;
  }

  .insights-toggle {
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
  }

  .insights-sub {
    grid-column: 1 / -1;
    order: 3;
    font-size: 0.74rem;
  }

  .insight-stats {
    gap: 0.4rem;
  }

  .season-board-row {
    grid-template-columns: 1.25rem minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "rank name name"
      ". s1 s2";
    gap: 0.4rem 0.65rem;
  }

  .season-board-stat {
    text-align: left;
    min-width: 0;
  }

  .season-board-stat small {
    display: block;
    line-height: 1.25;
  }

  .season-board-history li {
    grid-template-columns: 1fr;
  }

  .season-board-history strong {
    text-align: left;
  }

  .insight-table {
    font-size: 0.72rem;
  }

  .insight-table .insight-first {
    display: none;
  }

  .insights-controls {
    align-items: flex-start;
  }

  .insights-controls .hint {
    flex: 1 1 100%;
    overflow-wrap: anywhere;
  }

  .recent {
    gap: 0.35rem 0.85rem;
    font-size: 0.74rem;
  }

  .tip[data-tip]::after {
    max-width: min(240px, calc(100vw - 2rem));
  }
}

/* —— Responsive: small phone —— */
@media (max-width: 420px) {
  .shell {
    width: calc(100% - 1rem);
  }

  .mark {
    width: 2.15rem;
    height: 2.15rem;
    font-size: 0.75rem;
  }

  .theme-toggle {
    width: 56px;
    height: 30px;
  }

  html[data-theme="dark"] .theme-knob {
    transform: translateX(24px);
  }

  .theme-knob {
    width: 22px;
    height: 22px;
  }

  .matchup {
    padding: 0.85rem;
  }

  .panel-titles h2 {
    font-size: 0.95rem;
  }

  .heatmap {
    min-height: 190px;
  }
}

/* Touch / tap comfort */
@media (hover: none) and (pointer: coarse) {
  .btn,
  .chip button,
  .theme-toggle,
  .ti-fs,
  .ti-mode-btn {
    min-height: 44px;
  }

  .chip button {
    min-width: 28px;
    padding: 0.15rem 0.25rem;
  }

  .add-form input {
    min-height: 40px;
  }

  /* No hover on touch: the JS tap-tip handles tooltips instead, so the
     CSS hover bubble never sticks or double-renders after a tap. */
  .tip[data-tip]::after {
    display: none !important;
  }

  .ti-capsule {
    cursor: pointer;
  }
}
