:root {
  --void: #0a0502;
  --line: #5a2a0e;
  --orange: #ff8a1f;
  --amber: #ffb347;
  --warm: #ffe6cc;
  --dim: #b08a6c;
  --red: #ff5a4a;
  --mcore: clamp(84px, 26vw, 118px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background:
    radial-gradient(ellipse at 22% 45%, #2e1204 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(255,138,31,.05) 39px 40px),
    repeating-linear-gradient(90deg, transparent 0 39px, rgba(255,138,31,.05) 39px 40px),
    var(--void);
  color: var(--warm);
  font: 500 1.125rem/1.5 "Rajdhani", system-ui, sans-serif;
  overflow: hidden;
}
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.hud {
  height: 100%; height: 100dvh; max-width: 1280px; margin: 0 auto; gap: 24px;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  display: grid; grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
}
.core-panel, .console, .login { position: relative; background: rgba(20,10,4,.8); border: 1px solid var(--line); min-height: 0; }
.core-panel::before, .core-panel::after, .console::before, .console::after, .login::before, .login::after {
  content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid var(--orange);
}
.core-panel::before, .console::before, .login::before { top: -2px; left: -2px; border-right: 0; border-bottom: 0; }
.core-panel::after, .console::after, .login::after { bottom: -2px; right: -2px; border-left: 0; border-top: 0; }

.core-panel, .login { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; }
.wordmark { font: 700 1.5rem "Orbitron", sans-serif; letter-spacing: .18em; margin: 0; color: var(--orange); text-shadow: 0 0 14px rgba(255,138,31,.65); }
.status { margin: 0; color: var(--dim); min-height: 1.5em; overflow-wrap: anywhere; }
.caption, .hint, .end { display: none; }
.caption { margin: 0; max-width: min(92vw, 34ch); text-align: center; font-size: clamp(1rem, 4.4vw, 1.2rem); line-height: 1.4; overflow-wrap: anywhere; }
.caption.you { color: var(--dim); }
.caption.err { color: var(--red); }
.hint { margin: 0; color: var(--dim); font-size: .95rem; }

/* ---- The hologram (drawn on a canvas by hologram.js) ---- */
.core { position: relative; width: min(100%, 360px); aspect-ratio: 1; }
.holo { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---- Boot and voice mode: the reactor takes the whole screen ---- */
.boot { display: none; flex-direction: column; align-items: center; gap: 14px; width: min(80vw, 320px); }
.bar { width: 100%; height: 4px; background: rgba(255,138,31,.18); overflow: hidden; }
.bar b { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--orange), var(--amber)); box-shadow: 0 0 10px var(--orange); transition: width 2.2s cubic-bezier(.4,0,.2,1); }
.bar b.full { width: 100%; }
#start { display: none; }
.hud.booting, .hud.voicemode { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.hud.booting .console, .hud.voicemode .console { display: none; }
.hud.booting .core-panel, .hud.voicemode .core-panel { display: flex; flex-direction: column; justify-content: center; align-items: center; }
.hud.booting .boot { display: flex; }
.hud.booting.ready #start { display: block; }
.hud.booting .core { width: min(78vw, 42vh, 400px); width: min(78vw, 42dvh, 400px); }
.hud.voicemode .core { width: min(82vw, 40vh, 420px); width: min(82vw, 40dvh, 420px); cursor: pointer; }
.hud.voicemode .hint { display: block; }
.hud.voicemode .caption { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5; overflow: hidden; min-height: 2.8em; }
.hud.voicemode .end { display: block; min-width: 140px; }
.hud.voicemode .status { font: 600 1.1rem "Orbitron", sans-serif; letter-spacing: .2em; text-transform: uppercase; color: var(--orange); }

/* ---- Chat ---- */
.console { display: flex; flex-direction: column; padding: 20px; gap: 16px; animation: reveal .6s ease-out; }
@keyframes reveal { from { opacity: 0; } }
.log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 6px; -webkit-overflow-scrolling: touch; }
.msg { max-width: min(78ch, 100%); padding: 8px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.jarvis { border-left: 2px solid var(--orange); background: linear-gradient(90deg, rgba(255,138,31,.12), transparent); }
.msg.user { align-self: flex-end; border-right: 2px solid var(--dim); text-align: right; color: var(--dim); }
.msg.error { border-left-color: var(--red); color: var(--red); }
.msg.thinking { color: var(--dim); }
.msg.streaming::after { content: "\258D"; margin-left: 2px; color: var(--orange); animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.bars { display: inline-flex; gap: 4px; align-items: center; height: 20px; vertical-align: middle; margin-right: 10px; }
.bars i { width: 4px; height: 100%; background: var(--orange); transform: scaleY(.3); animation: eq .9s ease-in-out infinite; }
.bars i:nth-child(2) { animation-delay: .1s; } .bars i:nth-child(3) { animation-delay: .2s; }
.bars i:nth-child(4) { animation-delay: .3s; } .bars i:nth-child(5) { animation-delay: .4s; }
@keyframes eq { 50% { transform: scaleY(1); } }

.input-row { display: flex; gap: 12px; border-top: 1px solid var(--line); padding-top: 16px; }
textarea {
  flex: 1; resize: none; background: rgba(255,138,31,.06); border: 1px solid var(--line);
  color: var(--warm); font: inherit; font-size: 1rem; padding: 10px 14px; max-height: 140px; min-width: 0;
}
textarea::placeholder { color: var(--dim); }
.btn { background: transparent; color: var(--orange); border: 1px solid var(--orange); padding: 10px 24px; min-height: 44px; font: 600 1rem "Orbitron", sans-serif; cursor: pointer; transition: background .15s, color .15s; }
.btn:hover:not(:disabled) { background: var(--orange); color: var(--void); }
button:disabled { opacity: .4; cursor: wait; }
textarea:focus-visible, button:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.btn.talk { display: grid; place-items: center; width: 52px; padding: 0; }
.btn.talk[hidden] { display: none; }
.btn.talk svg { width: 22px; height: 22px; fill: currentColor; }

/* ---- Sign-in ---- */
.login-wrap { height: 100%; height: 100dvh; overflow: auto; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 24px; }
.login { width: min(100%, 380px); }
.login .core { width: 220px; }
.login form { display: flex; flex-direction: column; gap: 14px; width: 100%; }
.field { position: relative; width: 100%; }
.field input { width: 100%; min-height: 54px; padding: 12px 84px 12px 16px; font: inherit; font-size: 1.125rem; color: var(--warm); background: rgba(255,138,31,.06); border: 1px solid var(--line); }
.field input:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.reveal { position: absolute; top: 4px; right: 4px; bottom: 4px; padding: 0 14px; background: none; border: 0; color: var(--orange); font: 600 .85rem "Orbitron", sans-serif; cursor: pointer; }
.login .btn { width: 100%; min-height: 54px; font-size: 1.05rem; }
.login .err { margin: 0; color: var(--red); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 800px) {
  .hud { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 12px;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .core-panel { display: grid; grid-template-columns: var(--mcore) minmax(0, 1fr); grid-template-areas: "core mark" "core stat"; gap: 2px 16px; padding: 12px; justify-items: start; align-items: center; }
  .core-panel .core { grid-area: core; width: var(--mcore); }
  .wordmark { grid-area: mark; font-size: clamp(.8rem, 4.2vw, 1.05rem); letter-spacing: .1em; overflow-wrap: anywhere; }
  .status { grid-area: stat; }
  .console { padding: 12px; }
}
@media (max-width: 480px) {
  .login-wrap { padding: 0; place-items: stretch; }
  .login { width: 100%; min-height: 100%; border: 0; background: none; justify-content: center;
    padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom)); }
  .login::before, .login::after { display: none; }
}
@media (max-height: 600px) { .login .core { width: 120px; } }
@media (prefers-reduced-motion: reduce) { .bars i, .console, .msg.streaming::after { animation: none !important; } }

/* ---- Chat header and conversation drawer ---- */
.chat-head { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.chat-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 .95rem "Orbitron", sans-serif; letter-spacing: .08em; color: var(--orange); }
.icon-btn { width: 44px; height: 44px; flex: none; display: grid; place-items: center; background: none; border: 1px solid var(--line); color: var(--orange); cursor: pointer; }
.icon-btn:hover { border-color: var(--orange); }
.icon-btn svg, .mini svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.drawer-wrap { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 5; }
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.55); opacity: 0; transition: opacity .2s; }
.drawer { position: absolute; top: 0; bottom: 0; left: 0; width: min(86%, 320px); background: #120803; border-right: 1px solid var(--line);
  transform: translateX(-102%); transition: transform .25s ease; display: flex; flex-direction: column; gap: 6px; padding: 14px 12px; overflow-y: auto; }
.console.drawer-open .drawer-wrap { pointer-events: auto; }
.console.drawer-open .scrim { opacity: 1; }
.console.drawer-open .drawer { transform: none; }
.drawer h2 { margin: 2px 4px 8px; font: 600 .8rem "Orbitron", sans-serif; letter-spacing: .18em; color: var(--dim); }
#chats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.chat-item { display: flex; align-items: center; gap: 2px; border: 1px solid transparent; }
.chat-item.active { border-color: var(--line); background: rgba(255,138,31,.1); }
.chat-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; color: var(--warm); font: inherit; padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; }
.chat-open .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-open .d { color: var(--dim); font-size: .85rem; }
.mini { width: 40px; height: 40px; flex: none; display: grid; place-items: center; background: none; border: 0; color: var(--dim); cursor: pointer; }
.mini:hover { color: var(--orange); }
.mini svg { width: 18px; height: 18px; }
.chat-none { color: var(--dim); padding: 8px 10px; }
.log.is-empty::before { content: "How can I help?"; margin: auto; color: var(--dim); font: 500 1.05rem "Orbitron", sans-serif; letter-spacing: .12em; opacity: .75; }

/* ---- Keep everything inside the screen: long titles and words must never widen the page ---- */
.hud > *, .core-panel > *, .console > *, .chat-head > * { min-width: 0; }
.chat-head { min-width: 0; }
.log { min-width: 0; overflow-x: hidden; }
.hud.booting .core-panel, .hud.voicemode .core-panel { overflow-y: auto; }
@media (max-height: 700px) {
  .hud.booting .core-panel, .hud.voicemode .core-panel { gap: 8px; padding: 12px; }
  .hud.voicemode .hint { display: none; }
}

/* ---- "Tap to hear JARVIS": shown when the phone refuses to play speech by itself ---- */
.hear-pill { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(max(16px, env(safe-area-inset-bottom)) + 92px); z-index: 30;
  max-width: 92vw; padding: 12px 22px; background: rgba(20,10,4,.94); color: var(--orange); border: 1px solid var(--orange);
  font: 600 .9rem "Orbitron", sans-serif; letter-spacing: .06em; cursor: pointer; box-shadow: 0 0 18px rgba(255,138,31,.45); }
.hear-pill[hidden] { display: none; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(max(12px, env(safe-area-inset-top)) + 8px); z-index: 40;
  max-width: min(92vw, 520px); padding: 10px 16px; background: rgba(20,10,4,.96); color: var(--warm); border: 1px solid var(--line);
  font-size: .95rem; line-height: 1.35; text-align: center; overflow-wrap: anywhere; }
.toast[hidden] { display: none; }
.msg .src { margin-top: 6px; font-size: .8rem; letter-spacing: .06em; color: var(--dim); }
.msg .src.err { color: var(--red); }
