:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e2e0db;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --chip: #f0eee9;
  --r1: #e4572e;
  --r2: #2e86ab;
  --r3: #7b4fb0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --panel: #1b1b1e;
    --ink: #ededf0;
    --muted: #a0a0a8;
    --line: #2e2e33;
    --chip: #26262b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* beats display:flex on .field */
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-columns: 380px 1fr;
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#map { height: 100%; min-height: 300px; }

.brand h1 { margin: 0; }
/* Logo colours: rust and dark brown on light, amber and white on dark (from the Route 56 logo design). */
.logo { --logo-pin: #B5361F; --logo-ink: #3B2A1E; --logo-sub: #6B5444; --logo-acc: #B5361F; line-height: 0; }
.logo svg { width: 100%; max-width: 280px; height: auto; display: block; }
.logo text { font-family: 'Bebas Neue', Impact, 'Arial Narrow', sans-serif; }
.logo .pin { fill: var(--logo-pin); }
.logo .hole { fill: var(--panel); }
.logo .dial { stroke: var(--logo-ink); }
.logo .acc-stroke { stroke: var(--logo-acc); }
.logo .ink { fill: var(--logo-ink); }
.logo .acc { fill: var(--logo-acc); }
.logo .sub { fill: var(--logo-sub); }
@media (prefers-color-scheme: dark) {
  .logo { --logo-pin: #F2B233; --logo-ink: #ffffff; --logo-sub: #bdbdbd; --logo-acc: #F2B233; }
}

.field { display: flex; flex-direction: column; gap: 6px; position: relative; min-width: 0; }
.field > span { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 12px; }
.field strong { color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type=search], select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
.scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.search { display: flex; gap: 6px; }
.search input { flex: 1; min-width: 0; }

button {
  font: inherit;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--ink);
  cursor: pointer;
}
button:hover { filter: brightness(0.97); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; flex: 1; }
button:disabled { opacity: 0.6; cursor: progress; }
.actions { display: flex; gap: 8px; }

.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 8px; }
.seg button.on { background: var(--panel); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg.small button { padding: 5px; }

.suggest {
  position: absolute; z-index: 1000; top: 100%; left: 0; right: 0;
  margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
}
.suggest li { padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.suggest li:hover { background: var(--chip); }

.avoid { border: 0; padding: 0; margin: 0; flex-direction: row; flex-wrap: wrap; gap: 6px 14px; }
.avoid legend { font-weight: 600; padding: 0; margin-bottom: 6px; width: 100%; }
.avoid label { display: flex; align-items: center; gap: 5px; }

.status { margin: 0; color: var(--muted); min-height: 1.4em; }
.status.error { color: #c62828; }
.progress { height: 4px; background: var(--chip); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.progress div { height: 100%; background: var(--accent); transition: width .3s; }

.results { display: flex; flex-direction: column; gap: 10px; }
.card {
  border: 1px solid var(--line); border-left: 5px solid var(--c);
  border-radius: 10px; padding: 12px; cursor: pointer;
}
.card.on { box-shadow: 0 0 0 2px var(--c); }
.card h3 { margin: 0 0 2px; font-size: 16px; display: flex; justify-content: space-between; align-items: baseline; }
.card .fun { font-size: 13px; color: var(--muted); font-weight: 500; }
.card .fun b { font-size: 18px; color: var(--ink); }
.card .meta { color: var(--muted); margin-bottom: 8px; }
.card ul { margin: 0 0 10px; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.card li { background: var(--chip); border-radius: 6px; padding: 3px 7px; font-size: 12px; }
.card .btns { display: flex; gap: 6px; }
.card .btns button { padding: 6px 10px; font-size: 13px; }

.legend { font-size: 12px; color: var(--muted); }
.foot { margin-top: auto; font-size: 11.5px; color: var(--muted); }
.foot a { color: inherit; }

@media (max-width: 760px) {
  /* Let the page grow with its content so the pinned map below can stay stuck to the top. */
  body { grid-template-columns: 1fr; grid-template-rows: 45vh auto; height: auto; min-height: 100%; }
  /* The map stays pinned at the top while the rider scrolls the route cards. */
  #map { grid-row: 1; position: sticky; top: 0; z-index: 5; height: 45vh; }
  .panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); overflow: visible; padding: 16px; }
}

/* ---------- Navigation mode ---------- */
body.navigating { grid-template-columns: 1fr; grid-template-rows: 1fr; }
body.navigating .panel { display: none; }
body.navigating #map { grid-row: 1; height: 100vh; height: 100dvh; }

.navmap { position: fixed; inset: 0; z-index: 1001; background: #e9e5dc; }
.navmap[hidden] { display: none; }
.navmap .maplibregl-ctrl-bottom-right { bottom: 150px; }
.nav { position: fixed; inset: 0; pointer-events: none; z-index: 1002; display: flex; flex-direction: column; justify-content: space-between; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
.nav[hidden] { display: none; }
.nav > * { pointer-events: auto; }

.nav-top {
  display: flex; align-items: center; gap: 14px;
  background: #14532d; color: #fff;
  border-radius: 16px; padding: 14px 18px;
  box-shadow: 0 6px 24px rgba(0,0,0,.3);
  max-width: 560px; width: 100%; align-self: center;
}
.nav-icon { width: 64px; height: 64px; flex: none; color: #fff; }
.nav-icon:empty { display: none; }
.nav-icon svg { width: 100%; height: 100%; }
.nav-text { min-width: 0; }
.nav-dist { font-size: 34px; font-weight: 700; line-height: 1.05; }
.nav-dist:empty { display: none; }
.nav-title { font-size: 20px; font-weight: 600; }
.nav-sub { font-size: 14px; opacity: .85; }
.nav-sub:empty { display: none; }

.nav-recenter {
  align-self: flex-end; margin-top: auto; margin-bottom: 10px;
  background: var(--panel); color: var(--ink); font-weight: 600;
  border-radius: 999px; padding: 10px 16px; box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.nav-recenter[hidden] { display: none; }

.nav-bottom {
  background: var(--panel); color: var(--ink);
  border-radius: 16px; padding: 12px 14px;
  box-shadow: 0 -2px 20px rgba(0,0,0,.25);
  max-width: 560px; width: 100%; align-self: center;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 10px;
}
.nav-eta { font-size: 24px; font-weight: 700; color: #15803d; }
.nav-label { color: var(--muted); }
.nav-left { color: var(--muted); }
.nav-btns { display: flex; gap: 4px; align-items: center; }
.nav-btns button { padding: 7px 9px; font-size: 13px; white-space: nowrap; }
.nav-btns .end { padding: 9px 16px; font-size: 15px; }
body.navigating .leaflet-control-zoom { display: none; }
@media (max-width: 480px) {
  .nav-top { padding: 10px 14px; gap: 10px; }
  .nav-icon { width: 52px; height: 52px; }
  .nav-dist { font-size: 28px; }
  .nav-title { font-size: 18px; }
  .nav-bottom { padding: 10px 12px; }
  .nav-eta { font-size: 20px; }
}
.nav-btns .end { background: #c62828; border-color: #c62828; color: #fff; font-weight: 600; }

.me { background: none; border: 0; }
.me-icon { width: 52px; height: 52px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.45)); }
.me-icon svg { width: 100%; height: 100%; display: block; }

.card .btns .ride { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---------- Places along the route ---------- */
.card .places { font-size: 13px; color: var(--muted); margin: -2px 0 10px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card .places .warn { color: #c62828; font-weight: 600; }
.poi {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-size: 15px; background: #fff; border: 2px solid #555; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.poi-fuel { border-color: #1e6bd6; }
.poi-biker { border-color: #e4572e; width: 32px; height: 32px; font-size: 17px; }
.poi-cafe { border-color: #8d6e63; width: 24px; height: 24px; font-size: 13px; }
.poi-camera { border-color: #c62828; }

.nav-cam {
  align-self: center; margin-top: 8px; padding: 8px 14px; border-radius: 999px;
  background: #c62828; color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: 0 3px 12px rgba(0,0,0,.3);
}
.nav-next { color: var(--muted); font-size: 13px; margin-top: 2px; }
.nav-next:empty { display: none; }

.card .incidents { color: var(--ink); }
.poi-incident { border-color: #f59e0b; width: 30px; height: 30px; }
.poi-incident.closed { border-color: #c62828; background: #fee2e2; }
.nav-incident { background: #b45309; }

/* ---------- Rider settings ---------- */
.settings { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; gap: 12px; }
.settings summary { font-weight: 600; cursor: pointer; }
.settings[open] summary { margin-bottom: 4px; }
.settings .check { display: flex; gap: 8px; align-items: center; }
.marker-preview { display: inline-block; width: 22px; height: 22px; vertical-align: middle; margin-right: 4px; }
.marker-preview svg { width: 100%; height: 100%; }
.seg [data-marker] { display: flex; align-items: center; justify-content: center; }
.swatches { display: flex; gap: 10px; }
.swatches button { width: 30px; height: 30px; padding: 0; border-radius: 50%; background: var(--sw); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--line); }
.swatches button.on { box-shadow: 0 0 0 2px var(--ink); }

/* Speed limit sign and current speed while riding */
.nav-speed { position: absolute; left: 12px; bottom: 150px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.nav-speed[hidden] { display: none; }
.limit-sign { width: 58px; height: 58px; border-radius: 50%; background: #fff; border: 7px solid #d32f2f; display: grid; place-items: center; font: 700 22px/1 -apple-system, sans-serif; color: #111; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.limit-sign[hidden] { display: none; }
.my-speed { min-width: 58px; padding: 4px 8px; border-radius: 10px; background: var(--panel); color: var(--ink); text-align: center; font: 700 18px/1.1 -apple-system, sans-serif; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.my-speed small { display: block; font-size: 10px; font-weight: 500; color: var(--muted); }
.my-speed.over { background: #d32f2f; color: #fff; }
.my-speed.over small { color: #fff; }

.card li.warn { background: #fde2e2; color: #b71c1c; }
.card .fav { color: var(--accent); font-weight: 600; }

/* ---------- Rating window ---------- */
.rate { border: 0; border-radius: 16px; padding: 20px; width: min(92vw, 420px); background: var(--panel); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.rate::backdrop { background: rgba(0,0,0,.45); }
.rate h2 { margin: 0 0 12px; font-size: 20px; }
.stars { display: flex; gap: 8px; justify-content: center; }
.stars button { width: 52px; height: 52px; font-size: 28px; line-height: 1; border-radius: 12px; color: #c9c4b8; background: var(--chip); border-color: var(--line); }
.stars button.on { color: #F2B233; border-color: #F2B233; background: #fff6df; }
.stars .zero { font-size: 18px; font-weight: 700; }
.stars .zero.on { color: #c62828; border-color: #c62828; background: #fde2e2; }
.rate-label { text-align: center; margin: 8px 0 12px; font-weight: 600; min-height: 1.4em; }
.rate textarea { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; resize: vertical; }
.rate-small { font-size: 12px; color: var(--muted); margin: 8px 0 12px; }
.card .community { color: var(--ink); font-weight: 600; }
.card .community b { color: #d99a0b; }

.hint { margin: 0; color: var(--muted); font-size: 13px; }
.builder { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.builder label { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.stop-pin { background: #141414; color: #F2B233; font: 700 12px/1 sans-serif; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; border: 2px solid #F2B233; box-shadow: 0 1px 4px rgba(0,0,0,.4); transform: translate(-50%, -50%); }

/* ---------- Rider reports while riding ---------- */
.nav-report {
  position: absolute; right: 12px; bottom: 160px; width: 72px; height: 72px; border-radius: 50%;
  background: #F2B233; color: #141414; border: 3px solid #141414; font-size: 26px; line-height: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.nav-report span { font-size: 11px; font-weight: 700; }
.report-sheet {
  position: absolute; left: 12px; right: 12px; bottom: 12px; max-width: 560px; margin: 0 auto;
  background: var(--panel); color: var(--ink); border-radius: 18px; padding: 14px; box-shadow: 0 -4px 24px rgba(0,0,0,.4); z-index: 3;
}
.report-sheet[hidden] { display: none; }
.report-sheet p { margin: 0 0 10px; font-weight: 700; text-align: center; }
.report-sheet small { font-weight: 400; color: var(--muted); }
.report-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.report-grid button {
  height: 92px; font-size: 34px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: var(--chip); border: 2px solid var(--line);
}
.report-grid button span { font-size: 14px; font-weight: 700; }
.report-grid .cancel { font-size: 24px; color: var(--muted); }
.nav-report-alert { background: #6d28d9; }
.nav-still {
  align-self: center; margin-top: 8px; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px;
  background: var(--panel); color: var(--ink); border-radius: 999px; box-shadow: 0 3px 12px rgba(0,0,0,.3); font-weight: 600;
}
.nav-still[hidden] { display: none; }
.nav-still button { width: 52px; height: 44px; font-size: 22px; border-radius: 999px; }
.poi-report { border-color: #6d28d9; width: 30px; height: 30px; }

/* ---------- Back on time ---------- */
.nav-backby { font-size: 13px; font-weight: 700; color: #15803d; margin-top: 2px; }
.nav-backby.late { color: #c62828; }
.nav-late {
  align-self: center; margin-top: 8px; max-width: 520px; width: 100%;
  background: var(--panel); color: var(--ink); border-radius: 14px; padding: 12px 14px;
  box-shadow: 0 4px 18px rgba(0,0,0,.35); border-left: 6px solid #c62828;
}
.nav-late[hidden] { display: none; }
.nav-late p { margin: 0 0 10px; font-weight: 600; }
.nav-late div { display: flex; gap: 8px; }
.nav-late button { flex: 1; padding: 12px; font-size: 15px; }
.nav-late .primary { background: #15803d; border-color: #15803d; color: #fff; font-weight: 700; }
.card .spare { color: #15803d; font-weight: 600; }
.card .late { color: #c62828; font-weight: 700; }
