@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap");

:root {
  --void: #070c12;
  --panel: rgba(12, 20, 29, 0.94);
  --surface: #14212d;
  --surface-hover: #192b39;
  --hairline: rgba(181, 207, 221, 0.13);
  --text: #eef5f7;
  --muted: #8da0ad;
  --cyan: #39d0e6;
  --orange: #ff9d5c;
  --green: #54e1a6;
  --pink: #ff648d;
}

* { box-sizing: border-box; }
html, body, main, #map { width: 100%; height: 100%; margin: 0; }

body {
  min-width: 320px;
  overflow: hidden;
  background: var(--void);
  color: var(--text);
  font-family: "Manrope", system-ui, sans-serif;
}

button { font: inherit; }
#map { position: absolute; inset: 0; background: #0b141d; }
.workspace { position: relative; isolation: isolate; }

.sidebar {
  position: absolute;
  z-index: 10;
  inset: 0 auto 0 0;
  display: flex;
  width: 368px;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--hairline);
  box-shadow: 20px 0 50px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
  transition: transform 240ms ease;
}

.sidebar-header { padding: 26px 24px 20px; border-bottom: 1px solid var(--hairline); }
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; gap: 11px; align-items: center; min-width: 0; }
.brand-mark { position: relative; width: 25px; height: 25px; flex: 0 0 auto; }

.brand-mark::before, .brand-mark::after {
  position: absolute;
  content: "";
  border-radius: 999px;
  transform: rotate(-38deg);
}

.brand-mark::before {
  top: 3px;
  left: 2px;
  width: 23px;
  height: 4px;
  background: var(--cyan);
  box-shadow: 0 0 12px rgba(57, 208, 230, 0.7);
}

.brand-mark::after { right: 2px; bottom: 4px; width: 15px; height: 4px; background: var(--orange); }
.brand-name { font-size: 13px; font-weight: 700; letter-spacing: 0.01em; }
.brand-context { margin-top: 2px; color: var(--muted); font-size: 10px; }

.icon-button, .tool-button, .show-panel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hairline);
  background: rgba(16, 27, 37, 0.88);
  color: var(--text);
  cursor: pointer;
}

.icon-button { width: 32px; height: 32px; border-radius: 7px; font-size: 18px; }
.icon-button:hover, .tool-button:hover, .show-panel:hover { background: var(--surface-hover); }

.icon-button:focus-visible, .tool-button:focus-visible, .show-panel:focus-visible, .route-leg:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

h1 { max-width: 12ch; margin: 28px 0 8px; font-size: 30px; line-height: 1.06; letter-spacing: -0.045em; }
.summary { margin: 0; color: #aab9c2; font-size: 12px; line-height: 1.55; }

.metric-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 1px;
  margin-top: 20px;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--hairline);
}

.metric { min-width: 0; padding: 12px 11px; background: rgba(14, 24, 34, 0.94); }
.metric strong { display: block; font-size: 17px; line-height: 1.1; letter-spacing: -0.025em; }
.metric:first-child strong { color: var(--cyan); }
.metric span { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; }

.layer-heading { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px 11px; }
.layer-heading h2 { margin: 0; font-size: 11px; font-weight: 700; }
.layer-heading span { color: var(--muted); font-size: 10px; }

.route-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 18px;
  scrollbar-color: #334958 transparent;
  scrollbar-width: thin;
}

.route-leg {
  display: grid;
  grid-template-columns: 4px 28px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 56px;
  padding: 8px 10px 8px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.route-leg:hover { background: rgba(24, 40, 53, 0.65); }
.route-leg.is-active { border-color: rgba(57, 208, 230, 0.28); background: var(--surface); }
.leg-swatch { width: 3px; height: 31px; border-radius: 99px; box-shadow: 0 0 8px currentColor; }
.leg-number { color: #5f7381; font-size: 10px; font-weight: 700; font-variant-numeric: tabular-nums; }
.leg-name {
  display: block;
  overflow: hidden;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leg-detail {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leg-distance { color: #c4d2d9; font-size: 10px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 24px;
  border-top: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 9px;
}

.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.map-toolbar { position: absolute; z-index: 9; top: 18px; right: 18px; display: flex; gap: 8px; }

.tool-button {
  min-height: 36px;
  gap: 7px;
  padding: 0 13px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  font-size: 10px;
  font-weight: 700;
}

.tool-button[aria-pressed="true"] { border-color: rgba(57, 208, 230, 0.42); color: var(--cyan); }

.elevation-panel {
  position: absolute;
  z-index: 8;
  right: 18px;
  bottom: 18px;
  left: 386px;
  height: 188px;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: rgba(8, 15, 22, 0.91);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(14px);
  transition: left 240ms ease;
}

.elevation-panel[hidden] { display: none; }
.elevation-header { display: flex; align-items: flex-start; gap: 18px; padding: 12px 13px 2px 15px; }
.elevation-heading { min-width: 0; flex: 1; }
.elevation-kicker { color: var(--cyan); font-size: 8px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.elevation-title { overflow: hidden; margin: 2px 0 0; font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.elevation-stats { display: flex; gap: 18px; }
.elevation-stat { min-width: 58px; }
.elevation-stat span { display: block; color: var(--muted); font-size: 8px; }
.elevation-stat strong { display: block; margin-top: 2px; font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.elevation-close { flex: 0 0 auto; width: 28px; height: 28px; }
.elevation-plot { position: relative; height: 142px; padding: 2px 12px 9px; }
.elevation-chart { display: block; width: 100%; height: 100%; overflow: visible; touch-action: none; }
.elevation-grid { stroke: rgba(181, 207, 221, 0.12); stroke-width: 1; }
.elevation-axis-label { fill: #8da0ad; font: 8px "Manrope", system-ui, sans-serif; }
.elevation-area { opacity: 0.18; }
.elevation-line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.elevation-peak { stroke: #071019; stroke-width: 2; }
.elevation-guide { stroke: rgba(238, 245, 247, 0.48); stroke-width: 1; opacity: 0; pointer-events: none; }
.elevation-hover-dot { stroke: #071019; stroke-width: 2; opacity: 0; pointer-events: none; }
.elevation-tooltip {
  position: absolute;
  z-index: 2;
  top: 5px;
  padding: 5px 7px;
  border: 1px solid var(--hairline);
  border-radius: 5px;
  background: #101b25;
  color: var(--text);
  font-size: 8px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
}

.elevation-tooltip[hidden] { display: none; }
.panel-closed .elevation-panel { left: 18px; }

.show-panel {
  position: absolute;
  z-index: 9;
  top: 18px;
  left: 18px;
  display: none;
  height: 36px;
  padding: 0 13px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.22);
  font-size: 10px;
  font-weight: 700;
}

.map-caption {
  position: absolute;
  z-index: 8;
  right: 18px;
  bottom: 218px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--hairline);
  border-radius: 7px;
  background: rgba(8, 15, 22, 0.84);
  color: #9fb0ba;
  font-size: 9px;
  backdrop-filter: blur(10px);
}

.caption-line { width: 25px; border-top: 3px solid var(--cyan); box-shadow: 0 0 7px var(--cyan); }
.caption-pass { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); box-shadow: 0 0 7px rgba(255,157,92,.7); }

.map-error {
  position: absolute;
  z-index: 20;
  inset: 50% auto auto 50%;
  display: none;
  max-width: 320px;
  padding: 16px 18px;
  border: 1px solid rgba(255, 100, 141, 0.5);
  border-radius: 8px;
  background: #111b25;
  color: var(--text);
  transform: translate(-50%, -50%);
  font-size: 12px;
  line-height: 1.5;
}

.panel-closed .sidebar { transform: translateX(-100%); }
.panel-closed .show-panel { display: inline-flex; }
.elevation-hidden .map-caption { bottom: 30px; }

.maplibregl-ctrl-group {
  overflow: hidden;
  border: 1px solid var(--hairline) !important;
  border-radius: 8px !important;
  background: rgba(11, 20, 28, 0.9) !important;
  box-shadow: 0 8px 24px rgba(0,0,0,.22) !important;
}

.maplibregl-ctrl button { filter: invert(1) brightness(1.8); }
.maplibregl-ctrl-attrib { background: rgba(8, 15, 22, 0.7) !important; color: #83949f !important; font-size: 9px !important; }
.maplibregl-ctrl-attrib a { color: #a9bac4 !important; }
.maplibregl-popup { max-width: 230px !important; }

.maplibregl-popup-content {
  padding: 13px 15px;
  border: 1px solid rgba(166, 196, 209, 0.18);
  border-radius: 8px;
  background: rgba(11, 19, 27, 0.96);
  box-shadow: 0 14px 32px rgba(0,0,0,.42);
  color: var(--text);
  font-family: "Manrope", system-ui, sans-serif;
}

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #0b131b; }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: #0b131b; }
.maplibregl-popup-close-button { padding: 4px 7px; color: #8da0ad; }
.popup-title { margin: 0; font-size: 12px; font-weight: 700; }
.popup-note { margin: 4px 0 0; color: var(--muted); font-size: 10px; }

@media (max-width: 700px) {
  .sidebar {
    inset: auto 10px 10px;
    width: auto;
    height: min(46svh, 340px);
    border: 1px solid var(--hairline);
    border-radius: 12px;
    box-shadow: 0 16px 50px rgba(0,0,0,.4);
  }

  .sidebar-header { padding: 14px 16px 12px; }
  .brand-context, .summary { display: none; }
  h1 { max-width: none; margin: 14px 0 0; font-size: 21px; }
  .metric-grid { margin-top: 12px; }
  .metric { padding: 8px; }
  .metric strong { font-size: 14px; }
  .metric span { margin-top: 2px; }
  .layer-heading { padding: 11px 16px 7px; }
  .route-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 6px;
    padding: 0 8px 8px;
  }
  .route-leg {
    grid-template-columns: 3px minmax(0, 1fr);
    gap: 7px;
    min-height: 58px;
    padding: 8px;
  }
  .leg-swatch { width: 3px; height: 100%; min-height: 28px; }
  .leg-number, .leg-distance, .leg-detail { display: none; }
  .leg-name {
    display: -webkit-box;
    overflow: hidden;
    font-size: 10px;
    line-height: 1.35;
    text-overflow: clip;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .sidebar-footer { display: none; }
  .icon-button { width: 40px; height: 40px; }
  .map-toolbar { top: 10px; right: 10px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .tool-button { width: 42px; min-height: 42px; padding: 0; }
  .tool-label, .map-caption { display: none; }
  .elevation-panel, .panel-closed .elevation-panel {
    inset: 62px 10px auto 10px;
    height: 142px;
    min-height: 142px;
    max-height: 142px;
  }
  .elevation-header { gap: 10px; padding: 9px 10px 0 12px; }
  .elevation-stats { gap: 10px; }
  .elevation-stat { min-width: 48px; }
  .elevation-plot { height: 104px; padding: 0 8px 7px; }
  .workspace:not(.elevation-hidden) .map-caption { display: none; }
  .panel-closed .sidebar { transform: translateY(calc(100% + 14px)); }
  .show-panel { top: auto; bottom: 14px; left: 14px; min-height: 42px; }
  .maplibregl-ctrl-bottom-right {
    right: 10px;
    bottom: calc(min(46svh, 340px) + 20px);
  }
  .panel-closed .maplibregl-ctrl-bottom-right { bottom: 70px; }
}

@media (max-width: 360px) {
  .sidebar { inset-right: 8px; inset-bottom: 8px; inset-left: 8px; }
  .sidebar-header { padding: 12px 14px 10px; }
  .metric { padding: 7px 6px; }
  .metric span { font-size: 8px; }
  .elevation-kicker { display: none; }
  .elevation-header { gap: 6px; }
  .elevation-stats { gap: 6px; }
  .elevation-stat { min-width: 42px; }
  .elevation-stat span { font-size: 7px; }
  .elevation-stat strong { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
