:root {
  --bg0: #01040f; --bg1: #04102e; --bg2: #0a2160;
  --ink: #eef3ff; --ink2: #a9b8d8; --ink3: #6c7ca0;
  --glass: rgba(18, 32, 72, 0.42); --glass-2: rgba(10, 20, 48, 0.62);
  --line: rgba(160, 190, 255, 0.14); --line-2: rgba(180, 210, 255, 0.28);
  --accent: #4d8dff; --accent-2: #8fc1ff; --ok: #3ee0a2; --warn: #ffbf47; --err: #ff5c7a; --ai: #c9a8ff;
  --r: 18px; --term-h: 270px;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg0); color: var(--ink); font: 400 15px/1.45 Inter, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- background: PS5 home waves ---------- */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: radial-gradient(120% 90% at 70% -10%, #1a3f9a 0%, var(--bg2) 22%, var(--bg1) 52%, var(--bg0) 100%); }
.wave { position: absolute; left: -20%; width: 140%; height: 60%; border-radius: 45%; filter: blur(2px); opacity: .55; }
.w1 { top: 48%; background: radial-gradient(60% 40% at 50% 0%, rgba(77,141,255,.35), transparent 70%); animation: drift 22s ease-in-out infinite alternate; }
.w2 { top: 58%; background: radial-gradient(55% 35% at 40% 0%, rgba(140,110,255,.22), transparent 70%); animation: drift 30s ease-in-out infinite alternate-reverse; }
.w3 { top: 66%; background: radial-gradient(70% 30% at 60% 0%, rgba(80,200,255,.16), transparent 70%); animation: drift 38s ease-in-out infinite alternate; }
@keyframes drift { from { transform: translateX(-4%) rotate(-2deg); } to { transform: translateX(4%) rotate(2deg); } }
#particles { position: absolute; inset: 0; width: 100%; height: 100%; }
@media (prefers-reduced-motion: reduce) { .wave { animation: none; } }

/* ---------- login ---------- */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { position: relative; z-index: 1; width: min(420px, 100%); text-align: center; padding: 48px 36px 40px; border-radius: 28px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(24px) saturate(140%); box-shadow: 0 30px 80px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.06); animation: rise .6s cubic-bezier(.2,.8,.2,1); }
.login-card h1 { font-weight: 200; font-size: 34px; letter-spacing: .02em; margin: 10px 0 4px; }
.login-card .sub { color: var(--ink2); margin: 0 0 28px; font-weight: 300; }
.brand-mark { display: inline-grid; place-items: center; color: var(--accent-2); text-shadow: 0 0 18px rgba(120,170,255,.8); }
.login-card .brand-mark { font-size: 30px; }
#f { display: flex; gap: 10px; }
#f input { flex: 1; min-width: 0; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line-2); background: rgba(0,0,0,.25); color: var(--ink); font: 400 15px Inter; outline: none; transition: border-color .2s, box-shadow .2s; }
#f input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(77,141,255,.22); }
#f button { display: flex; align-items: center; gap: 8px; padding: 0 18px; border-radius: 14px; border: 0; background: linear-gradient(180deg, #fff, #dfe8ff); color: #0b1530; font-weight: 600; }
#f button kbd { font: 600 12px Inter; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: #0b1530; color: #8fc1ff; }
.err { color: var(--err); min-height: 1.4em; margin: 14px 0 0; }
.shake { animation: shake .4s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98); } }
body.leaving .login-card { opacity: 0; transform: scale(1.04); transition: .4s; }

/* ---------- app shell ---------- */
body.app { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; height: 100dvh; overflow: hidden; }
.top, .stage-wrap, .gallery-wrap, .term { position: relative; z-index: 1; }
.top { display: flex; align-items: center; gap: 24px; padding: 14px 24px 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 300; font-size: 18px; letter-spacing: .02em; white-space: nowrap; }
.brand b { font-weight: 600; }
.tabs { display: flex; gap: 6px; }
.tab { border: 0; background: none; padding: 6px 14px; border-radius: 999px; color: var(--ink2); font-weight: 400; font-size: 16px; position: relative; transition: color .2s; }
.tab.active { color: var(--ink); font-weight: 500; }
.tab.active::after { content: ''; position: absolute; left: 50%; bottom: -4px; width: 18px; height: 2px; margin-left: -9px; border-radius: 2px; background: var(--ink); box-shadow: 0 0 10px var(--accent-2); }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); font-size: 12.5px; color: var(--ink2); backdrop-filter: blur(12px); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: #3b4766; }
.pill.on i { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.pill.busy i { background: var(--ai); box-shadow: 0 0 12px var(--ai); animation: pulse 1s ease-in-out infinite; }
.pill.half i { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.clock { font-weight: 300; font-size: 15px; color: var(--ink); margin-left: 6px; font-variant-numeric: tabular-nums; }
@keyframes pulse { 50% { opacity: .35; } }

.brain-switch { cursor: pointer; padding: 3px 4px 3px 11px; gap: 4px; }
.brain-switch .b-lbl { color: var(--ink3); margin-right: 3px; }
.brain-switch .b-opt { padding: 2px 9px; border-radius: 999px; color: var(--ink3); transition: .2s; }
.brain-switch .b-opt.sel { background: #fff; color: #0b1530; font-weight: 600; }
.brain-switch .b-opt.sel[data-b=qwen] { background: linear-gradient(90deg, #76b900, #b7f34a); }
@media (max-width: 860px) { .brain-switch .b-lbl { display: none; } }

/* ---------- stage ---------- */
.stage-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; padding: 4px 24px 14px; min-height: 0; }
.stage { min-height: 0; display: flex; }
.viewport { position: relative; flex: 1; min-height: 0; border-radius: var(--r); overflow: hidden; background: #000 radial-gradient(80% 80% at 50% 40%, #0b1a44, #01040f); border: 1px solid var(--line); box-shadow: 0 24px 60px rgba(0,0,0,.5), inset 0 0 0 1px rgba(255,255,255,.03); outline: none; transition: box-shadow .3s, border-color .3s; }
.viewport:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(77,141,255,.35), 0 24px 60px rgba(0,0,0,.5); }
#screen { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.vp-empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; transition: opacity .5s; }
.vp-empty h2 { font-weight: 200; font-size: 30px; margin: 22px 0 6px; }
.vp-empty p { color: var(--ink2); margin: 0; font-weight: 300; }
.vp-empty.gone { opacity: 0; pointer-events: none; }
.orb { width: 84px; height: 84px; margin: 0 auto; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #cfe2ff, #4d8dff 40%, #0b1c4a 75%); box-shadow: 0 0 60px rgba(77,141,255,.6); animation: breathe 3s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.08); box-shadow: 0 0 90px rgba(77,141,255,.85); } }

.hud { position: absolute; display: flex; gap: 8px; align-items: center; z-index: 2; opacity: .9; transition: opacity .25s; }
.viewport:not(:hover) .hud { opacity: .55; }
.hud-tl { top: 14px; left: 14px; }
.hud-tr { top: 12px; right: 12px; }
.hud-bl { bottom: 14px; left: 14px; }
.hud-br { bottom: 14px; right: 14px; }
.live-badge { font: 600 11px Inter; letter-spacing: .14em; padding: 4px 9px; border-radius: 6px; background: rgba(0,0,0,.5); color: var(--ink3); border: 1px solid var(--line); }
.live-badge.on { color: #fff; background: rgba(255,40,80,.85); border-color: transparent; box-shadow: 0 0 16px rgba(255,40,80,.6); }
.live-badge.rec { animation: pulse 1s infinite; }
.hud-meta { font: 500 11.5px var(--mono); color: var(--ink2); background: rgba(0,0,0,.45); padding: 4px 8px; border-radius: 6px; }
.icon-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: rgba(6,12,30,.6); backdrop-filter: blur(10px); border-radius: 10px; padding: 6px 10px; font-size: 13px; color: var(--ink2); transition: .2s; }
.icon-btn:hover, .icon-btn.active { color: var(--ink); border-color: var(--line-2); background: rgba(40,70,150,.5); }
.icon-btn span { font-size: 12px; }

.dpad { display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px); gap: 3px; }
.dpad button { border: 1px solid var(--line); background: rgba(6,12,30,.62); backdrop-filter: blur(10px); border-radius: 9px; font-size: 12px; color: var(--ink2); transition: .15s; }
.dpad button:hover { color: #fff; background: rgba(77,141,255,.45); }
.dpad button:active { transform: scale(.92); }
.dpad [data-cam=pitchu] { grid-column: 2; grid-row: 1; }
.dpad [data-cam=yawl] { grid-column: 1; grid-row: 2; }
.dpad .mid { grid-column: 2; grid-row: 2; font-size: 9px; }
.dpad [data-cam=yawr] { grid-column: 3; grid-row: 2; }
.dpad [data-cam=pitchd] { grid-column: 2; grid-row: 3; }

.face { display: grid; grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 38px); gap: 2px; }
.fb { border-radius: 50%; border: 1px solid var(--line); background: rgba(6,12,30,.65); backdrop-filter: blur(10px); font-size: 16px; transition: .15s; }
.fb:hover { transform: scale(1.08); }
.fb:active { transform: scale(.9); }
.fb.tri { grid-column: 2; grid-row: 1; color: #46e0b0; }
.fb.sqr { grid-column: 1; grid-row: 2; color: #ff7ad9; }
.fb.cir { grid-column: 3; grid-row: 2; color: #ff5c7a; }
.fb.crs { grid-column: 2; grid-row: 3; color: #7fb2ff; }
.fb.cir.recording { background: #ff2a55; color: #fff; box-shadow: 0 0 18px #ff2a55; }

.crop-box { position: absolute; border: 2px dashed var(--accent-2); background: rgba(77,141,255,.12); display: none; z-index: 3; pointer-events: none; border-radius: 6px; }
.viewport.cropping { cursor: crosshair; }
.ai-glow { position: absolute; inset: 0; pointer-events: none; border-radius: var(--r); box-shadow: inset 0 0 0 0 rgba(201,168,255,0); transition: box-shadow .6s; z-index: 1; }
.ai-glow.on { box-shadow: inset 0 0 0 2px rgba(201,168,255,.55), inset 0 0 60px rgba(150,110,255,.25); animation: aiwave 2s ease-in-out infinite; }
@keyframes aiwave { 50% { box-shadow: inset 0 0 0 2px rgba(120,190,255,.55), inset 0 0 80px rgba(80,150,255,.22); } }

/* ---------- side rail ---------- */
.side { min-height: 0; overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
.rail-title { margin: 6px 2px 10px; font-weight: 400; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink3); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.tile { position: relative; text-align: left; border: 1px solid var(--line); border-radius: 16px; padding: 14px 12px 12px; min-height: 86px; background: linear-gradient(150deg, color-mix(in srgb, var(--a) 30%, transparent), var(--b) 85%); display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden; transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s, border-color .25s; }
.tile::before { content: ''; position: absolute; inset: 0; background: radial-gradient(90% 70% at 85% 0%, color-mix(in srgb, var(--a) 55%, transparent), transparent 60%); opacity: .7; }
.tile:hover, .tile:focus-visible { transform: scale(1.04); border-color: rgba(255,255,255,.85); box-shadow: 0 0 0 2px rgba(255,255,255,.18), 0 14px 34px rgba(0,0,0,.45), 0 0 28px color-mix(in srgb, var(--a) 40%, transparent); outline: none; z-index: 1; }
.tile:active { transform: scale(.98); }
.tile > * { position: relative; }
.t-ico { position: absolute; top: 10px; right: 12px; font-size: 22px; opacity: .9; }
.t-name { font-weight: 500; font-size: 14.5px; }
.t-sub { font-size: 12px; color: var(--ink2); }
.tile.running { animation: pulse 1s infinite; }

.blender-card { border-radius: 16px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(16px); overflow: hidden; }
.bl-frame { position: relative; aspect-ratio: 16/9; display: grid; place-items: center; color: var(--ink3); font-size: 13px; background: #050a18 center/cover no-repeat; cursor: zoom-in; }
.bl-frame.has { color: transparent; }
.bl-spin { position: absolute; width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent-2); animation: spin 1s linear infinite; display: none; }
.bl-spin.on { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
.bl-actions { display: flex; gap: 6px; padding: 10px; flex-wrap: wrap; }
.pill-btn { flex: 1; border: 1px solid var(--line-2); background: rgba(255,255,255,.04); border-radius: 999px; padding: 7px 10px; font-size: 12.5px; white-space: nowrap; transition: .2s; }
.pill-btn:hover { background: #fff; color: #0b1530; }

/* ---------- gallery ---------- */
.gallery-wrap { overflow-y: auto; padding: 4px 24px 18px; min-height: 0; }
.gallery-head h2 { font-weight: 200; font-size: 30px; margin: 4px 0 2px; }
.gallery-head p { color: var(--ink2); margin: 0 0 16px; font-weight: 300; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.g-item { border-radius: 16px; overflow: hidden; border: 1px solid var(--line); background: var(--glass); transition: transform .25s, border-color .25s; }
.g-item:hover { transform: translateY(-3px); border-color: var(--line-2); }
.g-item img, .g-item video { display: block; width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #000; }
.g-meta { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 12px; color: var(--ink2); }
.g-meta .src { text-transform: uppercase; letter-spacing: .08em; font-size: 10.5px; padding: 2px 6px; border-radius: 5px; background: rgba(255,255,255,.08); }
.g-meta button, .g-meta a { margin-left: auto; border: 1px solid var(--line-2); background: none; border-radius: 999px; padding: 3px 10px; font-size: 11.5px; color: var(--ink); text-decoration: none; }
.g-meta a { margin-left: 0; }

/* ---------- terminal ---------- */
.term { height: var(--term-h); min-height: 150px; max-height: 75vh; display: flex; flex-direction: column; margin: 0 24px 16px; border-radius: var(--r); background: var(--glass-2); border: 1px solid var(--line); backdrop-filter: blur(22px) saturate(140%); box-shadow: 0 -10px 40px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.05); overflow: hidden; }
.term-grip { height: 12px; flex: none; cursor: ns-resize; position: relative; }
.term-grip::after { content: ''; position: absolute; left: 50%; top: 5px; width: 44px; height: 3px; margin-left: -22px; border-radius: 3px; background: var(--line-2); }
.term-log { flex: 1; overflow-y: auto; padding: 2px 18px 8px; font: 400 13px/1.55 var(--mono); scrollbar-width: thin; scrollbar-color: rgba(160,190,255,.25) transparent; }
.ln { white-space: pre-wrap; word-break: break-word; padding: 1px 0; animation: lnin .25s ease-out; }
@keyframes lnin { from { opacity: 0; transform: translateY(4px); } }
.ln.user { color: #fff; margin-top: 10px; }
.ln.user::before { content: '❯ '; color: var(--accent-2); text-shadow: 0 0 8px var(--accent); }
.ln.ai { color: #e6ddff; font-family: Inter, sans-serif; font-size: 14px; line-height: 1.55; padding-left: 14px; border-left: 2px solid rgba(201,168,255,.4); margin: 4px 0; }
.ln.tool { color: #9d8cd6; font-size: 12px; padding-left: 14px; opacity: .85; }
.ln.ok { color: var(--ok); }
.ln.err { color: var(--err); }
.ln.warn { color: var(--warn); }
.ln.sys { color: var(--ink2); }
.ln.meta { color: var(--ink3); font-size: 11.5px; padding-left: 14px; }
.ln a { color: var(--accent-2); }
.cursor-blink::after { content: '▍'; color: var(--ai); animation: pulse .9s infinite; margin-left: 1px; }
.chips { display: flex; gap: 8px; padding: 6px 16px 4px; overflow-x: auto; scrollbar-width: none; flex: none; }
.chip { flex: none; border: 1px solid var(--line); background: rgba(255,255,255,.04); border-radius: 999px; padding: 5px 12px; font-size: 12.5px; color: var(--ink2); transition: .2s; }
.chip:hover { color: #0b1530; background: #fff; }
.prompt { display: flex; align-items: flex-end; gap: 10px; padding: 8px 12px 12px 18px; flex: none; }
.caret { font: 500 18px var(--mono); color: var(--accent-2); text-shadow: 0 0 12px var(--accent); padding-bottom: 9px; transition: color .3s; }
.caret.busy { color: var(--ai); text-shadow: 0 0 14px var(--ai); animation: pulse 1s infinite; }
#input { flex: 1; resize: none; max-height: 160px; border: 1px solid var(--line); border-radius: 14px; background: rgba(0,0,0,.3); color: var(--ink); padding: 11px 14px; font: 400 14.5px/1.4 var(--mono); outline: none; transition: border-color .2s, box-shadow .2s; }
#input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(77,141,255,.18); }
.send { width: 44px; height: 44px; flex: none; border-radius: 50%; border: 0; background: linear-gradient(180deg, #fff, #dfe8ff); color: #0b1530; font-size: 16px; transition: transform .15s; }
.send:hover { transform: scale(1.06); }
.send:active { transform: scale(.94); }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: 70px; right: 24px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 16px; border-radius: 14px; background: rgba(240,245,255,.95); color: #0b1530; font-size: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.4); animation: rise .35s cubic-bezier(.2,.8,.2,1); max-width: 340px; }

/* ---------- fullscreen + responsive ---------- */
.viewport:fullscreen { border-radius: 0; border: 0; }
@media (max-width: 1100px) { .stage-wrap { grid-template-columns: minmax(0, 1fr) 260px; } }
@media (max-width: 860px) {
  body.app { height: auto; min-height: 100dvh; overflow: auto; grid-template-rows: auto auto auto; }
  .top { flex-wrap: wrap; gap: 10px; padding: 12px 16px 8px; }
  .status { width: 100%; justify-content: flex-start; }
  .stage-wrap { grid-template-columns: 1fr; padding: 4px 16px 12px; }
  .viewport { aspect-ratio: 16/10; flex: none; width: 100%; }
  .side { overflow: visible; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .term { margin: 0 16px 16px; height: 62vh; }
  .gallery-wrap { padding: 4px 16px 16px; }
  .hud-tr .icon-btn span { display: none; }
  .dpad { grid-template-columns: repeat(3, 30px); grid-template-rows: repeat(3, 30px); }
  .face { grid-template-columns: repeat(3, 32px); grid-template-rows: repeat(3, 32px); }
}
