/* Self-hosted fonts (SIL OFL) */
@font-face { font-family: "Big Shoulders Display"; font-weight: 100 900; font-style: normal; font-display: swap; src: url("fonts/big-shoulders-display-latin-wght-normal.woff2") format("woff2"); }
@font-face { font-family: "Public Sans"; font-weight: 100 900; font-style: normal; font-display: swap; src: url("fonts/public-sans-latin-wght-normal.woff2") format("woff2"); }

/* Palette: the race bib. Tyvek white, navy ink, the pink start wave. */
:root {
  --tyvek: #FAFAF7;        /* panels */
  --ink: #14213D;          /* text, buttons */
  --wave: #E0457B;         /* pink start: stripe, course line */
  --wave-deep: #C22F64;    /* pink text on white */
  --grey: #5F6673;

  --water: #E4E9EE;        /* page behind the map */
  --panel: var(--tyvek);
  --panel-solid: var(--tyvek);
  --field: #EEEFF0;        /* inputs, chips */
  --field-hover: #E3E5E8;
  --hairline: rgba(20, 33, 61, 0.14);
  --violet: var(--ink);    /* primary buttons, selected states */
  --violet-deep: #0B1529;
  --accent: var(--wave-deep);
  --accent-soft: rgba(224, 69, 123, 0.10);
  --accent-ring: rgba(224, 69, 123, 0.40);
  --text: var(--ink);
  --muted: var(--grey);
  --pin: var(--wave);
  --radius: 6px;
  --display: "Big Shoulders Display", "Arial Narrow", sans-serif;
  --body: "Public Sans", system-ui, sans-serif;
  color-scheme: light;

  /* Map colors, read by app.js */
  --map-land: #F6F6F3;
  --map-land-edge: #D5D9DF;
  --map-route: #E0457B;
  --map-route-width: 5;
  --map-closed: #8A919C;
  --map-pin: #14213D;
  --map-pin-ring: #FFFFFF;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--water);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Full-bleed map ---------- */
main { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; background: var(--water); }
.leaflet-container { font-family: var(--body); background: var(--water); }

/* Shared glass surface for everything floating over the map */
.glass {
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid var(--hairline);
  box-shadow: 0 12px 40px rgba(30, 24, 48, 0.14);
}

/* ---------- Title chip ---------- */
.topbar {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  right: 64px;
  z-index: 1001;
  padding: 10px 14px;
  border-radius: 14px;
  width: max-content;
  max-width: calc(100% - 76px);
}
.topbar h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 24px;
  line-height: 1.05;
  margin: 0;
  letter-spacing: 0.01em;
}
.topbar p { margin: 2px 0 0; font-size: 14px; color: var(--muted); }

/* ---------- Bottom sheet / side panel ---------- */
.sheet {
  position: absolute;
  left: 8px; right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  max-height: 70%;
  overflow-y: auto;
  border-radius: var(--radius);
  padding: 20px 18px 20px;
  z-index: 1000;
}
/* Phones: keep the panel short so the map stays usable */
@media (max-width: 819px) {
  .sheet { max-height: 62%; padding: 18px 16px 16px; }
  .sheet::before { /* grab handle */
    content: ""; display: block; width: 36px; height: 4px; border-radius: 2px;
    background: var(--hairline); margin: -8px auto 10px;
  }
  .lede { font-size: 15px; margin-bottom: 12px; }
  .facts > div { padding-top: 10px; }
  .facts dd { font-size: 18px; }
  .official-sub { display: none; }
  .official summary { padding-top: 12px; }
  .eta:not(.long) { font-size: clamp(36px, 11.5vw, 44px); }

  /* Peek: after moving the map, the start panel shrinks to one line. */
  .sheet.peek { cursor: pointer; padding-bottom: 14px; }
  .sheet.peek .lede { margin: 0; }
  .sheet.peek .lede-more, .sheet.peek #view-start > :not(.lede) { display: none !important; }
  .sheet.peek .lede::after { content: " ⌃"; color: var(--accent); font-weight: 600; }
}
button.primary.continue { width: 100%; margin-top: 14px; }

@media (min-width: 820px) {
  .topbar { top: 20px; left: 20px; width: 380px; max-width: none; padding: 14px 18px; }
  .topbar h1 { font-size: 28px; }
  .sheet {
    top: 108px; bottom: auto; left: 20px; right: auto;
    width: 380px;
    max-height: calc(100% - 128px);
    padding: 22px;
  }
}

.view { position: relative; }
.lede { margin: 0 0 16px; font-size: 16px; color: var(--muted); max-width: 34em; }
.lede strong { color: var(--text); font-weight: 600; }

/* Start / goal / finish */
/* Wraps on narrow screens instead of clipping. Each fact has a divider on its left;
   the row starts 17px early and clips, so the divider at the start of a row is hidden. */
.facts {
  display: flex;
  flex-wrap: wrap;
  margin: 0 0 0 -17px;
  overflow: hidden;
  background: linear-gradient(var(--hairline), var(--hairline)) 17px 0 / 100% 1px no-repeat;
}
.facts div { flex: 1 0 auto; margin-left: -1px; padding: 12px 16px 0; border-left: 1px solid var(--hairline); }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd {
  margin: 2px 0 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.live {
  margin: 16px 0 0;
  padding-left: 20px;
  position: relative;
  font-weight: 500;
}
.live::before {
  content: "";
  position: absolute; left: 2px; top: 0.45em;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--pin);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(232, 71, 91, 0.55); }
  100% { box-shadow: 0 0 0 10px rgba(232, 71, 91, 0); }
}

/* ---------- ETA readout ---------- */
.where {
  margin: 0;
  font-family: var(--display);
  font-weight: 500;
  font-size: 19px;
  color: var(--accent);
}
.eta {
  margin: 2px 0 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(40px, 12vw, 52px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.snap-note {
  margin: 10px 0 0; padding: 8px 12px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); font-size: 14px;
}
.eta.long { font-size: clamp(30px, 10vw, 42px); }
.eta-note { margin: 8px 0 0; color: var(--muted); font-size: 14px; max-width: 32em; }

.close {
  position: absolute; top: -6px; right: -6px;
  width: 36px; height: 36px;
  border: 0; border-radius: 50%;
  background: var(--field);
  font-size: 20px; line-height: 1;
  color: var(--text);
  cursor: pointer;
}
.close:hover { background: var(--field-hover); }

/* ---------- Forms ---------- */
form { margin-top: 20px; display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 500; font-size: 14px; color: var(--muted); }
input:not([type="radio"]) {
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text);
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--field);
  min-height: 48px;
}
input::placeholder { color: #8A8299; }
input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

fieldset { border: 0; margin: 0; padding: 0; }
legend { font-weight: 500; font-size: 14px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.seg {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--field); border-radius: 12px; padding: 4px; gap: 4px;
}
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  text-align: center;
  padding: 9px 4px;
  border-radius: 9px;
  font-weight: 500;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.seg input:checked + span { background: var(--violet); color: #fff; }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-ring); }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

button.primary, button.secondary {
  font-family: var(--body);
  font-weight: 600;
  font-size: 16px;
  min-height: 50px;
  border-radius: 12px;
  cursor: pointer;
  padding: 0 18px;
  transition: background-color 0.15s;
}
button.primary { background: var(--violet); color: #fff; border: 0; }
button.primary:hover { background: var(--violet-deep); }
button.primary:disabled { opacity: 0.6; cursor: progress; }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent-ring); margin-top: 18px; }
button.secondary:hover { background: var(--accent-soft); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Official tracker */
.official { margin-top: 16px; border-top: 1px solid var(--hairline); }
.official summary {
  list-style: none; cursor: pointer;
  display: grid; gap: 2px;
  padding: 14px 28px 2px 0; position: relative;
}
.official summary::-webkit-details-marker { display: none; }
.official summary::after {
  content: ""; position: absolute; right: 6px; top: 22px;
  width: 8px; height: 8px;
  border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: rotate(45deg); transition: transform 0.15s;
}
.official[open] summary::after { transform: rotate(-135deg); top: 26px; }
.official summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.official-title { font-weight: 600; color: var(--text); }
.official-sub { font-size: 14px; color: var(--muted); }
.official-body { padding-top: 12px; }

/* The bib: a nod to the paper one pinned to his shirt */
.bib {
  display: flex; align-items: center; gap: 14px;
  background: #FFFFFF; color: var(--text); border: 1px solid var(--hairline);
  border-radius: 10px; padding: 10px 10px 10px 16px;
  position: relative;
}
.bib::before, .bib::after { /* safety-pin holes */
  content: ""; position: absolute; top: 8px; width: 6px; height: 6px; border-radius: 50%;
  background: rgba(30, 24, 48, 0.2);
}
.bib::before { left: 6px; }
.bib::after { right: 6px; }
.bib-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.bib-number {
  flex: 1;
  font-family: var(--display); font-weight: 800; font-size: 40px; line-height: 1;
  letter-spacing: 0.02em; font-variant-numeric: tabular-nums;
}
.bib button {
  border: 0; border-radius: 10px; min-height: 40px; padding: 0 14px;
  background: var(--text); color: #fff;
  font: inherit; font-weight: 600; font-size: 15px; cursor: pointer;
}
.bib-pending {
  margin: 0; padding: 12px 14px; border-radius: 12px;
  background: var(--field); color: var(--muted); font-size: 15px;
}

.steps { margin: 14px 0 0; padding-left: 22px; display: grid; gap: 8px; font-size: 15px; }
.steps li::marker { color: var(--accent); font-weight: 600; }
.official a, .inline-link { color: var(--accent); text-underline-offset: 2px; }
.inline-link {
  background: none; border: 0; padding: 0; font: inherit; text-decoration: underline; cursor: pointer;
}
.inline-link:focus-visible, .official a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* Your own registration(s), on the start view */
.mine { margin-top: 16px; display: grid; gap: 8px; }
.mine-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
}
.mine-title { font-weight: 600; }
.mine-eta { font-family: var(--display); font-weight: 700; font-size: 20px; color: var(--accent); font-variant-numeric: tabular-nums; }
button.secondary.small { margin-top: 0; min-height: 38px; padding: 0 14px; font-size: 15px; }

.edit-banner {
  margin: 0 44px 12px 0;
  font-size: 14px;
  color: var(--accent);
}

button.text-danger {
  justify-self: center;
  background: none; border: 0; padding: 8px 12px;
  font: inherit; font-size: 15px; font-weight: 500;
  color: var(--pin); cursor: pointer;
}
button.text-danger:hover { text-decoration: underline; }

/* Calendar buttons */
.cal { display: grid; gap: 8px; margin-top: 20px; }
.primary-link, .secondary-link {
  display: flex; align-items: center; justify-content: center;
  min-height: 50px; padding: 0 16px; border-radius: 12px;
  font-weight: 600; font-size: 16px; text-decoration: none; text-align: center;
}
.primary-link { background: var(--violet); color: #fff; }
.primary-link:hover { background: var(--violet-deep); }
.secondary-link { color: var(--accent); border: 1px solid var(--accent-ring); }
.secondary-link:hover { background: var(--accent-soft); }
.primary-link:focus-visible, .secondary-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Private edit link */
.private-link { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--hairline); }
.private-link .label { margin: 0 0 8px; font-size: 14px; font-weight: 500; color: var(--muted); }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; font-size: 14px !important; color: var(--muted) !important; }
.copy-row button {
  flex: none; min-width: 76px; border: 0; border-radius: 12px;
  background: var(--field); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.copy-row button:hover { background: var(--field-hover); }

.form-error { margin: 0; color: var(--pin); font-weight: 500; font-size: 15px; }

/* ---------- Map chrome ---------- */
.mile-marker {
  background: var(--panel-solid);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  display: grid;
  place-items: center;
}
.minor-hidden .mile-marker.minor { display: none; }
.mile-marker.big { border-radius: 999px; background: var(--accent); color: #fff; }

.leaflet-tooltip.mile-tip {
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(30, 24, 48, 0.15);
}
.leaflet-tooltip-top.mile-tip::before { border-top-color: var(--panel-solid); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-solid); color: var(--text); }

.leaflet-bar { border: 1px solid var(--hairline) !important; border-radius: 12px !important; overflow: hidden; box-shadow: 0 8px 24px rgba(30, 24, 48, 0.14) !important; }
.leaflet-bar a, .leaflet-bar a:hover {
  background: var(--panel-solid); color: var(--text);
  border-bottom-color: var(--hairline);
  width: 38px; height: 38px; line-height: 38px;
}
.leaflet-bar a:hover { background: var(--field-hover); }
.leaflet-top.leaflet-right { top: env(safe-area-inset-top); }
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.8) !important;
  font-size: 10px;
  color: var(--muted) !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
@media (max-width: 819px) {
  /* attribution sits above the sheet on phones */
  .leaflet-bottom.leaflet-right { bottom: auto; top: 96px; }
}

/* ---------- Admin list ---------- */
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.admin-head .where { font-size: 24px; font-weight: 700; color: var(--text); }
.admin-head .secondary { margin-top: 0; min-height: 40px; }
.pins { list-style: none; margin: 12px 0 0; padding: 0; }
.pins li {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--hairline);
  align-items: start;
}
.pins .mile {
  font-family: var(--display);
  font-weight: 700;
  font-size: 24px;
  line-height: 1;
  color: var(--accent);
}
.pins .mile small { display: block; margin-top: 3px; font-family: var(--body); font-size: 12px; font-weight: 500; color: var(--muted); }
.pins .who { font-weight: 600; }
.pins .detail { color: var(--muted); font-size: 14px; }
.pins button {
  border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 13px; cursor: pointer; padding: 4px;
}
.pins button:hover { color: var(--pin); }
.empty { color: var(--muted); display: block !important; }

/* ---------- The bib look ----------
   Every panel is the Tyvek bib pinned to my shirt: flat paper, four pin holes,
   a pink start-wave stripe on the title card, numbers set big and condensed. */
.glass {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  background-color: var(--tyvek);
  background-image:
    radial-gradient(circle at 12px 12px, rgba(20, 33, 61, 0.22) 3px, transparent 3.5px),
    radial-gradient(circle at calc(100% - 12px) 12px, rgba(20, 33, 61, 0.22) 3px, transparent 3.5px),
    radial-gradient(circle at 12px calc(100% - 12px), rgba(20, 33, 61, 0.22) 3px, transparent 3.5px),
    radial-gradient(circle at calc(100% - 12px) calc(100% - 12px), rgba(20, 33, 61, 0.22) 3px, transparent 3.5px);
  border: 1px solid rgba(20, 33, 61, 0.10);
  box-shadow: 0 1px 0 rgba(20, 33, 61, 0.06), 0 10px 24px rgba(20, 33, 61, 0.10);
}

.topbar { padding: 0 18px 12px; overflow: hidden; border-radius: var(--radius); }
.topbar .stripe {
  margin: 0 -18px 8px;
  padding: 5px 18px;
  background: var(--wave);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.topbar h1 { font-weight: 800; font-size: 36px; line-height: 0.95; letter-spacing: 0.005em; }
.topbar #subtitle { color: var(--grey); font-size: 13px; }
@media (min-width: 820px) {
  .topbar { padding: 0 22px 16px; }
  .topbar .stripe { margin: 0 -22px 10px; padding: 6px 22px; }
  .topbar h1 { font-size: 46px; }
  .sheet { top: 136px; max-height: calc(100% - 156px); }
}

.sheet { border-radius: var(--radius); padding-top: 24px; }
@media (max-width: 819px) {
  .sheet::before { background: rgba(20, 33, 61, 0.18); }
}
.lede { color: var(--grey); }

/* Numbers carry the page, the way they do on a bib */
.facts dd, .eta, .mine-eta, .pins .mile, .bib-number { font-weight: 800; }
.facts dd { font-size: 22px; }
.eta { font-size: clamp(44px, 13vw, 54px); line-height: 0.92; }
.eta.long { font-size: clamp(34px, 10.5vw, 44px); }
.where { color: var(--wave-deep); font-weight: 700; font-size: 15px; }
.mine-eta { color: var(--ink); font-size: 26px; }
.pins .mile { color: var(--ink); font-size: 30px; }

/* Buttons: navy ink, square-ish, like the tear-off tabs at the bottom of a bib */
button.primary, .primary-link { border-radius: 4px; font-weight: 700; }
button.secondary, .secondary-link { border-radius: 4px; color: var(--ink); border-color: rgba(20, 33, 61, 0.35); }
button.secondary:hover, .secondary-link:hover { background: rgba(20, 33, 61, 0.05); }
input:not([type="radio"]) { border-radius: 4px; background: #fff; border-color: rgba(20, 33, 61, 0.18); }
.seg, .seg span { border-radius: 4px; }
.seg input:checked + span { background: var(--ink); }
.close { border-radius: 4px; }
.snap-note { color: var(--wave-deep); border-radius: 4px; }
.mine-row { border-radius: 4px; background: rgba(224, 69, 123, 0.08); border-color: rgba(224, 69, 123, 0.30); }
.official summary::after { border-color: var(--ink); }
.steps li::marker { color: var(--wave-deep); }
.bib { border-top: 6px solid var(--wave); border-radius: 4px; }

/* Mile markers: little tags hung on the course */
.mile-marker {
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  font-weight: 800;
  font-size: 13px;
}
.mile-marker.big { border-radius: 3px; background: var(--wave); border-color: var(--wave); color: #fff; }

.leaflet-bar { border-radius: 6px !important; }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--tyvek); color: var(--ink); }
.leaflet-gl-layer { filter: saturate(0.6); }

@media (prefers-reduced-motion: reduce) {
  .live::before { animation: none; }
  * { transition: none !important; }
}

/* Print: just the list, black on white */
@media print {
  .topbar, #map, .admin-head button, .pins button, .admin-login { display: none !important; }
  body, main { position: static; background: #fff; color: #000; }
  .sheet { position: static; background: #fff; box-shadow: none; border: 0; backdrop-filter: none; max-height: none; width: auto; padding: 0; }
  .admin-head .where, .pins .who { color: #000; }
  .pins .detail, .pins .mile small { color: #333; }
  .pins li { grid-template-columns: 80px 1fr; break-inside: avoid; border-top-color: #ccc; }
  .pins .mile { color: #000; font-size: 30px; }
}
