/* ── AION — Immersive 3D ────────────────────────────────────────────────── */
:root {
  --primary:  #7c3aed;
  --primary2: #5b21b6;
  --accent:   #a78bfa;
  --glass:    rgba(6,4,20,0.8);
  --border:   rgba(124,58,237,0.25);
  --text:     #e2e8f0;
  --muted:    #64748b;
  --green:    #10b981;
  --red:      #ef4444;
  --yellow:   #f59e0b;
  --radius:   14px;
  --drawer-w: 380px;
  --tab-w:    42px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width:100%; height:100%; overflow:hidden; background:#04040f; color:var(--text); font-family:'Inter',system-ui,sans-serif; }
.hidden { display:none !important; }

/* ── Auth ─────────────────────────────────────────────────────────────────── */
#auth-screen {
  position:fixed; inset:0; z-index:100;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2rem; padding:2rem;
  background:radial-gradient(ellipse at 50% 30%,rgba(124,58,237,.2),transparent 70%),#04040f;
}
.auth-logo { text-align:center; }
.auth-orb { width:64px; height:64px; border-radius:50%; margin:0 auto 1rem; background:radial-gradient(circle,#a78bfa,#5b21b6); box-shadow:0 0 40px rgba(124,58,237,.6); animation:orb-pulse 2s ease-in-out infinite; }
@keyframes orb-pulse { 0%,100%{box-shadow:0 0 40px rgba(124,58,237,.6)}50%{box-shadow:0 0 70px rgba(124,58,237,.9)} }
.auth-logo h1 { font-size:2.2rem; font-weight:900; background:linear-gradient(135deg,#a78bfa,#60a5fa); -webkit-background-clip:text; -webkit-text-fill-color:transparent; }
.auth-logo p  { color:var(--muted); font-size:.9rem; margin-top:.3rem; }
.auth-card { background:rgba(12,6,32,.8); border:1px solid var(--border); border-radius:var(--radius); padding:1.75rem; width:100%; max-width:380px; backdrop-filter:blur(20px); box-shadow:0 24px 48px rgba(0,0,0,.6); }
.tabs { display:flex; gap:.5rem; margin-bottom:1.25rem; }
.tab-btn { flex:1; padding:.5rem; border:none; border-radius:8px; background:rgba(255,255,255,.05); color:var(--muted); cursor:pointer; font-size:.9rem; font-weight:500; transition:all .2s; }
.tab-btn.active { background:var(--primary); color:white; }
.form-group { display:flex; flex-direction:column; gap:.3rem; margin-bottom:.9rem; }
.form-group label { font-size:.78rem; color:var(--muted); font-weight:500; }
.form-group input { padding:.6rem .85rem; border:1px solid var(--border); border-radius:8px; background:rgba(255,255,255,.04); color:var(--text); font-size:.9rem; outline:none; transition:border .2s; }
.form-group input:focus { border-color:var(--primary); }
.btn-primary { width:100%; padding:.72rem; background:var(--primary); color:white; border:none; border-radius:8px; font-size:1rem; font-weight:600; cursor:pointer; transition:background .2s; }
.btn-primary:hover { background:var(--primary2); }

/* ── Main App ─────────────────────────────────────────────────────────────── */
#app { position:fixed; inset:0; }
#world-canvas { position:absolute; inset:0; width:100%!important; height:100%!important; z-index:0; }

/* ── TOP HUD ──────────────────────────────────────────────────────────────── */
#top-hud {
  position:absolute; top:0; left:0; right:0; z-index:10;
  display:flex; align-items:center; gap:1rem; padding:.75rem 1.5rem;
  background:linear-gradient(to bottom,rgba(4,4,15,.75),transparent);
}
.hud-logo { font-size:1rem; font-weight:800; letter-spacing:-.2px; }
.hud-status { font-size:.78rem; color:var(--accent); flex:1; transition:color .3s; }
.hud-right { display:flex; align-items:center; gap:.6rem; margin-left:auto; }
.budget-wrap { display:flex; flex-direction:column; gap:2px; }
.budget-track { width:70px; height:3px; background:rgba(255,255,255,.1); border-radius:2px; overflow:hidden; }
#budget-bar { height:100%; background:linear-gradient(90deg,var(--green),var(--primary)); transition:width .5s; width:0; }
.budget-lbl { font-size:.6rem; color:var(--muted); }
.hud-btn { background:rgba(255,255,255,.06); border:1px solid var(--border); color:var(--muted); border-radius:8px; padding:.35rem .6rem; cursor:pointer; font-size:.85rem; transition:all .2s; backdrop-filter:blur(8px); }
.hud-btn:hover { color:var(--text); border-color:var(--primary); }

/* ── AION — center ───────────────────────────────────────────────────────── */
#aion-wrap {
  position:absolute; left:50%; top:50%;
  transform:translate(-50%,-42%);
  z-index:5;
  display:flex; flex-direction:column; align-items:center;
  pointer-events:none;
  filter:drop-shadow(0 0 40px rgba(59,130,246,.4));
  transition:transform .55s cubic-bezier(.4,0,.2,1), filter .3s;
}
/* Cuando AION proyecta en pantalla: se encoge y va a la esquina superior derecha */
#aion-wrap.docked {
  transform:translate(calc(-50% + 36vw), calc(-42% - 32vh)) scale(.5);
  z-index:9;
}
#aion-wrap:hover { filter:drop-shadow(0 0 60px rgba(96,165,250,.65)); }
#aion-canvas {
  cursor:pointer; pointer-events:all;
  background:transparent;
  display:block;
}
#avatar3d-canvas { cursor:pointer; pointer-events:auto; }
#aion-canvas.sleeping { cursor:pointer; animation:sleep-float 4s ease-in-out infinite; }
@keyframes sleep-float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }

/* Indicador del cerebro activo — JUSTO encima de la cabeza, debajo de la burbuja */
#brain-indicator {
  position:absolute; bottom:calc(100% + 6px); left:50%; transform:translateX(-50%) translateY(6px);
  display:none; align-items:center; gap:.4rem;
  padding:.34rem .75rem; border-radius:999px;
  background:rgba(10,8,30,.92); border:1px solid rgba(167,139,250,.6);
  box-shadow:0 0 22px rgba(124,58,237,.6);
  font-size:.78rem; font-weight:700; color:#e9d5ff; white-space:nowrap;
  pointer-events:none; backdrop-filter:blur(6px);
  opacity:0; transition:opacity .25s, transform .25s;
  z-index:15;   /* debajo de la burbuja de voz (#speech-holo es z-index:20) */
}
#brain-indicator.show { display:flex; opacity:1; transform:translateX(-50%) translateY(0); }
#brain-indicator .bi-icon { font-size:1rem; animation:brain-pulse 1.1s ease-in-out infinite; }
@keyframes brain-pulse { 0%,100%{opacity:.55;transform:scale(.92)} 50%{opacity:1;transform:scale(1.12)} }

/* Wake hint */
.wake-hint {
  position:absolute; bottom:-30px; left:50%; transform:translateX(-50%);
  font-size:.72rem; color:rgba(167,139,250,.6);
  white-space:nowrap; pointer-events:none;
  animation:hint-pulse 2.5s ease-in-out infinite;
}
@keyframes hint-pulse { 0%,100%{opacity:.4} 50%{opacity:.9} }
.wake-hint.hidden { display:none; }

/* Holographic speech bubble — sobre el indicador, ancho cómodo */
#speech-holo {
  position:absolute; bottom:calc(100% + 46px); left:50%;
  transform:translateX(-50%);
  background:rgba(6,4,20,.92);
  border:1px solid rgba(167,139,250,.35);
  border-radius:14px; padding:.7rem 1.2rem;
  font-size:.9rem; color:var(--text);
  width:max-content; max-width:min(70vw, 520px); text-align:center;
  white-space:pre-wrap; word-break:break-word;
  backdrop-filter:blur(16px);
  box-shadow:0 0 30px rgba(59,130,246,.25), inset 0 1px 0 rgba(255,255,255,.06);
  animation:holo-in .25s ease; z-index:20;
}
#speech-holo::after { content:''; position:absolute; top:100%; left:50%; transform:translateX(-50%); border:8px solid transparent; border-top-color:rgba(6,4,20,.92); }
@keyframes holo-in { from{opacity:0;transform:translateX(-50%) translateY(10px)} to{opacity:1;transform:translateX(-50%) translateY(0)} }

/* Waveform center-bottom (subtle, only when active) */
.waveform-center {
  position:absolute; bottom:28px; left:50%; transform:translateX(-50%);
  z-index:6; display:none;
  width:200px!important; height:50px!important;
  pointer-events:none;
}
.waveform-center.active { display:block; }

/* ── CHAT DRAWER ──────────────────────────────────────────────────────────── */
#chat-drawer {
  position:absolute; right:0; top:24rem;   /* DEBAJO del panel de Controles abierto → no se solapan */
  transform:translateX(calc(100% - var(--tab-w)));
  width:var(--drawer-w);
  max-height:calc(100vh - 25rem);
  z-index:20;
  display:flex;
  transition:transform .45s cubic-bezier(.4,0,.2,1);
  filter:drop-shadow(-8px 0 32px rgba(0,0,0,.6));
}
#chat-drawer.open {
  transform:translateX(0);
}
/* Pestañas como handles cortos arriba de cada drawer → Controles y Chat se apilan sin solaparse */
#chat-tab, #controls-tab { align-self:flex-start; height:6.5rem; }

/* Tab handle — always peeking from the right edge */
#chat-tab {
  width:var(--tab-w); flex-shrink:0;
  background:rgba(12,6,32,.85);
  border:1px solid var(--border); border-right:none;
  border-radius:12px 0 0 12px;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:.35rem;
  cursor:pointer; padding:.6rem 0;
  backdrop-filter:blur(16px);
  transition:background .2s;
}
#chat-tab:hover { background:rgba(124,58,237,.2); }
.chat-tab-icon { font-size:1.2rem; }
.chat-tab-label { font-size:.58rem; color:var(--muted); font-weight:600; letter-spacing:.04em; writing-mode:vertical-rl; text-orientation:mixed; }

/* Drawer body */
.drawer-body {
  flex:1; display:flex; flex-direction:column; overflow:hidden;
  background:rgba(6,4,20,.88);
  border:1px solid var(--border); border-right:none;
  backdrop-filter:blur(24px);
  border-radius:12px 0 0 12px;
}

.terminal-header { display:flex; align-items:center; gap:.4rem; padding:.55rem .9rem; background:rgba(255,255,255,.025); border-bottom:1px solid var(--border); flex-shrink:0; }
.terminal-dot { width:11px; height:11px; border-radius:50%; flex-shrink:0; }
.terminal-dot.red{background:#ef4444} .terminal-dot.yellow{background:#f59e0b} .terminal-dot.green{background:#10b981}
.terminal-title { flex:1; font-size:.72rem; color:var(--muted); font-family:monospace; padding-left:.4rem; }
.terminal-clear { background:none; border:none; color:var(--muted); cursor:pointer; font-size:.8rem; padding:.1rem .3rem; border-radius:4px; }
.terminal-clear:hover { color:var(--text); background:rgba(255,255,255,.06); }

.terminal-output {
  flex:1; overflow-y:auto; padding:.75rem 1rem;
  font-family:'JetBrains Mono','Fira Code',monospace;
  font-size:.78rem; line-height:1.6; min-height:120px; max-height:280px;
  scrollbar-width:thin; scrollbar-color:rgba(124,58,237,.3) transparent;
}
.tline { margin-bottom:.2rem; display:flex; gap:.5rem; align-items:flex-start; }
.tline-time { color:var(--muted); font-size:.65rem; flex-shrink:0; padding-top:.12rem; }
.tline-user .tline-text::before { content:'❯ '; color:var(--accent); }
.tline-user .tline-text { color:#e2e8f0; }
.tline-aion .tline-text { color:#86efac; }
.tline-system .tline-text { color:var(--muted); font-size:.7rem; }
.tline-error .tline-text { color:#fca5a5; }
.tline-meta { font-size:.62rem; color:#475569; margin-bottom:.4rem; padding-left:3.5rem; }
.tline-file .tline-text::before { content:'📎 '; }
.tline-file .tline-text { color:#60a5fa; }

/* Artifact inside drawer */
.artifact-view { border-top:1px solid var(--border); display:flex; flex-direction:column; max-height:260px; flex-shrink:0; }
.artifact-view-header { display:flex; align-items:center; padding:.4rem .75rem; background:rgba(124,58,237,.08); border-bottom:1px solid var(--border); flex-shrink:0; }
.artifact-tabs-row { display:flex; gap:.3rem; flex:1; overflow-x:auto; scrollbar-width:none; }
.artifact-tab { padding:.2rem .55rem; border:1px solid var(--border); border-radius:20px; background:rgba(255,255,255,.04); color:var(--muted); font-size:.7rem; cursor:pointer; white-space:nowrap; transition:all .15s; }
.artifact-tab:hover { color:var(--text); }
.artifact-tab.active { background:var(--primary); color:white; border-color:var(--primary); }
.artifact-close { background:none; border:none; color:var(--muted); cursor:pointer; font-size:.85rem; }
.artifact-content { flex:1; overflow-y:auto; padding:.75rem; scrollbar-width:thin; scrollbar-color:rgba(124,58,237,.3) transparent; }

/* Terminal input */
.terminal-input-wrap { display:flex; align-items:flex-end; gap:.4rem; padding:.55rem .75rem; border-top:1px solid var(--border); background:rgba(255,255,255,.015); flex-shrink:0; }
.terminal-prompt { color:var(--accent); font-family:monospace; font-size:.9rem; padding-bottom:.1rem; flex-shrink:0; }
#terminal-input { flex:1; background:transparent; border:none; outline:none; color:var(--text); font-family:'JetBrains Mono',monospace; font-size:.82rem; resize:none; max-height:100px; line-height:1.5; scrollbar-width:none; }
#terminal-input::placeholder { color:rgba(100,116,139,.45); }
.attach-btn { color:var(--muted); cursor:pointer; font-size:1rem; flex-shrink:0; transition:color .2s; }
.attach-btn:hover { color:var(--accent); }
.terminal-send { background:var(--primary); border:none; color:white; width:30px; height:30px; border-radius:8px; cursor:pointer; font-size:.9rem; flex-shrink:0; transition:background .2s; display:flex; align-items:center; justify-content:center; }
.terminal-send:hover { background:var(--primary2); }
#terminal-panel.drag-over { border-color:var(--accent); }

/* ── Artifact renderers ────────────────────────────────────────────────────── */
.artifact-code { border-radius:9px; overflow:hidden; border:1px solid rgba(124,58,237,.2); }
.code-header { display:flex; align-items:center; justify-content:space-between; padding:.4rem .85rem; background:rgba(255,255,255,.04); border-bottom:1px solid rgba(124,58,237,.15); }
.code-lang { font-size:.7rem; color:var(--accent); font-weight:700; font-family:monospace; }
.code-copy { padding:.2rem .5rem; background:var(--primary); color:white; border:none; border-radius:5px; font-size:.68rem; cursor:pointer; }
.artifact-code pre { margin:0; border-radius:0; max-height:320px; overflow-y:auto; }
.artifact-code code { font-size:.78rem!important; }
.artifact-chart { height:240px; }
.artifact-chart canvas { width:100%!important; height:100%!important; }
.artifact-markdown { font-size:.85rem; line-height:1.7; }
.artifact-markdown h1,.artifact-markdown h2,.artifact-markdown h3 { color:#a78bfa; margin:.9rem 0 .35rem; font-weight:700; }
.artifact-markdown h1 { font-size:1.2rem; }
.artifact-markdown h2 { font-size:1rem; }
.artifact-markdown code { background:rgba(124,58,237,.2); border-radius:4px; padding:.1rem .3rem; font-size:.82em; color:#f0abfc; }
.artifact-markdown pre { background:#1e1e2e; border-radius:7px; padding:.8rem; overflow-x:auto; margin:.5rem 0; }
.artifact-markdown pre code { background:none; padding:0; }
.artifact-markdown blockquote { border-left:3px solid var(--primary); padding-left:.85rem; color:var(--muted); }
.artifact-markdown strong { color:#fbbf24; }
.artifact-markdown a { color:#60a5fa; }
.artifact-markdown table { border-collapse:collapse; width:100%; }
.artifact-markdown th,.artifact-markdown td { border:1px solid var(--border); padding:.4rem .65rem; }
.artifact-markdown th { background:rgba(124,58,237,.15); color:#a78bfa; }
.artifact-table { overflow-x:auto; }
.stage-table { border-collapse:collapse; width:100%; font-size:.82rem; }
.stage-table th { background:rgba(124,58,237,.15); color:#a78bfa; font-weight:600; text-align:left; padding:.5rem .75rem; border:1px solid var(--border); }
.stage-table td { padding:.4rem .75rem; border:1px solid var(--border); }
.stage-table tr:nth-child(even) td { background:rgba(255,255,255,.02); }
.stage-table tr:hover td { background:rgba(124,58,237,.07); }
.checklist { list-style:none; display:flex; flex-direction:column; gap:.45rem; }
.check-item { display:flex; align-items:center; gap:.6rem; padding:.5rem .85rem; background:rgba(255,255,255,.03); border:1px solid var(--border); border-radius:8px; cursor:pointer; }
.check-item.done label { text-decoration:line-through; color:var(--muted); }
.check-item input[type=checkbox] { accent-color:var(--primary); width:15px; height:15px; cursor:pointer; }
.check-item label { cursor:pointer; font-size:.86rem; }
.artifact-text { font-size:.88rem; line-height:1.7; }

/* ── Pair / QR ────────────────────────────────────────────────────────────── */
#pair-screen { position:fixed; inset:0; z-index:200; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2rem; padding:2rem; background:radial-gradient(ellipse at 50% 30%,rgba(124,58,237,.2),transparent 70%),#04040f; }
#qr-modal { position:fixed; inset:0; background:rgba(0,0,0,.75); display:flex; align-items:center; justify-content:center; z-index:300; }
.qr-modal-content { background:rgba(6,4,20,.9); border:1px solid var(--border); border-radius:var(--radius); padding:2rem; text-align:center; max-width:300px; backdrop-filter:blur(20px); }
.qr-modal-content img { width:190px; height:190px; border-radius:8px; }
.qr-pin { font-size:2rem; font-weight:800; letter-spacing:.2em; color:var(--primary); margin:.75rem 0; }

/* ── Error toast ──────────────────────────────────────────────────────────── */
.error-toast { position:fixed; top:1rem; right:1.5rem; background:var(--red); color:white; padding:.7rem 1rem; border-radius:9px; font-size:.87rem; z-index:999; animation:toast-in .25s ease; max-width:280px; }
@keyframes toast-in { from{opacity:0;transform:translateY(-8px)} to{opacity:1;transform:translateY(0)} }

/* ── Scrollbars ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width:4px; height:4px; }
::-webkit-scrollbar-track { background:transparent; }
::-webkit-scrollbar-thumb { background:rgba(124,58,237,.3); border-radius:2px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width:640px) {
  :root { --drawer-w:calc(100vw - 30px); --tab-w:36px; }
  /* Controles arriba, Chat debajo del panel de Controles (apilados, sin solaparse). */
  #chat-drawer { top:22rem; max-height:calc(100vh - 23rem); }
  .waveform-center { bottom:12px; width:140px!important; }
  /* PWA móvil: áreas de toque ≥44px y controles alcanzables */
  .dtool { padding:.65rem .75rem; font-size:1.15rem; }
  #draw-fab { width:48px; height:48px; font-size:1.3rem; }
  #backdrop-close { top:max(12px, env(safe-area-inset-top)); padding:.55rem .9rem; font-size:1.05rem; }
  .hud-btn { padding:.5rem .55rem; font-size:1.05rem; }
  #deck-bar button { padding:.6rem .8rem !important; font-size:.85rem !important; }
  /* La fila superior no cabía en el teléfono y el último botón (⏻) se cortaba:
     respetar márgenes seguros, dejar que el estado encoja con elipsis, que los
     botones NUNCA se encojan/corten, y ocultar el budget (libera espacio). */
  #top-hud {
    gap:.5rem;
    padding:max(.55rem, env(safe-area-inset-top)) max(.6rem, env(safe-area-inset-right)) .55rem max(.6rem, env(safe-area-inset-left));
  }
  .hud-right { gap:.35rem; flex-shrink:0; }
  .hud-status { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .budget-wrap { display:none; }
}

/* ── STAGE — tablero visual de AION ─────────────────────────────────────────── */
#stage {
  position:absolute; top:50%; right:2.5%; transform:translateY(-50%) translateX(20px);
  width:min(42vw, 540px); max-height:82vh; z-index:8;
  display:flex; flex-direction:column;
  background:rgba(8,6,24,.86); border:1px solid rgba(124,58,237,.35);
  border-radius:18px; backdrop-filter:blur(18px);
  box-shadow:0 0 60px rgba(124,58,237,.3), inset 0 1px 0 rgba(255,255,255,.05);
  opacity:0; pointer-events:none; transition:opacity .35s, transform .35s;
  overflow:hidden;
}
#stage.open { opacity:1; pointer-events:auto; transform:translateY(-50%) translateX(0); }
#stage-header {
  display:flex; align-items:center; justify-content:space-between;
  padding:.7rem 1rem; border-bottom:1px solid rgba(124,58,237,.25);
  font-weight:700; color:#e9d5ff; font-size:.95rem;
}
#stage-close { background:none; border:none; color:#94a3b8; cursor:pointer; font-size:1rem; }
#stage-close:hover { color:#fff; }
#stage-body { padding:1rem; overflow-y:auto; display:flex; flex-direction:column; gap:1rem; }

.stage-block { background:rgba(255,255,255,.03); border:1px solid rgba(255,255,255,.07); border-radius:12px; padding:.85rem 1rem; animation:stage-in .4s ease; }
@keyframes stage-in { from{opacity:0;transform:translateY(12px)} to{opacity:1;transform:translateY(0)} }
.stage-block-title { font-weight:700; color:#c4b5fd; margin-bottom:.6rem; font-size:.9rem; }
.stage-text { color:#e2e8f0; font-size:.95rem; line-height:1.5; margin:0; }

.stage-bullets { margin:0; padding-left:1.1rem; color:#e2e8f0; }
.stage-bullets li { margin:.3rem 0; line-height:1.4; }

.stage-comparison { display:flex; align-items:stretch; gap:.6rem; }
.stage-cmp-side { flex:1; background:rgba(255,255,255,.03); border-radius:10px; padding:.6rem .7rem; }
.stage-cmp-label { font-weight:700; margin-bottom:.4rem; }
.stage-cmp-pro { color:#86efac; font-size:.85rem; margin:.2rem 0; }
.stage-cmp-con { color:#fca5a5; font-size:.85rem; margin:.2rem 0; }
.stage-cmp-vs { align-self:center; color:#a78bfa; font-weight:800; font-size:.8rem; }

.stage-metrics { display:flex; flex-wrap:wrap; gap:.6rem; }
.stage-metric { flex:1; min-width:90px; text-align:center; background:rgba(255,255,255,.03); border:1px solid; border-radius:10px; padding:.7rem .5rem; }
.stage-metric-value { font-size:1.6rem; font-weight:800; line-height:1; }
.stage-metric-label { font-size:.75rem; color:#94a3b8; margin-top:.3rem; }
.stage-metric-hint { font-size:.65rem; color:#64748b; margin-top:.2rem; }

.stage-steps { display:flex; flex-direction:column; gap:.5rem; }
.stage-step { display:flex; align-items:center; gap:.6rem; color:#e2e8f0; font-size:.9rem; }
.stage-step-num { flex:none; width:24px; height:24px; border-radius:50%; background:#7c3aed; color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:.8rem; }

.stage-tree-root { text-align:center; font-weight:700; color:#e9d5ff; background:rgba(124,58,237,.25); border-radius:8px; padding:.4rem; margin-bottom:.6rem; }
.stage-tree-branches { display:flex; gap:.5rem; flex-wrap:wrap; }
.stage-tree-branch { flex:1; min-width:120px; background:rgba(255,255,255,.04); border-radius:8px; padding:.5rem; border-top:2px solid #7c3aed; }
.stage-tree-label { font-weight:600; color:#c4b5fd; font-size:.85rem; }
.stage-tree-detail { color:#94a3b8; font-size:.78rem; margin-top:.25rem; }

.stage-table { width:100%; border-collapse:collapse; font-size:.85rem; }
.stage-table th, .stage-table td { border:1px solid rgba(255,255,255,.1); padding:.4rem .6rem; text-align:left; color:#e2e8f0; }
.stage-table th { background:rgba(124,58,237,.2); color:#e9d5ff; }

.stage-image { width:100%; border-radius:10px; display:block; }
.stage-caption { text-align:center; color:#94a3b8; font-size:.8rem; margin-top:.4rem; }
.stage-chart-wrap { height:240px; position:relative; }
.stage-chart-wrap canvas { max-height:240px; }

@media (max-width:760px) {
  #stage { right:0; left:0; width:auto; margin:0 8px; top:auto; bottom:90px; transform:translateY(20px); max-height:55vh; }
  #stage.open { transform:translateY(0); }
}

/* ── BACKDROP — video o web detrás de AION ──────────────────────────────────── */
#stage-backdrop {
  position:absolute; inset:0; z-index:1;   /* detrás del avatar (z-5), sobre el world (z-0) */
  display:none; opacity:0; transition:opacity .5s;
  background:rgba(2,2,10,.55);
}
#stage-backdrop.open { display:block; opacity:1; }
#backdrop-content { position:absolute; inset:0; }
#backdrop-content iframe,
#backdrop-content video {
  position:absolute; inset:0; width:100%; height:100%; border:0;
}
#backdrop-content video { object-fit:cover; }
/* Oscurecer un poco para que AION resalte al frente */
#stage-backdrop::after { content:''; position:absolute; inset:0; background:radial-gradient(ellipse at 50% 55%, transparent 30%, rgba(2,2,12,.6) 100%); pointer-events:none; }
#backdrop-close {
  position:absolute; top:12px; right:16px; z-index:16;
  background:rgba(10,8,30,.9); border:1px solid rgba(167,139,250,.6); color:#e9d5ff;
  border-radius:8px; padding:.35rem .7rem; cursor:pointer; font-size:.95rem; backdrop-filter:blur(6px);
}
#backdrop-close:hover { color:#fff; border-color:#a78bfa; }
.backdrop-fallback { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:1rem; text-align:center; padding:2rem; color:#cbd5e1; }
.backdrop-fallback a { color:#a78bfa; }

/* Captura de web en el backdrop */
.backdrop-web { position:absolute; inset:0; }
.backdrop-shot { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; object-position:top center; }
/* Etiqueta de URL: debajo del HUD, recortada para no encimarse */
.backdrop-weburl {
  position:absolute; top:60px; left:16px; z-index:4;
  max-width:60vw; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  background:rgba(10,8,30,.85); border:1px solid rgba(167,139,250,.4); color:#e9d5ff;
  padding:.35rem .8rem; border-radius:8px; font-size:.82rem; backdrop-filter:blur(6px);
}
.backdrop-weburl a { color:#a78bfa; margin-left:.5rem; }

/* ── PIZARRA interactiva (dibujar sobre lo proyectado) ──────────────────────── */
#draw-canvas {
  position:absolute; inset:0; z-index:3; display:none;
  cursor:crosshair; touch-action:none;
}
#draw-canvas.active { display:block; }
#draw-toolbar {
  position:absolute; bottom:18px; left:50%; transform:translateX(-50%) translateY(20px);
  z-index:12; display:none; align-items:center; gap:.4rem;
  background:rgba(8,6,24,.92); border:1px solid rgba(124,58,237,.4);
  border-radius:999px; padding:.45rem .6rem; backdrop-filter:blur(14px);
  box-shadow:0 10px 40px rgba(0,0,0,.5); opacity:0; transition:opacity .3s, transform .3s;
}
#draw-toolbar.open { display:flex; opacity:1; transform:translateX(-50%) translateY(0); }
.dtool {
  background:rgba(255,255,255,.06); border:1px solid transparent; color:#e2e8f0;
  border-radius:10px; padding:.4rem .55rem; cursor:pointer; font-size:1rem; line-height:1;
  transition:all .15s;
}
.dtool:hover { background:rgba(124,58,237,.3); }
.dtool.sel { border-color:#a78bfa; background:rgba(124,58,237,.35); }
.dt-action { font-size:.85rem; font-weight:700; padding:.4rem .7rem; }
#dt-color { width:34px; height:30px; border:none; background:none; cursor:pointer; padding:0; border-radius:8px; }
/* Botón flotante para abrir la pizarra cuando hay algo proyectado */
#draw-fab {
  position:absolute; bottom:18px; right:18px; z-index:11; display:none;
  background:rgba(124,58,237,.9); color:#fff; border:none; border-radius:50%;
  width:46px; height:46px; font-size:1.2rem; cursor:pointer; box-shadow:0 6px 24px rgba(124,58,237,.5);
}
#draw-fab.show { display:block; }

/* ── FEED de YouTube Shorts ──────────────────────────────────────────────────── */
.feed-wrap { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; }
.feed-video {
  width:min(46vh, 92vw); height:min(82vh, 164vw); aspect-ratio:9/16; border:0; border-radius:16px;
  box-shadow:0 0 60px rgba(0,0,0,.6); background:#000;
}
.feed-info {
  position:absolute; bottom:24px; left:50%; transform:translateX(-50%);
  width:min(46vh, 92vw); padding:.6rem .9rem; text-align:left;
  background:linear-gradient(to top, rgba(0,0,0,.75), transparent);
  border-radius:0 0 16px 16px; color:#fff;
}
.feed-title { font-weight:700; font-size:.9rem; line-height:1.3; max-height:2.6em; overflow:hidden; }
.feed-channel { font-size:.75rem; color:#cbd5e1; margin-top:.2rem; }
.feed-nav {
  position:absolute; right:max(16px, calc(50% - min(23vh, 46vw) - 60px)); top:50%; transform:translateY(-50%);
  display:flex; flex-direction:column; gap:.6rem; z-index:4;
}
.feed-btn {
  width:46px; height:46px; border-radius:50%; border:1px solid rgba(167,139,250,.5);
  background:rgba(10,8,30,.85); color:#e9d5ff; font-size:1.1rem; cursor:pointer;
  display:flex; align-items:center; justify-content:center; text-decoration:none; backdrop-filter:blur(6px);
}
.feed-btn:hover { background:rgba(124,58,237,.5); }
@media (max-width:760px) {
  .feed-nav { right:8px; }
}

/* Aviso de carga de captura (mShots genera la imagen en segundo plano) */
.backdrop-loading {
  position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); z-index:2;
  background:rgba(10,8,30,.85); border:1px solid rgba(167,139,250,.4); color:#e9d5ff;
  padding:.6rem 1rem; border-radius:10px; font-size:.85rem; backdrop-filter:blur(6px);
}

/* ── MINIBROWSER (navegador remoto Playwright) ──────────────────────────────── */
.mb-wrap { position:absolute; top:48px; left:0; right:0; bottom:0; display:flex; flex-direction:column; background:#0a0820; }
.mb-bar {
  display:flex; align-items:center; gap:.4rem; padding:.45rem .6rem;
  background:rgba(8,6,24,.95); border-bottom:1px solid rgba(124,58,237,.35); z-index:2;
}
.mb-btn {
  background:rgba(255,255,255,.07); border:1px solid rgba(124,58,237,.3); color:#e2e8f0;
  border-radius:8px; padding:.35rem .6rem; cursor:pointer; font-size:.9rem; line-height:1;
}
.mb-btn:hover { background:rgba(124,58,237,.35); }
.mb-go { font-weight:700; }
.mb-url {
  flex:1; min-width:0; background:rgba(255,255,255,.06); border:1px solid rgba(124,58,237,.3);
  color:#e9d5ff; border-radius:8px; padding:.4rem .7rem; font-size:.85rem; outline:none;
}
.mb-url:focus { border-color:#a78bfa; }
.mb-status { font-size:.72rem; color:#94a3b8; max-width:160px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.mb-screen-wrap { position:relative; flex:1; overflow:hidden; display:flex; align-items:flex-start; justify-content:center; background:#fff; }
.mb-screen { width:100%; height:100%; object-fit:contain; object-position:top center; cursor:pointer; outline:none; background:#fff; }
.mb-loading {
  position:absolute; top:50%; left:50%; transform:translate(-50%,-50%);
  background:rgba(10,8,30,.9); color:#e9d5ff; padding:.6rem 1rem; border-radius:10px; font-size:.85rem;
}

/* Visor en vivo de Steel.dev (navegador gestionado) */
/* Mayor especificidad que "#backdrop-content iframe { inset:0 }" para que el offset gane.
   height:calc(100% - 48px) → llena de 48px hasta abajo, ancho completo. */
#backdrop-content iframe.mb-steel { position:absolute; top:48px; left:0; right:0; bottom:0; width:100%; height:calc(100% - 48px); border:0; background:#fff; }

/* Imagen generada por AION: completa y centrada (no recortada) */
.backdrop-image {
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  padding:64px 24px 24px;   /* deja libre la marca de AION arriba */
}
.backdrop-image img {
  max-width:100%; max-height:100%; width:auto; height:auto; object-fit:contain;
  border-radius:14px; box-shadow:0 12px 48px rgba(0,0,0,.55);
}

/* ── Badge de privacidad: indicador de cerebro + toggle + medidor de egreso ── */
/* Inline dentro de la barra superior (#top-hud .hud-right) — ya NO flota fijo (evita solaparse). */
#badge-cerebro { display: flex; gap: 6px; align-items: center; color: #e5e7eb; font: 600 12px system-ui; }
#badge-cerebro #btn-privado { background: none; border: 1px solid #374151; border-radius: 8px; cursor: pointer; color: inherit; padding: 2px 6px; }
#badge-cerebro #btn-privado.activo { background: #7c3aed; border-color: #7c3aed; }
#badge-cerebro #medidor-egreso { opacity: .8; cursor: pointer; }

/* ── Drawer "Controles": panel grid 3×3, estilo chat, encima del chat ──────── */
#controls-drawer {
  position:absolute; right:0; top:3.4rem;
  transform:translateX(calc(100% - var(--tab-w)));
  width:var(--drawer-w); max-height:20rem; z-index:21; display:flex;
  transition:transform .45s cubic-bezier(.4,0,.2,1);
  filter:drop-shadow(-8px 0 32px rgba(0,0,0,.6));
}
#controls-drawer.open { transform:translateX(0); }
#controls-tab {
  width:var(--tab-w); flex-shrink:0;
  background:rgba(12,6,32,.85);
  border:1px solid var(--border); border-right:none;
  border-radius:12px 0 0 12px;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:.35rem;
  cursor:pointer; padding:.6rem 0; backdrop-filter:blur(16px); transition:background .2s;
}
#controls-tab:hover { background:rgba(124,58,237,.2); }
.controls-body { overflow-y:auto; }
#controls-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:.55rem; padding:.9rem; }
#controls-grid .hud-btn {
  width:100%; aspect-ratio:1/1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:.25rem;
  font-size:1.5rem; padding:.3rem;
}
#controls-grid .ctrl-lbl { font-size:.6rem; font-weight:600; color:var(--muted); line-height:1; }
.controls-budget { padding:.2rem .9rem .9rem; }

/* ── Diálogo de confirmación in-app (ej. descargar Gemma 4 al activar el candado) ── */
.aion-modal-ov { position:fixed; inset:0; z-index:200; background:rgba(0,0,0,.55); display:flex; align-items:center; justify-content:center; padding:1rem; backdrop-filter:blur(4px); }
.aion-modal { background:#0b0b14; border:1px solid var(--border); border-radius:14px; max-width:380px; width:100%; padding:1.1rem 1.2rem; color:#e5e7eb; box-shadow:0 20px 60px rgba(0,0,0,.6); }
.aion-modal-title { font-weight:700; font-size:1rem; margin-bottom:.5rem; }
.aion-modal-msg { font-size:.9rem; color:var(--muted); line-height:1.45; margin-bottom:1.1rem; }
.aion-modal-btns { display:flex; gap:.6rem; justify-content:flex-end; }
.aion-modal-btns button { border-radius:8px; padding:.5rem .9rem; cursor:pointer; font-size:.9rem; border:1px solid var(--border); }
.aion-modal-cancel { background:transparent; color:var(--muted); }
.aion-modal-ok { background:var(--primary, #7c3aed); color:#fff; border-color:var(--primary, #7c3aed); }

/* Barra de progreso de descarga del cerebro local (visible, no depende del chat) */
#cerebro-progreso { position:fixed; left:50%; bottom:1.2rem; transform:translateX(-50%); z-index:210;
  width:min(92vw,420px); background:rgba(11,11,20,.96); border:1px solid var(--border); border-radius:12px;
  padding:.7rem .9rem; color:#e5e7eb; box-shadow:0 12px 40px rgba(0,0,0,.6); font:600 13px system-ui; }
#cerebro-progreso .cp-row { display:flex; justify-content:space-between; align-items:center; gap:.5rem; margin-bottom:.45rem; }
#cerebro-progreso .cp-bar { height:8px; background:rgba(255,255,255,.1); border-radius:6px; overflow:hidden; }
#cerebro-progreso .cp-fill { height:100%; width:0%; background:var(--primary,#7c3aed); transition:width .3s; }
#cerebro-progreso.error .cp-fill { background:#ef4444; }

/* ── Panel "qué se compartió" — bitácora de egresos a la nube ─────────────── */
#panel-compartido { position: fixed; top: 44px; right: 8px; z-index: 61; width: min(420px, 90vw); max-height: 70vh; overflow: auto;
  background: #0b0b14; color: #e5e7eb; border: 1px solid #374151; border-radius: 12px; padding: 12px; font: 13px system-ui; }
#panel-compartido .pc-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 8px; }
#panel-compartido .fila-egreso { border-top: 1px solid #1f2937; padding: 8px 0; }
#panel-compartido code { color: #a7f3d0; word-break: break-word; }
#panel-compartido #pc-cerrar { background: none; border: 0; color: #9ca3af; cursor: pointer; }

/* ── Tarjeta de descarga de modelo sugerido ───────────────────────────────── */
#sugerencia-modelo { position: fixed; right: 12px; bottom: 64px; z-index: 9999;
  background: #1b1530; color: #eee; border: 1px solid #7c3aed; border-radius: 10px;
  padding: 10px 12px; max-width: 280px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
#sugerencia-modelo button { margin: 8px 6px 0 0; padding: 4px 10px; border-radius: 6px;
  border: 0; cursor: pointer; background: #7c3aed; color: #fff; }
#sugerencia-modelo #sm-no { background: #333; }
#sm-prog { margin-top: 8px; height: 6px; background: #333; border-radius: 3px; overflow: hidden; }
#sm-bar { height: 100%; width: 0; background: #7c3aed; transition: width .2s; }
#sm-status { margin-top: 6px; font-size: 11px; color: #b9a9e6; word-break: break-word; }
#btn-redetectar { background: none; border: 0; color: #aaa; cursor: pointer; font-size: 14px; }

/* ── AION embebido en la barra lateral de la extensión (~360-400px) ─────────────────
   MISMA presentación que el modo Nube: el avatar limpio (avatar.html) arriba y el chat debajo.
   (Se activa con body.embed-sidebar cuando la URL trae ?embed=sidebar.) */

/* Ocultar TODO lo pesado: mundo 3D, avatar de cubos (FaceParticles, canvas hijo directo de #app),
   avatar nativo (#aion-wrap), proyección, HUD, controles, pestaña, waveform. */
body.embed-sidebar #app > canvas,   /* world-canvas + canvas de FaceParticles + waveform */
body.embed-sidebar #aion-wrap,
body.embed-sidebar #stage,
body.embed-sidebar #stage-backdrop,
body.embed-sidebar #draw-toolbar,
body.embed-sidebar #draw-fab,
body.embed-sidebar #controls-drawer,
body.embed-sidebar #top-hud,
body.embed-sidebar #chat-tab { display: none !important; }

/* Apilar en columna: avatar (iframe limpio) arriba, chat llenando el resto */
body.embed-sidebar #app { display: flex; flex-direction: column; }

/* El MISMO avatar que Nube (avatar.html), montado por JS como primer hijo de #app */
body.embed-sidebar #embed-avatar { flex: 0 0 auto; width: 100%; height: 230px; border: 0; background: #04040f; }

/* El chat deja de ser cajón lateral: fluye DEBAJO del avatar y ocupa todo lo que queda */
body.embed-sidebar #chat-drawer {
  position: relative; left: auto; right: auto; top: auto; bottom: auto;
  width: 100%; max-height: none; min-height: 0; flex: 1 1 auto;
  transform: none !important; filter: none;
}
body.embed-sidebar #chat-drawer .drawer-body { width: 100%; flex: 1 1 auto; min-height: 0; }
