/* an element marked hidden stays hidden, whatever display its class gives it */
[hidden] { display: none !important; }
/* JARVIS — calm dark interface.
   Graphite surfaces, off-white text, one restrained accent (set per theme by theme.js through
   --accent-rgb / --cyan*). Solid panels with hairline borders: no glows, no blur, no scanlines. */
:root {
  --bg: #0d0e10;
  --surface: #151719;
  --surface-2: #1b1d20;
  --surface-3: #232629;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --ink: #e7e5e1;           /* solid primary buttons */
  --accent-rgb: 116, 179, 194;
  --dial-size: min(56vh, 520px, 92vw);
  --cyan: rgb(116, 179, 194);
  --cyan-2: #b3d3db;
  --cyan-dim: rgba(var(--accent-rgb), 0.32);
  --cyan-faint: rgba(var(--accent-rgb), 0.10);
  --glass: var(--surface);
  --glass-2: var(--surface-2);
  --text: #e7e5e1;
  --text-2: #b8b5af;
  --muted: #8b8882;
  --warn: #d4a45c;
  --err: #e06464;
  --ok: #7fb893;
  --alarm: #d64545;
  --font-head: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  letter-spacing: 0;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'ss01', 'cv11';
}
button, input { font-family: inherit; }
::selection { background: rgba(var(--accent-rgb), 0.3); }
:focus-visible { outline: 2px solid rgba(var(--accent-rgb), 0.6); outline-offset: 2px; }

/* ---------- background layers ---------- */
#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
#hud { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
.scanlines { display: none; }

/* ---------- stage ---------- */
#stage { position: relative; z-index: 2; height: 100%; display: grid; place-items: center; }

.corner {
  position: absolute; z-index: 5;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
.corner.tl { top: 22px; left: 26px; }
.corner.tr { top: 22px; right: 26px; display: flex; gap: 6px; }
.corner.bl { bottom: 22px; left: 26px; }
.corner.br { bottom: 22px; right: 26px; text-align: right; }
.corner .label { color: var(--muted); font-size: 10px; letter-spacing: 0.16em; margin-bottom: 6px; }
.corner .row { display: flex; gap: 14px; justify-content: space-between; line-height: 1.75; }
.corner.br .row { flex-direction: row-reverse; }
.corner .row b { color: var(--text); font-weight: 400; }
.corner .row b.bad { color: var(--err); }
.corner .row b.warn { color: var(--warn); }

.brand {
  font-family: var(--font-head); font-weight: 600; font-size: 19px; letter-spacing: 0.26em; color: var(--text);
}
.sub { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.dot.bad { background: var(--err); }
.dot.warn { background: var(--warn); }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.hud-btn {
  background: var(--surface); color: var(--text-2); border: 1px solid var(--line);
  padding: 6px 12px; font-family: var(--font-body); font-size: 12.5px; font-weight: 500; letter-spacing: 0.01em;
  border-radius: 6px; cursor: pointer; position: relative; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.hud-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--line-2); }
.hud-btn.active { background: var(--surface-3); color: var(--text); border-color: var(--line-2); }

/* ---------- center column ---------- */
.center { display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(92vw, 720px); }

.sys-text {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase;
  height: 18px; transition: opacity 0.4s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.sys-text.flash { color: var(--text); }

#orbWrap {
  position: relative; width: var(--dial-size); aspect-ratio: 1; display: grid; place-items: center;
}
#orb { width: 100%; height: 100%; display: block; }
.hud-ring { position: absolute; border-radius: 50%; pointer-events: none; display: none; }
.ring-a { inset: 3%; border: 1px solid var(--line); }
.ring-b { inset: 0; border: 1px dashed var(--line); animation: spin 90s linear infinite; }
.ring-c { inset: 9%; border-top: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); border-left: 1px solid transparent; border-right: 1px solid transparent; animation: spin 24s linear infinite reverse; }
@keyframes spin { to { transform: rotate(360deg); } }

.hud-tag {
  position: absolute; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; color: var(--muted); pointer-events: none;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.hud-tag i { display: inline-block; width: 22px; height: 1px; background: var(--line-2); }
.hud-tag.t1 { top: 12%; left: -2%; }
.hud-tag.t2 { top: 12%; right: -2%; flex-direction: row-reverse; }
.hud-tag.t3 { bottom: 12%; left: -2%; }
.hud-tag.t4 { bottom: 12%; right: -2%; flex-direction: row-reverse; }

.state-label {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.24em; color: var(--text-2); text-transform: uppercase;
  min-height: 18px; margin-top: -6px; transition: color 0.3s;
}
.state-label.listening { color: var(--cyan-2); }
.state-label.error { color: var(--err); }
.transcript { font-size: 16px; color: var(--text-2); min-height: 22px; max-width: 80%; text-align: center; }

/* ---------- input ---------- */
.input-bar {
  display: flex; align-items: center; gap: 8px; width: 100%; max-width: 620px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; padding: 6px 8px;
  position: relative; transition: border-color 0.15s;
}
.input-bar:focus-within { border-color: var(--cyan-dim); }
.input-bar input {
  flex: 1; background: transparent; border: 0; outline: 0; color: var(--text); font-size: 16px; padding: 8px 6px;
}
.input-bar input:focus-visible { outline: 0; }
.input-bar input::placeholder { color: var(--muted); }
.mic {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-2); background: transparent; color: var(--text-2);
  display: grid; place-items: center; cursor: pointer; transition: background 0.15s, color 0.15s, border-color 0.15s; user-select: none; -webkit-user-select: none; touch-action: none;
}
.mic:hover { background: var(--surface-2); color: var(--text); }
.mic.live { background: var(--cyan); border-color: var(--cyan); color: var(--bg); }
.mic.off { opacity: 0.4; cursor: not-allowed; }
.send, .toggle {
  background: transparent; border: 1px solid var(--line-2); border-radius: 7px; color: var(--text-2); padding: 8px 12px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.send:hover, .toggle:hover { background: var(--surface-2); color: var(--text); }
.send { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.send:hover { background: #fff; color: var(--bg); }
.toggle.on { background: rgba(127, 184, 147, 0.1); border-color: rgba(127, 184, 147, 0.5); color: var(--ok); }

.status-bar { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; min-height: 16px; }
.status-bar .pip { width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); }
.status-bar.busy .pip { animation: blink 1.2s infinite; }
.status-bar.error { color: var(--err); }
.status-bar.error .pip { background: var(--err); }

/* ---------- floating response panels ---------- */
#floaters { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.floater {
  position: absolute; pointer-events: auto; max-width: min(340px, 40vw); min-width: 220px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow);
  padding: 12px 14px 12px; font-size: 15px; line-height: 1.5;
  animation: float-in 0.45s var(--ease) both; transition: opacity 0.5s, transform 0.5s;
}
.floater::before, .floater::after { content: none; }
.floater .who { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 10px; }
.floater .who .time { color: var(--muted); letter-spacing: 0.04em; }
.floater.user { background: var(--surface-2); color: var(--text-2); font-size: 14.5px; }
.floater.jarvis .who { color: var(--cyan-2); }
.floater.rich { max-width: min(420px, 44vw); font-size: 13.5px; }
.floater.rich .body { max-height: 38vh; overflow: auto; padding-right: 4px; }
.floater.fading { opacity: 0; transform: translateY(-14px); }
.floater.left { left: 4vw; }
.floater.right { right: 4vw; }
.line { display: flex; gap: 10px; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size: 12px; min-width: 0; }
.line:last-child { border-bottom: 0; }
.line .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); min-width: 0; }
.line .n small { color: var(--muted); display: block; font-size: 10px; overflow: hidden; text-overflow: ellipsis; }
.line .v { color: var(--text-2); white-space: nowrap; flex-shrink: 0; }
.meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); letter-spacing: 0.04em; margin-top: 6px; word-break: break-all; }
select { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 6px; color: var(--text); padding: 7px 10px; font-size: 14px; font-family: var(--font-body); max-width: 100%; }
select option { background: var(--surface-2); color: var(--text); }
.floater a { color: var(--cyan-2); text-decoration: none; }
.floater a:hover { text-decoration: underline; }
.floater .actions { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
@keyframes float-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- HUD cards (system) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.card {
  position: relative; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px;
}
.card .k { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; color: var(--muted); margin-bottom: 6px; }
.card .v { font-family: var(--font-head); font-size: 22px; font-weight: 500; color: var(--text); }
.card .v small { font-size: 12px; color: var(--muted); font-family: var(--font-mono); margin-left: 4px; }
.card .d { font-size: 13px; color: var(--text-2); margin-top: 4px; line-height: 1.45; word-break: break-word; }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px; position: relative; overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--cyan); border-radius: 2px; transition: width 0.6s; }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--err); }

/* ---------- overlay panels ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; animation: fade 0.2s; }
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.panel {
  width: min(880px, 94vw); max-height: 88vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55); position: relative;
  animation: float-in 0.35s var(--ease);
}
.panel::before, .panel::after { content: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); font-family: var(--font-head); font-weight: 600; letter-spacing: 0.14em; font-size: 13px; color: var(--text); }
.panel-head button { background: none; border: 1px solid var(--line-2); border-radius: 6px; color: var(--text-2); width: 30px; height: 30px; cursor: pointer; font-size: 16px; line-height: 1; }
.panel-head button:hover { background: var(--surface-3); color: var(--text); }
.panel-body { padding: 18px; overflow: auto; }
.panel-body h3 { font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.16em; color: var(--muted); margin: 20px 0 10px; text-transform: uppercase; }
.panel-body h3:first-child { margin-top: 0; }
.panel-body p { margin: 6px 0; color: var(--text-2); line-height: 1.55; }
.panel-body p.note { font-size: 14px; }
.panel-body b { color: var(--text); font-weight: 600; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs button { background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--muted); font-family: var(--font-body); font-size: 13px; font-weight: 500; padding: 6px 11px; cursor: pointer; transition: background 0.15s, color 0.15s; }
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.active { border-color: var(--line-2); color: var(--text); background: var(--surface-3); }

.field { display: grid; grid-template-columns: 200px 1fr; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.field label { font-family: var(--font-body); font-size: 13.5px; font-weight: 500; color: var(--text); }
.field label small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 2px; line-height: 1.4; }
.field input[type=text], .field input[type=password], .field select, .field input[type=number] {
  width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: 6px; color: var(--text); padding: 8px 10px; font-size: 14.5px; outline: 0;
}
.field input:focus, .field select:focus { border-color: var(--cyan-dim); }
.field input[type=range] { width: 100%; accent-color: var(--cyan); }
.field .inline { display: flex; gap: 8px; align-items: center; }
.field .inline input { flex: 1; }
.btn {
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 7px; color: var(--text); padding: 7px 13px;
  font-family: var(--font-body); font-size: 13px; font-weight: 500; cursor: pointer; transition: background 0.15s, color 0.15s, border-color 0.15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { background: #fff; border-color: #fff; }
.btn.danger { border-color: rgba(224, 100, 100, 0.4); color: #eba3a3; background: rgba(224, 100, 100, 0.07); }
.btn.danger:hover { background: rgba(224, 100, 100, 0.16); }
.btn.ok { border-color: rgba(127, 184, 147, 0.45); color: var(--ok); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.small { padding: 4px 9px; font-size: 12px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch i { width: 34px; height: 20px; border: 1px solid var(--line-2); border-radius: 10px; position: relative; background: var(--surface-3); transition: background 0.2s, border-color 0.2s; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); transition: left 0.2s, background 0.2s; }
.switch input:checked + i { border-color: var(--ok); background: var(--ok); }
.switch input:checked + i::after { left: 17px; background: var(--bg); }
.switch span { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; color: var(--text-2); }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.perm { border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); padding: 14px; position: relative; }
.perm .k { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.14em; color: var(--muted); }
.perm .st { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.1em; margin: 8px 0 10px; }
.perm .st.on { color: var(--ok); }
.perm .st.off { color: var(--err); }
.perm .d { font-size: 13px; color: var(--text-2); line-height: 1.45; margin-bottom: 10px; }

.list { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size: 12.5px; }
.list .item:last-child { border-bottom: 0; }
.list .item .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .item .dim { color: var(--muted); font-size: 11px; }
.empty { color: var(--muted); font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.06em; padding: 12px; text-align: center; border: 1px dashed var(--line-2); border-radius: 8px; }

.scan-progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; position: relative; margin: 10px 0; }
.scan-progress i { position: absolute; inset: 0 auto 0 0; width: 40%; background: linear-gradient(90deg, transparent, var(--cyan), transparent); animation: sweep 1.4s linear infinite; }
.scan-progress.done i { animation: none; width: 100%; background: var(--ok); }
.scan-progress.threats i { animation: none; width: 100%; background: var(--err); }
@keyframes sweep { from { left: -40%; } to { left: 100%; } }
.console { background: #0a0b0c; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-family: var(--font-mono); font-size: 11px; color: var(--text-2); max-height: 160px; overflow: auto; white-space: pre-wrap; line-height: 1.55; }

.badge { display: inline-block; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em; padding: 2px 7px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--text-2); text-transform: uppercase; }
.badge.ok { border-color: rgba(127, 184, 147, 0.4); color: var(--ok); background: rgba(127, 184, 147, 0.08); }
.badge.bad { border-color: rgba(224, 100, 100, 0.4); color: var(--err); background: rgba(224, 100, 100, 0.08); }
.badge.warn { border-color: rgba(212, 164, 92, 0.4); color: var(--warn); background: rgba(212, 164, 92, 0.08); }

.history { display: flex; flex-direction: column; gap: 8px; }
.history .msg { padding: 8px 12px; border-left: 2px solid var(--cyan-dim); border-radius: 0 6px 6px 0; background: var(--surface-2); font-size: 15px; line-height: 1.5; }
.history .msg.user { border-color: var(--line-2); background: transparent; color: var(--text-2); }
.history .msg .who { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 3px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(0, 0, 0, 0.6); }
.modal[hidden] { display: none; }
.modal-box {
  width: min(520px, 92vw); background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; padding: 22px 24px; position: relative;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55); animation: float-in 0.3s var(--ease);
}
.modal-kicker { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.16em; color: var(--warn); margin-bottom: 8px; }
.modal-title { font-family: var(--font-head); font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 12px; line-height: 1.35; }
.modal-detail { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-2); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; white-space: pre-wrap; word-break: break-all; margin: 0 0 16px; max-height: 40vh; overflow: auto; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 16px; font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.06em; color: var(--text); animation: float-in 0.3s var(--ease); }
.toast.err { border-color: rgba(224, 100, 100, 0.5); color: #eba3a3; }
.toast.ok { border-color: rgba(127, 184, 147, 0.5); color: var(--ok); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .floater { position: relative !important; left: auto !important; right: auto !important; top: auto !important; max-width: 92vw; margin: 6px auto; }
  #floaters { position: fixed; inset: auto 0 150px 0; display: flex; flex-direction: column; align-items: center; max-height: 40vh; overflow: auto; }
  .corner.bl, .corner.br { display: none; }
  .corner.tl { top: 10px; left: 14px; }
  .corner.tl .sub { margin-top: 3px; font-size: 10px; }
  .brand { font-size: 16px; letter-spacing: 0.22em; }
  .corner.tr { top: 50px; left: 12px; right: 12px; flex-wrap: wrap; justify-content: center; gap: 6px; }
  .hud-btn { padding: 6px 10px; font-size: 12px; }
  .hud-tag { display: none; }
  .field { grid-template-columns: 1fr; }
  .center { width: 94vw; gap: 8px; }
  .sys-text { letter-spacing: 0.1em; font-size: 10px; }
  #orbWrap { width: min(44vh, 80vw); }
  .input-bar { max-width: 94vw; padding: 6px; gap: 6px; }
  .input-bar input { font-size: 15px; padding: 6px 4px; min-width: 0; }
  .mic { width: 38px; height: 38px; flex-shrink: 0; }
  .send, .toggle { padding: 8px 8px; font-size: 10px; letter-spacing: 0.06em; flex-shrink: 0; }
  .status-bar { font-size: 10px; letter-spacing: 0.08em; }
}
@media (prefers-reduced-motion: reduce) {
  .ring-b, .ring-c { animation: none; }
}

/* ---------- scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.16) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.24); background-clip: padding-box; }
*::-webkit-scrollbar-corner { background: transparent; }

/* ---------- HUD windows ---------- */
#windows { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
.win {
  position: absolute; pointer-events: auto; display: flex; flex-direction: column; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: var(--shadow);
  animation: float-in 0.35s var(--ease) both;
}
.win::before, .win::after { content: none; }
.win.closing { opacity: 0; transform: scale(0.98); transition: all 0.2s; }
.win.dragging { box-shadow: 0 22px 52px rgba(0, 0, 0, 0.55); }
.win.flash { animation: winflash 0.8s; }
@keyframes winflash { 0%, 100% { border-color: var(--line-2); } 50% { border-color: var(--cyan); } }
.win-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 12px; cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none;
  background: var(--surface-2); border-bottom: 1px solid var(--line); border-radius: 9px 9px 0 0;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.12em; color: var(--text-2); text-transform: uppercase;
}
.win-bar:active { cursor: grabbing; }
.win-ctl { display: flex; gap: 4px; }
.win-btn { width: 24px; height: 22px; border: 1px solid var(--line-2); border-radius: 5px; background: transparent; color: var(--text-2); cursor: pointer; font-size: 11px; line-height: 1; display: grid; place-items: center; }
.win-btn:hover { background: var(--surface-3); color: var(--text); }
.win-body { flex: 1; overflow: auto; padding: 10px 12px; font-size: 14px; line-height: 1.5; min-height: 0; }
.win-resize { position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize; touch-action: none; background: linear-gradient(135deg, transparent 50%, rgba(255, 255, 255, 0.22) 50%, rgba(255, 255, 255, 0.22) 60%, transparent 60%, transparent 75%, rgba(255, 255, 255, 0.22) 75%, rgba(255, 255, 255, 0.22) 85%, transparent 85%); }
.win.min { height: auto !important; min-height: 0; }
.win.min .win-body, .win.min .win-resize { display: none; }

/* chat window content */
.chat-log { display: flex; flex-direction: column; gap: 8px; }
.chat-msg { padding: 8px 11px; border-left: 2px solid var(--cyan-dim); border-radius: 0 6px 6px 0; background: var(--surface-2); font-size: 14.5px; line-height: 1.5; animation: float-in 0.3s var(--ease); word-break: break-word; }
.chat-msg.user { border-color: var(--line-2); color: var(--text-2); background: transparent; }
.chat-msg.error { border-color: var(--err); color: #efb4b4; }
.chat-msg .who { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 3px; display: flex; justify-content: space-between; }
.chat-msg.user .who { color: var(--muted); }
.chat-msg.typing::after { content: '▍'; animation: blink 0.8s infinite; color: var(--cyan); }

/* ---------- mouse reticle ---------- */
#reticle { position: fixed; left: 0; top: 0; width: 30px; height: 30px; margin: -15px 0 0 -15px; pointer-events: none; z-index: 60; opacity: 0; transition: opacity 0.4s; will-change: transform; }
#reticle::before, #reticle::after, #reticle i { transition: transform 0.12s, border-color 0.12s; }
#reticle::before { content: ''; position: absolute; inset: 0; border: 1px solid rgba(231, 229, 225, 0.45); border-radius: 50%; }
#reticle::after { content: ''; position: absolute; inset: 11px; border: 1px solid rgba(var(--accent-rgb), 0.9); border-radius: 50%; }
#reticle i { position: absolute; left: 50%; top: -5px; width: 1px; height: 7px; background: rgba(231, 229, 225, 0.55); }
#reticle i:nth-child(2) { top: auto; bottom: -5px; }
#reticle i:nth-child(3) { top: 50%; left: -5px; width: 7px; height: 1px; }
#reticle i:nth-child(4) { top: 50%; left: auto; right: -5px; width: 7px; height: 1px; }
body.has-mouse #reticle { opacity: 1; }
#reticle.hot::before { transform: scale(1.35) rotate(45deg); }
#reticle.hot::after { transform: scale(1.3); }
#reticle.hot::before { border-color: rgba(255, 255, 255, 0.8); }
body.attack #reticle::before, body.attack #reticle::after, body.attack #reticle i { border-color: rgba(224, 100, 100, 0.85); background: rgba(224, 100, 100, 0.85); }
body.attack #reticle::before, body.attack #reticle::after { background: transparent; }

/* ---------- attack mode: flat, unmistakable, no pulsing ---------- */
#attackFx { position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: 0; transition: opacity 0.3s; }
#attackFx::before { content: ''; position: absolute; inset: 0; border: 3px solid var(--alarm); }
#attackFx::after {
  content: 'SYSTEM UNDER ATTACK'; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  background: var(--alarm); color: #fff; font-family: var(--font-mono); font-weight: 600; font-size: clamp(12px, 1.1vw, 15px); letter-spacing: 0.2em;
  padding: 9px 22px 10px; border-radius: 0 0 8px 8px; white-space: nowrap;
}
body.attack #attackFx { opacity: 1; }
body.attack .brand { color: #ef8a8a; }
body.attack .state-label { color: #ef8a8a; }
body.attack .sys-text { color: #ef8a8a; }
body.attack .input-bar, body.attack .hud-btn { border-color: rgba(214, 69, 69, 0.55); }
body.attack .dot { background: var(--alarm); }
body.neutralised #attackFx { opacity: 1; }
body.neutralised #attackFx::before { border-color: #4f9a6a; }
body.neutralised #attackFx::after { content: 'SYSTEM ATTACK NEUTRALISED'; background: #4f9a6a; color: #fff; }

/* access gate */
.gate { text-align: center; padding: 10px 0; }
.gate input { width: 100%; max-width: 300px; margin: 12px auto; display: block; background: var(--bg); border: 1px solid var(--line-2); border-radius: 7px; color: var(--text); padding: 10px 12px; font-size: 16px; text-align: center; letter-spacing: 0.2em; outline: 0; }
.gate input:focus { border-color: var(--cyan-dim); }

/* ---------- the reticle IS the cursor ---------- */
body.has-mouse, body.has-mouse * { cursor: none !important; }
#reticle.text::before, #reticle.text::after { border-radius: 2px; }
#reticle.text::before { inset: 4px 13px; border-width: 0 1px; }
#reticle.text::after { display: none; }
#reticle.text i:nth-child(3), #reticle.text i:nth-child(4) { display: none; }
#reticle.grab::before { border-style: dashed; }

/* wake mode waiting for the wake word: calm, no pulse */
.mic.armed { background: rgba(127, 184, 147, 0.1); border-color: rgba(127, 184, 147, 0.5); color: var(--ok); }

/* model switch menu */
.model-menu { position: fixed; right: 26px; bottom: 96px; z-index: 25; width: min(360px, 92vw); max-height: 60vh; overflow: auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; padding: 6px; box-shadow: var(--shadow); animation: float-in 0.2s var(--ease); }
.model-menu .k { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.16em; color: var(--muted); padding: 6px 8px 8px; }
.model-item { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--text); padding: 7px 10px; cursor: pointer; font-size: 14px; }
.model-item small { font-family: var(--font-mono); font-size: 10px; color: var(--muted); letter-spacing: 0.04em; }
.model-item:hover { background: var(--surface-2); }
.model-item.active { border-color: var(--cyan-dim); background: var(--surface-3); }
@media (max-width: 900px) { .model-menu { right: 12px; left: 12px; width: auto; bottom: 120px; } }

/* microphone level meter (wake mode) */
.mic-meter { display: inline-block; width: 70px; height: 5px; margin-left: 10px; background: var(--line); border-radius: 3px; overflow: hidden; position: relative; vertical-align: middle; }
.mic-meter i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--cyan); transition: width 0.05s linear; }
.mic-meter.quiet { outline: 1px solid var(--warn); }
.transcript { transition: opacity 0.3s; }

/* audio unlock prompt (Chrome autoplay policy) */
.audio-gate { position: fixed; left: 50%; top: 14%; transform: translateX(-50%); z-index: 45; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 22px; background: var(--surface-2); border: 1px solid var(--cyan-dim); border-radius: 10px; color: var(--text); cursor: pointer; font-family: var(--font-body); box-shadow: var(--shadow); animation: float-in 0.3s var(--ease); }
.audio-gate:hover { background: var(--surface-3); }
.audio-gate b { font-family: var(--font-mono); font-size: 12px; font-weight: 500; letter-spacing: 0.12em; color: var(--text); }
.audio-gate span { font-size: 13px; color: var(--muted); }

/* what the microphone heard */
.chat-msg.heard { border-left-color: var(--line); background: transparent; color: var(--muted); font-size: 12.5px; font-family: var(--font-mono); padding: 4px 10px; }
.chat-msg.heard .who { color: var(--muted); }
.chat-msg.heard.error { color: #efb4b4; border-left-color: var(--err); }

/* "remember" checkbox inside modals */
.modal-actions { flex-wrap: wrap; align-items: center; }
.modal-actions .remember { display: flex; align-items: center; gap: 8px; margin-right: auto; font-family: var(--font-body); font-size: 13px; color: var(--text-2); cursor: pointer; }
.modal-actions .remember input { accent-color: var(--cyan); width: 15px; height: 15px; }

/* custom context menu */
.ctx-menu { position: fixed; z-index: 70; min-width: 230px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 9px; padding: 5px; box-shadow: var(--shadow); animation: float-in 0.15s var(--ease); }
.ctx-title { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.16em; color: var(--muted); padding: 5px 10px 6px; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.ctx-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--text); padding: 6px 10px; cursor: pointer; font-family: var(--font-body); font-size: 13.5px; }
.ctx-item i { font-style: normal; width: 18px; text-align: center; font-size: 13px; }
.ctx-item:hover { background: var(--surface-3); }
.ctx-item.checked { color: var(--cyan-2); }
.ctx-item.danger:hover { background: rgba(224, 100, 100, 0.14); color: #eba3a3; }
.ctx-item[disabled] { opacity: 0.4; cursor: not-allowed; }
.win-flags { font-size: 11px; margin-left: 6px; margin-right: auto; }
.win.pinned { border-color: var(--cyan-dim); }
.win.locked .win-bar { cursor: default; }
.win.locked .win-resize { display: none; }

/* maximized window */
.win.max { border-color: var(--line-2); border-radius: 0; }
.win.max .win-bar { border-radius: 0; }
.win.max .win-resize { display: none; }
#fsBtn { padding: 6px 10px; }

/* HUD chrome is not selectable / draggable (prevents the cursor freeze on press-drag) */
#stage, .corner, .center, .win-bar, .hud-btn, .state-label, .sys-text, .transcript, #orbWrap, .status-bar { user-select: none; -webkit-user-select: none; }
canvas, img, svg { -webkit-user-drag: none; user-drag: none; }
.chat-msg, .win-body, .panel-body, .modal-detail, input, textarea { user-select: text; -webkit-user-select: text; }

.gate-row { display: flex; gap: 8px; align-items: center; max-width: 340px; margin: 12px auto; }
.gate-row input { flex: 1; margin: 0; }

.ctx-item i { width: 10px; color: var(--cyan); font-family: var(--font-mono); }
.win-flags { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.12em; color: var(--ok); }

.preset-row { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 6px 8px; }
.preset-row .btn { flex: 1; text-align: center; }

/* always-visible model presets (bottom-right) */
.preset-bar { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.preset-bar button { background: transparent; border: 1px solid var(--line-2); border-radius: 6px; color: var(--text-2); font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.08em; padding: 5px 9px; cursor: pointer; transition: background 0.15s, color 0.15s; }
.preset-bar button:hover { background: var(--surface-2); color: var(--text); }
.preset-bar button.active { background: var(--surface-3); border-color: var(--cyan-dim); color: var(--text); }
@media (max-width: 900px) { .corner.br { display: block; bottom: 8px; right: 8px; left: 8px; text-align: center; } .corner.br .row { display: none; } .preset-bar { justify-content: center; } }

/* presets under the text box */
.center-presets { justify-content: center; align-items: center; margin-top: 2px; }
.center-presets .k { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.16em; color: var(--muted); margin-right: 4px; }
.center-presets button { padding: 5px 11px; font-size: 10.5px; }
#presetMore { background: transparent; }

/* ---------- cockpit HUD layout ---------- */
@media (min-width: 1400px) {
  .corner.tl, .corner.bl { left: 76px; }
  .corner.tr, .corner.br { right: 76px; }
}
@media (min-width: 1100px) {
  .corner.tr { display: grid; grid-template-columns: repeat(5, auto); gap: 6px; }
  .corner.tr .hud-btn { padding: 6px 12px; }
}
.corner.br .row b { max-width: min(300px, 22vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- chat window text bar (shown when the chat is maximized) ---------- */
.chat-wrap { display: flex; flex-direction: column; min-height: 100%; }
.chat-wrap .chat-log { flex: 1; }
.chat-bar { display: none; gap: 6px; align-items: center; position: sticky; bottom: -10px; margin: 10px -12px -10px; padding: 8px 12px 10px; background: var(--surface); border-top: 1px solid var(--line); }
.win.max .chat-bar { display: flex; }
.chat-bar-input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line-2); border-radius: 7px; color: var(--text); font-size: 16px; padding: 10px 12px; outline: 0; font-family: var(--font-body); }
.chat-bar-input:focus { border-color: var(--cyan-dim); }
.chat-bar-btn { background: transparent; border: 1px solid var(--line-2); border-radius: 7px; color: var(--text-2); font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.08em; padding: 10px 14px; cursor: pointer; }
.chat-bar-btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chat-bar-btn:hover { background: var(--surface-3); color: var(--text); }
.chat-bar-btn.primary:hover { background: #fff; color: var(--bg); }
#symBtn { font-size: 15px; min-width: 38px; }

/* ---------- symbol picker ---------- */
.sym-pop { position: fixed; z-index: 60; width: min(340px, 94vw); max-height: 60vh; overflow: auto; padding: 10px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow); }
.sym-h { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; margin: 6px 0 4px; }
.sym-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 4px; }
.sym-grid button { height: 32px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; color: var(--text); font-size: 17px; cursor: pointer; font-family: "Cambria Math", "Segoe UI Symbol", var(--font-body); }
.sym-grid button:hover { background: var(--surface-3); border-color: var(--line-2); }

/* ---------- rendered maths in chat ---------- */
.chat-msg .katex { font-size: 1.08em; color: var(--text); }
.chat-msg .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; margin: 6px 0; }
.chat-msg .text { white-space: pre-wrap; }

/* ---------- cursor always on top (menus and windows never cover it) ---------- */
#reticle { z-index: 2147483000; }

/* ---------- layout editor ---------- */
body.layout-edit [data-move] { pointer-events: auto !important; outline: 1px dashed rgba(var(--accent-rgb), 0.7); outline-offset: 4px; background-color: rgba(var(--accent-rgb), 0.04); }
body.layout-edit [data-move]:hover { outline-color: var(--text); background-color: rgba(var(--accent-rgb), 0.1); }
body.layout-edit [data-move] * { pointer-events: none; }
#layoutBar { position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 90; display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow); font-family: var(--font-mono); font-size: 12px; color: var(--text); max-width: 94vw; flex-wrap: wrap; justify-content: center; }
#layoutBar b { letter-spacing: 0.12em; color: var(--text); font-weight: 600; }
#layoutBar span { color: var(--muted); }
#layoutBar.top { bottom: auto; top: 10px; }

/* ---------- layout editor: resize handles + panels that re-arrange when resized ---------- */
.layout-handle { position: fixed; z-index: 88; width: 14px; height: 14px; cursor: nwse-resize; background: linear-gradient(135deg, transparent 50%, var(--text) 50%); opacity: 0.8; }
.layout-handle:hover { opacity: 1; }
.sized { container-type: inline-size; }
#orbWrap.sized { container-type: normal; aspect-ratio: auto; }
@container (max-width: 190px) { .brand { font-size: 15px; letter-spacing: 0.16em; } .sub { font-size: 10px; letter-spacing: 0.04em; } }
@container (max-width: 250px) {
  .row { flex-direction: column; align-items: flex-start; gap: 0; line-height: 1.25; margin-bottom: 5px; }
  .corner.br .row { flex-direction: column; align-items: flex-end; }
  .row b { white-space: normal; overflow-wrap: anywhere; max-width: 100% !important; }
  .preset-bar { flex-wrap: wrap; justify-content: flex-end; }
}
@container (max-width: 280px) { .hud-btn { padding: 5px 6px; font-size: 11px; } }
@container (max-width: 460px) { #textInput { font-size: 14px; } #sendBtn, #contBtn, #symBtn { padding: 6px 8px; font-size: 10px; } }
@container (max-width: 330px) { #contBtn { display: none; } #micBtn { width: 34px; height: 34px; } #textInput::placeholder { color: transparent; } }
@container (max-width: 240px) { #symBtn { display: none; } #sendBtn { padding: 6px; } }
@container (max-width: 380px) { .preset-bar { flex-wrap: wrap; justify-content: center; gap: 4px; } .preset-bar button { padding: 4px 7px; font-size: 9px; } .center-presets .k { display: none; } }
@container (max-width: 220px) { #statusText { font-size: 10px; letter-spacing: 0.06em; } .mic-meter { display: none; } }
#presetBarMain.sized, #statusBar.sized, #inputBar.sized, #transcript.sized, #stateLabel.sized, #sysText.sized { max-width: none; }
#transcript.sized, #stateLabel.sized, #sysText.sized { white-space: normal; height: auto; overflow-wrap: anywhere; }
#presetBarMain.sized { flex-wrap: wrap; justify-content: center; }
.corner.tr.sized { display: grid; gap: 6px; }
#inputBar.sized > button { flex-shrink: 0; }
#inputBar.sized input { min-width: 0; width: 0; flex: 1 1 auto; }

/* ---------- terminal output ---------- */
.term-cmd { font-family: var(--font-mono); font-size: 12px; color: var(--text); background: #0a0b0c; border-left: 2px solid var(--cyan-dim); border-radius: 0 5px 5px 0; padding: 6px 8px; margin: 6px 0; white-space: pre-wrap; word-break: break-word; }
.term-out { font-family: var(--font-mono); font-size: 11.5px; line-height: 1.45; color: var(--text-2); background: #0a0b0c; border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin: 6px 0; max-height: 40vh; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.line .v.bad { color: var(--err); }

/* ===== Holographic projection (Three.js + MediaPipe hand control) ===== */
#holoLayer { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#holoGl, #holoFx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#holoFx { z-index: 5; }
/* the core has always sat on a dark backdrop (the old bloom pass painted it opaque); keep that explicitly */
#holoGl { background: var(--bg); }
body.holo-clean #holoGl { background: #000; }
body.holo-on #orbWrap { opacity: 0.16; transition: opacity 0.6s; }
body.holo-on #stage .center .sys-text, body.holo-on #stage .state-label { opacity: 0.45; }
body.holo-on { cursor: crosshair; }

#holoBar {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 8; pointer-events: auto;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 8px 12px; max-width: 94vw;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px;
  font-family: var(--font-mono); font-size: 12px; color: var(--text);
}
#holoBar .ttl { font-family: var(--font-head); font-weight: 600; letter-spacing: 0.14em; color: var(--text); font-size: 12px; margin-right: 4px; }
#holoBar select { background: var(--surface-2); color: var(--text); border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 6px; font-family: var(--font-mono); font-size: 11px; }
#holoBar .btn { font-size: 12px; padding: 5px 10px; }
#holoBar .btn.on { background: var(--surface-3); border-color: var(--cyan-dim); color: var(--text); }
#holoBar .st { color: var(--muted); font-size: 11px; letter-spacing: 0.04em; }
#holoBar .st.ok { color: var(--ok); }
#holoBar .st.error { color: var(--err); }
#holoBar .st.wait { color: var(--warn); }
#holoBar .hint { flex-basis: 100%; text-align: center; color: var(--muted); font-size: 10.5px; letter-spacing: 0.02em; }

#holoCam {
  position: fixed; right: 16px; bottom: 16px; z-index: 8; pointer-events: none;
  border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; background: var(--surface);
}
#holoCam[hidden] { display: none; }
#holoCam canvas { display: block; width: 200px; height: 150px; }
#holoCam b { position: absolute; left: 8px; top: 5px; font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.1em; color: var(--text-2); font-weight: 400; }
@media (max-width: 760px) { #holoCam canvas { width: 132px; height: 99px; } #holoBar .hint { display: none; } }

/* ===== Hologram only: nothing on screen but the core (H toggles, Esc / double-click returns) ===== */
body.holo-clean { background: #000; cursor: none; }
body.holo-clean #stage, body.holo-clean #hud, body.holo-clean #bg, body.holo-clean .scanlines,
body.holo-clean #windows, body.holo-clean #holoBar, body.holo-clean #holoCam, body.holo-clean #reticle,
body.holo-clean #attackFx, body.holo-clean #layoutBar, body.holo-clean .layout-handle,
body.holo-clean .model-menu, body.holo-clean .ctx-menu, body.holo-clean .sym-pop, body.holo-clean .audio-gate {
  opacity: 0 !important; pointer-events: none !important; transition: opacity 0.5s;
}
#stage, #hud, #bg, #windows, #holoBar { transition: opacity 0.5s; }

/* ===== Phones and narrow tablets ===== */
@media (max-width: 900px) {
  html, body { overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
  body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  #stage { place-items: start center; }

  /* the menu: one row you swipe sideways, every button reachable */
  .corner.tr {
    top: calc(44px + env(safe-area-inset-top)); left: 0; right: 0; padding: 2px 12px 8px;
    flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; overflow-y: hidden; gap: 6px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch; pointer-events: auto;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 22px), transparent 100%);
            mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 22px), transparent 100%);
  }
  .corner.tr::-webkit-scrollbar { display: none; }
  .hud-btn { flex: 0 0 auto; min-height: 34px; padding: 8px 12px; font-size: 12.5px; white-space: nowrap; }
  #fsBtn { display: none; }                       /* phones have no use for the full-screen button */
  .corner.br { display: none !important; }        /* the model presets already sit under the input bar */

  .center { margin-top: calc(96px + env(safe-area-inset-top)); width: 94vw; gap: 8px; }
  #orbWrap { width: min(38vh, 78vw); }
  .transcript { font-size: 15px; max-width: 92%; }
  .input-bar { width: 100%; box-sizing: border-box; }
  .input-bar input { font-size: 16px; }           /* 16px stops iOS zooming into the field */
  .center-presets { flex-wrap: wrap; justify-content: center; gap: 6px; }
  .center-presets .k { display: none; }
  .center-presets button { padding: 8px 12px; }

  /* windows are bottom sheets; the chat brings its own text bar */
  .win { border-left: 0; border-right: 0; border-bottom: 0; border-radius: 12px 12px 0 0; clip-path: none; }
  .win-resize { display: none; }
  .win-bar { border-radius: 11px 11px 0 0; }
  .win-btn { min-width: 34px; min-height: 30px; }
  .win .chat-bar { display: flex !important; }
  body.has-win #orbWrap { width: min(26vh, 60vw); }
  body.has-win .sys-text, body.has-win .center-presets, body.has-win .status-bar, body.has-win #inputBar { display: none; }

  /* panels fill the screen and their tabs swipe */
  .panel { width: 100vw; max-width: 100vw; height: 100%; max-height: 100%; box-sizing: border-box; clip-path: none; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 0 0 auto; }
  .perm-grid { grid-template-columns: 1fr !important; }
  .modal-box { width: 92vw; max-width: 92vw; box-sizing: border-box; }
  #toasts { top: calc(96px + env(safe-area-inset-top)); width: 92vw; }

  /* the core: its bar takes the menu's place while it is projected */
  body.holo-on .corner.tl, body.holo-on .corner.tr { opacity: 0; pointer-events: none; }
  body.holo-on #stage { touch-action: none; }
  #holoBar { top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 8px; transform: none; max-width: none; gap: 6px; padding: 8px 10px; }
  #holoBar .ttl { flex-basis: 100%; text-align: center; font-size: 11px; }
  #holoBar .btn { flex: 1 1 auto; min-height: 36px; padding: 8px 8px; font-size: 12px; }
  #holoBar .st { flex-basis: 100%; text-align: center; font-size: 10px; }
  #holoBar .hint { display: none; }
  #holoCam { right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) { #hud { display: none !important; } }
body.holo-clean { touch-action: none; }

/* ===== Links: their own colour, never the theme's ===== */
:root { --link: #d9b36c; --link-visited: #b9a3d6; }
.win-body a, .tabpane a, .panel-body a, .chat-msg a, .floater a, .modal-box a, .note a, .msg a {
  color: var(--link); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; font-weight: 500;
}
.win-body a:visited, .tabpane a:visited, .panel-body a:visited, .chat-msg a:visited, .floater a:visited { color: var(--link-visited); }
.win-body a:hover, .tabpane a:hover, .panel-body a:hover, .chat-msg a:hover, .floater a:hover, .modal-box a:hover { color: var(--text); text-decoration-thickness: 2px; }

/* ===== The tabbed RESULTS window: one tab per pop-up, close the window to close them all ===== */
.win-body.tabbed { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.tabwin { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.tabstrip { display: flex; gap: 3px; padding: 6px 6px 0; overflow-x: auto; overflow-y: hidden; flex: 0 0 auto; scrollbar-width: none; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.tabstrip::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; min-width: 84px; max-width: 190px; padding: 6px 6px 6px 10px; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; background: transparent; color: var(--muted); font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer; transition: background 0.15s, color 0.15s; }
.tab:hover { color: var(--text); background: var(--surface-3); }
.tab.active { color: var(--text); border-color: var(--line-2); background: var(--surface); }
.tab .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: left; }
.tab .x { font-style: normal; font-size: 13px; line-height: 1; padding: 1px 4px; border-radius: 3px; opacity: 0.55; }
.tab .x:hover { opacity: 1; color: var(--text); background: var(--surface-3); }
.tabpane { flex: 1; min-height: 0; overflow: auto; padding: 10px 12px; font-size: 14px; line-height: 1.5; }
.tabbody[hidden] { display: none; }

@media (max-width: 900px) {
  .tab { min-height: 34px; max-width: 150px; }
  .tab .x { padding: 4px 8px; font-size: 15px; }
}

/* ===== Phones: panels are full-screen sheets that scroll inside, never sideways ===== */
@media (max-width: 900px) {
  .overlay { place-items: stretch; }
  .panel { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-left: 0; border-right: 0; border-radius: 0; animation: none; }
  .panel-head { padding: calc(12px + env(safe-area-inset-top)) 14px 12px; letter-spacing: 0.12em; font-size: 12px; flex: 0 0 auto; }
  .panel-head button { width: 38px; height: 38px; font-size: 18px; }
  .panel-body { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 14px 14px calc(24px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
  .panel-body *, .tabpane * { max-width: 100%; box-sizing: border-box; }
  .field { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .field > * { min-width: 0; }
  .field input[type=text], .field input[type=password], .field input[type=number], .field select, .field input[type=range] { width: 100%; min-width: 0; font-size: 16px; }
  .inline { flex-wrap: wrap; }
  .inline > * { flex: 1 1 auto; }
  .btn { min-height: 38px; }
  .console, .modal-detail, pre { white-space: pre-wrap; word-break: break-word; }
  .list .line, .line { flex-wrap: wrap; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 auto; }
}
@media (max-width: 900px) {
  .panel-body div[style*="display:flex"], .panel-body div[style*="display: flex"] { flex-wrap: wrap !important; }
  .panel-body p, .panel-body b, .panel-body .note, .panel-body .d, .tabpane, .chat-msg, .win-body { overflow-wrap: anywhere; }
}

/* ===== LISTEN: the open-mic button, and voice controls sized for thumbs ===== */
.chat-listen { display: none; }
.chat-listen.on, #contBtn.on { background: rgba(127, 184, 147, 0.12); border-color: rgba(127, 184, 147, 0.55); color: var(--ok); }
.mic, #contBtn, .chat-listen { touch-action: manipulation; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
@media (max-width: 900px) {
  #fsBtn { display: inline-block !important; }                      /* full screen is back on phones */
  .input-bar { flex-wrap: wrap; row-gap: 8px; }
  .input-bar input { flex: 1 1 0; }
  .mic { width: 46px; height: 46px; }
  .send, #symBtn { min-height: 44px; }
  #contBtn { order: 9; flex: 1 1 100%; min-height: 48px; font-size: 12px; letter-spacing: 0.2em; }   /* one big thumb-sized LISTEN bar */
  .chat-listen { display: block; min-height: 44px; padding: 10px 10px; }
  .chat-bar { flex-wrap: nowrap; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .chat-bar-btn { min-height: 44px; padding: 10px 10px; font-size: 11px; }
}
