:root {
  --bg: #070a10;
  --surface: #0e1420;
  --surface-2: #141d2e;
  --border: rgba(148, 163, 184, 0.16);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --cyan: #38bdf8;
  --violet: #a855f7;
  --green: #10b981;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --level: 0;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: radial-gradient(circle at 50% -10%, #111c33 0%, var(--bg) 68%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
}

/* HEADER */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 10, 16, 0.85);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 10px var(--amber);
  flex-shrink: 0;
}

.brand-dot.ready {
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}

.brand-dot.error {
  background: var(--rose);
  box-shadow: 0 0 10px var(--rose);
}

.brand-text h1 {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.brand-text p {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pill-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.12s, border-color 0.2s, background 0.2s;
}

.pill-btn:active {
  transform: scale(0.96);
}

.pill-btn.accent {
  border-color: rgba(56, 189, 248, 0.5);
  background: rgba(56, 189, 248, 0.14);
  color: var(--cyan);
}

.pill-btn.active {
  background: var(--cyan);
  color: #030712;
  border-color: var(--cyan);
}

.hidden {
  display: none !important;
}

/* TOOLBAR DE VOZ Y MICROFONO */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 20, 32, 0.72);
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.mic-chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.mic-chip.granted {
  border-color: rgba(16, 185, 129, 0.45);
  color: #6ee7b7;
}

.mic-chip.denied {
  border-color: rgba(244, 63, 94, 0.55);
  color: #fda4af;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

select.voice-select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  outline: none;
  max-width: 195px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--cyan);
  width: 15px;
  height: 15px;
}

/* MODO ORBE VOZ */
#orbView {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 18px;
  overflow-y: auto;
}

.orb-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  width: 100%;
  min-height: 280px;
}

.orb-button {
  position: relative;
  width: 184px;
  height: 184px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  touch-action: manipulation;
}

.orb-ring {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 2px solid rgba(56, 189, 248, 0.28);
  transform: scale(calc(1 + var(--level) * 0.28));
  transition: transform 0.08s linear, border-color 0.25s;
}

.orb-core {
  width: 156px;
  height: 156px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #7dd3fc 0%, #0284c7 46%, #4c1d95 100%);
  box-shadow: 0 0 38px rgba(56, 189, 248, 0.35), inset 0 0 24px rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.35rem;
  transform: scale(calc(1 + var(--level) * 0.14));
  transition: transform 0.08s linear, background 0.3s, box-shadow 0.3s;
}

.orb-button.state-listening .orb-core {
  background: radial-gradient(circle at 32% 30%, #6ee7b7 0%, #10b981 50%, #0369a1 100%);
  box-shadow: 0 0 46px rgba(16, 185, 129, 0.52), inset 0 0 26px rgba(255, 255, 255, 0.3);
}

.orb-button.state-listening .orb-ring {
  border-color: rgba(16, 185, 129, 0.7);
}

.orb-button.state-thinking .orb-core {
  background: radial-gradient(circle at 32% 30%, #e9d5ff 0%, #a855f7 52%, #1d4ed8 100%);
  box-shadow: 0 0 46px rgba(168, 85, 247, 0.55);
  animation: pulseSpin 1.3s ease-in-out infinite;
}

.orb-button.state-speaking .orb-core {
  background: radial-gradient(circle at 32% 30%, #bae6fd 0%, #38bdf8 50%, #6366f1 100%);
  box-shadow: 0 0 54px rgba(56, 189, 248, 0.65);
  animation: pulseSpeak 0.9s ease-in-out infinite alternate;
}

@keyframes pulseSpin {
  0%, 100% { transform: scale(0.96); }
  50% { transform: scale(1.06); }
}

@keyframes pulseSpeak {
  from { transform: scale(0.98); }
  to { transform: scale(1.09); }
}

.orb-status {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}

.orb-transcript-card {
  width: 100%;
  max-width: 580px;
  background: rgba(14, 20, 32, 0.85);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.orb-user-said {
  font-size: 0.85rem;
  color: var(--cyan);
}

.orb-ai-said {
  font-size: 0.96rem;
  line-height: 1.5;
  color: var(--text);
}

.orb-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.ptt-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 14px;
  padding: 12px 20px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

.ptt-btn.holding {
  background: var(--green);
  color: #030712;
  border-color: var(--green);
}

/* MODO CHAT HISTORIAL */
#chatView {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 88%;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.model {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 0.93rem;
  line-height: 1.48;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble {
  background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.model .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}

.speak-mini-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--cyan);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  cursor: pointer;
}

/* COMPOSER INFERIOR COMPARTIDO */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(7, 10, 16, 0.94);
  flex-shrink: 0;
}

.composer input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 0.93rem;
  outline: none;
}

.composer input:focus {
  border-color: var(--cyan);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.recording {
  background: var(--rose);
  border-color: var(--rose);
  color: #fff;
}

.icon-btn.send {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #030712;
  font-weight: 800;
}

/* BANNER PIN O TIP IOS */
.notice-bar {
  margin: 8px 16px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.35);
  font-size: 0.8rem;
  color: #bae6fd;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.notice-bar button {
  background: transparent;
  border: none;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}
