:root {
  --bg: #03070f;
  --panel: rgba(10, 26, 48, .72);
  --line: rgba(0, 180, 255, .22);
  --text: #e6f6ff;
  --muted: #7fa3c4;
  --accent: #00c8ff;
  --accent-2: #7fe0ff;
  --alert: #ff5a6e;
  --warm: #ffb547;
  --user: rgba(0, 120, 200, .28);
  --hud-font: "Orbitron", "Rajdhani", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 17px/1.45 "Rajdhani", -apple-system, BlinkMacSystemFont, system-ui, sans-serif; overflow: hidden; }
.hidden { display: none !important; }
.screen { position: relative; height: 100dvh; display: flex; flex-direction: column; }

/* Fundo em grade com vinheta */
.grid-bg { position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(0, 140, 255, .16), transparent 60%),
    linear-gradient(rgba(0, 200, 255, .05) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, rgba(0, 200, 255, .05) 1px, transparent 1px) 0 0 / 28px 28px; }

/* ---------- Login ---------- */
#login { align-items: center; justify-content: center; gap: 18px; padding: 24px; }
#login h1 { font-family: var(--hud-font); letter-spacing: .35em; font-weight: 400; margin: 0; color: var(--accent-2);
  text-shadow: 0 0 14px rgba(0, 200, 255, .6); }
#login form { display: flex; flex-direction: column; gap: 10px; width: min(320px, 100%); }
input, textarea { background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font: inherit; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 200, 255, .15); }
button { font: inherit; color: var(--text); background: transparent; border: 1px solid var(--accent); border-radius: 12px;
  padding: 12px; font-family: var(--hud-font); font-size: 14px; letter-spacing: .15em; text-transform: uppercase; }
#login button { background: rgba(0, 200, 255, .12); }
.error { color: var(--alert); min-height: 1em; margin: 0; text-align: center; }

/* ---------- HUD ---------- */
.hud { position: relative; padding: calc(env(safe-area-inset-top) + 8px) 16px 10px; border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; transition: padding .3s; }
.hud-top { width: 100%; display: flex; justify-content: space-between; align-items: flex-start; }
.readout { display: flex; flex-direction: column; min-width: 96px; }
.readout.right { text-align: right; }
.readout strong { font-family: var(--hud-font); font-weight: 600; font-size: 24px; color: var(--accent-2);
  text-shadow: 0 0 10px rgba(0, 200, 255, .45); line-height: 1.1; }
.readout span:last-child { color: var(--muted); font-size: 14px; }
.label { font-family: var(--hud-font); font-size: 9px; letter-spacing: .25em; text-transform: uppercase; color: var(--muted); }
.icon { border: 0; padding: 6px 10px; font-size: 22px; line-height: 1; letter-spacing: 0; color: var(--accent-2); }

.status { margin-top: 4px; font-family: var(--hud-font); font-size: 11px; letter-spacing: .35em; color: var(--accent); }
.hud-bottom { width: 100%; display: flex; gap: 8px; margin-top: 10px; }
.chip { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 6px 10px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel); }
.chip span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.chip.small { flex: 0 0 auto; text-align: center; }

/* HUD recolhida: mais espaço para a conversa */
.hud.compact { flex-direction: row; gap: 12px; padding-bottom: 8px; }
.hud.compact .hud-top { order: 2; flex: 1; align-items: center; }
.hud.compact .readout strong { font-size: 18px; }
.hud.compact .readout span:last-child { display: none; }
.hud.compact .hud-bottom, .hud.compact .status { display: none; }
.hud.compact .reactor { order: 1; width: 52px; height: 52px; margin: 0; }

/* ---------- Reator ---------- */
.reactor { --level: 0; --tint: var(--accent); width: 150px; height: 150px; margin: -6px 0 0; padding: 0; border: 0;
  border-radius: 50%; position: relative; transition: width .3s, height .3s; }
.reactor.big { width: 180px; height: 180px; }
.reactor svg { width: 100%; height: 100%; overflow: visible;
  filter: drop-shadow(0 0 calc(8px + var(--level) * 18px) var(--tint)); }
.reactor .ring { fill: none; stroke: var(--tint); transform-origin: 100px 100px; }
.reactor .r1 { stroke-width: 1.5; stroke-dasharray: 60 12 4 12; opacity: .55; animation: spin 28s linear infinite; }
.reactor .r2 { stroke-width: 5; stroke-dasharray: 2 6; opacity: .7; animation: spin 18s linear infinite reverse; }
.reactor .r3 { stroke-width: 2; stroke-dasharray: 100 20 30 20; opacity: .9; animation: spin 10s linear infinite; }
.reactor .r4 { stroke-width: 3; opacity: .9; }
.reactor .ticks circle { fill: none; stroke: var(--tint); stroke-width: 10; stroke-dasharray: 3 5.5; opacity: .45;
  transform-origin: 100px 100px; animation: spin 40s linear infinite reverse; }
.reactor .core { transform-origin: 100px 100px; transform: scale(calc(.85 + var(--level) * .35));
  transition: transform .12s ease-out; animation: breathe 4s ease-in-out infinite; }
.reactor .core-dot { fill: #fff; opacity: .9; }

.reactor[data-state="listening"] { --tint: var(--alert); }
.reactor[data-state="listening"] .r3 { animation-duration: 3s; }
.reactor[data-state="listening"] .r4 { animation: ping 1.2s ease-out infinite; transform-origin: 100px 100px; }
.reactor[data-state="thinking"] .r1 { animation-duration: 4s; }
.reactor[data-state="thinking"] .r2 { animation-duration: 2.5s; }
.reactor[data-state="thinking"] .r3 { animation-duration: 1.4s; }
.reactor[data-state="thinking"] .core { animation: breathe .9s ease-in-out infinite; }
.reactor[data-state="speaking"] .r3 { animation-duration: 5s; }
.reactor[data-state="speaking"] .core { animation: none; }
.reactor[data-state="error"] { --tint: var(--warm); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { opacity: .75; } }
@keyframes ping { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(1.5); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .reactor * { animation: none !important; } }

/* ---------- Menu ---------- */
.menu { position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 48px); z-index: 10;
  background: rgba(6, 16, 32, .96); border: 1px solid var(--line); border-radius: 14px; padding: 6px;
  display: flex; flex-direction: column; min-width: 240px; backdrop-filter: blur(10px); }
.menu button { border: 0; text-align: left; padding: 11px 12px; border-radius: 10px; font-family: "Rajdhani", sans-serif;
  font-size: 16px; letter-spacing: .02em; text-transform: none; }
.menu button:active { background: rgba(0, 200, 255, .12); }

/* ---------- Conversa ---------- */
main { position: relative; flex: 1; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user); border: 1px solid rgba(0, 160, 255, .35); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-left: 2px solid var(--accent);
  border-bottom-left-radius: 4px; }
.msg.system { align-self: center; color: var(--muted); font-size: 14px; background: none; text-align: center; }
.msg .thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.msg .thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.msg .thumbs .doc { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }

/* ---------- Anexos e campo de texto ---------- */
.previews { display: flex; gap: 8px; padding: 8px 12px 0; overflow-x: auto; }
.preview { position: relative; flex: none; }
.preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--accent); }
.preview .doc { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--accent);
  font-size: 11px; text-align: center; padding: 4px; overflow: hidden; }
.preview button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%;
  background: var(--bg); font-size: 12px; line-height: 1; letter-spacing: 0; }

#composer { position: relative; display: flex; align-items: flex-end; gap: 4px;
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px); border-top: 1px solid var(--line); background: rgba(3, 7, 15, .9); }
#composer textarea { flex: 1; resize: none; max-height: 140px; border-radius: 18px; padding: 10px 14px; }
#composer .icon { padding: 9px 8px; }
#mic.on { color: var(--alert); text-shadow: 0 0 10px var(--alert); }
.send { color: var(--accent); }
.msg .thumbs + div:empty { display: none; }
