:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #f0f4f8;
  --muted: #94a3b8;
  --accent: #c9a227;
  --accent-dim: #8b6914;
  --danger: #f87171;
  --radius: 12px;
  --app-vh: 100vh;
  --video-w: 480;
  --video-h: 854;
  /* poster.jpg — keep subject in frame when cropping */
  --poster-w: 1376;
  --poster-subject-left: 945;
  --poster-subject-x: calc(
    (var(--poster-subject-left) + min(var(--poster-subject-left), var(--poster-w))) / 2 /
      var(--poster-w) * 100%
  );
}

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

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-error {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: rgba(0, 0, 0, 0.9);
  color: var(--danger);
  text-align: center;
}

.app-error:not([hidden]) {
  display: flex;
}

.site-logo {
  position: fixed;
  top: max(1.5rem, env(safe-area-inset-top));
  left: max(1.5rem, env(safe-area-inset-left));
  right: auto;
  z-index: 60;
  display: block;
  width: 100%;
  max-width: 50px;
  height: auto;
  pointer-events: none;
}

/* Start screen — fullscreen poster */
.start-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  overflow: hidden;
  transition: opacity 0.35s ease;
}

.start-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.start-screen__poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--poster-subject-x) center;
}

.start-screen__overlay {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: max(2.5rem, env(safe-area-inset-top)) max(1.5rem, env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom)) max(1.5rem, env(safe-area-inset-left));
  text-align: center;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.45) 0%,
    rgba(0, 0, 0, 0) 28%,
    rgba(0, 0, 0, 0) 62%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

.start-screen__branding {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.start-screen__title {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: clamp(2.5rem, 8vw, 3.5rem);
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
}

.start-screen__subtitle {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: clamp(1rem, 3.5vw, 1.35rem);
  font-weight: 400;
  color: #fff;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.45);
}

.start-screen__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: min(280px, 80vw);
}

.start-screen__progress {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}

.start-screen__progress-bar {
  width: 0%;
  height: 100%;
  background: #fff;
  border-radius: 999px;
  transition: width 0.2s ease;
}

.start-screen .btn--primary {
  width: 100%;
  background: #fff;
  color: #0f1419;
  border: none;
}

.start-screen .btn--primary:hover:not(:disabled) {
  background: #f0f4f8;
}

.start-screen .btn--primary:disabled {
  background: rgba(255, 255, 255, 0.55);
  color: rgba(15, 20, 25, 0.7);
}

@media (orientation: landscape) {
  .start-screen__overlay {
    align-items: flex-start;
    padding-left: 15%;
    text-align: left;
  }

  .start-screen__branding,
  .start-screen__actions {
    align-items: flex-start;
  }
}

.btn--primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* Main layout — mobile first */
.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: 0.75rem 1rem max(1.5rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

.app__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding-bottom: 0.5rem;
}

.app__title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
}

/* Video stage — exact 480×854; scales proportionally, no letterboxing */
.video-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  aspect-ratio: 480 / 854;
  height: 100%;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  margin-inline: auto;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
}

.video-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  z-index: 0;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.wake-hint {
  position: absolute;
  bottom: 4rem;
  left: 0;
  right: 0;
  text-align: center;
  padding: 0 1rem;
  z-index: 5;
  pointer-events: none;
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  margin: 0 auto;
  width: fit-content;
  max-width: 90%;
  padding: 0.4rem 1rem;
  border-radius: 4px;
}

.status-pill {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: var(--muted);
  white-space: nowrap;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill[data-state="listening"] {
  color: #86efac;
}

.status-pill[data-state="thinking"] {
  color: #fcd34d;
}

.status-pill[data-state="awaiting_wake"],
.status-pill[data-state="awaiting_question"] {
  color: #93c5fd;
}

.status-pill[data-state="speaking"] {
  color: var(--accent);
}

/* Controls */
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.mic-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
}

.mic-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.mic-btn .icon-stop {
  display: none;
}

.mic-btn.recording {
  background: #b91c1c;
  border-color: #f87171;
  color: #fff;
}

.mic-btn.recording .icon-mic {
  display: none;
}

.mic-btn.recording .icon-stop {
  display: block;
}

.mic-btn.pulsing::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: mic-ripple 1.4s ease-out infinite;
  pointer-events: none;
}

.mic-btn.pulsing::after {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0.45;
  animation: mic-ripple 1.4s ease-out 0.55s infinite;
  pointer-events: none;
}

.mic-btn.recording::before,
.mic-btn.recording::after {
  animation: none;
  border-color: #f87171;
}

.mic-btn--disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@keyframes mic-ripple {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

.text-form {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.text-input {
  flex: 1;
  padding: 0.6rem 0.85rem;
  border: 1px solid #334155;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

.text-input:focus {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
}

.transcript {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
  min-height: 1.25rem;
  text-align: center;
}

.speech-notice {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
  padding: 0 0.5rem;
}

.stt-banner {
  margin-top: 0.5rem;
  padding: 0.65rem 0.85rem;
  font-size: 0.8rem;
  color: #fecaca;
  background: rgba(127, 29, 29, 0.35);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: var(--radius);
  line-height: 1.45;
}

.stt-banner pre {
  margin-top: 0.5rem;
  font-size: 0.65rem;
  overflow: auto;
  max-height: 40vh;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  padding: 0.75rem 1.5rem;
}

.btn--primary {
  background: var(--accent);
  color: #1a1200;
}

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid #334155;
  padding: 0.6rem 1rem;
}

.btn--ghost {
  background: transparent;
  color: var(--muted);
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.btn--ghost:hover {
  color: var(--text);
}

/* Desktop — centered column */
@media (min-width: 600px) {
  .app {
    max-width: 28rem;
    padding: 1rem 1.5rem 2rem;
  }

  .video-stage {
    flex: 0 1 auto;
    width: min(100%, calc(70dvh * var(--video-w) / var(--video-h)));
    max-height: 70dvh;
  }

  .controls {
    max-width: min(100%, calc(70dvh * var(--video-w) / var(--video-h)));
    margin-left: auto;
    margin-right: auto;
    width: 100%;
  }
}
