:root {
  --bg: #0b0f14;
  --card: #141b24;
  --line: #222c39;
  --text: #f1f4f8;
  --muted: #8b98a9;
  --accent: #ff6a3d;
  --accent-soft: rgba(255, 106, 61, 0.18);
  --live: #3ddc84;
  --heart: #ff3f62;
  --warn: #ffb020;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

p,
h1,
ol {
  margin: 0;
  padding: 0;
}

/* Phone: one column where the map sits right after the live figures, before
   the history cards. The panel's children are laid out by .layout itself. */
.layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100dvh;
  padding: 20px 16px 16px;
  padding-top: max(20px, env(safe-area-inset-top));
}

.panel {
  display: contents;
}

#hr-card,
#splits-card,
#tracks-card,
.foot {
  order: 2;
}

.map-wrap {
  order: 1;
  position: relative;
  height: 56dvh;
  flex: none;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
}

#map {
  position: absolute;
  inset: 0;
}

.head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.eyebrow,
.label {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-top: 2px;
}

.pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.pill::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.pill[data-state='live'] {
  color: var(--live);
}

.pill[data-state='live']::before {
  animation: blink 1.4s ease-in-out infinite;
}

.pill[data-state='stale'] {
  color: var(--warn);
}

.pill[data-state='finished'] {
  color: var(--accent);
}

@keyframes blink {
  50% {
    opacity: 0.25;
  }
}

.notice {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 16px 10px;
}

.hero-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-value {
  font-size: 64px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.hero-value small {
  font-size: 26px;
  margin-left: 3px;
  letter-spacing: 0;
}

.hero-sub {
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.hero-sub strong {
  color: var(--text);
}

.profile {
  display: block;
  width: 100%;
  height: 84px;
  margin-top: 12px;
  overflow: visible;
}

.profile-axis {
  position: relative;
  height: 18px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.profile-axis span {
  position: absolute;
  top: 3px;
  transform: translateX(-50%);
}

.profile-axis span:first-child {
  transform: none;
}

.profile-axis span:last-child {
  transform: translateX(-100%);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat,
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 14px;
  min-width: 0;
}

.stat-wide {
  grid-column: 1 / -1;
}

.value {
  margin-top: 5px;
  font-size: 30px;
  font-weight: 750;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.value small {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 5px;
  letter-spacing: 0;
}

.stat-hr .value {
  color: var(--heart);
}

.stat.is-stale .value {
  color: var(--muted);
}

.heart {
  display: inline-block;
  color: var(--heart);
  animation: beat var(--beat, 1s) ease-in-out infinite;
  animation-play-state: var(--beat-state, paused);
}

@keyframes beat {
  0%,
  100% {
    transform: scale(1);
  }
  15% {
    transform: scale(1.35);
  }
  30% {
    transform: scale(1);
  }
}

.music {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(120deg, #1d1630, #141b24 70%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
}

.music img {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  object-fit: cover;
  background: #0b0f14;
  flex: none;
}

.music-text {
  min-width: 0;
  flex: 1;
}

.music-title {
  font-size: 17px;
  font-weight: 700;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.music-artist {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.play {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--text);
  color: var(--bg);
  font-size: 16px;
  cursor: pointer;
}

.chart {
  display: block;
  width: 100%;
  height: 90px;
  margin-top: 10px;
  overflow: visible;
}

.chart-legend {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.splits,
.tracks {
  list-style: none;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.splits li {
  display: grid;
  grid-template-columns: 26px 1fr 48px;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.splits .km {
  color: var(--muted);
}

.splits .bar {
  height: 8px;
  border-radius: 4px;
  background: var(--accent-soft);
  overflow: hidden;
}

.splits .bar i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
}

.splits .time {
  text-align: right;
  font-weight: 650;
}

.tracks li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  min-width: 0;
}

.tracks img,
.tracks .noart {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  flex: none;
  background: #0b0f14;
}

.tracks div {
  min-width: 0;
  flex: 1;
}

.tracks p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tracks .who {
  color: var(--muted);
  font-size: 12px;
}

.tracks .at {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  flex: none;
}

.tracks a {
  color: inherit;
  text-decoration: none;
}

.foot {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 4px 0 8px;
}

.map-btn {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(11, 15, 20, 0.88);
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.map-btn[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a0d07;
}

.runner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(255, 106, 61, 0.6);
  animation: ping 1.8s ease-out infinite;
}

.runner.is-stale {
  background: var(--muted);
  animation: none;
}

@keyframes ping {
  to {
    box-shadow: 0 0 0 18px rgba(255, 106, 61, 0);
  }
}

.dot {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 7px;
  border-radius: 999px;
  background: #fff;
  color: #0b0f14;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.dot.aid {
  background: #38bdf8;
}

.maplibregl-ctrl-attrib {
  font-size: 10px;
}

@media (min-width: 900px) {
  .layout {
    flex-direction: row;
    gap: 0;
    padding: 0;
    height: 100dvh;
  }

  .panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 440px;
    flex: none;
    overflow-y: auto;
    padding: 28px 24px;
  }

  .map-wrap {
    flex: 1;
    height: auto;
    margin: 16px 16px 16px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .heart,
  .runner,
  .pill::before {
    animation: none !important;
  }
}

[hidden] {
  display: none !important;
}
