/* Cerebro: palette and type from docs/project-page.html (signal cyan on deep blue-black, Space Grotesk + IBM Plex).
   The console (/) is dark by design: the bottom half matches VS Code's dark terminal. The dashboard follows the
   system theme, with an explicit override. */
:root {
  --bg: #0b1015; --panel: #121a21; --panel-2: #18222b; --line: #24323d; --fg: #e6edf2; --muted: #93a3b0; --dim: #63737f;
  --sig: #38c6e0; --sig-soft: rgba(56, 198, 224, 0.12); --amber: #f0b043; --amber-soft: rgba(240, 176, 67, 0.13);
  --ok: #46d184; --ok-soft: rgba(70, 209, 132, 0.12); --bad: #ff6b72; --bad-soft: rgba(255, 107, 114, 0.12);
  --todo: #8c9ba7; --todo-soft: rgba(140, 155, 167, 0.12);
  --f-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --f-mono: "Cascadia Mono", Consolas, Menlo, "DejaVu Sans Mono", ui-monospace, monospace;
  /* VS Code Dark Modern panel and terminal */
  --vs-bg: #181818; --vs-panel: #181818; --vs-border: #2b2b2b; --vs-tab: #e7e7e7; --vs-tab-dim: #9d9d9d; --vs-accent: #0078d4;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 var(--f-body); -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- console layout: top half helmets, bottom half terminal ---------- */
body.console { overflow: hidden; overscroll-behavior: none; }
#app { display: grid; grid-template-rows: 50% 50%; height: 100vh; height: 100dvh; }
/* The stage is a dark machine room: the WebGL canvas fills it edge to edge (under the bar and the status bar) so the
   helmet cables run off the top of the screen. */
.stage { position: relative; isolation: isolate; display: grid; grid-template-rows: auto 1fr auto; min-height: 0; overflow: hidden;
  background: linear-gradient(180deg, #020304 0%, rgba(2, 3, 4, 0) 26%),
    radial-gradient(75% 60% at 50% 58%, #0c1b25 0%, #070b0f 58%, #040608 100%); padding-top: env(safe-area-inset-top); }
.stage-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; pointer-events: none; }
.bar, .carousel, .carousel-foot { position: relative; z-index: 1; }
.toast { z-index: 3; }
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px 0; }
.brand { font: 600 13px/1 var(--f-display); letter-spacing: 0.22em; text-transform: uppercase; color: var(--sig); }
.bar-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: nowrap; justify-content: flex-end; white-space: nowrap; }
.queue-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); color: var(--fg); text-decoration: none; }
.queue-chip.warn { border-color: #d9a43f; color: #f0c674; }
@media (max-width: 520px) {
  .wide-only { display: none; }
  .bar { gap: 8px; }
  .bar-actions { gap: 10px; }
  .toggle span { display: none; }
  .toggle { padding: 6px 8px; }
  .link { font-size: 12.5px; }
}
.link { background: none; border: 0; padding: 4px 0; color: var(--muted); text-decoration: none; font-size: 13.5px; cursor: pointer; }
.link:hover, .link:focus-visible { color: var(--fg); }
.toggle { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 13px; }
.toggle svg { width: 16px; height: 16px; fill: currentColor; }
.toggle svg .wave { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; opacity: 0.35; }
.toggle[aria-pressed="true"] { color: var(--sig); border-color: color-mix(in srgb, var(--sig) 55%, transparent); background: var(--sig-soft); }
.toggle[aria-pressed="true"] svg .wave { opacity: 1; }

.carousel { display: grid; grid-template-rows: 1fr auto; justify-items: center; align-items: center; min-height: 0; padding: 0 16px 4px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  cursor: grab; outline: none; }
.carousel:focus-visible .meta .name { text-decoration: underline 2px var(--sig); text-underline-offset: 4px; }
.carousel.moving { cursor: grabbing; }
.carousel #fallback { grid-row: 1; pointer-events: none; }
.meta { grid-row: 2; text-align: center; min-height: 40px; max-width: 100%; transition: opacity 0.2s; pointer-events: none;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9); }
.carousel.moving .meta { opacity: 0.3; }
.meta .name { font: 600 15px/1.2 var(--f-display); letter-spacing: 0.01em; }
.meta .state { font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.carousel-foot { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0 16px 10px; }
.nav { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  font-size: 20px; line-height: 1; cursor: pointer; }
.nav:disabled { opacity: 0.3; cursor: default; }
.dots { display: flex; gap: 7px; flex-wrap: wrap; justify-content: center; max-width: 70vw; }
.dots button { width: 8px; height: 8px; padding: 0; border-radius: 50%; border: 0; background: var(--line); cursor: pointer; }
.dots button[aria-selected="true"] { background: var(--sig); box-shadow: 0 0 8px var(--sig); }
.dots button.plus { background: transparent; outline: 1px dashed var(--dim); }
.dots button.working { background: color-mix(in srgb, var(--sig) 45%, var(--line)); }
.dots button.waiting { background: var(--amber); }
.dots button.exited { background: #1a232b; }
.dots button.plus[aria-selected="true"] { outline-color: var(--sig); }
.toast { position: absolute; left: 50%; bottom: 52px; transform: translateX(-50%); max-width: min(92%, 640px); padding: 8px 14px;
  border-radius: 10px; background: rgba(18, 26, 33, 0.92); border: 1px solid var(--line); font-size: 13.5px; color: var(--fg);
  opacity: 0; pointer-events: none; transition: opacity 0.25s; text-align: center; }
.toast.show { opacity: 1; }
.toast.bad { border-color: color-mix(in srgb, var(--bad) 60%, transparent); }

/* ---------- the sphere (login card, and the stand-in when WebGL or the helmet model is unavailable) ---------- */
/* Sized from the top half's height (50dvh) minus the bar, name and dots, so it never clips on a phone. */
.sphere { --size: clamp(120px, min(62vw, calc(50dvh - 175px)), 280px); --c1: #e9fbff; --c2: #7fe0f1; --c3: #1590ad; --c4: #062a35; --glow: rgba(56, 198, 224, 0.45);
  position: relative; width: var(--size); height: var(--size); border-radius: 50%; display: grid; place-items: center;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.85) 0 4%, rgba(255, 255, 255, 0) 18%),
    radial-gradient(circle at 38% 32%, var(--c1) 0%, var(--c2) 22%, var(--c3) 58%, var(--c4) 100%);
  box-shadow: 0 0 calc(var(--size) * 0.22) var(--glow), inset -12px -18px 40px rgba(0, 0, 0, 0.55), inset 8px 10px 24px rgba(255, 255, 255, 0.12);
  cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: pan-x;
  transition: filter 0.3s, transform 0.2s; animation: breathe 5s ease-in-out infinite; }
.sphere::after { content: ""; position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  background: conic-gradient(from 0deg, transparent 0 70%, rgba(255, 255, 255, 0.18) 80%, transparent 90%); opacity: 0; }
.sphere span { position: relative; z-index: 1; font: 700 calc(var(--size) * 0.15)/1 var(--f-display); letter-spacing: -0.01em;
  color: rgba(4, 22, 28, 0.82); text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35); pointer-events: none; }
.sphere:focus-visible { outline: 2px solid var(--sig); outline-offset: 8px; }
.sphere.small { --size: 96px; animation: none; cursor: default; }
.sphere.working { animation: breathe 1.6s ease-in-out infinite; --glow: rgba(56, 198, 224, 0.7); }
.sphere.working::after { opacity: 1; animation: spin 2.2s linear infinite; }
.sphere.waiting { --c2: #ffd88a; --c3: #c98614; --c4: #3a2405; --glow: rgba(240, 176, 67, 0.6); animation: breathe 1.2s ease-in-out infinite; }
.sphere.starting { filter: saturate(0.5) brightness(0.8); }
.sphere.exited, .sphere.ended { --c1: #c9d3da; --c2: #7d8b95; --c3: #3a4650; --c4: #11171c; --glow: rgba(140, 155, 167, 0.15); animation: none; }
.sphere.listening { transform: scale(1.06); --glow: rgba(233, 251, 255, 0.85); animation: none;
  box-shadow: 0 0 0 6px rgba(233, 251, 255, 0.25), 0 0 calc(var(--size) * 0.35) var(--glow), inset -12px -18px 40px rgba(0, 0, 0, 0.5); }
.sphere.sending { filter: brightness(1.15); animation: breathe 0.7s ease-in-out infinite; }
.sphere.new { background: transparent; border: 2px dashed color-mix(in srgb, var(--sig) 55%, transparent); box-shadow: none; animation: none; }
.sphere.new span { color: var(--sig); font-size: calc(var(--size) * 0.3); font-weight: 500; text-shadow: none; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.025); } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sphere, .sphere::after { animation: none !important; } }

/* ---------- terminal (VS Code dark panel) ---------- */
.panel-term { display: grid; grid-template-rows: 35px 1fr; min-height: 0; background: var(--vs-panel); border-top: 1px solid var(--vs-border);
  padding-bottom: env(safe-area-inset-bottom); position: relative; }
.term-tabs { display: flex; align-items: center; gap: 14px; padding: 0 8px 0 16px; font: 11px/1 -apple-system, "Segoe UI", system-ui, sans-serif;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--vs-tab-dim); min-width: 0; }
.tab { color: var(--vs-tab); padding: 11px 0 9px; border-bottom: 1px solid var(--vs-tab); }
.term-title { text-transform: none; letter-spacing: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.term-actions { margin-left: auto; display: flex; gap: 2px; }
.term-actions button { width: 28px; height: 26px; border: 0; border-radius: 5px; background: none; color: var(--vs-tab-dim); cursor: pointer; font-size: 14px; }
.term-actions button:hover { background: rgba(90, 93, 94, 0.31); color: var(--vs-tab); }
.term { min-height: 0; padding: 4px 0 0 16px; overflow: hidden; }
.term .xterm { height: 100%; }
.term .xterm-viewport { background: var(--vs-bg) !important; }
.term-empty { position: absolute; inset: 35px 0 0; display: grid; place-items: center; padding: 16px; text-align: center;
  color: var(--vs-tab-dim); font-size: 13px; }
.term-actions button[aria-pressed="true"] { color: var(--vs-tab); background: rgba(90, 93, 94, 0.31); }

/* ---------- terminal focus mode (issue #1): the terminal takes the working area, the helmets become a strip ---------- */
.focus-handle { display: none; }
body.term-focus #app { grid-template-rows: auto 1fr; height: var(--vvh, 100dvh); }
body.term-focus .stage { grid-template-rows: auto auto; touch-action: none; }
body.term-focus .carousel, body.term-focus .carousel-foot { display: none; }
body.term-focus .term { touch-action: none; }   /* the drag is ours: it becomes wheel reports, never a page scroll */
/* xterm.js re-renders its row elements whenever the screen changes. A touch keeps targeting the element it started on,
   so once that row is replaced the rest of the drag goes to a detached node and never reaches our listener (found while
   testing #1: only the first scroll step of each drag arrived). Rows ignore pointers; touches land on the stable
   .xterm-screen, where xterm.js listens for mouse, wheel, selection and links anyway. Unconditional, so the drag that
   enters focus mode (and triggers a refit and redraw) keeps its touches too. */
.term .xterm-rows { pointer-events: none; }
body.term-focus .toast { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); }
body.term-focus .focus-handle { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 5px;
  width: 100%; padding: 6px 16px 8px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px;
  -webkit-tap-highlight-color: transparent; }
.focus-handle i { width: 38px; height: 4px; border-radius: 99px; background: color-mix(in srgb, var(--sig) 55%, var(--line)); }
.focus-handle span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.focus-handle.working i { background: var(--sig); box-shadow: 0 0 8px var(--sig); }
.focus-handle.waiting i { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.focus-handle.waiting span { color: var(--amber); }
.focus-handle.exited i, .focus-handle.ended i { background: var(--line); }
.focus-handle:focus-visible { outline: 2px solid var(--sig); outline-offset: -2px; }

/* ---------- login and dialogs ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(90% 70% at 50% 40%, #0f2430 0%, var(--bg) 65%); }
.login-card { width: min(100%, 340px); display: grid; gap: 10px; justify-items: stretch; }
.login-card .sphere { justify-self: center; margin-bottom: 10px; }
.login-card label, .new-dialog label { font-size: 13px; color: var(--muted); }
.login-card input, .new-dialog input, .new-dialog select { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); font-size: 16px; }
.login-card button, .new-dialog button { padding: 10px 14px; border-radius: 8px; border: 0; background: var(--sig); color: #04161c;
  font-weight: 600; cursor: pointer; }
.new-dialog button.ghost { background: transparent; border: 1px solid var(--line); color: var(--fg); }
.msg { min-height: 1.4em; margin: 0; color: var(--bad); font-size: 13px; }
.new-dialog.wide { width: min(96vw, 720px); }
.new-dialog textarea { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: #181818;
  color: var(--fg); font: 16px/1.4 ui-monospace, Menlo, Consolas, monospace; resize: vertical; box-sizing: border-box; }
@media (max-width: 520px) { .term-actions button { width: 34px; height: 32px; font-size: 16px; } }
.copy-text { max-height: 60vh; overflow: auto; margin: 8px 0; padding: 10px; border-radius: 8px; background: #181818; color: #cccccc;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word;
  -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
.new-dialog { width: min(92vw, 380px); border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--fg); padding: 18px; }
.new-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.new-dialog form { display: grid; gap: 8px; }
.new-dialog h2 { margin: 0 0 6px; font: 600 18px var(--f-display); }
.new-dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.new-dialog h3 { margin: 6px 0 0; font: 600 12px var(--f-display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--sig); }
.dialog-note { margin: 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.resume-section { display: grid; gap: 8px; }
.resume-list { display: grid; gap: 6px; }
.new-dialog button.resume { display: grid; gap: 2px; text-align: left; background: var(--panel-2); border: 1px solid var(--line); color: var(--fg); font-weight: 400; }
.new-dialog button.resume span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-dialog button.danger { background: var(--bad); color: #1c0406; }
.perf-hud { position: absolute; left: 16px; right: 16px; top: calc(env(safe-area-inset-top) + 44px); z-index: 2; font: 11px/1.3 var(--f-mono); color: #9fe7f5; pointer-events: none;
  text-shadow: 0 1px 2px #000; }

/* ---------- dashboard ---------- */
body.dash { min-height: 100%; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) body.dash { --bg: #f4f6f8; --panel: #ffffff; --panel-2: #eef2f5; --line: #d5dde4; --fg: #111a22; --muted: #52616e;
    --dim: #7c8a96; --sig: #0a8ca8; --sig-soft: rgba(10, 140, 168, 0.10); --amber: #b7710c; --amber-soft: rgba(183, 113, 12, 0.12);
    --ok: #1d8a4e; --ok-soft: rgba(29, 138, 78, 0.12); --bad: #b8323a; --bad-soft: rgba(184, 50, 58, 0.10); --todo: #6b7885; color-scheme: light; }
}
:root[data-theme="light"] body.dash { --bg: #f4f6f8; --panel: #ffffff; --panel-2: #eef2f5; --line: #d5dde4; --fg: #111a22; --muted: #52616e;
  --dim: #7c8a96; --sig: #0a8ca8; --sig-soft: rgba(10, 140, 168, 0.10); --amber: #b7710c; --amber-soft: rgba(183, 113, 12, 0.12);
  --ok: #1d8a4e; --ok-soft: rgba(29, 138, 78, 0.12); --bad: #b8323a; --bad-soft: rgba(184, 50, 58, 0.10); --todo: #6b7885; color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
.dash .wrap { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }
.dash header { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-top: env(safe-area-inset-top); }
.dash h1 { margin: 0; font: 700 26px/1.1 var(--f-display); letter-spacing: -0.01em; }
.dash h1 small { display: block; font: 500 12px/1 var(--f-body); letter-spacing: 0.18em; text-transform: uppercase; color: var(--sig); margin-bottom: 6px; }
.dash header .actions { margin-left: auto; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn { padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); cursor: pointer; font-size: 13.5px; text-decoration: none; }
.btn.primary { background: var(--sig); color: #04161c; border-color: transparent; font-weight: 600; }
.dash .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 14px; margin-top: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font: 600 15px var(--f-display); }
.card h2 .age { margin-left: auto; font: 400 12px var(--f-body); color: var(--dim); }
.pill { display: inline-block; white-space: nowrap; padding: 2px 8px; border-radius: 999px; font: 500 11.5px/1.5 var(--f-body); }
.pill.fresh, .pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.stale, .pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.error, .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.never, .pill.mu { background: var(--todo-soft); color: var(--todo); }
.kv { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 4px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl.wide { min-width: 640px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 8px 6px 0; border-bottom: 1px solid var(--line); }
.tbl td { padding: 6px 8px 6px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent); vertical-align: top; overflow-wrap: anywhere; }
.tbl-wrap { overflow-x: auto; }
.err { color: var(--bad); font-size: 12.5px; margin: 8px 0 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--f-mono); font-size: 12.5px; }
.small { font-size: 12.5px; }
.bars { display: grid; gap: 4px; margin-top: 8px; }
.bars div { display: grid; grid-template-columns: 82px 1fr 72px; gap: 8px; align-items: center; font-size: 12px; }
.bars i { display: block; height: 8px; border-radius: 4px; background: var(--sig); min-width: 2px; }
/* Skills & tools (#57): forms keep 16px inputs so iOS Safari does not zoom on focus. */
.sk-h { margin: 14px 0 6px; font: 600 13.5px var(--f-display); display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.sk-panel { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.sk-panel summary { cursor: pointer; font: 600 13.5px var(--f-display); color: var(--sig); padding: 4px 0; }
.sk-form { display: grid; gap: 10px; margin-top: 10px; max-width: 640px; }
.sk-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.sk-form input:not([type="checkbox"]), .sk-form select, .sk-form textarea { font: 16px var(--f-body); color: var(--fg); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; box-sizing: border-box; }
.sk-form .sk-check { display: flex; gap: 8px; align-items: flex-start; color: var(--fg); }
.sk-form .sk-check input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; }
.sk-form button { justify-self: start; }
.sk-box { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); min-width: 0; }
.sk-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.sk-more { margin: 6px 0 4px; }
.sk-more summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.sk-btn { padding: 5px 10px; font-size: 12.5px; }
.sk-diff { max-height: 320px; overflow: auto; font: 12px/1.45 var(--f-mono); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; white-space: pre; }
