:root {
  --bg:        #080b10;
  --panel:     #0f141b;
  --panel-2:   #151c25;
  --raise:     #1c2530;
  --line:      #222c39;
  --line-2:    #2e3b4b;
  --text:      #dde6f1;
  --muted:     #8697ab;
  --dim:       #61738a;
  --accent:    #ffb454;
  --accent-2:  #ffd9a0;
  --accent-bg: #2a1f0d;
  --ok:        #2ee6a8;
  --err:       #ff5f6d;
  --sans: 'IBM Plex Sans', ui-sans-serif, system-ui, sans-serif;
  --cond: 'IBM Plex Sans Condensed', 'IBM Plex Sans', ui-sans-serif, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --rail: 290px;
  --insp: 340px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#app {
  height: 100vh;
  display: grid;
  grid-template-rows: 46px 1fr;
  grid-template-columns: var(--rail) 1fr auto;
  grid-template-areas: "top top top" "left view right";
}

/* ------------------------------------------------------------- topbar -- */
#topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 14px;
  padding: 0 12px 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-logo { height: 30px; width: auto; flex: none; display: block; }
.brand-text { display: flex; align-items: baseline; gap: 9px; }
.brand h1 {
  font-family: var(--cond);
  font-size: 16px; font-weight: 700; letter-spacing: .02em;
  margin: 0;
}
.brand .tick { color: var(--accent); }
.brand small {
  font-family: var(--mono); font-size: 10px; color: var(--dim);
  letter-spacing: .06em; text-transform: uppercase;
}
.spacer { flex: 1; }

.searchwrap { display: flex; align-items: center; gap: 0; }
#search {
  width: 168px; height: 26px;
  background: var(--bg); border: 1px solid var(--line-2); border-right: none;
  border-radius: 2px 0 0 2px; padding: 0 8px;
  font-family: var(--mono); font-size: 12px;
}
#search::placeholder { color: var(--dim); }
#btnSearch {
  height: 26px; padding: 0 9px; background: var(--raise);
  border: 1px solid var(--line-2); border-radius: 0 2px 2px 0; cursor: pointer;
  font-family: var(--cond); font-weight: 600; letter-spacing: .04em;
}
#btnSearch:hover { background: var(--line-2); }

.btn {
  height: 26px; padding: 0 10px;
  background: var(--raise); border: 1px solid var(--line-2); border-radius: 2px;
  cursor: pointer; font-family: var(--cond); font-weight: 600;
  letter-spacing: .04em; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--line-2); }
.btn.sm { height: 23px; padding: 0 8px; font-size: 12px; }
.btn.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #241703; }
.btn.primary:hover { background: var(--accent-2); }
.group { display: flex; gap: 4px; }

.switch { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); width: 13px; height: 13px; margin: 0; }

/* --------------------------------------------------------------- rails -- */
#side-left, #side-right {
  background: var(--panel);
  overflow-y: auto; overflow-x: hidden;
  z-index: 4;
}
#side-left { grid-area: left; border-right: 1px solid var(--line); }
#side-right {
  grid-area: right; border-left: 1px solid var(--line);
  width: var(--insp); display: none;
}
#side-right.open { display: block; }
#side-left.collapsed { display: none; }

.sec { border-bottom: 1px solid var(--line-2); padding: 12px 13px 14px; }
.sec > h3 {
  margin: 0 0 9px; font-family: var(--cond); font-size: 11.5px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase; color: var(--text);
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none; transition: color .12s;
}
.sec > h3:hover { color: var(--accent); }
/* fold / unfold caret at the end of each heading */
.sec > h3::before {
  order: 2; margin-left: auto; content: '\25be'; font-size: 13px; color: var(--accent); opacity: .9;
}
.sec.collapsed > h3::before { content: '\25b8'; color: var(--muted); }
.sec.collapsed > h3 { margin-bottom: 0; }
.sec.collapsed > :not(h3) { display: none; }

.card {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 2px; padding: 9px 10px;
}
.card.empty { color: var(--dim); }
.card .fname {
  font-family: var(--mono); font-size: 11px; color: var(--accent-2);
  word-break: break-all; margin-bottom: 6px;
}
.card.empty .fname { color: var(--dim); }

.kv, .metrics > div {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 2px 0;
}
.kv span, .metrics span { color: var(--muted); font-size: 12px; }
.kv b, .metrics b { font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }

.stack { display: flex; flex-direction: column; gap: 7px; }
.row { display: flex; gap: 6px; align-items: center; }
.row.wrap { flex-wrap: wrap; }

label.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
label.field > span {
  font-family: var(--cond); font-size: 11px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--dim);
}
select, input[type="number"] {
  height: 25px; background: var(--bg); border: 1px solid var(--line-2);
  border-radius: 2px; padding: 0 6px; width: 100%;
  font-family: var(--mono); font-size: 12px;
}
input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="number"] { font-variant-numeric: tabular-nums; }

ul.layers { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
ul.layers li { display: flex; align-items: center; }
ul.layers label {
  display: flex; align-items: center; gap: 8px; cursor: pointer; width: 100%;
  padding: 4px 6px; border-radius: 5px; font-size: 12.5px; color: var(--text);
  transition: background .12s, color .12s;
}
ul.layers label:hover { background: var(--panel-2); color: var(--accent-2); }
ul.layers input { accent-color: var(--accent); width: 13px; height: 13px; margin: 0; }
#ramp.hidden { display: none; }
.ramp-bar { height: 8px; border-radius: 1px; border: 1px solid var(--line); }
.ramp-scale {
  display: flex; justify-content: space-between; margin-top: 2px;
  font-family: var(--mono); font-size: 10.5px; color: var(--dim);
  font-variant-numeric: tabular-nums;
}

ul.layers i {
  width: 9px; height: 9px; border-radius: 1px; flex: none;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08);
}

ul.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
ul.legend li { display: flex; align-items: center; gap: 7px; font-size: 12px; }
ul.legend i { width: 14px; height: 3px; border-radius: 1px; flex: none; }
ul.legend span { color: var(--muted); font-family: var(--mono); font-size: 11px; }
ul.legend b {
  margin-left: auto; font-family: var(--mono); font-weight: 500;
  font-variant-numeric: tabular-nums; color: var(--dim);
}

.hint {
  color: var(--muted); font-size: 12px; line-height: 1.55;
}
.hint kbd {
  font-family: var(--mono); font-size: 10px; background: var(--raise);
  border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 2px;
  padding: 0 4px; color: var(--text);
}

/* ------------------------------------------------------------ viewport -- */
#viewport { grid-area: view; position: relative; overflow: hidden; background: var(--bg); }
#gl { display: block; width: 100%; height: 100%; cursor: grab; }

#dropzone {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: radial-gradient(120% 90% at 50% 40%, rgba(20,28,38,.94), rgba(8,11,16,.97));
  z-index: 3; text-align: center; padding: 24px;
}
#dropzone.hidden { display: none; }
#dropzone.dragging { background: radial-gradient(120% 90% at 50% 40%, rgba(42,31,13,.95), rgba(8,11,16,.97)); }
.dz-inner { max-width: 460px; display: grid; gap: 14px; justify-items: center; }
.dz-mark { display: flex; gap: 3px; align-items: flex-end; height: 34px; margin-bottom: 2px; }
.dz-mark i { width: 3px; background: var(--line-2); border-radius: 1px; }
.dz-mark i:nth-child(3) { background: var(--accent); }
.dz-inner h2 {
  font-family: var(--cond); font-size: 21px; font-weight: 700; margin: 0;
  letter-spacing: .01em; text-wrap: balance;
}
.dz-inner p { margin: 0; color: var(--muted); max-width: 42ch; line-height: 1.6; }
.dz-inner .formats {
  font-family: var(--mono); font-size: 11px; color: var(--dim);
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;
}
.dz-actions { display: flex; gap: 8px; margin-top: 2px; }

#hud {
  position: absolute; left: 10px; bottom: 10px; z-index: 2;
  display: flex; gap: 8px; align-items: flex-end; pointer-events: none;
}
.chip {
  background: rgba(15,20,27,.88); border: 1px solid var(--line);
  border-radius: 2px; padding: 4px 8px;
  font-family: var(--mono); font-size: 11px; font-variant-numeric: tabular-nums;
  display: flex; gap: 6px; align-items: center; backdrop-filter: blur(6px);
}
.chip span { color: var(--dim); }
#measurePanel { pointer-events: auto; }
#measurePanel.hidden { display: none; }
#measureOut { display: flex; gap: 6px; align-items: baseline; }
#measureOut b { color: var(--accent-2); }

#viewTools {
  position: absolute; right: 10px; top: 10px; z-index: 2;
  display: flex; gap: 4px;
}

/* ----------------------------------------------------------- inspector -- */
.ins-bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px 8px 13px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.ins-bar h3 {
  margin: 0; font-family: var(--cond); font-size: 11px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--dim);
}
#closeInspector {
  margin-left: auto; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 15px; line-height: 1; padding: 2px 4px;
}
#closeInspector:hover { color: var(--text); }
#inspector { padding: 12px 13px 22px; display: grid; gap: 12px; }
#inspector h4 {
  margin: 6px 0 0; font-family: var(--cond); font-size: 11px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase; color: var(--dim);
}
.ins-head { display: grid; gap: 3px; }
.ins-kind {
  font-family: var(--cond); font-size: 15px; font-weight: 600; letter-spacing: .02em;
  color: var(--accent-2);
}
.ins-kind[data-cat="crosswalk"] { color: #ffc38a; }
.ins-kind[data-cat="way"] { color: #bfe0ff; }
.ins-id { font-family: var(--mono); font-size: 12px; color: var(--dim); }
.metrics {
  display: grid; gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 2px;
}
.metrics > div { background: var(--panel-2); padding: 5px 8px; }

dl.tags {
  margin: 0; display: grid; grid-template-columns: minmax(0,auto) minmax(0,1fr);
  gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 2px;
}
dl.tags dt, dl.tags dd {
  margin: 0; background: var(--panel-2); padding: 3px 8px;
  font-family: var(--mono); font-size: 11.5px; word-break: break-word;
}
dl.tags dt { color: var(--muted); }
dl.tags dd { color: var(--text); }
.sub { border-left: 2px solid var(--line-2); padding-left: 8px; margin-top: 6px; }
.sub-h { font-family: var(--cond); font-weight: 600; letter-spacing: .03em; }
.sub-h .id, .id { font-family: var(--mono); font-size: 11px; color: var(--dim); font-weight: 400; }
.id-link { color: var(--accent); cursor: pointer; font-family: var(--mono); font-size: 11px; text-decoration: none; }
.id-link:hover { text-decoration: underline; }
.muted { color: var(--dim); font-size: 12px; }
.ins-actions { display: flex; gap: 6px; margin-top: 4px; }

/* -------------------------------------------------------------- status -- */
#status {
  position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 14px);
  background: var(--panel-2); border: 1px solid var(--line-2); border-left: 3px solid var(--accent);
  border-radius: 2px; padding: 7px 13px; font-size: 12.5px;
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
  z-index: 20; max-width: 70vw;
}
#status.show { opacity: 1; transform: translate(-50%, 0); }
#status[data-kind="ok"] { border-left-color: var(--ok); }
#status[data-kind="error"] { border-left-color: var(--err); }

/* --------------------------------------------------------------- modal -- */
#modal {
  position: fixed; inset: 0; display: none; place-items: center;
  background: rgba(4,6,9,.72); z-index: 30; padding: 20px;
}
#modal.open { display: grid; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 3px;
  width: min(760px, 100%); max-height: 86vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 {
  margin: 0; font-family: var(--cond); font-size: 12px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.modal-head .group { margin-left: auto; }
#modalBody {
  margin: 0; padding: 12px; overflow: auto; font-family: var(--mono);
  font-size: 11.5px; line-height: 1.55; white-space: pre; color: var(--text);
}
#modalBody.hidden, #modalImg.hidden { display: none; }
#modalImg { max-width: 100%; max-height: 74vh; object-fit: contain; background: #000; }

/* ---------------------------------------------------------- responsive -- */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-areas: "top" "view"; }
  #side-left, #side-right {
    position: fixed; top: 46px; bottom: 0; width: min(300px, 86vw);
    box-shadow: 0 0 24px rgba(0,0,0,.5);
  }
  #side-left { left: 0; }
  #side-right { right: 0; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
/* ------------------------------------------------- entry-data progress -- */
.dz-progress { width: min(360px, 80vw); display: grid; gap: 6px; margin-top: 4px; }
.dz-progress.hidden { display: none; }
.dz-bar {
  height: 4px; background: var(--raise); border: 1px solid var(--line);
  border-radius: 2px; overflow: hidden;
}
.dz-bar i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width .15s linear; }
.dz-bar i.indeterminate { width: 35%; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
.dz-prog-label {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---- route challenges ---------------------------------------------------- */
/* Hover tooltip. Fixed to the viewport, follows the cursor (positioned in JS). */
#challengeTip {
  position: fixed; left: 0; top: 0; z-index: 30; display: none;
  max-width: 320px; padding: 9px 12px;
  background: rgba(12, 17, 23, 0.96); border: 1px solid var(--line-2, #2e3b4b);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
#challengeTip b {
  display: block; font-family: var(--cond); font-size: 13px; font-weight: 700;
  letter-spacing: .04em; margin-bottom: 2px;
}
#challengeTip em {
  display: block; font-style: normal; font-size: 11px; color: var(--dim, #61738a);
  margin-bottom: 5px;
}
#challengeTip span { display: block; font-size: 12px; line-height: 1.5; color: var(--text, #dde6f1); }

/* "adjust positions" toggle in the challenges panel */
label.tgl {
  display: flex; align-items: center; gap: 7px; cursor: pointer;
  font-family: var(--cond); font-size: 12px; color: var(--dim);
}
label.tgl input { accent-color: var(--accent); width: 13px; height: 13px; margin: 0; }

/* ---- About panel + sidebar help tooltip --------------------------------- */
.btn.accent { border-color: var(--accent); color: var(--accent-2); }
.btn.accent:hover { background: var(--accent-bg); }

#uiTip {
  position: fixed; left: 0; top: 0; z-index: 45; display: none;
  max-width: 260px; padding: 8px 11px;
  background: rgba(12,17,23,.97); border: 1px solid var(--line-2);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.5);
  font-size: 12px; line-height: 1.5; color: var(--text); pointer-events: none;
}

#about {
  position: fixed; inset: 0; display: none; place-items: center;
  background: rgba(4,6,9,.75); z-index: 40; padding: 24px;
}
#about.open { display: grid; }
.about-box {
  width: min(680px, 96vw); max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.about-head {
  display: flex; align-items: center; gap: 12px; padding: 15px 20px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel);
}
.about-head img { height: 30px; width: auto; }
.about-head h2 { margin: 0; font-family: var(--cond); font-size: 18px; font-weight: 700; }
.about-head .btn { margin-left: auto; }
.about-body { padding: 8px 22px 22px; color: var(--text); font-size: 14px; line-height: 1.6; }
.about-body h4 {
  margin: 18px 0 6px; font-family: var(--cond); font-size: 12px;
  letter-spacing: .12em; text-transform: uppercase; color: var(--accent-2);
}
.about-body p { margin: 8px 0; color: var(--muted); }
.about-body ul { margin: 6px 0; padding-left: 18px; }
.about-body li { margin: 5px 0; color: var(--muted); }
.about-body b { color: var(--text); font-weight: 600; }
