/* Moxie SIL — mission-control HUD skin.
 * Design language: docs/design/style-guide.md (valpatel.com control-room).
 * Void background + 3D hero, right rail of grouped HUD panels, mono telemetry
 * labels, neon-cyan accents, mint/magenta/amber state colors. Fonts vendored
 * (vendor/fonts/fonts.css) — fully offline.
 *
 * Layout: the WebGL canvas (#app) is fixed fullscreen behind everything.
 * #hud is a fixed grid overlay:  topbar / notice / [stage | rail].
 * The rail (#panel) scrolls independently; on phone widths it becomes a
 * bottom drawer toggled by #rail-toggle so the robot stays visible. */

:root {
  /* backgrounds — deepest → elevated */
  --void:      #060609;
  --bg:        #0a0a0f;
  --surface-1: #0e0e14;
  --surface-2: #12121a;
  --surface-3: #1a1a2e;
  --hairline:  #2a303c;

  /* text — cool grey ramp */
  --text:      #e8edf5;
  --text-dim:  #c8d0dc;
  --muted:     #8892a4;
  --muted-2:   #6b7a8d;
  --dim:       #5a6577;
  --dimmer:    #4a5568;

  /* accents */
  --cyan:      #00f0ff;
  --cyan-dim:  #0e7490;
  --amber:     #fcee0a;
  --mint:      #05ffa1;
  --magenta:   #ff2a6d;
  --purple:    #a855f7;

  /* cyan at low alpha — ambient glow / hairlines */
  --glow-06:   rgba(0, 240, 255, 0.06);
  --glow-12:   rgba(0, 240, 255, 0.12);
  --glow-30:   rgba(0, 240, 255, 0.30);

  --font-ui:   'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  /* spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;

  --rail-w: 380px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

/* ---- void atmosphere ------------------------------------------------------ */
/* behind the (alpha) WebGL canvas: a faint cyan aura where the robot stands,
   a vignette pulling the edges down toward --void */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(55% 48% at 42% 46%, var(--glow-06) 0%, transparent 70%),
    radial-gradient(130% 100% at 50% 45%, transparent 45%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(180deg, var(--bg) 0%, var(--void) 100%);
}

/* over the canvas, under the HUD: a whisper of scanline */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 240, 255, 0.016) 0px,
    rgba(0, 240, 255, 0.016) 1px,
    transparent 1px,
    transparent 3px
  );
}

#app, #app canvas {
  position: fixed;
  inset: 0;
  display: block;
}
#app { z-index: 1; }

/* ---- HUD overlay grid ----------------------------------------------------- */
#hud {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail-w);
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar"
    "notice notice"
    "stage  panel";
  pointer-events: none;          /* let orbit-drag reach the canvas… */
}
#topbar, #notice, #panel { pointer-events: auto; }   /* …except real HUD chrome */

/* ---- title bar ------------------------------------------------------------ */
#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 48px;
  padding: 0 var(--sp-4);
  background: linear-gradient(180deg, rgba(6, 6, 9, 0.92), rgba(6, 6, 9, 0.78));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}
#topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
#topbar .glyph {
  width: 9px;
  height: 9px;
  background: var(--cyan);
  transform: rotate(45deg);
  box-shadow: 0 0 10px var(--glow-30);
  flex: none;
}
#topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}
#topbar h1 .sep {
  color: var(--cyan);
  padding: 0 5px;
  font-weight: 400;
}
#topbar .tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
}
#topbar .tag.dim { color: var(--dim); border-color: transparent; }
#topbar .linkstate {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: none;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--muted);
  white-space: nowrap;
}

/* link lamp — colored via body[data-bus] (set by the HUD glue script) */
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dimmer);
  flex: none;
}
body[data-bus="live"] .dot { background: var(--mint);    box-shadow: 0 0 8px rgba(5, 255, 161, 0.6);  animation: pulse 2s ease-in-out infinite; }
body[data-bus="down"] .dot { background: var(--magenta); box-shadow: 0 0 8px rgba(255, 42, 109, 0.6); }
body[data-bus="rec"]  .dot { background: var(--amber);   box-shadow: 0 0 8px rgba(252, 238, 10, 0.55); animation: pulse 1.2s ease-in-out infinite; }
body[data-bus="wait"] .dot { background: var(--cyan);    box-shadow: 0 0 8px var(--glow-30);           animation: pulse 1.2s ease-in-out infinite; }
body[data-bus="live"] #link-label { color: var(--mint); }
body[data-bus="down"] #link-label { color: var(--magenta); }
body[data-bus="rec"]  #link-label { color: var(--amber); }
body[data-bus="wait"] #link-label { color: var(--cyan); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ---- disclaimer bar ------------------------------------------------------- */
/* Legal/ethical notice gets its own slim bar under the topbar: full width,
   readable size + contrast, and an unmistakable GitHub affordance. */
#notice {
  grid-area: notice;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 6px var(--sp-4);
  background: rgba(6, 6, 9, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
  box-shadow: 0 1px 0 var(--glow-06);
}
.notice-badge {
  flex: none;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--amber);
  border: 1px solid rgba(252, 238, 10, 0.35);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
}
.disclaimer {
  margin: 0;
  min-width: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}
.disclaimer strong { color: var(--text); font-weight: 600; }
.notice-link {
  flex: none;
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--cyan);
  border: 1px solid var(--glow-30);
  border-radius: 4px;
  padding: 4px 10px;
  white-space: nowrap;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.notice-link:hover {
  background: rgba(0, 240, 255, 0.08);
  box-shadow: 0 0 10px var(--glow-12);
}

/* ---- stage overlays ------------------------------------------------------- */
#stage {
  grid-area: stage;
  position: relative;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
}

#hud-frame { display: none; }   /* removed: the 3D is the full-screen background, not one framed section */
#hud-frame .corner {
  position: absolute;
  width: 20px;
  height: 20px;
}
#hud-frame .tl { top: 0;    left: 0;    border-top: 1px solid var(--glow-30);    border-left: 1px solid var(--glow-30); }
#hud-frame .tr { top: 0;    right: 0;   border-top: 1px solid var(--glow-30);    border-right: 1px solid var(--glow-30); }
#hud-frame .bl { bottom: 0; left: 0;    border-bottom: 1px solid var(--glow-30); border-left: 1px solid var(--glow-30); }
#hud-frame .br { bottom: 0; right: 0;   border-bottom: 1px solid var(--glow-30); border-right: 1px solid var(--glow-30); }

/* ---- speech callout ------------------------------------------------------- */
#bubble {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(420px, calc(100% - 32px));
  min-width: min(220px, calc(100% - 32px));
  pointer-events: auto;
  padding: 9px 14px 12px;
  background: rgba(14, 14, 20, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--glow-30);
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--glow-06), 0 0 28px var(--glow-06);
  opacity: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#bubble .callout-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 5px;
}
#bubble-text {
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
}
/* typewriter caret — blinks while Moxie's line is typing out */
#bubble.typing #bubble-text::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -0.16em;
  background: var(--cyan);
  box-shadow: 0 0 6px var(--glow-30);
  animation: caret-blink 0.75s steps(1, end) infinite;
}
@keyframes caret-blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  #bubble.typing #bubble-text::after { animation: none; opacity: 1; }
}
/* corner tick + downward connector toward the robot */
#bubble::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  width: 12px;
  height: 12px;
  border-top: 2px solid var(--cyan);
  border-left: 2px solid var(--cyan);
  border-radius: 6px 0 0 0;
}
#bubble::after {
  content: "";
  position: absolute;
  bottom: -19px;
  left: 50%;
  width: 1px;
  height: 18px;
  background: linear-gradient(180deg, var(--glow-30), transparent);
}
#bubble.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-8px);
  pointer-events: none;
}

/* ---- stage hint ----------------------------------------------------------- */
#scene-hint {
  position: absolute;
  left: 26px;
  bottom: 24px;
  pointer-events: none;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--dim);
}
#scene-hint code {
  font-family: inherit;
  color: var(--cyan-dim);
}

/* ---- HUD rail ------------------------------------------------------------- */
#panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 10px 10px 10px 0;               /* float, don't touch the edges */
  background: rgba(9, 12, 19, 0.30);       /* GLASS — the 3D shows through */
  backdrop-filter: blur(22px) saturate(1.15);
  -webkit-backdrop-filter: blur(22px) saturate(1.15);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.42);
  overflow: hidden;
}
#rail-scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3) 20px;
}

/* drawer handle — hidden on desktop, shown in phone/drawer mode */
#rail-toggle {
  display: none;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: 44px;
  padding: 0 var(--sp-4);
  border: none;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  background: rgba(10, 10, 15, 0.9);
  font-size: 11px;
  letter-spacing: 0.12em;
}
#rail-toggle .tick {
  width: 12px;
  height: 2px;
  background: var(--cyan);
  box-shadow: 0 0 6px var(--glow-30);
  flex: none;
}
#rail-toggle .caret { margin-left: auto; }

/* ---- panel groups (collapsible) ------------------------------------------- */
.group {
  flex: none;
  background: rgba(14, 14, 20, 0.85);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(0, 240, 255, 0.03);
  transition: border-color 0.2s ease;
}
.group:hover { border-color: #343c4c; }

.group summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 10px var(--sp-3);
  cursor: pointer;
  user-select: none;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}
.group summary::-webkit-details-marker { display: none; }
.group summary .tick {
  width: 12px;
  height: 2px;
  background: var(--cyan);
  box-shadow: 0 0 6px var(--glow-30);
  flex: none;
}
.group summary .hint {
  margin-left: auto;
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--dim);
  text-align: right;
}
.caret {
  flex: none;
  width: 7px;
  height: 7px;
  border-right: 1px solid var(--muted-2);
  border-bottom: 1px solid var(--muted-2);
  transform: rotate(45deg);            /* points down = open */
  transition: transform 0.15s ease;
}
.group:not([open]) summary .caret { transform: rotate(-45deg); }  /* points right = closed */
.group summary:hover .caret { border-color: var(--cyan); }
.group summary:focus-visible {
  outline: none;
  color: var(--cyan);
}

/* subsections inside a group: flat, separated by hairlines — instrumentation,
   not a stack of forms */
.sub {
  padding: 10px var(--sp-3) var(--sp-3);
  border-top: 1px solid rgba(42, 48, 60, 0.6);
}
.sub h3 {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  margin: 0 0 var(--sp-2);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.sub h3 .hint {
  margin-left: auto;
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--dim);
  text-align: right;
}
.sub p.hint {
  margin: var(--sp-2) 0 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--dim);
  overflow-wrap: anywhere;
}

/* ---- motors: telemetry sliders ------------------------------------------- */
.motor { margin-bottom: 11px; }
.motor label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}
.motor .val {
  font-variant-numeric: tabular-nums;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--glow-30);
}

.motor input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 16px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
/* track: dark channel with a cyan center notch at the rest pose */
.motor input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background:
    linear-gradient(var(--glow-30), var(--glow-30)) 50% 0 / 2px 100% no-repeat,
    linear-gradient(90deg, #171c28, #1e2534);
  border: 1px solid #232a38;
}
.motor input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background:
    linear-gradient(var(--glow-30), var(--glow-30)) 50% 0 / 2px 100% no-repeat,
    linear-gradient(90deg, #171c28, #1e2534);
  border: 1px solid #232a38;
}
/* thumb: square-ish cyan indicator, soft glow */
.motor input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -4.5px;
  border-radius: 2px;
  background: var(--cyan);
  border: none;
  box-shadow: 0 0 8px var(--glow-30);
  transition: box-shadow 0.15s ease;
}
.motor input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: var(--cyan);
  border: none;
  box-shadow: 0 0 8px var(--glow-30);
}
.motor input[type="range"]:hover::-webkit-slider-thumb,
.motor input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.55);
}
.motor input[type="range"]:focus-visible { outline: none; }

/* ---- buttons -------------------------------------------------------------- */
button {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 7px 12px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease,
              background 0.15s ease, box-shadow 0.15s ease;
}
button:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  background: var(--surface-3);
  box-shadow: 0 0 10px var(--glow-12);
}
button:active { background: #101826; }
button.wide { width: 100%; margin-top: 2px; }
/* tap-to-play speech phrase chips (pre-cached voice) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  text-transform: none; letter-spacing: 0; font-weight: 500;
  padding: 5px 10px; font-size: 11px; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
button.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(0, 240, 255, 0.08);
  box-shadow: inset 0 0 12px var(--glow-06), 0 0 10px var(--glow-12);
}
button:focus-visible {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px var(--glow-30);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#faces button { flex: 1 1 30%; }

/* recording: the REC button burns amber while the bus reports recording */
body[data-bus="rec"] #rec-toggle {
  border-color: var(--amber);
  color: var(--amber);
  box-shadow: 0 0 10px rgba(252, 238, 10, 0.18);
  animation: pulse 1.2s ease-in-out infinite;
}

/* ---- inputs --------------------------------------------------------------- */
.row {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}
.row input[type="text"] {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 10px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.row input[type="text"]::placeholder { color: var(--dimmer); }
.row input[type="text"]:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px var(--glow-30), 0 0 14px var(--glow-06);
}
.row input[type="color"] {
  width: 44px;
  height: 28px;
  padding: 3px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.row input[type="color"]:hover { border-color: var(--cyan); }

label.chk {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 24px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  user-select: none;
  cursor: pointer;
}
label.chk input {
  accent-color: var(--cyan);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* ---- bus status line ------------------------------------------------------ */
#bus-status {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 10px 0 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--muted);
  overflow-wrap: anywhere;
}
#bus-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dimmer);
  flex: none;
}
body[data-bus="live"] #bus-status { color: var(--mint); }
body[data-bus="live"] #bus-status::before { background: var(--mint); box-shadow: 0 0 8px rgba(5, 255, 161, 0.6); animation: pulse 2s ease-in-out infinite; }
body[data-bus="down"] #bus-status { color: var(--magenta); }
body[data-bus="down"] #bus-status::before { background: var(--magenta); box-shadow: 0 0 8px rgba(255, 42, 109, 0.6); }
body[data-bus="rec"] #bus-status { color: var(--amber); }
body[data-bus="rec"] #bus-status::before { background: var(--amber); box-shadow: 0 0 8px rgba(252, 238, 10, 0.55); animation: pulse 1.2s ease-in-out infinite; }
body[data-bus="wait"] #bus-status { color: var(--cyan); }
body[data-bus="wait"] #bus-status::before { background: var(--cyan); box-shadow: 0 0 8px var(--glow-30); animation: pulse 1.2s ease-in-out infinite; }

/* ---- comms log ------------------------------------------------------------ */
#transcript {
  max-height: 200px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#transcript:empty::before {
  content: "— awaiting traffic —";
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--dimmer);
  align-self: center;
  padding: 8px 0;
}
#transcript .turn {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  padding: 5px 9px;
  border-radius: 4px;
  background: var(--surface-2);
  max-width: 92%;
  overflow-wrap: anywhere;
}
#transcript .turn.user {
  align-self: flex-start;
  border-left: 2px solid var(--muted-2);
  color: var(--text-dim);
}
#transcript .turn.moxie {
  align-self: flex-end;
  text-align: right;
  border-right: 2px solid var(--cyan);
  color: #a9eef6;
  background: rgba(0, 240, 255, 0.05);
}
#transcript .who {
  display: block;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-2);
}
#transcript .turn.moxie .who { color: var(--cyan-dim); }

/* ---- session / file load -------------------------------------------------- */
.file-load {
  display: block;
  margin-top: 9px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}
.file-load input[type="file"] {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  max-width: 100%;
}
.file-load input[type="file"]::file-selector-button {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-right: 8px;
  padding: 4px 9px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.file-load input[type="file"]::file-selector-button:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

/* scene lighting slider */
.rng { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.rng-name { font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; color: var(--muted); }
.rng input[type=range] { flex: 1; min-width: 0; accent-color: var(--cyan); }
.rng-val { font-family: var(--font-mono); font-size: 11px; color: var(--cyan); min-width: 2.6em; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- scrollbars ----------------------------------------------------------- */
#rail-scroll, #transcript { scrollbar-width: thin; scrollbar-color: #232a38 transparent; }
#rail-scroll::-webkit-scrollbar, #transcript::-webkit-scrollbar { width: 8px; }
#rail-scroll::-webkit-scrollbar-track, #transcript::-webkit-scrollbar-track { background: transparent; }
#rail-scroll::-webkit-scrollbar-thumb, #transcript::-webkit-scrollbar-thumb {
  background: #232a38;
  border-radius: 4px;
}
#rail-scroll::-webkit-scrollbar-thumb:hover, #transcript::-webkit-scrollbar-thumb:hover {
  background: var(--cyan-dim);
}

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

/* narrow: hide the secondary topbar tag */
@media (max-width: 1100px) {
  #topbar .tag.dim { display: none; }
}

/* tablet portrait */
@media (max-width: 860px) {
  #topbar .tag { display: none; }
  #scene-hint { display: none; }
  /* condense the notice: keep the full disclaimer, drop the flourish */
  .notice-more { display: none; }
}

/* Compact (phones, tablets, small laptops): the rail is a bottom drawer over the
   full-screen 3D so Moxie stays visible; tap the handle to open the controls. */
@media (max-width: 899px) {
  #hud {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "topbar" "notice" "stage" "panel";
  }
  /* thin single-line notice on phones — no wrap, small text, compact GitHub chip */
  #notice {
    flex-wrap: nowrap;
    row-gap: 0;
    gap: 8px;
    padding: 3px var(--sp-3);
  }
  .disclaimer {
    font-size: 10px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .notice-by { display: none; }              /* byline lives on the hub footer */

  #panel {
    margin: 0 8px 8px;                      /* float above the bottom edge */
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    background: rgba(9, 12, 19, 0.34);      /* GLASS, so Moxie shows through */
    backdrop-filter: blur(22px) saturate(1.15);
    -webkit-backdrop-filter: blur(22px) saturate(1.15);
    max-height: 42vh;                       /* never cover more than ~40% — Moxie stays visible */
  }
  /* when the drawer is open, keep the stage area tall so Moxie isn't squeezed */
  #hud:not(.rail-closed) { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  #rail-toggle { display: flex; }
  #hud.rail-closed #rail-scroll { display: none; }
  #hud.rail-closed #rail-toggle { border-bottom: none; }
  #hud.rail-closed #rail-toggle .caret { transform: rotate(-135deg); }  /* points up = pull open */
  /* small, thin GitHub chip (not a 40px touch button — it must not bloat the bar) */
  .notice-link {
    flex: none;
    min-height: 0;
    padding: 2px 8px;
    font-size: 9px;
    letter-spacing: 0.06em;
    display: inline-flex;
    align-items: center;
  }

  /* comfortable touch targets */
  button { min-height: 40px; padding: 9px 14px; }
  #rail-toggle { min-height: 48px; }
  .row input[type="text"] { min-height: 40px; }
  .row input[type="color"] { height: 40px; width: 52px; }
  label.chk { min-height: 40px; }
  label.chk input { width: 18px; height: 18px; }
  .motor input[type="range"] { height: 28px; }
  .motor input[type="range"]::-webkit-slider-thumb { width: 16px; height: 16px; margin-top: -7px; }
  .motor input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; }
  .group summary { min-height: 44px; }
  #transcript { max-height: 140px; }
}

/* very small phones: tighten the brand row */
@media (max-width: 420px) {
  #topbar { padding: 0 var(--sp-3); min-height: 44px; }
  #topbar h1 { font-size: 14px; }
  .notice-badge { display: none; }
}

/* mic recording state */
body[data-mic="on"] #mic-btn { border-color: var(--magenta); color: var(--magenta);
  box-shadow: 0 0 0 1px rgba(255,42,109,.25), 0 0 18px rgba(255,42,109,.18); }
body[data-mic="on"] #mic-btn::before { content: "● "; }

/* axis legend (shown with "show axes") */
#axis-legend { display: flex; flex-direction: column; gap: 3px; margin: 7px 0 2px 22px; }
#axis-legend .ax { display: flex; align-items: center; gap: 6px;
  font-family: 'JetBrains Mono', monospace; font-size: 10.5px; color: var(--text-dim); }
#axis-legend .ax i { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
#axis-legend .ax em { font-style: normal; color: var(--muted); }
#axis-legend .ax-x i { background: #ff4136; }
#axis-legend .ax-y i { background: #2ecc40; }
#axis-legend .ax-z i { background: #0074ff; }

/* Back-to-hub link in the SIL topbar */
#topbar #hub-back {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  color: var(--muted); text-decoration: none; font-size: 12px;
  border: 1px solid var(--hairline); border-radius: 8px; padding: 5px 10px;
  transition: color .15s, border-color .15s, background .15s;
}
#topbar #hub-back:hover { color: var(--cyan); border-color: var(--cyan-dim); background: rgba(0,240,255,.06); }
#topbar #hub-back svg { width: 14px; height: 14px; }
.notice-by { flex: none; margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.notice-by a { color: var(--cyan-dim); text-decoration: none; }
.notice-by a:hover { color: var(--cyan); }
.notice-link { margin-left: var(--sp-3) !important; }

/* ---- Wide landscape: multi-column rail so ALL controls fit on one screen with
   no scrolling. Column count scales with viewport HEIGHT (each column can only
   hold so much), so nothing ever spills into a clipped off-screen column. The
   3D stage keeps a sensible minimum width. ---- */
.rail-multicol #rail-scroll {          /* shared bits, applied by the queries below */
  display: block;
  column-gap: var(--sp-3);
  padding-bottom: var(--sp-3);
}
.rail-multicol #rail-scroll > .group {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  margin-bottom: var(--sp-3);
}
/* Medium widths: a narrow single-column GLASS side panel (scrolls) — far better
   than a full-width drawer wasting the space. */
@media (min-width: 900px) {
  :root { --rail-w: clamp(320px, 26vw, 380px); }   /* SIDE-PANEL single-column base */
  #hud { grid-template-columns: minmax(0, 1fr) var(--rail-w); }
  #rail-toggle { display: none; }
  #hud.rail-closed #rail-scroll { display: flex; }
}
/* Tall enough for 2 columns to hold every control with no scroll. */
@media (min-width: 1300px) and (min-height: 1131px) {
  :root { --rail-w: clamp(600px, 34vw, 720px); }
  #hud { grid-template-columns: minmax(440px, 1fr) var(--rail-w); }
  #rail-scroll {
    display: block; column-count: 2; column-gap: var(--sp-3); padding-bottom: var(--sp-3);
  }
  #rail-scroll > .group { break-inside: avoid; -webkit-column-break-inside: avoid; margin-bottom: var(--sp-3); }
}
/* Shorter but wide → 3 columns so it still fits with no scroll. */
@media (min-width: 1500px) and (max-height: 1130px) {
  :root { --rail-w: clamp(860px, 54vw, 1020px); }
  #hud { grid-template-columns: minmax(400px, 1fr) var(--rail-w); }
  #rail-scroll {
    display: block; column-count: 3; column-gap: var(--sp-3); padding-bottom: var(--sp-3);
  }
  #rail-scroll > .group { break-inside: avoid; -webkit-column-break-inside: avoid; margin-bottom: var(--sp-3); }
}

/* ---- Environment awareness (env.js): hosted-demo vs local, disabled hints ---- */
.env-badge {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.1em;
  padding: 2px 7px; border-radius: 4px; margin-right: var(--sp-3); white-space: nowrap;
}
.env-badge.local  { color: var(--mint);  border: 1px solid rgba(5, 255, 161, 0.4); }
.env-badge.hosted { color: var(--amber); border: 1px solid rgba(252, 238, 10, 0.4); }
button.needs-backend { opacity: 0.5; cursor: help; }
button.needs-backend::after {
  content: "\2298"; margin-left: 5px; font-size: 0.9em; opacity: 0.8;   /* ⊘ = needs server */
}
.hint.warn, #bus-status.warn { color: var(--amber); }
.hint.warn code { color: var(--cyan); }
#env-banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: var(--sp-3); max-width: min(920px, 94vw);
  padding: 10px 12px 10px 14px;
  background: rgba(10, 12, 20, 0.94); backdrop-filter: blur(12px);
  border: 1px solid var(--hairline); border-left: 3px solid var(--amber);
  border-radius: 12px; box-shadow: 0 14px 40px rgba(0,0,0,0.55);
  font-size: 13px; color: var(--text-dim); line-height: 1.45;
}
#env-banner .eb-badge {
  flex: none; font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.1em;
  color: var(--amber); border: 1px solid rgba(252,238,10,0.4); border-radius: 4px; padding: 2px 7px;
}
#env-banner .eb-text b { color: var(--text); }
#env-banner .eb-link { flex: none; color: var(--cyan); text-decoration: none; font-weight: 500; }
#env-banner .eb-link:hover { text-decoration: underline; }
#env-banner .eb-x {
  flex: none; background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 2px 4px; line-height: 1;
}
#env-banner .eb-x:hover { color: var(--text); }
@media (max-width: 640px) { #env-banner { flex-wrap: wrap; } }

/* ---- Large displays: scale the HUD text up so it isn't tiny on big monitors. --- */
@media (min-width: 1900px) {
  html, body            { font-size: 15.5px; }
  .group summary        { font-size: 12.5px; }
  .sub h3               { font-size: 12px; }
  .motor label          { font-size: 13px; }
  button                { font-size: 12.5px; }
  .sub p.hint, .hint    { font-size: 11.5px; }
  .rng-name             { font-size: 11.5px; }
  .rng-val              { font-size: 12.5px; }
  .row input[type="text"], select { font-size: 13.5px; }
  #bus-status           { font-size: 12.5px; }
  #transcript .turn     { font-size: 13px; }
  #topbar h1            { font-size: 17px; }
  #topbar .tag          { font-size: 11px; }
}
@media (min-width: 2500px) {
  html, body            { font-size: 17.5px; }
  .group summary        { font-size: 14px; }
  .sub h3               { font-size: 13.5px; }
  .motor label          { font-size: 14.5px; }
  button                { font-size: 14px; }
  .sub p.hint, .hint    { font-size: 13px; }
  .rng-name             { font-size: 13px; }
  .rng-val              { font-size: 14px; }
  .row input[type="text"], select { font-size: 15px; }
  #bus-status           { font-size: 14px; }
  #transcript .turn     { font-size: 14.5px; }
  #topbar h1            { font-size: 19px; }
  #topbar .tag          { font-size: 12px; }
}
