:root {
  --ink: #1c2733;
  --ink-soft: #33414f;
  --paper: #f2f4f0;
  --paper-dim: #c9d0d6;
  --tail: #1fa463;
  --cross: #e3a21a;
  --head: #d64545;
  --crown: #f5c542; /* KOMpass accent; distinct from the amber crosswind colour */
  --candidate: #ff8a1f; /* "within 10 % of the KOM" */
  --sheet: rgba(28, 39, 51, 0.96);
  --font: "Barlow Semi Condensed", "Arial Narrow", system-ui, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--paper);
  background: var(--ink);
  overflow: hidden;
}

#map { position: absolute; inset: 0; z-index: 0; }

/* top bar: the wind compass is the one memorable element */
.bar {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 12px; right: 12px;
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px;
  z-index: 10;
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
.wind {
  display: flex; align-items: center; gap: 10px;
  background: var(--sheet);
  border-radius: 999px;
  padding: 6px 16px 6px 6px;
}
.compass { width: 44px; height: 44px; }
.compass circle { fill: none; stroke: var(--paper-dim); stroke-width: 1.5; }
#arrow { transform-origin: 24px 24px; transition: transform 500ms ease; }
#arrow path { fill: var(--paper); }
.compass .crown { fill: var(--crown); stroke: var(--ink); stroke-width: 1; stroke-linejoin: round; }
.wind-text { display: flex; flex-direction: column; line-height: 1.05; }
#wind-speed { font-size: 22px; font-weight: 700; }
#wind-from { font-size: 13px; color: var(--paper-dim); }

.who { display: flex; align-items: center; gap: 10px; margin-left: auto; }
/* first name in full: as wide as its content, never cut */
#athlete { flex: none; min-width: max-content; white-space: nowrap; font-weight: 500; background: var(--sheet); padding: 8px 14px; border-radius: 999px; }
#athlete:empty { display: none; }
.btn {
  font: inherit; font-weight: 600; font-size: 15px;
  color: var(--ink); background: var(--paper);
  border: 0; border-radius: 999px; padding: 10px 16px; cursor: pointer;
}
.btn:focus-visible, .link:focus-visible, #slider:focus-visible { outline: 2px solid var(--cross); outline-offset: 2px; }
.btn[hidden] { display: none; }

/* bottom sheet */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--sheet);
  border-radius: 20px 20px 0 0;
  max-height: 55vh;
  display: flex; flex-direction: column;
  padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  transition: max-height 250ms ease;
}
/* grab handle: a bigger tap/swipe target than the visible bar */
.handle { display: block; width: 72px; height: 22px; margin: -6px auto 2px; padding: 0; border: 0; background: none; cursor: pointer; touch-action: none; }
.handle::before { content: ""; display: block; width: 40px; height: 4px; margin: 9px auto; border-radius: 2px; background: var(--paper-dim); }
.handle:focus-visible { outline: 2px solid var(--cross); outline-offset: 2px; border-radius: 6px; }
.mini-status { display: none; margin-left: auto; min-width: 0; font-size: 12px; font-weight: 400; color: var(--paper-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* phone: collapsed sheet is one line, KOM counter and sync status */
@media (max-width: 899px) {
  .sheet.collapsed > :not(.handle):not(.koms) { display: none; }
  .sheet.collapsed .koms { margin-bottom: 0; }
  .sheet.collapsed #only-koms { display: none; }
  .sheet.collapsed .mini-status { display: block; }
}

.notice {
  position: absolute; z-index: 12; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top, 0px) + 70px); max-width: calc(100% - 32px);
  background: var(--paper); color: var(--ink); font-weight: 600;
  padding: 10px 16px; border-radius: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.time { display: flex; align-items: center; gap: 12px; }
.time label { min-width: 120px; font-weight: 600; font-size: 17px; }
#slider { flex: 1; accent-color: var(--paper); height: 28px; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0 6px; }
.chip {
  font: inherit; font-size: 13px; color: var(--paper-dim);
  background: none; border: 1px solid var(--ink-soft); border-radius: 999px;
  padding: 4px 10px; cursor: pointer; display: inline-flex; align-items: center;
}
.chip[aria-pressed="true"] { color: var(--ink); background: var(--paper); border-color: var(--paper); }
.chip:focus-visible { outline: 2px solid var(--cross); outline-offset: 2px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 6px; font-size: 13px; color: var(--paper-dim); }
.chips { display: flex; gap: 6px; }
.mode { margin: 0 0 6px; }
.koms { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; font-size: 14px; font-weight: 600; color: var(--crown); }
.crown-icon { width: 14px; height: 11px; vertical-align: -1px; }
.crown-icon path { fill: var(--crown); stroke: var(--ink); stroke-width: 1; stroke-linejoin: round; }
.crown-marker { background: none; border: 0; }
.crown-marker .crown-icon { width: 20px; height: 16px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5)); }
.list .meta.kom { color: var(--paper); }
.list .meta.kom.candidate { color: var(--candidate); font-weight: 600; }
.best-mode .time { opacity: 0.4; }
.list .meta.best { color: var(--paper); }
.list .meta.best.none { color: var(--paper-dim); }
.count { font-size: 12px; color: var(--paper-dim); margin: 0 0 4px; }
.count:empty { display: none; }
.course-arrow { display: inline-block; font-weight: 700; line-height: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.tail { background: var(--tail); } .dot.cross { background: var(--cross); } .dot.head { background: var(--head); }

.sync { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--paper-dim); margin: 0 0 6px; }
.sync[hidden] { display: none; }
.link:disabled { opacity: 0.5; cursor: default; }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li { display: grid; grid-template-columns: 6px 1fr auto; gap: 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--ink-soft); cursor: pointer; }
.list li:first-child { border-top: 0; }
.list .stripe { width: 6px; height: 34px; border-radius: 3px; }
.list .name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .meta { font-size: 13px; color: var(--paper-dim); }
.list .along { font-size: 18px; font-weight: 700; text-align: right; }
.list .along small { display: block; font-size: 12px; font-weight: 400; color: var(--paper-dim); }
.list .empty, .list .error { color: var(--paper-dim); padding: 10px 0; cursor: default; display: block; }
.list .error { color: var(--cross); }
li.tail .stripe, li.tail .along { background: var(--tail); color: var(--tail); }
li.cross .stripe, li.cross .along { background: var(--cross); color: var(--cross); }
li.head .stripe, li.head .along { background: var(--head); color: var(--head); }
li .along { background: none !important; }

.privacy { font-size: 11px; line-height: 1.35; color: var(--paper-dim); margin: 8px 0 0; }
/* "View on Strava" links: Strava guidelines ask for bold, underline or #FC5200; here orange and underlined */
.strava-link { font-size: 12px; font-weight: 600; color: #fc5200; margin-left: 6px; text-decoration: underline; }
.detail a.strava-link { font-size: 15px; margin-left: 0; background: none; padding: 0; }
.strava-connect { display: block; line-height: 0; border-radius: 6px; }
.strava-connect[hidden] { display: none; }
.strava-connect:focus-visible { outline: 2px solid var(--cross); outline-offset: 2px; }
.strava-link:focus-visible { outline: 2px solid var(--cross); outline-offset: 2px; }

.credits { display: flex; align-items: center; gap: 14px; font-size: 12px; color: var(--paper-dim); padding-top: 8px; }
.link { font: inherit; color: var(--paper-dim); background: none; border: 0; text-decoration: underline; cursor: pointer; margin-left: auto; padding: 0; }

/* map controls: top right below the header with 12 px gap (zoom, then layer switch); bottom ones clear of the sheet */
.leaflet-top.leaflet-right { top: calc(var(--bar-bottom, 68px) + 12px); }
.leaflet-top.leaflet-right .leaflet-control { margin-top: 0; margin-right: 12px; margin-bottom: 8px; }
.leaflet-bottom { bottom: calc(var(--sheet-h, 0px) + 6px); transition: bottom 250ms ease; }
@media (min-width: 900px) { .leaflet-bottom { bottom: 0; } }
.maptiler-logo { display: block; line-height: 0; }
.maptiler-logo img { display: block; }
@media (min-width: 900px) {
  /* the sheet is a left panel (12 + 380 px): bottom-left controls (MapTiler logo) go right of it */
  .leaflet-bottom.leaflet-left { left: 404px; }
}

/* direction arrows on segment lines */
.dir-arrow { background: none; border: 0; opacity: 0.65; pointer-events: none; }
.dir-arrow svg { width: 10px; height: 10px; display: block; }
.list li.hl { background: var(--ink-soft); }
.list li.day {
  display: block; cursor: default; padding: 12px 0 4px; border-top: 0;
  font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--paper-dim);
}

/* detail card */
.detail {
  position: absolute; z-index: 11;
  left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: var(--paper); color: var(--ink);
  border-radius: 16px; padding: 14px 16px;
}
.detail h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
.detail dl { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 10px 0; }
.detail dt { font-size: 12px; color: #5a6672; }
.detail dd { margin: 0; font-size: 18px; font-weight: 600; }
.detail .row { display: flex; gap: 10px; }
.detail a.btn { text-decoration: none; display: inline-block; background: var(--ink); color: var(--paper); }
.detail .close { margin-left: auto; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--ink); }

/* desktop: sheet becomes a left panel */
@media (min-width: 900px) {
  .sheet { left: 12px; right: auto; top: 76px; bottom: 12px; width: 380px; max-height: none; border-radius: 16px; }
  .sheet.collapsed { max-height: none; }
  .handle { display: none; }
  .detail { left: auto; right: 12px; width: 360px; }
}

@media (prefers-reduced-motion: reduce) {
  #arrow, .sheet, .leaflet-bottom { transition: none; }
}
