:root {
  --bg: #070202; --ink: #fbe9e0; --dim: rgba(255, 205, 185, .58); --line: rgba(255, 110, 70, .22);
  --ember: #ff6a3d; --ember2: #ff2b3f; --card: rgba(40, 10, 8, .62);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.45 Bahnschrift, "Segoe UI", system-ui, -apple-system, sans-serif; overscroll-behavior: none; }
body { background: radial-gradient(120% 60% at 50% 0%, #2a0806 0%, #0d0303 55%, #050101 100%) fixed; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

#brain { position: fixed; left: 50%; top: calc(var(--safe-t) + 10px); width: min(78vw, 46vh); height: min(78vw, 46vh);
  transform: translateX(-50%); pointer-events: none; z-index: 0; transition: top .5s, width .5s, height .5s, opacity .5s;
  filter: brightness(1.45) drop-shadow(0 0 14px rgba(255, 80, 40, .35)); }
body.chatting #brain { width: min(46vw, 24vh); height: min(46vw, 24vh); }

.screen { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; }
.brand { display: flex; flex-direction: column; line-height: 1.1; }
.brand b { letter-spacing: .42em; font-weight: 600; font-size: 1.05rem; color: #ffd9c9;
  text-shadow: 0 0 18px rgba(255, 90, 50, .6); }
.brand span { font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; color: var(--dim); }

/* ---------- login */
#login { justify-content: flex-end; align-items: center; padding: 0 24px calc(40px + var(--safe-b)); gap: 26px; }
#login .brand { align-items: center; margin-top: auto; }
#login-form { width: min(100%, 360px); display: flex; flex-direction: column; gap: 12px; }
#login-form input, #msg { width: 100%; background: rgba(20, 5, 4, .75); color: var(--ink); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 16px; font: inherit; outline: none; }
#login-form input:focus, #msg:focus { border-color: rgba(255, 120, 70, .6); box-shadow: 0 0 0 3px rgba(255, 90, 50, .12); }
#login-form button { padding: 14px; border: 0; border-radius: 14px; font-weight: 600; letter-spacing: .06em;
  background: linear-gradient(180deg, #ff6a3d, #d8262f); box-shadow: 0 8px 30px rgba(255, 60, 40, .35); }
#login-msg { min-height: 1.4em; margin: 0; text-align: center; color: #ffb4a0; font-size: .9rem; }

/* ---------- app */
header { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 10px) 16px 6px;
  position: relative; z-index: 3; }
.head-btns { display: flex; gap: 8px; }
.icon { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: rgba(25, 6, 5, .6);
  display: grid; place-items: center; font-size: 1.05rem; padding: 0; }
.icon[aria-pressed="true"] { border-color: rgba(255, 130, 80, .8); background: rgba(255, 90, 50, .22); }
#menu { position: absolute; right: 16px; top: calc(var(--safe-t) + 56px); background: rgba(25, 7, 6, .96);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; min-width: 170px; }
#menu button { background: none; border: 0; text-align: left; padding: 12px 16px; }
#menu button + button { border-top: 1px solid var(--line); }
.stage { flex: 0 0 min(36vh, 64vw); transition: flex-basis .5s; }
body.chatting .stage { flex-basis: min(18vh, 34vw); }

#chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 10px; scrollbar-width: none; flex: 0 0 auto; }
#chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 13px;
  font-size: .82rem; white-space: nowrap; backdrop-filter: blur(6px); }
.chip i { font-style: normal; color: var(--dim); margin-right: 6px; }
.chip.ok { border-color: rgba(120, 230, 170, .35); }
.chip.warn { border-color: rgba(255, 170, 70, .55); }

#chat { flex: 1 1 auto; overflow-y: auto; padding: 6px 14px 12px; display: flex; flex-direction: column; gap: 10px;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22px); mask-image: linear-gradient(180deg, transparent 0, #000 22px); }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word;
  animation: pop .25s ease-out; }
.msg.du { align-self: flex-end; background: linear-gradient(180deg, rgba(255, 106, 61, .9), rgba(216, 38, 47, .9));
  border-bottom-right-radius: 5px; }
.msg.jarvis { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.jarvis.live::after { content: "▍"; color: var(--ember); animation: blink 1s steps(2) infinite; }
.msg .tool { display: block; font-size: .75rem; color: var(--dim); letter-spacing: .04em; }
.msg.sys { align-self: center; background: none; color: var(--dim); font-size: .8rem; padding: 2px 8px; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
@keyframes blink { 50% { opacity: 0; } }

#bar { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px calc(10px + var(--safe-b));
  background: linear-gradient(180deg, transparent, rgba(5, 1, 1, .9) 30%); }
#msg { resize: none; max-height: 30vh; scrollbar-width: none; overflow-y: auto; padding: 10px 14px; border-radius: 20px; line-height: 1.35; }
#send { background: linear-gradient(180deg, #ff6a3d, #d8262f); border: 0; }
#mic.rec { background: #d8262f; border-color: #ff8a6a; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(255, 60, 40, 0); } 0% { box-shadow: 0 0 0 0 rgba(255, 60, 40, .55); } }

#sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; }
.sheet-in { width: 100%; max-height: 70vh; overflow: auto; background: #140504; border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(20px + var(--safe-b)); position: relative; }
.sheet-in h3 { margin: 0 0 10px; font-weight: 600; letter-spacing: .06em; }
.sheet-in pre { margin: 0; white-space: pre-wrap; font: inherit; color: #f3d5ca; }
.sheet-in .x { position: absolute; right: 14px; top: 12px; background: none; border: 0; font-size: 1.1rem; color: var(--dim); }
