/* ── 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%,-52%);
  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:filter .3s;
}
#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;
}
#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)} }

/* 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 */
#speech-holo {
  position:absolute; bottom:calc(100% + 14px); left:50%;
  transform:translateX(-50%);
  background:rgba(6,4,20,.92);
  border:1px solid rgba(167,139,250,.35);
  border-radius:14px; padding:.65rem 1.1rem;
  font-size:.9rem; color:var(--text); max-width:340px; 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:50%;
  transform:translateY(-50%) translateX(calc(100% - var(--tab-w)));
  width:var(--drawer-w);
  max-height:80vh;
  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:translateY(-50%) translateX(0);
}

/* 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; }
  #chat-drawer { top:auto; bottom:0; transform:translateX(calc(100% - var(--tab-w))); max-height:70vh; }
  #chat-drawer.open { transform:translateX(0); }
  #chat-tab { width:var(--tab-w); writing-mode:horizontal-tb; flex-direction:row; padding:.5rem; }
  .waveform-center { bottom:12px; width:140px!important; }
}
