:root {
  --ink: #171513;
  --paper: #f5efe3;
  --cream: #fff8e9;
  --accent: #a53c33;
  --focus: #e7c179;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #090909;
}

body {
  color: var(--cream);
  font-family: Georgia, "Times New Roman", "Songti SC", serif;
  overflow: hidden;
}

button,
a { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.app {
  width: 100vw;
  height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(255,255,255,.065), transparent 46%),
    #090909;
}

.screen {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  aspect-ratio: 16 / 9;
  isolation: isolate;
  animation: page-arrive 520ms cubic-bezier(.2,.8,.2,1) both;
}

.screen--book {
  perspective: 1800px;
  animation: none;
}

body:has(.screen--book) .slide-hint { display: none !important; }
.screen--book > .childhood-added-photo {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 460ms ease;
}
.screen--book.is-open > .childhood-added-photo.photo-ready {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.screen--book.is-open .screen__art { opacity: 1; animation: none; }

.screen--tear { aspect-ratio: 1663 / 946; width: min(100vw, calc(100dvh * 1663 / 946)); }
.tear-canvas { display: block; width: 100%; height: 100%; }
.tear-trigger { z-index: 3; touch-action: manipulation; }
.tear-trigger:focus-visible { outline: 1px dashed #665d50; outline-offset: -12px; }
.tear-error { position: absolute; inset: 40% 10%; text-align: center; }
.screen--book.language-changed .screen__art { animation: none; opacity: 1; }

.screen--book .screen__art,
.screen--book .photo-layer {
  opacity: 0;
}

.screen--book.is-opening .screen__art,
.screen--book.is-opening .photo-layer {
  animation: book-art-reveal 1400ms linear both;
}

.screen__art {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.screen__heading {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.screen--layered-childhood {
  perspective: 1800px;
  animation: none;
}

.childhood-book {
  position: absolute;
  inset: 2.8% 4.5%;
  display: flex;
  filter: drop-shadow(0 2.2vw 2vw rgba(0, 0, 0, .48));
  perspective: 1800px;
  transform-style: preserve-3d;
}

.childhood-book::after {
  position: absolute;
  z-index: 20;
  top: 1.2%;
  bottom: 1.2%;
  left: 50%;
  width: .9%;
  content: "";
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(74, 54, 39, .22), rgba(255, 252, 241, .2) 44%, rgba(70, 49, 34, .28));
  box-shadow: 0 0 1vw rgba(63, 43, 28, .28);
  pointer-events: none;
}

.childhood-book::before {
  position: absolute;
  z-index: 24;
  top: 1.5%;
  right: 1.8%;
  bottom: 1.5%;
  width: 1.25%;
  content: "";
  border-radius: 999px;
  background: linear-gradient(90deg, #171717, #393631 52%, #111);
  box-shadow: -.25vw 0 .45vw rgba(0,0,0,.22);
  pointer-events: none;
}

.childhood-page {
  position: relative;
  width: 50%;
  height: 100%;
  overflow: hidden;
  color: #26221e;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  background:
    radial-gradient(circle at 30% 22%, rgba(255,255,255,.58), transparent 25%),
    repeating-linear-gradient(4deg, rgba(91,72,51,.018) 0 1px, transparent 1px 5px),
    linear-gradient(100deg, #f6efe1, #fffaf0 46%, #efe4d2);
  isolation: isolate;
}

.childhood-page--left::after {
  position: absolute;
  z-index: 0;
  inset: 2.5% 3.5% 2.5% 4%;
  content: "";
  clip-path: polygon(1% 1%, 97% 0, 100% 8%, 98% 18%, 100% 29%, 98% 42%, 100% 55%, 98% 69%, 100% 83%, 96% 100%, 3% 98%, 0 88%, 2% 74%, 0 59%, 2% 45%, 0 29%, 2% 13%);
  background:
    repeating-linear-gradient(8deg, rgba(255,255,255,.055) 0 1px, transparent 1px 5px),
    #aebdca;
  box-shadow: .5vw .45vw .8vw rgba(64,54,45,.12);
}

.childhood-page--right::before {
  position: absolute;
  z-index: 0;
  top: 5%;
  left: 7%;
  width: 58%;
  height: 46%;
  content: "";
  clip-path: polygon(2% 4%, 92% 0, 100% 13%, 96% 30%, 100% 52%, 95% 70%, 99% 94%, 5% 100%, 0 84%, 3% 63%, 0 41%);
  background: #829985;
  opacity: .6;
}

.childhood-page--right::after {
  position: absolute;
  z-index: 0;
  right: 6%;
  bottom: 3%;
  width: 44%;
  height: 31%;
  content: "";
  clip-path: polygon(7% 0, 100% 5%, 96% 100%, 0 94%);
  background:
    linear-gradient(rgba(93,139,177,.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(93,139,177,.28) 1px, transparent 1px),
    rgba(248,244,231,.8);
  background-size: 7% 12%;
}

.childhood-page--left {
  border-radius: 5% 0 0 5% / 4% 0 0 4%;
  transform-origin: 100% 50%;
  transform: rotateY(88deg);
  box-shadow: inset -1.8vw 0 2.2vw rgba(79, 57, 38, .18);
}

.childhood-page--right {
  border-radius: 0 5% 5% 0 / 0 4% 4% 0;
  transform-origin: 0 50%;
  transform: rotateY(-88deg);
  box-shadow: inset 1.8vw 0 2.2vw rgba(79, 57, 38, .16);
}

.screen--layered-childhood.is-ready .childhood-page--left {
  animation: childhood-open-left 1500ms cubic-bezier(.18,.72,.2,1) both;
}

.screen--layered-childhood.is-ready .childhood-page--right {
  animation: childhood-open-right 1500ms cubic-bezier(.18,.72,.2,1) both;
}

.scrap-component {
  position: absolute;
  z-index: 3;
  opacity: 0;
}

.screen--layered-childhood.is-ready .scrap-component {
  animation: childhood-piece-settle 620ms cubic-bezier(.2,.82,.24,1) both;
  animation-delay: 1030ms;
}

.childhood-title {
  z-index: 8;
  top: 3.5%;
  left: 8%;
  width: 43%;
  min-height: 15%;
  padding: 7.5% 7% 5%;
  clip-path: polygon(2% 3%, 96% 0, 100% 86%, 91% 100%, 3% 94%, 0 16%);
  background: #caa083;
  box-shadow: .5vw .6vw 1vw rgba(64,43,30,.2);
  font: 600 clamp(13px, 1.5vw, 25px)/1.1 "Courier New", monospace;
  letter-spacing: .08em;
  text-align: center;
  transform: rotate(-1.3deg);
}

.childhood-title::after {
  display: block;
  width: 86%;
  height: 1px;
  margin: 5% auto 0;
  content: "";
  background: #342c25;
}

.childhood-title__icon {
  display: block;
  margin-bottom: 2%;
  font: 700 clamp(16px, 2.1vw, 34px)/1 Georgia, serif;
}

.childhood-title__icon::after {
  display: inline-block;
  width: 18%;
  height: 1.7em;
  margin-left: 8%;
  border: 2px solid rgba(63,59,54,.66);
  border-left-color: transparent;
  border-radius: 999px;
  content: "";
  transform: rotate(-18deg) translateY(.35em);
  vertical-align: middle;
}

.childhood-story {
  z-index: 5;
  top: 14%;
  left: 51%;
  width: 44%;
  padding: 6% 5.5%;
  clip-path: polygon(1% 5%, 96% 0, 100% 91%, 92% 100%, 4% 96%, 0 13%);
  background: #f0e3ce;
  box-shadow: .45vw .55vw .9vw rgba(76,53,34,.16);
  font: clamp(11px, 1.13vw, 19px)/1.72 "Songti SC", "STSong", serif;
  letter-spacing: .05em;
}

.childhood-story::before {
  position: absolute;
  top: -5%;
  left: 35%;
  width: 31%;
  height: 10%;
  content: "";
  transform: rotate(-1deg);
  background: rgba(136, 53, 50, .82);
}

.childhood-photo {
  z-index: 6;
  padding: clamp(4px, .55vw, 9px);
  border: 0;
  background: #faf7ef;
  box-shadow: 0 .7vw 1.25vw rgba(55, 39, 27, .25);
  cursor: zoom-in;
}

.childhood-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  user-select: none;
  -webkit-user-drag: none;
}

.childhood-photo__tape {
  position: absolute;
  z-index: 2;
  top: -8%;
  left: 34%;
  width: 34%;
  height: 13%;
  transform: rotate(-2deg);
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.16) 0 2px, transparent 2px 5px),
    rgba(155, 48, 43, .88);
  box-shadow: 0 .15vw .22vw rgba(50,33,25,.16);
}

.childhood-photo:focus-visible {
  outline: 3px solid #d8ad63;
  outline-offset: 5px;
}

.childhood-photo--1 { top: 28%; left: 7%; width: 38%; height: 27%; transform: rotate(-1.4deg); }
.childhood-photo--2 { top: 58%; left: 6%; width: 38%; height: 27%; transform: rotate(.7deg); }
.childhood-photo--3 { top: 49%; left: 39%; width: 48%; height: 26%; transform: rotate(-1.8deg); }
.childhood-photo--4 { top: 73%; left: 44%; width: 46%; height: 24%; transform: rotate(1.1deg); }
.childhood-photo--5 { top: 7%; left: 10%; width: 50%; height: 31%; transform: rotate(.8deg); }
.childhood-photo--6 { top: 40%; left: 27%; width: 46%; height: 35%; transform: rotate(-1.2deg); }

.childhood-photo--1 img { object-position: 58% center; }
.childhood-photo--2 img { object-position: center 35%; }
.childhood-photo--3 img { object-position: center 38%; }
.childhood-photo--4 img { object-position: center 46%; }
.childhood-photo--5 img { object-position: center 42%; }
.childhood-photo--6 img { object-position: center 35%; }

.childhood-photo--2 .childhood-photo__tape,
.childhood-photo--5 .childhood-photo__tape { background-color: rgba(75, 92, 115, .85); }

.childhood-photo--3 .childhood-photo__tape,
.childhood-photo--6 .childhood-photo__tape { background-color: rgba(126, 137, 92, .88); }

.childhood-note {
  top: 12%;
  right: 5%;
  width: 33%;
  padding: 4.5% 4%;
  clip-path: polygon(4% 0, 100% 4%, 96% 94%, 8% 100%, 0 15%);
  background: #efe1ca;
  color: #315b93;
  font: clamp(12px, 1.36vw, 23px)/1.55 "Kaiti SC", "STKaiti", cursive;
  white-space: pre-line;
  transform: rotate(1.2deg);
}

.childhood-label {
  top: 72%;
  left: 8%;
  padding: 1.8% 3%;
  background: #aeb9bc;
  font: clamp(8px, .72vw, 12px)/1.2 "Courier New", monospace;
  letter-spacing: .09em;
  transform: rotate(-4deg);
}

.childhood-birth {
  right: 7%;
  bottom: 7%;
  padding: 3.5% 4%;
  border: 1px solid #7b5f43;
  background: #d8b78c;
  font: clamp(8px, .8vw, 14px)/1.5 "Courier New", monospace;
  letter-spacing: .04em;
  text-align: center;
  white-space: pre-line;
  transform: rotate(-1deg);
}

.childhood-doodle {
  bottom: 3%;
  left: 9%;
  font: clamp(20px, 2.3vw, 38px)/1 Georgia, serif;
  transform: rotate(-4deg);
}

.childhood-horse {
  right: 31%;
  bottom: 5%;
  width: 16%;
  height: 14%;
  display: grid;
  place-items: center;
  border: .4vw solid #b88b66;
  border-radius: 48% 52% 45% 55%;
  background: #f1dfbb;
  color: #704f37;
  font: clamp(22px, 3vw, 50px)/1 Georgia, serif;
  transform: rotate(4deg);
}

.screen--layered-childhood.is-ready .childhood-title,
.screen--layered-childhood.is-ready .childhood-story,
.screen--layered-childhood.is-ready .childhood-note { animation-delay: 1060ms; }
.screen--layered-childhood.is-ready .childhood-photo--1,
.screen--layered-childhood.is-ready .childhood-photo--5 { animation-delay: 1160ms; }
.screen--layered-childhood.is-ready .childhood-photo--2,
.screen--layered-childhood.is-ready .childhood-photo--6 { animation-delay: 1250ms; }
.screen--layered-childhood.is-ready .childhood-photo--3,
.screen--layered-childhood.is-ready .childhood-photo--4 { animation-delay: 1340ms; }
.screen--layered-childhood.is-ready .childhood-label,
.screen--layered-childhood.is-ready .childhood-birth,
.screen--layered-childhood.is-ready .childhood-doodle,
.screen--layered-childhood.is-ready .childhood-horse { animation-delay: 1430ms; }

.hotspot {
  position: absolute;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  outline: none;
}

.hotspot--entry { cursor: pointer; }
.hotspot.childhood-added-photo {
  box-sizing: border-box;
  padding: .23%;
  background: #f4ede4;
  box-shadow: 1px 3px 4px #35281b66, inset 0 0 3px #c9b7a1;
  z-index: 5;
}
.childhood-added-photo img { width: 100%; height: 100%; display: block; object-fit: cover; }
.childhood-frame-tape { position:absolute; width:44%; height:24%; left:28%; top:-12%; transform:rotate(-7deg); background:url('../assets/the-boy/generated/burgundy-torn-washi-v1.png?v=20261201') center/100% 100% no-repeat; pointer-events:none; filter:drop-shadow(0 1px 1px #342b2533); }
.hotspot--photo {
  z-index: 4;
  cursor: zoom-in;
}

.photo-layer,
.book-opening__photos {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.photo-layer { z-index: 2; }

.photo-overlay {
  position: absolute;
  display: block;
  object-fit: cover;
  object-position: center;
  border: clamp(4px, .58vw, 9px) solid #f6f0e6;
  box-shadow:
    0 0 0 clamp(3px, .45vw, 7px) #f6f0e6,
    0 .45vw 1vw rgba(45, 34, 23, .22);
  transform: scale(1.025);
  transform-origin: center;
  user-select: none;
  -webkit-user-drag: none;
}

.book-opening {
  visibility: hidden;
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  perspective: 1800px;
  pointer-events: none;
}
.screen--book.is-opening .book-opening { visibility: visible; }

.book-opening__half {
  position: relative;
  width: 50%;
  height: 100%;
  overflow: hidden;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  background: #eee7d8;
  filter: drop-shadow(0 18px 24px rgba(0,0,0,.36));
}

.book-opening__sheet {
  position: absolute;
  top: 0;
  width: 200%;
  height: 100%;
}

.book-opening__art {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
}

.book-opening__half--left {
  transform-origin: 100% 50%;
  transform: rotateY(82deg);
}

.book-opening__half--left .book-opening__sheet { left: 0; }

.book-opening__half--right {
  transform-origin: 0 50%;
  transform: rotateY(-82deg);
}

.book-opening__half--right .book-opening__sheet { left: -100%; }

.screen--book.is-opening .book-opening__half--left {
  animation: open-left-page 1400ms cubic-bezier(.18,.72,.2,1) both;
}

.screen--book.is-opening .book-opening__half--right {
  animation: open-right-page 1400ms cubic-bezier(.18,.72,.2,1) both;
}

.lightbox[hidden] { display: none; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: minmax(48px, 1fr) minmax(0, auto) minmax(48px, 1fr);
  align-items: center;
  gap: clamp(8px, 2vw, 28px);
  padding: clamp(48px, 6vw, 76px) clamp(12px, 3vw, 48px) 24px;
  background: rgba(4,4,4,.91);
  backdrop-filter: blur(13px);
  -webkit-backdrop-filter: blur(13px);
  animation: lightbox-in 220ms ease both;
}

.lightbox__figure {
  grid-column: 2;
  min-width: 0;
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 12px;
}

.lightbox__image {
  display: block;
  max-width: min(84vw, 1320px);
  max-height: 80dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  background: #eee8dc;
  border: clamp(7px, .8vw, 13px) solid #f4efe5;
  box-shadow: 0 24px 80px rgba(0,0,0,.62);
  transform: rotate(-.18deg);
}

.lightbox__caption {
  min-height: 1.3em;
  color: rgba(255,248,233,.76);
  font: 12px/1.35 "Courier New", monospace;
  letter-spacing: .08em;
}

.lightbox__nav {
  border: 1px solid rgba(255,255,255,.34);
  color: #fff8e9;
  background: rgba(23,21,19,.72);
  cursor: pointer;
}

.lightbox__nav:hover,
.lightbox__nav:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
  background: rgba(74,67,59,.9);
}

.lightbox__nav {
  width: clamp(44px, 5vw, 62px);
  height: clamp(56px, 7vw, 76px);
  border-radius: 999px;
  font: 48px/1 Georgia, serif;
}

.lightbox__nav--previous { justify-self: end; }
.lightbox__nav--next { justify-self: start; }

@keyframes page-arrive {
  from { opacity: 0; transform: scale(.985); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes childhood-open-left {
  0% {
    opacity: .42;
    transform: rotateY(88deg) translateX(2%);
    filter: brightness(.62);
  }
  74% {
    opacity: 1;
    transform: rotateY(-3deg) translateX(0);
    filter: brightness(.98);
  }
  100% {
    opacity: 1;
    transform: rotateY(0deg);
    filter: brightness(1);
  }
}

@keyframes childhood-open-right {
  0% {
    opacity: .42;
    transform: rotateY(-88deg) translateX(-2%);
    filter: brightness(.62);
  }
  74% {
    opacity: 1;
    transform: rotateY(3deg) translateX(0);
    filter: brightness(.98);
  }
  100% {
    opacity: 1;
    transform: rotateY(0deg);
    filter: brightness(1);
  }
}

@keyframes childhood-piece-settle {
  0% {
    opacity: 0;
    translate: 0 -2.2%;
    scale: .975;
  }
  65% { opacity: 1; }
  100% {
    opacity: 1;
    translate: 0 0;
    scale: 1;
  }
}

@keyframes lightbox-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes book-art-reveal {
  0%, 78% { opacity: 0; }
  79%, 100% { opacity: 1; }
}

@keyframes open-left-page {
  0% {
    opacity: .5;
    transform: rotateY(82deg) translateX(2%);
    filter: brightness(.58) drop-shadow(-14px 18px 24px rgba(0,0,0,.52));
  }
  72% {
    opacity: 1;
    transform: rotateY(0deg) translateX(0);
    filter: brightness(1) drop-shadow(0 18px 24px rgba(0,0,0,.36));
  }
  99% { opacity: 1; }
  100% { opacity: 0; transform: rotateY(0deg); }
}

@keyframes open-right-page {
  0% {
    opacity: .5;
    transform: rotateY(-82deg) translateX(-2%);
    filter: brightness(.58) drop-shadow(14px 18px 24px rgba(0,0,0,.52));
  }
  72% {
    opacity: 1;
    transform: rotateY(0deg) translateX(0);
    filter: brightness(1) drop-shadow(0 18px 24px rgba(0,0,0,.36));
  }
  99% { opacity: 1; }
  100% { opacity: 0; transform: rotateY(0deg); }
}

.app { width: 100%; padding: 12px 12px 36px; }
.screen { width: min(calc(100vw - 24px), calc((100dvh - 48px) * 16 / 9)); }
.screen--tear { width: min(calc(100vw - 24px), calc((100dvh - 48px) * 1663 / 946)); }
.app:has(.screen--tear) {
  display: block; height: auto; min-height: 100dvh; padding: 0;
  background: #e9e7e4; overflow: visible;
}
body:has(.screen--tear) { overflow-x: hidden; overflow-y: auto; }
.app .screen--tear { width: 100%; height: max(620px, 100dvh); aspect-ratio: auto; animation: none; }
.screen--tear .tear-canvas { position: absolute; inset: 0; }
body:has(.screen--tear) .slide-hint { color: #514b44; }
.lightbox { padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom)); }
.lightbox__image { max-width: 100%; max-height: calc(100dvh - 96px); }
.lightbox__figure { max-width: 80vw; }

@media (orientation: portrait) and (max-width: 1024px) {
  body { overflow: auto; }
  .app {
    display: grid; place-items: center; height: 100dvh;
    padding: 12px 8px 40px; overflow: hidden;
  }
  .screen--book { width: min(calc(100vw - 16px), calc((100dvh - 52px) * 16 / 9)); }
  .app .screen--tear { width: 100%; height: max(800px, 100dvh); }
  .lightbox { grid-template-columns: 1fr 1fr; gap: 12px; align-content: center; padding-inline: 12px; }
  .lightbox__figure { grid-column: 1 / -1; grid-row: 1; max-width: 100%; }
  .lightbox__image { max-width: 100%; max-height: calc(100dvh - 180px); }
  .lightbox__nav { grid-row: 2; width: 44px; height: 44px; font-size: 34px; }
  .lightbox__caption { text-align: center; font-size: 11px; }
}

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