:root {
  --hue: 193;                     /* accent hue — JS updates on theme change; all cyan tokens derive from this */
  --bg: #03070d;
  --panel: rgba(11, 24, 37, 0.74);
  --line: hsla(var(--hue), 80%, 68%, 0.28);
  --cyan: hsl(var(--hue), 95%, 65%);
  --cyan-dim: hsl(var(--hue), 60%, 75%);
  --glow: 79, 230, 255;          /* rgb triple matching --cyan; JS updates when theme changes */
  --text: #eaf6fd;
  --muted: #9fb6c8;
  --me: rgba(44, 112, 190, 0.45);
  /* Semantic accents (orb states, evaluator, errors) — single source for each hue. */
  --amber: #ffb454;  --amber-text: #ffcf6a;  --amber-glow: 255, 180, 84;
  --green: #2cf2c0;  --green-glow: 44, 242, 192;
  --red: #ff8080;    --red-text: #ff9a9a;    --red-glow: 255, 90, 90;
  /* Radius scale — every corner on the page uses one of these. */
  --r-sm: 0.45rem; --r-md: 0.6rem; --r-lg: 0.9rem; --r-pill: 999px;
  color-scheme: dark;
  --panel-w: 220px;
}

/* High-contrast / outdoor mode: solid panels, brighter text, no dimming overlays or glows —
   maximises legibility in bright sunlight (driving, outside). Toggled with the 🔆 button. */
body.hc {
  --panel: rgba(6, 14, 22, 0.95);
  --line: hsla(var(--hue), 80%, 68%, 0.55);
  --text: #ffffff;
  --muted: #d4e4f0;
  --cyan-dim: #cdeaf6;
  --me: rgba(28, 92, 170, 0.88);
}
body.hc .grid-bg, body.hc .vignette, body.hc .bracket { opacity: 0 !important; }
body.hc .msg { backdrop-filter: none; }
body.hc .wordmark .tag { opacity: 1; }
body.hc #clock, body.hc .wordmark h1, body.hc #send,
body.hc .msg.bot strong, body.hc #orb .orb-tag { text-shadow: none; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: radial-gradient(120% 90% at 50% -10%, #07172a 0%, #040a13 55%, #02060b 100%);
  color: var(--text);
  font-family: "Rajdhani", system-ui, sans-serif;
  font-weight: 500;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- Atmosphere ---- */
.grid-bg {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: 0.32;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(80% 70% at 50% 38%, #000 30%, transparent 80%);
}
.vignette { position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(70% 55% at 50% 42%, transparent 40%, rgba(0,0,0,0.55) 100%); }
/* CRT scanline effect — very subtle, adds depth without overwhelming the content. */
.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 2; opacity: 0.025;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px, transparent 3px,
    rgba(0,0,0,0.9) 3px, rgba(0,0,0,0.9) 4px
  );
}
body.hc .scanlines { display: none; }
.bracket { position: fixed; width: 26px; height: 26px; z-index: 2; pointer-events: none;
  border: 2px solid var(--cyan); opacity: 0.5; box-shadow: 0 0 12px rgba(var(--glow),0.4); }
.bracket.tl { top: 10px; left: 10px; border-right: 0; border-bottom: 0; }
.bracket.tr { top: 10px; right: 10px; border-left: 0; border-bottom: 0; }
.bracket.bl { bottom: 10px; left: 10px; border-right: 0; border-top: 0; }
.bracket.br { bottom: 10px; right: 10px; border-left: 0; border-top: 0; }

/* ---- Top HUD ---- */
#hud-top {
  position: relative; z-index: 3;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 1rem 1.2rem 0.4rem;
}
.clock-block { min-width: 6.5rem; }
#clock { font-family: "Orbitron", monospace; font-size: 1.5rem; font-weight: 700; letter-spacing: 2px;
  color: var(--cyan); text-shadow: 0 0 16px rgba(var(--glow),0.55); line-height: 1; }
#date { font-size: 0.7rem; letter-spacing: 3px; color: var(--muted); text-transform: uppercase; margin-top: 4px; }
.wordmark { text-align: center; flex: 1; }
.wordmark h1 { font-family: "Orbitron", sans-serif; font-weight: 900; font-size: 1.15rem; margin: 0;
  letter-spacing: 6px; color: #eaffff; text-shadow: 0 0 22px rgba(var(--glow),0.5); }
.wordmark .tag { font-size: 0.6rem; letter-spacing: 4px; color: var(--cyan-dim); opacity: 0.7; }
.actions { display: flex; gap: 0.4rem; min-width: 6.5rem; justify-content: flex-end; }
.actions button { width: 2.4rem; height: 2.4rem; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); font-size: 1rem;
  cursor: pointer; backdrop-filter: blur(6px); transition: border-color .2s, box-shadow .2s; }
.actions button:hover { border-color: var(--cyan); box-shadow: 0 0 14px rgba(var(--glow),0.35); }
.actions button.active { border-color: var(--cyan); color: var(--cyan); box-shadow: 0 0 12px rgba(var(--glow),0.3); }

/* ---- 3-column Command Deck ---- */
#deck {
  position: relative; z-index: 3;
  display: grid; grid-template-columns: var(--panel-w) 1fr var(--panel-w);
  flex: 1; min-height: 0;
}

/* ---- Stage (center column) ---- */
#stage { position: relative; z-index: 3; display: flex; flex-direction: column;
  align-items: center; min-height: 0; overflow: hidden; padding: 0.5rem 1rem 0; }

/* ---- The Orb ---- */
#orb {
  position: relative; width: clamp(110px, min(38vw, calc(100vw - 480px)), 230px); aspect-ratio: 1; flex-shrink: 0;
  display: grid; place-items: center; cursor: pointer; margin: clamp(0.4rem, 2vh, 1.4rem) 0 0.4rem;
  --accent: var(--cyan); --accent-soft: rgba(var(--glow), 0.22);
}
#orb[data-state="listening"] { --accent: var(--green); --accent-soft: rgba(var(--green-glow), 0.26); }
#orb[data-state="thinking"]  { --accent: var(--amber); --accent-soft: rgba(var(--amber-glow), 0.26); }
#orb[data-state="speaking"]  { --accent: #6aa0ff; --accent-soft: rgba(106, 160, 255, 0.28); }

.orb-ring { position: absolute; border-radius: 50%; border: 1px solid var(--accent-soft); }
.ring-1 { inset: 0;   border-style: dashed; border-color: var(--accent-soft); animation: spin 22s linear infinite; }
.ring-2 { inset: 11%; border-width: 2px; border-color: var(--accent-soft); animation: spin 14s linear infinite reverse; }
.ring-3 { inset: 22%; border-style: dotted; opacity: 0.8; animation: spin 9s linear infinite; }
.orb-scan { position: absolute; inset: 5%; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 78%, var(--accent-soft) 90%, transparent 100%);
  animation: spin 6s linear infinite; mix-blend-mode: screen; opacity: 0.7; }
.orb-core {
  position: absolute; inset: 31%; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #f0ffff 0%, var(--accent) 38%, rgba(4,18,26,0.9) 78%);
  box-shadow: 0 0 50px var(--accent), 0 0 110px var(--accent-soft), inset 0 0 30px rgba(255,255,255,0.25);
  animation: breathe 4.5s ease-in-out infinite;
}
.orb-tag { position: absolute; bottom: -1.4rem; font-size: 0.62rem; letter-spacing: 3px;
  color: var(--muted); text-transform: uppercase; }
#orb[data-state="idle"] .orb-tag { animation: blink 2.4s ease-in-out infinite; }
#orb[data-state="listening"] .orb-core { animation-duration: 1.3s; }
#orb[data-state="speaking"]  .orb-core { animation-duration: 0.9s; }
#orb[data-state="thinking"]  .ring-1 { animation-duration: 5s; }
#orb[data-state="thinking"]  .ring-2 { animation-duration: 3.5s; }
#orb[data-state="listening"] .orb-tag, #orb[data-state="thinking"] .orb-tag, #orb[data-state="speaking"] .orb-tag { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 0%,100% { transform: scale(0.96); opacity: 0.92; } 50% { transform: scale(1.05); opacity: 1; } }
@keyframes blink { 0%,100% { opacity: 0.35; } 50% { opacity: 0.9; } }

#callStatus { font-family: "Orbitron", sans-serif; font-size: 0.72rem; letter-spacing: 2px;
  text-transform: uppercase; color: var(--accent, var(--cyan)); margin-top: 0.6rem;
  text-shadow: 0 0 12px var(--cyan-dim); }
#callStatus.hidden { visibility: hidden; }

/* ---- Transcript ---- */
#messages {
  width: 100%; flex: 1; min-height: 0; overflow-y: auto;
  margin: 0.8rem 0 0.4rem; padding: 0.6rem 0.8rem 0.4rem;
  display: flex; flex-direction: column; gap: 0;
  mask-image: linear-gradient(to bottom, transparent, #000 8%, #000 92%, transparent);
}
#messages::-webkit-scrollbar { width: 0; }
.msg { max-width: 82%; padding: 0.55rem 0.85rem; line-height: 1.4; white-space: pre-wrap;
  font-size: 0.98rem; border: 1px solid var(--line); backdrop-filter: blur(4px); }
.msg.me { align-self: flex-end; background: var(--me); border-color: rgba(80,160,255,0.4);
  border-radius: var(--r-lg) var(--r-lg) 0.2rem var(--r-lg); }
.msg.bot { align-self: flex-start; background: var(--panel);
  border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 0.2rem; }
.msg.err { align-self: center; background: rgba(70,20,20,0.5); color: var(--red-text); border-color: rgba(var(--red-glow), 0.3);
  border-radius: var(--r-md); font-size: 0.85rem; }
/* Rendered markdown inside bot bubbles */
.msg.bot ul { margin: 0.3rem 0; padding-left: 1.2rem; }
.msg.bot li { margin: 0.15rem 0; }
.msg.bot div + div { margin-top: 0.3rem; }
.msg.bot strong { color: var(--cyan); }
.msg.bot code { background: rgba(255,255,255,0.08); padding: 0 0.25rem; border-radius: 0.25rem; font-size: 0.9em; }
.msg.bot a { color: var(--cyan); }

/* ---- Composer ---- */
#composer { position: relative; z-index: 3; display: flex; gap: 0.5rem; padding: 0.7rem 1rem 1rem; }
#composer button, #input { border: 1px solid var(--line); background: var(--panel); color: var(--text);
  backdrop-filter: blur(8px); }
#input { flex: 1; padding: 0.7rem 1rem; border-radius: var(--r-md); font-size: 1rem; font-family: inherit; letter-spacing: 0.3px; }
#input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 14px rgba(var(--glow),0.25); }
#mic { width: 3rem; border-radius: var(--r-md); font-size: 1.15rem; cursor: pointer; }
#mic.recording { background: rgba(var(--red-glow), 0.2); border-color: var(--red); animation: blink 1s infinite; }
#send { padding: 0 1.1rem; border-radius: var(--r-md); font-family: "Orbitron", sans-serif; font-size: 0.72rem;
  letter-spacing: 2px; color: var(--cyan); cursor: pointer; }
#send:hover { border-color: var(--cyan); box-shadow: 0 0 14px rgba(var(--glow),0.3); }
#attachBtn { width: 3rem; border-radius: var(--r-md); font-size: 1.15rem; cursor: pointer; }
#attachBtn:hover { border-color: var(--cyan); box-shadow: 0 0 14px rgba(var(--glow),0.25); }

/* ---- Drag & drop to ingest files ---- */
#dropZone { position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center; pointer-events: none;
  background: rgba(3,12,20,0.82); backdrop-filter: blur(4px);
  border: 2px dashed var(--cyan); box-shadow: inset 0 0 80px rgba(var(--glow),0.15); }
#dropZone.show { display: flex; }
#dropZone .drop-inner { font-family: "Orbitron", sans-serif; font-size: 1.3rem;
  letter-spacing: 2px; color: var(--cyan); text-align: center; line-height: 2; }

/* ---- Working indicator (animated dots) + busy composer ---- */
.msg.typing { display: inline-flex; gap: 5px; align-items: center; padding: 0.7rem 1rem; }
.msg.typing .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan);
  opacity: 0.35; animation: typedot 1.2s infinite ease-in-out; }
.msg.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.msg.typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typedot { 0%, 100% { opacity: 0.3; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-4px); box-shadow: 0 0 10px var(--cyan); } }
#composer.busy { opacity: 0.6; }
#composer.busy #input { cursor: progress; }
/* Orb dimmed while a text answer is still streaming — can't start a voice call until it resolves. */
#orb.locked { opacity: 0.45; filter: grayscale(0.4); cursor: not-allowed; }

/* ---- Generative UI cards (model fills components; it never writes CSS) ---- */
.card { position: relative; z-index: 3; align-self: flex-start; max-width: 88%;
  margin: 0.3rem 0; padding: 0.8rem 1rem; border: 1px solid var(--line);
  border-left: 3px solid var(--cyan); border-radius: var(--r-md); background: var(--panel);
  backdrop-filter: blur(8px); box-shadow: 0 0 22px rgba(var(--glow), 0.12); }
.card-title { font-family: "Orbitron", sans-serif; font-size: 0.8rem; letter-spacing: 1px;
  color: var(--cyan); margin-bottom: 0.5rem; text-transform: uppercase; }
.card-body { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.95rem; }
.card-row { display: flex; justify-content: space-between; gap: 1rem;
  border-bottom: 1px solid rgba(var(--glow), 0.08); padding-bottom: 0.25rem; }
.card-label { color: rgba(255, 255, 255, 0.82); }
.card-value { color: var(--text); font-weight: 600; text-align: right; }
.card-section { font-family: "Orbitron", sans-serif; font-size: 0.72rem; letter-spacing: 1px;
  color: var(--cyan); margin-top: 0.5rem; }
.card-list { margin: 0.2rem 0; padding-left: 1.1rem; }
.card-list li { margin: 0.15rem 0; }
.card-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 0.5rem; }
.stat-tile { text-align: center; padding: 0.5rem; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: rgba(var(--glow), 0.05); }
.stat-value { font-family: "Orbitron", sans-serif; font-size: 1.1rem; color: var(--cyan); }
.stat-label { font-size: 0.72rem; color: rgba(255, 255, 255, 0.82); margin-top: 0.2rem; }
.card-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.compare-col { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.5rem; }
.compare-name { font-weight: 700; color: var(--cyan); margin-bottom: 0.3rem; }
.compare-col ul { margin: 0; padding-left: 1rem; font-size: 0.88rem; }
.card-text { color: var(--text); }
.trend-row { display: grid; grid-template-columns: 66px 1fr 58px; align-items: center; gap: 0.5rem; margin: 0.15rem 0; }
.trend-label { font-size: 0.8rem; color: rgba(255, 255, 255, 0.6); }
.trend-track { height: 8px; border-radius: 4px; background: rgba(var(--glow), 0.1); overflow: hidden; }
.trend-fill { height: 100%; background: linear-gradient(90deg, rgba(var(--glow), 0.45), var(--cyan));
  box-shadow: 0 0 8px rgba(var(--glow), 0.4); }
.trend-value { text-align: right; font-weight: 600; color: var(--text); font-size: 0.85rem; }
.trend-change { margin-top: 0.4rem; color: var(--cyan); font-family: "Orbitron", sans-serif; font-size: 0.75rem; }
/* Checkable plan items: exercise name + sets×reps badge; tap to tick off during a workout. */
.card-list li { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.card-list li.done { opacity: 0.45; text-decoration: line-through; }
.card-list .item-badge { font-family: "Orbitron", sans-serif; font-size: 0.68rem; color: var(--cyan);
  border: 1px solid var(--line); border-radius: var(--r-pill); padding: 0.05rem 0.5rem; margin-left: 0.5rem;
  background: rgba(var(--glow), 0.06); white-space: nowrap; }
/* Macros card: kcal headline + bars sized by calorie share (protein cyan, fat amber, carb green). */
.macros-kcal { text-align: center; margin-bottom: 0.35rem; }
.macros-kcal-value { font-family: "Orbitron", sans-serif; font-size: 1.6rem; color: var(--cyan);
  text-shadow: 0 0 14px rgba(var(--glow), 0.5); }
.macros-kcal-unit { font-size: 0.78rem; color: rgba(255, 255, 255, 0.7); }
.macro-row { display: grid; grid-template-columns: 70px 1fr 56px; align-items: center; gap: 0.5rem; margin: 0.15rem 0; }
.macro-label { font-size: 0.8rem; color: rgba(255, 255, 255, 0.7); }
.macro-track { height: 10px; border-radius: 5px; background: rgba(var(--glow), 0.08); overflow: hidden; }
.macro-fill { height: 100%; border-radius: 5px; }
.macro-fill.protein { background: linear-gradient(90deg, rgba(var(--glow), 0.45), var(--cyan));
  box-shadow: 0 0 8px rgba(var(--glow), 0.4); }
.macro-fill.fat { background: linear-gradient(90deg, rgba(var(--amber-glow), 0.45), var(--amber));
  box-shadow: 0 0 8px rgba(var(--amber-glow), 0.4); }
.macro-fill.carb { background: linear-gradient(90deg, rgba(var(--green-glow), 0.45), var(--green));
  box-shadow: 0 0 8px rgba(var(--green-glow), 0.4); }
.macro-value { text-align: right; font-weight: 600; color: var(--text); font-size: 0.85rem; }
/* Progress ring (e.g. weight -> goal). */
.progress-wrap { position: relative; width: 96px; height: 96px; margin: 0.2rem auto; }
.progress-ring { width: 96px; height: 96px; }
.progress-ring .ring-bg { fill: none; stroke: rgba(var(--glow), 0.12); stroke-width: 8; }
.progress-ring .ring-fill { fill: none; stroke: var(--cyan); stroke-width: 8; stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: center;
  filter: drop-shadow(0 0 6px rgba(var(--glow), 0.55)); transition: stroke-dashoffset 0.8s ease; }
.progress-center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: "Orbitron", sans-serif; font-size: 1.05rem; color: var(--cyan); }
.cursor { display: inline-block; color: var(--cyan); margin-left: 1px; animation: curblink 1s step-end infinite; }
@keyframes curblink { 50% { opacity: 0; } }
/* Table card — finance/calendar data in structured rows. */
.card-table-wrap { overflow-x: auto; }
.card-table { width: 100%; border-collapse: collapse; font-size: 0.87rem; min-width: 180px; }
.card-table th { font-family: "Orbitron", sans-serif; font-size: 0.58rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--cyan); text-align: left;
  padding: 0.3rem 0.55rem; border-bottom: 1px solid rgba(var(--glow), 0.28); white-space: nowrap; }
.card-table td { padding: 0.27rem 0.55rem; border-bottom: 1px solid rgba(255,255,255,0.05);
  color: var(--text); }
.card-table tbody tr:last-child td { border-bottom: none; }
.card-table tbody tr:hover td { background: rgba(var(--glow), 0.04); }

/* ---- Business-evaluator mode badge ---- */
#evalBadge { position: relative; z-index: 3; align-self: center; margin: 0 1rem;
  display: inline-flex; gap: 0.5rem; align-items: center; cursor: pointer;
  font-family: "Orbitron", sans-serif; font-size: 0.7rem; letter-spacing: 1.5px;
  padding: 0.4rem 0.8rem; border-radius: var(--r-pill); color: var(--amber-text);
  border: 1px solid rgba(var(--amber-glow),0.5); background: rgba(var(--amber-glow),0.08);
  box-shadow: 0 0 16px rgba(var(--amber-glow),0.18); }
#evalBadge.hidden { display: none; }
#evalBadge .eval-x { color: rgba(255,255,255,0.7); font-size: 0.62rem; }
#evalBadge:hover { border-color: var(--amber-text); box-shadow: 0 0 20px rgba(var(--amber-glow),0.3); }
#evalToggle.active { color: var(--amber-text); border-color: rgba(var(--amber-glow),0.6);
  box-shadow: 0 0 16px rgba(var(--amber-glow),0.3); background: rgba(var(--amber-glow),0.12); }

/* ---- Dialogs ---- */
dialog { background: rgba(7,16,26,0.96); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: 0 0 60px rgba(0,0,0,0.7), 0 0 30px rgba(var(--glow),0.12);
  max-width: 92vw; max-height: 88dvh; overflow-y: auto; }
dialog::backdrop { background: rgba(2,6,11,0.75); backdrop-filter: blur(3px); }
dialog h2 { font-family: "Orbitron", sans-serif; font-size: 0.95rem; letter-spacing: 1px; margin: 0 0 0.6rem; color: var(--cyan); }
dialog label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.9rem; }
dialog input, dialog textarea { padding: 0.55rem; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-family: inherit; font-size: 1rem; }
dialog menu { padding: 0; margin: 1rem 0 0; display: flex; justify-content: flex-end; }
dialog menu button { padding: 0.55rem 1.3rem; min-height: 2.75rem; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--panel); color: var(--cyan); cursor: pointer; font-family: "Orbitron"; font-size: 0.7rem; letter-spacing: 1px; }
.muted { color: var(--muted); font-size: 0.85rem; }

#memory { width: 30rem; }
#syncAisos, #srcSync, #recallsBtn, #graphBtn { background: var(--panel); color: var(--cyan); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 0.45rem 0.8rem; cursor: pointer; }

/* ---- Knowledge graph (Obsidian-style force-directed canvas) ---- */
#graph { width: min(92vw, 58rem); }
#graphCanvas { width: 100%; height: min(60vh, 32rem); display: block; border: 1px solid var(--line);
  border-radius: var(--r-md); background: radial-gradient(circle at 50% 42%, rgba(var(--glow),0.06), var(--bg) 75%);
  touch-action: none; cursor: grab; }
#graphLegend { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; margin: 0.3rem 0 0.55rem; }
#graphLegend .chip { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.7rem;
  letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
#graphLegend .chip i { width: 0.6rem; height: 0.6rem; border-radius: 50%; display: inline-block;
  box-shadow: 0 0 6px currentColor; }
#memoryList, #sourcesList { list-style: none; padding: 0; margin: 0.75rem 0; max-height: 46vh; overflow-y: auto; }
#memoryList li, #sourcesList li { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
#memoryList .fact-type { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; }
#memoryList button, #sourcesList .src-actions button { background: none; border: none; cursor: pointer; font-size: 1rem; }
#memoryList button { color: var(--red); }
#sources { width: 32rem; }
.src-form { display: flex; flex-direction: column; gap: 0.4rem; margin: 0.75rem 0; }
.src-form input, .src-form textarea { font-size: 0.9rem; }
.src-form button { background: var(--me); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 0.45rem 0.8rem; cursor: pointer; align-self: flex-start; }

@media (max-width: 480px) {
  .wordmark h1 { font-size: 0.92rem; letter-spacing: 4px; }
  #clock { font-size: 1.2rem; }
  .clock-block, .actions { min-width: 0; }
  .wordmark .tag { display: none; }
}

/* ---- Accessibility ---- */
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .ring-1, .ring-2, .ring-3, .orb-scan, .orb-core, #orb[data-state="idle"] .orb-tag,
  #mic.recording, .msg.typing .dot, .cursor { animation: none; }
  .progress-ring .ring-fill { transition: none; }
}

/* ---- Theme swatches (settings dialog) ---- */
.theme-swatches { display: flex; gap: 0.45rem; margin-bottom: 0.8rem; flex-wrap: wrap; }
.swatch {
  width: 1.65rem; height: 1.65rem; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0; flex-shrink: 0; transition: border-color 0.15s, transform 0.15s;
}
.swatch:hover { transform: scale(1.15); border-color: rgba(255,255,255,0.45); }
.swatch.active { border-color: var(--text); box-shadow: 0 0 10px rgba(var(--glow),0.45); }

/* ---- Thought stream (tool activity — now in right panel) ---- */
#thought-stream {
  font-family: "Orbitron", sans-serif; font-size: 0.58rem; letter-spacing: 1px;
  color: var(--cyan); min-height: 1em; margin-top: 0.5rem;
  text-shadow: 0 0 10px rgba(var(--glow), 0.5); opacity: 0.85;
  word-break: break-word;
}
#thought-stream[hidden] { display: none; }

/* ---- Domain / token status bar (now in right panel) ---- */
#domain-bar {
  display: flex; flex-direction: column; gap: 0.1rem;
}
#domain-bar.hidden { display: none; }
#domain-label { color: var(--cyan); }
#token-count { color: var(--muted); }

/* ---- Pi system monitor (left panel block) ---- */
#sys-monitor {
  display: flex; flex-direction: column; gap: 0.4rem;
}
#sys-monitor.hidden { display: none; }
#cpu-spark { display: block; width: 100%; height: 36px;
  border: 1px solid rgba(var(--glow), 0.1); border-radius: var(--r-sm);
  background: rgba(var(--glow), 0.02); }
#sys-stats {
  display: flex; flex-direction: column; gap: 0.15rem;
  font-size: 0.58rem; color: var(--muted);
  font-family: "Orbitron", sans-serif; letter-spacing: 0.5px;
}

/* ---- Side panels ---- */
#panel-left, #panel-right {
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  padding: 0.7rem 0.65rem;
  gap: 0.9rem;
  background: rgba(4, 10, 18, 0.55);
  backdrop-filter: blur(6px);
}
#panel-left  { border-right: 1px solid var(--line); }
#panel-right { border-left:  1px solid var(--line); }
#panel-left::-webkit-scrollbar, #panel-right::-webkit-scrollbar { width: 0; }

.panel-section { display: flex; flex-direction: column; gap: 0.45rem; }

.panel-label {
  font-family: "Orbitron", monospace;
  font-size: 0.5rem; text-transform: uppercase; letter-spacing: 0.2em;
  color: var(--cyan); opacity: 0.7;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(var(--glow), 0.15);
}
.panel-label::before { content: "◈  "; }

/* ---- Context rows in right panel ---- */
.ctx-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.58rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px 0;
  border-bottom: 1px solid rgba(var(--glow), 0.04);
}
.ctx-row #domain-label, .ctx-row #token-count {
  font-family: "Orbitron", monospace; font-size: 0.58rem;
  letter-spacing: 0.5px;
}

/* ---- Composer prompt char ---- */
.prompt-char {
  color: var(--cyan); font-family: "Orbitron", monospace;
  font-size: 1rem; font-weight: 700; flex-shrink: 0;
  align-self: center; margin: 0 1px;
  text-shadow: 0 0 10px rgba(var(--glow), 0.5);
}

/* ---- HUD-style message transcript (overrides bubble style) ---- */
.msg {
  max-width: 100%;
  align-self: stretch;
  padding: 0.65rem 0.4rem 0.55rem;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-top: none;
  border-bottom: 1px solid rgba(var(--glow), 0.06);
  backdrop-filter: none;
  background: transparent;
}
.msg::before {
  display: block;
  font-family: "Orbitron", monospace;
  font-size: 0.48rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  margin-bottom: 6px;
  padding-bottom: 4px;
}
.msg.me {
  background: transparent;
  border-color: rgba(80, 160, 255, 0.08);
  border-radius: 0;
}
.msg.me::before {
  content: "USER";
  color: rgba(var(--glow), 0.45);
  border-bottom: 1px solid rgba(var(--glow), 0.1);
}
.msg.bot {
  background: transparent;
  border-radius: 0;
}
.msg.bot::before {
  content: "JARVIS";
  color: rgba(255, 255, 255, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.msg.err {
  border-radius: 0;
  background: transparent;
}
.msg.err::before {
  content: "ERROR";
  color: var(--red-text);
  border-bottom: 1px solid rgba(var(--red-glow), 0.2);
}
/* Typing bubble keeps its bubble shape */
.msg.typing {
  border-radius: var(--r-lg);
  background: var(--panel);
  align-self: flex-start;
  max-width: 82%;
  border: 1px solid var(--line);
}
.msg.typing::before { display: none; }

/* ---- Responsive: collapse panels on small screens ---- */
@media (max-width: 820px) {
  #deck { grid-template-columns: 1fr; }
  #panel-left, #panel-right { display: none; }
}

/* ---- Message entry animation ---- */
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg { animation: msgIn 0.18s ease-out both; }

/* ---- Message timestamp via ::after ---- */
.msg[data-time]::after {
  content: attr(data-time);
  display: block;
  font-family: "Orbitron", monospace;
  font-size: 0.44rem;
  color: rgba(255, 255, 255, 0.16);
  letter-spacing: 0.08em;
  text-align: right;
  margin-top: 7px;
}

/* ---- Stat grid (node count + temp) ---- */
.stat-grid { display: flex; flex-direction: column; gap: 0.2rem; }
.stat-grid-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.56rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); padding: 3px 0;
  border-bottom: 1px solid rgba(var(--glow), 0.04);
}
.stat-grid-row span:last-child {
  font-family: "Orbitron", monospace;
  font-size: 0.56rem; color: var(--text); letter-spacing: 0;
}

/* ---- Tool activity log (right panel) ---- */
#thought-stream {
  display: flex; flex-direction: column; gap: 3px;
  max-height: 10rem; overflow: hidden;
}
.tool-entry {
  font-family: "Orbitron", monospace;
  font-size: 0.52rem; color: var(--cyan); letter-spacing: 0.5px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(var(--glow), 0.06);
  animation: msgIn 0.15s ease-out both;
  opacity: 0.85;
}
.tool-entry::before { content: "→ "; opacity: 0.55; }

/* ---- Recall source cards (right panel) ---- */
#recall-list {
  display: flex; flex-direction: column; gap: 4px;
}
.recall-source {
  display: flex; align-items: baseline; gap: 5px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(var(--glow), 0.05);
  animation: msgIn 0.15s ease-out both;
}
.recall-type {
  font-family: "Orbitron", monospace;
  font-size: 0.42rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--cyan); opacity: 0.55; flex-shrink: 0;
  border: 1px solid rgba(var(--glow), 0.2);
  border-radius: var(--r-pill);
  padding: 1px 5px;
}
.recall-name {
  font-size: 0.58rem; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1; min-width: 0;
}

/* ---- Status dot on panel labels ---- */
.status-label::after {
  content: "";
  display: inline-block; width: 5px; height: 5px;
  border-radius: 50%; margin-left: 6px; vertical-align: middle;
  background: var(--muted); opacity: 0.5;
  transition: background 0.4s, opacity 0.4s;
}
.status-label.online::after  { background: var(--green); opacity: 1; box-shadow: 0 0 6px rgba(var(--green-glow),0.5); }
.status-label.warm::after    { background: var(--amber); opacity: 1; box-shadow: 0 0 6px rgba(var(--amber-glow),0.4); }
.status-label.hot::after     { background: var(--red);   opacity: 1; box-shadow: 0 0 6px rgba(var(--red-glow),0.5); }

/* ============================================================
   v40 — Animations, mobile-first, particle field
   ============================================================ */

/* ---- Floating particle canvas ---- */
#particles { position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: 0.5; }

/* ---- Boot overlay ---- */
#boot-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.1rem;
  background: var(--bg);
  transition: opacity 0.45s ease, visibility 0.45s;
}
#boot-overlay.boot-done { opacity: 0; visibility: hidden; }
.boot-logo {
  font-family: "Orbitron", sans-serif; font-weight: 900;
  font-size: clamp(2rem, 11vw, 4.2rem);
  letter-spacing: clamp(8px, 4vw, 18px);
  color: var(--cyan);
  text-shadow: 0 0 40px rgba(var(--glow), 0.9), 0 0 100px rgba(var(--glow), 0.35);
  animation: bootGlow 0.9s ease-in-out 2 alternate both;
}
.boot-sub {
  font-family: "Orbitron", sans-serif;
  font-size: clamp(0.42rem, 2vw, 0.6rem);
  letter-spacing: clamp(3px, 2vw, 7px);
  color: var(--cyan-dim); opacity: 0.65; text-transform: uppercase;
}
.boot-bar {
  width: min(200px, 52vw); height: 2px;
  background: rgba(var(--glow), 0.1); border-radius: 1px; overflow: hidden;
}
#boot-fill {
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--cyan));
  box-shadow: 0 0 14px rgba(var(--glow), 0.9);
  animation: bootLoad 1.5s cubic-bezier(0.35, 0, 0.15, 1) forwards;
}
.boot-status {
  font-family: "Orbitron", sans-serif; font-size: 0.5rem; letter-spacing: 3px;
  color: var(--muted); text-transform: uppercase;
  animation: bootBlink 0.7s steps(1) infinite;
}
@keyframes bootGlow  { from { opacity: 0.2; } to { opacity: 1; } }
@keyframes bootLoad  { from { width: 0; } to { width: 100%; } }
@keyframes bootBlink { 50% { opacity: 0; } }

/* ---- JARVIS wordmark: ambient glow pulse + periodic glitch ---- */
@keyframes titleGlow {
  0%, 100% { text-shadow: 0 0 22px rgba(var(--glow), 0.5); }
  50%       { text-shadow: 0 0 50px rgba(var(--glow), 1), 0 0 110px rgba(var(--glow), 0.35); }
}
@keyframes glitch {
  0%, 6%, 100% { filter: none; transform: none; }
  1%  { filter: hue-rotate(90deg) brightness(1.9); transform: translate(-3px, 0); }
  2%  { filter: hue-rotate(-90deg) brightness(0.7); transform: translate(3px, 0); }
  3%  { filter: none; transform: none; }
  4%  { filter: hue-rotate(180deg) brightness(2.2); transform: translate(-2px, 1px); }
  5%  { filter: none; transform: none; }
}
.wordmark h1 {
  animation: titleGlow 3.2s ease-in-out infinite,
             glitch 11s ease-in-out infinite 6s;
}

/* ---- Orb: outer expansion pulse ring ---- */
.orb-pulse {
  position: absolute; inset: -16%; border-radius: 50%;
  border: 1px solid var(--accent-soft); pointer-events: none;
  animation: orbExpand 3.8s ease-out infinite;
}
@keyframes orbExpand {
  0%   { opacity: 0.75; transform: scale(0.86); }
  65%  { opacity: 0;    transform: scale(1.24); }
  100% { opacity: 0;    transform: scale(1.24); }
}
#orb[data-state="listening"] .orb-pulse { animation-duration: 1.1s; }
#orb[data-state="thinking"]  .orb-pulse { animation-duration: 0.7s; }
#orb[data-state="speaking"]  .orb-pulse { animation-duration: 0.85s; }

/* ---- Enhanced message entrance — slide from side ---- */
@keyframes msgInBot {
  from { opacity: 0; transform: translate(-10px, 5px) scale(0.97); }
  to   { opacity: 1; transform: translate(0, 0)       scale(1); }
}
@keyframes msgInMe {
  from { opacity: 0; transform: translate(10px, 5px) scale(0.97); }
  to   { opacity: 1; transform: translate(0, 0)      scale(1); }
}
.msg.bot { animation: msgInBot 0.22s ease-out both; }
.msg.me  { animation: msgInMe  0.22s ease-out both; }

/* ---- Settings dialog: theme section ---- */
.settings-theme { margin-bottom: 0.9rem; }
.settings-theme-label {
  display: block; margin-bottom: 0.5rem;
  font-family: "Orbitron", monospace; font-size: 0.5rem; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--cyan); opacity: 0.7;
}

/* ---- Mobile bottom navigation pill ---- */
#mobile-nav {
  display: none;
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 0.55rem);
  left: 50%; transform: translateX(-50%);
  z-index: 20;
  background: rgba(6, 14, 24, 0.92);
  backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 0.28rem 0.5rem;
  gap: 0;
  flex-direction: row;
  box-shadow: 0 0 32px rgba(var(--glow), 0.2), 0 8px 28px rgba(0,0,0,0.6);
}
#mobile-nav button {
  width: 3.1rem; height: 3.1rem; border-radius: 50%;
  background: transparent; border: none; font-size: 1.25rem;
  cursor: pointer; display: grid; place-items: center;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent; color: inherit;
}
#mobile-nav button:active { background: rgba(var(--glow), 0.15); transform: scale(0.9); }
#mobile-nav button.active { color: var(--cyan); }

@media (max-width: 820px) {
  #mobile-nav { display: flex; }
  /* Push composer up so mobile nav pill doesn't overlap the input */
  #composer { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 4.7rem); }
  /* HUD action buttons duplicated by mobile-nav — hide to declutter the header */
  .actions { display: none; }
  /* Slightly taller orb container on mobile */
  #orb { margin-top: 0.2rem; }
  /* Slightly larger composer input text for thumb comfort */
  #input { font-size: 1.05rem; }
  /* Bigger composer action buttons for thumb reach */
  #mic, #attachBtn { width: 3.4rem; height: 3.4rem; font-size: 1.25rem; }
  #send { padding: 0 1.4rem; min-height: 3.2rem; }
  /* Taller list rows in dialogs for touch targets */
  #memoryList li, #sourcesList li { min-height: 2.75rem; padding: 0.65rem 0; }
  #memoryList button, #sourcesList .src-actions button { width: 2.4rem; height: 2.4rem; }
  /* Utility buttons in dialogs */
  #syncAisos, #srcSync, #recallsBtn, #graphBtn, #srcSave { min-height: 2.75rem; padding: 0.55rem 1rem; }
}

/* Landscape on narrow devices: nav pill eats too much vertical space — hide it and restore HUD actions */
@media (max-width: 820px) and (orientation: landscape) {
  #mobile-nav { display: none; }
  .actions { display: flex; }
  #composer { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 0.7rem); }
  #orb { width: clamp(60px, 20vh, 100px); }
}

/* ============================================================
   v41 — Deep mobile-first pass (keyboard, orb, swatches, dialogs)
   ============================================================ */

/* Dynamic viewport height: body shrinks when iOS keyboard appears so composer stays visible */
body { height: 100dvh; }

/* Memory action buttons wrapper — flex row that wraps on narrow screens */
.memory-actions {
  display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem;
}

@media (max-width: 820px) {
  /* Orb: panels hidden → full stage width → make it much larger */
  #orb { width: min(190px, 48vw); }

  /* Swatches in settings dialog: bigger touch targets */
  #settings .swatch { width: 2.5rem; height: 2.5rem; }

  /* Source textarea: shorter so dialog fits on screen with keyboard open */
  #srcContent { max-height: 5rem; resize: none; }

  /* Graph canvas: shorter on portrait mobile */
  #graphCanvas { height: min(42vh, 250px); }

  /* Memory action buttons: give each enough flex so they fill two columns */
  .memory-actions button { flex: 1; min-width: 8rem; }
}

/* ---- Reduced motion overrides for v40 additions ---- */
@media (prefers-reduced-motion: reduce) {
  .boot-logo, .boot-status, #boot-fill,
  .orb-pulse, .wordmark h1,
  .msg.bot, .msg.me { animation: none !important; }
  #particles { display: none; }
}

/* ============================================================
   v42 — Brain search inside the memory dialog
   ============================================================ */
.brain-search { margin-bottom: 0.5rem; }
#brainSearchInput {
  width: 100%; box-sizing: border-box; padding: 0.5rem 0.75rem;
  background: transparent; border: 1px solid var(--cyan);
  border-radius: 4px; color: var(--text); font-family: inherit; font-size: 1rem;
}
#brainSearchInput:focus {
  outline: none; border-color: var(--cyan);
  box-shadow: 0 0 6px rgba(var(--glow), 0.4);
}
#brainSearchResults {
  list-style: none; padding: 0; margin: 0 0 0.75rem;
  max-height: 14rem; overflow-y: auto;
}
#brainSearchResults li { padding: 0.4rem 0; border-bottom: 1px solid rgba(255,255,255,.07); }
#brainSearchResults li:last-child { border-bottom: none; }
.brain-result-type {
  font-size: 0.68rem; opacity: 0.55; text-transform: uppercase;
  letter-spacing: .05em; margin-right: 0.35rem;
}
.brain-result-name { font-weight: 600; font-size: 0.9rem; }
.brain-result-detail {
  font-size: 0.78rem; opacity: 0.65; margin: 0.1rem 0 0; line-height: 1.4;
}

/* Music player card — embedded YouTube iframe that auto-plays */
.card-music .music-player {
  width: 100%; aspect-ratio: 16/9;
  border: none; border-radius: 6px; margin-top: 0.4rem; display: block;
}
.music-channel { font-size: 0.75rem; opacity: 0.55; margin-bottom: 0.25rem; }

/* Spotify card — album art + deep-link button (no Premium required) */
.spotify-art { width: 100%; aspect-ratio: 1; border-radius: 6px; object-fit: cover; display: block; margin-bottom: 0.5rem; }
.spotify-subtitle { font-size: 0.9rem; opacity: 0.8; margin-bottom: 0.15rem; }
.spotify-type-label { font-size: 0.72rem; opacity: 0.5; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.6rem; }
.spotify-open-btn {
  display: inline-block;
  background: #1DB954;
  color: #000;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.45rem 1.1rem;
  border-radius: 2rem;
  text-decoration: none;
  margin-top: 0.2rem;
}
.spotify-open-btn:hover { background: #1ed760; }
