:root {
  --bg: #070b16;
  --panel: #0e1424;
  --panel-2: #141b30;
  --line: #222c47;
  --text: #dfe6f5;
  --muted: #8592b0;
  --accent: #ffd27a;
  --accent-2: #7fb2ff;
  --ok: #7ddca0;
  --warn: #ffb36b;
  --bad: #ff7b7b;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent-2); }

#layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; height: 100vh; }

/* ---- stage ---- */
#stage { position: relative; overflow: hidden; }
#sky { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#sky:active { cursor: grabbing; }

#hud { position: absolute; top: 14px; left: 16px; pointer-events: none; text-shadow: 0 1px 3px #000; }
#hud-place { font-weight: 600; font-size: 15px; }
#hud-time { color: var(--muted); font-variant-numeric: tabular-nums; }
#hud-rate { color: var(--accent); font-size: 12px; margin-left: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#timebar { pointer-events: auto; display: flex; align-items: center; gap: 4px; margin-top: 8px; }
#timebar button { width: 34px; height: 30px; display: grid; place-items: center; padding: 0; border-radius: 8px; cursor: pointer;
  background: rgba(20, 27, 48, .85); border: 1px solid var(--line); color: var(--muted); }
#timebar button svg { width: 16px; height: 16px; fill: currentColor; }
#timebar button:hover { color: var(--text); border-color: var(--accent-2); }
#timebar button[aria-pressed="true"] { color: var(--bg); background: var(--accent); border-color: var(--accent); }
#timebar button.now { width: auto; padding: 0 10px; font: inherit; font-size: 12.5px; font-weight: 600; }

#card { position: absolute; top: 14px; right: 16px; width: min(320px, calc(100% - 32px)); background: rgba(14, 20, 36, 0.92);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; backdrop-filter: blur(6px); }
#card h3 { margin: 0 24px 8px 0; font-size: 15px; color: var(--accent); }
#card dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
#card dt { color: var(--muted); }
#card dd { margin: 0; }
#card dd.click, #card dt.click { cursor: pointer; text-decoration: underline dotted; }
#card-close { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; }

#toast { position: absolute; left: 50%; bottom: 112px; transform: translateX(-50%); max-width: min(640px, calc(100% - 32px));
  background: rgba(14, 20, 36, 0.92); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; opacity: 0;
  transition: opacity .3s; pointer-events: none; text-align: center; }
#toast.show { opacity: 1; }
#toast.bad { border-color: var(--bad); }

#command { position: absolute; left: 50%; bottom: 52px; transform: translateX(-50%); width: min(640px, calc(100% - 32px));
  display: flex; gap: 8px; }
#query { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(14, 20, 36, 0.92); color: var(--text); }
#query:focus { outline: 2px solid var(--accent-2); outline-offset: 0; }
#command button { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 10px; padding: 0 16px; font: inherit; cursor: pointer; }
#command button:disabled { opacity: .45; cursor: default; }
#go { background: #24345e; }
#mic { width: 46px; padding: 0; display: grid; place-items: center; }
#mic.rec { background: #5a1f2a; border-color: var(--bad); color: #fff; animation: pulse 1s infinite; }
#mic.busy { opacity: .6; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 123, 123, .2); } }

#chips { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); width: min(900px, calc(100% - 32px));
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; justify-content: safe center; flex-wrap: nowrap; }
#chips::-webkit-scrollbar { display: none; }
#chips button { flex: none; background: rgba(20, 27, 48, .85); border: 1px solid var(--line); color: var(--muted); border-radius: 999px;
  padding: 4px 11px; font: inherit; font-size: 12.5px; cursor: pointer; }
#chips button:hover { color: var(--text); border-color: var(--accent-2); }

/* ---- inspector ---- */
#inspector { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 16px 16px 24px; }
#inspector h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
#inspector .sub { margin: 4px 0 12px; color: var(--muted); font-size: 13px; }
#model-switch { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 3px; }
#model-switch button { background: none; border: 0; color: var(--muted); padding: 6px 4px; border-radius: 6px; font: inherit; font-size: 13px; cursor: pointer; }
#model-switch button[aria-checked="true"] { background: #24345e; color: var(--text); }
#model-switch button:disabled { opacity: .4; cursor: default; }
#load-status { margin-top: 8px; font-size: 12px; color: var(--muted); min-height: 1.2em; }
.bar { height: 4px; background: var(--panel-2); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--accent-2); width: 0; transition: width .2s; }

.panel { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.panel h2 button { margin-left: auto; text-transform: none; letter-spacing: 0; font: inherit; font-size: 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 10px; cursor: pointer; }
.panel h2 button:disabled { opacity: .4; cursor: default; }
.hint { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--muted); font-size: 10px; cursor: help; }
.muted { color: var(--muted); }
.caption { color: var(--muted); font-size: 12px; margin: 6px 0 0; }

.spans { font-size: 16px; line-height: 1.9; margin: 0 0 10px; }
.span { border-radius: 4px; padding: 1px 3px; }
.span small { font-size: 10px; vertical-align: super; margin-left: 2px; opacity: .85; }

.call { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.call.suppressed { opacity: .65; border-style: dashed; }
.call .head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.call .who { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.call .ms { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.call pre { margin: 0; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.call pre .fn { color: var(--accent); }
.call pre .k { color: var(--accent-2); }
.call pre .s { color: var(--ok); }
.call .result { margin-top: 6px; font-size: 13px; }
.call .result.bad { color: var(--warn); }
.call .none { color: var(--muted); font-style: italic; }
.conf { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.conf .meter { flex: 1; height: 6px; background: #0a0f1c; border-radius: 3px; overflow: hidden; position: relative; }
.conf .meter i { position: absolute; inset: 0 auto 0 0; border-radius: 3px; }
.conf .meter b { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--muted); left: 10%; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

#toolmap { width: 100%; display: block; background: radial-gradient(ellipse at center, #121a33 0%, #0a0f1c 70%); border-radius: 8px; border: 1px solid var(--line); }

.why { display: flex; flex-wrap: wrap; gap: 6px 4px; align-items: flex-end; }
.why .w { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 13px; }
.why .w i { display: block; width: 100%; min-width: 14px; border-radius: 2px 2px 0 0; background: var(--accent); }
.why .w.flip i { background: var(--bad); }
.why-legend { font-size: 12px; color: var(--muted); margin-top: 8px; }

.speed { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.speed div { background: var(--panel-2); border-radius: 8px; padding: 8px; }
.speed b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; color: var(--text); }
.speed span { font-size: 11px; color: var(--muted); }

#history { margin: 0; padding-left: 20px; font-size: 13px; color: var(--muted); max-height: 200px; overflow-y: auto; }
#history li { margin-bottom: 3px; cursor: pointer; }
#history li:hover { color: var(--text); }
#history li .ok { color: var(--ok); }
#history li .no { color: var(--warn); }

#inspector footer { margin-top: 18px; font-size: 11px; color: var(--muted); }

@media (max-width: 900px) {
  #layout { grid-template-columns: 1fr; grid-template-rows: 62vh auto; height: auto; }
  #stage { height: 62vh; }
  #inspector { border-left: 0; border-top: 1px solid var(--line); }
  #card { top: auto; bottom: 150px; }
  #chips { justify-content: flex-start; }
  #toast { bottom: 150px; }
}
