*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #ffffff;
  color: #222;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: #ffffff;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.stage {
  position: relative;
  width: min(100vw, 430px);
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: #ffffff;
  --scene-shift: 4.5dvh;
}

@media (min-width: 480px) {
  .stage {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    height: min(100dvh, 900px);
  }
}

.camera-preview {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  left: -9999px;
}

.greeting {
  position: absolute;
  top: 5%;
  left: 8%;
  right: 8%;
  z-index: 5;
  text-align: center;
  pointer-events: none;
}

.greeting[hidden] {
  display: none !important;
}

.greeting__title {
  margin: 0;
  font-size: clamp(1.25rem, 5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.greeting__name {
  margin: 0.35rem 0 0;
  font-size: clamp(1rem, 4vw, 1.35rem);
  font-weight: 500;
  opacity: 0.85;
}

.greeting__name:empty {
  display: none;
}

.prop {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7% 4% 4%;
  box-sizing: border-box;
  transform: translateY(var(--scene-shift, 0));
}

.prop[hidden] {
  display: none !important;
}

.candle-wrap {
  --candle-ar: 158 / 967;
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  height: 29.4%;
  width: auto;
  aspect-ratio: var(--candle-ar);
  margin-bottom: -7%;
  pointer-events: none;
}

.candle {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
}

.flame {
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 190%;
  max-height: min(11dvh, 80px);
  height: auto;
  transform: translateX(-50%) scale(var(--flame-scale, 1));
  transform-origin: center bottom;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 0 10px rgba(255, 160, 40, 0.55));
  user-select: none;
  -webkit-user-drag: none;
  z-index: 4;
  transition: filter 0.35s ease;
}

.flame--smoke {
  filter: drop-shadow(0 0 6px rgba(140, 140, 140, 0.35));
}

.cake-area {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  width: min(100%, 380px);
  height: 32%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.cake {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  user-select: none;
  -webkit-user-drag: none;
}

.blow-hint {
  position: absolute;
  top: calc(max(2.5%, env(safe-area-inset-top, 0px)) + var(--scene-shift, 0));
  left: 6%;
  right: 6%;
  z-index: 10;
  margin: 0;
  text-align: center;
  font-family: "Lobster", "Segoe Script", "Comic Sans MS", cursive;
  font-size: clamp(1.2rem, 5vw, 1.65rem);
  font-weight: 400;
  line-height: 1.2;
  color: #c45c7a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
  opacity: 0;
  transform: translateY(-10px);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
  pointer-events: none;
}

.blow-hint[hidden] {
  display: none !important;
}

.blow-hint--visible {
  opacity: 1;
  transform: translateY(0);
}

.wish-caption {
  flex: 0 0 auto;
  z-index: 5;
  margin: 0.85rem 0 0;
  max-width: 18rem;
  padding: 0 0.5rem;
  text-align: center;
  font-family: "Lobster", "Segoe Script", "Comic Sans MS", cursive;
  font-size: clamp(1.15rem, 4.6vw, 1.55rem);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0.01em;
  color: #c45c7a;
  text-wrap: balance;
}

/* --- Финал: фото + поздравление + шары --- */

.reveal {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: #111;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.reveal[hidden] {
  display: none !important;
}

.reveal--visible {
  opacity: 1;
}

.reveal__photo,
.reveal__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.reveal__video {
  /* селфи как в зеркале */
  transform: scaleX(-1);
  background: #111;
}

.reveal__title {
  position: absolute;
  left: 5%;
  right: 5%;
  top: 12%;
  z-index: 8;
  margin: 0;
  text-align: center;
  font-family: "Lobster", "Segoe Script", "Comic Sans MS", cursive;
  font-size: clamp(1.75rem, 8vw, 2.6rem);
  line-height: 1.15;
  color: #fff;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.25),
    0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.reveal-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 1rem 1.15rem calc(1.1rem + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s ease;
}

.reveal-actions[hidden] {
  display: none !important;
}

.reveal-actions--visible {
  opacity: 1;
  pointer-events: auto;
}

.reveal-actions__btn {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0.35rem;
  background: transparent;
  color: #fff;
  line-height: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.55));
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.reveal-actions__btn svg {
  display: block;
  width: 1.85rem;
  height: 1.85rem;
}

.reveal-actions__btn:active {
  transform: scale(0.92);
  opacity: 0.85;
}

.balloon-layer {
  position: absolute;
  inset: 0;
  z-index: 7;
  overflow: hidden;
  pointer-events: none;
}

.balloon {
  position: absolute;
  left: var(--balloon-left, 50%);
  bottom: -20%;
  width: var(--balloon-size, 64px);
  height: auto;
  margin-left: calc(var(--balloon-size, 64px) / -2);
  animation: balloon-rise var(--balloon-duration, 10s) linear var(--balloon-delay, 0s)
    infinite;
  will-change: transform;
}

.balloon svg {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2));
}

@keyframes balloon-rise {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 0;
  }
  8% {
    opacity: 1;
  }
  50% {
    transform: translate3d(var(--balloon-sway, 20px), -55vh, 0)
      rotate(var(--balloon-rot, 10deg));
  }
  92% {
    opacity: 1;
  }
  100% {
    transform: translate3d(calc(var(--balloon-sway, 20px) * -0.6), -120vh, 0)
      rotate(calc(var(--balloon-rot, 10deg) * -1));
    opacity: 0.85;
  }
}

.rotate-hint {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.85rem;
  z-index: 10;
  pointer-events: none;
}

@media (orientation: landscape) and (max-height: 500px) {
  .rotate-hint {
    display: block;
  }
}

.page--locked {
  visibility: hidden;
  pointer-events: none;
}

.media-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: #ffffff;
}

.media-gate[hidden] {
  display: none !important;
}

.media-gate__card {
  width: min(100%, 360px);
  text-align: center;
}

.media-gate__title {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
}

.media-gate__msg {
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
  line-height: 1.45;
  color: #444;
}

.media-gate__btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 0.85rem 1.25rem;
  min-width: 12rem;
  background: #1a1a1a;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.media-gate__btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.media-gate__btn:not(:disabled):hover {
  background: #333;
}

/* --- Шкала микрофона (калибровка) --- */

.mic-debug {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  padding: 0.45rem 0.55rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
  background: rgba(17, 24, 39, 0.94);
  color: #e5e7eb;
  font: 11px/1.3 ui-monospace, "Cascadia Code", Consolas, monospace;
  pointer-events: auto;
  max-height: 42vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.mic-debug[hidden] {
  display: none !important;
}

.mic-debug--blown .mic-debug__head strong::after {
  content: " · BLOWN";
  color: #f87171;
}

.mic-debug__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.85rem;
  margin-bottom: 0.35rem;
}

.mic-debug__head b {
  color: #34d399;
  font-weight: 700;
}

.mic-debug__peak b {
  color: #facc15;
  font-size: 1.15em;
}

.mic-debug__reset {
  margin-left: auto;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
}

.mic-debug__canvas {
  display: block;
  width: 100%;
  height: 96px;
  border-radius: 6px;
}

@media (min-width: 640px) {
  .mic-debug {
    font-size: 12px;
  }

  .mic-debug__canvas {
    height: 120px;
  }
}

.mic-debug__hint {
  margin: 0.35rem 0 0;
  opacity: 0.65;
  font-size: 11px;
}

.mic-debug__hint code {
  color: #93c5fd;
}
