/* Dark (default for legacy pages without data-theme) */
:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #161b22;
  --surface-elevated: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #7ee787;
  --accent-dim: #3fb950;
  --danger: #f85149;
  --topbar-bg: rgba(13, 17, 23, 0.92);
  --btn-on-accent: #0d1117;
  --chart-text: #e6edf3;
  --chart-muted: #8b949e;
  --chart-grid: rgba(139, 148, 158, 0.18);
  --chart-power: #58a6ff;
  --chart-hr: #f85149;
  --chart-speed: #d2a8ff;
  --chart-ctl: #3fb950;
  --chart-atl: #f85149;
  --chart-tsb: #58a6ff;
  --chart-route: #1a7f37;
  --font: "DM Sans", system-ui, sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #1a7f37;
  --accent-dim: #2da44e;
  --danger: #cf222e;
  --topbar-bg: rgba(246, 248, 250, 0.94);
  --btn-on-accent: #ffffff;
  --chart-text: #1f2328;
  --chart-muted: #656d76;
  --chart-grid: rgba(31, 35, 40, 0.1);
  --chart-power: #0969da;
  --chart-hr: #cf222e;
  --chart-speed: #8250df;
  --chart-ctl: #1a7f37;
  --chart-atl: #cf222e;
  --chart-tsb: #0969da;
  --chart-route: #1a7f37;
}

html[data-theme="system"] {
  color-scheme: light dark;
}

@media (prefers-color-scheme: light) {
  html[data-theme="system"] {
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface-elevated: #ffffff;
    --border: #d0d7de;
    --text: #1f2328;
    --muted: #656d76;
    --accent: #1a7f37;
    --accent-dim: #2da44e;
    --danger: #cf222e;
    --topbar-bg: rgba(246, 248, 250, 0.94);
    --btn-on-accent: #ffffff;
    --chart-text: #1f2328;
    --chart-muted: #656d76;
    --chart-grid: rgba(31, 35, 40, 0.1);
    --chart-power: #0969da;
    --chart-hr: #cf222e;
    --chart-speed: #8250df;
    --chart-ctl: #1a7f37;
    --chart-atl: #cf222e;
    --chart-tsb: #0969da;
    --chart-route: #1a7f37;
  }
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-elevated: #1c2128;
    --border: #30363d;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #7ee787;
    --accent-dim: #3fb950;
    --danger: #f85149;
    --topbar-bg: rgba(13, 17, 23, 0.92);
    --btn-on-accent: #0d1117;
    --chart-text: #e6edf3;
    --chart-muted: #8b949e;
    --chart-grid: rgba(139, 148, 158, 0.18);
    --chart-power: #58a6ff;
    --chart-hr: #f85149;
    --chart-speed: #d2a8ff;
    --chart-ctl: #3fb950;
    --chart-atl: #f85149;
    --chart-tsb: #58a6ff;
    --chart-route: #1a7f37;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 0.95rem;
  color: var(--text);
  text-decoration: none;
}
.nav-desktop { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.nav-desktop a { color: var(--muted); font-size: 0.9rem; }
.nav-mobile { display: none; }
.theme-switcher {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}
.theme-switcher button {
  font: inherit;
  font-size: 0.72rem;
  padding: 0.35rem 0.55rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1.2;
}
.theme-switcher button.is-active,
.theme-switcher button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--btn-on-accent);
  font-weight: 600;
}
.theme-switcher button:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: -2px;
}
.btn {
  display: inline-block;
  background: var(--accent);
  color: var(--btn-on-accent);
  font-weight: 600;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95rem;
}
.btn.small { padding: 0.45rem 0.85rem; font-size: 0.85rem; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.full { width: 100%; text-align: center; }
.linkish { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; }
.container { max-width: 960px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.app-shell .container { padding-bottom: 5.5rem; }
.footer {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}
.hero { padding: 2rem 0 3rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.2em; font-size: 0.75rem; color: var(--accent); }
.hero h1 { font-size: clamp(2rem, 5vw, 2.75rem); line-height: 1.15; margin: 0.5rem 0 1rem; }
.lede { color: var(--muted); font-size: 1.1rem; max-width: 36rem; }
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; }
.cards.three { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.cards article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}
.auth-card {
  max-width: 400px;
  margin: 2rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
}
.auth-card.wide { max-width: 480px; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }
.stack input,
.stack select {
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 0.85rem; }
.error { color: var(--danger); }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.accent { color: var(--accent); }
.activity-list { list-style: none; padding: 0; margin: 0; }
.activity-list li { border-bottom: 1px solid var(--border); }
.activity-list a {
  display: grid;
  grid-template-columns: 4rem 1fr auto;
  gap: 0.75rem;
  padding: 1rem 0;
  color: var(--text);
  text-decoration: none;
}
.activity-list .sport { text-transform: capitalize; color: var(--accent); font-size: 0.85rem; }
.activity-list .meta { color: var(--muted); font-size: 0.85rem; }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}
.metric strong { line-height: 1.35; word-break: normal; overflow-wrap: anywhere; }
.metric span { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.metric-hint { font-size: 0.7rem; color: var(--muted); margin: 0.25rem 0 0; line-height: 1.3; font-weight: 400; text-transform: none; letter-spacing: 0; }
.metric-sub { font-size: 0.72rem; color: var(--muted); margin: 0.1rem 0 0.35rem; line-height: 1.25; font-weight: 400; }
.info-tip { cursor: help; font-size: 0.72rem; color: var(--muted); text-decoration: none; margin-left: 0.15rem; border: none; }
.chart-legend-hint { margin-top: -1.25rem; margin-bottom: 2rem; }
.metric-grid.compact { margin-bottom: 1rem; }
.tier-badge { font-size: 0.65rem; border: 1px solid var(--accent); color: var(--accent); padding: 0.1rem 0.35rem; border-radius: 4px; vertical-align: middle; }
.metric.highlight { border-color: var(--accent-dim); }
.activity-map { margin-bottom: 1rem; }
.map { height: 320px; border-radius: 12px; margin-bottom: 0; background: var(--surface); border: 1px solid var(--border); }
.map-error { margin-top: 0; }
.map[hidden] { display: none; }
.map-placeholder {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 4.5rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
}
.map-placeholder p { margin: 0; }
.map-placeholder-icon { font-size: 1.25rem; line-height: 1; opacity: 0.85; }
.charts canvas { margin-bottom: 1rem; max-height: 180px; }
.pmc-chart-wrap {
  position: relative;
  width: 100%;
  height: min(52vh, 320px);
  min-height: 320px;
  margin-bottom: 2rem;
}
.chart-tall { width: 100% !important; height: 100% !important; max-height: none; margin-bottom: 0; }
.metric-grid.dashboard-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
}
.dropzone input { display: block; margin: 0 auto; }
.inline { display: inline; }
.banner-warn {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid var(--danger);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.banner-warn p { margin: 0; color: var(--text); }
.banner-info {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.banner-info p { margin: 0; color: var(--text); }
.rank-filters { gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; margin: 1rem 0; }
.rank-filters label { font-size: 0.85rem; color: var(--muted); }
.report-block { margin-bottom: 1.5rem; }
.report-block h2 { font-size: 1rem; margin-bottom: 0.5rem; }
.report-list { margin: 0; padding-left: 1.25rem; color: var(--muted); font-size: 0.9rem; }
.compare-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.compare-tabs a {
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}
.compare-tabs a.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(126, 231, 135, 0.08);
}
.compare-panel { margin-bottom: 1.5rem; }
.compare-form select, .compare-form input[type="email"], .compare-form input[type="date"] {
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 100%;
  max-width: 100%;
}
.opt-in-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.checkbox-row { display: flex; gap: 0.75rem; align-items: flex-start; font-size: 0.9rem; color: var(--muted); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.compare-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -0.25rem; }
.compare-table {
  width: 100%;
  min-width: 320px;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.compare-table th, .compare-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 0.5rem;
  text-align: left;
}
.compare-table th { color: var(--muted); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; }
.compare-table .delta { color: var(--accent); font-weight: 600; }
.compare-meta p { margin: 0.25rem 0; }
.founding-member-badge {
  font-size: 0.75rem;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.35rem;
  white-space: nowrap;
}
.banner-demo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: color-mix(in srgb, var(--chart-tsb) 12%, transparent);
  border: 1px solid var(--chart-tsb);
  border-radius: 12px;
  padding: 0.85rem 1.1rem;
  margin-bottom: 1.25rem;
}
.banner-demo p { margin: 0; color: var(--text); font-size: 0.9rem; }
.member-badge { font-size: 0.75rem; color: var(--muted); }
.nav-badge { border: 1px solid var(--border); border-radius: 999px; padding: 0.2rem 0.55rem; }
.cardish { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin: 1rem 0; }
.data-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.data-table th, .data-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); text-align: left; }
.advanced-metrics h2 { font-size: 1rem; margin: 0 0 0.75rem; }
.profile-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.profile-section h2 { font-size: 1rem; margin: 0 0 0.5rem; }
.profile-section .theme-switcher button { font-size: 0.8rem; padding: 0.45rem 0.75rem; }

@media (max-width: 768px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid.dashboard-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pmc-chart-wrap { min-height: 240px; margin-bottom: 5.5rem; }
  .activity-list a {
    grid-template-columns: 3.25rem minmax(0, 1fr);
    grid-template-rows: auto auto;
  }
  .activity-list .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    grid-column: 2;
  }
  .activity-list .meta { grid-column: 1 / -1; font-size: 0.8rem; }
  .nav-desktop { display: none; }
  .nav-mobile {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: var(--topbar-bg);
    border-top: 1px solid var(--border);
    padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0));
    backdrop-filter: blur(8px);
  }
  .nav-mobile a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.62rem;
    text-align: center;
    padding: 0.35rem 0.1rem;
    line-height: 1.2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    border-radius: 10px;
  }
  .nav-mobile a.active {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
  }
  .nav-mobile a.active { color: var(--accent); }
  .nav-mobile a span { display: block; }
  .nav-mobile .nav-icon { display: flex; align-items: center; justify-content: center; }
  .footer { padding-bottom: 4.5rem; }
  .compare-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0.25rem; }
  .compare-tabs a { flex: 0 0 auto; font-size: 0.82rem; padding: 0.45rem 0.75rem; }
  .row-2 { grid-template-columns: 1fr; }
}
