/* ==========================================================================
   fast. — ultra routes in 3D
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg:            #0d1015;
  --glass:         rgba(13, 16, 21, 0.80);
  --glass-strong:  rgba(13, 16, 21, 0.92);
  --line:          rgba(255, 255, 255, 0.09);
  --line-strong:   rgba(255, 255, 255, 0.16);
  --text:          #eef1f5;
  --text-2:        #aab3c0;
  --text-3:        #737d8c;
  --accent:        #ff5a36;   /* set per route from js/routes.js */

  --radius: 14px;
  --panel-w: 324px;
  --profile-h: 176px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100dvh;
}

button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }

/* --------------------------------------------------------------------------
   Map stage
   -------------------------------------------------------------------------- */

.stage { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #1a2230; }

/* --------------------------------------------------------------------------
   Side panel
   -------------------------------------------------------------------------- */

.panel {
  position: absolute;
  top: 14px;
  left: 14px;
  width: var(--panel-w);
  max-height: calc(100% - 28px);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  scrollbar-width: thin;
}

.panel-head { display: flex; align-items: baseline; gap: 10px; }
.brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-decoration: none;
}
.brand span { color: var(--accent); transition: color .4s; }
.tagline {
  margin: 0;
  color: var(--text-3);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* route switcher */
.route-tabs { display: flex; flex-direction: column; gap: 5px; }
.route-tab {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px 8px 18px;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: background .15s, border-color .15s;
}
.route-tab::before {
  content: "";
  position: absolute;
  left: 6px; top: 9px; bottom: 9px;
  width: 3px;
  border-radius: 2px;
  background: var(--tab-color, var(--accent));
  opacity: 0.35;
  transition: opacity .15s;
}
.route-tab:hover { background: rgba(255, 255, 255, 0.07); }
.route-tab.is-active {
  background: rgba(255, 255, 255, 0.10);
  border-color: var(--line-strong);
}
.route-tab.is-active::before { opacity: 1; }
.tab-name { font-weight: 650; font-size: 14px; white-space: nowrap; }
.tab-sub { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-tab.is-active .tab-sub { color: var(--text-2); }

/* route info */
.route-info h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -0.015em;
}
.route-place { margin: 2px 0 12px; color: var(--text-2); font-size: 13px; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin: 0;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.stats > div { padding: 9px 12px; background: rgba(18, 22, 29, 0.9); }
.stats dt {
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.stats dd {
  margin: 1px 0 0;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.stats dd small { font-size: 12px; font-weight: 500; color: var(--text-2); margin-left: 2px; }

.route-blurb { margin: 12px 0 0; color: var(--text-2); font-size: 13px; }

/* controls */
.controls { display: flex; flex-direction: column; gap: 8px; }
.control-row { display: flex; gap: 6px; align-items: center; }

.btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 600;
  transition: background .15s, transform .05s;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: transparent;
  background: var(--accent);
  color: #111;
  transition: background .4s, filter .15s;
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn-primary .ico { font-size: 11px; }
.btn-square { width: 40px; padding: 0; font-variant-numeric: tabular-nums; }

.seg {
  flex: 1;
  display: flex;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}
.seg-btn {
  flex: 1;
  height: 28px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
}
.seg-btn.is-active { background: rgba(255, 255, 255, 0.14); color: var(--text); }

.slider-row { justify-content: space-between; gap: 12px; color: var(--text-2); font-size: 13px; }
.slider-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.slider-row input { flex: 1; max-width: 170px; accent-color: var(--accent); }

.panel-foot { color: var(--text-3); font-size: 11.5px; }
.panel-foot a { color: var(--text-2); }

button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* loading pill */
.loading {
  position: absolute;
  left: 50%; bottom: 18px;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  pointer-events: none;
}
.loading[hidden] { display: none; }
.loading.is-error { color: #ffb4a6; }
.loading.is-error .spinner { display: none; }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   Elevation profile
   -------------------------------------------------------------------------- */

.profile {
  position: relative;
  height: calc(var(--profile-h) + env(safe-area-inset-bottom, 0px));
  padding: 8px 14px calc(6px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.profile-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 0 2px 2px;
}
.profile-title {
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.profile-readout {
  color: var(--text-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-readout b { color: var(--text); font-weight: 650; }
.profile-readout .up { color: #ff8f6b; }
.profile-readout .down { color: #6bc5ff; }
#profile-canvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* --------------------------------------------------------------------------
   Map markers + tooltip
   -------------------------------------------------------------------------- */

.mk {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  pointer-events: none;
}
.mk-label {
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.mk-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #111;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
}
/* minor waypoints (cols, refuges, refreshment points) appear once zoomed in */
.mk-minor { display: none; }
.show-minor .mk-minor { display: flex; }
.mk-minor .mk-label { font-size: 10.5px; font-weight: 500; padding: 1px 6px; background: rgba(13, 16, 21, 0.78); }
.mk-minor .mk-dot { width: 7px; height: 7px; border-width: 1.5px; }
.mk-col .mk-label { color: #d7f5d0; }
.mk-base .mk-label { border-color: var(--accent); }
.mk-start .mk-label { background: var(--accent); color: #111; border-color: transparent; font-weight: 700; }
.mk-start .mk-dot { width: 13px; height: 13px; background: var(--accent); border-color: #fff; }

.maplibregl-popup.tip { pointer-events: none; }
.maplibregl-popup.tip .maplibregl-popup-content {
  padding: 4px 9px;
  border-radius: 7px;
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font: 600 12px/1.4 var(--font);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
.maplibregl-popup.tip .maplibregl-popup-tip { display: none; }

.maplibregl-ctrl-attrib { font-size: 10.5px; }

/* --------------------------------------------------------------------------
   Small screens: panel becomes a compact top bar
   -------------------------------------------------------------------------- */

@media (max-width: 760px) {
  :root { --profile-h: 128px; }

  .panel {
    top: 0; left: 0; right: 0;
    width: auto;
    max-height: none;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 10px;
    gap: 8px;
    border-radius: 0 0 var(--radius) var(--radius);
    border-width: 0 0 1px;
  }
  .panel-head { gap: 8px; }
  .brand { font-size: 18px; }
  .tagline { font-size: 10.5px; }

  .route-tabs { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .route-tabs::-webkit-scrollbar { display: none; }
  .route-tab { flex: 1 0 auto; padding: 7px 12px; justify-content: center; }
  .route-tab::before { display: none; }
  .route-tab.is-active { border-color: var(--tab-color, var(--accent)); }
  .tab-sub { display: none; }

  .route-info h1, .route-place, .route-blurb, .panel-foot, .slider-row { display: none; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stats > div { padding: 5px 8px; }
  .stats dt { font-size: 9.5px; letter-spacing: 0.04em; white-space: nowrap; }
  .stats dd { font-size: 14px; }
  .stats dd small { font-size: 10px; }

  .controls { flex-direction: row; }
  .controls .control-row:first-child { flex: 1.4; }
  .controls .control-row { flex: 1; }
  .btn { height: 34px; }
  .btn-square { width: 36px; }
  #fly-label { font-size: 13px; }

  .maplibregl-ctrl-top-right { display: none; }
  .profile { padding-left: 8px; padding-right: 8px; }
  .profile-readout { font-size: 12px; }
}

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