/* ===== Tema da Luma — troque as cores aqui ===== */
:root {
  --bg: #0d0b14;
  --bg-2: #14111f;
  --panel: #1a1628;
  --panel-2: #231e35;
  --line: #2e2845;
  --text: #ece8f6;
  --muted: #9a93b3;
  --accent: #a77bff;      /* roxo da Luma */
  --accent-2: #ff7ac6;    /* rosa */
  --accent-glow: rgba(167, 123, 255, .45);
  --user-bubble: #2a2340;
  --danger: #ff6b81;
  --radius: 18px;
  --side-w: 270px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 15.5px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

/* ---------- avatar ---------- */
.avatar { border-radius: 50%; object-fit: cover; background: var(--panel-2); flex: none; }
.avatar-sm { width: 30px; height: 30px; }
.avatar-msg { width: 32px; height: 32px; margin-top: 2px; }
.avatar-xl { width: 112px; height: 112px; box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent), 0 0 50px var(--accent-glow); }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at top, #2a1d4a 0%, var(--bg) 60%); }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.login-card h1 { margin: 10px 0 0; font-size: 26px; }
.login-card input { width: 100%; padding: 13px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 16px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.btn-primary { width: 100%; padding: 13px; border: 0; border-radius: 12px; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent, #fff); }

/* ---------- layout ---------- */
.app { display: flex; height: 100dvh; }
.sidebar { width: var(--side-w); background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 12px; gap: 10px; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 4px 6px 8px; }
.brand { font-weight: 700; font-size: 17px; flex: 1; }
.new-chat { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: transparent; text-align: left; }
.new-chat:hover { background: var(--panel); }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.conv { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 10px; color: var(--muted); font-size: 14px; cursor: pointer; }
.conv:hover { background: var(--panel); color: var(--text); }
.conv.active { background: var(--panel-2); color: var(--text); }
.conv .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv .del { opacity: 0; border: 0; background: none; color: var(--muted); padding: 0 4px; }
.conv:hover .del { opacity: 1; }
.conv-group { font-size: 12px; color: var(--muted); padding: 12px 10px 4px; text-transform: uppercase; letter-spacing: .06em; }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.looks-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.looks { display: flex; flex-wrap: wrap; gap: 8px 4px; }
.look { min-width: 46px; }
.look { flex: 1; border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.look img { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; border: 2px solid transparent; transition: .2s; }
.look:hover img { border-color: var(--line); }
.look.active img { border-color: var(--accent); box-shadow: 0 0 14px var(--accent-glow); }
.look.active { color: var(--text); }
.link-btn { background: none; border: 0; color: var(--muted); text-align: left; padding: 4px 0; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; color: var(--muted); }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 20px; background: var(--line); position: relative; transition: .2s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 17px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 54px; display: flex; align-items: center; gap: 8px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.top-title { flex: 1; display: flex; align-items: center; gap: 8px; font-weight: 600; overflow: hidden; }
.top-title #convTitle { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #3a2a10; color: #ffc46b; flex: none; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 0; background: transparent; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.only-mobile { display: none; }

/* ---------- chat ---------- */
.chat { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.messages { max-width: 780px; margin: 0 auto; padding: 24px 16px 8px; display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; gap: 12px; animation: rise .25s ease; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); padding: 10px 16px; border-radius: var(--radius); border-bottom-right-radius: 6px; max-width: 80%; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .body { flex: 1; min-width: 0; }
.msg.assistant .content { word-wrap: break-word; }
.msg .content p { margin: 0 0 .7em; } .msg .content p:last-child { margin-bottom: 0; }
.msg .content ul, .msg .content ol { margin: .2em 0 .7em; padding-left: 1.4em; }
.msg .content code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; font-size: .92em; }
.msg .content pre { background: #0a0910; border: 1px solid var(--line); padding: 12px 14px; border-radius: 12px; overflow-x: auto; }
.msg .content pre code { background: none; padding: 0; }
.msg .content a { color: var(--accent); }
.msg .content h3, .msg .content h4 { margin: .8em 0 .3em; }
.voice-tag { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tool-pill { font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; }
.actions { display: flex; gap: 2px; margin-top: 6px; opacity: .0; transition: opacity .15s; }
.msg:hover .actions, .msg.last .actions { opacity: 1; }
.actions button { border: 0; background: none; color: var(--muted); padding: 4px 6px; border-radius: 8px; font-size: 13px; }
.actions button:hover { background: var(--panel); color: var(--text); }
.actions button.playing { color: var(--accent); }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
.error-box { color: var(--danger); background: rgba(255,107,129,.08); border: 1px solid rgba(255,107,129,.3); padding: 8px 12px; border-radius: 10px; font-size: 14px; }

/* ---------- welcome ---------- */
.welcome { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 32px 16px; gap: 8px; }
.welcome h2 { margin: 18px 0 0; font-size: 28px; background: linear-gradient(135deg, #fff, var(--accent) 60%, var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome p { margin: 0; }
.orb-wrap { animation: float 5s ease-in-out infinite; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 22px; max-width: 620px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 8px 14px; font-size: 14px; color: var(--muted); }
.chip:hover { color: var(--text); border-color: var(--accent); }

/* ---------- composer ---------- */
.composer-wrap { padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); }
.composer { max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 26px; padding: 7px 7px 7px 18px; transition: border-color .2s, box-shadow .2s; }
.composer:focus-within { border-color: #4a3f6e; }
.composer textarea { flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; max-height: 200px; padding: 8px 0; }
.mic.listening { color: #fff; background: var(--danger); animation: pulse 1.4s infinite; }
.send { width: 38px; height: 38px; border-radius: 50%; border: 0; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent, #fff); flex: none; }
.send:disabled { background: var(--line); color: var(--muted); cursor: default; }
.send.stop { background: var(--text); color: var(--bg); }
.hint { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; opacity: .7; }

/* ---------- modo conversa ---------- */
.voice-overlay { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 24px 16px calc(32px + env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at center, #241a40 0%, var(--bg) 70%); }
.voice-overlay::before { content: ""; position: absolute; inset: -40px; background: var(--look-bg, none) center / cover; filter: blur(40px) saturate(1.3); opacity: .28; z-index: -1; }
.voice-overlay { isolation: isolate; overflow: hidden; }
.close-voice { align-self: flex-end; font-size: 18px; }
.voice-stage { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; min-height: 0; }

/* palco do personagem: retrato + anéis de energia atrás */
.stage { position: relative; --lvl: 0; height: min(64dvh, 135vw); aspect-ratio: 3 / 4; display: grid; place-items: center; }
.halo { position: absolute; inset: -12% -30%; display: grid; place-items: center; pointer-events: none; }
.halo .ring { position: absolute; width: 70%; aspect-ratio: 1; border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: 0 0 18px var(--accent-glow), inset 0 0 18px var(--accent-glow);
  transform: scale(calc(.85 + var(--lvl) * .25)); transition: transform .08s linear; opacity: .7; }
.halo .r2 { width: 85%; border-color: var(--accent-2); box-shadow: 0 0 22px var(--accent-glow), inset 0 0 22px var(--accent-glow); transform: scale(calc(.9 + var(--lvl) * .18)); }
.halo .r3 { width: 100%; border-color: var(--accent); opacity: .4; box-shadow: 0 0 26px var(--accent-glow); transform: scale(calc(.95 + var(--lvl) * .12)); }
.halo .r4 { width: 118%; border-color: var(--accent-2); opacity: .25; box-shadow: none; transform: scale(calc(1 + var(--lvl) * .08)); }
.stage::before { content: ""; position: absolute; inset: -20% -40%; border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 60%); opacity: calc(.5 + var(--lvl) * .9); pointer-events: none; }
.stage.listening .halo .ring { animation: ripple 2.2s infinite; }
.stage.listening .r2 { animation-delay: .55s; } .stage.listening .r3 { animation-delay: 1.1s; } .stage.listening .r4 { animation-delay: 1.65s; }
.stage.thinking .halo { animation: spin 6s linear infinite; }
.stage.thinking .halo .ring { border-style: dashed; }

.character { position: relative; width: 100%; height: 100%; border-radius: 22px; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 20px 80px rgba(0,0,0,.6), 0 0 calc(30px + var(--lvl) * 70px) var(--accent-glow);
  animation: idle 6s ease-in-out infinite; }
.character .layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 0; background: var(--panel-2); }
.character .mouth, .character .blink { opacity: 0; background: transparent; }
.character .mouth.on, .character .blink.on { opacity: 1; }
.stage.speaking .character { animation: talk .5s ease-in-out infinite alternate; }
/* vídeos: parado (idle) por baixo, falando por cima — troca suave conforme a voz */
.character .vid { opacity: 0; transition: opacity .14s linear; background: transparent; pointer-events: none; }
.character .vid.ready { opacity: 1; }
.character #vidTalk.ready { opacity: 0; }
.character #vidTalk.ready.on { opacity: 1; }
.character #vidTalk { transition: opacity .22s ease; }
.stage.has-video .character, .stage.has-video.speaking .character { animation: none; }
/* sincronia labial: bocas recortadas da folha de referência, mesmo enquadramento do retrato */
.character .visemes { background: transparent; pointer-events: none; }
.character .visemes img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; }
.character .visemes img.on { opacity: 1; }
.stage.lipsync .vid { opacity: 0 !important; }
.stage.has-lips.speaking .character { animation: idle 6s ease-in-out infinite; }
.stage.has-lips.speaking .character .base { transform: none; }
.stage.has-video.speaking .character .base { transform: none; }
.stage.no-sprites.speaking .character .base { transform: scale(calc(1 + var(--lvl) * .04)); transform-origin: 50% 60%; }
.voice-state { font-size: 18px; font-weight: 600; margin: 0; }
.voice-text { color: var(--muted); max-width: 560px; min-height: 3em; margin: 0; }
.voice-tap { padding: 14px 28px; border-radius: 99px; border: 0; font-weight: 600; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent, #fff); box-shadow: 0 8px 30px var(--accent-glow); }

.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(20px); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,107,129,.6); } 100% { box-shadow: 0 0 0 12px rgba(255,107,129,0); } }
@keyframes float { 50% { transform: translateY(-8px); } }
@keyframes ripple { 0% { transform: scale(.8); opacity: .8; } 100% { transform: scale(1.5); opacity: 0; } }
@keyframes breathe { 50% { transform: scale(.94); opacity: .8; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes idle { 50% { transform: translateY(-6px) rotate(-.4deg); } }
@keyframes talk { from { transform: translateY(0) rotate(-.3deg); } to { transform: translateY(-3px) rotate(.3deg); } }
@media (prefers-reduced-motion: reduce) { .character, .halo, .orb-wrap { animation: none !important; } }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .only-mobile { display: grid; }
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; display: none; }
  .scrim.show { display: block; }
  .msg.user .bubble { max-width: 88%; }
  .avatar-msg { display: none; }
  .welcome h2 { font-size: 24px; }
  .actions { opacity: 1; }
  body { font-size: 16px; }
}
