/* Trip Tracker — "Camino HUD". Map is the hero; chrome is theme-aware smoked
   glass with a single Camino-waymark gold accent. Mobile-first, thumb-reach. */

:root {
  --font-ui: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, monospace;

  /* light (default) */
  --glass: rgba(250, 247, 240, 0.74);
  --glass-solid: #f6f2e9;
  --brd: rgba(28, 24, 16, 0.12);
  --brd-hi: rgba(255, 255, 255, 0.6);
  --ink: #1d1a13;
  --ink-2: #58513f;
  --muted: #8b8474;
  --accent: #e39a12;        /* gold for marks/lines */
  --accent-ink: #8f5e00;    /* gold that clears contrast as text */
  --accent-soft: rgba(227, 154, 18, 0.14);
  --hairline: rgba(28, 24, 16, 0.1);
  --live: #e5484d;
  --shadow: 0 -14px 40px rgba(20, 16, 8, 0.16);
  --shadow-head: 0 8px 30px rgba(20, 16, 8, 0.14);

  /* chart (dataviz tokens) */
  --c-line-done: var(--accent);
  --c-line-rest: #b7ae9b;
  --c-area-done: rgba(227, 154, 18, 0.16);
  --c-area-rest: rgba(29, 26, 19, 0.05);
  --c-grid: rgba(28, 24, 16, 0.09);
  --c-text: var(--muted);
  --surface: #f6f2e9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --glass: rgba(20, 22, 18, 0.62);
    --glass-solid: #171a14;
    --brd: rgba(255, 255, 255, 0.12);
    --brd-hi: rgba(255, 255, 255, 0.08);
    --ink: #f2efe6;
    --ink-2: #c8c3b4;
    --muted: #8f897a;
    --accent: #ffb51e;
    --accent-ink: #ffc857;
    --accent-soft: rgba(255, 181, 30, 0.16);
    --hairline: rgba(255, 255, 255, 0.1);
    --live: #ff5a5f;
    --shadow: 0 -16px 46px rgba(0, 0, 0, 0.5);
    --shadow-head: 0 10px 34px rgba(0, 0, 0, 0.44);

    --c-line-done: var(--accent);
    --c-line-rest: #6b6858;
    --c-area-done: rgba(255, 181, 30, 0.16);
    --c-area-rest: rgba(255, 255, 255, 0.05);
    --c-grid: rgba(255, 255, 255, 0.09);
    --surface: #171a14;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--glass-solid);
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; overflow: hidden; }

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

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--brd);
}

/* ---------- header ---------- */
.hud-header {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 10px;
  right: 10px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 16px;
  box-shadow: var(--shadow-head);
}
.brand svg { width: 26px; height: 26px; display: block; }
.brand path { fill: var(--accent); }
.brand .ribs { stroke: var(--glass-solid); stroke-width: 1.1; opacity: 0.55; }
.head-titles { flex: 1; min-width: 0; }
.head-titles h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.head-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  border: 1px solid var(--brd);
}
.chip::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.chip[data-status="trip"] { color: var(--accent-ink); }
.chip[data-status="done"] { color: var(--ink-2); }
.chip[data-status="live"] {
  color: #fff;
  background: var(--live);
  border-color: transparent;
}
.chip[data-status="live"]::before {
  background: #fff;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
  animation: livepulse 1.5s infinite;
}
@keyframes livepulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.75); }
  70% { box-shadow: 0 0 0 7px rgba(255, 255, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

.banner {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 66px);
  left: 10px;
  z-index: 19;
  padding: 7px 13px;
  border-radius: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-ink);
  box-shadow: var(--shadow-head);
}

/* ---------- bottom sheet ---------- */
.sheet {
  position: fixed;
  left: 0; right: 0; top: 0;
  height: 100dvh;
  z-index: 30;
  border: none;
  border-top: 1px solid var(--brd);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  will-change: transform;
  touch-action: none;
}
.grabber {
  flex: none;
  height: 26px;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}
.grabber span {
  width: 40px; height: 5px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--ink) 26%, transparent);
}
.sheet-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 14px calc(env(safe-area-inset-bottom) + 22px);
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.sheet[data-detent="peek"] .sheet-scroll { overflow-y: hidden; }

/* ---------- telemetry: peek strip ---------- */
.peek {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: stretch;
  gap: 14px;
  padding: 4px 2px 14px;
  background: linear-gradient(var(--glass-solid) 82%, transparent);
}
.peek-speed {
  display: flex;
  align-items: baseline;
  gap: 5px;
  line-height: 0.9;
}
.peek-speed .v {
  font-family: var(--font-mono);
  font-size: clamp(46px, 15vw, 60px);
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.peek-speed .u { font-size: 13px; color: var(--muted); font-weight: 600; }
.peek-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}
.peek-dist {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
}
.peek-dist .v { font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
.peek-dist .u { font-size: 10px; color: var(--muted); margin-left: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.peek-dist .sep { width: 1px; align-self: stretch; background: var(--hairline); }

.peek-fresh {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.fresh-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.peek-fresh[data-state="live"] { color: var(--ink-2); }
.peek-fresh[data-state="live"] .fresh-dot {
  background: #24b56a;
  box-shadow: 0 0 0 0 rgba(36, 181, 106, 0.6);
  animation: livepulse 2s infinite;
}
.peek-fresh[data-state="stale"] { color: var(--live); }
.peek-fresh[data-state="stale"] .fresh-dot { background: var(--live); }

/* ---------- telemetry grid ---------- */
.tele-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding-bottom: 6px;
}
.tile {
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  border: 1px solid var(--hairline);
  border-radius: 13px;
  padding: 9px 10px 10px;
  min-width: 0;
}
.tile-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-value {
  display: flex;
  align-items: baseline;
  gap: 3px;
  white-space: nowrap;
}
.tile-value .v {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.tile-value .u { font-size: 10px; color: var(--muted); }

.heart {
  width: 9px; height: 9px;
  margin-left: 2px;
  border-radius: 50%;
  background: var(--live);
  opacity: 0.35;
  transform: scale(1);
}
.heart.beating { opacity: 1; animation: beat var(--bpm, 0.9s) infinite ease-in-out; }
@keyframes beat {
  0%, 100% { transform: scale(1); }
  18% { transform: scale(1.5); }
  36% { transform: scale(1); }
}
.batt {
  position: relative;
  width: 20px; height: 10px;
  margin-left: 4px;
  border: 1.4px solid color-mix(in srgb, var(--ink) 42%, transparent);
  border-radius: 3px;
  align-self: center;
}
.batt::after {
  content: ""; position: absolute; right: -3px; top: 2.5px;
  width: 2px; height: 3px; border-radius: 0 1px 1px 0;
  background: color-mix(in srgb, var(--ink) 42%, transparent);
}
.batt-fill {
  position: absolute; inset: 1.4px; width: 60%;
  border-radius: 1px; background: #24b56a;
}
.batt-fill.low { background: var(--live); }

@media (max-width: 340px) {
  .tele-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- content blocks ---------- */
.block { margin-top: 16px; }
.block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.block-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-2);
}
.block-hint { font-size: 10px; color: var(--muted); }

/* ---------- elevation chart ---------- */
.chart {
  position: relative;
  width: 100%;
  border-radius: 13px;
  background: color-mix(in srgb, var(--ink) 3%, transparent);
  border: 1px solid var(--hairline);
  padding: 2px;
}
.chart-empty {
  padding: 30px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
.elev-svg { display: block; width: 100%; height: 150px; touch-action: none; }
.elev-grid .gl { stroke: var(--c-grid); stroke-width: 1; }
.elev-grid .gt {
  fill: var(--c-text);
  font: 9px var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.elev-grid .gt-x { text-anchor: middle; }
.elev-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.elev-line.rest { stroke: var(--c-line-rest); opacity: 0.85; }
.elev-line.done { stroke: var(--c-line-done); }
.elev-area.rest { fill: var(--c-area-rest); }
.elev-area.done { fill: var(--c-area-done); }
.elev-tick { fill: var(--accent); opacity: 0.9; }
.elev-prog { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.elev-hover { fill: var(--ink); stroke: var(--surface); stroke-width: 2; opacity: 0; }
.elev-hover.on { opacity: 1; }
.elev-cross { stroke: var(--ink); stroke-width: 1; opacity: 0; stroke-dasharray: 2 3; }
.elev-cross.on { opacity: 0.4; }
.elev-readout {
  position: absolute;
  top: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
  background: var(--glass-solid);
  border: 1px solid var(--hairline);
  border-radius: 7px;
  padding: 2px 7px;
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.elev-readout.on { opacity: 1; }

/* ---------- feed ---------- */
.composer { margin-bottom: 12px; }
.composer-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.c-name, .c-text {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  border: 1px solid var(--hairline);
  border-radius: 11px;
  padding: 10px 12px;
  min-width: 0;
}
.c-name { flex: 0 0 33%; }
.c-text { flex: 1; }
.c-name:focus, .c-text:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--accent-soft);
}
.c-send {
  flex: none;
  width: 42px; height: 42px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #201400;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.c-send svg { width: 20px; height: 20px; fill: currentColor; }
.c-send:active { transform: scale(0.94); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.chat { display: flex; flex-direction: column; gap: 7px; margin-bottom: 4px; }
.chat[data-empty="1"] { display: none; }
.comment {
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink-2);
}
.comment .c-who { font-weight: 650; color: var(--ink); margin-right: 6px; }
.comment .c-when { color: var(--muted); font-size: 11px; margin-left: 6px; }
.comment.pending { opacity: 0.5; }
.comment.failed { color: var(--live); }

.feed-list { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.card {
  border: 1px solid var(--hairline);
  border-radius: 15px;
  overflow: hidden;
  background: color-mix(in srgb, var(--ink) 3%, transparent);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 8px;
}
.card-glyph {
  width: 22px; height: 22px;
  border-radius: 7px;
  background: var(--accent-soft);
  flex: none;
  position: relative;
}
.card-glyph::after {
  content: "";
  position: absolute; inset: 0;
  -webkit-mask: center / 14px no-repeat; mask: center / 14px no-repeat;
  background: var(--accent-ink);
}
.card-glyph[data-k="tweet"]::after { -webkit-mask-image: var(--i-tweet); mask-image: var(--i-tweet); }
.card-glyph[data-k="photo"]::after { -webkit-mask-image: var(--i-photo); mask-image: var(--i-photo); }
.card-glyph[data-k="video"]::after { -webkit-mask-image: var(--i-video); mask-image: var(--i-video); }
.card-meta {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.card-when { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-km {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 999px;
}
.card-media { line-height: 0; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.card-media img, .card-media video {
  width: 100%;
  max-height: 62vh;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.card-media video { cursor: auto; }
.card-text {
  margin: 0;
  padding: 10px 12px 12px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
}
.card[data-kind="tweet"] .card-text { font-size: 15.5px; }
.card-comments-toggle {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: none;
  border-top: 1px solid var(--hairline);
  background: transparent;
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.card-comments { padding: 2px 12px 12px; display: flex; flex-direction: column; gap: 7px; }

@keyframes flash {
  0% { box-shadow: 0 0 0 2px var(--accent); }
  100% { box-shadow: 0 0 0 2px transparent; }
}
.card-flash { animation: flash 1.4s ease-out; }

/* ---------- rider marker ---------- */
.rider { width: 0; height: 0; }
.rider-pulse {
  position: absolute;
  left: -17px; top: -17px;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  animation: ripple 2.4s ease-out infinite;
}
@keyframes ripple {
  0% { transform: scale(0.4); opacity: 0.55; }
  100% { transform: scale(1.5); opacity: 0; }
}
.rider-dot {
  position: absolute;
  left: -13px; top: -13px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
}
.rider-arrow { width: 16px; height: 16px; transform-origin: 50% 50%; }
.rider-arrow path { fill: #22160a; }
.rider-stale { display: none; font-weight: 800; color: #fff; font-size: 15px; }
.rider.is-stale .rider-pulse { animation-duration: 3.6s; background: #9aa0a6; opacity: 0.4; }
.rider.is-stale .rider-dot { background: #9aa0a6; }
.rider.is-stale .rider-arrow { display: none; }
.rider.is-stale .rider-stale { display: block; }

/* ---------- photo pins ---------- */
.pin {
  width: 30px; height: 30px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  transform: translateY(-4px);
}
.pin svg {
  width: 30px; height: 30px;
  fill: none;
  stroke: #fff;
  stroke-width: 1.4;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
  paint-order: stroke;
}
.pin svg path { fill: var(--accent); }
.pin svg circle { fill: color-mix(in srgb, var(--accent) 40%, #201400); }
.pin-flash { animation: pinflash 1.2s ease-out; }
@keyframes pinflash {
  0%, 100% { transform: translateY(-4px) scale(1); }
  40% { transform: translateY(-8px) scale(1.35); }
}

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(10, 8, 4, 0.92);
  display: grid;
  place-items: center;
  padding: 20px;
}
.lightbox[hidden] { display: none; }
[hidden] { display: none !important; }
.lightbox img { max-width: 100%; max-height: 82vh; border-radius: 10px; }
.lb-cap { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 16px); color: #eee; font-size: 13px; padding: 0 20px; text-align: center; }
.lb-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
}

/* ---------- maplibre control skinning ---------- */
.maplibregl-ctrl-group {
  background: var(--glass) !important;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--brd) !important;
  box-shadow: var(--shadow-head) !important;
}
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--brd) !important; }
.maplibregl-ctrl-attrib {
  background: var(--glass) !important;
  border-radius: 8px;
}
.maplibregl-ctrl-attrib a, .maplibregl-ctrl-attrib { color: var(--ink-2) !important; }
.maplibregl-ctrl-top-right { top: calc(env(safe-area-inset-top) + 70px); }
.maplibregl-ctrl-bottom-left { bottom: 8px; }

.sse-down .peek-fresh[data-state="none"] .fresh-txt::after { content: " · reconnecting"; }

/* glyph masks (inline data URIs, no external requests) */
:root {
  --i-tweet: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="black" d="M20 4H4a2 2 0 00-2 2v10a2 2 0 002 2h3v3l4-3h9a2 2 0 002-2V6a2 2 0 00-2-2z"/></svg>');
  --i-photo: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="black" d="M9 4l-1.2 2H4.5A1.5 1.5 0 003 7.5v10A1.5 1.5 0 004.5 19h15a1.5 1.5 0 001.5-1.5v-10A1.5 1.5 0 0019.5 6h-3.3L15 4zm3 4.8a3.7 3.7 0 110 7.4 3.7 3.7 0 010-7.4z"/></svg>');
  --i-video: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="black" d="M4 5.5A1.5 1.5 0 015.5 4h9A1.5 1.5 0 0116 5.5v3l4-2.6v12.2L16 15.5v3a1.5 1.5 0 01-1.5 1.5h-9A1.5 1.5 0 014 18.5z"/></svg>');
}
