/* ===== App Layout ===== */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 var(--space-lg);
  z-index: 100;
  background: transparent;
}

.app-main {
  position: relative;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100dvh;
  padding: var(--header-height) var(--space-lg) var(--space-xl);
}

/* ===== Screen System ===== */

.screen {
  display: none;
  flex-direction: column;
  width: 100%;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity var(--transition-normal), transform var(--transition-normal);
}

.screen.active {
  display: flex;
  opacity: 1;
  transform: translateX(0);
}

/* ===== Welcome Screen ===== */

.screen--welcome {
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - var(--header-height) - var(--space-xl));
  text-align: center;
  gap: var(--space-lg);
}

.welcome__illustration {
  width: 180px;
  height: 180px;
  margin-bottom: var(--space-md);
}

.welcome__title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
}

.welcome__subtitle {
  max-width: 320px;
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  line-height: var(--leading-relaxed);
}

.welcome__disclaimer {
  margin-top: auto;
  padding-top: var(--space-2xl);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  max-width: 300px;
  line-height: var(--leading-relaxed);
}

/* ===== Capture Screen ===== */

.screen--capture {
  gap: var(--space-lg);
  padding-top: var(--space-md);
}

.capture__cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* ===== Camera View ===== */

.camera-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  display: none;
  flex-direction: column;
}

.camera-view.active {
  display: flex;
}

.camera-view__video {
  flex: 1;
  width: 100%;
  object-fit: cover;
  transition: clip-path 180ms ease;
}

/* Mirror front-camera preview like a selfie camera */
.camera-view__video--mirror {
  transform: scaleX(-1);
}

.camera-view__burst,
.camera-view__glow {
  display: none;
}

/* --- Flash mode (Telegram-style) ---
 * The outside area is NOT white paint — it's the same video blurred out
 * via backdrop-filter, lightly brightened and warm-tinted. A soft warm
 * halo ring enhances the edge of the circle.
 *
 * Layer stack (bottom to top):
 *   - video (full-screen, z:auto)
 *   - glow element: backdrop-filter blur + warm tint over everything
 *     except a circular cutout in the middle (the "window")
 *   - burst element: soft warm halo ring hugging the circle edge
 *   - controls (z:40)
 */
.camera-view--flash-on .camera-view__guide {
  /* Dashed guide irrelevant — we have a circle now */
  display: none;
}

/* Blurred video backdrop outside the circle */
.camera-view--flash-on .camera-view__glow {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  /* Minimal brightening tint — the look should come from the blur, not paint */
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(34px) brightness(1.06) saturate(1.05);
  -webkit-backdrop-filter: blur(34px) brightness(1.06) saturate(1.05);
  /* Cut out a 42vmin-radius circle (~84% of shortest viewport dim)
     slightly above vertical center, matching Telegram's framing */
  -webkit-mask: radial-gradient(
    circle 42vmin at 50% 45%,
    transparent 92%,
    black 100%
  );
  mask: radial-gradient(
    circle 42vmin at 50% 45%,
    transparent 92%,
    black 100%
  );
}

/* Subtle white halo at the circle edge (the "shine") */
.camera-view--flash-on .camera-view__burst {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 16;
  pointer-events: none;
  background: radial-gradient(
    circle 55vmin at 50% 45%,
    rgba(255, 255, 255, 0) 64%,
    rgba(255, 255, 255, 0.45) 72%,
    rgba(255, 255, 255, 0.18) 80%,
    rgba(255, 255, 255, 0) 92%
  );
  filter: blur(8px);
}

/* Controls above the halo */
.camera-view__controls {
  z-index: 40;
}

.camera-view--flash-on .camera-view__controls {
  background: transparent;
}

.camera-view--flash-on .camera-view__cancel-btn,
.camera-view--flash-on .camera-view__flip-btn,
.camera-view--flash-on .camera-view__flash-btn {
  background: rgba(0,0,0,0.12);
  color: #333;
}

.camera-view--flash-on .camera-view__flash-btn--on {
  background: #1a1a1a;
  color: #ffd84d;
}

.camera-view--flash-on .camera-view__capture-btn {
  background: #1a1a1a;
  border-color: rgba(0,0,0,0.2);
}

.camera-view__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.camera-view__guide {
  width: 70%;
  max-width: 300px;
  aspect-ratio: 1.5;
  border: 3px dashed rgba(255, 255, 255, 0.6);
  border-radius: 50%;
}

.camera-view__controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  /* Bottom-align so capture/flip sit level with cancel (flash floats above cancel) */
  align-items: end;
  justify-items: center;
  gap: var(--space-lg);
  padding: var(--space-xl) var(--space-lg);
  padding-bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  z-index: 40;  /* above glow and burst */
}

/* Left cluster: flash stacked on top of cancel */
.camera-view__cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

.camera-view__flash-btn--on {
  background: #ffd84d;  /* warm yellow when on */
  color: #1a1a1a;
}

.camera-view__capture-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid rgba(255,255,255,0.5);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 100ms ease;
}

.camera-view__capture-btn:active {
  transform: scale(0.9);
}

.camera-view__cancel-btn,
.camera-view__flip-btn,
.camera-view__flash-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 150ms ease, color 150ms ease, transform 100ms ease;
}

.camera-view__flash-btn:active,
.camera-view__cancel-btn:active,
.camera-view__flip-btn:active {
  transform: scale(0.92);
}

/* SVG children shouldn't intercept clicks; the button should be the target */
.camera-view__controls button svg {
  pointer-events: none;
}

/* ===== Preview Screen ===== */

.screen--preview {
  gap: var(--space-lg);
  padding-top: var(--space-md);
}

.preview__actions {
  display: flex;
  gap: var(--space-md);
}

.preview__actions .btn {
  flex: 1;
}

/* ===== Analyzing Screen ===== */

.screen--analyzing {
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - var(--header-height) - var(--space-xl));
  gap: var(--space-xl);
  text-align: center;
}

.analyzing__thumbnail {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--color-surface);
  box-shadow: var(--shadow-sm);
}

/* ===== Results Screen ===== */

.screen--results {
  gap: var(--space-lg);
  padding-top: var(--space-md);
  align-items: center;
}

.results__value {
  text-align: center;
  padding: var(--space-lg) 0;
}

.results__number {
  font-size: var(--text-hero);
  font-weight: var(--weight-bold);
  line-height: 1;
  transition: color var(--transition-normal);
}

.results__unit {
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  font-weight: var(--weight-medium);
  margin-left: var(--space-xs);
}

.results__explanation {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  width: 100%;
  box-shadow: var(--shadow-sm);
}

.results__explanation p {
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}

.results__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: 100%;
  padding-top: var(--space-md);
}

/* ===== Demo Mode Banner ===== */

.demo-banner {
  background: var(--color-mild-bg);
  border: 1px solid var(--color-mild);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-xs);
  color: var(--color-mild);
  text-align: center;
  font-weight: var(--weight-medium);
  width: 100%;
}

/* ===== Responsive ===== */

@media (min-width: 480px) {
  .app-main {
    padding-left: var(--space-xl);
    padding-right: var(--space-xl);
  }

  .welcome__illustration {
    width: 220px;
    height: 220px;
  }
}

@media (min-width: 768px) {
  .app-main {
    padding-top: calc(var(--header-height) + var(--space-lg));
  }

  .preview__actions {
    max-width: 400px;
    margin: 0 auto;
  }

  .results__actions {
    max-width: 400px;
  }
}

/* ===== Reduced Motion ===== */

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