/* ── Reset ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  width: 100%;
  height: 100%;
  height: -webkit-fill-available; /* Safari fix */
}

body {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: -webkit-fill-available; /* Safari fix */
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ── Screens ───────────────────────────────── */
/* Use opacity only for hide/show — NOT visibility:hidden
   because Safari won't decode video inside a visibility:hidden element */
.screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;

  /* Hidden: opacity 0 + pointer-events off, but NOT visibility:hidden */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  z-index: 2;
}

/* ── Height-fitted video ───────────────────── */
/* Always 100% height, auto width, black pillarbox sides */
.cover-video {
  position: absolute;
  top: 0;
  left: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  width: auto;
  height: 100%;
  max-width: 100%;
  object-fit: contain;
  object-position: center top;
  display: block;
  background: #000;
  /* Safari needs these */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* ── Idle screen ───────────────────────────── */
.idle-cta {
  position: absolute;
  bottom: 10vh;
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  z-index: 3;
  pointer-events: none;
}

.idle-cta p {
  font-size: clamp(1rem, 4vw, 1.5rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 2px 20px rgba(0,0,0,0.85);
}

.pulse-ring {
  width: 68px;
  height: 68px;
  border: 3px solid rgba(255,255,255,0.8);
  border-radius: 50%;
  animation: pulse 2.2s ease-out infinite;
}

@keyframes pulse {
  0%   { transform: scale(0.85); opacity: 1; }
  65%  { transform: scale(1.55); opacity: 0; }
  100% { transform: scale(0.85); opacity: 0; }
}

/* ── Mic listening badge ───────────────────── */
.mic-badge {
  position: absolute;
  top: max(28px, env(safe-area-inset-top, 28px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  font-size: 0.88rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.mic-dot {
  width: 9px; height: 9px;
  background: #f33;
  border-radius: 50%;
  flex-shrink: 0;
  animation: blink 1s step-start infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.hidden { display: none !important; }

/* ── Loading screen ────────────────────────── */
.loader-box {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.spinner {
  width: 52px; height: 52px;
  border: 4px solid rgba(255,255,255,0.12);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

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

.loader-box p {
  font-size: 1rem;
  opacity: 0.6;
  letter-spacing: 0.05em;
}

/* ── Avatar screen ─────────────────────────── */

/* Top gradient + controls */
.avatar-topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(20px, env(safe-area-inset-top, 20px)) 22px 24px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%, transparent 100%);
}

#avatar-status {
  font-size: 0.82rem;
  letter-spacing: 0.07em;
  opacity: 0.8;
}

#btn-end {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 9px 22px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.18s;
}
#btn-end:hover, #btn-end:active { background: rgba(255,255,255,0.28); }

/* Transcript */
.transcript {
  position: absolute;
  bottom: 90px;
  left: 5%; right: 5%;
  z-index: 5;
  background: rgba(0,0,0,0.68);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 14px 20px;
  border-radius: 14px;
  font-size: clamp(0.95rem, 3vw, 1.2rem);
  line-height: 1.55;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.1);
}

/* Voice bars */
.voice-bars {
  position: absolute;
  bottom: max(36px, env(safe-area-inset-bottom, 36px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 40px;
}

.voice-bars .bar {
  width: 5px;
  background: rgba(255,255,255,0.5);
  border-radius: 3px;
  height: 6px;
  transition: height 0.08s;
}

.voice-bars.active .bar {
  animation: dance 0.5s ease-in-out infinite alternate;
}
.voice-bars.active .bar:nth-child(1) { animation-delay: 0.00s; }
.voice-bars.active .bar:nth-child(2) { animation-delay: 0.10s; }
.voice-bars.active .bar:nth-child(3) { animation-delay: 0.20s; }
.voice-bars.active .bar:nth-child(4) { animation-delay: 0.10s; }
.voice-bars.active .bar:nth-child(5) { animation-delay: 0.00s; }

@keyframes dance {
  from { height: 6px; }
  to   { height: 36px; }
}

/* Error overlay */
.error-msg {
  position: absolute;
  bottom: 100px;
  left: 5%; right: 5%;
  z-index: 6;
  background: rgba(180,0,0,0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 14px 20px;
  border-radius: 14px;
  font-size: 0.95rem;
  text-align: center;
  line-height: 1.5;
}

/* ── Tap-to-unmute hint ────────────────────── */
.unmute-hint {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 12px 24px;
  border-radius: 999px;
  font-size: 1rem;
  white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.2);
  animation: fadeInUp 0.4s ease;
  pointer-events: none;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Focus ring for accessibility ──────────── */
button:focus-visible {
  outline: 2px solid rgba(255,255,255,0.7);
  outline-offset: 3px;
}
