:root {
  --ink: #0a0d0c;
  --panel: #11161a;
  --panel-edge: #1c252b;
  --amber: #ffb02e;
  --amber-dim: #8a5e17;
  --cyan: #4fd9d4;
  --paper: #d8e2e0;
  --paper-dim: #6f8480;
  --danger: #ff5d5d;
  --mono: 'JetBrains Mono', 'Consolas', monospace;
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh; /* fallback for browsers that don't support dvh */
  height: 100dvh; /* accounts for mobile Safari's address bar — 100vh assumes
                      it's hidden, which pushes content (like the footer's
                      speed buttons) below the actually-visible area with no
                      way to scroll to it, since this layout deliberately
                      disables page scrolling */
}

/* ---------- Header / Tape ---------- */

#tape {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-edge);
  font-family: var(--display);
}

#tape .brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;    /* allows the brand to shrink so right-side buttons stay visible */
  overflow: hidden;
}

#tape .brand .mark {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--amber);
  text-transform: uppercase;
  text-decoration: none;
}
a.mark:hover { color: #ffc158; }

/* Route name on the shared page — same size/weight as the brand mark
   above, but white, so it echoes the "Drop your" (white) + "GPS logs"
   (amber) pairing on the upload page. */
#tape .brand .trip-name { color: var(--paper); font-size: 22px; margin-left: 28px; }

#tape .brand .sub {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--paper-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}

#tape .rec {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--paper);
  letter-spacing: 1px;
}
#tape .rec #recLabel { display: none; }

.tape-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Overflow/settings panels: speedGroup, dayRow (now nested inside
   playbackSettings), and playbackSettings itself are all real dropdown
   panels on both desktop and mobile now, consistent with the header menu
   below — their trigger buttons stay hidden only via the shared
   .panel-trigger rule below, which each trigger then overrides. */
/* Header menu — always visible, always a real dropdown, on both mobile and
   desktop. Share/My trips/About/Sign out/Tips all live inside it. This
   used to only become a real dropdown on mobile (display:contents on
   desktop made it invisible plumbing), but that conditional complexity
   was itself the source of a desktop bug — simpler to just have one
   consistent behavior everywhere. */
#headerMenuBtn {
  background: #161d22; border: 1px solid var(--panel-edge); color: var(--paper);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px; border-radius: 4px; cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#headerMenuBtn svg { width: 20px; height: 20px; }
#headerMenuBtn:hover { color: var(--cyan); border-color: var(--cyan); }
.dropdown-panel {
  display: none;
  position: absolute; top: 100%; right: 0; margin-top: 6px; z-index: 6000;
  flex-direction: column; gap: 6px; min-width: 170px;
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 4px;
  padding: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.dropdown-panel.open { display: flex; }
.dropdown-panel .statsbtn, .dropdown-panel .amber-cta, .dropdown-panel #signOutBtn, .dropdown-panel #signUpLink {
  width: 100%; justify-content: center;
}
.tape-right, .tape-right-simple { position: relative; flex-shrink: 0; }
.dropdown-wrap { position: relative; display: inline-flex; }


/* ---------- Segmented control (map style) ---------- */

.seg-group {
  display: flex;
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  overflow: hidden;
}

.segbtn {
  background: #161d22;
  border: none;
  border-right: 1px solid var(--panel-edge);
  color: var(--paper-dim);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 6px 10px;
  cursor: pointer;
}

.segbtn:last-child { border-right: none; }

.segbtn.active {
  background: rgba(255,176,46,0.12);
  color: var(--amber);
}

.segbtn:hover:not(.active) { color: var(--paper); }

.statsbtn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #161d22;
  border: 1px solid var(--panel-edge);
  color: var(--paper-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 3px;
  cursor: pointer;
}

.statsbtn svg { width: 13px; height: 13px; }

/* Must come after .statsbtn — these share equal specificity (both single
   classes), and elements like #settingsToggleBtn have both classes, so
   whichever rule is LATER in the file wins the display tiebreaker. This
   was previously defined before .statsbtn, meaning .statsbtn's
   display:flex silently won over this display:none the entire time,
   regardless of screen width — these buttons have been visible on
   genuine desktop this whole time, not just as a narrow-window edge case. */
.panel-trigger {
  display: none;
}
#speedTriggerBtn {
  display: inline-flex;
}
#statsToggle {
  display: inline-flex;
}
#settingsToggleBtn {
  display: inline-flex;
}
#settingsToggleBtn svg { width: 16px; height: 16px; }

.statsbtn:hover { color: var(--paper); }

.statsbtn.active {
  background: rgba(255,176,46,0.12);
  border-color: var(--amber);
  color: var(--amber);
}

/* When a light basemap is active, dim the HUD/markers slightly less harshly */
body.light-basemap .leaflet-control-attribution {
  background: rgba(255,255,255,0.7) !important;
  color: #555 !important;
}

#tape .rec .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--paper-dim);
}

#tape .rec.live .dot {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
  animation: pulse 1.2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- Main stage ---------- */

#stage {
  position: relative;
  min-height: 0;
}

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

/* Leaflet dark tuning */
.leaflet-container { background: #0d1113; }
.leaflet-control-attribution {
  background: rgba(10,13,12,0.7) !important;
  color: var(--paper-dim) !important;
  font-family: var(--mono);
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--cyan) !important; }
.leaflet-bar a {
  background: var(--panel) !important;
  color: var(--paper) !important;
  border-color: var(--panel-edge) !important;
}
.leaflet-bar a:hover { background: #1a2329 !important; color: var(--amber) !important; }

/* Car marker */
.car-icon {
  width: 100%;
  height: 100%;
  display: block;
  transform-origin: 50% 50%;
  filter: drop-shadow(0 0 6px rgba(79,217,212,0.65));
}

/* Day flag markers */
.day-flag {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--amber);
  border: 2px solid #1a1206;
  color: #1a1206;
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.leaflet-tooltip.leaflet-tooltip-top {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 11px;
  border-radius: 2px;
}

/* ---------- Drop zone overlay ---------- */

#dropzone {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 40%, rgba(20,28,30,0.92), rgba(8,10,10,0.97));
  z-index: 1200;
  transition: opacity 0.25s ease;
}

#appPromo {
  display: flex; align-items: center; gap: 12px;
  background: rgba(17,22,26,0.6); border: 1px solid var(--panel-edge); border-radius: 4px;
  padding: 10px 16px; width: min(480px, 86vw); box-sizing: border-box;
  cursor: pointer; transition: border-color 0.15s;
}
#appPromo:hover { border-color: var(--amber); }
#appPromoQr {
  background: #fff; padding: 4px; border-radius: 3px; flex-shrink: 0;
  width: 78px; height: 78px;
}
#appPromoText { display: flex; flex-direction: column; gap: 2px; text-align: left; }
#appPromoText strong { color: var(--paper); font-family: var(--display); font-size: 1.1rem; text-transform: uppercase; letter-spacing: 0.02em; }
#appPromoText span { color: var(--paper-dim); font-size: 0.78rem; }


/* Speed trigger: full label on desktop, just "Speed" on mobile to save space */
.speed-short { display: none; }
.speed-full { display: inline; }

/* The share icon (mobileActionsWrap) replaces the amber Share/Save&Share
   button on ALL screen sizes. Its visibility is controlled by the .hidden
   class (removed by app.js / trip-view.js / export.js when a trip loads). */
#shareBtn, #reshareBtn { display: none !important; }

@media (max-width: 640px) {
  #mobileActionsDropdown .amber-cta,
  #mobileActionsDropdown .statsbtn { width: 100%; justify-content: center; }
  /* Shorten speed button so the entire footer row fits on one line */
  .speed-full { display: none; }
  .speed-short { display: inline; }
}
#shareBtn.working { opacity: 0.6; pointer-events: none; }
#shareBtn.done { color: #4fd9d4; }
#dropzone.hidden { display: none; }

/* --- Shared/read-only trip view (trip.html) --- */
body.shared-view #app { grid-template-rows: auto 1fr auto; }

/* Floating map-style switcher, present on both the upload page and the
   shared trip page — z-index follows the same reasoning as the About/Tips
   buttons: Leaflet's own panes/controls go up to z-index 1000, and #map
   doesn't isolate its own stacking context, so anything meant to sit
   above the map needs to clear that bar. */
#topRightControls {
  position: absolute; top: 16px; right: 16px; z-index: 1500;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
#mapControlsRow {
  display: flex; align-items: center; gap: 8px;
}
#mapStyleGroup {
  background: rgba(10,14,13,0.72); backdrop-filter: blur(2px);
}

.segbtn.locked { opacity: 0.55; cursor: pointer; }
.segbtn.locked:hover { opacity: 0.85; }
.segbtn .lock { font-size: 9px; margin-left: 2px; }

#mapStyleUnlockPrompt {
  position: absolute; top: 54px; right: 16px; z-index: 1501;
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 4px;
  padding: 9px 12px; font-family: var(--mono); font-size: 0.78rem; color: var(--paper-dim);
  max-width: 260px; text-align: right;
}
#mapStyleUnlockPrompt.hidden { display: none; }
#mapStyleUnlockPrompt a { color: var(--amber); text-decoration: none; }
#mapStyleUnlockPrompt a:hover { text-decoration: underline; }

#tripLoadingOverlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: 'Barlow Condensed', sans-serif; font-size: 1.4rem; letter-spacing: 0.05em;
  text-transform: uppercase; color: #8a99a0;
  background: radial-gradient(circle at 50% 40%, rgba(20,28,30,0.92), rgba(8,10,10,0.97));
  z-index: 5000;
}
#tripLoadingOverlay.hidden { display: none; }

.deleted-trip-card {
  width: min(420px, 86vw);
  border: 1px dashed var(--panel-edge);
  border-radius: 4px;
  padding: 36px 30px;
  text-align: center;
  background: rgba(17,22,26,0.6);
}
.deleted-trip-card p {
  color: var(--paper-dim); font-size: 0.95rem; line-height: 1.6; margin: 0 0 20px;
}

#playHintOverlay {
  position: absolute; inset: 0; z-index: 2000;
  background: rgba(5,8,8,0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  cursor: pointer;
}
#playHintOverlay.hidden { display: none; }
#playHintOverlay p {
  font-family: var(--display); text-transform: uppercase; color: var(--paper);
  font-size: 1.3rem; letter-spacing: 0.03em; line-height: 1.4; margin: 0; text-align: center;
  max-width: 480px;
}
#playHintOverlay .amber { color: var(--amber); }

.tape-right-simple { display: flex; align-items: center; gap: 10px; }

.amber-cta {
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--amber); color: #1a1200;
  font-family: var(--mono); font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.03em;
  padding: 8px 16px; border-radius: 4px; border: none; cursor: pointer;
}
.amber-cta:hover { background: #ffc158; }

#signOutBtn, #signUpLink {
  background: none; border: 1px solid var(--cyan); color: var(--cyan);
  font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 6px 12px; border-radius: 4px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
#signOutBtn:hover, #signUpLink:hover { background: var(--cyan); color: #0a1a1a; }

#dropzone .card {
  width: min(480px, 86vw);
  border: 1px dashed var(--panel-edge);
  border-radius: 4px;
  padding: 36px 30px;
  text-align: center;
  background: rgba(17,22,26,0.6);
}

#dropzone .card.drag {
  border-color: var(--amber);
  background: rgba(255,176,46,0.06);
}

#dropzone h1 {
  font-family: var(--display);
  font-size: 28px;
  letter-spacing: 0.5px;
  color: var(--paper);
  margin: 0 0 6px;
  text-transform: uppercase;
}

#dropzone h1 span { color: var(--amber); }

#dropzone p {
  font-size: 12px;
  color: var(--paper-dim);
  line-height: 1.6;
  margin: 0 0 20px;
}

#dropzone .formats {
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--paper-dim);
  text-transform: uppercase;
  margin-bottom: 20px;
}

#dropzone .formats code {
  color: var(--cyan);
  background: rgba(79,217,212,0.08);
  padding: 1px 5px;
  border-radius: 2px;
}

#fileBtn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--amber);
  color: #1a1206;
  border: none;
  padding: 11px 22px;
  border-radius: 2px;
  cursor: pointer;
  font-weight: 700;
}

#fileBtn:hover { background: #ffc266; }

#dropzone .error {
  margin-top: 14px;
  font-size: 11px;
  color: var(--danger);
  min-height: 14px;
}

#uploadProgress {
  /* Sits inside #dropCard normally (hidden). When .showing is added by
     setProgress(), it becomes a fixed centred overlay above everything. */
}

#uploadProgress.showing {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  width: min(400px, 88vw);
  display: block !important;  /* override .hidden */
}

#uploadProgressBox {
  background: var(--panel);
  border: 1px solid var(--cyan);
  border-radius: 6px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 0 32px rgba(79,217,212,0.15), 0 8px 32px rgba(0,0,0,0.6);
}

#uploadProgressLabel {
  font-size: 11px;
  color: var(--paper-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

#uploadProgressNote {
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--amber);
  line-height: 1.4;
  min-height: 1.2em;
}

#uploadProgressBar, .uploadProgressBar {
  width: 100%;
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

#uploadProgressFill, .uploadProgressFill {
  height: 100%;
  background: var(--cyan);
  border-radius: 2px;
  transition: width 0.15s ease;
  width: 0%;
}

@keyframes progressPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}
  50%       { opacity: 0.4; }
}

#mergeProgress, #trimProgress {
  margin-top: 14px;
  width: 100%;
}

#mergeProgressLabel, #trimProgressLabel {
  font-size: 11px;
  color: var(--paper-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

#fileInput { display: none; }

/* ---------- HUD telemetry overlay ---------- */

#hud {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 800;
  background: rgba(10,14,13,0.72);
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  padding: 12px 16px;
  pointer-events: none;
  backdrop-filter: blur(2px);
  min-width: 200px;
}

#hud.hidden { display: none; }

/* ---------- Stats panel ---------- */

#statsPanel {
  min-width: 230px;
  max-width: 280px;
  max-height: 60vh;
  overflow-y: auto;
}

.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  font-size: 11px;
  color: var(--paper-dim);
  letter-spacing: 0.3px;
}

.stat b {
  color: var(--paper);
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
}

.stats-subtitle {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--panel-edge);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--paper-dim);
  margin-bottom: 8px;
}

.stats-days {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.stats-day-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--paper-dim);
}

.stats-day-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stats-day-label {
  color: var(--paper);
  min-width: 52px;
}

.stats-day-val {
  color: var(--paper-dim);
  font-size: 10px;
  margin-left: auto;
  text-align: right;
}

.stats-empty {
  font-size: 11px;
  color: var(--paper-dim);
}

#hud .row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  font-size: 11px;
  color: var(--paper-dim);
  letter-spacing: 0.5px;
  margin-top: 3px;
}

#hud .row b { color: var(--paper); font-weight: 500; }

#hud .timestamp {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--panel-edge);
  font-size: 11px;
  color: var(--cyan);
  letter-spacing: 0.5px;
}

/* ---------- Transport controls ---------- */

#transport {
  background: var(--panel);
  border-top: 1px solid var(--panel-edge);
  padding: 10px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#transport.disabled { display: none; }

#scrubRow {
  display: flex;
  align-items: center;
  gap: 12px;
}

#scrub {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--panel-edge);
  border-radius: 2px;
  outline: none;
}

#scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--amber);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(255,176,46,0.18);
}

#scrub::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: none;
  border-radius: 50%;
  background: var(--amber);
  cursor: pointer;
}

.timecode {
  font-size: 12px;
  color: var(--paper-dim);
  min-width: 62px;
  text-align: center;
  letter-spacing: 0.5px;
}

#controlsRow {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 10px;
}

/* Explicit order for every item in the left-anchored group, so the
   sequence is unambiguous rather than relying on DOM position (which
   playbackSettings' children only inherit via display:contents) —
   speed/camera-follow/smooth-pointer/reveal-route stay anchored right
   next to play regardless of window width, with the icon style picker
   pushed to the far right via margin-left: auto. */
#controlsRow .btn-group { order: 1; }
#controlsRow .dropdown-wrap { order: 2; }
#controlsRow #statsDropdownWrap { order: 3; }
#controlsRow #settingsDropdownWrap { order: 4; }

.btn-group {
  display: flex;
  gap: 6px;
}

.iconbtn {
  background: #161d22;
  border: 1px solid var(--panel-edge);
  color: var(--paper);
  width: 38px;
  height: 38px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}

.iconbtn:hover { border-color: var(--cyan); color: var(--cyan); }

#replayBtn {
  width: 46px; height: 46px;
}
#replayBtn svg { width: 18px; height: 18px; }

.iconbtn.primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #1a1206;
  width: 46px;
  height: 46px;
}

.iconbtn.primary:hover { background: #ffc266; border-color: #ffc266; color: #1a1206; }

.iconbtn svg { width: 16px; height: 16px; }
.iconbtn.primary svg { width: 18px; height: 18px; }

/* Opens upward instead of the header dropdown's default downward — this
   sits at the bottom of the screen, so there's no room to open below it. */
.dropdown-panel-up {
  top: auto; bottom: 100%; margin-top: 0; margin-bottom: 6px;
  left: 0; right: auto;
}

.speedbtn {
  background: none;
  border: none;
  color: var(--paper-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  border-radius: 3px;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.speedbtn:hover {
  background: rgba(255,255,255,0.04);
  color: var(--paper);
}

.speedbtn.active {
  background: rgba(79,217,212,0.1);
  color: var(--cyan);
}

.rate-input {
  width: 150px;
  background: #161d22;
  border: 1px solid var(--panel-edge);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 8px;
  border-radius: 3px;
}

.rate-input:focus {
  outline: none;
  border-color: var(--cyan);
}

.rate-input::placeholder { color: var(--paper-dim); }

/* Hide native spinner arrows for a cleaner look */
.rate-input::-webkit-outer-spin-button,
.rate-input::-webkit-inner-spin-button { opacity: 0.5; }

#followToggle,
#smoothToggle,
#revealToggle,
#splitDaysToggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--paper-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  user-select: none;
}

#followToggle input,
#smoothToggle input,
#revealToggle input,
#splitDaysToggle input { accent-color: var(--cyan); }

/* ---------- Settings dropdown sections ---------- */

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 6px;
  margin-top: 6px;
  border-top: 1px solid var(--panel-edge);
}
#trimSection #trimButtonGroup {
  flex-direction: column;
  border: none;
}
#trimSection #trimButtonGroup .segbtn {
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  text-align: center;
}
#trimSection #trimButtonGroup .segbtn + .segbtn {
  margin-top: 4px;
}

.settings-section-label {
  font-size: 10px;
  color: var(--paper-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 6px;
}
#playbackSettings #iconStyleGroup, #playbackSettings #unitGroup {
  width: 100%;
}
#playbackSettings #iconStyleGroup .segbtn, #playbackSettings #unitGroup .segbtn {
  flex: 1;
  text-align: center;
}

/* ---------- Day jump list ---------- */

#dayColoursSection {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#dayRow {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.daybtn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--paper-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  border-radius: 3px;
  cursor: pointer;
  flex: 1;
  text-align: left;
}

.daybtn:hover { background: rgba(255,255,255,0.04); color: var(--paper); }

.daybtn-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--amber);
  color: #1a1206;
  font-weight: 700;
  font-size: 10px;
  flex-shrink: 0;
}

.day-group {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.day-swatch {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1px solid var(--panel-edge);
  border-radius: 50%;
  padding: 0;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

.day-swatch::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
.day-swatch::-webkit-color-swatch { border: none; border-radius: 50%; }
.day-swatch::-moz-color-swatch { border: none; border-radius: 50%; }

@media (max-width: 640px) {
  #hud { left: 10px; top: auto; bottom: 10px; min-width: 140px; padding: 8px 11px; }
  #hud .row:has(#hudLat), #hud .row:has(#hudLon) { display: none; }
  .tape-right { justify-content: flex-end; }

  /* Settings/speed/day triggers sit in the bottom controls row, near the
     bottom of the screen — opening downward would push the panel below
     the visible viewport, forcing a scroll. Open upward instead.

     These use position:fixed rather than absolute — #transport has its
     own overflow-y:auto (for tall footers), and per the CSS spec, an
     ancestor with overflow other than visible clips ANY descendant that
     extends beyond its bounds, position:absolute and high z-index
     notwithstanding. Fixed positioning is anchored to the viewport
     itself, so it's never subject to that clipping at all. */
  .panel-trigger { display: inline-flex; }
  #playbackSettings, #speedGroup, #statsPanel {
    position: fixed; bottom: 80px; left: 12px; right: 12px; z-index: 5000;
    max-height: 40vh; overflow-y: auto;
    background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 4px;
    padding: 10px; box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  }
  #playbackSettings label, #playbackSettings .settings-section, #playbackSettings #dayColoursSection { width: 100%; }

  #mapControlsRow { position: relative; gap: 8px; }
  .segbtn { padding: 5px 7px; font-size: 9px; }

  /* The header and footer both grow with wrapped content on a narrow
     screen — without a floor on the map area, a tall footer (lots of
     controls wrapping to several rows) can squeeze #stage down to almost
     nothing. Guarantee the map keeps a real minimum share of the screen,
     and let the footer scroll within itself instead. */
  #stage { min-height: 38vh; min-height: 38dvh; }
  #transport { max-height: 42vh; max-height: 42dvh; overflow-y: auto; }
  html, body { overflow-y: auto; overflow-x: hidden; } /* defensive fallback — #transport's own scroll is the primary mechanism, this just ensures nothing can ever become permanently unreachable */

  /* Trip name hidden on mobile -- brand stays as a simple row matching
     the My Trips/Tools header style. */
  /* When a trip is loaded, switch the brand to a column so the trip name
     can appear below the logo — matching the old behaviour the user liked.
     Sub "new trip" hides in this state since the trip name takes its place.
     When no trip is loaded the brand stays as a simple row, matching My Trips. */
  #tape.trip-loaded .brand { flex-direction: column; align-items: flex-start; gap: 2px; }
  #tape.trip-loaded .brand .mark { font-size: 14px; }
  #tape.trip-loaded .brand .sub { display: none; }
  #tape.trip-loaded .brand .trip-name { display: block; font-size: 15px; margin-left: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100vw - 130px); }
  #tape .rec { max-width: 140px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex-shrink: 1; }
  #tape .rec #recLabel { overflow: hidden; text-overflow: ellipsis; }

  /* topRightControls now only holds the map-style buttons (Stats moved to
     the footer) — still constrain/wrap the group so it can't push past
     the viewport width on narrow screens. */
  #topRightControls { flex-wrap: wrap; max-width: calc(100vw - 32px); justify-content: flex-end; }
  #mapStyleGroup { height: auto; }
  #mapStyleGroup .segbtn { padding: 5px 8px; font-size: 8px; }
}

@media (max-width: 400px) {
  /* Very narrow phones need one more notch down. */
  #dropzone h1 { font-size: 22px; }
  #dropzone .card { padding: 28px 18px; }
  .statsbtn, #createOwnLink { font-size: 9px; padding: 6px 8px; }
}

/* Generic hidden utility — placed last so it wins the cascade over any
   earlier display rule for the same element (e.g. .statsbtn's display:flex).
   The one-off #id.hidden rules above predate this and are now redundant
   but harmless. */
.hidden { display: none !important; }

/* ---------- About modal (injected by about.js) ---------- */
/* z-index is intentionally high (5000+) — Leaflet's own internal panes and
   controls go up to z-index 1000 (see node_modules/leaflet/dist/leaflet.css),
   and neither #app, #stage, nor #map establishes its own isolated stacking
   context, so anything meant to sit above the map needs to clear that bar.
   #dropzone (z-index 1200) is the existing precedent for this in this file. */

#aboutOverlay {
  position: fixed; inset: 0; z-index: 5001;
  background: rgba(5,8,8,0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
#aboutOverlay.hidden { display: none; }

#aboutModal {
  position: relative;
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 6px;
  max-width: 440px; width: 100%; padding: 28px 24px 22px;
  font-family: var(--mono); color: var(--paper);
}
#aboutModal h2 {
  font-family: var(--display); text-transform: uppercase; color: var(--amber);
  font-size: 1.3rem; margin: 0 0 12px;
}
#aboutModal h3 {
  font-family: var(--display); text-transform: uppercase; color: var(--paper-dim);
  font-size: 0.9rem; margin: 22px 0 10px; letter-spacing: 0.03em;
}
#aboutModal p { font-size: 0.88rem; line-height: 1.5; color: var(--paper-dim); margin: 0; }

#aboutCloseBtn, #shareSuccessCloseBtn, #nameTripCloseBtn, #genericSignInCloseBtn {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--paper-dim);
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 4px;
}
#aboutCloseBtn:hover, #shareSuccessCloseBtn:hover, #nameTripCloseBtn:hover, #genericSignInCloseBtn:hover { color: var(--paper); }

#shareLinkRow { display: flex; gap: 8px; margin-top: 18px; }
#shareLinkInput, #genericSignInEmail {
  flex: 1; min-width: 0;
  background: #0d1113; border: 1px solid var(--panel-edge); color: var(--paper);
  font-family: var(--mono); font-size: 0.82rem; padding: 9px 10px; border-radius: 4px;
}
#copyLinkBtn {
  background: var(--amber); color: #1a1200; border: none;
  font-family: var(--mono); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 9px 16px; border-radius: 4px; cursor: pointer; white-space: nowrap;
}
#copyLinkBtn:hover { background: #ffc158; }
#shareQuickLinks { display: flex; gap: 8px; margin-top: 12px; }
#shareQuickLinks a {
  flex: 1; text-align: center; text-decoration: none;
  background: none; border: 1px solid var(--panel-edge); color: var(--paper-dim);
  font-family: var(--mono); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 9px 16px; border-radius: 4px;
}

#nameTripActions { display: flex; gap: 8px; margin-top: 18px; }
#nameTripActions button { flex: 1; justify-content: center; }
#nameTripInput {
  width: 100%; background: #0d1113; border: 1px solid var(--panel-edge); color: var(--paper);
  font-family: var(--mono); font-size: 0.85rem; padding: 9px 11px; border-radius: 4px;
  box-sizing: border-box;
}
#shareQuickLinks a:hover { color: var(--paper); border-color: var(--paper-dim); }

#feedbackForm { display: flex; flex-direction: column; gap: 8px; }
#feedbackMessage, #feedbackEmail {
  width: 100%; background: #0d1113; border: 1px solid var(--panel-edge); color: var(--paper);
  font-family: var(--mono); font-size: 0.85rem; padding: 9px 11px; border-radius: 4px;
  box-sizing: border-box; resize: vertical;
}
#feedbackSubmitBtn {
  align-self: flex-start;
  background: var(--amber); color: #1a1200; border: none;
  font-family: var(--display); font-weight: 700; font-size: 0.9rem; text-transform: uppercase;
  padding: 12px 24px; border-radius: 4px; cursor: pointer;
}
#feedbackSubmitBtn:disabled { opacity: 0.5; cursor: default; }
#feedbackMsg { font-size: 0.8rem; }

#aboutPrivacyLink {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--panel-edge);
  font-size: 0.8rem; text-align: center;
}
#aboutPrivacyLink a { color: var(--paper-dim); }
#aboutPrivacyLink a:hover { color: var(--cyan); }
#feedbackMsg.ok { color: #7fdd8f; }
#feedbackMsg.error { color: var(--danger); }

/* ---------- Tips button + modal (injected by tips.js) ---------- */
#tipsOverlay {
  position: fixed; inset: 0; z-index: 5001;
  background: rgba(5,8,8,0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
#tipsOverlay.hidden { display: none; }

#tipsModal {
  position: relative;
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 6px;
  max-width: 480px; width: 100%; padding: 28px 24px 22px;
  font-family: var(--mono); color: var(--paper);
  max-height: 80vh; overflow-y: auto;
}
#tipsModal h2 {
  font-family: var(--display); text-transform: uppercase; color: var(--amber);
  font-size: 1.3rem; margin: 0 0 12px;
}
#tipsModal h3 {
  font-family: var(--display); text-transform: uppercase; color: var(--paper-dim);
  font-size: 0.85rem; margin: 20px 0 8px; letter-spacing: 0.03em;
}
#tipsModal h3:first-of-type { margin-top: 0; }

#tipsCloseBtn {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--paper-dim);
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 4px;
}
#tipsCloseBtn:hover { color: var(--paper); }

.tips-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.tips-table td { padding: 5px 0; vertical-align: top; }
.tips-table td:first-child { color: var(--cyan); white-space: nowrap; padding-right: 14px; width: 1%; }
.tips-table td:last-child { color: var(--paper-dim); line-height: 1.4; }
.tips-table kbd {
  background: #0d1113; border: 1px solid var(--panel-edge); border-radius: 3px;
  padding: 2px 7px; font-family: var(--mono); font-size: 0.8rem; color: var(--paper);
}

/* ============================================================
   Elevation Profile Chart
   ============================================================ */
#elevationPanel {
  position: relative;
  height: 72px;
  background: var(--panel);
  border-top: 1px solid var(--panel-edge);
  flex-shrink: 0;
  cursor: crosshair;
}
#elevationChart {
  width: 100%; height: 100%; display: block;
}
#elevCursor {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: rgba(255,176,46,0.85);
  pointer-events: none; display: none;
  box-shadow: 0 0 4px rgba(255,176,46,0.4);
}
#elevationTooltip {
  position: absolute; top: 4px; left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.3px;
  color: var(--paper-dim); pointer-events: none; white-space: nowrap;
}

/* ============================================================
   Speed Heatmap
   ============================================================ */
/* #heatmapBtn inherits .segbtn sizing — active uses amber to match segbtn pattern */
#heatmapBtn.active {
  background: var(--amber); color: #1a1200; font-weight: 700;
}
/* Speed heatmap legend — inline below the map controls, not floating on map */
#heatmapLegendRow {
  background: rgba(10,14,13,0.88); border: 1px solid var(--panel-edge);
  border-radius: 3px; padding: 5px 10px;
  font-family: var(--mono); font-size: 9px; color: var(--paper-dim);
  white-space: nowrap; min-width: 140px;
}
#heatmapLegendRow .legend-bar {
  height: 5px; border-radius: 2px; margin-bottom: 4px;
  background: linear-gradient(to right, #4fd9d4, #ffb02e, #e05555);
}
#heatmapLegendRow .legend-labels {
  display: flex; justify-content: space-between;
}

/* ============================================================
   Embed modal
   ============================================================ */
#embedModal {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(5,8,8,0.8);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#embedModal.hidden { display: none; }
#embedBox {
  background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: 6px; padding: 28px 24px; max-width: 560px; width: 100%;
  font-family: var(--mono);
}
#embedBox h2 {
  font-family: var(--display); text-transform: uppercase; color: var(--amber);
  font-size: 1.2rem; margin: 0 0 8px;
}
#embedBox p { font-size: 0.82rem; color: var(--paper-dim); margin: 0 0 16px; }
#embedCode {
  width: 100%; background: #0d1113; border: 1px solid var(--panel-edge);
  color: var(--cyan); font-family: var(--mono); font-size: 0.75rem;
  padding: 10px; border-radius: 4px; resize: none; height: 72px;
  box-sizing: border-box;
}
#embedCopyBtn {
  margin-top: 10px; background: var(--amber); color: #1a1200;
  border: none; font-family: var(--mono); font-size: 0.8rem;
  text-transform: uppercase; padding: 8px 18px; border-radius: 4px; cursor: pointer;
}
#embedCopyBtn:hover { background: #ffc158; }
#embedCloseBtn {
  float: right; background: none; border: none; color: var(--paper-dim);
  font-size: 1.4rem; cursor: pointer; padding: 0; margin-top: -4px;
}
#embedPreviewLink { margin-top: 12px; font-size: 0.78rem; }
#embedPreviewLink a { color: var(--cyan); text-decoration: none; }
#embedPreviewLink a:hover { text-decoration: underline; }

/* ── Cookie consent banner ────────────────────────────────────────── */
#cookieConsentBanner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center; gap: 16px;
  flex-wrap: wrap; background: var(--panel); border-top: 1px solid var(--panel-edge);
  padding: 12px 20px; font-family: var(--mono);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.4);
}
#cookieConsentBanner p {
  margin: 0; font-size: 0.78rem; color: var(--paper-dim); max-width: 640px;
}
#cookieConsentBanner a { color: var(--cyan); }
#cookieConsentBanner .cookieConsentButtons { display: flex; gap: 10px; }
#cookieConsentBanner button {
  background: var(--amber); color: #1a1200; border: none;
  font-family: var(--mono); font-size: 0.78rem; text-transform: uppercase;
  padding: 8px 20px; border-radius: 4px; cursor: pointer; white-space: nowrap;
}
#cookieConsentBanner button:hover { background: #ffc158; }
#cookieConsentBanner button.secondary {
  background: none; border: 1px solid var(--panel-edge); color: var(--paper-dim);
}
#cookieConsentBanner button.secondary:hover { border-color: var(--danger); color: var(--danger); background: none; }
