html, body, #map { margin: 0; height: 100%; background: #101418; }
#hud {
  position: absolute; top: 8px; left: 8px; z-index: 1;
  background: rgba(20,20,20,0.85); color: #ddd;
  font: 12px/1.4 system-ui, sans-serif;
  padding: 6px 10px; border-radius: 4px;
}
#hud b { color: #6cf; }
#layerctl {
  position: absolute; bottom: 12px; left: 12px; z-index: 1;
  background: rgba(20,20,20,0.85); color: #ddd;
  font: 12px/1.4 system-ui, sans-serif;
  padding: 6px 10px; border-radius: 4px;
  display: flex; gap: 8px;
}
#layerctl button {
  background: #2a2a2e; color: #ddd; border: 1px solid #444;
  padding: 4px 8px; border-radius: 3px; cursor: pointer; font: inherit;
}
#layerctl button.on { background: #1e4a78; border-color: #6cf; color: #fff; }
#cachehud {
  position: absolute; bottom: 12px; right: 12px; z-index: 1;
  background: rgba(20,20,20,0.85); color: #ddd;
  font: 11px/1.4 ui-monospace, monospace;
  padding: 5px 9px; border-radius: 4px;
}
#cachehud b { color: #6cf; }
#cachehud .lo { color: #999; }

#searchwrap {
  position: absolute; top: 8px; right: 64px; z-index: 2;
  width: 340px; max-width: calc(100vw - 80px);
  font: 13px/1.4 system-ui, sans-serif;
}
#searchbox {
  display: flex; gap: 6px; align-items: center;
  background: rgba(20,20,20,0.92); border: 1px solid #444;
  border-radius: 6px; padding: 6px 8px;
}
#searchbox input {
  flex: 1; background: transparent; color: #fff; border: 0; outline: 0;
  font: inherit;
}
#searchbox input::placeholder { color: #888; }
#searchchips {
  display: flex; gap: 4px; margin-top: 4px;
  background: rgba(20,20,20,0.85); border-radius: 6px; padding: 4px;
  flex-wrap: wrap;
}
#searchchips button {
  background: #2a2a2e; color: #ccc; border: 1px solid #444;
  padding: 3px 8px; border-radius: 12px; cursor: pointer; font: 11px/1 inherit;
}
#searchchips button.on { background: #1e4a78; border-color: #6cf; color: #fff; }
#searchresults {
  margin-top: 4px; max-height: 60vh; overflow-y: auto;
  background: rgba(20,20,20,0.95); border: 1px solid #444; border-radius: 6px;
  display: none;
}
#searchresults.open { display: block; }
.sr-item {
  padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #2a2a2e;
  display: flex; align-items: center; gap: 8px;
}
.sr-item:last-child { border-bottom: 0; }
.sr-item:hover, .sr-item.active { background: #1e4a78; }
.sr-icon {
  width: 22px; height: 22px; flex-shrink: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font: bold 11px monospace;
}
.sr-icon.place { background: #5a3a78; color: #ffe; }
.sr-icon.road { background: #6a5a1a; color: #ffe; }
.sr-icon.trail { background: #1a4a6a; color: #ffe; }
.sr-text { flex: 1; min-width: 0; }
.sr-name { color: #fff; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-meta { color: #999; font-size: 11px; }
.sr-meta .sub { text-transform: capitalize; }
.sr-empty { padding: 10px; color: #888; text-align: center; font-size: 12px; }

#maptooltip {
  position: fixed; pointer-events: none; z-index: 10;
  background: rgba(20,20,20,0.92); color: #fff;
  font: 12px/1.3 system-ui, sans-serif;
  padding: 4px 8px; border-radius: 4px;
  white-space: nowrap;
  display: none;
  max-width: 320px;
  overflow: hidden; text-overflow: ellipsis;
  border: 1px solid #444;
}
#maptooltip .kind { color: #6cf; font-size: 10px; text-transform: uppercase; margin-right: 4px; }

#debugpane {
  position: fixed; top: 100px; right: 12px;
  width: 380px; max-width: calc(100vw - 24px);
  max-height: calc(100vh - 220px);
  background: rgba(15,15,18,0.96); border: 1px solid #555;
  border-radius: 6px; z-index: 5;
  display: none; flex-direction: column;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
#debugpane.open { display: flex; }
#debugpane .head {
  padding: 8px 10px; background: #2a2a2e;
  border-bottom: 1px solid #444; border-radius: 6px 6px 0 0;
  display: flex; justify-content: space-between; align-items: center;
  font: bold 12px system-ui, sans-serif; color: #ddd;
}
#debugpane .head button {
  background: transparent; color: #ccc; border: 0; font-size: 18px;
  cursor: pointer; line-height: 1; padding: 0 4px;
}
#debugpane .head button:hover { color: #fff; }
#debug-copy {
  font: 11px system-ui, sans-serif !important; padding: 2px 8px !important;
  border: 1px solid #555 !important; border-radius: 3px !important;
  background: #2a2a2e !important;
}
#debug-copy.copied { background: #1e7a3a !important; color: #fff !important; }
#debug-body {
  padding: 8px 10px; overflow-y: auto; flex: 1;
  font: 11px/1.45 ui-monospace, monospace; color: #ddd;
}
.dbg-section { margin-bottom: 14px; }
.dbg-section h4 {
  color: #6cf; margin: 0 0 5px;
  font: bold 11px ui-monospace, monospace;
  letter-spacing: 0.5px; text-transform: uppercase;
}
.dbg-row { display: flex; gap: 8px; padding: 1px 0; }
.dbg-row .k { color: #88a; min-width: 110px; flex-shrink: 0; }
.dbg-row .v { color: #fff; word-break: break-all; flex: 1; }
.dbg-row .v.num { color: #9c6; }
.dbg-row .v.null { color: #777; font-style: italic; }
.dbg-empty { color: #888; font-style: italic; padding: 8px; }
.dbg-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.dbg-links a {
  background: #1e4a78; color: #fff; text-decoration: none;
  padding: 3px 8px; border-radius: 3px;
  font: 11px system-ui, sans-serif;
}
.dbg-links a:hover { background: #2a6cb8; }

#legendpane {
  position: fixed; top: 100px; left: 12px;
  width: 240px;
  background: rgba(15,15,18,0.96); border: 1px solid #555;
  border-radius: 6px; z-index: 5;
  display: none; flex-direction: column;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  font: 12px/1.4 system-ui, sans-serif; color: #ddd;
}
#legendpane.open { display: flex; }
#legendpane .head {
  padding: 8px 10px; background: #2a2a2e;
  border-bottom: 1px solid #444; border-radius: 6px 6px 0 0;
  display: flex; justify-content: space-between; align-items: center;
  font: bold 12px system-ui, sans-serif; color: #ddd;
}
#legendpane .head button {
  background: transparent; color: #ccc; border: 0; font-size: 18px;
  cursor: pointer; line-height: 1; padding: 0 4px;
}
#legend-body { padding: 10px 12px; }
.lg-section { margin-bottom: 10px; }
.lg-section h4 {
  color: #6cf; margin: 0 0 6px;
  font: bold 10px system-ui; letter-spacing: 0.5px; text-transform: uppercase;
}
.lg-row {
  display: flex; align-items: center; gap: 9px;
  padding: 3px 0;
}
.lg-row svg { flex-shrink: 0; }
.lg-row .lbl { color: #ddd; font-size: 12px; }

#routepanel {
  position: fixed; top: 100px; left: 12px;
  width: 280px;
  background: rgba(15,15,18,0.96); border: 1px solid #555;
  border-radius: 6px; z-index: 5;
  display: none; flex-direction: column;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  font: 12px/1.4 system-ui, sans-serif; color: #ddd;
}
#routepanel.open { display: flex; }
#routepanel .head {
  padding: 8px 10px; background: #2a2a2e;
  border-bottom: 1px solid #444; border-radius: 6px 6px 0 0;
  display: flex; justify-content: space-between; align-items: center;
  font: bold 12px system-ui, sans-serif; color: #ddd;
}
#routepanel .head button {
  background: transparent; color: #ccc; border: 0; font-size: 18px;
  cursor: pointer; line-height: 1; padding: 0 4px;
}
#route-body { padding: 10px 12px; }
#route-body label { display: block; color: #aaa; font-size: 11px; margin-bottom: 4px; }
#route-profile {
  width: 100%; background: #2a2a2e; color: #fff; border: 1px solid #555;
  border-radius: 4px; padding: 5px 7px; font: 12px system-ui, sans-serif;
}
.rt-controls { display: flex; gap: 6px; margin-top: 8px; }
.rt-controls button {
  flex: 1; background: #2a2a2e; color: #ddd; border: 1px solid #444;
  border-radius: 4px; padding: 5px 8px; cursor: pointer; font: 11px system-ui;
}
.rt-controls button:hover { background: #1e4a78; }
#route-status {
  margin-top: 8px; padding: 6px 8px; color: #6cf;
  background: rgba(28, 60, 100, 0.35); border-radius: 4px; font-size: 11px;
}
#route-results { list-style: none; padding: 0; margin: 8px 0 0; }
.rt-item, .rt-empty { padding: 7px 8px; border-radius: 4px; }
.rt-item {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  margin-bottom: 4px; background: #1e1e22;
}
.rt-item:hover { background: #1e4a78; }
.rt-swatch { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 4px rgba(0,0,0,0.6); }
.rt-stats { display: flex; flex-direction: column; gap: 2px; }
.rt-stats b { color: #fff; font-size: 12px; font-weight: 500; }
.rt-meta { color: #999; font-size: 11px; }
.rt-empty { color: #888; font-style: italic; font-size: 12px; }

.rt-tuning {
  margin-top: 8px; padding: 6px 8px;
  background: rgba(40,40,46,0.6); border-radius: 4px;
}
.rt-tuning summary {
  cursor: pointer; font: bold 11px ui-monospace, monospace;
  color: #6cf; letter-spacing: 0.5px; text-transform: uppercase;
}
.rt-tuning .tn-row { margin-top: 6px; }
.rt-tuning .tn-row label {
  display: flex; justify-content: space-between;
  font: 11px ui-monospace, monospace; color: #aaa;
}
.rt-tuning .tn-row label span { color: #6cf; }
.rt-tuning .tn-row input[type=range] { width: 100%; margin: 2px 0; }
.tn-reset {
  margin-top: 8px; width: 100%;
  background: #2a2a2e; color: #ddd; border: 1px solid #444;
  border-radius: 4px; padding: 4px; cursor: pointer; font: 11px system-ui;
}
.tn-reset:hover { background: #1e4a78; }

.rt-item { flex-direction: column; align-items: stretch; }
.rt-item-head { display: flex; align-items: center; gap: 8px; }

#stagespane {
  position: fixed; top: 100px; left: 304px;
  width: 320px; max-height: calc(100vh - 220px);
  background: rgba(15,15,18,0.96); border: 1px solid #555;
  border-radius: 6px; z-index: 5;
  display: none; flex-direction: column;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  font: 12px/1.4 system-ui, sans-serif; color: #ddd;
  overflow: hidden;
  pointer-events: auto;
}
#stagespane.open { display: flex; }
#stages-body {
  padding: 6px 8px; overflow-y: auto; flex: 1;
}
.stages-head {
  font: bold 11px ui-monospace, monospace;
  color: #6cf; padding: 4px 6px 6px;
  letter-spacing: 0.5px; text-transform: uppercase;
  border-bottom: 1px solid #2a2a2e; margin-bottom: 4px;
}
.stage-row {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 8px;
  padding: 4px 6px; border-radius: 3px; pointer-events: auto;
  cursor: pointer;
}
.stage-row:hover, .stage-row.active { background: #1e4a78; }
.stage-num { color: #888; font: 11px ui-monospace, monospace; text-align: right; }
.stage-name { color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-meta { color: #999; font-size: 10px; white-space: nowrap; align-self: center; }
