/* ==========================================================================
   Taiwan Bike Map — frosted glass UI
   Translucent layered surfaces over an ambient tint, iOS-style depth.
   Every selector app.js and index.html rely on is defined here.
   ========================================================================== */

:root {
  /* Type ----------------------------------------------------------------
     System stack, no webfont request: the app is a PWA that has to paint
     instantly on a phone with bad signal. On Windows 11 this resolves to
     Segoe UI Variable (Display cut for headings, Text cut for body), on
     Apple to SF Pro, with Noto Sans TC / PingFang TC carrying the Chinese. */
  --font-display: "Segoe UI Variable Display", -apple-system, BlinkMacSystemFont,
    "SF Pro Display", system-ui, "Segoe UI", Roboto, "Noto Sans TC",
    "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-ui: "Segoe UI Variable Text", -apple-system, BlinkMacSystemFont,
    "SF Pro Text", system-ui, "Segoe UI", Roboto, "Noto Sans TC",
    "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-num: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Variable Text",
    monospace;

  /* Ink */
  --ink: #0b1220;
  --ink-soft: #3f4b5f;
  --ink-muted: #7c8899;

  /* Accent */
  --accent: #0a84ff;
  --accent-deep: #0060df;
  --accent-alt: #5e5ce6;

  /* Semantic */
  --good: #0f9d58;
  --warn: #e8890c;
  --bad: #e5484d;

  /* Glass surfaces */
  --glass: rgba(255, 255, 255, 0.62);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --glass-quiet: rgba(255, 255, 255, 0.42);
  --glass-edge: rgba(255, 255, 255, 0.75);
  --hairline: rgba(11, 18, 32, 0.08);
  --hairline-soft: rgba(11, 18, 32, 0.05);
  --blur: saturate(180%) blur(20px);

  /* Depth */
  --lift-1: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px -10px rgba(16, 24, 40, 0.14);
  --lift-2: 0 2px 6px rgba(16, 24, 40, 0.06), 0 24px 56px -16px rgba(16, 24, 40, 0.26);
  --lift-accent: 0 6px 18px -6px rgba(10, 132, 255, 0.55);

  /* Geometry */
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-pill: 999px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--ink);
  background: #eef1f7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { overflow: hidden; }

/* Ambient wash. Glass needs something behind it or it reads as flat grey. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(52rem 42rem at 8% -6%, rgba(10, 132, 255, 0.20), transparent 60%),
    radial-gradient(44rem 38rem at 96% 8%, rgba(94, 92, 230, 0.18), transparent 62%),
    radial-gradient(40rem 36rem at 24% 104%, rgba(14, 165, 200, 0.16), transparent 60%),
    linear-gradient(180deg, #f6f8fc 0%, #eaeef6 100%);
}

h1, h2, p { margin: 0; }

h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

h2 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

p {
  margin-top: 3px;
  color: var(--ink-muted);
  font-size: 12px;
  line-height: 1.4;
}

a {
  color: var(--accent-deep);
  font-weight: 600;
  text-decoration: none;
}

a:hover { text-decoration: underline; }

button, input, select { font: inherit; }

/* ---------------------------------------------------------------- layout */

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

#map {
  grid-column: 2;
  width: 100%;
  height: 100vh;
  min-height: 100vh;
  touch-action: pan-x pan-y;
}

.panel {
  grid-column: 1;
  height: 100vh;
  padding: 18px 16px calc(24px + var(--safe-bottom));
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--glass-quiet);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-right: 1px solid var(--hairline);
  box-shadow: var(--lift-2);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* --------------------------------------------------------- glass surfaces */

.section-card,
.summary-card,
.status-card,
.report-box,
#liveGpsHud {
  position: relative;
  background: var(--glass);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--lift-1);
}

/* Top highlight — the thing that sells a surface as glass rather than paint. */
.section-card::before,
.summary-card::before,
#liveGpsHud::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: linear-gradient(90deg, transparent, var(--glass-edge) 22%, var(--glass-edge) 78%, transparent);
  pointer-events: none;
}


.section-card,
.summary-card,
.status-card {
  padding: 13px 14px;
  margin-bottom: 9px;
}

/* ----------------------------------------------------------- brand + head */

.brand-row,
.top-line,
.quick-route-row {
  display: flex;
  align-items: center;
  gap: 11px;
}

.section-title {
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

/* ------------------------------------------------------ inputs + buttons */

input,
select {
  width: 100%;
  padding: 12px 13px;
  font-size: 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input::placeholder { color: #9aa5b4; }

input:focus,
select:focus {
  background: #fff;
  border-color: rgba(10, 132, 255, 0.6);
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.14);
}

label {
  display: block;
  margin: 12px 0 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

button {
  width: 100%;
  padding: 12px 13px;
  font-size: 15px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  cursor: pointer;
}

.plate-pill,
.locate-btn,
.go-btn,
.secondary-btn,
#saveReportBtn {
  border: 0;
  font-weight: 650;
  cursor: pointer;
}

.plate-pill {
  width: auto;
  max-width: 190px;
  padding: 10px 17px;
  border-radius: var(--r-pill);
  white-space: nowrap;
  color: #fff;
  background: linear-gradient(140deg, #1b2333, #0b1220);
  box-shadow: 0 8px 20px -8px rgba(11, 18, 32, 0.7);
}

.locate-btn {
  width: auto;
  min-width: 88px;
  padding: 10px 14px;
  border-radius: var(--r-pill);
  color: var(--accent-deep);
  background: rgba(10, 132, 255, 0.10);
  border: 1px solid rgba(10, 132, 255, 0.22);
}

.locate-btn:hover { background: rgba(10, 132, 255, 0.16); }

.quick-route-row input { flex: 1; min-width: 0; }

.go-btn {
  width: 76px;
  min-width: 76px;
  border-radius: var(--r-md);
  color: #fff;
  letter-spacing: 0.01em;
  background: linear-gradient(140deg, var(--accent), var(--accent-alt));
  box-shadow: var(--lift-accent);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.go-btn:hover { box-shadow: 0 10px 24px -6px rgba(10, 132, 255, 0.65); }
.go-btn:active { transform: scale(0.97); }

.secondary-btn,
#saveReportBtn {
  margin-top: 10px;
  color: #fff;
  border-radius: var(--r-md);
  background: linear-gradient(140deg, #263045, #0b1220);
  box-shadow: 0 6px 16px -8px rgba(11, 18, 32, 0.8);
}

/* ------------------------------------------------------------------ chips */

.bike-chip-row,
.toggle-grid,
.summary-grid {
  display: grid;
  gap: 8px;
}

/* One row of four, not a 2x2 block of tall pills. The CC band sits inside the
   chip, which is exactly what the field underneath is asking about. */
.bike-chip-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.bike-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 8px 4px;
  border-radius: var(--r-sm);
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink-soft);
  line-height: 1.15;
  transition: transform 0.12s ease;
}

.bike-chip-main {
  font-size: 14px;
  font-weight: 700;
}

/* Inherits the chip colour so it stays legible on every plate background. */
.bike-chip-sub {
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: inherit;
  opacity: 0.62;
}

.bike-chip:active { transform: scale(0.96); }

.bike-chip.is-active {
  border-color: transparent;
  box-shadow: 0 6px 14px -6px rgba(11, 18, 32, 0.45);
}

.bike-chip.is-active .bike-chip-sub { opacity: 0.8; }

.label-hint {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-muted);
}

.toggle-chip {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 550;
}

.toggle-chip input {
  width: 21px;
  height: 21px;
  margin: 0;
  accent-color: var(--accent);
}

.toggle-chip + .toggle-chip { margin-top: 6px; }

/* The master switch for a group reads as the primary control. */
.toggle-chip-lead {
  background: rgba(10, 132, 255, 0.08);
  border-color: rgba(10, 132, 255, 0.22);
  color: var(--ink);
  font-weight: 650;
}

/* Detail that only matters once its master switch is on. */
.setting-group {
  margin: 8px 0 4px;
  padding: 10px 0 2px 12px;
  border-left: 2px solid var(--hairline);
}

.setting-group[hidden] { display: none; }
.setting-group > label:first-child { margin-top: 0; }

/* ---------------------------------------------------------- status stack */

.status-stack {
  display: grid;
  gap: 2px;
  margin-bottom: 10px;
  padding: 3px 2px;
}

.state-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 6px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.42;
  color: var(--ink);
}

.state-line-muted {
  font-weight: 500;
  color: var(--ink-muted);
}

.state-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: #c3cbd8;
  box-shadow: 0 0 0 3px rgba(195, 203, 216, 0.22);
}

.state-line[data-state="good"] { color: #0a6b3d; }
.state-line[data-state="warn"] { color: #9a5b02; }
.state-line[data-state="bad"]  { color: #b02328; }

.state-line[data-state="good"] .state-dot { background: var(--good); box-shadow: 0 0 0 3px rgba(15, 157, 88, 0.18); }
.state-line[data-state="warn"] .state-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(232, 137, 12, 0.20); }
.state-line[data-state="bad"]  .state-dot { background: var(--bad);  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.20); }
.state-line[data-state="busy"] .state-dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.20); animation: pulse 1.15s ease-in-out infinite; }

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

/* ------------------------------------------------------- score + summary */

.summary-score-card.is-empty { display: none; }

.summary-box {
  display: none;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-soft);
}

/* Distance and time - the only route figures not shown elsewhere. */
.route-figures {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.route-figure-sep {
  color: var(--ink-muted);
  font-weight: 400;
}

.summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 11px;
}

.summary-pill {
  padding: 9px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--hairline-soft);
  background: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- collapsibles */

.collapse-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 1px 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 620;
  letter-spacing: -0.005em;
}

.collapse-toggle:hover { color: var(--ink); }

.collapse-indicator {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--ink-muted);
  transition: transform 0.2s ease;
}

.collapsible-section .collapse-body,
.collapsible-section .warnings { display: none; }

.collapsible-section.is-open .collapse-body,
.collapsible-section.is-open .warnings {
  display: block;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--hairline-soft);
}

.collapsible-section.is-open .collapse-indicator { transform: rotate(180deg); }

.warnings:empty { display: none !important; }

/* ----------------------------------------------------------- panel tabs */

.panel-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  margin-bottom: 9px;
  padding: 3px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.panel-tab {
  width: 100%;
  padding: 9px 6px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--ink-muted);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.panel-tab:hover { color: var(--ink-soft); }

.panel-tab.is-active {
  color: #fff;
  background: linear-gradient(140deg, #1b2333, #0b1220);
  box-shadow: 0 6px 14px -6px rgba(11, 18, 32, 0.6);
}

.panel-pane { display: none; }
.panel-pane.is-active { display: block; }

/* First control in a pane should not push away from the pane's own padding. */
.panel-pane > label:first-child { margin-top: 0; }

/* ------------------------------------------------------------- warnings */

.warnings {
  display: grid;
  gap: 6px;
}

/* Counts first, so a long list reads as "12 cameras, 1 restriction" at a
   glance instead of making the rider count rows. */
.warn-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 2px;
}

.warn-pill {
  padding: 4px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline-soft);
  background: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.warn-pill-bad {
  border-color: rgba(229, 72, 77, 0.3);
  background: rgba(229, 72, 77, 0.1);
  color: #b02328;
}

.warn-pill-warn {
  border-color: rgba(232, 137, 12, 0.3);
  background: rgba(232, 137, 12, 0.1);
  color: #9a5b02;
}

/* Left accent bar instead of a full tinted card: reads as a list of alerts
   rather than a stack of competing boxes. */
.warning-item {
  padding: 8px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--hairline-soft);
  border-left: 3px solid var(--warn);
  background: rgba(255, 255, 255, 0.62);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-soft);
}

/* An illegal route is the one thing that must never be truncated. */
.warning-item.is-blocking {
  border-left-color: var(--bad);
  background: rgba(229, 72, 77, 0.08);
  color: #b02328;
  font-weight: 600;
}

.warning-item.is-overflow { display: none; }
.warnings.show-all .warning-item.is-overflow { display: block; }

.warn-more {
  width: 100%;
  padding: 8px 10px;
  border: 1px dashed var(--hairline);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.warn-more:hover {
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.5);
}

/* --------------------------------------------------------- notes + misc */

.mini-note {
  margin-top: 7px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-muted);
}

.note {
  padding: 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline-soft);
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink-soft);
  font-size: 11.5px;
  line-height: 1.6;
}

.links-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.report-box {
  display: none;
  margin-top: 12px;
  padding: 13px;
  border-radius: var(--r-md);
  background: rgba(10, 132, 255, 0.06);
  border: 1px solid rgba(10, 132, 255, 0.16);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* -------------------------------------------------- map overlay controls */

.map-overlay {
  position: absolute;
  top: 14px;
  left: 414px;
  right: 14px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}


/* === Map furniture =====================================================
   Search on the map, not buried in a panel; a round action button bottom
   right. This is the arrangement people already know from every map app,
   so there is nothing to learn.
   ====================================================================== */

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0 6px 0 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--lift-2);
  pointer-events: auto;
}

.search-icon {
  flex: 0 0 auto;
  font-size: 15px;
  opacity: 0.55;
}

.search-bar input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 16px;
  box-shadow: none;
}

.search-bar input:focus {
  border: 0;
  box-shadow: none;
  background: transparent;
}

/* Safari renders its own clear affordance on type=search; ours is styled. */
.search-bar input::-webkit-search-decoration,
.search-bar input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-clear {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-muted);
  font-size: 15px;
  cursor: pointer;
}

.search-clear[hidden] { display: none; }
.search-clear:hover { background: rgba(11, 18, 32, 0.06); }

/* --- Sheet peek ---------------------------------------------------------
   The row that stays visible when the sheet is collapsed: which plate you
   are riding, what the route is doing, and a locate button. */
.sheet-peek {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: 2px 14px 12px;
}

.sheet-peek .state-line {
  flex: 1;
  min-width: 0;
  padding: 0;
}

.sheet-peek .state-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-peek .plate-pill {
  flex: 0 0 auto;
  max-width: 96px;
  padding: 9px 14px;
  font-size: 13.5px;
}

.sheet-peek .locate-btn {
  flex: 0 0 auto;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 17px;
}


/* ---- Camera alert ------------------------------------------------------
   Replaces a permanent "Camera: --" row inside the ride card. Appears only
   within 800 m of a camera that is relevant to your plate and heading. */
.camera-alert {
  display: flex;
  align-items: center;
  gap: 9px;
  align-self: flex-start;
  max-width: 100%;
  padding: 9px 15px 9px 12px;
  border-radius: var(--r-pill);
  border: 1px solid rgba(232, 137, 12, 0.35);
  background: rgba(255, 247, 237, 0.96);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: #9a5b02;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  box-shadow: var(--lift-1);
  pointer-events: auto;
}

.camera-alert[hidden] { display: none; }

.camera-alert-icon { font-size: 15px; }

.camera-alert.is-close {
  border-color: transparent;
  background: var(--bad);
  color: #fff;
}

/* ---- Map controls ------------------------------------------------------ */
.map-control {
  position: fixed;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: var(--accent-deep);
  font-size: 20px;
  box-shadow: var(--lift-1);
  cursor: pointer;
}

.map-control[hidden] { display: none; }

/* Sits above the ride button, out of the sheet's way. */
#liveRecenterBtn {
  right: 16px;
  bottom: calc(84px + var(--safe-bottom));
}


/* ---- Ride history ------------------------------------------------------ */
.ride-history { display: grid; gap: 7px; }

.ride-card {
  padding: 11px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--hairline-soft);
  background: rgba(255, 255, 255, 0.62);
  cursor: pointer;
}

.ride-card:hover { background: rgba(255, 255, 255, 0.85); }

.ride-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.ride-when {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

.ride-card-actions { display: flex; gap: 2px; }

.ride-action {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-muted);
  font-size: 12px;
  cursor: pointer;
}

.ride-action:hover { background: rgba(11, 18, 32, 0.06); color: var(--ink); }
.ride-delete:hover { background: rgba(229, 72, 77, 0.12); color: var(--bad); }

.ride-figures {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.ride-figure b {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.ride-top b { color: var(--accent-deep); }

/* ---- Turn banner -------------------------------------------------------
   The only turn guidance used to be spoken, and off by default, so a rider
   with the phone on silent had no idea where to turn. */
.nav-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 100%;
  padding: 11px 16px 11px 13px;
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: #fff;
  box-shadow: var(--lift-2);
  pointer-events: auto;
}

.nav-banner[hidden] { display: none; }

.nav-banner-icon {
  flex: 0 0 auto;
  font-size: 27px;
  line-height: 1;
}

.nav-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.nav-banner-distance {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* The street name can be long; one line with an ellipsis beats wrapping the
   banner to three lines over the map. */
.nav-banner-detail {
  overflow: hidden;
  font-size: 11.5px;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.7);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-banner.is-imminent {
  background: linear-gradient(140deg, var(--accent), var(--accent-deep));
  border-color: transparent;
}

.nav-banner.is-imminent .nav-banner-detail { color: rgba(255, 255, 255, 0.82); }

.layer-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: auto;
}

.layer-chip {
  width: auto;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: var(--ink-muted);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--lift-1);
  transition: background 0.16s ease, color 0.16s ease, transform 0.12s ease;
}

.layer-chip:active { transform: scale(0.96); }

.layer-chip.is-on {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(140deg, #1b2333, #0b1220);
  box-shadow: 0 8px 20px -8px rgba(11, 18, 32, 0.75);
}

.map-hint {
  padding: 8px 14px;
  border-radius: var(--r-pill);
  background: rgba(11, 18, 32, 0.84);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: #fff;
  font-size: 12px;
  font-weight: 550;
  pointer-events: auto;
  box-shadow: var(--lift-1);
}

.map-hint[hidden] { display: none; }

.ride-fab {
  position: fixed;
  right: 16px;
  bottom: calc(20px + var(--safe-bottom));
  z-index: 7;
  display: none;
  align-items: center;
  gap: 9px;
  width: auto;
  padding: 15px 22px;
  border: 0;
  border-radius: var(--r-pill);
  color: #fff;
  font-size: 15px;
  font-weight: 650;
  background: linear-gradient(140deg, var(--accent), var(--accent-alt));
  box-shadow: var(--lift-accent), var(--lift-2);
  cursor: pointer;
}

.ride-fab-icon { font-size: 13px; }

.ride-fab.is-active {
  background: linear-gradient(140deg, #ff5a5f, #c9252b);
  box-shadow: 0 8px 22px -6px rgba(201, 37, 43, 0.6), var(--lift-2);
}

/* ------------------------------------------------------------------- HUD */

#liveGpsHud {
  display: flex;
  align-items: baseline;
  gap: 5px;
  width: auto !important;
  padding: 9px 15px !important;
  border-radius: var(--r-pill) !important;
  background: rgba(11, 18, 32, 0.9) !important;
  color: #fff;
  font-family: var(--font-ui);
  box-shadow: var(--lift-2) !important;
  pointer-events: auto;
}

.hud-title {
  margin-bottom: 5px;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.hud-network {
  margin-bottom: 7px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--good);
}

.hud-speed {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.hud-unit {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.6);
}

.hud-meta {
  margin-bottom: 6px;
  font-size: 11.5px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.hud-button {
  width: 100%;
  margin-top: 5px;
  padding: 10px;
  border: 0;
  border-radius: var(--r-pill);
  background: linear-gradient(140deg, var(--accent), var(--accent-alt));
  color: #fff;
  font-size: 12px;
  font-weight: 650;
  box-shadow: var(--lift-accent);
}

/* -------------------------------------------------- map info windows */

.camera-chip {
  display: inline-block;
  margin-bottom: 6px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: #0b1220;
  color: #fff;
  font-size: 11px;
  font-weight: 650;
}

.camera-enforcement {
  display: inline-block;
  margin: 4px 4px 4px 0;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  background: rgba(10, 132, 255, 0.12);
  color: var(--accent-deep);
  font-size: 11.5px;
  font-weight: 600;
}

.camera-meta {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--hairline);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.camera-approx-note {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(232, 137, 12, 0.28);
  background: rgba(232, 137, 12, 0.10);
  color: #9a5b02;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.5;
}

.camera-correction-btn {
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--r-pill);
  background: #0b1220;
  color: #fff;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.camera-correction-btn:hover { filter: brightness(1.15); }

.vote-row {
  display: flex;
  gap: 7px;
  margin-top: 8px;
}

.vote-row button {
  padding: 7px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline);
  background: #fff;
  font-size: 12px;
  font-weight: 600;
}

/* -------------------------------------------------------- sheet chrome */

.sheet-handle { display: none; }

.sheet-window,
.sheet-summary,
.sheet-body { display: block; }

/* ==========================================================================
   Phone: map on top, panel below.
   ========================================================================== */

@media (max-width: 768px) {
  /* ======================================================================
     Phone: a full-height map with a draggable sheet over it.

     Previously the map was 56dvh at the top of a scrolling page with the
     panel below it in normal flow, so scrolling to read a warning scrolled
     the map off screen entirely - while the speed HUD and ride button, both
     position:fixed, stayed pinned over the panel.

     app.js has always set .is-collapsed / .is-half / .is-full on the panel
     and shipped a grab handle, but no rule consumed them. Those states are
     now what actually drives the sheet.
     ====================================================================== */

  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app {
    display: block;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  #map {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    max-height: none;
    z-index: 1;
  }

  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 94dvh;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    border-right: 0;
    border-top: 1px solid var(--hairline);
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -16px 44px -12px rgba(16, 24, 40, 0.3);
    transform: translateY(var(--sheet-offset, 62dvh));
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  }

  /* While a finger is down the offset is written inline, frame by frame. */
  .panel.is-dragging { transition: none; }

  /* Collapsed shows the handle, the plate/locate row and the destination
     field - everything needed to start a route - and nothing else.

     One source of truth: the sheet, the ride button and app.js's drag
     snapping all read this. It has to clear the handle (30) plus the search
     card (padding 32 + plate row 44 + gap 12 + input row 46) plus its margin,
     or the Go button is cut off by the bottom of the screen. */
  /* Handle (30) + peek row (~58) + breathing room. The search bar moved
     onto the map, so the sheet no longer has to show it. */
  :root { --sheet-peek: 104px; }

  .panel.is-collapsed { --sheet-offset: calc(94dvh - var(--sheet-peek)); }
  .panel.is-half { --sheet-offset: 46dvh; }
  .panel.is-full { --sheet-offset: 0dvh; }

  /* Only the lower section scrolls; the handle and search card stay put. */
  .sheet-window {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 0 12px calc(28px + var(--safe-bottom));
  }

  .sheet-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 100%;
    /* Tall enough to grab reliably; the visible bar is much smaller. */
    height: 30px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    touch-action: none;
    cursor: grab;
  }

  .sheet-handle:active { cursor: grabbing; }

  .sheet-handle-bar {
    width: 40px;
    height: 5px;
    border-radius: var(--r-pill);
    background: rgba(124, 136, 153, 0.55);
  }

  .sheet-handle-label { display: none; }

  /* Map controls sit above the collapsed sheet, not under it. */
  .map-overlay {
    top: calc(10px + var(--safe-top));
    left: 10px;
    right: 10px;
    gap: 9px;
    z-index: 3;
  }

  .layer-chip-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
    max-width: 100%;
  }

  .layer-chip-row::-webkit-scrollbar { display: none; }

  /* 44px minimum touch target. */
  .layer-chip {
    min-height: 44px;
    padding: 11px 15px;
    font-size: 13px;
  }

  .ride-fab {
    display: flex;
    right: 12px;
    left: auto;
    bottom: calc(14px + var(--sheet-peek) + var(--safe-bottom));
    z-index: 3;
    padding: 13px 20px;
    min-height: 48px;
    transition: bottom 0.3s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease;
  }

  /* One start control per viewport. The floating button is the phone's, so
     the HUD's duplicate is hidden there; desktop has no floating button and
     keeps the HUD button. */
  #liveFollowBtn { display: none; }

  /* Out of the way once the sheet is opened over it. Keyed off <body>
     because the button precedes .panel in the DOM, so a sibling selector
     from the panel cannot reach it. */
  body.sheet-half .ride-fab,
  body.sheet-full .ride-fab {
    opacity: 0;
    pointer-events: none;
  }

  /* Same reason: dim the map controls once the sheet covers the map. */
  body.sheet-full .map-overlay,
  body.sheet-full .map-control,
  body.sheet-full #liveGpsHud {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  /* Bottom-left, clear of the sheet, the ride button and the alerts. */
  #liveGpsHud {
    position: fixed !important;
    top: auto !important;
    left: 12px !important;
    right: auto !important;
    bottom: calc(14px + var(--sheet-peek) + var(--safe-bottom)) !important;
    padding: 8px 13px !important;
    z-index: 3 !important;
  }

  #liveRecenterBtn {
    right: 12px;
    bottom: calc(74px + var(--sheet-peek) + var(--safe-bottom));
  }

  .camera-alert { font-size: 12.5px; padding: 8px 13px 8px 11px; }

  .hud-speed { font-size: 23px; }
  .hud-unit { font-size: 10px; }


  /* Comfortable thumb targets throughout the sheet. */
  .plate-pill { max-width: 168px; min-height: 44px; padding: 11px 16px; font-size: 14px; }
  .locate-btn { min-width: 84px; min-height: 44px; padding: 11px 12px; font-size: 14px; }
  .go-btn { min-height: 46px; }
  .panel input, .panel select { min-height: 46px; font-size: 16px; }
  .panel-tab { min-height: 44px; }
  .bike-chip { min-height: 48px; }
  .collapse-toggle { min-height: 40px; }
  .toggle-chip { min-height: 46px; }

  .toggle-grid { grid-template-columns: 1fr; }
}

/* Small phones. This block used to carry `#map { height: 52dvh }` and a
   stacked search row from the old scrolling layout. Because 390px is exactly
   the width of a standard iPhone, and this rule comes after the phone block,
   it silently overrode the full-height map - leaving a grey band between the
   map and the sheet, and pushing the Go button out of the collapsed peek. */
@media (max-width: 390px) {
  .sheet-window { padding-left: 10px; padding-right: 10px; }
  .layer-chip { padding: 11px 13px; font-size: 12.5px; }
  .plate-pill { max-width: 150px; font-size: 13.5px; }
  .locate-btn { min-width: 76px; font-size: 13.5px; }
  .go-btn { width: 68px; min-width: 68px; }
}

/* ==========================================================================
   Desktop: fixed sidebar beside a full-height map.
   ========================================================================== */

@media (min-width: 769px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app {
    display: grid;
    grid-template-columns: 400px minmax(0, 1fr);
    grid-template-rows: 100vh;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
  }

  .panel {
    grid-column: 1;
    grid-row: 1;
    position: relative;
    display: block;
    width: 400px;
    min-width: 400px;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    visibility: visible;
    opacity: 1;
    z-index: 20;
  }

  .panel > *,
  .panel   .panel .sheet-window,
  .panel .sheet-summary,
  .panel .sheet-body,
  .panel .section-card,
  .panel .summary-card {
    position: static;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
  }

  #map {
    grid-column: 2;
    grid-row: 1;
    position: relative;
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    z-index: 1;
  }

  .sheet-handle { display: none; }

  .sheet-window,
  .sheet-summary,
  .sheet-body {
    transform: none;
    max-height: none;
    overflow: visible;
    padding: 0;
  }

  #liveGpsHud {
    position: fixed !important;
    right: 22px !important;
    bottom: 22px !important;
    top: auto !important;
    z-index: 30 !important;
  }
}

/* Panel scrollbar, desktop only. */
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: var(--r-pill);
  background-clip: padding-box;
  background-color: rgba(124, 136, 153, 0.34);
}
.panel::-webkit-scrollbar-thumb:hover { background-color: rgba(124, 136, 153, 0.55); }

/* Browsers without backdrop-filter get solid surfaces instead of washed-out
   translucency. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .panel { background: rgba(255, 255, 255, 0.92); }
    .section-card,
  .summary-card,
  .status-card,
  #liveGpsHud { background: rgba(255, 255, 255, 0.96); }
  .layer-chip { background: rgba(255, 255, 255, 0.96); }
}

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