/* Kieran's birthday card.
   Everything happens on one stage in the film's shape (16:9): the envelope and the three photos
   in it, the PC, the film, and the party that goes on after it. On a phone held upright the
   stage lies on its side, so turning the phone is all it takes, whether or not the phone's
   rotation lock is on. Sizes inside the stage are in cqw / cqh: hundredths of its width / height. */

:root {
  --stone-hi: #6e604c;       /* the game's interface browns */
  --stone-lo: #1d1812;
  --paper: #d4c294;          /* the envelope */
  --paper-lit: #e1d1a6;
  --paper-in: #a8946a;
  --paper-edge: #7b6a4b;
  --wax: #8f1b1b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --vw: 100vw;
  --vh: 100vh;
}
@supports (height: 100dvh) { :root { --vw: 100dvw; --vh: 100dvh; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: #fff; overflow: hidden;
  font-family: Georgia, 'Times New Roman', serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
.px { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; background: #000; overflow: hidden; }

/* ---------- the stage: 16:9, as large as the screen allows, always centred ---------- */
.frame { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(var(--vw), calc(var(--vh) * 16 / 9)); aspect-ratio: 16 / 9; container-type: size; overflow: hidden; background: #000;
  --seal: 0; --flap: 0; --sink: 0; }
@media (orientation: portrait) {
  .frame { width: min(var(--vh), calc(var(--vw) * 16 / 9)); transform: translate(-50%, -50%) rotate(90deg); }
}
#film, #loop, #gl, #backdrop { position: absolute; inset: 0; width: 100%; height: 100%; }
#film, #loop { object-fit: contain; }
#film { z-index: 1; }
#loop { z-index: 2; opacity: 0; }            /* over the film's last picture, which is the one before its first */
html.is-ended #loop { opacity: 1; }
/* the PC, live: it goes out over the film's first picture, which is the same picture, so nothing dips */
#gl { z-index: 3; display: block; transition: opacity 0.3s ease; }
html.is-playing #gl { opacity: 0; }
html.no-3d #gl, html.gl-off #gl { display: none; }
#backdrop { z-index: 4; background: radial-gradient(ellipse at 50% 45%, #2c2218 0%, #0c0a07 78%); opacity: calc(1 - var(--sink)); }

/* ---------- the envelope: 34 wide, 76:54, a little below the middle. Its back, the photos, its
   front, its flap and its seal are layers of their own, so that the photos can come out between
   the back and the front. Once they are out it sinks away by itself (--sink), faster than the
   photos come down, so it never passes over them. ---------- */
.env { position: absolute; left: 33cqw; top: calc(56cqh - 12.08cqw); width: 34cqw; height: 24.16cqw;
  transform: translateY(calc(var(--sink) * 85cqh)); opacity: calc(1 - var(--sink)); }
.env-back { z-index: 5; background: linear-gradient(var(--paper-in), #97845d); box-shadow: 0 1.2cqw 3.4cqw rgba(0, 0, 0, 0.6); }
/* the front: everything but the triangle the flap covers. It and the flap are SVG shapes (index.html):
   as a box with a clip-path, Chrome painted the front whole while the envelope stood still. */
.env-front, .env-flap { cursor: pointer; }
.env-front svg, .env-flap svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.env-front { z-index: 7; }
.env-for { position: absolute; left: 50%; top: 85%; height: 3.3cqw; width: auto; transform: translate(-50%, -50%); opacity: 0.86; }
.env-flap { z-index: 8; transform-origin: 50% 0;
  transform: translateY(calc(var(--sink) * 85cqh)) perspective(70cqw) rotateX(calc(var(--flap) * -178deg)); }
.env-flap .flap-in { display: none; }
.frame.flap-open .env-flap { z-index: 5; }                                                              /* open: behind the photos, */
.frame.flap-open .env-flap .flap-in { display: inline; }                                                /* and showing its inside */
.frame.flap-open .env-flap .flap-out { display: none; }
.env-seal { z-index: 9; left: 50cqw; top: calc(56cqh - 12.08cqw + 14cqw); width: 6.8cqw; height: 6.8cqw; min-width: 44px; min-height: 44px; padding: 0;
  border: 0; border-radius: 50%; cursor: pointer; display: grid; place-items: center;
  background: radial-gradient(circle at 36% 32%, #c23a32 0%, var(--wax) 46%, #5f1010 100%);
  box-shadow: 0 0.35cqw 0.9cqw rgba(0, 0, 0, 0.55), inset 0 0 0 0.35cqw rgba(0, 0, 0, 0.16);
  transform: translate(-50%, -50%) translateY(calc(var(--sink) * 85cqh)) scale(calc(1 + var(--seal) * 0.35)); opacity: calc(1 - var(--seal)); }
.env-seal svg { width: 46%; height: 46%; fill: #f3e2c4; filter: drop-shadow(0 0.1cqw 0.1cqw rgba(0, 0, 0, 0.4)); }
html.is-ready:not(.is-opening) .env-seal { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0.35cqw 0.9cqw rgba(0, 0, 0, 0.55), 0 0 0 0 rgba(255, 220, 120, 0.55); } 50% { box-shadow: 0 0.35cqw 0.9cqw rgba(0, 0, 0, 0.55), 0 0 0 1.3cqw rgba(255, 220, 120, 0); } }
html.is-opening .env, html.is-opening .gate__hint { pointer-events: none; }
.gate__hint { position: absolute; z-index: 9; left: 50%; top: calc(56cqh + 12.08cqw + 3.2cqh); transform: translateX(-50%); display: grid; justify-items: center; gap: 1.5cqh;
  opacity: calc(1 - var(--seal) * 3); cursor: pointer; }
.gate__how { height: clamp(15px, 5.4cqh, 30px); width: auto; }
.gate__note { height: clamp(11px, 3.6cqh, 20px); width: auto; opacity: 0.85; }
.frame.opened .env, .frame.opened .gate__hint, .frame.opened #backdrop, .frame.opened .photo { display: none; }

/* ---------- the three photos: out of the envelope into a fan, then down and out of the picture in
   one move. main.js places them. ---------- */
.photo { position: absolute; z-index: 6; left: 0; top: 0; width: 20cqw; aspect-ratio: 3 / 4; object-fit: cover; display: block;
  box-shadow: 0 0.7cqw 2cqw rgba(0, 0, 0, 0.5); transform-origin: 50% 50%; will-change: transform; pointer-events: none;      /* no border: the film's photos have none */
  -webkit-user-drag: none; user-select: none; }

/* ---------- buttons ---------- */
.osrs-btn { display: inline-grid; place-items: center; cursor: pointer; min-height: 48px; padding: clamp(12px, 2.4vmin, 16px) clamp(20px, 4.4vmin, 34px);
  background: linear-gradient(#5a4a37, #3b3024); border: 2px solid; border-color: #8a7a60 #241d14 #241d14 #8a7a60;
  outline: 1px solid #0e0b07; border-radius: 0; }
.osrs-btn img { height: clamp(22px, 5vmin, 34px); width: auto; }
.osrs-btn:hover:not(:disabled), .osrs-btn:focus-visible { background: linear-gradient(#6a5843, #46392b); }
.osrs-btn:active:not(:disabled) { border-color: #241d14 #8a7a60 #8a7a60 #241d14; }
.sound { position: absolute; z-index: 10; left: 50%; bottom: 7%; transform: translateX(-50%); }
/* after the film: bottom right, clear of Kieran and Snaps (bottom middle) and of the title (top) */
#again { position: absolute; z-index: 10; right: 4cqw; bottom: 7cqh; min-height: max(48px, 12cqh); padding: 1.6cqh 3cqw; box-shadow: 0 2cqh 6cqh rgba(0, 0, 0, 0.5);
  animation: rise 0.9s ease 0.6s both; }
#again img { height: clamp(18px, 5.6cqh, 34px); }
@keyframes rise { from { opacity: 0; transform: translateY(3cqh); } to { opacity: 1; transform: none; } }

.icon-btn { position: fixed; right: calc(12px + var(--safe-right)); bottom: calc(12px + var(--safe-bottom)); width: 44px; height: 44px;
  display: grid; place-items: center; background: rgba(0, 0, 0, 0.45); border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 50%;
  color: #fff; cursor: pointer; opacity: 0.7; z-index: 6; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .off, .icon-btn[aria-pressed='true'] .on { display: none; }
.icon-btn[aria-pressed='true'] .off { display: block; }

/* ---------- outside the stage, upright on the screen ---------- */
.loading { position: absolute; left: calc(10px + var(--safe-left)); top: calc(10px + var(--safe-top)); height: clamp(14px, 2.8vmin, 26px); width: auto; z-index: 5; }
html.is-ready .loading { display: none; }
/* for someone holding the phone upright: in the band above the stage, until the film is under way */
.turn-hint { display: none; position: absolute; left: 50%; top: calc(16px + var(--safe-top)); transform: translateX(-50%); padding: 7px 12px; background: rgba(0, 0, 0, 0.6);
  pointer-events: none; z-index: 5; white-space: nowrap; }
.turn-hint img { height: clamp(14px, 2.2vh, 24px); width: auto; }
@media (orientation: portrait) {
  html.is-ready:not(.is-ended) .turn-hint { display: block; }
  html.is-playing .turn-hint { animation: fade-away 5s ease forwards; }
}
@keyframes fade-away { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .env-seal, #again, .turn-hint { animation: none !important; }
}
