:root {
  --olive-1: #8d9852;
  --olive-2: #6b7638;
  --olive-3: #4a5226;
  --olive-4: #2e3416;
  --paper: #fbfaf4;
  --paper-2: #f1eee2;
  --ink: #3b4122;

  --cam-w: min(74vw, 46dvh, 400px);
  --print-w: min(80vw, 64dvh, 440px);
  --print-h: calc(var(--print-w) * 107 / 88);
}

@media (orientation: landscape) {
  :root {
    --cam-w: min(56vw, 66dvh, 440px);
    --print-w: min(60vw, 66dvh, 440px);
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Mali", system-ui, sans-serif;
  color: var(--paper);
  background-color: var(--olive-3);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    radial-gradient(ellipse 90% 70% at 50% 38%, var(--olive-1) 0%, var(--olive-2) 38%, var(--olive-3) 72%, var(--olive-4) 100%);
  background-attachment: fixed;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- hint ---------- */
.hint {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 4.5dvh);
  left: 0; right: 0;
  margin: 0;
  text-align: center;
  font-size: clamp(16px, 4.6vw, 22px);
  font-weight: 600;
  letter-spacing: .02em;
  color: rgba(251, 250, 244, .92);
  text-shadow: 0 2px 10px rgba(0,0,0,.25);
  transition: opacity .35s ease;
  pointer-events: none;
  z-index: 5;
}
.hint.fade { opacity: 0; }
.hint.pop { animation: hintPop .5s cubic-bezier(.2,.9,.3,1.5) both; }
.hint small {
  display: block;
  margin-top: .3em;
  font-size: .68em;
  font-weight: 500;
  opacity: .8;
}
.hint .emoji {
  display: inline-block;
  animation: wiggle 2.4s ease-in-out infinite;
}
@keyframes hintPop {
  0%   { transform: translateY(-6px) scale(.9); }
  100% { transform: none; }
}
@keyframes wiggle {
  0%, 60%, 100% { transform: rotate(0); }
  70% { transform: rotate(-14deg); }
  80% { transform: rotate(12deg); }
  90% { transform: rotate(-6deg); }
}

@media (orientation: landscape) {
  .hint { top: calc(env(safe-area-inset-top) + 3dvh); font-size: clamp(14px, 3.4dvh, 20px); }
}

/* ---------- camera ---------- */
.camera {
  position: relative;
  width: var(--cam-w);
  aspect-ratio: 320 / 260;
  margin-bottom: 24dvh;
  cursor: pointer;
  outline: none;
  transition: transform .55s cubic-bezier(.3,.7,.3,1), opacity .45s ease;
  animation: float 4s ease-in-out infinite;
}
@media (orientation: landscape) {
  .camera { margin-bottom: 18dvh; }
}

.camera-body { position: relative; z-index: 1; }
.camera-body svg {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 14px 18px rgba(20, 24, 6, .35));
}

.camera:active .camera-body { transform: scale(.98); }
.camera.busy { animation: none; cursor: default; }
.camera.busy:active .camera-body { transform: none; }

.camera.shake .camera-body { animation: shake .48s cubic-bezier(.36,.07,.19,.97) both; }

.camera.away {
  opacity: 0;
  transform: translateY(-14dvh) scale(.82);
  pointer-events: none;
}

#flashGlow { transition: opacity .12s ease-out; }
.camera.flashing #flashGlow { opacity: 1; }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-.6deg); }
  50% { transform: translateY(-6px) rotate(.6deg); }
}
@keyframes shake {
  0%   { transform: translate(0, 0) rotate(0); }
  12%  { transform: translate(-3px, 1px) rotate(-2deg); }
  24%  { transform: translate(3px, -1px) rotate(2deg); }
  36%  { transform: translate(-3px, 0) rotate(-1.6deg); }
  48%  { transform: translate(3px, 1px) rotate(1.4deg); }
  60%  { transform: translate(-2px, -1px) rotate(-1deg); }
  72%  { transform: translate(2px, 0) rotate(.7deg); }
  84%  { transform: translate(-1px, 0) rotate(-.3deg); }
  100% { transform: translate(0, 0) rotate(0); }
}

/* the window just under the eject slot */
.slot {
  position: absolute;
  left: 50%;
  top: 85.6%;
  width: 58%;
  aspect-ratio: 88 / 107;
  transform: translateX(-50%);
  overflow: hidden;
  z-index: 2;
  pointer-events: none;
}
.slot .print {
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  transform: translateY(-101%);
}
.slot .print.ejecting {
  animation: eject 1.45s forwards;
}
/* creeps out during the rustle, then shoots out on the loud "ฟี๊สส" */
@keyframes eject {
  0%   { transform: translateY(-101%); animation-timing-function: cubic-bezier(.3,.3,.6,1); }
  66%  { transform: translateY(-74%);  animation-timing-function: cubic-bezier(.3,.75,.35,1); }
  100% { transform: translateY(0); }
}

/* ---------- flash ---------- */
.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 50;
  background: radial-gradient(circle at 50% 35%, rgba(255,255,245,1) 0%, rgba(255,255,240,.85) 35%, rgba(255,255,235,.55) 100%);
}
.flash.pop { animation: flash .55s ease-out; }
@keyframes flash {
  0%   { opacity: 0; }
  12%  { opacity: .72; }
  100% { opacity: 0; }
}

/* ---------- print (polaroid) ---------- */
.print {
  container-type: inline-size;
  aspect-ratio: 88 / 107;
  perspective: 1400px;
}
.print.free {
  position: fixed;
  z-index: 20;
  left: calc(50% - var(--print-w) / 2);
  top: calc(50% - var(--print-h) / 2 - 3dvh);
  width: var(--print-w);
  cursor: pointer;
}
@media (orientation: landscape) {
  .print.free { top: calc(50% - var(--print-h) / 2 + 2dvh); }
}

.flipper {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .75s cubic-bezier(.4,.2,.2,1);
}
.print.flipped .flipper { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 1.2cqw;
  background:
    linear-gradient(160deg, rgba(255,255,255,.7), rgba(255,255,255,0) 40%),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  box-shadow:
    0 1px 1px rgba(0,0,0,.08),
    0 2.5cqw 6cqw rgba(20, 24, 6, .38),
    inset 0 0 0 1px rgba(0,0,0,.05);
}

.front { padding: 6cqw 6cqw 0; }
.photo {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: #1f2620;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}
.photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(.25) contrast(.55) saturate(0) sepia(.5);
}
.photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #2b3a3c;
  opacity: .92;
  box-shadow: inset 0 0 8cqw rgba(0,0,0,.25);
}
.print.developed .photo img {
  filter: none;
  transition: filter 2.8s ease-out;
}
.print.developed .photo::after {
  opacity: 0;
  transition: opacity 2.4s ease-out;
}

.back {
  transform: rotateY(180deg);
  display: grid;
  place-items: center;
  background:
    repeating-linear-gradient(180deg, transparent 0 calc(9cqw - 1px), rgba(107, 118, 56, .14) calc(9cqw - 1px) 9cqw),
    linear-gradient(180deg, var(--paper), var(--paper-2));
}
.back-inner {
  text-align: center;
  padding: 0 8cqw;
  color: var(--ink);
}
.pin {
  width: 11cqw;
  height: 11cqw;
  color: #c0392b;
  filter: drop-shadow(0 1cqw 1cqw rgba(0,0,0,.2));
  margin-bottom: 2cqw;
}
.place {
  font-size: 12cqw;
  font-weight: 700;
  line-height: 1.25;
  transform: rotate(-3deg);
  word-break: break-word;
}
.sub {
  margin-top: 2.5cqw;
  font-size: 6.5cqw;
  font-weight: 500;
  opacity: .7;
  transform: rotate(-3deg);
}
.sub:empty { display: none; }

/* ---------- next button ---------- */
.next-btn {
  position: fixed;
  z-index: 30;
  right: calc(env(safe-area-inset-right) + 7vw);
  bottom: calc(env(safe-area-inset-bottom) + 5dvh);
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  background: var(--paper);
  color: var(--olive-3);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(20, 24, 6, .35), inset 0 -3px 0 rgba(0,0,0,.08);
  animation: popIn .45s cubic-bezier(.2,.9,.3,1.4) both;
}
.next-btn svg { width: 30px; height: 30px; }
.next-btn:active { transform: scale(.92); }
.next-btn[hidden] { display: none; }

@media (orientation: landscape) {
  .next-btn {
    bottom: auto;
    top: calc(50% - 32px);
    right: calc(env(safe-area-inset-right) + 6vw);
  }
}

@keyframes popIn {
  0%   { opacity: 0; transform: scale(.4) translateX(-20px); }
  100% { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .camera { animation: none; }
}
