:root {
  --bg: #f7f4ee;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e6e1d6;
  --accent: #c0392b;
  --accent-soft: #fbe9e7;
  --success: #2e7d4f;
  --success-soft: #e8f5ec;
  --gold: #d4a017;
  --gold-soft: #fff4d6;
  --info: #2d6cdf;
  --info-soft: #e8f0ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--ink); }
.wrap { max-width: 980px; margin: 0 auto; padding: 16px 18px 64px; }

/* --- Top nav --- */
.topnav {
  background: var(--ink);
  color: white;
  position: sticky; top: 0; z-index: 5;
}
.topnav .row {
  max-width: 980px; margin: 0 auto;
  padding: 10px 18px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.topnav .brand {
  font-weight: 800; font-size: 16px; letter-spacing: 0.02em;
  text-decoration: none; color: white;
  display: flex; align-items: center; gap: 8px;
}
.topnav .brand img { height: 28px; width: auto; }
.topnav .links { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.topnav .links a {
  color: white; text-decoration: none;
  padding: 6px 12px; border-radius: 6px;
  font-size: 14px; font-weight: 600;
}
.topnav .links a:hover { background: rgba(255,255,255,0.12); }
.topnav .links a.active { background: var(--accent); }
.topnav select {
  background: rgba(255,255,255,0.1); color: white;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px; padding: 5px 10px; font-size: 14px;
  font-family: inherit;
}

/* --- Hero --- */
.hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 22px;
  margin-top: 18px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.02);
}
.hero .meta {
  font-size: 13px; color: var(--muted);
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.hero h1 {
  font-size: clamp(24px, 4vw, 34px);
  margin: 0 0 18px;
  line-height: 1.1;
}
.hero h1 .year { color: var(--muted); font-weight: 500; }
.hero .row {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: 16px;
}
.hero-time {
  font-size: clamp(40px, 8vw, 64px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1; letter-spacing: -0.02em;
}
.hero-delta {
  font-weight: 700;
  font-size: clamp(16px, 2.5vw, 22px);
  padding: 6px 12px;
  border-radius: 999px;
}
.hero-delta.faster { background: var(--success-soft); color: var(--success); }
.hero-delta.slower { background: var(--accent-soft); color: var(--accent); }
.hero-target {
  margin-top: 8px;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--gold-soft); color: #8a6914;
  padding: 4px 11px; border-radius: 999px;
  font-size: 13px; font-weight: 700;
}

/* Place badges */
.places {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 22px;
}
.place {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.place .lbl {
  font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); font-weight: 700;
}
.place .rank {
  font-size: 26px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.place .rank .of { color: var(--muted); font-weight: 500; font-size: 18px; }
.place .prev {
  margin-top: 6px;
  font-size: 12px; color: var(--muted);
}
.place .pct {
  margin-top: 4px;
  display: inline-block;
  font-size: 12px; font-weight: 700;
  background: var(--success-soft); color: var(--success);
  padding: 2px 8px; border-radius: 999px;
}
.place .pct.improved::after { content: " ↑"; }

/* --- Highlights --- */
.highlights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.hl {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 14px 16px;
}
.hl.gold { border-left-color: var(--gold); }
.hl.success { border-left-color: var(--success); }
.hl.info { border-left-color: var(--info); }
.hl .lbl {
  font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); font-weight: 700;
}
.hl .val { font-size: 18px; font-weight: 800; margin: 2px 0 4px; }
.hl .det { font-size: 13px; color: var(--muted); }

/* --- Section heads --- */
h2.sec {
  font-size: 20px;
  margin: 32px 0 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--ink);
}

/* --- Tables --- */
table.legs {
  width: 100%; border-collapse: collapse;
  background: white; border-radius: 12px; overflow: hidden;
  box-shadow: 0 1px 0 var(--line);
  font-size: 14px;
}
table.legs thead th {
  text-align: left; padding: 10px 10px;
  font-size: 11px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
  background: #faf8f3;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.legs tbody td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.legs tbody tr:last-child td { border-bottom: none; }
table.legs td.num { color: var(--muted); width: 28px; font-variant-numeric: tabular-nums; }
table.legs td.runner .runner-name { font-weight: 600; }
table.legs td.runner .sex {
  display: inline-block; margin-left: 4px;
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px;
}
table.legs td.runner .sex.M { background: var(--info-soft); color: var(--info); }
table.legs td.runner .sex.F { background: #fce4ec; color: #c2185b; }
table.legs td.runner .sub {
  display: inline-block;
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px;
  background: var(--gold-soft); color: #8a6914;
  margin-left: 4px;
}
table.legs td.tnum { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.legs td.split-time { font-weight: 700; }
table.legs td .delta {
  display: block;
  font-size: 12px; font-weight: 700;
  margin-top: 2px;
}
table.legs td .delta.faster { color: var(--success); }
table.legs td .delta.slower { color: var(--accent); }
table.legs td .delta.same { color: var(--muted); }
table.legs td.dim { color: var(--muted); font-size: 12px; }

/* Mobile cards */
@media (max-width: 700px) {
  table.legs thead { display: none; }
  table.legs, table.legs tbody, table.legs tr, table.legs td { display: block; width: 100%; }
  table.legs { background: transparent; box-shadow: none; }
  table.legs tbody tr {
    background: white; border: 1px solid var(--line);
    border-radius: 10px; margin-bottom: 10px; padding: 12px 14px;
  }
  table.legs tbody td { border: none; padding: 2px 0; }
  table.legs td.num { display: inline; color: var(--accent); font-weight: 700; }
  table.legs td.num::after { content: ". "; }
  table.legs td.point { display: inline; font-weight: 700; font-size: 16px; }
  table.legs td.runner { margin-top: 6px; }
  table.legs td.dist::before { content: "📏 "; color: var(--muted); }
  table.legs td.profile::before { content: "⛰ "; color: var(--muted); }
  table.legs td.split-time::before { content: "🎯 Split: "; color: var(--muted); font-weight: 400; }
  table.legs td.cum-time::before { content: "⏱ Akkumulert: "; color: var(--muted); font-weight: 400; }
  table.legs td.pace::before { content: "Tempo: "; color: var(--muted); font-weight: 400; }
  table.legs td.rank-class::before { content: "🏆 Plass i klassen: "; color: var(--muted); font-weight: 400; }
  table.legs td.veksling::before { content: "🤝 Vekslet: "; color: var(--muted); font-weight: 400; }
}

/* --- Roster --- */
.roster {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.roster .card {
  background: white; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
.roster .card .nm { font-weight: 700; font-size: 14px; }
.roster .card .leg { color: var(--muted); font-size: 12px; }

/* --- Footer --- */
footer.foot {
  margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px; text-align: center;
}
footer.foot a { color: var(--muted); }

/* --- Year archive table (historikk) --- */
table.years {
  width: 100%; border-collapse: collapse;
  background: white; border-radius: 12px; overflow: hidden;
  box-shadow: 0 1px 0 var(--line);
}
table.years th, table.years td {
  padding: 12px 14px; text-align: left;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
table.years th {
  font-size: 11px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
  background: #faf8f3;
}
table.years td.year-link { font-weight: 800; font-size: 16px; }
table.years td.year-link a { text-decoration: none; }
table.years td.time { font-weight: 700; }
