/* Running Route Suggester — "topographic survey" theme.
   Palette derived from Ordnance-Survey-style maps, not generic defaults:
   map paper + dark pine rail + OS-byway magenta route line + surveyor amber. */
:root {
  --paper:   #eae4d6;
  --paper-2: #e0d9c7;
  --ink:     #182420;
  --pine:    #1e2f28;
  --pine-2:  #26382f;
  --moss:    #4a6b52;
  --route:   #b6237c;   /* selected route line */
  --route-2: #c98bb0;   /* alt route line */
  --amber:   #d98a1f;   /* technical surface / elevation fill */
  --contour: #cabfa6;
  --line:    rgba(24,36,32,.16);
  --paper-line: rgba(24,36,32,.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

/* ---- layout: control rail + map/results ---- */
.app { display: grid; grid-template-columns: 380px 1fr; height: 100vh; height: 100dvh; }

/* mobile tab bar: hidden on desktop, shown + fixed-bottom under the breakpoint below */
.tabbar { display: none; }

@media (max-width: 860px) {
  :root { --tabbar-h: 54px; }
  html, body { height: 100%; overflow: hidden; } /* only the active panel scrolls */

  .app { display: block; height: 100vh; height: 100dvh; position: relative; }
  /* .stage has no visual box of its own on mobile — its children (#map, .results)
     are promoted to act as direct, independently toggleable panels of .app.
     ".app" prefix needed here too — same equal-specificity/source-order issue
     as above (.stage's own unscoped `display: flex` rule comes later in the file). */
  .app .stage { display: contents; }

  /* ".app" prefix bumps specificity above the base (unscoped) .rail/#map/.results
     rules elsewhere in this file — without it, equal-specificity base rules that
     happen to come later in the file (e.g. .rail's own `display: flex`) win the
     cascade regardless of this media query, and the panel never actually hides. */
  .app .rail, .app #map, .app .results {
    display: none;
    height: calc(100vh - var(--tabbar-h));
    height: calc(100dvh - var(--tabbar-h));
  }
  .app[data-tab="plan"] .rail { display: flex; }
  .app[data-tab="map"] #map { display: block; }
  .app[data-tab="results"] .results { display: block; max-height: none; }

  .app .rail { overflow-y: auto; }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar-h);
    background: var(--pine); border-top: 1px solid rgba(234,228,214,.14); z-index: 1000;
  }
  .tabbar button {
    flex: 1; border: none; background: none; color: rgba(234,228,214,.6);
    font-family: "Archivo", sans-serif; font-weight: 700; font-size: 13px;
  }
  .tabbar button.on { color: var(--paper); box-shadow: inset 0 2px 0 var(--amber); }

  /* touch targets: bump below-guideline hit areas (~44px) for finger use */
  .pt-ops button { min-width: 40px; min-height: 40px; font-size: 15px; }
  .pin-btn, .go { min-height: 44px; }
  .leaflet-touch .leaflet-bar a, .leaflet-touch .locate-ctrl a { width: 40px; height: 40px; line-height: 40px; }
  .pt-marker span { width: 32px; height: 32px; }
}

@media (max-width: 420px) {
  .rail-head { padding: 20px 16px 16px; }
  .form { padding: 16px 16px 22px; }
}

/* ---- control rail ---- */
.rail {
  background: var(--pine);
  color: var(--paper);
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.rail-head {
  position: relative;
  padding: 28px 26px 22px;
  border-bottom: 1px solid rgba(234,228,214,.14);
  overflow: hidden;
}
/* signature: concentric contour rings behind the title */
.rail-head::before {
  content: ""; position: absolute; inset: -60% -20% auto auto; width: 320px; height: 320px;
  background: repeating-radial-gradient(circle at 70% 30%,
      transparent 0 13px, rgba(234,228,214,.10) 13px 14px);
  pointer-events: none;
}
.brand {
  font-family: "Archivo", sans-serif; font-weight: 800; font-size: 25px;
  letter-spacing: -.02em; line-height: 1.02; margin: 0; position: relative;
}
.brand em { color: var(--amber); font-style: normal; }
.tagline {
  font-family: "JetBrains Mono", monospace; font-size: 11px; letter-spacing: .08em;
  text-transform: uppercase; color: rgba(234,228,214,.6); margin: 8px 0 0; position: relative;
}

.form { padding: 20px 26px 30px; display: flex; flex-direction: column; gap: 20px; }
.field label {
  display: block; font-family: "JetBrains Mono", monospace; font-size: 11px;
  letter-spacing: .07em; text-transform: uppercase; color: rgba(234,228,214,.62);
  margin-bottom: 9px;
}
.coord-row { display: flex; gap: 8px; align-items: center; }
.coord-readout {
  flex: 1; font-family: "JetBrains Mono", monospace; font-size: 12.5px;
  background: var(--pine-2); border: 1px solid rgba(234,228,214,.12);
  border-radius: 7px; padding: 9px 11px; color: var(--paper); min-height: 38px;
  display: flex; align-items: center;
}
.coord-readout.empty { color: rgba(234,228,214,.4); }
.pin-btn {
  border: 1px solid rgba(234,228,214,.2); background: transparent; color: var(--paper);
  border-radius: 7px; padding: 9px 11px; cursor: pointer; font-size: 12px;
  font-family: "JetBrains Mono", monospace; white-space: nowrap;
}
.pin-btn.active { background: var(--amber); border-color: var(--amber); color: var(--ink); font-weight: 600; }

.loop-toggle { display: flex; align-items: center; gap: 9px; margin-top: 12px; }
.loop-toggle input { accent-color: var(--amber); width: 16px; height: 16px; }
.loop-toggle span { font-size: 13px; color: rgba(234,228,214,.85); }

/* distance slider */
.dist-value { font-family: "Archivo", sans-serif; font-weight: 800; font-size: 21px; color: var(--amber); }
.dist-value small { font-size: 13px; color: rgba(234,228,214,.6); font-weight: 500; }
input[type=range] { width: 100%; accent-color: var(--amber); margin-top: 6px; }

/* segmented controls */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg.wrap { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
.seg button {
  border: 1px solid rgba(234,228,214,.16); background: var(--pine-2); color: rgba(234,228,214,.82);
  border-radius: 7px; padding: 9px 6px; cursor: pointer; font-size: 12.5px;
  font-family: "Inter", sans-serif; transition: .12s;
}
.seg button:hover { border-color: rgba(234,228,214,.4); }
.seg button.on { background: var(--paper); color: var(--ink); border-color: var(--paper); font-weight: 600; }

.go {
  margin-top: 4px; width: 100%; border: none; border-radius: 8px; cursor: pointer;
  background: var(--route); color: #fff; font-family: "Archivo", sans-serif; font-weight: 700;
  font-size: 15px; letter-spacing: .01em; padding: 14px; transition: .12s;
}
.go:hover { filter: brightness(1.08); }
.go:disabled { opacity: .55; cursor: default; }

.msg {
  font-family: "JetBrains Mono", monospace; font-size: 12px; line-height: 1.5;
  color: var(--amber); background: rgba(217,138,31,.1); border: 1px solid rgba(217,138,31,.3);
  border-radius: 7px; padding: 10px 12px;
}

/* ---- stage: map + results ---- */
.stage { position: relative; display: flex; flex-direction: column; }
#map { flex: 1; min-height: 320px; background: var(--paper-2); }

.results {
  background: var(--paper); border-top: 2px solid var(--ink);
  max-height: 46%; overflow-y: auto; padding: 0;
}
.results-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 20px 8px; position: sticky; top: 0; background: var(--paper);
}
.results-head h2 {
  font-family: "Archivo", sans-serif; font-size: 15px; margin: 0; letter-spacing: -.01em;
}
.results-head span { font-family: "JetBrains Mono", monospace; font-size: 11px; color: rgba(24,36,32,.5); }

.card {
  border-top: 1px solid var(--paper-line); padding: 14px 20px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; transition: background .12s;
}
.card:hover { background: var(--paper-2); }
.card.sel { background: var(--paper-2); box-shadow: inset 4px 0 0 var(--route); }
.card-title { font-family: "Archivo", sans-serif; font-weight: 700; font-size: 15px; }
.card-title .rank { color: var(--route); }
.route-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle;
}
.card-strategy { font-family: "JetBrains Mono", monospace; font-size: 10.5px; color: rgba(24,36,32,.5); text-transform: uppercase; letter-spacing: .05em; }
.stats { font-family: "JetBrains Mono", monospace; font-size: 12px; text-align: right; color: var(--ink); }
.stats b { color: var(--moss); }

/* surface bar */
.surfbar { grid-column: 1 / -1; height: 7px; border-radius: 4px; overflow: hidden; display: flex; margin-top: 6px; background: #d8d0be; }
.surfbar i { height: 100%; display: block; }
.surfbar .paved { background: #6b7a72; }
.surfbar .unpaved { background: var(--moss); }
.surfbar .technical { background: var(--amber); }
.legend { grid-column: 1/-1; display: flex; gap: 14px; font-family: "JetBrains Mono", monospace; font-size: 10px; color: rgba(24,36,32,.6); margin-top: 2px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 4px; vertical-align: middle; }

/* elevation ridgeline (signature) */
.elev { grid-column: 1/-1; margin-top: 8px; }
.elev svg { width: 100%; height: 54px; display: block; }
.dl {
  grid-column: 1/-1; margin-top: 10px; display: inline-flex; align-self: start;
  font-family: "JetBrains Mono", monospace; font-size: 11.5px; text-decoration: none;
  color: var(--route); border: 1px solid var(--route); border-radius: 6px; padding: 5px 11px;
}
.dl:hover { background: var(--route); color: #fff; }

.empty-state {
  padding: 26px 20px; font-family: "JetBrains Mono", monospace; font-size: 12.5px;
  color: rgba(24,36,32,.55); line-height: 1.6;
}
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 7px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* "locate me" map control — inherits the Leaflet zoom-button box */
.locate-ctrl a { font-size: 18px; font-weight: 700; }

/* ---- route points list ---- */
.hint { font-size: 12px; line-height: 1.45; color: rgba(234,228,214,.55);
  margin: 0 0 9px; font-family: "Inter", sans-serif; }
.pt-list { list-style: none; margin: 0 0 9px; padding: 0;
  display: flex; flex-direction: column; gap: 5px; }
.pt-list li { display: flex; align-items: center; gap: 9px;
  background: var(--pine-2); border: 1px solid rgba(234,228,214,.12);
  border-radius: 7px; padding: 6px 8px; }
.pt-num { flex: none; width: 22px; height: 22px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font: 700 12px/1 "JetBrains Mono", monospace; }
.pt-num.start { background: var(--amber); color: var(--ink); }
.pt-num.finish { background: var(--route); }
.pt-num.via { background: var(--moss); }
.pt-co { flex: 1; font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--paper); }
.pt-co small { color: rgba(234,228,214,.45); margin-left: 5px; text-transform: uppercase;
  letter-spacing: .05em; font-size: 10px; }
.pt-ops { display: flex; gap: 2px; }
.pt-ops button { border: none; background: transparent; color: rgba(234,228,214,.7);
  cursor: pointer; font-size: 12px; padding: 2px 5px; border-radius: 5px; line-height: 1; }
.pt-ops button:hover { background: rgba(234,228,214,.12); color: var(--paper); }
.pt-ops button:disabled { opacity: .25; cursor: default; }
.pin-btn.ghost { opacity: .7; }

/* numbered draggable route-point markers on the map */
.pt-marker span { display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; color: #fff; border: 2px solid #fff;
  font: 700 13px/1 "JetBrains Mono", monospace; box-shadow: 0 1px 5px rgba(0,0,0,.45);
  cursor: grab; }

/* direction arrows along the selected route */
.route-arrow { background: none; border: none; }
.route-arrow span { display: block; width: 16px; height: 16px; font-size: 13px;
  line-height: 16px; text-align: center; color: #fff;
  text-shadow: 0 0 2px rgba(24,36,32,.95), 0 0 3px rgba(24,36,32,.7); }
