/* ---------- Design tokens ---------- */
:root {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --ink: #14151A;
  --ink-secondary: #55565E;
  --ink-muted: #86868D;
  --line: #E7E2D8;
  --accent: #FC4C02;
  --accent-ink: #FFF6F0;
  --accent-dark: #C93B00;

  /* categorical chart palette — fixed order, validated (see dataviz skill) */
  --chart-1: #FC4C02; /* distance */
  --chart-2: #1D5FBF; /* elevation */
  --chart-3: #1F8A54; /* pace / progress */
  --chart-4: #8C3FA8; /* reserve */
  --chart-grid: #DCD6C9;
  --chart-track: #F0EBE0;

  --font-display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --font-body: "Barlow", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow-soft: 0 1px 2px rgba(20,21,26,0.04), 0 8px 24px rgba(20,21,26,0.06);
  --header-h: 76px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: var(--header-h); }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.05; margin: 0 0 0.4em; letter-spacing: 0.01em; }
h2 { font-size: clamp(1.9rem, 1.5rem + 1.8vw, 3rem); text-transform: uppercase; }
h3 { font-size: 1.15rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink); }
p { margin: 0 0 1em; color: var(--ink-secondary); max-width: 65ch; }
a { color: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 24px; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff;
  padding: 12px 18px; z-index: 200; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.eyebrow {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  margin: 0 0 0.5em;
}

.section { padding: 88px 0; }
.section-alt { background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.section-lead { max-width: 60ch; margin-bottom: 2.5rem; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(250,247,242,0.86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  height: var(--header-h);
}
.header-inner { height: 100%; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { width: 40px; height: 40px; object-fit: contain; }
.brand-word { font-family: var(--font-display); font-weight: 700; font-size: 1.4rem; text-transform: lowercase; }
.brand-dot { color: var(--accent); }

.primary-nav { display: flex; gap: 2rem; }
.primary-nav a {
  text-decoration: none; font-family: var(--font-display); text-transform: uppercase;
  letter-spacing: 0.06em; font-size: 0.95rem; font-weight: 600; color: var(--ink-secondary);
  padding: 8px 2px; border-bottom: 2px solid transparent; transition: color 150ms, border-color 150ms;
}
.primary-nav a:hover, .primary-nav a:focus-visible { color: var(--ink); border-color: var(--accent); }

.nav-toggle {
  display: none; flex-direction: column; justify-content: center; gap: 5px;
  width: 44px; height: 44px; background: none; border: none; padding: 0;
}
.nav-toggle span { display: block; width: 24px; height: 2px; background: var(--ink); margin: 0 auto; transition: transform 200ms, opacity 200ms; }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------- Hero ---------- */
.hero { padding: 64px 0 80px; text-align: center; overflow: hidden; }
.hero-inner { display: flex; flex-direction: column; align-items: center; }
.hero-banner { max-width: 340px; width: 60%; margin-bottom: 2.2rem; }
.hero-title {
  font-size: clamp(2.4rem, 1.8rem + 3.6vw, 4.6rem);
  text-transform: uppercase;
  max-width: 16ch;
  margin-bottom: 0.5em;
}
.hero-sub { max-width: 46ch; font-size: 1.05rem; margin: 0 auto 2.4rem; }

.countdown { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.countdown-unit {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 18px; min-width: 84px; box-shadow: var(--shadow-soft);
}
.countdown-num {
  display: block; font-family: var(--font-display); font-weight: 700; font-size: 2.2rem;
  color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1;
}
.countdown-label { display: block; margin-top: 4px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); }
.countdown-caption { margin-top: 1rem; font-size: 0.85rem; color: var(--ink-muted); }

/* ---------- About ---------- */
.about-grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 4rem; align-items: center; }
.about-media img { border-radius: var(--radius); box-shadow: var(--shadow-soft); aspect-ratio: 4/5; object-fit: cover; width: 100%; }
.about-facts { list-style: none; padding: 0; margin: 1.6rem 0 0; display: grid; gap: 0.9rem; }
.about-facts li { display: flex; justify-content: space-between; gap: 1rem; border-top: 1px solid var(--line); padding-top: 0.9rem; font-size: 0.95rem; }
.about-facts strong { font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; }
.about-facts span { color: var(--ink-secondary); text-align: right; }

/* ---------- Stats ---------- */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 3rem; }
.stat-tile { background: var(--bg); padding: 1.8rem 1.4rem; text-align: center; }
.stat-value { display: block; font-family: var(--font-display); font-weight: 700; font-size: clamp(1.8rem, 1.4rem + 1.6vw, 2.6rem); color: var(--ink); font-variant-numeric: proportional-nums; }
.stat-label { display: block; margin-top: 0.3rem; font-size: 0.82rem; color: var(--ink-muted); }

/* ---------- Predictor ---------- */
.predictor-card {
  background: var(--ink); color: #fff; border-radius: var(--radius);
  padding: 2.2rem 2rem; margin: 0 0 1.5rem; text-align: center;
}
.predictor-card figcaption { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 0.6rem; }
.predictor-card h3 { color: #fff; margin: 0; }
.predictor-tag {
  font-family: var(--font-body); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink); background: var(--accent); border-radius: 999px; padding: 3px 10px; font-weight: 600;
}
.predictor-time {
  font-family: var(--font-display); font-weight: 700; font-variant-numeric: tabular-nums;
  font-size: clamp(2.6rem, 2rem + 2.6vw, 4.2rem); color: var(--accent); line-height: 1; margin: 0.3rem 0 0.6rem;
}
.predictor-note { color: rgba(255,255,255,0.72); max-width: 52ch; margin: 0 auto 1.2rem; font-size: 0.9rem; }
.predictor-runs { list-style: none; margin: 0; padding: 1rem 0 0; border-top: 1px solid rgba(255,255,255,0.14); display: grid; gap: 0.6rem; max-width: 560px; margin-left: auto; margin-right: auto; }
.predictor-runs li { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.85rem; flex-wrap: wrap; }
.predictor-run-name { color: #fff; }
.predictor-run-meta { color: rgba(255,255,255,0.65); font-variant-numeric: tabular-nums; }

/* ---------- Charts ---------- */
.charts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; }

/* Dashboards page: even vertical rhythm between every top-level card/figure. */
#dash-overview .stat-row,
#dash-overview .predictor-card,
#dash-overview .charts-grid,
#dash-overview .map-shell,
#dash-overview .wrap > .chart-card {
  margin-bottom: 1.5rem;
}
.chart-card {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.4rem 1.4rem 1rem; margin: 0;
}
.chart-card--wide { grid-column: 1 / -1; }
.chart-card figcaption { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.6rem; flex-wrap: wrap; }
.table-toggle {
  background: none; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
  font-size: 0.78rem; color: var(--ink-secondary); font-family: var(--font-body); font-weight: 600;
  transition: border-color 150ms, color 150ms;
}
.table-toggle:hover { border-color: var(--accent); color: var(--accent); }
.chart-mount { width: 100%; }
.chart-mount svg { width: 100%; height: auto; display: block; overflow: visible; }

.heatmap-wrap { overflow-x: auto; }
.heatmap-table { border-collapse: collapse; font-size: 0.72rem; width: 100%; min-width: 480px; }
.heatmap-table th, .heatmap-table td { padding: 4px 6px; text-align: center; border: 1px solid var(--bg); font-variant-numeric: tabular-nums; }
.heatmap-table thead th { font-family: var(--font-body); font-weight: 600; color: var(--ink-secondary); text-transform: uppercase; letter-spacing: 0.03em; font-size: 0.65rem; padding-bottom: 6px; }
.heatmap-table tbody th { text-align: right; font-weight: 400; color: var(--ink-muted); white-space: nowrap; padding-right: 10px; font-size: 0.68rem; }
.heatmap-table td { border-radius: 3px; min-width: 34px; color: var(--ink); }
.heatmap-table thead th:first-child,
.heatmap-table tbody th {
  position: sticky; left: 0; background: var(--bg); z-index: 1;
}

/* Recent-activity log: collapses from a table into stacked cards on narrow
   screens instead of forcing horizontal scroll. */
@media (max-width: 640px) {
  .activity-log-table thead { display: none; }
  .activity-log-table, .activity-log-table tbody, .activity-log-table tr, .activity-log-table td { display: block; width: 100%; }
  .activity-log-table tr { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 10px; }
  .activity-log-table td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    text-align: right; border-bottom: 1px dashed var(--line); padding: 6px 0;
  }
  .activity-log-table tr td:last-child { border-bottom: none; }
  .activity-log-table td::before {
    content: attr(data-label); text-align: left; font-weight: 600; color: var(--ink-secondary);
    text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.03em;
  }
}

.chart-table-wrap table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 0.8rem; }
.chart-table-wrap caption { text-align: left; font-size: 0.75rem; color: var(--ink-muted); margin-bottom: 0.4rem; }
.chart-table-wrap th, .chart-table-wrap td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.chart-table-wrap th:first-child, .chart-table-wrap td:first-child { text-align: left; }

/* chart internals (SVG built by js/charts.js) */
.cx-bar { fill: var(--chart-1); transition: opacity 150ms; }
.cx-bar:hover, .cx-bar.is-active { opacity: 0.82; }
.cx-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cx-line--distance { stroke: var(--chart-1); }
.cx-line--elevation { stroke: var(--chart-2); }
.cx-line--pace { stroke: var(--chart-3); }
.cx-area { opacity: 0.1; }
.cx-area--distance { fill: var(--chart-1); }
.cx-area--elevation { fill: var(--chart-2); }
.cx-area--pace { fill: var(--chart-3); }
.cx-dot { stroke: var(--bg); stroke-width: 2; }
.cx-grid { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.cx-axis-label { font-family: var(--font-body); font-size: 10px; fill: var(--ink-muted); }
.cx-goal-line { stroke: var(--ink-muted); stroke-width: 1.5; stroke-dasharray: 3 3; }
.cx-empty { fill: var(--ink-muted); font-size: 13px; font-family: var(--font-body); }

.cx-tooltip {
  position: absolute; pointer-events: none; background: var(--ink); color: #fff;
  padding: 8px 12px; border-radius: 8px; font-size: 0.78rem; line-height: 1.4;
  transform: translate(-50%, -110%); white-space: nowrap; opacity: 0; transition: opacity 120ms;
  z-index: 10; box-shadow: var(--shadow-soft);
}
.cx-tooltip.is-visible { opacity: 1; }
.cx-tooltip strong { font-variant-numeric: tabular-nums; font-family: var(--font-display); font-size: 0.9rem; }
.chart-card { position: relative; }

/* ---------- Map ---------- */
.map-shell { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-soft); border: 1px solid var(--line); }
.activity-map { width: 100%; height: 480px; background: var(--chart-track); }
.map-legend {
  position: absolute; bottom: 14px; left: 14px; z-index: 400;
  background: rgba(255,255,255,0.92); backdrop-filter: blur(6px);
  border-radius: var(--radius-sm); padding: 8px 12px; display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 0.78rem; box-shadow: var(--shadow-soft);
}
.map-legend-item { display: flex; align-items: center; gap: 6px; }
.map-legend-swatch { width: 16px; height: 3px; background: var(--chart-1); border-radius: 2px; display: inline-block; }
.map-legend-goal .map-legend-swatch { background: var(--ink); }
.map-popup-title { font-family: var(--font-display); font-weight: 600; text-transform: uppercase; margin-bottom: 2px; }
.map-popup-meta { font-size: 0.82rem; color: var(--ink-secondary); }

/* ---------- Photo grid ---------- */
.photo-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 160px; gap: 10px;
  grid-auto-flow: dense;
}
.photo-cell {
  padding: 0; border: none; background: none; border-radius: var(--radius-sm); overflow: hidden;
  position: relative; grid-column: span 1; grid-row: span 1;
}
/* Orientation-driven spans: landscape photos run wide, portrait photos run tall. */
.photo-hero { grid-column: span 2; grid-row: span 2; }
.photo-wide { grid-column: span 2; grid-row: span 1; }
.photo-tall { grid-column: span 1; grid-row: span 2; }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; transition: transform 300ms ease; }
.photo-cell:hover img, .photo-cell:focus-visible img { transform: scale(1.06); }
.photo-cell::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(20,21,26,0.35), transparent 40%);
  opacity: 0; transition: opacity 200ms;
}
.photo-cell:hover::after, .photo-cell:focus-visible::after { opacity: 1; }

/* ---------- Medal gallery ---------- */
.medal-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 18px; }
.medal-cell {
  padding: 0; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius);
  overflow: hidden; aspect-ratio: 1; position: relative; box-shadow: var(--shadow-soft);
  transition: transform 220ms ease, box-shadow 220ms ease;
}
.medal-cell img { width: 100%; height: 100%; object-fit: cover; transition: transform 300ms ease; }
.medal-cell:hover, .medal-cell:focus-visible { transform: translateY(-6px) rotate(-1deg); box-shadow: 0 16px 32px rgba(20,21,26,0.14); }
.medal-cell:hover img, .medal-cell:focus-visible img { transform: scale(1.08); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(20,21,26,0.92); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 5vh 5vw;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.lightbox-close {
  position: absolute; top: 20px; right: 24px; background: none; border: none; color: #fff;
  font-size: 2.2rem; line-height: 1; padding: 8px 14px;
}

/* ---------- Footer ---------- */
.site-footer { padding: 40px 0; border-top: 1px solid var(--line); }
.footer-inner { display: flex; align-items: center; gap: 12px; }
.footer-inner p { margin: 0; font-size: 0.82rem; color: var(--ink-muted); }
.footer-mark { opacity: 0.6; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .about-grid { grid-template-columns: 1fr; gap: 2rem; }
  .about-media { order: -1; }
  .about-media img { aspect-ratio: 16/9; }
  .charts-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .medal-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 760px) {
  .primary-nav {
    position: absolute; top: var(--header-h); left: 0; right: 0; background: var(--bg);
    border-bottom: 1px solid var(--line); flex-direction: column; gap: 0; padding: 8px 24px 16px;
    display: none;
  }
  .primary-nav.is-open { display: flex; }
  .primary-nav a { padding: 12px 0; border-bottom: 1px solid var(--line); }
  .nav-toggle { display: flex; }

  .photo-grid { grid-template-columns: repeat(2, 1fr); grid-auto-rows: 150px; }
  .photo-hero { grid-column: span 2; grid-row: span 1; }

  .medal-grid { grid-template-columns: repeat(2, 1fr); }
  .activity-map { height: 360px; }
  .section { padding: 64px 0; }
}

@media (max-width: 480px) {
  .countdown-unit { min-width: 70px; padding: 10px 12px; }
  .countdown-num { font-size: 1.7rem; }
  .stat-row { grid-template-columns: 1fr 1fr; }
}
