/* Scroll to SF — night ocean chart.
   Deep navy water, chart-cream type, Golden Gate orange, bathymetric blue. */

@font-face {
  font-family: "Big Shoulders Display";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(../../assets/fonts/bigshouldersdisplay-700.woff2) format("woff2");
}
@font-face {
  font-family: "Big Shoulders Display";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url(../../assets/fonts/bigshouldersdisplay-800.woff2) format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../../assets/fonts/ibmplexmono-400.woff2) format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(../../assets/fonts/ibmplexmono-400i.woff2) format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(../../assets/fonts/ibmplexmono-500.woff2) format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(../../assets/fonts/ibmplexmono-600.woff2) format("woff2");
}

:root {
  --ink: #0b1b26;
  --ink-2: #0f2431;
  --ink-3: #15303f;
  --line: rgba(205, 224, 231, 0.14);
  --line-strong: rgba(205, 224, 231, 0.28);
  --cream: #ede6d4;
  --fog: #9fb0b5;
  --orange: #ff5a1f;
  --orange-deep: #cc3f0c;
  --blue: #86b9cd;
  --sage: #9cc394;
  --display: "Big Shoulders Display", "Arial Narrow", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sheet-r: 18px;
  --card-r: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
  border-radius: 4px;
}

a { color: var(--blue); text-decoration: none; }

.hidden { display: none !important; }

/* ------------------------------------------------------------- screens */

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.screen.on { display: flex; }

/* -------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 18px 10px;
}

.brand {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--fog);
  letter-spacing: 0.02em;
}
.brand b { color: var(--cream); font-weight: 500; }
@media (max-width: 460px) { .brand b { display: none; } }

.top-actions { display: flex; gap: 8px; }

.chip {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--cream);
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  white-space: nowrap;
}
.chip:active { background: var(--ink-3); }
.chip.accent { color: var(--orange); border-color: rgba(255, 90, 31, 0.4); }

/* ---------------------------------------------------------------- hero */

.hero { padding: 26px 18px 6px; }

.route-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--blue);
}
.route-line .dash {
  flex: 0 1 72px;
  border-top: 1px dashed var(--blue);
  opacity: 0.6;
  position: relative;
  top: 1px;
}

.title {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(64px, 21vw, 112px);
  line-height: 0.86;
  letter-spacing: 0.005em;
  margin: 10px 0 14px;
  color: var(--cream);
}
.title em {
  font-style: normal;
  color: var(--orange);
}

.sub {
  color: var(--fog);
  font-size: 13.5px;
  max-width: 34em;
}

/* ------------------------------------------------------------- tickets */

.tickets {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 20px 18px 8px;
}

.ticket {
  text-align: left;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--card-r);
  padding: 14px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: transform 0.06s ease;
}
.ticket:active { transform: scale(0.97); background: var(--ink-3); }

.t-dist {
  font-family: var(--display);
  font-weight: 800;
  font-size: 44px;
  line-height: 1;
  color: var(--cream);
}
.t-dist small {
  font-size: 22px;
  margin-left: 2px;
  color: var(--blue);
  font-weight: 700;
}
.t-meta { font-size: 11.5px; color: var(--fog); margin-top: 6px; line-height: 1.4; }
.t-best { font-size: 11.5px; color: var(--blue); margin-top: 4px; }

.ticket-sf {
  grid-column: 1 / -1;
  border-color: rgba(255, 90, 31, 0.45);
  background: linear-gradient(180deg, rgba(255, 90, 31, 0.1), rgba(255, 90, 31, 0.02)), var(--ink-2);
  padding: 16px 14px 14px;
}
.ticket-sf .t-dist { color: var(--orange); font-size: 52px; }
.ticket-sf .t-dist small { color: var(--orange); opacity: 0.75; }

.t-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.t-sub { font-size: 12px; color: var(--cream); }

.t-bar {
  margin-top: 10px;
  height: 4px;
  border-radius: 2px;
  background: var(--ink);
  overflow: hidden;
  position: relative;
}
.t-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  min-width: 2px;
  background: var(--orange);
  border-radius: 2px;
}

.homefoot {
  margin-top: auto;
  padding: 14px 18px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: var(--fog);
  font-size: 11.5px;
  border-top: 1px solid var(--line);
}
.homefoot b { color: var(--blue); font-weight: 500; }
.homefoot button { color: var(--fog); font-size: 11.5px; text-decoration: underline; text-underline-offset: 3px; }

/* ---------------------------------------------------------------- race */

.racebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px 8px;
}
.race-mode { font-size: 13px; color: var(--fog); flex: 1; text-align: center; }
.race-clock {
  font-size: 15px;
  font-weight: 600;
  color: var(--cream);
  min-width: 86px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.odo { padding: 6px 18px 0; display: flex; align-items: baseline; gap: 8px; }
.odo-num {
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(34px, 9.6vw, 52px);
  letter-spacing: -0.02em;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}
.odo-unit { font-size: 20px; color: var(--blue); font-weight: 500; }
.odo-sub {
  padding: 0 18px 8px;
  font-size: 12px;
  color: var(--fog);
  font-variant-numeric: tabular-nums;
}
.odo-sub b { color: var(--orange); font-weight: 500; }

/* tape */

.tape-wrap {
  position: relative;
  flex: 1;
  min-height: 160px;
  margin: 2px 18px 10px;
  border: 1px solid var(--line);
  border-radius: var(--card-r);
  overflow: hidden;
  background: var(--ink-2);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.tape {
  position: absolute;
  left: 0;
  right: 0;
  will-change: transform;
}

.tlabel {
  position: absolute;
  right: 14px;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--fog);
  font-variant-numeric: tabular-nums;
  will-change: top;
  pointer-events: none;
}

.needle {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 2px solid var(--orange);
  pointer-events: none;
}
.needle::before {
  content: "";
  position: absolute;
  left: 0;
  top: -6px;
  border: 5px solid transparent;
  border-left: 8px solid var(--orange);
}

.tape-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 36px;
  color: var(--fog);
  font-size: 13px;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.tape-hint.off { opacity: 0; }

/* race footer */

.race-foot {
  padding: 0 18px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sprint-bar {
  height: 6px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.sprint-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--orange);
}
.foot-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--fog);
  font-variant-numeric: tabular-nums;
}
.foot-row .next-ms { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foot-row button { color: var(--blue); font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }

/* map */

.map-card {
  margin: 0 18px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--card-r);
  overflow: hidden;
  background: var(--ink-2);
  flex: 0 0 auto;
}
.map-card .map {
  height: 30dvh;
  min-height: 170px;
  background: #cdd9d4;
}
#s-result .map-card .map { height: 26dvh; }
.map-cap {
  padding: 8px 12px;
  font-size: 11.5px;
  color: var(--fog);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-variant-numeric: tabular-nums;
}
.map-cap button { color: var(--blue); font-size: 11.5px; text-decoration: underline; text-underline-offset: 3px; }

.leaflet-container { font: 10px/1.4 var(--mono) !important; }
.leaflet-control-attribution {
  background: rgba(11, 27, 38, 0.72) !important;
  color: var(--fog) !important;
}
.leaflet-control-attribution a { color: var(--blue) !important; }

.pos-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--orange);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(255, 90, 31, 0.35), 0 1px 4px rgba(0, 0, 0, 0.4);
}
.end-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
}

/* -------------------------------------------------------------- result */

.result-scroll { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }

.result-card {
  margin: 10px 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--card-r);
  background: var(--ink-2);
  padding: 18px 16px 16px;
}
.r-mode { font-size: 12.5px; color: var(--fog); }
.r-big {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(52px, 16vw, 84px);
  line-height: 1;
  margin: 6px 0 2px;
  color: var(--cream);
}
.r-big small { font-size: 0.45em; color: var(--blue); font-weight: 700; }
.r-rank { font-size: 13px; color: var(--orange); min-height: 20px; }

.r-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}
.r-stat {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--ink);
}
.r-stat b {
  display: block;
  font-weight: 600;
  font-size: 15px;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}
.r-stat span { font-size: 10.5px; color: var(--fog); }

.claim {
  margin: 0 18px 10px;
  border: 1px dashed rgba(255, 90, 31, 0.5);
  border-radius: var(--card-r);
  padding: 12px 14px;
  background: rgba(255, 90, 31, 0.06);
}
.claim p { font-size: 12.5px; color: var(--cream); margin-bottom: 8px; }

.result-actions {
  display: flex;
  gap: 10px;
  padding: 4px 18px calc(16px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------- buttons */

.btn {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
  border-radius: 10px;
  padding: 13px 18px;
  text-align: center;
  flex: 1;
}
.btn-primary { background: var(--orange); color: #16100c; }
.btn-primary:active { background: var(--orange-deep); color: var(--cream); }
.btn-ghost { background: var(--ink-2); border: 1px solid var(--line); color: var(--cream); }
.btn-ghost:active { background: var(--ink-3); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* -------------------------------------------------------------- sheets */

#backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 14, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}
#backdrop.on { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 102%);
  width: min(100%, 560px);
  max-height: 86dvh;
  background: var(--ink-2);
  border: 1px solid var(--line-strong);
  border-bottom: none;
  border-radius: var(--sheet-r) var(--sheet-r) 0 0;
  z-index: 50;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
}
.sheet.on { transform: translate(-50%, 0); }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
}
.sheet-head h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.01em;
}
.sheet-close { color: var(--fog); font-size: 13px; padding: 6px 0 6px 12px; }

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 18px calc(20px + env(safe-area-inset-bottom));
}

/* leaderboard */

.tabs { display: flex; gap: 6px; padding-bottom: 12px; }
.tab {
  flex: 1;
  font-size: 13px;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--fog);
  background: var(--ink);
}
.tab.on { color: var(--ink); background: var(--blue); border-color: var(--blue); font-weight: 600; }

.lb-list { display: flex; flex-direction: column; }
.lb-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.lb-row .rank { color: var(--fog); width: 2.4em; flex: none; }
.lb-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--cream); }
.lb-row .val { color: var(--blue); }
.lb-row.me { background: rgba(255, 90, 31, 0.08); border-radius: 6px; }
.lb-row.me .name { color: var(--orange); }
.lb-empty, .lb-note { padding: 14px 2px; color: var(--fog); font-size: 12.5px; }

/* profile & forms */

.p-section { padding: 12px 0 16px; border-bottom: 1px solid var(--line); }
.p-section:last-child { border-bottom: none; }
.p-section h3 { font-size: 13px; font-weight: 600; color: var(--cream); margin-bottom: 4px; }
.p-section p { font-size: 12.5px; color: var(--fog); margin-bottom: 10px; }
.p-section p b { color: var(--cream); font-weight: 500; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.field label { font-size: 11.5px; color: var(--fog); }
input {
  user-select: text;
  -webkit-user-select: text;
}
.field input, .inline-form input {
  font: inherit;
  font-size: 16px;
  color: var(--cream);
  background: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 11px 12px;
}
.field input:focus, .inline-form input:focus { border-color: var(--blue); outline: none; }
.field input::placeholder, .inline-form input::placeholder { color: rgba(159, 176, 181, 0.55); }

.form-msg { min-height: 18px; font-size: 12px; color: var(--orange); margin-bottom: 6px; }
.form-msg.ok { color: var(--sage); }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }
.inline-form .btn { flex: none; padding: 11px 16px; }

.linkish { color: var(--blue); font-size: 12.5px; text-decoration: underline; text-underline-offset: 3px; }

/* calibration */

.cal-bar-wrap { padding: 14px 0 6px; }
.cal-bar {
  width: 100%;
  height: 340px;
  background: var(--ink);
  border: 1px solid var(--blue);
  border-radius: 6px;
  position: relative;
  margin-bottom: 6px;
}
.cal-bar::after {
  content: "drag the slider until this box is exactly as tall as a bank card's short edge";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fog);
  font-size: 11px;
  padding: 0 8px;
  text-align: center;
}
.cal-read { font-size: 12px; color: var(--fog); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--orange); margin: 10px 0; }

/* --------------------------------------------------------------- toast */

#toast {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translate(-50%, -16px);
  width: min(92%, 420px);
  background: var(--ink-3);
  border: 1px solid var(--orange);
  border-radius: 12px;
  padding: 12px 14px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast b { display: block; font-size: 14px; color: var(--orange); font-weight: 600; }
#toast span { font-size: 12px; color: var(--cream); }

/* ------------------------------------------------------------ desktop */

.desktop-note { display: none; }

@media (min-width: 700px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .desktop-note {
    display: block;
    padding: 10px 18px 0;
    color: var(--fog);
    font-size: 12px;
  }
  .desktop-note b { color: var(--blue); font-weight: 500; }
}

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