:root {
  --bg: #071127;
  --bg2: #14274a;
  --text: #eef5ff;
  --muted: #a9bad9;
  --line: rgba(130, 194, 255, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: radial-gradient(circle at 20% 12%, #1d3f75 0%, var(--bg) 44%),
    linear-gradient(160deg, #050b18 0%, var(--bg) 45%, var(--bg2) 100%);
  color: var(--text);
  font-family: "SF Pro Display", "PingFang SC", "Avenir Next", sans-serif;
  overflow: hidden;
}

body {
  min-height: 100dvh;
}

canvas {
  display: block;
}

#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 90;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transform: scale(1.02);
  transition: opacity 380ms ease, transform 380ms ease;
}

.screen.is-active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.cake-screen {
  z-index: 25;
  background: radial-gradient(circle at 50% 24%, rgba(58, 109, 181, 0.46), rgba(4, 8, 20, 0.78) 62%);
}

.cake-canvas {
  position: absolute;
  inset: 0;
}

.overlay {
  position: absolute;
  left: calc(env(safe-area-inset-left) + 12px);
  right: calc(env(safe-area-inset-right) + 12px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(7, 18, 40, 0.54);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 12px;
}

.overlay h1,
.overlay h2,
.overlay p {
  margin: 0;
}

.overlay-top {
  top: calc(env(safe-area-inset-top) + 10px);
}

.hero-overlay {
  animation: heroFloat 4.6s ease-in-out infinite;
}

.hero-overlay h1 {
  font-size: clamp(1.32rem, 5.8vw, 2.1rem);
  letter-spacing: 0.03em;
}

.subtitle {
  margin-top: 4px;
  color: #9ed3ff;
  font-size: clamp(0.86rem, 3.2vw, 1.02rem);
  letter-spacing: 0.14em;
}

.status {
  margin-top: 7px;
  color: #d4e8ff;
  font-size: 0.86rem;
  line-height: 1.4;
}

@keyframes heroFloat {
  0% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(0, -6px, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

.tiny-manual {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 12px);
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  height: 29px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 232, 192, 0.44);
  background: rgba(18, 22, 35, 0.56);
  color: #ffe9c0;
  font-size: 0.73rem;
  letter-spacing: 0.02em;
  z-index: 34;
  opacity: 0.8;
}

.tiny-manual:active {
  transform: scale(0.97);
}

.btn {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(12, 32, 67, 0.72);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 650;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(140deg, rgba(35, 191, 162, 0.93), rgba(32, 121, 205, 0.9));
  border-color: rgba(143, 247, 211, 0.5);
}

.gallery-screen {
  z-index: 30;
  background:
    radial-gradient(circle at 15% 10%, rgba(114, 86, 60, 0.42), transparent 30%),
    radial-gradient(circle at 86% 86%, rgba(36, 67, 105, 0.38), transparent 32%),
    linear-gradient(166deg, #130f10 0%, #201920 55%, #131425 100%);
}

.gallery-top {
  z-index: 35;
}

.overlay-bottom {
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.gallery-bottom {
  z-index: 35;
}

.photo-deck {
  position: absolute;
  left: 50%;
  top: 54%;
  width: min(92vw, 500px);
  aspect-ratio: 3 / 4;
  transform: translate(-50%, -50%);
  perspective: 1300px;
  transform-style: preserve-3d;
  user-select: none;
  touch-action: pan-y;
}

.photo-card {
  position: absolute;
  inset: 0;
  margin: 0;
  border-radius: 16px;
  border: 1px solid rgba(255, 240, 224, 0.32);
  overflow: hidden;
  background: #16151f;
  box-shadow: 0 26px 50px rgba(0, 0, 0, 0.45);
  transform-origin: center center;
  backface-visibility: hidden;
}

.photo-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.photo-card p {
  position: absolute;
  left: 10px;
  bottom: 8px;
  margin: 0;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 0.8rem;
}

.photo-card.current {
  z-index: 4;
  transform: translateX(0) rotateY(0deg) rotateZ(0deg) translateZ(0);
}

.photo-card.incoming {
  z-index: 3;
  transform: translateX(26%) rotateY(-40deg) rotateZ(4deg) translateZ(-90px) scale(0.94);
  opacity: 0.9;
}

.photo-deck.flip-next .photo-card.current {
  animation: oldAwayNext 740ms cubic-bezier(0.22, 0.73, 0.15, 1) forwards;
}

.photo-deck.flip-next .photo-card.incoming {
  animation: newInNext 740ms cubic-bezier(0.22, 0.73, 0.15, 1) forwards;
}

.photo-deck.flip-prev .photo-card.current {
  animation: oldAwayPrev 740ms cubic-bezier(0.22, 0.73, 0.15, 1) forwards;
}

.photo-deck.flip-prev .photo-card.incoming {
  animation: newInPrev 740ms cubic-bezier(0.22, 0.73, 0.15, 1) forwards;
}

@keyframes oldAwayNext {
  0% {
    transform: translateX(0) rotateY(0deg) rotateZ(0deg) translateZ(0);
    opacity: 1;
  }
  100% {
    transform: translateX(-42%) rotateY(64deg) rotateZ(-8deg) translateZ(-120px) scale(0.88);
    opacity: 0.18;
  }
}

@keyframes newInNext {
  0% {
    transform: translateX(26%) rotateY(-40deg) rotateZ(4deg) translateZ(-90px) scale(0.94);
    opacity: 0.9;
  }
  100% {
    transform: translateX(0) rotateY(0deg) rotateZ(0deg) translateZ(0) scale(1);
    opacity: 1;
  }
}

@keyframes oldAwayPrev {
  0% {
    transform: translateX(0) rotateY(0deg) rotateZ(0deg) translateZ(0);
    opacity: 1;
  }
  100% {
    transform: translateX(42%) rotateY(-64deg) rotateZ(8deg) translateZ(-120px) scale(0.88);
    opacity: 0.18;
  }
}

@keyframes newInPrev {
  0% {
    transform: translateX(-26%) rotateY(40deg) rotateZ(-4deg) translateZ(-90px) scale(0.94);
    opacity: 0.9;
  }
  100% {
    transform: translateX(0) rotateY(0deg) rotateZ(0deg) translateZ(0) scale(1);
    opacity: 1;
  }
}

.virtual-hand {
  position: absolute;
  width: 80px;
  height: 90px;
  right: -34px;
  top: 42%;
  border-radius: 22px 22px 22px 30px;
  background: linear-gradient(170deg, rgba(255, 225, 200, 0.45), rgba(245, 175, 144, 0.2));
  border: 1px solid rgba(255, 219, 196, 0.36);
  filter: blur(0.2px);
  opacity: 0;
  transform: rotate(-18deg) translate3d(0, 0, 0);
  pointer-events: none;
}

.virtual-hand::before,
.virtual-hand::after {
  content: "";
  position: absolute;
  background: inherit;
  border: 1px solid rgba(255, 219, 196, 0.3);
}

.virtual-hand::before {
  width: 26px;
  height: 52px;
  left: -16px;
  top: 24px;
  border-radius: 20px;
  transform: rotate(26deg);
}

.virtual-hand::after {
  width: 16px;
  height: 22px;
  left: 14px;
  top: -12px;
  border-radius: 10px;
  box-shadow: 17px 0 0 rgba(255, 225, 200, 0.26), 33px 0 0 rgba(255, 225, 200, 0.2);
}

.photo-deck.flip-next .virtual-hand {
  animation: handMoveNext 740ms ease forwards;
}

.photo-deck.flip-prev .virtual-hand {
  animation: handMovePrev 740ms ease forwards;
}

@keyframes handMoveNext {
  0% {
    opacity: 0;
    transform: rotate(-18deg) translate3d(34px, 12px, 0) scale(0.9);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: rotate(-8deg) translate3d(-180px, -20px, 0) scale(1.04);
  }
}

@keyframes handMovePrev {
  0% {
    opacity: 0;
    transform: rotate(18deg) translate3d(-34px, 12px, 0) scale(0.9);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: rotate(8deg) translate3d(180px, -20px, 0) scale(1.04);
  }
}

.photo-dots {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 78px);
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 36;
}

.photo-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(221, 229, 255, 0.3);
  transition: transform 180ms ease, background 180ms ease;
}

.photo-dots span.active {
  transform: scale(1.3);
  background: #fff;
}

.camera-layer {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 10px);
  bottom: calc(env(safe-area-inset-bottom) + 124px);
  width: 108px;
  height: 148px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(168, 224, 255, 0.45);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  z-index: 36;
  opacity: 0;
  pointer-events: none;
}

body.camera-on .camera-layer {
  opacity: 0.86;
}

#cameraFeed {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.hand-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(125, 255, 212, 0.9);
  box-shadow: 0 0 10px rgba(125, 255, 212, 0.8);
  background: rgba(125, 255, 212, 0.18);
  transform: translate3d(-999px, -999px, 0);
  pointer-events: none;
  z-index: 37;
}

body.low-performance .overlay {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

@media (max-width: 430px) {
  .overlay-bottom {
    grid-template-columns: 1fr;
  }

  .photo-dots {
    bottom: calc(env(safe-area-inset-bottom) + 152px);
  }
}

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