/* Japan & Taiwan rotary polaroid stand */

.album-body {
  background: #140e0c;
}

.album-main {
  position: relative;
  height: 100vh;
  height: 100svh;
  padding-top: 4.5rem;
  overflow: hidden;
}

/* ---------- Cozy apartment backdrop ---------- */

.room {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 55% 60% at 88% 38%, rgba(255, 176, 96, 0.28), transparent 70%),
    linear-gradient(180deg, #2c1d17 0%, #3b281e 52%, #24170f 100%);
  transform-origin: 50% 72%;
}

.room-blur {
  position: absolute;
  inset: -4%;
  filter: blur(12px);
}

.room-blur > span {
  position: absolute;
}

.room-window {
  left: 7%;
  top: 13%;
  width: 25%;
  height: 46%;
  border: 12px solid #4a3326;
  border-radius: 4px;
  background:
    radial-gradient(circle at 18% 82%, #ffd59a 0 3px, transparent 4px),
    radial-gradient(circle at 34% 76%, #ffe7b8 0 2px, transparent 3px),
    radial-gradient(circle at 52% 86%, #ffc983 0 3px, transparent 4px),
    radial-gradient(circle at 68% 79%, #fff1cf 0 2px, transparent 3px),
    radial-gradient(circle at 83% 88%, #ffd59a 0 3px, transparent 4px),
    linear-gradient(180deg, #24264f 0%, #4b3a7c 42%, #b9668a 80%, #f0a066 100%);
  box-shadow: 0 0 80px rgba(185, 102, 138, 0.35);
}

.room-window-pane:first-child {
  left: calc(50% - 5px);
  top: 0;
  bottom: 0;
  width: 10px;
}

.room-window-pane:last-child {
  left: 0;
  right: 0;
  top: calc(45% - 5px);
  height: 10px;
}

.room-window-pane {
  position: absolute;
  background: #4a3326;
}

.room-curtain {
  left: 2.5%;
  top: 8%;
  width: 8%;
  height: 72%;
  border-radius: 0 0 30% 10%;
  background: repeating-linear-gradient(90deg, #6b3a3e 0 18px, #874b4f 18px 30px, #5e3236 30px 44px);
}

.room-lights {
  inset: 0;
}

.room-lights i {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: #ffe2a8;
  box-shadow: 0 0 18px 7px rgba(255, 186, 104, 0.65);
}

.room-shelf {
  left: 64%;
  top: 19%;
  width: 20%;
  height: 11%;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 0 8%;
  border-bottom: 10px solid #5a3a26;
}

.room-shelf i {
  width: 12%;
  border-radius: 2px 2px 0 0;
}

.room-shelf i:nth-child(1) { height: 78%; background: #2f5d5a; }
.room-shelf i:nth-child(2) { height: 92%; background: #c08a3e; }
.room-shelf i:nth-child(3) { height: 70%; background: #7a3d55; }
.room-shelf i:nth-child(4) { height: 86%; background: #e7dcc4; }
.room-shelf i:nth-child(5) { height: 64%; background: #3f4a7a; transform: rotate(14deg); transform-origin: bottom left; }

.room-lamp-glow {
  left: 62%;
  top: 6%;
  width: 52vw;
  height: 52vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 196, 120, 0.42), transparent 62%);
}

.room-lamp {
  left: 84%;
  top: 30%;
  width: 9%;
  height: 12%;
  clip-path: polygon(20% 0, 80% 0, 100% 100%, 0 100%);
  background: linear-gradient(180deg, #ffe9c2, #f4b56a);
}

.room-plant {
  left: 23%;
  top: 36%;
  width: 13%;
  height: 34%;
}

.room-plant i {
  position: absolute;
  left: 50%;
  bottom: 22%;
  width: 34%;
  height: 58%;
  border-radius: 50% 50% 50% 50% / 70% 70% 30% 30%;
  background: #34523a;
  transform-origin: 50% 100%;
}

.room-plant i:nth-child(1) { transform: translateX(-50%) rotate(-48deg); background: #2c4630; }
.room-plant i:nth-child(2) { transform: translateX(-50%) rotate(-22deg); }
.room-plant i:nth-child(3) { transform: translateX(-50%) rotate(4deg); background: #3e6142; }
.room-plant i:nth-child(4) { transform: translateX(-50%) rotate(28deg); }
.room-plant i:nth-child(5) { transform: translateX(-50%) rotate(52deg); background: #2c4630; }
.room-plant i:nth-child(6) { transform: translateX(-50%) rotate(-8deg) scale(0.8); background: #47704a; }

.room-plant::after {
  content: "";
  position: absolute;
  left: 30%;
  bottom: 0;
  width: 40%;
  height: 24%;
  border-radius: 4px 4px 12px 12px;
  background: linear-gradient(180deg, #b0613f, #8a4a30);
}

.room-sofa {
  left: 10%;
  top: 50%;
  width: 80%;
  height: 30%;
  border-radius: 48px 48px 14px 14px;
  background: linear-gradient(180deg, #503649, #3a2636);
}

.room-pillow {
  position: absolute;
  top: 10%;
  width: 13%;
  height: 34%;
  border-radius: 18px;
}

.room-pillow:first-child {
  left: 8%;
  background: #b98a3e;
  transform: rotate(-8deg);
}

.room-pillow:last-child {
  right: 9%;
  background: #a95e6c;
  transform: rotate(6deg);
}

.room-rug {
  left: -5%;
  top: 78%;
  width: 110%;
  height: 30%;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 40px, transparent 40px 80px),
    linear-gradient(180deg, #5c3f34, #3d2820);
}

.room-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 75% 70% at 50% 55%, transparent 45%, rgba(10, 6, 4, 0.72) 100%);
}

/* ---------- Intro: camera zooms in on the coffee table ---------- */

.js .album-body .room {
  transition: transform 2.8s cubic-bezier(0.65, 0, 0.25, 1) 0.5s;
}

.js .album-body.is-entered .room {
  transform: scale(1.35);
}

.js .album-body .stand-viewport {
  /* Wide shot; JS measures --intro-scale/--intro-y so the whole stand fits the screen */
  opacity: 0;
  transform: translateY(var(--intro-y, 8vh)) scale(var(--intro-scale, 0.35));
  transition:
    transform 2.8s cubic-bezier(0.65, 0, 0.25, 1) 0.5s,
    opacity 0.5s ease;
}

.js .album-body.is-entered .stand-viewport {
  opacity: 1;
  transform: none;
}

/* Fade in before the push starts, so the wide shot is seen first */
.js .album-body.is-entered .stand-viewport {
  transition:
    transform 2.8s cubic-bezier(0.65, 0, 0.25, 1) 0.5s,
    opacity 0.5s ease;
}

.js .album-body .stand {
  transform: rotateX(-16deg) rotateY(-38deg);
  transition: transform 2.8s cubic-bezier(0.65, 0, 0.25, 1) 0.5s;
}

.js .album-body.is-entered .stand {
  transform: rotateX(-3deg);
}

.js .album-body .stand-controls,
.js .album-body .stand-hint {
  opacity: 0;
  transition: opacity 0.6s ease 2.9s;
}

.js .album-body.is-entered .stand-controls {
  opacity: 1;
}

/* The hint sits over the polaroid's strip, so it shows briefly after the zoom and then gets out of the way */
.js .album-body.is-entered .stand-hint {
  animation: hint-flash 4.5s ease 2.9s both;
}

@keyframes hint-flash {
  0% { opacity: 0; }
  12%, 80% { opacity: 1; }
  100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .js .album-body .room,
  .js .album-body .stand-viewport,
  .js .album-body .stand,
  .js .album-body .stand-controls,
  .js .album-body .stand-hint {
    transition: none;
  }
}

.album-back {
  position: absolute;
  top: 5rem;
  left: max(1rem, calc((100vw - var(--wrap)) / 2 + 1rem));
  z-index: 2;
}

/* ---------- Stand geometry ----------
   --ch: polaroid height, sized so the whole stand fits the viewport
   --cw: width (fits a 2:3 photo window plus the caption strip)
   --r:  distance from the axle to a polaroid's bottom edge
   --axis: axle height measured from the top of the stand box */

.stand-area {
  /* Front polaroid fills the screen below the header (the rest of the stand runs off the bottom) */
  --ch: min(calc((100svh - 6rem) / 1.04), calc((100vw - 2rem) / 0.605));
  --cw: calc(var(--ch) * 0.605); /* card shaped around a 2:3 photo */
  --r: calc(var(--ch) * 0.1);
  --hub: calc(var(--ch) * 0.62);
  --gap: calc(var(--ch) * 0.14);
  --axis: calc(var(--ch) + var(--r) + var(--ch) * 0.04);
  --stand-h: calc(var(--axis) + var(--r) + var(--ch) * 1.02);
  --base-h: calc(var(--ch) * 0.1);
  --base-d: calc(var(--ch) * 0.7);
  --table-w: calc(var(--cw) * 3.8);
  --table-d: calc(var(--ch) * 1.5);
  --table-t: calc(var(--ch) * 0.08);

  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stand-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  perspective: 2800px;
  perspective-origin: 50% 45%;
  transform-origin: 50% 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.stand-viewport.is-dragging {
  cursor: grabbing;
}

.stand-viewport:focus-visible .stand-cards {
  outline: 2px solid var(--accent-2);
  outline-offset: 12px;
  border-radius: 6px;
}

.stand {
  position: relative;
  flex-shrink: 0;
  width: var(--cw);
  height: var(--stand-h);
  transform-style: preserve-3d;
  transform: rotateX(-3deg);
}

.stand > * {
  position: absolute;
  transform-style: preserve-3d;
}

.stand-cards {
  inset: 0;
}

/* ---------- Polaroids ---------- */

.polaroid {
  position: absolute;
  left: 0;
  top: calc(var(--axis) - var(--ch));
  width: var(--cw);
  height: var(--ch);
  transform-origin: 50% 100%;
  transform-style: preserve-3d;
}

.polaroid-face {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  overflow: hidden;
}

/* JS shows one side at a time (whichever faces the viewer), so each polaroid is one layer */
.polaroid-back,
.polaroid.show-back .polaroid-front {
  display: none;
}

.polaroid.show-back .polaroid-back {
  display: block;
}

/* Lite polaroids (far back in the fan on phones) are just a flat color set by JS */
.polaroid.is-lite > .polaroid-face {
  display: none;
}

.polaroid-front {
  background: #f7f5f0;
  padding: 7.4% 7.4% 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

/* Darkens cards as they lean away from the light (opacity set by JS) */
.polaroid-shade {
  position: absolute;
  inset: 0;
  background: #05060a;
  opacity: 0;
  pointer-events: none;
}

.polaroid-photo {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: #2a2420;
}

.polaroid-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.polaroid-caption {
  margin: 0;
  height: calc(var(--ch) - var(--cw) * 1.352);
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-family: "Caveat", cursive;
  font-size: clamp(1.4rem, 3vmin, 2rem); /* same size the old fullscreen view used */
  line-height: 1.1;
  color: #1e1b4b;
  white-space: nowrap;
}

.polaroid-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75em;
  margin: 0;
}

.polaroid-place {
  font-weight: 700;
}

/* Long subjects wrap onto a second line instead of running off the card */
.polaroid-place > :first-child {
  min-width: 0;
  white-space: normal;
}

/* Location opens Google Maps; only clickable on the polaroid at the front */
.polaroid-map-link {
  color: inherit;
  text-decoration: none;
  pointer-events: none;
}

.polaroid.is-front .polaroid-map-link {
  pointer-events: auto;
  cursor: pointer;
}

.polaroid.is-front .polaroid-map-link:hover,
.polaroid.is-front .polaroid-map-link:focus-visible {
  text-decoration: underline dotted;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  outline: none;
}

.polaroid-date {
  font-weight: 500;
  font-size: 0.75em;
  color: #4c4a6b;
}

/* Like count, on the right end of the place line */
.polaroid-likes {
  display: inline-flex;
  align-items: center;
  gap: 0.2em;
  font-size: 0.85em;
  color: #be123c;
}

.polaroid-likes[hidden] {
  display: none;
}

.polaroid-likes svg {
  width: 0.85em;
  height: 0.85em;
  fill: currentColor;
}

/* Heart stamp, pressed onto the photo when liked */
.polaroid-stamp {
  position: absolute;
  right: 7%;
  bottom: 7%;
  width: 28%;
  height: 28%;
  fill: #e11d48;
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 0.6;
  opacity: 0;
  transform: rotate(-14deg) scale(1.4);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25));
  pointer-events: none;
}

.polaroid.is-liked .polaroid-stamp {
  opacity: 0.92;
  transform: rotate(-14deg) scale(1);
}

.polaroid.is-stamping .polaroid-stamp {
  animation: heart-stamp 0.42s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes heart-stamp {
  0% { opacity: 0; transform: rotate(-14deg) scale(2.2); }
  55% { opacity: 1; transform: rotate(-14deg) scale(0.88); }
  100% { opacity: 0.92; transform: rotate(-14deg) scale(1); }
}

.polaroid-back {
  transform: rotateX(180deg);
  background: linear-gradient(160deg, #1b1f2b, #0d1018);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}


/* ---------- Stand hardware ---------- */

.stand-axle {
  left: calc(var(--cw) * 0.08);
  top: calc(var(--axis) - 4px);
  width: calc(var(--cw) * 0.92 + var(--gap));
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(#3b3355, #171427);
}

.stand-hub {
  left: calc(var(--cw) + var(--gap) - var(--hub) / 2);
  top: calc(var(--axis) - var(--hub) / 2);
  width: var(--hub);
  height: var(--hub);
  /* Side-on, perpendicular to the axle like the real stand */
  transform: rotateY(90deg);
}

.stand-hub-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle, transparent 0 calc(var(--hub) * 0.4), rgba(255, 255, 255, 0.55) 0 calc(var(--hub) * 0.415), transparent 0),
    repeating-conic-gradient(rgba(255, 255, 255, 0.45) 0 2.5deg, transparent 2.5deg 15deg),
    conic-gradient(from 200deg, var(--accent-1), var(--accent-2), #f0abfc, var(--accent-1));

  box-shadow: 0 0 40px rgba(168, 85, 247, 0.35);
}

.stand-hub-ring::after {
  content: "";
  position: absolute;
  inset: 26%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #2a2440, #0d0b16);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.stand-pillar {
  left: calc(var(--cw) + var(--gap) - var(--hub) * 0.17);
  top: var(--axis);
  width: calc(var(--hub) * 0.34);
  height: calc(var(--stand-h) - var(--axis));
  transform: rotateY(90deg);
  background: linear-gradient(180deg, #2a2440, #141120);
  border-radius: 0 0 2px 2px;
}

.stand-base {
  left: calc(var(--cw) * -0.12);
  top: var(--stand-h);
  width: calc(var(--cw) * 1.24 + var(--gap) * 1.5);
  height: var(--base-h);
}

.stand-base-top,
.stand-base-front {
  position: absolute;
  left: 0;
  width: 100%;
}

.stand-base-top {
  top: calc(var(--base-d) / -2);
  height: var(--base-d);
  transform: rotateX(90deg);
  background: linear-gradient(90deg, #1a1630, #2c2547 50%, #1a1630);
  border-radius: 6px;
}

.stand-base-front {
  top: 0;
  height: 100%;
  transform: translateZ(calc(var(--base-d) / 2));
  background: linear-gradient(120deg, var(--accent-1), var(--accent-2));
  border-radius: 0 0 6px 6px;
}

/* ---------- Coffee table the stand sits on ---------- */

.stand-table {
  left: calc(var(--cw) * 0.5 + var(--gap) * 0.75 - var(--table-w) / 2);
  top: calc(var(--stand-h) + var(--base-h));
  width: var(--table-w);
  height: 0;
}

.stand-table > span {
  position: absolute;
}

.stand-table-top {
  left: 0;
  top: calc(var(--table-d) / -2);
  width: 100%;
  height: var(--table-d);
  transform: rotateX(90deg);
  border-radius: 10px;
  background:
    radial-gradient(ellipse 60% 70% at 78% 30%, rgba(255, 196, 120, 0.22), transparent 70%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.09) 0 2px, transparent 2px 11px, rgba(255, 230, 200, 0.04) 11px 13px, transparent 13px 27px),
    linear-gradient(0deg, #4f321f, #6b4529 30%, #5a3a23 55%, #74502f 80%, #553621);
}

.stand-table-shadow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--cw) * 1.6);
  height: calc(var(--base-d) * 1.4);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(10, 5, 2, 0.6), transparent 70%);
}

.stand-table-front {
  left: 0;
  top: 0;
  width: 100%;
  height: var(--table-t);
  transform: translateZ(calc(var(--table-d) / 2));
  border-radius: 0 0 6px 6px;
  background: linear-gradient(180deg, #5a3a23, #3a2414);
}

.stand-table-side {
  left: calc(100% - var(--table-d) / 2);
  top: 0;
  width: var(--table-d);
  height: var(--table-t);
  transform: rotateY(90deg);
  background: linear-gradient(180deg, #4a2f1c, #2e1c10);
}

/* ---------- Controls ---------- */

.stand-controls {
  position: absolute;
  top: 50%;
  right: max(1rem, calc((100vw - var(--wrap)) / 2 + 1rem));
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  color: #fff;
  z-index: 2;
}

.stand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.stand-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.stand-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.stand-btn svg {
  width: 20px;
  height: 20px;
}

.stand-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.75rem;
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted-light);
  pointer-events: none;
}

.stand-toast {
  position: absolute;
  left: 50%;
  bottom: 2.75rem;
  margin: 0;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  background: #fff;
  color: var(--bg-dark);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  transform: translate(-50%, 8px);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 3;
}

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

/* ---------- Name prompt ---------- */

.name-dialog {
  width: min(360px, calc(100vw - 2rem));
  padding: 1.5rem;
  border: 0;
  border-radius: 16px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.name-dialog::backdrop {
  background: rgba(5, 6, 10, 0.6);
}

.name-dialog label {
  display: block;
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.name-dialog input[type="text"] {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  font: inherit;
}

.name-dialog input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-2);
}

.name-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

.name-dialog-actions .btn {
  border: 0;
  cursor: pointer;
}

.name-dialog-cancel {
  padding: 0.75rem 1rem;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  /* Phones: the live-blurred room is swapped for a pre-rendered image of it. Re-blurring a
     full-screen layer every frame of the zoom crashed mobile Safari; scaling a flat image is
     cheap, so the room can still push in during the intro. Regenerate room-phone.webp if the
     room's design changes. */
  .room-blur,
  .room-vignette {
    display: none; /* both are baked into the image */
  }

  .room {
    background: #2a1c16 url("/assets/images/japan-taiwan/room-phone.webp") center / cover no-repeat;
  }

  /* The polaroid is nearly full width on phones, so flip by swiping */
  .stand-controls {
    display: none;
  }
}
