* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  background: #000;
  color: #00d9ff;
  -webkit-font-smoothing: antialiased;
}

:root {
  --gold: #ffb344;
  --red: #cf2030;
  --cyan: #00d9ff;
  --cyan-bright: #5cf2ff;
  --orange: #ff6b35;
  --green: #00ff88;
  --purple: #b980ff;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, rgba(0, 217, 255, 0.05) 0%, rgba(0,0,0,1) 70%),
    #000005;
}

/* === Grid background === */
#app::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 217, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 217, 255, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* === Scan line === */
#app::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    transparent 0%,
    rgba(0, 217, 255, 0.04) 50%,
    transparent 100%);
  background-size: 100% 6px;
  pointer-events: none;
  z-index: 1;
  animation: scanlines 6s linear infinite;
}

@keyframes scanlines {
  0% { background-position: 0 0; }
  100% { background-position: 0 100%; }
}

/* === HUD targeting corners === */
.hud-corner {
  position: absolute;
  width: 40px;
  height: 40px;
  border: 2px solid var(--gold);
  z-index: 4;
  opacity: 0.7;
  filter: drop-shadow(0 0 4px var(--gold));
}
.hud-corner.tl { top: 14px; left: 14px; border-right: none; border-bottom: none; }
.hud-corner.tr { top: 14px; right: 14px; border-left: none; border-bottom: none; }
.hud-corner.bl { bottom: 14px; left: 14px; border-right: none; border-top: none; }
.hud-corner.br { bottom: 14px; right: 14px; border-left: none; border-top: none; }

/* === Top header === */
#label {
  position: fixed;
  top: 30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 8px;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 179, 68, 0.6);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
}

#label::before, #label::after {
  content: '';
  width: 40px;
  height: 1px;
  background: var(--gold);
  box-shadow: 0 0 6px var(--gold);
}

#sysinfo {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: 3px;
  color: rgba(0, 217, 255, 0.5);
  z-index: 5;
  text-transform: uppercase;
}

/* === Iron Man Helmet === */
#helmet {
  position: absolute;
  width: 500px;
  height: 500px;
  z-index: 1;
  pointer-events: none;
  opacity: 0.45;
  transition: opacity 0.5s;
}

body.listening #helmet,
body.processing #helmet,
body.speaking #helmet { opacity: 0.65; }

#helmet svg { width: 100%; height: 100%; }

.helmet-outline {
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.5;
  stroke-linejoin: miter;
  filter: drop-shadow(0 0 4px rgba(255, 179, 68, 0.5));
}

.eye {
  fill: var(--cyan);
  stroke: var(--cyan-bright);
  stroke-width: 1;
  filter: drop-shadow(0 0 8px var(--cyan));
  opacity: 0.85;
  animation: eye-glow 3s ease-in-out infinite;
}

body.listening .eye { fill: var(--orange); stroke: var(--orange); filter: drop-shadow(0 0 10px var(--orange)); }
body.processing .eye { fill: var(--purple); stroke: var(--purple); filter: drop-shadow(0 0 10px var(--purple)); }
body.speaking .eye { fill: var(--green); stroke: var(--green); filter: drop-shadow(0 0 10px var(--green)); }

@keyframes eye-glow {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.helmet-mouth line {
  stroke: var(--gold);
  stroke-width: 1.5;
  opacity: 0.7;
  filter: drop-shadow(0 0 2px var(--gold));
}

.forehead-jewel {
  fill: var(--cyan);
  stroke: var(--cyan-bright);
  stroke-width: 1;
  filter: drop-shadow(0 0 6px var(--cyan));
  animation: jewel-pulse 2s ease-in-out infinite;
}

@keyframes jewel-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.helmet-accent {
  stroke: var(--gold);
  stroke-width: 1;
  opacity: 0.6;
}

/* === Arc Reactor === */
#arc-reactor {
  position: absolute;
  width: 280px;
  height: 280px;
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 0 20px var(--cyan));
}

#arc-reactor svg { width: 100%; height: 100%; }

.reactor-outer, .reactor-mid, .reactor-inner {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 1;
  opacity: 0.4;
}

.reactor-outer {
  animation: rotate 30s linear infinite;
  transform-origin: center;
  stroke-dasharray: 8 4;
}

.reactor-mid {
  animation: rotate 20s linear infinite reverse;
  transform-origin: center;
  stroke-dasharray: 4 2;
}

.reactor-inner {
  stroke-width: 2;
  opacity: 0.6;
  animation: pulse-ring 3s ease-in-out infinite;
}

.reactor-core {
  fill: var(--cyan-bright);
  stroke: white;
  stroke-width: 0.5;
  filter: drop-shadow(0 0 15px var(--cyan-bright));
  animation: core-pulse 2s ease-in-out infinite;
}

body.listening .reactor-core { fill: var(--orange); filter: drop-shadow(0 0 15px var(--orange)); }
body.processing .reactor-core { fill: var(--purple); filter: drop-shadow(0 0 15px var(--purple)); }
body.speaking .reactor-core { fill: var(--green); filter: drop-shadow(0 0 15px var(--green)); }

.reactor-segments line {
  stroke: var(--cyan);
  stroke-width: 1.5;
  opacity: 0.6;
  filter: drop-shadow(0 0 3px var(--cyan));
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulse-ring {
  0%, 100% { opacity: 0.4; transform: scale(1); transform-origin: center; }
  50% { opacity: 0.8; transform: scale(1.05); transform-origin: center; }
}

@keyframes core-pulse {
  0%, 100% { opacity: 0.85; r: 20; }
  50% { opacity: 1; r: 22; }
}

/* === Background glow === */
#glow {
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.3;
  transition: background 0.8s ease;
  pointer-events: none;
  z-index: 0;
  background: var(--cyan);
}

body.listening #glow { background: var(--orange); }
body.processing #glow { background: var(--purple); }
body.speaking #glow { background: var(--green); }
body.error #glow { background: var(--red); }

/* === Waveform === */
#wave-container {
  position: absolute;
  bottom: 18%;
  width: 100%;
  max-width: 380px;
  height: 70px;
  z-index: 3;
}

#waveform { width: 100%; height: 100%; }

/* === Side panels === */
.side-panel {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 130px;
  z-index: 5;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: rgba(0, 217, 255, 0.7);
  text-transform: uppercase;
  border: 1px solid rgba(0, 217, 255, 0.3);
  padding: 10px;
  background: rgba(0, 30, 50, 0.4);
  backdrop-filter: blur(8px);
}

.side-panel.left { left: 30px; border-left: 3px solid var(--gold); }
.side-panel.right { right: 30px; border-right: 3px solid var(--gold); text-align: right; }

.panel-header {
  font-size: 11px;
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 0 4px var(--gold);
  margin-bottom: 8px;
  letter-spacing: 4px;
  border-bottom: 1px solid rgba(255, 179, 68, 0.3);
  padding-bottom: 4px;
}

.panel-data > div { margin: 4px 0; line-height: 1.6; }

.bar {
  width: 100%;
  height: 4px;
  background: rgba(0, 217, 255, 0.15);
  margin: 2px 0 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--cyan-bright));
  box-shadow: 0 0 6px var(--cyan);
  animation: bar-flicker 4s ease-in-out infinite;
}

@keyframes bar-flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.status-line {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(0, 217, 255, 0.2);
  color: var(--cyan-bright);
  font-weight: 700;
}

/* === Status === */
#status {
  position: absolute;
  bottom: 28%;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--cyan);
  z-index: 5;
  text-shadow: 0 0 12px var(--cyan);
  display: flex;
  align-items: center;
  gap: 10px;
}

#status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
  animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

body.listening #status { color: var(--orange); text-shadow: 0 0 12px var(--orange); }
body.processing #status { color: var(--purple); text-shadow: 0 0 12px var(--purple); }
body.speaking #status { color: var(--green); text-shadow: 0 0 12px var(--green); }
body.error #status { color: var(--red); text-shadow: 0 0 12px var(--red); }

/* === Transcript === */
#transcript {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: var(--cyan-bright);
  background: rgba(0, 30, 50, 0.85);
  backdrop-filter: blur(20px);
  padding: 10px 22px;
  max-width: 80%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid var(--cyan);
  border-left: 4px solid var(--gold);
  transition: opacity 0.3s ease;
  z-index: 10;
  text-shadow: 0 0 6px rgba(92, 242, 255, 0.5);
  box-shadow: 0 0 20px rgba(0, 217, 255, 0.2);
}

#transcript.hidden { opacity: 0; pointer-events: none; }
#transcript.visible { opacity: 1; }

#transcript::before {
  content: '> ';
  color: var(--gold);
  font-weight: bold;
}

/* === Bottom info === */
#bottom-info {
  position: fixed;
  bottom: 22px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 70px;
  font-size: 9px;
  letter-spacing: 2px;
  color: rgba(255, 179, 68, 0.5);
  text-transform: uppercase;
  z-index: 5;
}

.dot-pulse {
  color: var(--red);
  text-shadow: 0 0 6px var(--red);
  animation: blink 1.5s ease-in-out infinite;
}

/* === Botão Tap to Talk === */
#btn-talk {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--red));
  border: 3px solid var(--gold);
  color: #000;
  font-size: 28px;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 0 30px rgba(255, 179, 68, 0.6);
  transition: all 0.2s;
  font-family: inherit;
}

#btn-talk:hover {
  transform: translateX(-50%) scale(1.1);
  box-shadow: 0 0 40px rgba(255, 179, 68, 0.9);
}

#btn-talk:active { transform: translateX(-50%) scale(0.95); }

#btn-talk.active {
  background: linear-gradient(135deg, #00ff88, #00d9ff);
  border-color: #00ff88;
  animation: btn-pulse 0.8s ease-in-out infinite;
}

@keyframes btn-pulse {
  0%, 100% { box-shadow: 0 0 30px rgba(0,255,136,0.6); }
  50% { box-shadow: 0 0 60px rgba(0,255,136,1); }
}

/* === Erros visíveis === */
#error-msg {
  position: fixed;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(207,32,48,0.95);
  color: #fff;
  padding: 10px 20px;
  border: 1px solid #cf2030;
  font-size: 12px;
  z-index: 30;
  letter-spacing: 1px;
  max-width: 80%;
  text-align: center;
}

/* === MOBILE / TABLET === */
@media (max-width: 768px) {
  #helmet { width: 90vw; height: 90vw; max-width: 400px; max-height: 400px; }
  #arc-reactor { width: 60vw; height: 60vw; max-width: 240px; max-height: 240px; }
  #wave-container { max-width: 90vw; height: 60px; bottom: 25%; }

  /* Esconder painéis laterais em mobile */
  .side-panel { display: none; }

  #status { font-size: 12px; bottom: 32%; letter-spacing: 4px; }
  #label { font-size: 11px; letter-spacing: 4px; }
  #label::before, #label::after { width: 20px; }
  #sysinfo { font-size: 8px; letter-spacing: 2px; }

  .hud-corner { width: 25px; height: 25px; }

  #transcript {
    bottom: 80px;
    font-size: 12px;
    max-width: 95%;
    padding: 8px 16px;
  }

  #bottom-info {
    bottom: 30px;
    padding: 0 30px;
    font-size: 8px;
  }

  /* Big tap-to-talk overlay para mobile */
  body.mobile-tap-mode #app::before {
    background-size: 50px 50px;
  }
}

/* iOS safe area */
@supports (padding: max(0px)) {
  #label { top: max(30px, env(safe-area-inset-top)); }
  #bottom-info { bottom: max(20px, env(safe-area-inset-bottom)); }
  .hud-corner.tl { top: max(14px, env(safe-area-inset-top)); }
  .hud-corner.tr { top: max(14px, env(safe-area-inset-top)); }
  .hud-corner.bl { bottom: max(14px, env(safe-area-inset-bottom)); }
  .hud-corner.br { bottom: max(14px, env(safe-area-inset-bottom)); }
}

/* Botão tap-to-talk para iOS (Safari não permite mic sem gesto) */
#tap-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  cursor: pointer;
}
#tap-overlay.show { display: flex; }
#tap-overlay button {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffb344, #cf2030);
  border: 4px solid #ffb344;
  color: #000;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 4px;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 0 60px rgba(255, 179, 68, 0.8);
  animation: pulse-btn 2s ease-in-out infinite;
}
@keyframes pulse-btn {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
#tap-overlay p {
  color: #ffb344;
  margin-top: 30px;
  letter-spacing: 3px;
  font-size: 13px;
}
