:root {
  color-scheme: light dark;
  --sidebar-bg: #111827;
  --sidebar-text: #f9fafb;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-text: #7ec8ff;
  --accent-fill: #0058c6;
  --accent-soft: rgba(10, 132, 255, 0.22);
  --border: rgba(255, 255, 255, 0.1);
  --sheet: rgba(28, 28, 30, 0.92);
  --fill-secondary: rgba(118, 118, 128, 0.24);
  --muted: #d8d8de;
  --label: #f4f4f7;
  --track: rgba(120, 120, 128, 0.32);
  --sheet-inset: 0.55rem;
  --sheet-bottom: calc(0.45rem + env(safe-area-inset-bottom, 0px));
  --sidebar-width: 20.5rem;
  --panel-inset: 1rem;
  --panel-gap: 0.75rem;
  --search-stack: 3.7rem;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
}

html,
body {
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: #000;
  color: var(--sidebar-text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: block;
  position: relative;
  min-height: 0;
}

#sidebar {
  position: absolute;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  left: var(--sheet-inset);
  right: var(--sheet-inset);
  bottom: var(--sheet-bottom);
  max-height: calc(100dvh - var(--sheet-bottom) - 0.6rem);
  min-height: 0;
  overflow: hidden;
  padding: 0.2rem 1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
  border: 0;
  border-radius: 1.15rem;
  background: var(--sheet);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#sidebar:not(.is-sheet-ready) {
  visibility: hidden;
}

#sidebar:not(.is-expanded) {
  transform: translateY(var(--sheet-collapse, 0px));
}

body.has-profile #sidebar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(110%);
}

#sheet-header {
  flex-shrink: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: 0.7rem;
  margin-bottom: 0.15rem;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
}

#sheet-toggle {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

#sheet-toggle:hover,
#sheet-toggle:active,
#sheet-toggle:focus {
  background: transparent;
  outline: none;
}

#sheet-toggle:focus-visible {
  outline: 2px solid #0a84ff;
  outline-offset: 2px;
}

.sheet-handle-hit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 2.75rem;
  margin: 0;
  padding: 0.85rem 0 0.4rem;
  pointer-events: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.filter-summary {
  display: block;
  margin: 0.2rem 0 0;
  color: var(--accent-text);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
}

h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 0.9rem;
  color: var(--muted);
  line-height: 1.4;
  font-size: 0.82rem;
}

.colour-controls {
  margin: 0;
}

.colour-toggle {
  display: flex;
  width: 100%;
  padding: 0.16rem;
  margin: 0;
  border-radius: 999px;
  background: var(--fill-secondary);
  gap: 0;
}

.colour-toggle button {
  flex: 1;
  width: auto;
  margin: 0;
  padding: 0.38rem 0.65rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #ebebf5;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.colour-toggle button:hover:not(:disabled):not(.is-active) {
  background: rgba(255, 255, 255, 0.06);
}

.colour-toggle button.is-active {
  background: var(--accent-fill);
  color: #fff;
}

.colour-scale {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.colour-gradient {
  display: inline-block;
  width: 4.4rem;
  height: 0.38rem;
  border-radius: 999px;
  background: linear-gradient(90deg, #60a5fa, #9f1239);
  vertical-align: middle;
}

.control {
  margin: 0;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.control:last-child {
  border-bottom: 0;
  padding-bottom: 0.15rem;
}

.highway-control {
  margin: 0;
  padding: 0.85rem 0 0.15rem;
  border: 0;
  border-bottom: 0;
  min-inline-size: 0;
}

.highway-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
}

.highway-heading-label {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--label);
}

.highway-toggle-all {
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-text);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}

.highway-toggle-all:hover,
.highway-toggle-all:focus-visible {
  text-decoration: underline;
  outline: none;
}

.highway-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.highway-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 0.28rem 0.62rem;
  border: 0;
  border-radius: 999px;
  background: var(--fill-secondary);
  color: var(--label);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.highway-chip input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.highway-chip:has(input:checked) {
  background: var(--accent-fill);
  color: #fff;
}

.highway-chip:has(input:checked) span {
  color: #fff;
}

.dual-range {
  --range-start: 0%;
  --range-end: 100%;
  position: relative;
  height: 2.2rem;
  margin: 0.35rem 0 0.15rem;
  touch-action: manipulation;
}

.dual-range input[type="range"] {
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  margin: 0;
  transform: translateY(-50%);
  pointer-events: none;
  background: transparent;
}

.dual-range input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
  position: relative;
  z-index: 2;
}

.dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  position: relative;
  z-index: 2;
}

.dual-range input[type="range"]:nth-child(1) {
  z-index: 3;
}

.dual-range input[type="range"]:nth-child(2) {
  z-index: 4;
}

.dual-range::before,
.dual-range::after {
  content: "";
  position: absolute;
  top: 50%;
  height: 0.28rem;
  transform: translateY(-50%);
  border-radius: 999px;
  pointer-events: none;
}

.dual-range::before {
  left: 0;
  right: 0;
  background: var(--track);
}

.dual-range::after {
  left: var(--range-start);
  width: calc(var(--range-end) - var(--range-start));
  background: var(--accent);
}

.dual-range input[type="range"]::-webkit-slider-runnable-track {
  background: transparent;
  border: 0;
}

.dual-range input[type="range"]::-moz-range-track {
  background: transparent;
  border: 0;
}

label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.2rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--label);
}

label span {
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 0.28rem;
  margin: 0.85rem 0 0.35rem;
  border-radius: 999px;
  background: var(--track);
  accent-color: var(--accent);
  touch-action: manipulation;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 1.7rem;
  height: 1.7rem;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
}

.result-count {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
  font-weight: 500;
}

#map-wrap {
  position: absolute;
  inset: 0;
  min-width: 0;
  min-height: 0;
  height: auto;
}

#place-search {
  position: absolute;
  z-index: 1120;
  top: calc(0.55rem + env(safe-area-inset-top, 0px));
  left: var(--sheet-inset);
  right: var(--sheet-inset);
  touch-action: manipulation;
}

#place-search-form {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.28rem 0.28rem 0.28rem 0.85rem;
  border-radius: 999px;
  background: var(--sheet);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
}

#place-search-input {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0.45rem 0.2rem;
  border: 0;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

#place-search-input::placeholder {
  color: var(--muted);
  font-weight: 500;
}

#place-search-input:focus {
  outline: none;
}

.place-locate,
.place-feedback {
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fill-secondary);
  color: #fff;
  flex: 0 0 auto;
  cursor: pointer;
  text-decoration: none;
}

.place-locate svg,
.place-feedback svg {
  display: block;
  width: 1.15rem;
  height: 1.15rem;
}

.place-locate:hover,
.place-locate:hover:not(:disabled),
.place-feedback:hover {
  background: rgba(118, 118, 128, 0.42);
}

.place-locate:focus-visible,
.place-feedback:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

.place-locate.is-active {
  background: var(--accent-fill);
}

.place-locate.is-busy {
  opacity: 0.7;
}

.place-locate.is-busy svg {
  animation: map-loading-spin 0.8s linear infinite;
}

#place-search-results {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0.35rem;
  border-radius: 0.9rem;
  background: var(--sheet);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  max-height: min(50dvh, 18rem);
  overflow-x: hidden;
  overflow-y: auto;
}

#place-search-results[hidden] {
  display: none !important;
}

#place-search-results li {
  margin: 0;
}

#place-search-results button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.55rem 0.7rem;
  border: 0;
  border-radius: 0.65rem;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
}

#place-search-results button:hover,
#place-search-results button.is-active {
  background: rgba(118, 118, 128, 0.28);
}

#place-search-results .place-empty {
  padding: 0.55rem 0.7rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.user-location-dot {
  width: 16px;
  height: 16px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--accent-fill);
  box-shadow: 0 0 0 6px rgba(0, 88, 198, 0.22);
}

#map {
  min-height: 0;
  height: 100%;
}

#map-loading {
  position: absolute;
  z-index: 1060;
  top: calc(4.55rem + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.9rem 0.45rem 0.7rem;
  border-radius: 999px;
  background: var(--sheet);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
}

#map-loading[hidden] {
  display: none !important;
}

#debug-panel {
  position: absolute;
  z-index: 1055;
  top: calc(3.35rem + env(safe-area-inset-top, 0px));
  right: 0.65rem;
  max-width: min(22rem, calc(100% - 1.3rem));
  padding: 0.55rem 0.7rem;
  border-radius: 0.55rem;
  background: rgba(8, 12, 18, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #d1d5db;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.68rem;
  line-height: 1.45;
  pointer-events: none;
  white-space: pre-wrap;
}

#debug-panel[hidden] {
  display: none !important;
}

#debug-panel .debug-title {
  color: #f3f4f6;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

#debug-panel .debug-band {
  opacity: 0.55;
}

#debug-panel .debug-band.is-active {
  opacity: 1;
  color: #a7f3d0;
}

.map-loading-spinner {
  width: 0.95rem;
  height: 0.95rem;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top-color: #fff;
  border-radius: 50%;
  animation: map-loading-spin 0.7s linear infinite;
}

@keyframes map-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.curves-road-canvas {
  pointer-events: none;
  z-index: 450;
}

.profile-span-canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none !important;
  z-index: 1;
}

.profile-hover-dot,
.profile-range-dot,
.profile-hover-dot.maplibregl-marker,
.profile-range-dot.maplibregl-marker {
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #22d3ee;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.35);
  pointer-events: none !important;
}

.profile-range-dot.is-start,
.profile-range-dot-start {
  background: #34d399;
}

.profile-range-dot.is-end,
.profile-range-dot-end {
  background: #60a5fa;
}

.sheet-handle {
  display: block;
  width: 3rem;
  height: 0.4rem;
  margin: 0 auto;
  border-radius: 999px;
  background: rgba(235, 235, 245, 0.45);
  pointer-events: none;
  -webkit-tap-highlight-color: transparent;
}

#sidebar h1 {
  display: none;
}

#filters-body {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  padding-top: 0.15rem;
  max-height: min(52dvh, 28rem);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: manipulation;
  -webkit-overflow-scrolling: touch;
}

.maplibregl-ctrl-bottom-right {
  bottom: calc(6.75rem + env(safe-area-inset-bottom, 0px));
  right: 0.7rem;
  touch-action: manipulation;
}

.maplibregl-ctrl-group {
  overflow: hidden;
  background: #fff;
  touch-action: manipulation;
}

.maplibregl-ctrl-group button,
.maplibregl-ctrl-group button:hover:not(:disabled) {
  background: #fff;
  color: #333;
  touch-action: manipulation;
}

.maplibregl-ctrl-icon {
  background-color: transparent;
}

.maplibregl-ctrl-attrib,
.maplibregl-ctrl-attrib a {
  background: hsla(0, 0%, 100%, 0.75);
  color: rgba(0, 0, 0, 0.75);
}

#profile-panel {
  position: absolute;
  z-index: 1000;
  left: var(--sheet-inset);
  right: var(--sheet-inset);
  bottom: var(--sheet-bottom);
  transform: none;
  display: flex;
  flex-direction: column;
  width: auto;
  max-width: none;
  height: auto;
  max-height: min(72dvh, 34rem);
  padding: 0.85rem 1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
  background: var(--sheet);
  border: 0;
  border-radius: 1.15rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  color: var(--sidebar-text);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
}

#profile-panel[hidden] {
  display: none !important;
}

.profile-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border);
  min-width: 0;
  flex: 0 0 auto;
}

.profile-heading {
  min-width: 0;
  flex: 1 1 auto;
}

.profile-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.profile-stats {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

#profile-panel.is-loading .profile-stats {
  color: var(--accent-text);
}

.profile-actions {
  display: flex;
  flex-direction: row;
  gap: 0.45rem;
  flex: 0 0 auto;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.profile-full-road {
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  height: 2.15rem;
  margin: 0;
  padding: 0 0.75rem;
  border: 0;
  border-radius: 999px;
  background: var(--fill-secondary);
  color: #fff;
  flex: 0 0 auto;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.profile-full-road[hidden] {
  display: none !important;
}

.profile-full-road:hover,
.profile-full-road:hover:not(:disabled) {
  background: rgba(118, 118, 128, 0.42);
}

.profile-full-road:focus-visible {
  outline: 2px solid #0a84ff;
  outline-offset: 2px;
}

#profile-panel .profile-icon-btn {
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fill-secondary);
  color: #fff;
  flex: 0 0 auto;
  font: inherit;
  line-height: 0;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#profile-panel .profile-icon-btn svg {
  display: block;
  width: 1.2rem;
  height: 1.2rem;
}

#profile-panel #profile-maps svg {
  width: 1.35rem;
  height: 1.35rem;
}

#profile-panel .profile-icon-btn:hover,
#profile-panel .profile-icon-btn:hover:not(:disabled) {
  background: rgba(118, 118, 128, 0.42);
}

#profile-panel .profile-icon-btn:active {
  background: rgba(118, 118, 128, 0.55);
}

#profile-panel .profile-icon-btn:focus-visible {
  outline: 2px solid #0a84ff;
  outline-offset: 2px;
}

#profile-maps[hidden] {
  display: none !important;
}

#profile-share.is-copied,
#profile-share.is-copied:hover:not(:disabled) {
  background: rgba(48, 209, 88, 0.28);
}

#profile-chart-wrap {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  height: clamp(6.5rem, 28dvh, 13rem);
  min-height: 6.5rem;
  overflow: hidden;
  border-radius: 0.7rem;
  background: rgba(0, 0, 0, 0.28);
}

#profile-chart {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
  border-radius: 0.7rem;
  touch-action: none;
  pointer-events: none;
}

#profile-hover-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1.5px solid #22d3ee;
  pointer-events: none;
  z-index: 3;
  transform: translateX(-50%);
}

#profile-hover-cursor[hidden] {
  display: none !important;
}

#profile-range {
  position: absolute;
  inset: 0;
  z-index: 1;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

#profile-range[hidden] {
  display: none !important;
}

.profile-range-fill,
.profile-range-shade {
  position: absolute;
  top: 0;
  bottom: 0;
  pointer-events: none;
}

.profile-range-fill {
  background: rgba(10, 132, 255, 0.08);
}

#profile-range.is-custom .profile-range-fill {
  background: rgba(10, 132, 255, 0.22);
}

#profile-range.is-custom .profile-range-shade {
  background: rgba(0, 0, 0, 0.32);
}

.profile-range-handle {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  transform: translateX(-50%);
  cursor: ew-resize;
  touch-action: none;
  z-index: 2;
}

.profile-range-handle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(126, 200, 255, 0.55);
  transform: translateX(-50%);
}

#profile-range.is-custom .profile-range-handle::before {
  background: #7ec8ff;
}

.profile-range-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0.85rem;
  height: 1.45rem;
  border: 2px solid #fff;
  border-radius: 0.35rem;
  background: rgba(118, 118, 128, 0.9);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
}

#profile-range.is-custom .profile-range-handle::after {
  background: #0a84ff;
}

.profile-range-handle:focus-visible {
  outline: none;
}

.profile-range-handle:focus-visible::after {
  outline: 2px solid #7ec8ff;
  outline-offset: 2px;
}

#profile-panel.is-loading #profile-chart {
  opacity: 0;
}

#profile-panel.is-loading #profile-range {
  visibility: hidden;
  pointer-events: none;
}

#profile-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 0.75rem;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
}

#profile-loading[hidden] {
  display: none !important;
}

#profile-loading .map-loading-spinner {
  width: 1.35rem;
  height: 1.35rem;
  border-width: 2.5px;
}

.profile-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  align-items: center;
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  flex: 0 0 auto;
}

.swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-right: 0.3rem;
  border-radius: 50%;
  vertical-align: -0.1rem;
}

.swatch.hairpin {
  background: #c026d3;
}

.swatch.corner {
  background: #d55e00;
}

#streetview-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--accent-text);
  font-weight: 500;
}

#streetview-hint[hidden] {
  display: none !important;
}

#streetview-hint svg {
  width: 0.9rem;
  height: 0.9rem;
  flex: 0 0 auto;
}

@media (max-width: 900px) {
  body {
    background: #000;
  }

  #app {
    display: block;
    position: relative;
  }

  #map-wrap {
    position: absolute;
    inset: 0;
    height: auto;
  }

  #place-search {
    left: var(--sheet-inset);
    right: var(--sheet-inset);
  }

  #sidebar h1 {
    display: none;
  }

  #sidebar {
    position: absolute;
    z-index: 1100;
    left: var(--sheet-inset);
    right: var(--sheet-inset);
    bottom: var(--sheet-bottom);
    max-height: none;
    min-height: 0;
    overflow: hidden;
    padding: 0.2rem 1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
    border: 0;
    border-radius: 1.15rem;
    background: var(--sheet);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease;
    touch-action: none;
  }

  #sidebar:not(.is-sheet-ready) {
    visibility: hidden;
  }

  #sidebar:not(.is-expanded) {
    transform: translateY(var(--sheet-collapse, 0px));
  }

  body.has-profile #sidebar {
    opacity: 0;
    pointer-events: none;
    transform: translateY(110%);
  }

  #sheet-header {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }

  #sheet-toggle,
  #sheet-toggle:hover,
  #sheet-toggle:active {
    background: transparent;
  }

  .sheet-handle-hit,
  .sheet-handle {
    pointer-events: none;
    -webkit-tap-highlight-color: transparent;
  }

  .sheet-handle {
    display: block;
  }

  h1 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
  }

  #filters-body {
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    max-height: min(52dvh, 28rem);
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: manipulation;
  }

  input[type="range"] {
    appearance: none;
    height: 0.28rem;
    margin: 0.85rem 0 0.35rem;
    border-radius: 999px;
    background: rgba(120, 120, 128, 0.32);
  }

  input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 1.7rem;
    height: 1.7rem;
    border: 0;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
  }

  .maplibregl-ctrl-bottom-right {
    bottom: calc(6.75rem + env(safe-area-inset-bottom, 0px));
    right: 0.7rem;
  }

  #profile-panel {
    left: var(--sheet-inset);
    right: var(--sheet-inset);
    bottom: var(--sheet-bottom);
    width: auto;
    max-width: none;
    transform: none;
    max-height: min(72dvh, 34rem);
    padding: 0.85rem 1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
    border: 0;
    border-radius: 1.15rem;
    background: var(--sheet);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    overflow: hidden;
  }

  .profile-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
  }

  .profile-icon-btn,
  #profile-panel .profile-icon-btn {
    width: 2.75rem;
    height: 2.75rem;
  }

  #profile-chart-wrap {
    height: clamp(6.5rem, 28dvh, 13rem);
  }

  .profile-legend {
    color: var(--muted);
  }
}

@media (max-width: 600px) {
  .profile-header {
    gap: 0.5rem;
  }

  .profile-stats {
    font-size: 0.75rem;
  }

  #profile-chart-wrap {
    height: clamp(5.75rem, 26dvh, 11rem);
    min-height: 5.75rem;
  }
}

@media (max-height: 500px) {
  #profile-panel {
    max-height: calc(100% - 0.5rem);
  }

  #profile-chart-wrap {
    height: clamp(4.5rem, 40dvh, 8rem);
    min-height: 4.5rem;
  }
}

@media (min-width: 901px) {
  #sidebar {
    left: var(--panel-inset);
    right: auto;
    top: calc(var(--panel-inset) + var(--search-stack));
    bottom: var(--panel-inset);
    width: var(--sidebar-width);
    max-width: calc(100vw - 2rem);
    max-height: none;
    padding: 0.95rem 1.05rem 0.9rem;
    touch-action: auto;
    transform: none;
  }

  #sidebar:not(.is-expanded),
  body.has-profile #sidebar {
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }

  .sheet-handle-hit,
  .sheet-handle {
    display: none;
  }

  #sheet-header {
    padding-bottom: 0.7rem;
    touch-action: auto;
  }

  #sheet-toggle {
    cursor: default;
  }

  #filters-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    padding-top: 0.15rem;
    touch-action: manipulation;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 1.1rem;
    height: 1.1rem;
  }

  .maplibregl-ctrl-bottom-right {
    bottom: 0.5rem;
    right: 0.7rem;
  }

  body.has-profile .maplibregl-ctrl-bottom-right {
    bottom: calc(min(40dvh, 22rem) + 1.15rem);
  }

  #profile-panel {
    left: calc(var(--panel-inset) + var(--sidebar-width) + var(--panel-gap));
    right: var(--panel-inset);
    bottom: var(--panel-inset);
    max-height: min(40dvh, 22rem);
    padding: 0.95rem 1.05rem 0.9rem;
  }

  #place-search {
    left: var(--panel-inset);
    right: auto;
    width: var(--sidebar-width);
    top: var(--panel-inset);
  }

  #profile-chart-wrap {
    height: clamp(7.5rem, 22dvh, 14rem);
  }
}

.streetview-popup .maplibregl-popup-content {
  padding: 0;
  overflow: hidden;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.28);
}

.streetview-popup .maplibregl-popup-close-button {
  color: #fff;
  font-size: 1.35rem;
  padding: 0 0.4rem;
  z-index: 2;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.streetview-frame {
  display: block;
  line-height: 0;
}

.streetview-frame img {
  display: block;
  width: 400px;
  max-width: min(72vw, 400px);
  height: auto;
  aspect-ratio: 400 / 250;
  object-fit: cover;
  background: #0f172a;
}
