:root {
  --bg: #07060d; --panel: #0e0c18; --panel-2: #141122; --line: #ffffff12; --line-2: #ffffff22;
  --text: #ecebf5; --muted: #9a97b0; --violet: #8b5cf6; --violet-2: #a78bfa; --cyan: #22d3ee;
  --green: #34d399; --red: #f87171; --amber: #fbbf24;
  --top-h: 52px; --chat-w: 400px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--violet-2); }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; background: #ffffff10; padding: 1px 5px; border-radius: 5px; }
.hidden { display: none !important; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.mobile-only { display: none !important; }

#shell { height: 100%; display: flex; flex-direction: column; }
#top { height: var(--top-h); display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #0f0c1d, #0a0814); position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: 9px; color: #fff; text-decoration: none; margin-right: 8px; font-size: 15px; }
.logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: #000; border: 1px solid var(--line-2); box-shadow: 0 0 18px #8b5cf655; }
.pill { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: #ffffff08; font-size: 12.5px; color: #d7d5e6; white-space: nowrap; }
button.pill:hover { background: #ffffff12; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.pill.ok i { background: var(--green); box-shadow: 0 0 10px var(--green); }
.pill.bad i { background: var(--red); box-shadow: 0 0 10px var(--red); }
.pill.busy i { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.tbtn { height: 34px; min-width: 34px; padding: 0 11px; border-radius: 10px; border: 1px solid var(--line-2); background: #ffffff08; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.tbtn:hover { background: #ffffff14; }
.tbtn.on { background: var(--violet); border-color: var(--violet-2); color: #fff; box-shadow: 0 0 18px #8b5cf688; }

#main { flex: 1; min-height: 0; display: flex; }
#stage { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 14px; gap: 8px; background: radial-gradient(1200px 600px at 30% 0%, #1b1338 0%, transparent 60%), var(--bg); }
#screen-frame { flex: 1; min-height: 0; position: relative; border-radius: 14px; overflow: hidden; background: #05030f; border: 1px solid #ffffff1c; box-shadow: 0 0 0 1px #000, 0 30px 80px #000c, 0 0 60px #8b5cf622; }
#screen { position: absolute; inset: 0; }
#screen canvas { outline: none; }
#screen-frame.agent-active { border-color: #8b5cf6aa; box-shadow: 0 0 0 1px #000, 0 30px 80px #000c, 0 0 0 3px #8b5cf633, 0 0 70px #8b5cf655; transition: box-shadow .3s, border-color .3s; }
#screen-frame.controlling { border-color: #34d399aa; box-shadow: 0 0 0 3px #34d39933, 0 0 70px #34d39944; }
.screen-msg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 20px; background: radial-gradient(600px 300px at 50% 40%, #1d1440, #05030f); z-index: 2; }
.sm-title { font-size: 17px; font-weight: 700; }
.sm-sub { color: var(--muted); font-size: 13px; max-width: 460px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #ffffff1a; border-top-color: var(--violet-2); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#stage-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 0 4px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--red); box-shadow: 0 0 8px var(--red); animation: blink 1.6s infinite; }

#agent-banner { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; border-radius: 999px; background: #0b0816e6; border: 1px solid #8b5cf688; font-size: 12.5px; box-shadow: 0 8px 30px #000a; backdrop-filter: blur(8px); max-width: calc(100% - 24px); animation: drop .3s ease; }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -8px); } }
#agent-banner-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#agent-banner button, #control-hint button { border: 0; background: #f8717122; color: #fca5a5; border-radius: 999px; padding: 4px 12px; font-size: 12px; }
#control-hint { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 3; background: #052e22ee; border: 1px solid #34d39966; color: #d1fae5; padding: 6px 6px 6px 14px; border-radius: 999px; font-size: 12.5px; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
#control-hint button { background: #34d39922; color: #a7f3d0; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--violet-2); box-shadow: 0 0 0 0 #a78bfa; animation: pulse 1.4s infinite; flex-shrink: 0; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #a78bfaaa; } 100% { box-shadow: 0 0 0 10px #a78bfa00; } }

/* ---------- chat ---------- */
#chat { width: var(--chat-w); flex-shrink: 0; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--panel); min-height: 0; }
#messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin; scrollbar-color: #ffffff22 transparent; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 14px; word-wrap: break-word; animation: msgIn .25s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, #7c3aed, #6d28d9); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot p { margin: 0 0 6px; } .msg.bot p:last-child { margin: 0; }
.msg.bot ul, .msg.bot ol { margin: 4px 0 6px; padding-left: 20px; }
.msg.bot h4 { margin: 8px 0 4px; }
.msg.bot pre { background: #05040a; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-x: auto; font-size: 12px; margin: 6px 0; }
.msg.bot pre code { background: none; padding: 0; }
.msg .meta { margin-top: 6px; font-size: 11px; color: var(--muted); }
.sources { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.sources a { font-size: 11px; text-decoration: none; padding: 2px 8px; border-radius: 999px; background: #ffffff0c; border: 1px solid var(--line); color: #c4b5fd; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: #ffffff08; border: 1px solid var(--line); padding: 4px 12px; border-radius: 999px; text-align: center; }
.err { align-self: stretch; font-size: 13px; color: #fecaca; background: #7f1d1d33; border: 1px solid #f8717155; padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; }
.thinking { align-self: flex-start; display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: #c4b5fd; padding: 6px 10px; border-radius: 10px; background: #8b5cf614; border: 1px dashed #8b5cf655; max-width: 100%; }
.thinking .live { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.dots { display: inline-flex; gap: 3px; flex-shrink: 0; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--violet-2); animation: bounce 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-4px); opacity: 1; } }
.step { align-self: stretch; border: 1px solid var(--line); background: #ffffff05; border-radius: 11px; font-size: 12.5px; animation: msgIn .2s ease; overflow: hidden; }
.step summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; }
.step summary::-webkit-details-marker { display: none; }
.step .s-ico { font-size: 14px; }
.step .s-name { font-weight: 700; color: #ddd6fe; white-space: nowrap; }
.step .s-arg { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; }
.step .s-state { flex-shrink: 0; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; }
.step.running .s-state { border: 2px solid #ffffff22; border-top-color: var(--violet-2); animation: spin .8s linear infinite; }
.step.ok .s-state { background: #34d39922; color: var(--green); }
.step.fail .s-state { background: #f8717122; color: var(--red); }
.step.running { border-color: #8b5cf666; background: #8b5cf60d; }
.step-body { padding: 0 10px 9px; }
.step-body .thought { color: #c4b5fd; font-style: italic; margin-bottom: 6px; }
.step-body pre { margin: 0; max-height: 220px; overflow: auto; background: #05040a; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 11.5px; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Menlo, Consolas, monospace; color: #cfcde0; }
.step-body .arg-block { margin-bottom: 6px; }
.welcome { align-self: stretch; padding: 18px 16px; border-radius: 16px; border: 1px solid #8b5cf644; background: radial-gradient(400px 160px at 0% 0%, #8b5cf62a, transparent), var(--panel-2); animation: msgIn .3s ease; }
.welcome h3 { margin: 0 0 6px; font-size: 18px; }
.welcome p { margin: 0 0 10px; color: #cfcde0; }
.welcome .caps { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0 4px; }
.welcome .caps span { font-size: 12px; background: #ffffff08; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
#suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
#suggestions button { font-size: 12px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line-2); background: #ffffff08; color: #ddd6fe; text-align: left; transition: background .15s, transform .15s; }
#suggestions button:hover { background: #8b5cf622; transform: translateY(-1px); }
#composer { display: flex; align-items: flex-end; gap: 8px; margin: 0 12px 6px; padding: 8px; border-radius: 14px; border: 1px solid var(--line-2); background: #05040a; }
#composer:focus-within { border-color: #8b5cf6aa; box-shadow: 0 0 0 3px #8b5cf622; }
#prompt { flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; max-height: 160px; padding: 6px 4px; }
#send, #stop { width: 36px; height: 36px; border-radius: 10px; border: 0; font-size: 17px; font-weight: 700; flex-shrink: 0; }
#send { background: #fff; color: #000; } #send:disabled { opacity: .4; }
#stop { background: var(--red); color: #fff; }
.chat-foot { display: flex; padding: 0 14px 10px; font-size: 12px; }
.link { background: none; border: 0; color: var(--muted); padding: 0; text-decoration: none; font-size: 12px; }
.link:hover { color: #fff; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: #000b; backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { width: min(560px, 100%); max-height: 90vh; overflow: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; padding: 20px; box-shadow: 0 30px 90px #000; animation: msgIn .25s ease; }
.modal-card.narrow { width: min(420px, 100%); text-align: center; }
.modal-card h2 { margin: 0 0 6px; font-size: 19px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.icon-btn { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line-2); background: #ffffff08; }
.gate-logo { width: 60px; height: 60px; border-radius: 18px; margin: 4px auto 14px; display: grid; place-items: center; background: #000; border: 1px solid var(--line-2); box-shadow: 0 0 40px #8b5cf688; }
#gate-form { display: flex; gap: 8px; margin-top: 14px; }
#gate-form input { flex: 1; height: 42px; border-radius: 11px; border: 1px solid var(--line-2); background: #05040a; color: #fff; padding: 0 14px; font-size: 16px; letter-spacing: .15em; text-transform: uppercase; outline: none; }
#gate-form input:focus { border-color: var(--violet); }
.err-text { color: var(--red); font-size: 13px; min-height: 20px; margin-top: 8px; }
.btn { height: 40px; padding: 0 18px; border-radius: 11px; border: 1px solid var(--line-2); background: #ffffff0a; font-weight: 600; }
.btn.primary { background: #fff; color: #000; border-color: #fff; }
.btn.primary:hover { background: #e9e5ff; }
.btn.small { height: 32px; padding: 0 12px; font-size: 12.5px; }
.providers { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.prov { display: flex; gap: 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #ffffff05; cursor: pointer; }
.prov:has(input:checked) { border-color: #8b5cf6aa; background: #8b5cf612; }
.prov input { accent-color: var(--violet); margin-top: 3px; }
.prov small { display: block; color: var(--muted); font-size: 12px; }
.tag { font-size: 10px; background: var(--violet); color: #fff; padding: 1px 6px; border-radius: 999px; vertical-align: 2px; margin-left: 4px; }
.pane { margin-bottom: 12px; }
.pane label, .row label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.pane input, .pane select, .row input[type=number] { display: block; width: 100%; margin-top: 4px; height: 36px; border-radius: 9px; border: 1px solid var(--line-2); background: #05040a; color: #fff; padding: 0 10px; font: inherit; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.check { display: flex !important; gap: 8px; align-items: center; color: var(--text) !important; }
.note { font-size: 12.5px; padding: 9px 11px; border-radius: 10px; background: #ffffff08; border: 1px solid var(--line); }
.note.good { border-color: #34d39955; background: #34d39910; }
.note.bad { border-color: #f8717155; background: #f8717110; }
.progress { position: relative; height: 26px; border-radius: 9px; background: #ffffff0a; overflow: hidden; margin: 10px 0; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--violet), var(--cyan)); transition: width .3s; }
.progress .ptext { position: relative; font-size: 12px; line-height: 26px; padding: 0 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* fullscreen desktop */
body.full #chat, body.full #top { display: none; }
body.full #stage { padding: 0; }
body.full #screen-frame { border-radius: 0; border: 0; }
body.full #stage-foot { display: none; }

@media (max-width: 900px) {
  :root { --chat-w: 100%; }
  .mobile-only { display: inline-flex !important; }
  #top .pill span { display: none; }
  #top .pill { padding: 0 10px; }
  #btn-control span { display: none; }
  #btn-shot, .brand b { display: none; }
  #top { gap: 6px; padding: 0 8px; }
  #main { flex-direction: column; }
  #stage { flex: none; height: 42vh; padding: 8px; }
  #chat { border-left: 0; border-top: 1px solid var(--line); flex: 1; }
  body.chat-hidden #chat { display: none; }
  body.chat-hidden #stage { flex: 1; height: auto; }
}
