* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  --bg: #07090f;
  --photo: #1565c0;
  --photo-deep: #0d47a1;
  --photo-ink: #ffffff;
  --video: #ffca28;
  --video-deep: #ffb300;
  --video-ink: #1a1200;
  --focus: #ff6d00;
  --surface: #121826;
  --surface-border: rgba(255, 255, 255, 0.16);
  --shadow: 0 18px 48px rgb(0 0 0 / 55%);
  --radius-card: clamp(1.25rem, 4vw, 1.85rem);
  --radius-control: 0.9rem;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  color: #fff;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: max(clamp(0.65rem, 2.4vw, 1rem), env(safe-area-inset-top, 0px));
  padding-right: max(clamp(0.65rem, 2.4vw, 1rem), env(safe-area-inset-right, 0px));
  padding-bottom: max(clamp(0.65rem, 2.4vw, 1rem), env(safe-area-inset-bottom, 0px));
  padding-left: max(clamp(0.65rem, 2.4vw, 1rem), env(safe-area-inset-left, 0px));
  background:
    radial-gradient(120% 70% at 50% -10%, rgb(21 101 192 / 28%), transparent 55%),
    radial-gradient(90% 55% at 80% 110%, rgb(255 202 40 / 18%), transparent 50%),
    var(--bg);
}

.action-container {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: calc(100vh - 2 * clamp(0.65rem, 2.4vw, 1rem));
  min-height: calc(100dvh - 2 * clamp(0.65rem, 2.4vw, 1rem));
  flex-direction: column;
  gap: clamp(0.65rem, 2vw, 1rem);
}

.action {
  position: relative;
  display: flex;
  flex: 1 0 0;
  min-height: min(42vh, 22rem);
  width: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.55rem, 2vh, 1rem);
  padding: clamp(1.25rem, 5vw, 2.4rem);
  border: 1px solid transparent;
  border-radius: var(--radius-card);
  cursor: pointer;
  text-align: center;
  overflow: hidden;
  isolation: isolate;
  box-shadow: var(--shadow);
  transition:
    transform 140ms ease,
    filter 140ms ease,
    box-shadow 140ms ease;
}

.action__glow {
  position: absolute;
  inset: -20%;
  z-index: -1;
  background: radial-gradient(circle at 50% 20%, rgb(255 255 255 / 22%), transparent 55%);
  opacity: 0.55;
  pointer-events: none;
}

.action:active {
  transform: scale(0.985);
  filter: brightness(1.08);
}

.action:disabled {
  cursor: progress;
  filter: saturate(0.7) brightness(0.92);
}

.action--photo {
  color: var(--photo-ink);
  background:
    linear-gradient(160deg, #1e88e5 0%, var(--photo) 42%, var(--photo-deep) 100%);
  border-color: rgb(255 255 255 / 14%);
}

.action--video {
  color: var(--video-ink);
  background:
    linear-gradient(160deg, #ffe082 0%, var(--video) 46%, var(--video-deep) 100%);
  border-color: rgb(0 0 0 / 10%);
}

.action__icon {
  display: grid;
  place-items: center;
  width: clamp(4.2rem, 16vw, 5.6rem);
  height: clamp(4.2rem, 16vw, 5.6rem);
  border-radius: 28%;
  background: rgb(255 255 255 / 14%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 25%);
  font-size: clamp(2rem, 7.5vw, 3rem);
  line-height: 1;
}

.action--video .action__icon {
  background: rgb(0 0 0 / 10%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 35%);
}

.action__title {
  font-size: clamp(2.2rem, 10vw, 3.6rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.action:focus-visible,
.control:focus-visible {
  position: relative;
  z-index: 12;
  outline: 5px solid var(--focus);
  outline-offset: 3px;
}

.preview {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: clamp(5.75rem, 22vmin, 9.25rem);
  aspect-ratio: 1;
  overflow: hidden;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #0b0f18;
  box-shadow:
    0 0 0 6px rgb(7 9 15 / 70%),
    0 10px 28px rgb(0 0 0 / 55%);
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition:
    top 160ms ease,
    width 160ms ease,
    border-radius 160ms ease,
    transform 160ms ease;
}

.preview__ring {
  position: absolute;
  inset: -7px;
  border: 2px solid rgb(255 202 40 / 70%);
  border-radius: inherit;
  pointer-events: none;
}

/* Foto capturada: bem maior, no topo, retângulo arredondado para leitura. */
.preview.is-captured {
  top: max(0.55rem, env(safe-area-inset-top, 0px) + 0.35rem);
  width: min(84vw, 22rem);
  aspect-ratio: 4 / 3;
  border-radius: 1.35rem;
  border-width: 3px;
  box-shadow:
    0 0 0 5px rgb(7 9 15 / 55%),
    0 14px 36px rgb(0 0 0 / 55%);
  transform: translateX(-50%);
}

.preview video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.status {
  position: fixed;
  z-index: 5;
  top: 50%;
  left: 50%;
  width: min(90vw, 34rem);
  padding: 1.15rem 1.35rem;
  border: 1px solid var(--surface-border);
  border-radius: 1.15rem;
  color: #fff;
  background: rgb(18 24 38 / 96%);
  backdrop-filter: blur(10px);
  font-size: clamp(1.15rem, 4.8vw, 1.7rem);
  font-weight: 800;
  line-height: 1.3;
  text-align: center;
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
}

.result {
  position: fixed;
  z-index: 8;
  top: max(0.45rem, env(safe-area-inset-top, 0px));
  bottom: max(0.45rem, env(safe-area-inset-bottom, 0px));
  left: 50%;
  display: flex;
  flex-direction: column;
  width: min(92vw, 40rem);
  max-height: none;
  overflow: hidden;
  padding: clamp(1rem, 3.5vw, 1.55rem);
  border: 1px solid var(--surface-border);
  border-radius: calc(var(--radius-card) + 0.15rem);
  color: #fff;
  background: linear-gradient(180deg, #182033 0%, #101826 100%);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  overscroll-behavior: contain;
  backdrop-filter: blur(12px);
}

.result h2 {
  flex-shrink: 0;
  margin: 0 0 0.65rem;
  font-size: clamp(1.35rem, 5.2vw, 1.9rem);
  font-weight: 850;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.result p {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: clamp(1.1rem, 4.6vw, 1.55rem);
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
  color: rgb(255 255 255 / 94%);
}

/* Botões da conclusão: coluna, largura total, texto grande (mobile). */
.result__controls {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  align-items: stretch;
  gap: 0.75rem;
  width: 100%;
  margin-top: 1rem;
}

.result__controls .control {
  width: 100%;
  min-height: 4.75rem;
  padding: 1.15rem 1.25rem;
  font-size: clamp(1.5rem, 6.2vw, 1.95rem);
  font-weight: 850;
  line-height: 1.2;
}

.control {
  min-height: 3.35rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-control);
  color: #fff;
  background: #243044;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: filter 120ms ease, transform 120ms ease;
}

.control:active {
  transform: scale(0.98);
  filter: brightness(1.08);
}

.control--primary {
  color: var(--video-ink);
  background: linear-gradient(180deg, #ffe082, var(--video));
  border-color: transparent;
}

.control--danger {
  color: #fff;
  background: linear-gradient(180deg, #ef5350 0%, #e53935 45%, #b71c1c 100%);
  border-color: transparent;
}

.control--danger:active {
  filter: brightness(1.06);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (max-height: 500px) and (orientation: landscape) {
  .app {
    padding: 0.45rem;
  }

  .action-container {
    flex-direction: row;
    gap: 0.55rem;
  }

  .action {
    min-height: calc(100dvh - 0.9rem);
    gap: 0.4rem;
    padding: 0.75rem;
  }

  .action__icon {
    width: 3.2rem;
    height: 3.2rem;
    font-size: 1.7rem;
  }

  .action__title {
    font-size: clamp(1.45rem, 5.5vw, 2.3rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}


/* FEATURE: VIDEO_UI desligado — botão permanece no HTML para reativação. */
.is-feature-off,
[hidden].is-feature-off {
  display: none !important;
}

.app--photo-only .action-container {
  gap: 0;
}

.app--photo-only .action--photo {
  flex: 1 1 auto;
  min-height: calc(100dvh - 2 * clamp(0.65rem, 2.4vw, 1rem));
}

@media (max-height: 500px) and (orientation: landscape) {
  .app--photo-only .action-container {
    flex-direction: column;
  }

  .app--photo-only .action--photo {
    min-height: calc(100dvh - 0.9rem);
  }
}


/* Ask mode after photo preview (no auto-analysis).
   Layout cabe no viewport: foto menor, mic flexível, «Nova foto» sempre visível. */
.app:has(#ask-panel:not([hidden])) .preview.is-captured {
  width: min(68vw, 15.5rem);
}

.ask-panel {
  position: relative;
  z-index: 1;
  display: flex;
  height: calc(100dvh - 2 * clamp(0.65rem, 2.4vw, 1rem));
  min-height: calc(100dvh - 2 * clamp(0.65rem, 2.4vw, 1rem));
  max-height: calc(100dvh - 2 * clamp(0.65rem, 2.4vw, 1rem));
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: clamp(0.55rem, 1.6vw, 0.9rem);
  box-sizing: border-box;
  overflow: hidden;
  /* espaço sob a foto (menor no ask) + safe-area no rodapé */
  padding-top: calc(min(68vw, 15.5rem) * 0.75 + 1rem);
  padding-bottom: max(0.35rem, env(safe-area-inset-bottom, 0px));
}

.action--ask {
  color: #fff;
  background:
    linear-gradient(160deg, #43a047 0%, #2e7d32 46%, #1b5e20 100%);
  border-color: rgb(255 255 255 / 14%);
  flex: 1 1 auto;
  min-height: 0;
}

.action--ask.is-recording {
  background:
    linear-gradient(160deg, #ef5350 0%, #e53935 46%, #b71c1c 100%);
  filter: brightness(1.05);
}

.action--ask.is-stopped {
  background:
    linear-gradient(160deg, #78909c 0%, #546e7a 46%, #37474f 100%);
  filter: brightness(1.02);
}

.action--ask .action__title {
  text-transform: none;
  letter-spacing: 0.02em;
}

.preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.control--secondary {
  flex-shrink: 0;
  align-self: stretch;
  width: 100%;
  min-width: 0;
  min-height: 5.5rem;
  margin-top: auto;
  padding: 1.25rem 1.15rem;
  color: #fff;
  background: #243044;
  font-size: clamp(1.35rem, 5.5vw, 1.75rem);
  font-weight: 850;
  line-height: 1.2;
}

.app--photo-only .ask-panel {
  gap: clamp(0.75rem, 2vw, 1.1rem);
}


/* Overlay bem visível enquanto STT+LLM+TTS processa. */
.busy-overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgb(7 9 15 / 72%);
  backdrop-filter: blur(8px);
}

.busy-overlay__card {
  display: flex;
  width: min(88vw, 22rem);
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  padding: 1.6rem 1.4rem 1.45rem;
  border: 1px solid var(--surface-border);
  border-radius: calc(var(--radius-card) + 0.1rem);
  background: linear-gradient(180deg, #1a2438 0%, #101826 100%);
  box-shadow: var(--shadow);
}

.busy-overlay__waves {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.45rem;
  height: 2.6rem;
}

.busy-overlay__waves span {
  display: block;
  width: 0.55rem;
  height: 0.7rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #64b5f6, #1565c0);
  animation: busy-wave 0.9s ease-in-out infinite;
}

.busy-overlay__waves span:nth-child(2) { animation-delay: 0.12s; }
.busy-overlay__waves span:nth-child(3) { animation-delay: 0.24s; }
.busy-overlay__waves span:nth-child(4) { animation-delay: 0.36s; }

.busy-overlay__text {
  margin: 0;
  color: #fff;
  font-size: clamp(1.35rem, 5.5vw, 1.85rem);
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: 0.02em;
  text-align: center;
}

@keyframes busy-wave {
  0%, 100% { height: 0.7rem; opacity: 0.55; }
  50% { height: 2.4rem; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .busy-overlay__waves span {
    animation: none;
    height: 1.4rem;
    opacity: 0.9;
  }
}


/* Perguntar de novo (mesma foto) — CTA na coluna de conclusão. */
.control--ask-again {
  color: #fff;
  background: linear-gradient(180deg, #66bb6a 0%, #43a047 45%, #2e7d32 100%);
  border-color: transparent;
}

.control--ask-again:active {
  filter: brightness(1.06);
}
