:root {
  --bg: #10212e;
  --bg-2: #172e3f;
  --bg-3: #20405a;
  --line: #2c4d66;
  --text: #e6eef4;
  --muted: #9bb2c2;
  --accent: #3ea6ff;
  --accent-ink: #06243b;
  --danger: #ff7a7a;
  --route: #c0148c;
  --sidebar-w: 330px;
  --topbar-h: 48px;
  --status-h: 26px;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template: var(--topbar-h) 1fr var(--status-h) / var(--sidebar-w) 1fr;
  grid-template-areas: "top top" "side main" "status status";
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
body.sidebar-closed { grid-template-columns: 0 1fr; }
body.sidebar-closed #sidebar { display: none; }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 11px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: none; padding: 2px 0; color: var(--muted); text-decoration: underline; }
.icon-btn { background: none; border: none; padding: 2px 6px; color: var(--muted); font-size: 15px; line-height: 1; }
.icon-btn:hover { color: var(--text); }
.danger:hover { color: var(--danger) !important; }
input[type="text"], input[type="search"], input[type="number"], select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  width: 100%;
  min-width: 0;
}
input.invalid { border-color: var(--danger); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }

/* ---------- top bar ---------- */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand { font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.tools { display: flex; gap: 4px; }
.search { position: relative; flex: 1 1 200px; max-width: 380px; min-width: 120px; }
#search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  margin: 0; padding: 4px; list-style: none;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4); max-height: 60vh; overflow: auto;
}
#search-results li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 8px; border-radius: 5px; cursor: pointer; }
#search-results li:hover { background: var(--bg-3); }
#search-results li.none { color: var(--muted); cursor: default; }
.file-actions { display: flex; gap: 4px; margin-left: auto; }

/* ---------- sidebar ---------- */
#sidebar { grid-area: side; display: flex; flex-direction: column; background: var(--bg-2); border-right: 1px solid var(--line); min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: none; border-radius: 0; background: none; padding: 9px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); background: none; border-bottom-color: var(--accent); }
.panel { flex: 1; overflow: auto; padding: 10px 12px; min-height: 0; }
#sidebar > footer { padding: 6px 12px; border-top: 1px solid var(--line); font-size: 12px; }
.panel h3 { margin: 14px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.panel section:first-child h3 { margin-top: 2px; }
.count { opacity: 0.7; }
.empty { color: var(--muted); padding: 8px 2px; }
.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.item:hover { background: var(--bg-3); }
.item.selected { background: var(--bg-3); box-shadow: inset 3px 0 0 var(--accent); }
.item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.editor-wrap { margin-top: 12px; padding-top: 4px; border-top: 1px solid var(--line); }
.field { display: block; margin: 8px 0; color: var(--muted); font-size: 12px; }
.field > input, .field > select, .field > textarea { margin-top: 3px; color: var(--text); font-size: 14px; }
.field > input[type="range"] { width: 100%; }
.check { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.stats { display: flex; gap: 14px; align-items: flex-end; margin: 10px 0; }
.stats > * { display: flex; flex-direction: column; }
.stats b { font-size: 17px; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: 11px; }
.stats input { width: 70px; }
table.legs { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.legs th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 4px; border-bottom: 1px solid var(--line); }
table.legs td { padding: 3px 4px; border-bottom: 1px solid rgba(255,255,255,0.05); white-space: nowrap; }
table.legs tbody tr { cursor: pointer; }
table.legs tbody tr:hover { background: var(--bg-3); }
.shade-grid { display: grid; grid-template-columns: 16px 1fr 80px; gap: 6px 8px; align-items: center; }
.swatch { width: 16px; height: 16px; border-radius: 3px; border: 1px solid rgba(255,255,255,0.3); }

/* ---------- map area ---------- */
main { grid-area: main; position: relative; min-width: 0; min-height: 0; }
#map { position: absolute; inset: 0; background: #c9d3d8; }
#hud {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 5;
  max-width: calc(100% - 120px);
  background: rgba(16,33,46,0.92); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 14px; font-variant-numeric: tabular-nums; text-align: center; pointer-events: none;
}
#toast {
  position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); z-index: 6;
  background: var(--bg-3); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 16px;
}
#info {
  position: absolute; top: 10px; left: 10px; z-index: 4; width: 320px; max-width: calc(100% - 70px);
  max-height: calc(100% - 60px); overflow: auto;
  background: rgba(23,46,63,0.97); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
#info header { display: flex; justify-content: space-between; align-items: flex-start; }
#info .pos { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.feature { border-top: 1px solid var(--line); padding: 6px 0; }
.feature summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.feature summary .sub { color: #e7b6ff; font-size: 12px; }
.feature summary .cell { margin-left: auto; color: var(--muted); font-size: 11px; }
.feature table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.feature th { text-align: left; font-weight: 400; color: var(--muted); padding: 2px 8px 2px 0; vertical-align: top; width: 45%; }
.feature td { padding: 2px 0; overflow-wrap: anywhere; }

/* ---------- status bar ---------- */
#statusbar {
  grid-area: status; display: flex; align-items: center; gap: 18px; padding: 0 12px;
  background: var(--bg-2); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden;
}
#cursor-pos { color: var(--text); min-width: 250px; }
.disclaimer { margin-left: auto; color: #ffb37a; }
.fatal { position: fixed; inset: 40% 10% auto; background: #400; color: #fff; padding: 16px; border-radius: 8px; z-index: 99; }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  :root { --sidebar-w: min(86vw, 330px); }
  body { grid-template-columns: 0 1fr; }
  #sidebar { position: fixed; top: var(--topbar-h); bottom: var(--status-h); left: 0; width: var(--sidebar-w); z-index: 30; box-shadow: 8px 0 24px rgba(0,0,0,0.4); }
  .brand, #zoom, #chart-status { display: none; }
  #topbar { gap: 6px; overflow-x: auto; }
  #cursor-pos { min-width: 0; }
}

/* ---------- points of interest ---------- */
.feature.poi summary .poi-kind { color: #9fd0ff; }
.feature.poi a { color: var(--accent); }
.poi-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 8px; }
.osm-link { font-size: 12px; }

/* ---------- Layers panel: collapsible sections ---------- */
#panel-layers { padding: 6px 8px; }
.acc { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 8px; background: rgba(255,255,255,0.02); }
.acc-head { display: flex; align-items: center; gap: 6px; padding-right: 10px; }
.acc-toggle { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; background: none; border: none; border-radius: 8px; padding: 10px; text-align: left; }
.acc-toggle:hover { background: var(--bg-3); }
.acc-toggle .chev { color: var(--muted); transition: transform 0.15s; display: inline-block; width: 10px; }
.acc-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.acc-title { font-weight: 600; }
.acc-status { margin-left: auto; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-body { padding: 2px 12px 12px 28px; }
.acc-body.is-off { opacity: 0.45; }
.acc-body .field:first-child { margin-top: 2px; }
.sublayers { display: flex; flex-direction: column; gap: 1px; }
.subsection { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.field.indent { margin-left: 24px; }
.legend-icon { width: 18px; height: 18px; flex: none; }

/* switch */
.switch { position: relative; width: 34px; height: 20px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider { position: absolute; inset: 0; background: #3a5368; border-radius: 20px; transition: background 0.15s; }
.switch .slider::before { content: ''; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.15s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(14px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* range with value */
.range { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.range input { flex: 1; }
.range-val { width: 38px; text-align: right; color: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; }

/* bands / gradient editor */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin: 4px 0 10px; }
.segmented button { border: none; border-radius: 0; background: none; padding: 5px 14px; }
.segmented button.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.stops { display: flex; flex-direction: column; gap: 6px; }
/* colour | label | depth | unit | remove */
.stop-row { display: grid; grid-template-columns: 30px 1fr 64px 22px 22px; align-items: center; gap: 6px; }
.stop-row.wide { grid-template-columns: 30px 1fr; }
.stop-row.dry { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.stop-row .unit { color: var(--muted); font-size: 12px; white-space: nowrap; }
.depth-input { width: 64px !important; }
.stop-row .icon-btn { padding: 2px; }
.color-input { width: 30px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; cursor: pointer; flex: none; }
.color-input::-webkit-color-swatch-wrapper { padding: 2px; }
.color-input::-webkit-color-swatch { border: none; border-radius: 3px; }
.gradient-preview { height: 14px; border-radius: 4px; border: 1px solid var(--line); }
.gradient-ticks { position: relative; height: 14px; font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.gradient-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.gradient-ticks span:first-child { transform: none; }
.gradient-ticks span:last-child { transform: translateX(-100%); }


/* ---------- click feedback ---------- */
.water-drop { position: absolute; pointer-events: none; z-index: 1; }
.wake { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 1; visibility: hidden; }
