/*
 * Orbit — agent-native studio shell.
 *
 * The UI is an observation deck: it reports what the agent did, and offers no
 * approval, permission or editing affordances of its own.
 *
 * Layout — console on the left, live canvas on the right:
 *   ┌──────────────────────────────────────────────────────────────┐
 *   │  topbar                                    theme · collapse  │
 *   ├──────────────┬───────────────────────────────────────────────┤
 *   │ tool calls   │                                               │
 *   │ scene graph  │            live canvas (dominant)             │
 *   │ ─────────    │   grid + world axes + x/y/z gizmo bottom-left │
 *   │ tiny console │                                               │
 *   ├──────────────┴───────────────────────────────────────────────┤
 *   │  statusbar                                                   │
 *   └──────────────────────────────────────────────────────────────┘
 *
 * Visual language — black and white, modelled on ChatGPT's product surface:
 *   · Paper white chrome, ink black type. One accent: black (white in dark).
 *   · Inter, weights capped at 600, negative tracking on display sizes.
 *   · Pill controls, generous radii, hairline #e6e6e6 borders; tone and
 *     whitespace do the dividing, shadows are whispers.
 *   · Motion is the second material: 150–520ms on one ease-out curve,
 *     staggered entrances, sliding indicators, count-ups, a pulse on the
 *     canvas whenever the kernel mutates. Honors prefers-reduced-motion.
 */

/* ------------------------------------------------------------ tokens */

:root {
  color-scheme: light;

  /* paper + ink */
  --bg: #ffffff;
  --bg-panel: #ffffff;
  --bg-sunken: #f7f7f8;
  --bg-card: #ffffff;
  --bg-hover: #f2f2f3;
  --bg-active: #ebebec;
  --line: #e6e6e6;
  --line-soft: #f0f0f0;
  --line-strong: #d4d4d4;
  --text: #0d0d0d;
  --text-dim: #5b5b5b;
  --text-faint: #9a9a9a;

  /* the only accent is ink */
  --accent: #0d0d0d;
  --accent-ink: #ffffff;
  --accent-soft: rgba(13, 13, 13, 0.055);
  --accent-line: rgba(13, 13, 13, 0.16);
  --live: #0d0d0d;
  --error: #d1453b;
  --error-soft: rgba(209, 69, 59, 0.08);

  /* canvas */
  --canvas-bg: #f7f7f7;
  --grid-minor: #dcdcdc;
  --grid-major: #b9b9b9;
  --axis-ink: #6e6e6e;
  --gizmo-plate: rgba(255, 255, 255, 0.82);

  --shadow-1: 0 1px 2px rgba(16, 16, 16, 0.05);
  --shadow-2: 0 8px 24px -10px rgba(16, 16, 16, 0.22);
  --shadow-hud: 0 1px 2px rgba(16, 16, 16, 0.06), 0 6px 18px -12px rgba(16, 16, 16, 0.3);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;

  --panel-w: 288px;
  --topbar-h: 52px;
  --statusbar-h: 28px;

  --font-sans: "Söhne", "Inter", ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Söhne Mono", "JetBrains Mono", ui-monospace, SFMono-Regular,
    Menlo, Consolas, monospace;

  /* motion — one curve, four durations */
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-out-soft: cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast: 140ms;
  --t-med: 240ms;
  --t-slow: 420ms;
  --t-slower: 620ms;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0d0d0d;
  --bg-panel: #121212;
  --bg-sunken: #0f0f0f;
  --bg-card: #161616;
  --bg-hover: #1e1e1e;
  --bg-active: #252525;
  --line: #262626;
  --line-soft: #1c1c1c;
  --line-strong: #3a3a3a;
  --text: #f5f5f5;
  --text-dim: #a3a3a3;
  --text-faint: #6f6f6f;

  --accent: #ffffff;
  --accent-ink: #0d0d0d;
  --accent-soft: rgba(255, 255, 255, 0.08);
  --accent-line: rgba(255, 255, 255, 0.22);
  --live: #ffffff;
  --error: #f87171;
  --error-soft: rgba(248, 113, 113, 0.1);

  --canvas-bg: #0d0d0d;
  --grid-minor: #1e1e1e;
  --grid-major: #333333;
  --axis-ink: #9a9a9a;
  --gizmo-plate: rgba(18, 18, 18, 0.78);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 10px 30px -12px rgba(0, 0, 0, 0.8);
  --shadow-hud: 0 1px 2px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  font-feature-settings: "calt" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  transition: background var(--t-slow) var(--ease), color var(--t-slow) var(--ease);
}

code, .mono { font-family: var(--font-mono); font-size: 0.92em; }

::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 2px;
  border-radius: 4px;
}

button { font: inherit; }

/* ------------------------------------------------------------ motion */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes drop-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: none; }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes slide-in-left {
  from { opacity: 0; transform: translateX(-18px); }
  to { opacity: 1; transform: none; }
}
@keyframes canvas-in {
  from { opacity: 0; transform: scale(1.012); }
  to { opacity: 1; transform: none; }
}
@keyframes call-in {
  0% { opacity: 0; transform: translateY(-6px) scale(0.985); filter: blur(2px); }
  60% { filter: blur(0); }
  100% { opacity: 1; transform: none; filter: blur(0); }
}
@keyframes tick-draw {
  from { transform: scaleY(0); opacity: 0; }
  to { transform: scaleY(1); opacity: 1; }
}
@keyframes orbit-spin {
  from { transform: rotate(45deg); }
  to { transform: rotate(405deg); }
}
@keyframes breathe {
  0% { box-shadow: 0 0 0 0 var(--accent-line); }
  70% { box-shadow: 0 0 0 5px rgba(128, 128, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(128, 128, 128, 0); }
}
@keyframes canvas-pulse {
  0% { opacity: 0; transform: scale(0.994); }
  22% { opacity: 1; }
  100% { opacity: 0; transform: scale(1); }
}
@keyframes sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(320%); }
}
@keyframes sheen {
  from { transform: translateX(-140%) skewX(-18deg); }
  to { transform: translateX(240%) skewX(-18deg); }
}
@keyframes chip-in {
  from { opacity: 0; transform: translateY(4px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes gizmo-in {
  from { opacity: 0; transform: scale(0.7) rotate(-24deg); }
  to { opacity: 1; transform: none; }
}
@keyframes number-pop {
  0% { transform: translateY(0); }
  40% { transform: translateY(-1.5px); }
  100% { transform: translateY(0); }
}

/* staggered boot — the shell assembles itself, left to right */
.topbar { animation: drop-in var(--t-slow) var(--ease) both; }
.panel-left { animation: slide-in-left var(--t-slower) var(--ease-out-soft) 60ms both; }
.viewport-wrap { animation: fade-in 700ms var(--ease) 100ms both; }
.viewport canvas { animation: canvas-in 900ms var(--ease-out-soft) 140ms both; }
.statusbar { animation: rise-in var(--t-slow) var(--ease) 200ms both; }
.viewport-hud { animation: drop-in var(--t-slower) var(--ease-out-soft) 320ms both; }
.gizmo { animation: gizmo-in var(--t-slower) var(--ease-out-soft) 420ms both; }
.viewport-readout { animation: rise-in var(--t-slower) var(--ease-out-soft) 420ms both; }
.console { animation: rise-in var(--t-slower) var(--ease-out-soft) 240ms both; }

/* ------------------------------------------------------------ shell */

.app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--statusbar-h);
  height: 100vh;
  height: 100dvh;
}

/* ------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  transition: background var(--t-slow) var(--ease), border-color var(--t-slow) var(--ease);
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  position: relative;
  width: 20px; height: 20px;
  display: inline-block;
  flex-shrink: 0;
}
.brand-mark i {
  position: absolute; inset: 0;
  border: 1.4px solid var(--text);
  border-radius: 50%;
  transition: border-color var(--t-slow) var(--ease);
}
.brand-mark i:nth-child(1) { opacity: 0.9; }
.brand-mark i:nth-child(2) {
  opacity: 0.42;
  border-style: dashed;
  animation: orbit-spin 24s linear infinite;
}
.brand-mark i:nth-child(3) {
  inset: 6.5px;
  border: none;
  background: var(--text);
  opacity: 0.95;
  transition: background var(--t-slow) var(--ease);
}
.brand:hover .brand-mark i:nth-child(2) { animation-duration: 5s; }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong {
  font-size: 14.5px; font-weight: 600;
  letter-spacing: -0.025em;
}
.brand-text small {
  font-size: 9.5px; font-weight: 500;
  color: var(--text-faint);
  letter-spacing: 0.045em;
}

.topbar-status { display: flex; gap: 6px; margin-left: 6px; min-width: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-dim);
  white-space: nowrap;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
    background var(--t-slow) var(--ease);
}
.chip .dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--live);
  animation: breathe 2.6s var(--ease) infinite;
}
.chip-solid {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  transition: background var(--t-slow) var(--ease), color var(--t-slow) var(--ease);
}

.topbar-stats { display: flex; gap: 20px; margin-left: auto; }
.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.stat b {
  font-family: var(--font-mono);
  font-size: 12.5px; font-weight: 500;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat b.is-counting { animation: number-pop var(--t-med) var(--ease-out-soft); }
.stat small {
  font-size: 8.5px; font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase; letter-spacing: 0.09em;
}

.topbar-actions { display: flex; gap: 6px; align-items: center; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.icon-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--bg-hover);
}
.icon-btn:active { transform: scale(0.94); }

/* theme toggle — sun in light, moon in dark, cross-faded + rotated */
#theme-toggle svg { grid-area: 1 / 1; transition: opacity var(--t-med) var(--ease), transform var(--t-slow) var(--ease-out-soft); }
#theme-toggle .ico-sun { opacity: 1; transform: rotate(0deg) scale(1); }
#theme-toggle .ico-moon { opacity: 0; transform: rotate(-70deg) scale(0.7); }
[data-theme="dark"] #theme-toggle .ico-sun { opacity: 0; transform: rotate(70deg) scale(0.7); }
[data-theme="dark"] #theme-toggle .ico-moon { opacity: 1; transform: rotate(0deg) scale(1); }

#panel-toggle svg { display: block; }
#panel-toggle .ico-pane { transition: transform var(--t-slow) var(--ease-out-soft); }
#panel-toggle.is-collapsed .ico-pane { transform: translateX(-4px); }
#panel-toggle.is-collapsed { color: var(--text-faint); }

/* --------------------------------------------------------- workspace */

.workspace {
  display: flex;
  min-height: 0;
  background: var(--bg);
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  transition: background var(--t-slow) var(--ease);
}

.panel-left {
  position: relative;
  flex: 0 0 var(--panel-w);
  width: var(--panel-w);
  border-right: 1px solid var(--line);
  transition: flex-basis var(--t-slower) var(--ease-out-soft),
    width var(--t-slower) var(--ease-out-soft),
    border-color var(--t-slower) var(--ease),
    background var(--t-slow) var(--ease);
}

/* collapse — the console slides away and the canvas takes the whole width */
.panel-left > * {
  transition: opacity var(--t-med) var(--ease), transform var(--t-slower) var(--ease-out-soft);
}
.workspace[data-collapsed="true"] .panel-left {
  flex-basis: 0;
  width: 0;
  border-right-color: transparent;
}
.workspace[data-collapsed="true"] .panel-left > * {
  opacity: 0;
  transform: translateX(-12px);
  pointer-events: none;
}

/* -------------------------------------------------------- panel head */

.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px 8px 12px;
  flex-shrink: 0;
  position: relative;
}
.panel-head::after {
  /* hairline activity sweep — lights up while a tool call resolves */
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: var(--line);
  transition: background var(--t-slow) var(--ease);
}
.app.is-busy .panel-head::after {
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: sweep 720ms var(--ease) infinite;
}

.tabs {
  position: relative;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg-sunken);
  /* inset ring instead of a border, so the sliding indicator's offsets are
     measured from the same box the tabs themselves are laid out in */
  box-shadow: inset 0 0 0 1px var(--line);
  border-radius: var(--radius-pill);
}
.tab {
  position: relative;
  z-index: 1;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px;
  background: none;
  border: none;
  border-radius: var(--radius-pill);
  color: var(--text-faint);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--t-med) var(--ease);
}
.tab:hover { color: var(--text-dim); }
.tab.is-active { color: var(--text); }
.tab-count {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--text-dim);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
    transform var(--t-med) var(--ease-out-soft);
}
.tab.is-active .tab-count { background: var(--accent); color: var(--accent-ink); }
.tab-count.is-bumped { transform: scale(1.16); }

/* the sliding pill */
.tab-indicator {
  position: absolute;
  top: 2px; bottom: 2px; left: 0;
  width: 0;
  background: var(--bg-card);
  border-radius: var(--radius-pill);
  box-shadow: inset 0 0 0 1px var(--line), var(--shadow-1);
  transform: translateX(2px);
  transition: transform var(--t-slow) var(--ease-out-soft),
    width var(--t-slow) var(--ease-out-soft),
    background var(--t-slow) var(--ease);
}

.link-btn {
  background: none; border: none;
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 11px; font-weight: 500;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.link-btn:hover { color: var(--text); background: var(--bg-hover); }

/* ---------------------------------------------------------- tab panes */

.tab-panes { position: relative; flex: 1; min-height: 0; display: flex; }
.tab-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  animation: pane-in var(--t-slow) var(--ease-out-soft) both;
}
.tab-pane[hidden] { display: none; }
@keyframes pane-in {
  from { opacity: 0; transform: translateX(6px); }
  to { opacity: 1; transform: none; }
}

.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px; min-height: 0; }
.scroll-short { flex: 0 0 auto; max-height: 46%; border-top: 1px solid var(--line); }

.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: content-box;
  transition: background var(--t-fast) var(--ease);
}
.scroll:hover::-webkit-scrollbar-thumb { background: var(--line-strong); background-clip: content-box; }
.scroll::-webkit-scrollbar-track { background: transparent; }

.empty {
  padding: 18px 10px;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.6;
}

.panel-subhead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
  flex-shrink: 0;
}
.panel-subhead h2 {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-faint);
}
.badge {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------ object rows */

.row {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 7px 9px;
  margin-bottom: 2px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: inherit;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease-out-soft), box-shadow var(--t-fast) var(--ease);
}
/* staggered entrance, replayed only on the render that changed the list */
.scroll.is-animating .row { animation: chip-in var(--t-med) var(--ease-out-soft) both; }
.scroll.is-animating .row:nth-child(1) { animation-delay: 0ms; }
.scroll.is-animating .row:nth-child(2) { animation-delay: 26ms; }
.scroll.is-animating .row:nth-child(3) { animation-delay: 52ms; }
.scroll.is-animating .row:nth-child(4) { animation-delay: 78ms; }
.scroll.is-animating .row:nth-child(5) { animation-delay: 104ms; }
.scroll.is-animating .row:nth-child(6) { animation-delay: 130ms; }
.scroll.is-animating .row:nth-child(7) { animation-delay: 156ms; }
.scroll.is-animating .row:nth-child(8) { animation-delay: 182ms; }
.row:hover {
  background: var(--bg-hover);
  border-color: var(--line-strong);
  transform: translateX(2px);
}
.row.is-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.row.is-selected .row-meta,
.row.is-selected .row-tag { color: var(--accent-ink); opacity: 0.72; }
.row.is-selected .row-tag { background: transparent; border-color: var(--accent-line); }

.row-swatch {
  width: 11px; height: 11px;
  border-radius: 3px;
  border: 1px solid var(--accent-line);
  flex-shrink: 0;
  transition: transform var(--t-med) var(--ease-out-soft);
}
.row:hover .row-swatch { transform: scale(1.18) rotate(45deg); }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-name {
  font-size: 12.5px; font-weight: 500;
  letter-spacing: -0.008em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-meta {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-tag {
  font-family: var(--font-mono); font-size: 9px;
  padding: 1px 6px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--text-dim);
}

/* ------------------------------------------------------ detail list */

.kv { display: flex; flex-direction: column; gap: 1px; padding: 4px; }
.kv > div {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 8px;
  padding: 3.5px 8px;
  border-radius: 6px;
  transition: background var(--t-fast) var(--ease);
}
.scroll.is-animating .kv > div { animation: fade-in var(--t-med) var(--ease) both; }
.kv > div:hover { background: var(--bg-hover); }
.kv dt {
  font-size: 9.5px; font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase; letter-spacing: 0.055em;
  padding-top: 1px;
}
.kv dd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text);
  word-break: break-word;
}

/* -------------------------------------------------------- viewport */

.viewport-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background: var(--canvas-bg);
  transition: background var(--t-slow) var(--ease);
}

.viewport { position: absolute; inset: 0; }
.viewport canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* paper depth: a whisper of light from above, falloff at the edges */
.viewport-vignette {
  position: absolute; inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, 0.55), transparent 52%),
    radial-gradient(140% 120% at 50% 58%, transparent 66%, rgba(0, 0, 0, 0.055) 100%);
  transition: opacity var(--t-slow) var(--ease);
}
[data-theme="dark"] .viewport-vignette {
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, 0.045), transparent 46%),
    radial-gradient(140% 120% at 50% 55%, transparent 58%, rgba(0, 0, 0, 0.45) 100%);
}

/* mutation pulse — a hairline ring breathes whenever the kernel changes */
.viewport-pulse {
  position: absolute; inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  border: 1px solid var(--accent-line);
  border-radius: 2px;
}
.viewport-pulse.is-on { animation: canvas-pulse 700ms var(--ease-out-soft); }

.viewport-fallback {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 10px; padding: 30px;
  color: var(--text-dim); text-align: center;
}

.viewport-hud {
  position: absolute; top: 12px; left: 12px; right: 12px;
  z-index: 3;
  display: flex; justify-content: space-between; gap: 8px;
  pointer-events: none;
}
.hud-group {
  display: flex; gap: 3px; padding: 3px;
  pointer-events: auto;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-hud);
  transition: background var(--t-slow) var(--ease), border-color var(--t-slow) var(--ease);
}
.hud-group button {
  padding: 4px 11px;
  background: transparent;
  border: none;
  border-radius: var(--radius-pill);
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease-out-soft);
}
.hud-group button:hover { color: var(--text); background: var(--bg-hover); }
.hud-group button:active { transform: scale(0.95); }
.hud-group button.is-on {
  color: var(--accent-ink);
  background: var(--accent);
}

/* x / y / z direction indicator — small, bottom-left of the canvas */
.gizmo {
  position: absolute;
  left: 12px; bottom: 12px;
  z-index: 3;
  width: 62px; height: 62px;
  display: grid; place-items: center;
  pointer-events: auto;
  transform-origin: 50% 50%;
  transition: transform var(--t-med) var(--ease-out-soft), opacity var(--t-med) var(--ease);
}
.gizmo:hover { transform: scale(1.08); }
.gizmo svg { width: 100%; height: 100%; overflow: visible; }
.gizmo-plate {
  fill: var(--gizmo-plate);
  stroke: var(--line);
  stroke-width: 1;
  backdrop-filter: blur(8px);
  transition: fill var(--t-slow) var(--ease), stroke var(--t-slow) var(--ease);
}
.gizmo line {
  stroke: var(--axis-ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  transition: stroke var(--t-slow) var(--ease);
}
.gizmo-neg line {
  stroke-dasharray: 2 3;
  stroke-opacity: 0.4;
}
.gizmo-knob {
  fill: var(--accent);
  stroke: var(--bg-card);
  stroke-width: 1.4;
  transition: fill var(--t-slow) var(--ease), r var(--t-fast) var(--ease-out-soft);
}
.gizmo text {
  fill: var(--accent-ink);
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-anchor: middle;
  pointer-events: none;
  transition: fill var(--t-slow) var(--ease);
}
.gizmo [data-axis] { cursor: pointer; }
.gizmo [data-axis]:hover .gizmo-knob { r: 12; }
.gizmo [data-axis]:hover line { stroke: var(--text); stroke-width: 2; }
.gizmo [data-axis]:focus-visible { outline: none; }
.gizmo [data-axis]:focus-visible .gizmo-knob { stroke: var(--accent); r: 12.5; }
.gizmo.is-hidden { opacity: 0; transform: scale(0.6); pointer-events: none; }

.viewport-readout {
  position: absolute; bottom: 12px; right: 12px;
  z-index: 3;
  max-width: min(58%, 420px);
  padding: 4px 11px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-hud);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background var(--t-slow) var(--ease), border-color var(--t-slow) var(--ease);
}

/* ------------------------------------------------------ call stream */

.call {
  position: relative;
  padding: 7px 9px 7px 12px;
  margin-bottom: 5px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  animation: call-in var(--t-med) var(--ease-out-soft) both;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease-out-soft), box-shadow var(--t-fast) var(--ease);
}
.call::before {
  /* the tick — draws itself down the left edge on arrival */
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--line-strong);
  transform-origin: 50% 0;
  animation: tick-draw var(--t-slow) var(--ease-out-soft) both;
  transition: background var(--t-fast) var(--ease);
}
.call:hover {
  border-color: var(--line-strong);
  background: var(--bg-hover);
  transform: translateX(2px);
}
.call:hover::before { background: var(--accent); }
.call.is-error { border-color: rgba(209, 69, 59, 0.35); background: var(--error-soft); }
.call.is-error::before { background: var(--error); }
.call.is-error:hover { border-color: var(--error); }
.call.is-fresh { box-shadow: var(--shadow-2); }

.call-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.call-head code {
  font-size: 11.5px; font-weight: 500; color: var(--text);
  letter-spacing: -0.01em;
}
.call-ms {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.call-args {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-faint);
  word-break: break-all;
  margin-top: 2px;
  line-height: 1.45;
}
.call-error {
  margin-top: 4px;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--error);
}
.call-error em { color: var(--text-dim); font-style: normal; }

/* --------------------------------------------------------- console */

.console {
  flex-shrink: 0;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
  transition: background var(--t-slow) var(--ease), border-color var(--t-slow) var(--ease);
}
.console-row {
  display: flex; align-items: center; gap: 6px;
  padding: 0 4px 0 9px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}
.console-row:hover { border-color: var(--line-strong); }
.console-row.is-focused {
  background: var(--bg-card);
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.console-caret {
  color: var(--text-faint);
  flex-shrink: 0;
  transition: color var(--t-fast) var(--ease), transform var(--t-med) var(--ease-out-soft);
}
.console-row.is-focused .console-caret { color: var(--text); transform: translateX(1px); }
.console-row input {
  flex: 1;
  min-width: 0;
  padding: 6px 0;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: -0.01em;
}
.console-row input:focus { outline: none; }
.console-row input::placeholder { color: var(--text-faint); }

.console-row button {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px;
  flex-shrink: 0;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  color: var(--accent-ink);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform var(--t-fast) var(--ease-out-soft), opacity var(--t-fast) var(--ease),
    background var(--t-slow) var(--ease);
}
.console-row button::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: translateX(-140%) skewX(-18deg);
  pointer-events: none;
}
.console-row button:hover::after { animation: sheen 620ms var(--ease-out-soft); }
.console-row button:hover { transform: scale(1.06); }
.console-row button:active { transform: scale(0.92); }

.console-quick {
  display: flex;
  gap: 4px;
  margin-top: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 1px;
  mask-image: linear-gradient(90deg, #000 88%, transparent);
  -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent);
}
.console-quick::-webkit-scrollbar { height: 0; }
.console-quick button {
  flex-shrink: 0;
  padding: 2.5px 9px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  cursor: pointer;
  animation: chip-in var(--t-med) var(--ease-out-soft) both;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease-out-soft);
}
.console-quick button:nth-child(1) { animation-delay: 240ms; }
.console-quick button:nth-child(2) { animation-delay: 270ms; }
.console-quick button:nth-child(3) { animation-delay: 300ms; }
.console-quick button:nth-child(4) { animation-delay: 330ms; }
.console-quick button:nth-child(5) { animation-delay: 360ms; }
.console-quick button:nth-child(6) { animation-delay: 390ms; }
.console-quick button:nth-child(7) { animation-delay: 420ms; }
.console-quick button:nth-child(8) { animation-delay: 450ms; }
.console-quick button:nth-child(9) { animation-delay: 480ms; }
.console-quick button:hover {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.console-quick button:active { transform: translateY(0) scale(0.96); }

/* -------------------------------------------------------- statusbar */

.statusbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 14px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  color: var(--text-faint);
  transition: background var(--t-slow) var(--ease), border-color var(--t-slow) var(--ease);
}
.statusbar > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statusbar code { color: var(--text-dim); }
.statusbar-right { display: flex; gap: 12px; align-items: center; flex-shrink: 0; }
.statusbar a {
  color: var(--text-faint);
  text-decoration: none;
  font-weight: 500;
  position: relative;
  transition: color var(--t-fast) var(--ease);
}
.statusbar a::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -2px;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform var(--t-med) var(--ease-out-soft);
}
.statusbar a:hover { color: var(--text); }
.statusbar a:hover::after { transform: scaleX(1); }

/* -------------------------------------------------------- responsive */

@media (max-width: 1040px) {
  :root { --panel-w: 258px; }
  .topbar-stats { gap: 14px; }
  .chip-live #bridge-label { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
}

@media (max-width: 820px) {
  .topbar-stats, #autonomy-chip { display: none; }
}

@media (max-width: 680px) {
  /* the console becomes a drawer over the canvas */
  .panel-left {
    position: absolute;
    z-index: 20;
    top: 0; bottom: 0; left: 0;
    height: 100%;
    box-shadow: var(--shadow-2);
  }
  .workspace { position: relative; }
  .workspace[data-collapsed="true"] .panel-left { box-shadow: none; }
  .brand-text small { display: none; }
  .chip-live { display: none; }
  .gizmo { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
