/* The map page: sidebar tabs, a full-height 3D viewport with floating camera controls, inspector and
   status bar, the data view and the drive view's HUD. Colours come from the tokens below. */

:root {
  color-scheme: dark;
  --bg: #0a0f0d;
  --surface: #111815;
  --surface-2: #17201c;
  --surface-3: #1e2924;
  --glass: rgba(12, 18, 16, .86);
  --border: rgba(214, 236, 226, .09);
  --border-strong: rgba(214, 236, 226, .18);
  --text: #e9f0ec;
  --muted: #8d9d96;
  --faint: #62726b;
  --accent: #cdf36b;
  --accent-ink: #16200b;
  --accent-soft: rgba(205, 243, 107, .12);
  --info: #62d2cb;
  --warn: #f4b857;
  --danger: #ff6a5c;
  --danger-soft: rgba(255, 106, 92, .12);
  --violet: #b99bff;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --font: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.meta { color: var(--muted); }

/* ---- Controls ---------------------------------------------------------------------------- */

.btn, .road-editor button, .inspector button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 28px; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 8px;
  color: #d3e0da; background: var(--surface-2); cursor: pointer; font-size: 12px; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover, .road-editor button:hover, .inspector button:hover { border-color: rgba(214, 236, 226, .3); background: var(--surface-3); }
button:disabled, button:disabled:hover { opacity: .38; cursor: default; background: var(--surface-2); border-color: var(--border-strong); }
button.active, button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
button.ghost { border-color: transparent; background: transparent; }
input[type="text"], input[type="number"], input:not([type]), select {
  width: 100%; min-width: 0; height: 28px; padding: 3px 8px; border: 1px solid var(--border-strong); border-radius: 7px;
  background: #0c1311; color: var(--text); font-size: 12px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid rgba(205, 243, 107, .5); outline-offset: 1px; }
input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }

/* ---- Layout ------------------------------------------------------------------------------ */

.app { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: 100vh; }
.sidebar { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--surface); }
.main { position: relative; min-width: 0; min-height: 0; }

.brand { display: flex; align-items: center; gap: 11px; padding: 16px 16px 12px; }
.brand-mark { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 15px; }
.brand .eyebrow { color: var(--faint); font: 10px/1.3 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.brand h1 { margin: 1px 0 0; font-size: 14px; font-weight: 650; line-height: 1.3; }

.mode-switcher { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; margin: 0 16px 12px; padding: 3px; border-radius: 10px; background: #0b110f; border: 1px solid var(--border); }
.mode-switcher a { padding: 6px 8px; border-radius: 7px; color: var(--muted); text-align: center; text-decoration: none; font-size: 12px; font-weight: 550; }
.mode-switcher a:hover { color: var(--text); }
.mode-switcher a.active { color: var(--accent-ink); background: var(--accent); }

.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs button { position: relative; flex: none; padding: 8px 9px 9px; border: 0; color: var(--muted); background: none; cursor: pointer; font-size: 12px; font-weight: 550; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); }
.tabs button.active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.tabs .count { margin-left: 5px; padding: 0 5px; border-radius: 99px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; }
.tabs .count.muted { background: var(--surface-3); color: var(--muted); }
.tab-panels { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px 24px; scrollbar-width: thin; scrollbar-color: #2b3833 transparent; }
.tab-panel { display: grid; gap: 14px; align-content: start; }
.tab-panel:not(.active) { display: none; }

.card { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.section-title, .card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 9px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .06em; }
.section-title .btn, .card h2 button { font-size: 11px; min-height: 24px; padding: 2px 8px; letter-spacing: 0; }
.note { color: var(--muted); font-size: 12px; }
.note code { font: 11px var(--mono); color: #c7d6cf; }

/* ---- Sidebar: view settings -------------------------------------------------------------- */

.layer { display: grid; grid-template-columns: 16px 1fr 72px; gap: 9px; align-items: center; padding: 5px 0; }
.layer span { display: flex; align-items: center; gap: 8px; }
.layer input[type="range"] { width: 72px; }
.layer-opacity { color: var(--faint); font-size: 11px; text-align: right; }
.swatch { width: 9px; height: 9px; border-radius: 3px; }
.surface-key { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 2px 0 6px 25px; color: var(--muted); font-size: 11px; }
.surface-key span::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 2px; background: var(--key); }
.vertical-controls { display: grid; gap: 4px; margin-top: 8px; }
.vertical-control-head, .vertical-range-labels { display: flex; justify-content: space-between; align-items: center; }
.vertical-control-head output { color: var(--accent); font-weight: 700; }
.vertical-controls input { width: 100%; }
.vertical-range-labels { color: var(--faint); font-size: 10px; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { padding: 9px 10px; border-radius: 8px; background: #0e1513; }
.stat b { display: block; font-size: 14px; }
.stat span { color: var(--muted); font-size: 11px; }

/* ---- Sidebar: inspector lists ------------------------------------------------------------- */

.list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.list-item, .road-editor .list-item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 8px; width: 100%;
  min-height: 0; padding: 8px 10px; border: 1px solid transparent; border-radius: 8px;
  background: #0e1513; color: var(--text); text-align: left; cursor: pointer; white-space: normal;
}
.list-item:hover, .road-editor .list-item:hover { border-color: var(--border-strong); background: var(--surface-3); }
.list-item.active, .road-editor .list-item.active { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.list-item b { font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.list-item small { grid-column: 1; color: var(--muted); font-size: 11px; }
.list-item .badge-tag { grid-row: 1 / span 2; grid-column: 2; }
.list-item.hint b { color: #f7cf8d; }
.badge-tag { padding: 1px 7px; border-radius: 99px; background: var(--surface-3); color: var(--muted); font-size: 10px; font-weight: 600; }
.badge-tag.ok { background: rgba(90, 212, 138, .14); color: #8ce0ad; }
.badge-tag.bad { background: var(--danger-soft); color: #ffb0a8; }
.badge-tag.warn { background: rgba(244, 184, 87, .14); color: #f7cf8d; }
.empty { padding: 14px 10px; border: 1px dashed var(--border-strong); border-radius: 8px; color: var(--muted); text-align: center; font-size: 12px; }
.pass-banner { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; background: rgba(90, 212, 138, .1); color: #9fe6bb; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips button { min-height: 26px; padding: 3px 10px; border-radius: 99px; }
.legend { margin-top: 8px; color: var(--muted); font-size: 11px; }
.drive-link { display: inline-flex; align-items: center; min-height: 28px; padding: 0 4px; color: var(--accent); font-size: 12px; text-decoration: none; }
.drive-link[aria-disabled="true"] { color: var(--faint); pointer-events: none; }

/* Recipe library (read-only) */
.library-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.library-table th { color: var(--faint); font-weight: 600; text-align: left; padding: 3px 4px; }
.library-table td { padding: 5px 4px; border-top: 1px solid var(--border); vertical-align: top; }
.library-table td:first-child { width: 38%; font-family: var(--mono); color: #cfded7; }
.library-where { display: flex; gap: 8px; padding: 10px 12px; border-radius: 8px; border: 1px solid rgba(98, 210, 203, .25); background: rgba(98, 210, 203, .07); font-size: 12px; color: #bfe8e4; }

/* ---- Viewport ---------------------------------------------------------------------------- */

.terrain-view { position: absolute; inset: 0; display: none; overflow: hidden; background: radial-gradient(120% 90% at 50% 0%, #17302a, #0a0f0d 70%); }
body[data-view="editor"] .terrain-view, body[data-view="drive"] .terrain-view { display: block; }
.terrain-view canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.terrain-view canvas.hovering { cursor: pointer; }

.float { position: relative; z-index: 4; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow); }
.viewport-top { position: absolute; z-index: 4; left: 14px; right: 14px; top: 14px; display: flex; align-items: flex-start; gap: 10px; pointer-events: none; }
.viewport-top > * { pointer-events: auto; }
.viewport-top .spacer { flex: 1; pointer-events: none; }
.icon-button svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.segmented { position: static; display: flex; gap: 2px; padding: 4px; }
.segmented button { padding: 5px 12px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; font-size: 12px; font-weight: 550; }
.segmented button:hover { color: var(--text); }
.segmented button.active { color: var(--accent-ink); background: var(--accent); }
.icon-button { position: static; display: grid; place-items: center; width: 38px; height: 38px; color: #cfdcd6; cursor: pointer; }
.icon-button:hover { color: var(--accent); }

.statusbar { position: absolute; z-index: 4; left: 14px; right: 14px; bottom: 14px; display: flex; align-items: center; gap: 10px; pointer-events: none; }
.statusbar > * { pointer-events: auto; }
.status { display: flex; align-items: center; gap: 8px; max-width: min(760px, 70%); padding: 7px 12px; border-radius: 10px; font-size: 12px; }
.status::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status[data-tone="ok"]::before { background: #5ad48a; box-shadow: 0 0 8px #5ad48a; }
.statusbar .spacer { flex: 1; pointer-events: none; }
.probe { padding: 6px 10px; border-radius: 10px; color: var(--muted); font: 11px var(--mono); }
.probe.active { color: #e2eee8; }
.hint-keys { display: flex; align-items: center; gap: 5px; padding: 6px 10px; border-radius: 10px; color: var(--muted); font-size: 11px; }

/* Inspector */
.inspector { position: absolute; right: 14px; top: 66px; bottom: 60px; width: 330px; display: flex; flex-direction: column; overflow: hidden; }
.inspector-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 12px 12px 10px; border-bottom: 1px solid var(--border); }
.kind-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--surface-3); color: var(--info); font-weight: 700; font-size: 12px; }
.inspector-head small { display: block; color: var(--muted); font-size: 11px; }
.inspector-head b { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.inspector-head .ghost { width: 28px; padding: 0; font-size: 16px; color: var(--muted); }
.inspector-body { flex: 1; overflow-y: auto; padding: 4px 12px 14px; scrollbar-width: thin; scrollbar-color: #2b3833 transparent; }
.inspector-section { padding: 10px 0; border-bottom: 1px solid var(--border); }
.inspector-section:last-child { border-bottom: 0; }
.inspector-section > h3 { margin: 0 0 8px; color: var(--faint); font-size: 10.5px; font-weight: 650; letter-spacing: .08em; }
.props { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 5px 10px; margin: 0; font-size: 12px; }
.props dt { color: var(--muted); }
.props dd { margin: 0; overflow-wrap: anywhere; }
.props dd.mono { font-family: var(--mono); font-size: 11px; }
.actions { display: flex; flex-wrap: wrap; gap: 5px; }
.link-list { display: flex; flex-wrap: wrap; gap: 4px; }
.link-list button { min-height: 22px; padding: 1px 8px; border-radius: 99px; font: 11px var(--mono); }

/* ---- Data view --------------------------------------------------------------------------- */

.data-view { display: none; height: 100%; overflow-y: auto; padding: 28px; }
body[data-view="inspector"] .data-view, body[data-view="pipeline"] .data-view { display: block; }
.data-view h2 { margin: 0 0 14px; font-size: 16px; }
.data-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.panel { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.panel h3 { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 600; }
.panel > b { font-size: 16px; }
.pipeline { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stage strong { display: block; margin-bottom: 6px; color: var(--accent); }
.ready-row { display: grid; grid-template-columns: 10px 120px 1fr; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.ready-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--faint); }
.ready-dot.ok { background: #5ad48a; box-shadow: 0 0 8px #5ad48a; }

/* ---- Drive view HUD ---------------------------------------------------------------------- */

body[data-view="drive"] .app { display: block; }
body[data-view="drive"] .sidebar, body[data-view="drive"] .viewport-top, body[data-view="drive"] .statusbar, body[data-view="drive"] .inspector { display: none; }
body[data-view="drive"] .main { position: fixed; inset: 0; }
body[data-view="drive"] #terrain-canvas { cursor: grab; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 60vh; height: auto; }
  .sidebar { max-height: 60vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .main { height: 70vh; }
  .inspector { top: auto; left: 14px; right: 14px; width: auto; height: 45%; }
  .data-grid, .pipeline { grid-template-columns: 1fr; }
  .hint-keys { display: none; }
}

.drive-hud { position: absolute; inset: 0; z-index: 5; pointer-events: none; color: #eef4f2; font-family: var(--font); }
.drive-hud button, .drive-hud select, .drive-hud a, .drive-hud canvas { pointer-events: auto; }
.hud-label { display: block; color: #8fa39b; font-size: 10px; letter-spacing: .06em; }

.hud-trip { position: absolute; top: 14px; left: 14px; width: 300px; padding: 12px 14px; border: 1px solid rgba(255,255,255,.08); border-radius: 12px; background: rgba(10,14,13,.72); backdrop-filter: blur(10px); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.hud-exit { color: #9fb3ab; font-size: 11px; text-decoration: none; }
.hud-exit:hover { color: var(--accent); }
.hud-goal { margin: 8px 0 6px; }
.hud-goal b { font-size: 16px; }
.hud-trip select { width: 100%; padding: 6px 8px; border: 1px solid #3a4a44; border-radius: 7px; background: #111a17; color: #dfe9e5; font-size: 12px; }
.hud-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.hud-stats b { font: 600 14px/1.3 var(--mono); }
.hud-buttons { display: flex; gap: 6px; }
.hud-buttons button { flex: 1; padding: 6px 8px; border: 1px solid #3a4a44; border-radius: 7px; background: #13201c; color: #b9cbc4; cursor: pointer; font-size: 11px; white-space: nowrap; }
.hud-buttons button[aria-pressed="true"] { border-color: transparent; background: var(--accent); color: var(--accent-ink); font-weight: 700; }

.hud-navigator { position: absolute; right: 18px; bottom: 18px; width: 360px; overflow: hidden; border: 1px solid rgba(255,255,255,.1); border-radius: 16px; background: #15191b; box-shadow: 0 14px 40px rgba(0,0,0,.5); }
.hud-map { display: block; width: 360px; height: 248px; }
.hud-turn { position: absolute; top: 10px; left: 10px; display: grid; grid-template-columns: 44px auto; grid-template-rows: auto auto; align-items: center; column-gap: 8px; padding: 6px 12px 6px 6px; border-radius: 10px; background: rgba(12,16,18,.82); }
.hud-turn svg { grid-row: span 2; width: 44px; height: 44px; fill: none; stroke: #fff; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.hud-turn b { font: 700 18px/1.1 var(--mono); }
.hud-turn span { color: #a9bbb4; font-size: 11px; }
.hud-speed { position: absolute; top: 10px; right: 10px; display: grid; justify-items: center; gap: 4px; padding: 8px 10px; border-radius: 10px; background: rgba(12,16,18,.82); }
.hud-limit { display: grid; place-items: center; width: 40px; height: 40px; border: 5px solid #d3312a; border-radius: 50%; background: #f5f5f0; color: #111; font: 800 14px/1 var(--font); }
.hud-speed-value { text-align: center; }
.hud-speed-value b { display: block; font: 700 26px/1 var(--mono); }
.hud-speed-value span { color: #8fa39b; font-size: 9px; }
.hud-speed-value.over b { color: #ff7a5c; }
.hud-gear { color: #7fd6ff; font: 700 13px/1 var(--mono); }
.hud-cruise { min-height: 12px; color: #7fd6ff; font: 700 10px/1 var(--mono); }
.hud-cruise.auto { color: #58e08a; }
.hud-route { display: flex; justify-content: space-between; padding: 8px 12px; border-top: 1px solid rgba(255,255,255,.07); background: #0f1214; color: #c6d4cf; font-size: 12px; }

.hud-message { position: absolute; top: 18px; left: 50%; padding: 8px 16px; border-radius: 999px; background: rgba(10,14,13,.78); color: #f1f6f4; font-size: 13px; opacity: 0; transform: translate(-50%, -8px); transition: opacity .25s, transform .25s; }
.hud-message.visible { opacity: 1; transform: translate(-50%, 0); }

.hud-help { position: absolute; top: 50%; left: 50%; width: min(460px, calc(100% - 32px)); padding: 18px 22px; border: 1px solid rgba(255,255,255,.1); border-radius: 14px; background: rgba(10,14,13,.9); transform: translate(-50%, -50%); pointer-events: auto; }
.hud-help h2 { margin: 0 0 10px; font-size: 15px; }
.hud-help dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 12px; }
.hud-help dt { color: var(--accent); font-family: var(--mono); }
.hud-help dd { margin: 0; color: #cbd8d3; }

.hud-fullmap { position: absolute; inset: 40px; overflow: hidden; border: 1px solid rgba(255,255,255,.12); border-radius: 18px; background: #1b2023; box-shadow: 0 20px 60px rgba(0,0,0,.6); pointer-events: auto; }
.hud-fullmap canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.hud-fullmap-hint { position: absolute; bottom: 12px; left: 50%; padding: 6px 14px; border-radius: 999px; background: rgba(10,14,13,.8); color: #b9cbc4; font-size: 12px; transform: translateX(-50%); }

@media (max-width: 900px) {
  .hud-trip { width: auto; right: 14px; }
  .hud-navigator { width: 260px; }
  .hud-map { width: 260px; height: 180px; }
  .hud-fullmap { inset: 10px; }
}
