:root {
  --bg: #0b0d10;
  --fg: #f2f4f7;
  --muted: #98a2b3;
  --surface: rgba(20, 24, 30, 0.72);
  --border: rgba(255, 255, 255, 0.14);
  --accent: #3b82f6;
  --danger: #f97066;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

/* A `display` rule on a class outranks the UA's [hidden] rule, so any element
   using the hidden attribute needs this to actually stay hidden. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.stage {
  position: relative;
  display: flex;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

video {
  width: 100%;
  height: 100dvh;
  object-fit: cover;
  background: #000;
  display: block;
}

/* Mirror the selfie view so it reads as a mirror, not a flipped photo. */
video.mirrored {
  transform: scaleX(-1);
}

.controls {
  position: absolute;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  padding: 10px;
  width: min(560px, calc(100% - 24px));
  justify-content: center;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.btn {
  flex: 1 1 0;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

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

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
  background: #2f6fd0;
}

.btn-ghost {
  flex: 0 0 auto;
  margin-top: 8px;
}

.error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  z-index: 3;
}

.error h1 {
  margin: 0;
  font-size: 20px;
  color: var(--danger);
}

.error p {
  margin: 0;
  max-width: 34ch;
  color: var(--muted);
  font-size: 14px;
}

.toast {
  position: absolute;
  left: 50%;
  top: calc(20px + env(safe-area-inset-top, 0px));
  transform: translate(-50%, -12px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 4;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}

.flash.fire {
  animation: flash 260ms ease-out;
}

@keyframes flash {
  0% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .toast {
    transition: none;
  }
  .flash.fire {
    animation: none;
  }
}
