/* =============================================================================
   GROK VOICE PWA — style.css v2
   Mobile-first · Dark · Símbolo 3D reativo em CSS puro
   Estados: .state-idle / .state-connecting / .state-listening
            .state-processing / .state-speaking / .state-error
   ============================================================================= */

/* ---------------------------------------------------------------- TOKENS --- */
:root {
  --bg: #000000;
  --bg-2: #0a0a0a;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-2: rgba(255, 255, 255, 0.1);
  --stroke: rgba(255, 255, 255, 0.12);
  --fg: #ffffff;
  --muted: #888888;
  --danger: #ff2800;

  /* cor reativa (sobrescrita por estado) */
  --accent: #ff2800;
  --accent-2: #c0c0c0;
  --glow: rgba(255, 40, 0, 0.5);

  /* animação reativa */
  --spin: 26s;
  --spin-rev: 34s;
  --pulse: 4.2s;
  --intensity: 0.35;

  /* amplitude de áudio (0 → 1) escrita pelo JS */
  --amp: 0;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

/* ---- Estados ---- */
/* ---- Estados ---- */
body.state-idle       { --accent:#ff2800; --accent-2:#c0c0c0; --glow:rgba(255,40,0,.40); --spin:26s;  --spin-rev:34s; --pulse:4.2s; --intensity:.30; }
body.state-connecting { --accent:#c0c0c0; --accent-2:#ffffff; --glow:rgba(192,192,192,.45);  --spin:14s;  --spin-rev:18s; --pulse:1.8s; --intensity:.45; }
body.state-listening  { --accent:#ff2800; --accent-2:#ff4000; --glow:rgba(255,40,0,.60);  --spin:9s;   --spin-rev:12s; --pulse:2.4s; --intensity:.70; }
body.state-processing { --accent:#c0c0c0; --accent-2:#ff2800; --glow:rgba(192,192,192,.50); --spin:2.6s; --spin-rev:3.4s; --pulse:1.1s; --intensity:.85; }
body.state-speaking   { --accent:#ff2800; --accent-2:#c0c0c0; --glow:rgba(255,40,0,.55);  --spin:5s;   --spin-rev:7s;  --pulse:1.4s; --intensity:1;   }
body.state-error      { --accent:#ff2800; --accent-2:#c0c0c0; --glow:rgba(255,40,0,.45); --spin:20s;  --spin-rev:26s; --pulse:1s;  --intensity:.55; }

/* ---------------------------------------------------------------- RESET ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
h2 { font-family: var(--font-display); font-size: 1.15rem; margin: 0; letter-spacing: -0.01em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .74rem; }

/* ------------------------------------------------------------- BACKGROUND -- */
.bg-field { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bg-blob {
  position: absolute; width: 78vmax; height: 78vmax; border-radius: 50%;
  filter: blur(90px); opacity: .38;
  transition: background 1s ease;
}
.b1 { top: -34vmax; left: -22vmax; background: radial-gradient(circle at 50% 50%, var(--accent) 0%, transparent 62%); animation: drift1 24s ease-in-out infinite alternate; }
.b2 { bottom: -40vmax; right: -26vmax; background: radial-gradient(circle at 50% 50%, var(--accent-2) 0%, transparent 62%); animation: drift2 30s ease-in-out infinite alternate; }
.bg-grid {
  position: absolute; inset: 0; opacity: .22;
  background-image:
    linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 45%, #000 0%, transparent 72%);
  -webkit-mask-image: radial-gradient(circle at 50% 45%, #000 0%, transparent 72%);
}
@keyframes drift1 { to { transform: translate3d(9vmax, 7vmax, 0) scale(1.12); } }
@keyframes drift2 { to { transform: translate3d(-8vmax, -6vmax, 0) scale(1.1); } }

/* ------------------------------------------------------------------ SHELL -- */
.app {
  position: relative; z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 14px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 14px);
  max-width: 720px; margin-inline: auto; width: 100%;
}

/* ---------------------------------------------------------------- TOPBAR --- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.icon-btn {
  position: relative;
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: transform .18s ease, background .25s ease, color .25s ease, border-color .25s ease;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn:hover  { background: var(--surface-2); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: #04060d;
  font-size: .64rem; font-weight: 700; display: grid; place-items: center;
  border: 2px solid var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; opacity: .9; }
.brand-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--glow); animation: breathe var(--pulse) ease-in-out infinite; }
.brand-name { font-family: var(--font-display); font-size: .78rem; letter-spacing: .22em; font-weight: 700; color: #cfd4ee; }

/* ------------------------------------------------------------------ STAGE -- */
.stage {
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: clamp(18px, 5vh, 44px);
  min-height: 0;
}
.aura {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; opacity: .95;
}

/* ---------------- HOLOGRAMA 3D ---------------- */
.hologram-container {
  position: relative;
  width: clamp(180px, 50vmin, 280px);
  aspect-ratio: 0.8;
  display: flex; align-items: center; justify-content: center;
  perspective: 1200px;
}

.hologram-glow {
  position: absolute; inset: -20%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--glow) 0%, transparent 65%);
  filter: blur(35px);
  opacity: calc(.30 + var(--amp) * .60);
  transform: scale(calc(.9 + var(--amp) * .2));
  transition: background .6s ease, opacity .18s linear, transform .18s ease-out;
  pointer-events: none;
}

.rafa-holo {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: screen;
  mask-image: radial-gradient(circle at center, black 50%, transparent 80%);
  -webkit-mask-image: radial-gradient(circle at center, black 50%, transparent 80%);
  z-index: 2;
  filter: drop-shadow(0 0 10px var(--glow)) drop-shadow(0 0 20px color-mix(in srgb, var(--accent-2) 40%, transparent));
  transform-style: preserve-3d;
  animation: holoHover 6s ease-in-out infinite alternate;
  transition: opacity 0.15s ease-in-out;
}

.speaking-face { opacity: 0; }
body.state-speaking .idle-face { opacity: 0; }
body.state-speaking .speaking-face { opacity: 1; }

@keyframes holoHover {
  0% { transform: translateY(-5px) rotateY(-10deg) rotateX(5deg); }
  100% { transform: translateY(5px) rotateY(10deg) rotateX(-5deg); }
}

/* Efeito glitch no processamento */
body.state-processing .rafa-holo {
  animation: holoGlitch 0.5s ease-in-out infinite alternate;
}
@keyframes holoGlitch {
  0% { transform: translate(1px, -1px) skewX(2deg); opacity: 0.8; }
  25% { transform: translate(-2px, 2px) skewX(-2deg); opacity: 0.9; }
  50% { transform: translate(2px, -2px) skewX(1deg); opacity: 1; }
  75% { transform: translate(-1px, 1px) skewX(-1deg); opacity: 0.7; }
  100% { transform: translate(1px, -2px) skewX(2deg); opacity: 1; }
}

/* barras equalizadoras integradas ao holograma */
.bars {
  position: absolute; bottom: 10%; width: 140%; left: -20%; height: 30%;
  pointer-events: none;
  opacity: 0; transition: opacity .4s ease;
  z-index: 10;
  display: flex; justify-content: center; align-items: flex-end;
}
body.state-listening .bars,
body.state-speaking .bars { opacity: 1; }
.bars i {
  position: absolute; bottom: 0;
  width: 3px; border-radius: 3px;
  background: linear-gradient(to top, var(--accent), var(--accent-2));
  transform-origin: 50% 100%;
  box-shadow: 0 0 10px var(--glow);
  will-change: height;
}

/* readout */
.readout { text-align: center; padding-inline: 16px; }
.status {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 4.6vw, 1.4rem);
  font-weight: 700; letter-spacing: -.01em;
  color: var(--fg);
  text-shadow: 0 0 26px var(--glow);
  transition: color .4s ease;
}
.sub-status {
  margin: 6px 0 0;
  font-size: .76rem; color: var(--muted);
  letter-spacing: .04em; text-transform: lowercase;
  max-width: 34ch; margin-inline: auto;
}
body.state-error .status { color: var(--danger); }

/* ------------------------------------------------------------------- DOCK -- */
.dock {
  display: flex; align-items: center; justify-content: center;
  gap: clamp(18px, 8vw, 46px);
  padding-top: 8px;
}
.dock-btn {
  width: 52px; height: 52px; border-radius: 18px;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--stroke);
  color: #d6daf2;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: transform .18s ease, opacity .25s ease, background .25s ease, color .25s ease, border-color .25s ease;
}
.dock-btn:active:not(:disabled) { transform: scale(.9); }
.dock-btn:disabled { opacity: .32; cursor: not-allowed; }
.dock-btn .i-muted { display: none; }
.dock-btn[aria-pressed="true"] { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.dock-btn[aria-pressed="true"] .i-muted   { display: block; }
.dock-btn[aria-pressed="true"] .i-unmuted { display: none; }

.mic-btn {
  position: relative;
  width: 84px; height: 84px; border-radius: 50%;
  display: grid; place-items: center;
  color: #05070f;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1);
}
.mic-face {
  position: relative; z-index: 2;
  width: 100%; height: 100%; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(150deg, #ffffff 0%, color-mix(in srgb, var(--accent) 70%, #ffffff) 46%, var(--accent-2) 100%);
  box-shadow: 0 10px 34px color-mix(in srgb, var(--accent) 42%, transparent),
              inset 0 1px 0 rgba(255,255,255,.6);
  transition: background .6s ease, box-shadow .6s ease;
}
.mic-btn:active .mic-face { transform: scale(.93); }
.mic-btn .i-stop { display: none; }
.mic-btn.is-on .i-mic  { display: none; }
.mic-btn.is-on .i-stop { display: block; }

.mic-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--accent) 60%, transparent);
  opacity: 0; pointer-events: none;
}
.mic-btn.is-on .mic-ring   { animation: ripple 2.4s ease-out infinite; }
.mic-btn.is-on .mic-ring-2 { animation-delay: 1.2s; }
@keyframes ripple {
  0%   { transform: scale(1);    opacity: .55; }
  100% { transform: scale(1.95); opacity: 0; }
}

/* ----------------------------------------------------------------- DRAWER -- */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(2, 3, 8, .62);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .3s ease;
}
.scrim.show { opacity: 1; }

.drawer {
  position: fixed; z-index: 50;
  top: 0; bottom: 0; left: 0;
  width: min(88vw, 380px);
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px);
  display: flex; flex-direction: column; gap: 14px;
  background: linear-gradient(180deg, rgba(15,18,34,.97) 0%, rgba(7,9,18,.99) 100%);
  border-right: 1px solid var(--stroke);
  box-shadow: 24px 0 60px rgba(0,0,0,.55);
  transform: translateX(-104%);
  transition: transform .38s cubic-bezier(.22,1,.36,1);
  visibility: hidden;
}
.drawer.open { transform: translateX(0); visibility: visible; }

.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.drawer-head p { margin: 4px 0 0; font-size: .76rem; color: var(--muted); }

.primary-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 16px; border-radius: 15px;
  font-weight: 600; font-size: .9rem;
  color: #05070f;
  background: linear-gradient(135deg, #ffffff, var(--accent) 130%);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 32%, transparent);
  transition: transform .18s ease, filter .2s ease;
}
.primary-btn:active { transform: scale(.97); filter: brightness(1.08); }

.file-gallery {
  flex: 1; overflow-y: auto; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px; padding: 12px 2px; margin-right: -2px;
}
.file-gallery::-webkit-scrollbar { width: 4px; }
.file-gallery::-webkit-scrollbar-thumb { background: var(--stroke); border-radius: 4px; }

.file-item {
  position: relative; aspect-ratio: 1;
  border-radius: 12px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--stroke);
  transition: transform .2s ease, box-shadow .2s ease;
  animation: itemIn .3s ease both;
}
@keyframes itemIn { from { opacity: 0; transform: translateY(8px); } }
.file-item:active { transform: scale(.95); }
.file-item img { width: 100%; height: 100%; object-fit: cover; }

.file-del {
  position: absolute; top: 6px; right: 6px;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: grid; place-items: center; color: var(--fg);
  border: 1px solid rgba(255,255,255,0.2);
  transition: color .2s, background .2s;
}
.file-del:hover { color: var(--danger); background: rgba(0,0,0,0.8); }

.empty {
  margin: auto; text-align: center; color: var(--muted);
  font-size: .82rem; padding: 32px 20px; line-height: 1.7;
}
.empty svg { opacity: .35; margin-bottom: 10px; }

.drawer-foot { display: flex; gap: 8px; }
.ghost-btn {
  flex: 1; padding: 11px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--stroke);
  font-size: .8rem; color: #c9cde6;
  transition: background .2s, color .2s, border-color .2s;
}
.ghost-btn:hover { background: var(--surface-2); }
.ghost-btn.danger:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

/* ------------------------------------------------------------------- SHEET -- */
.sheet {
  position: fixed; z-index: 60;
  left: 0; right: 0; bottom: 0;
  max-height: 86dvh;
  padding: 8px 18px calc(var(--safe-b) + 20px);
  background: linear-gradient(180deg, rgba(18,21,40,.98), rgba(6,8,16,.99));
  border-top: 1px solid var(--stroke);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -20px 60px rgba(0,0,0,.6);
  transform: translateY(105%);
  transition: transform .4s cubic-bezier(.22,1,.36,1);
  visibility: hidden;
  display: flex; flex-direction: column;
}
.sheet.open { transform: translateY(0); visibility: visible; }
.sheet-grabber { width: 42px; height: 4px; border-radius: 4px; background: var(--stroke); margin: 6px auto 12px; flex: 0 0 auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-body { overflow-y: auto; padding-bottom: 6px; }

.field { margin: 18px 0; }
.field label { display: flex; justify-content: space-between; font-size: .82rem; color: #c6cae4; margin-bottom: 10px; }
.field label span { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 50%), rgba(255,255,255,.12) var(--fill, 50%));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 4px solid var(--accent);
  box-shadow: 0 3px 12px rgba(0,0,0,.5); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 4px solid var(--accent); cursor: pointer;
}

.switch-row { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid rgba(255,255,255,.06); cursor: pointer; }
.switch-row strong { display: block; font-size: .87rem; font-weight: 600; }
.switch-row small  { display: block; font-size: .72rem; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.switch-row > span:first-child { flex: 1; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.track { flex: 0 0 auto; width: 48px; height: 28px; border-radius: 20px; background: rgba(255,255,255,.13); border: 1px solid var(--stroke); position: relative; transition: background .25s ease; }
.thumb { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .25s cubic-bezier(.34,1.56,.64,1); box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.switch-row input:checked + .track { background: color-mix(in srgb, var(--accent) 75%, #000); }
.switch-row input:checked + .track .thumb { transform: translateX(20px); }

.about { margin-top: 20px; padding: 14px; border-radius: 15px; background: rgba(255,255,255,.03); border: 1px solid var(--stroke); }
.about p { display: flex; justify-content: space-between; gap: 12px; margin: 7px 0; font-size: .74rem; }
.about span { color: var(--muted); }
.about code { color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 62%; }

/* ------------------------------------------------------------------- TOAST -- */
.toast-wrap {
  position: fixed; z-index: 80;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 108px);
  width: min(92vw, 420px);
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 16px; border-radius: 14px;
  background: rgba(20, 24, 44, .95);
  border: 1px solid var(--stroke);
  box-shadow: 0 14px 40px rgba(0,0,0,.5);
  font-size: .82rem; color: #e7eaff;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  animation: toastIn .32s cubic-bezier(.22,1,.36,1) both;
  display: flex; align-items: center; gap: 10px;
}
.toast.out { animation: toastOut .28s ease forwards; }
.toast::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; box-shadow: 0 0 10px var(--glow); }
.toast.err::before { background: var(--danger); box-shadow: 0 0 10px rgba(255,107,125,.6); }
.toast.ok::before  { background: #22e08a; box-shadow: 0 0 10px rgba(34,224,138,.6); }
@keyframes toastIn  { from { opacity: 0; transform: translateY(18px) scale(.96); } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(-8px) scale(.97); } }

/* ------- CONFIRM DIALOG (substitui window.confirm) FIX v2 --------------- */
.confirm-overlay {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  background: rgba(2, 3, 8, .72);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fadeIn .22s ease both;
}
.confirm-overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }
.confirm-box {
  width: min(88vw, 360px);
  padding: 24px 22px 18px;
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(22,26,50,.98), rgba(8,10,20,.99));
  border: 1px solid var(--stroke);
  box-shadow: 0 24px 60px rgba(0,0,0,.7);
  animation: slideUp .28s cubic-bezier(.22,1,.36,1) both;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } }
.confirm-msg {
  margin: 0 0 18px;
  font-size: .92rem; color: #dde2ff; line-height: 1.5;
  font-family: var(--font-display);
}
.confirm-actions {
  display: flex; gap: 10px;
}
.confirm-actions .ghost-btn {
  flex: 1; padding: 12px; font-size: .86rem;
}

/* --------------------------------------------------------------- RESPONSIVE -- */
@media (min-width: 720px) {
  .app { max-width: 860px; }
  .mic-btn { width: 96px; height: 96px; }
  .dock-btn { width: 56px; height: 56px; }
}
@media (max-height: 620px) {
  .orb-shell { width: clamp(160px, 42vmin, 240px); }
  .readout { gap: 4px; }
  .sub-status { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .orb, .ring, .spinner, .bg-blob, .core-inner, .brand-dot { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
  * { transition-duration: .08s !important; }
}
