@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-display: block; src: url("fonts/barlow-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 700; font-display: block; src: url("fonts/barlow-condensed-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 800; font-display: block; src: url("fonts/barlow-condensed-latin-800-normal.woff2") format("woff2"); }

/* Themes: black background everywhere, the brightest colours for text (sunlight).
   --num the big number and the bottom row, --accent sparing highlights, --me your arrow. */
:root {
  --fg: #ffffff;
  --num: #ffffff;
  --accent: #ffd60a;
  --me: #ffd60a;
  --go-bg: #ffffff;
  --go-fg: #000000;
  --ok: #ffffff;
  --warn: #ffd60a;
  --bad: #ffd60a;
  --behind: #ff2d2d;
  --ahead: #00e676;
  --muted: #9b9b9b;
  --sheet: #0e0e0e;
  --line: #262626;
  --cond: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --ui: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme="amber"] {
  --num: #ffd60a; --accent: #ffd60a; --me: #ffffff; --go-bg: #ffd60a;
  --ok: #ffd60a; --warn: #ff8a00; --bad: #ff453a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #000; color: #fff;
  overscroll-behavior: none;
}
body {
  position: fixed; inset: 0; overflow: hidden;
  font: 17px/1.35 var(--ui);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.4; }
[hidden] { display: none !important; }

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: 50% 50%;
}

/* ---------- top: map ---------- */
#top { position: relative; min-height: 0; overflow: hidden; background: #000; }
#map { position: absolute; inset: 0; }
.maplibregl-ctrl-attrib { background: rgba(0, 0, 0, 0.55) !important; color: #777 !important; font-size: 10px !important; }
.maplibregl-ctrl-attrib a { color: #888 !important; }
.maplibregl-ctrl-attrib-button { filter: invert(1) opacity(0.5); }
.overlay-top-left, .overlay-top-right {
  position: absolute; top: calc(var(--st) + 8px); z-index: 5;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.overlay-top-left { left: 10px; align-items: flex-start; }
.overlay-top-right { right: 10px; align-items: flex-end; }
.chip {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.72); border: 1px solid rgba(255, 255, 255, 0.14);
  font: 700 14px/1 var(--ui); letter-spacing: 0.01em; white-space: nowrap;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: #666; flex: none; }
.chip.ok .dot { background: var(--ok); }
.chip.warn .dot { background: var(--warn); }
.chip.bad .dot { background: var(--bad); }
.chip.tap { border-color: var(--accent); color: var(--accent); }
.badge {
  padding: 6px 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.72);
  font: 700 17px/1 var(--cond); letter-spacing: 0.04em; white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.14);
}
.badge.over { color: var(--accent); }
.badge.big { font-size: 22px; }
.map-btn {
  position: absolute; right: 10px; bottom: 12px; z-index: 5;
  width: 46px; height: 46px; border-radius: 14px;
  background: rgba(0, 0, 0, 0.75); border: 1px solid rgba(255, 255, 255, 0.18);
  display: grid; place-items: center; color: #fff;
}
.map-btn-2 { bottom: 66px; }
#sim-banner {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 10px; z-index: 6; white-space: nowrap;
  background: #fff; color: #000; font: 800 15px/1 var(--ui); padding: 8px 12px; border-radius: 999px;
}
#sim-banner button { text-decoration: underline; font-weight: 800; }

.me-marker { width: 120px; height: 120px; pointer-events: none; z-index: 3; }
.ghost-marker { width: 120px; height: 120px; pointer-events: none; z-index: 2; }
.me-marker .me-fill { fill: var(--me); }
.me-marker .cone-stop { stop-color: var(--me); }

/* ---------- bottom ---------- */
#bottom { position: relative; min-height: 0; overflow: hidden; background: #000; }
.pane { position: absolute; inset: 0; display: none; }
#app.phase-ready #ready, #app.phase-boot #ready { display: flex; }
#app.phase-running #run { display: flex; }

/* ready */
#ready {
  flex-direction: column; gap: 10px;
  padding: 12px 14px calc(8px + var(--sb));
}
#ready-title { display: flex; flex-direction: column; gap: 2px; }
.rt-name { font: 700 15px/1.2 var(--ui); color: var(--muted); letter-spacing: 0.02em; text-transform: uppercase; }
.rt-sub { font: 700 22px/1.1 var(--cond); letter-spacing: 0.02em; }
.rt-fuel { margin-top: 4px; font: 600 15px/1.3 var(--ui); color: #cfcfcf; }
/* CAF / DECAF, like the labels on the map */
.pill {
  display: inline-block; padding: 1px 6px; border: 1.5px solid #fff; border-radius: 5px;
  background: #000; color: #fff; font: 800 12px/1.25 var(--ui); letter-spacing: 0.03em; vertical-align: 1px;
}
.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; border-radius: 22px;
  font: 800 30px/1 var(--cond); letter-spacing: 0.06em;
}
.big-btn.go {
  flex: 1 1 auto; min-height: 90px;
  background: var(--go-bg); color: var(--go-fg); font-size: clamp(54px, 13vh, 88px);
}
.big-btn.go:active { filter: brightness(0.85); }
.big-btn.live { height: 62px; flex: none; border: 2px solid #fff; color: #fff; font-size: 30px; }
.big-btn.live #live-sub { font-weight: 600; color: #cfcfcf; }
.live-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); }
#ready-nav { display: flex; justify-content: space-between; margin: 0 -6px; }
#ready-nav button { padding: 10px 6px; font: 600 16px/1 var(--ui); color: #cfcfcf; }

/* running */
#run {
  flex-direction: column; align-items: stretch;
  padding: 4px 12px calc(4px + var(--sb));
}
#app.phase-running #bottom { color: var(--num); }
#bottom.est::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0 16px, transparent 16px 32px);
}

#gap-wrap {
  flex: 1 1 auto; min-height: 0; width: 100%;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
#gap-num {
  font-family: var(--cond); font-weight: 800; line-height: 0.78;
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: -0.015em; white-space: nowrap;
  font-size: 200px; padding-top: 0.06em;
}
#gap-num .tilde { font-size: 0.45em; vertical-align: 0.45em; margin-right: 0.04em; font-weight: 700; }
#gap-word {
  text-align: center; font: 800 34px/1 var(--cond); letter-spacing: 0.16em;
  margin-top: -2px;
}
#gap-word:empty { display: none; }
#status-line {
  min-height: 20px; text-align: center; font: 700 15px/20px var(--ui); letter-spacing: 0.02em;
  opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#info {
  position: relative; touch-action: none;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 6px;
  padding-top: 2px; border-top: 2px solid currentColor;
}
#info .cell { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
#info .lbl { font: 800 11px/1.3 var(--ui); letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.72; }
#info .val { font: 700 30px/1 var(--cond); font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
#info .handle { align-self: center; align-items: center; padding: 6px 2px 0 14px; position: relative; }
#info .handle svg { display: block; }

/* ---------- sheets ---------- */
#scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: calc(100% - var(--st) - 24px);
  background: var(--sheet); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  padding-bottom: var(--sb);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.sheet-head h2 { margin: 0; font: 800 28px/1 var(--cond); letter-spacing: 0.03em; }
.sheet-head .x { font: 700 17px/1 var(--ui); color: var(--accent); padding: 10px 4px 10px 16px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 18px; touch-action: pan-y; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.set-block { padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-block:last-child { border-bottom: 0; }
.set-title { font: 700 14px/1.2 var(--ui); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; }
.big-value { font: 800 40px/1.05 var(--cond); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.big-value.small-value { font-size: 26px; }
.set-title.sub { margin-top: 14px; }
.aid-list { margin: 0 0 4px; font: 600 16px/1.6 var(--ui); color: #cfcfcf; }
#set-bars-list { margin: 6px 0 2px; }
.bar-row { font: 600 15px/1.35 var(--ui); color: #cfcfcf; padding: 5px 0; border-bottom: 1px solid #1f1f1f; }
.bar-row b { color: #fff; }
.bar-row b.warn { color: var(--accent); }
.bar-row.gel { color: #9b9b9b; }
.bar-row.total { border-bottom: 0; color: #9b9b9b; font-size: 14px; }
.aid-list b { color: #fff; }
.text-in {
  width: 100%; min-height: 48px; padding: 0 12px; margin-bottom: 4px; border-radius: 12px;
  background: #1c1c1c; border: 1px solid #3a3a3a; color: #fff; font: 700 20px/1 var(--ui);
  -webkit-user-select: text; user-select: text;
}
.text-in:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: flex; gap: 8px; }
.seg.wrap { flex-wrap: wrap; margin-bottom: 8px; }
.seg button {
  flex: 1 1 0; min-height: 46px; padding: 0 6px; border-radius: 12px; white-space: nowrap;
  background: #1c1c1c; border: 1px solid #2c2c2c; font: 700 16px/1 var(--ui);
  position: relative; overflow: hidden;
}
.seg.wrap button { flex: 0 0 calc(25% - 6px); }
.seg button.on { background: #fff; color: #000; border-color: #fff; }
.seg.compact { gap: 6px; }
.seg.stack { margin-top: 8px; }
.seg.compact button { padding: 0 2px; font-size: 15px; }
.seg .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; box-shadow: 0 0 0 1px #000; }
button.wide {
  display: block; width: 100%; min-height: 52px; margin: 10px 0 0; border-radius: 14px;
  background: #1c1c1c; border: 1px solid #2c2c2c; font: 700 17px/1.2 var(--ui); padding: 10px 14px;
  position: relative; overflow: hidden;
}
button.wide.primary { background: #fff; color: #000; }
/* first launch: one row per permission */
.perm-row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.perm-icon { flex: none; color: #fff; }
.perm-text { flex: 1 1 auto; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.perm-text b { font: 800 18px/1.2 var(--ui); color: #fff; }
.perm-text span { font: 500 14px/1.35 var(--ui); color: #bdbdbd; }
.perm-btn {
  flex: none; min-width: 96px; padding: 12px 14px; border-radius: 14px;
  background: #1c1c1c; border: 1px solid #3a3a3a; color: #fff; font: 700 16px/1 var(--ui);
}
.perm-btn.next { background: #fff; color: #000; border-color: #fff; }
.perm-btn.done { background: transparent; border-color: transparent; color: #fff; }
.perm-btn.bad { border-color: var(--accent); color: var(--accent); }
#wl-done { margin-top: 16px; }
/* pre-race check */
.chk { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font: 500 16px/1.4 var(--ui); color: #d8d8d8; }
.chk b { color: #fff; }
.chk-i { flex: none; width: 18px; font: 800 18px/1.3 var(--ui); text-align: center; }
.chk.ok .chk-i { color: #fff; }
.chk.bad .chk-i { color: var(--accent); }
.chk.info .chk-i { color: var(--muted); }
.chk-time { font: 700 17px/1.3 var(--ui); color: #fff; margin: 2px 0 6px; }
button.danger { background: #2a0d0d; border-color: #5a1a1a; color: #ff6b6b; }
.hold { position: relative; overflow: hidden; touch-action: pan-y; }
.hold::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: calc(var(--p, 0) * 100%); background: rgba(255, 255, 255, 0.28); pointer-events: none;
}
.primary.hold::before { background: rgba(0, 0, 0, 0.28); }
#btn-stop { touch-action: pan-y; }
.menu-row { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.menu-label { font: 700 14px/1.2 var(--ui); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.info-box { background: #161616; border: 1px solid #2a2a2a; border-radius: 12px; padding: 10px 12px; min-height: 44px; }
#sheet-practice .big-btn.go { min-height: 76px; font-size: 40px; margin-top: 8px; }

/* splits table */
table.splits { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
/* The header row stays pinned while the kilometres scroll under it. The list starts flush
   with the top of its scroll box (no padding there), and a band of sheet colour above the
   header hides any row that would otherwise peek out over it on iPhone Safari. */
#plan-body { padding-top: 0; }
table.splits th {
  text-align: left; font: 700 12px/1.2 var(--ui); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 4px 6px; position: sticky; top: 0; z-index: 1; background: var(--sheet);
  box-shadow: 0 -12px 0 var(--sheet), inset 0 -1px 0 #2a2a2a;
}
table.splits td { padding: 7px 4px; border-top: 1px solid #1f1f1f; font: 600 16px/1.2 var(--ui); }
table.splits td.pace { font: 700 20px/1 var(--cond); }
table.splits td.note { color: var(--muted); font-size: 13px; line-height: 1.25; }
table.splits td.elev { white-space: nowrap; color: #cfcfcf; }
table.splits td { white-space: nowrap; }
table.splits td.note { white-space: normal; }
table.splits tr.climb td.pace { color: var(--accent); }
table.splits tr.down td.pace { color: var(--muted); }
.prose h3 { font: 800 22px/1.2 var(--cond); margin: 18px 0 6px; letter-spacing: 0.02em; }
.prose p, .prose li { color: #d8d8d8; font-size: 16px; }
.prose ol, .prose ul { padding-left: 20px; }
.prose li { margin: 6px 0; }
.prose b { color: #fff; }
.prose .loc-status { font-weight: 700; color: #fff; }
.prose .loc-status.bad, .prose .loc-status.bad b { color: var(--accent); }
.prose details.more { margin: 8px 0 4px; border-top: 1px solid var(--line); }
.prose details.more > summary { padding: 12px 0; font: 700 16px/1.2 var(--ui); color: #fff; cursor: pointer; }
.prose #loc-retry { margin: 4px 0 8px; }

/* finish */
#finish {
  position: fixed; inset: 0; z-index: 30; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: calc(var(--st) + 20px) 20px calc(var(--sb) + 20px);
}
.fin-label { font: 800 30px/1 var(--cond); letter-spacing: 0.3em; color: var(--accent); }
.fin-time { font: 800 clamp(80px, 26vw, 140px)/1 var(--cond); font-variant-numeric: tabular-nums; }
.fin-gap { font: 700 26px/1.2 var(--cond); letter-spacing: 0.05em; text-align: center; }
#finish button.wide { max-width: 360px; }

/* pocket mode: the screen looks off (black pixels draw no power); a tap shows it for 12 s */
#pocket {
  position: fixed; inset: 0; z-index: 25; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px;
  padding: 0 20px calc(var(--sb) + 36px); touch-action: manipulation;
}
#pocket .pk-title { font: 800 22px/1 var(--cond); letter-spacing: 0.3em; color: #4a4a4a; }
#pocket .pk-sub { font: 600 15px/1.2 var(--ui); color: #3c3c3c; }

/* a long hold (settings, map, end run): a fill slides across the whole screen with a
   countdown; the label is drawn twice, white on the dark part, black on the fill */
#holdfx { position: fixed; inset: 0; z-index: 35; pointer-events: none; background: rgba(0, 0, 0, 0.78); --p: 0; }
#holdfx.danger { background: rgba(70, 0, 0, 0.85); }
#holdfx .hf-fill { position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--p) * 100%); overflow: hidden; background: var(--hf, #fff); }
#holdfx .hf-in {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100vw;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: var(--st) 24px var(--sb); text-align: center; color: #fff;
}
#holdfx .hf-fill .hf-in { color: #000; }
#holdfx .hf-title { font: 800 48px/1 var(--cond); letter-spacing: 0.2em; padding-left: 0.2em; text-transform: uppercase; }
#holdfx .hf-count { font: 800 min(46vw, 34vh)/0.82 var(--cond); font-variant-numeric: tabular-nums; }
#holdfx .hf-sub { font: 700 18px/1.3 var(--ui); }
/* the unlocked map: a header like the sheets', "Close" top right */
#map-head {
  position: absolute; left: 0; right: 0; top: 0; z-index: 7;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--st) + 8px) 12px 6px 16px;
  background: rgba(14, 14, 14, 0.94); border-bottom: 1px solid var(--line);
}
#map-head .mh-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; white-space: nowrap; overflow: hidden; }
#map-head b { font: 800 28px/1 var(--cond); letter-spacing: 0.03em; }
#map-head span { font: 600 14px/1.2 var(--ui); color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
#map-head .x { flex: none; font: 700 19px/1 var(--ui); color: var(--accent); padding: 12px 6px 12px 24px; }
#app.free-map #chips, #app.free-map #badges { visibility: hidden; }
/* on the run the map is held, not scrolled (until it is unlocked) */
#app.phase-running #map { touch-action: none; }

#toast {
  position: fixed; left: 50%; top: calc(var(--st) + 56px); transform: translateX(-50%); z-index: 40;
  background: #fff; color: #000; font: 700 16px/1.3 var(--ui); padding: 10px 14px; border-radius: 12px;
  max-width: calc(100% - 32px); text-align: center; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
}
#boot-msg {
  position: fixed; left: 0; right: 0; top: 40%; text-align: center; font: 700 18px var(--ui); color: var(--muted);
  z-index: 10; pointer-events: none;
}
#app:not(.phase-boot) #boot-msg { display: none; }
