/* ==========================================================================
   Grain — granola palette on Web3 bones (greens · creams · greys)
   ========================================================================== */

:root {
  --cream:      #EAE9DF;
  --cream-deep: #D8D9CC;
  --panel:      #F3F3EB;
  --ink:        #232A24;
  --moss:       #4F7D5B;
  --fern:       #7FB08A;
  --pine:       #3E6B4C;
  --sage:       #93A38C;
  --stone:      #8E9188;

  --ink-60: rgba(35, 42, 36, 0.60);
  --ink-40: rgba(35, 42, 36, 0.40);
  --line:   rgba(35, 42, 36, 0.12);

  --glow: 0 0 0 1px rgba(79,125,91,0.35), 0 8px 30px -8px rgba(79,125,91,0.45);
  --lift: 0 18px 50px -18px rgba(35,42,36,0.45);
  --radius: 22px;
  --radius-sm: 12px;

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

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

body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 9;
  opacity: 0.05; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --------------------------------------------------------------- top bar -- */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px;
  background: linear-gradient(to bottom, rgba(234,233,223,0.92), rgba(234,233,223,0));
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand__mark {
  width: 16px; height: 16px; align-self: center; border-radius: 5px;
  background: radial-gradient(circle at 30% 30%, var(--fern), var(--moss) 70%); box-shadow: var(--glow);
}
.brand__word { font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: -0.02em; }
.brand__eyebrow {
  font-family: var(--font-mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.18em; color: var(--ink-40);
}
.topbar__actions { display: flex; align-items: center; gap: 10px; }

.unit-toggle {
  display: inline-flex; padding: 3px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(35,42,36,0.06);
}
.unit-toggle__btn {
  font-family: var(--font-mono); font-weight: 700; font-size: 13px;
  border: 0; background: transparent; color: var(--ink-60);
  padding: 7px 15px; border-radius: 999px; cursor: pointer;
  transition: background 0.18s, color 0.18s;
}
.unit-toggle__btn.is-active {
  background: linear-gradient(180deg, var(--moss), var(--pine)); color: var(--panel);
  box-shadow: 0 2px 8px -2px rgba(62,107,76,0.6);
}

.btn {
  font-family: var(--font-display); font-weight: 600; font-size: 14px;
  border-radius: 999px; padding: 10px 18px; cursor: pointer; border: 1px solid transparent;
  transition: transform 0.12s, box-shadow 0.18s, background 0.18s, opacity 0.18s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--ghost { background: var(--panel); color: var(--ink); border-color: var(--line); }
.btn--ghost:hover:not(:disabled) { background: #fff; }

/* ----------------------------------------------------------- key banner -- */
.key-banner {
  position: absolute; z-index: 40; top: 64px; left: 50%; transform: translateX(-50%);
  background: var(--pine); color: var(--panel); font-size: 13px;
  padding: 10px 16px; border-radius: 999px; box-shadow: var(--lift);
}
.key-banner code { font-family: var(--font-mono); background: rgba(255,255,255,0.18); padding: 1px 6px; border-radius: 6px; }

/* ---------------------------------------------------------------- stack -- */
.stack {
  position: absolute; z-index: 20; top: 72px; left: 20px;
  width: 372px; max-height: calc(100vh - 92px);
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}

.card {
  padding: 18px; border-radius: var(--radius);
  background: rgba(243, 243, 235, 0.85);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  border: 1px solid rgba(255,255,255,0.5);
  box-shadow: var(--lift);
}
.card__head { margin-bottom: 14px; }
.card__title { font-family: var(--font-display); font-weight: 700; font-size: 21px; letter-spacing: -0.02em; margin: 0 0 4px; }
.card__hint { margin: 0; font-size: 12px; line-height: 1.45; color: var(--ink-60); }

/* --------------------------------------------------------- waypoints ----- */
.wps { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.wp { display: flex; align-items: center; gap: 9px; }
.wp__dot {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 11px;
  background: var(--sage); color: var(--panel);
}
.wp[data-role="start"] .wp__dot { background: var(--sage); }
.wp[data-role="end"] .wp__dot { background: var(--moss); }
.wp[data-role="via"] .wp__dot { background: var(--stone); }

.wp__field { position: relative; flex: 1 1 auto; min-width: 0; }
.wp__input {
  width: 100%; padding: 9px 11px; font-family: var(--font-body); font-size: 13px; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; outline: none;
  transition: box-shadow 0.18s, border-color 0.18s;
}
.wp__input::placeholder { color: var(--ink-40); }
.wp__input:focus { border-color: var(--moss); box-shadow: 0 0 0 3px rgba(79,125,91,0.18); }

.wp__remove {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-60);
  font-size: 16px; line-height: 1; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.wp__remove:hover { background: #fff; color: var(--ink); }

.wp__move { display: flex; gap: 3px; flex: 0 0 auto; }
.wp__mv {
  width: 22px; height: 24px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-60);
  font-size: 12px; line-height: 1; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.wp__mv:hover:not(:disabled) { background: #fff; color: var(--ink); }
.wp__mv:disabled { opacity: 0.35; cursor: not-allowed; }

.wp__results {
  list-style: none; margin: 0; padding: 6px;
  position: fixed; z-index: 60; /* fixed so the panel's scroll can't clip it */
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--lift); max-height: 230px; overflow-y: auto;
}
.wp__result {
  padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.3; cursor: pointer;
  display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline;
}
.wp__result:hover, .wp__result.is-active { background: rgba(79,125,91,0.12); }
.wp__result .r-name { font-weight: 600; }
.wp__result .r-ctx { color: var(--ink-60); font-size: 12px; }
.wp__empty { padding: 8px 10px; font-size: 13px; color: var(--ink-60); }

.wp-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.chip {
  font-family: var(--font-mono); font-weight: 500; font-size: 11px; letter-spacing: 0.02em;
  padding: 7px 11px; border-radius: 999px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  transition: background 0.15s, transform 0.12s;
}
.chip:hover { background: #fff; }
.chip:active { transform: translateY(1px); }
.chip--muted { color: var(--ink-60); margin-left: auto; }

/* --------------------------------------------------------------- dials --- */
.dials { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.dial__label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 7px; }
.dial__label > span:first-child { font-family: var(--font-display); font-weight: 600; font-size: 13px; }
.dial__poles {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--ink-40);
}
.tag {
  font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--stone); border: 1px solid currentColor; border-radius: 999px; padding: 1px 6px;
}
.dial--soon { opacity: 0.55; }

/* Segmented toggle (non-continuous dials: Distance, Headwind) */
.seg {
  display: flex; gap: 3px; padding: 3px;
  background: var(--cream-deep); border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(35,42,36,0.10);
}
.seg__btn {
  flex: 1; font-family: var(--font-mono); font-weight: 700; font-size: 12px;
  border: 0; background: transparent; color: var(--ink-60);
  padding: 8px 6px; border-radius: 999px; cursor: pointer;
  transition: background 0.16s, color 0.16s;
}
.seg__btn.is-active {
  background: linear-gradient(180deg, var(--moss), var(--pine)); color: var(--panel);
  box-shadow: 0 2px 6px -2px rgba(62,107,76,0.55);
}
.seg__btn:disabled { cursor: not-allowed; }

.range {
  --fill: 50%; -webkit-appearance: none; appearance: none;
  width: 100%; height: 12px; border-radius: 999px;
  background: linear-gradient(90deg, var(--moss), var(--fern)) 0 / var(--fill) 100% no-repeat, var(--cream-deep);
  box-shadow: inset 0 1px 3px rgba(35,42,36,0.22); cursor: pointer; outline-offset: 4px;
}
.range:disabled { cursor: not-allowed; background: var(--cream-deep); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #fff, var(--panel) 55%, var(--cream) 100%);
  border: 2px solid var(--moss);
  box-shadow: 0 3px 10px -2px rgba(35,42,36,0.5), inset 0 0 0 3px rgba(79,125,91,0.15);
  transition: transform 0.12s;
}
.range::-webkit-slider-thumb:hover { transform: scale(1.08); }
.range::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #fff, var(--panel) 55%, var(--cream) 100%);
  border: 2px solid var(--moss); box-shadow: 0 3px 10px -2px rgba(35,42,36,0.5);
}
.range:focus-visible { outline: 2px solid var(--ink); }

/* ----------------------------------------------------------- route info -- */
.card--info { padding: 16px 18px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.stat { display: flex; flex-direction: column; gap: 3px; }
.stat__label {
  font-family: var(--font-mono); font-size: 9px; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--ink-40);
}
.stat__value { font-family: var(--font-mono); font-weight: 700; font-size: 19px; color: var(--ink); }

.info-msg { margin: 12px 0 0; font-size: 12px; color: var(--ink-60); }
.card--info[data-state="ok"] .info-msg { display: none; }
.card--info[data-state="routing"] .info-msg { color: var(--moss); }
.card--info[data-state="error"] .info-msg { color: var(--pine); font-weight: 500; }

.attrib { margin: 12px 0 0; font-size: 10px; color: var(--ink-40); }

/* ------------------------------------------------------------- markers --- */
.wp-marker {
  width: 30px; height: 30px; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 13px; color: var(--ink);
  background: radial-gradient(circle at 32% 28%, #fff, var(--panel));
  border: 2.5px solid var(--sage); border-radius: 50% 50% 50% 6px;
  transform: rotate(-45deg); box-shadow: 0 4px 12px -3px rgba(35,42,36,0.55); cursor: grab;
}
.wp-marker > span { transform: rotate(45deg); }
.wp-marker.is-start { border-color: var(--sage); }
.wp-marker.is-end {
  border-color: var(--pine);
  background: radial-gradient(circle at 32% 28%, var(--fern), var(--moss)); color: var(--panel);
}
.wp-marker:active { cursor: grabbing; }

/* --------------------------------------------------------------- popup --- */
.grain-popup .maplibregl-popup-content {
  background: var(--panel); border-radius: 14px; box-shadow: var(--lift);
  padding: 12px; font-family: var(--font-body); border: 1px solid rgba(255,255,255,0.6);
}
.grain-popup .maplibregl-popup-close-button { color: var(--ink-40); font-size: 16px; padding: 2px 6px; }
.grain-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--panel); }
.grain-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--panel); }
.grain-popup.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--panel); }
.grain-popup.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--panel); }
.mappop__label { font-weight: 600; font-size: 13px; margin-bottom: 2px; max-width: 210px; }
.mappop__coord { font-family: var(--font-mono); font-size: 11px; color: var(--ink-60); margin-bottom: 9px; }
.mappop__add {
  font-family: var(--font-display); font-weight: 600; font-size: 13px; color: var(--panel);
  background: linear-gradient(180deg, var(--moss), var(--pine)); border: 0; border-radius: 999px;
  padding: 8px 14px; cursor: pointer; width: 100%;
}
.mappop__add:active { transform: translateY(1px); }

.maplibregl-ctrl-group { border-radius: 12px !important; overflow: hidden; box-shadow: var(--lift) !important; }

/* --------------------------------------------------------- responsive ---- */
@media (max-width: 640px) {
  .stack {
    top: auto; bottom: 0; left: 0; right: 0; width: auto;
    max-height: 66vh; padding: 0 12px 12px;
  }
  .brand__eyebrow { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }