:root {
  --outer-blue: #b4c3d3;
  --ink-blue: #71869a;
  --ink-red: #b86560;
  --print: "American Typewriter", "Courier New", Courier, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--outer-blue);
}

button,
video {
  font: inherit;
}

#background-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  isolation: isolate;
}

#ending-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* 唯一动态层：烟花/花瓣位于场景最上层，覆盖在相片、文字与电视之上；
   canvas 不拦截指针，相片放大与电视点击仍可正常触发。 */
#ending-canvas {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* 背景之外的所有元素独立排版，不再缩放一张固定比例舞台。 */
#ending-stage {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: visible;
  pointer-events: none;
}

.wish {
  pointer-events: none;
}

.ending-copy {
  pointer-events: auto;
}

.ending-copy,
.wish,
.decor {
  z-index: 3;
}

.ending-copy {
  position: absolute;
  top: clamp(90px, 15vh, 160px);
  left: 50%;
  width: min(62vw, 920px);
  color: var(--ink-blue);
  text-align: center;
  transform: translateX(-50%);
}

.ending-copy h1,
.ending-copy p {
  margin: 0;
  font-family: var(--print);
  font-weight: 600;
  text-transform: uppercase;
}

.ending-copy h1 {
  font-size: clamp(27px, 2.5vw, 43px);
  line-height: 1;
  letter-spacing: 0.25em;
  white-space: nowrap;
}

.copy-rule {
  display: block;
  width: 91%;
  height: clamp(1px, 0.18vw, 3px);
  margin: clamp(7px, 0.7vw, 12px) auto clamp(5px, 0.5vw, 9px);
  background: var(--ink-red);
  clip-path: polygon(0 34%, 7% 20%, 16% 39%, 24% 22%, 33% 42%, 44% 26%, 55% 44%, 67% 21%, 79% 38%, 90% 25%, 100% 45%, 100% 70%, 88% 56%, 76% 74%, 64% 55%, 51% 73%, 39% 54%, 28% 72%, 16% 53%, 6% 69%, 0 61%);
  opacity: 0.82;
}

.ending-copy p {
  font-size: clamp(11px, 0.96vw, 16px);
  line-height: 1.65;
  letter-spacing: 0.52em;
}

.wish {
  position: absolute;
  display: block;
  aspect-ratio: 3 / 1;
  filter: drop-shadow(2px 4px 4px rgba(72, 57, 45, 0.15));
}

.wish img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
}

.wish-health {
  top: 39%;
  left: clamp(42px, 7vw, 118px);
  width: clamp(270px, 23vw, 390px);
  transform: rotate(-3.2deg);
}

.wish-joy {
  top: 51%;
  right: clamp(38px, 5.5vw, 94px);
  width: clamp(305px, 26vw, 445px);
  transform: rotate(2.4deg);
}

.wish-smile {
  bottom: clamp(66px, 10vh, 96px);
  left: clamp(46px, 8vw, 136px);
  width: clamp(250px, 21vw, 355px);
  transform: rotate(2deg);
}

.wish-dream {
  bottom: clamp(42px, 7vh, 70px);
  right: clamp(42px, 6vw, 102px);
  width: clamp(320px, 28vw, 465px);
  transform: rotate(-2.2deg);
}

.tv-stage {
  position: absolute;
  top: 45%;
  left: 50%;
  width: clamp(390px, 32vw, 540px);
  aspect-ratio: 1170 / 870;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  cursor: zoom-in;
  pointer-events: auto;
  z-index: 4;
  transform: translateX(-50%);
  filter: drop-shadow(5px 10px 11px rgba(60, 44, 31, 0.2));
}

.decor {
  position: absolute;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.photo-scatter {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.quote-photo {
  position: absolute;
  left: var(--photo-x);
  top: var(--photo-y);
  width: var(--photo-w);
  margin: 0;
  padding: 6px 6px 18px;
  border: 1px solid rgba(119, 102, 83, 0.16);
  background: #fffdf7;
  box-shadow:
    0 8px 17px rgba(69, 53, 43, 0.16),
    0 2px 4px rgba(69, 53, 43, 0.12);
  transform: rotate(var(--photo-rotate));
  transform-origin: center;
  opacity: 0.96;
  appearance: none;
  font: inherit;
  cursor: zoom-in;
  pointer-events: auto;
  z-index: var(--photo-z);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.quote-photo:hover,
.quote-photo:focus-visible {
  z-index: 40;
  outline: 2px solid rgba(113, 134, 154, 0.62);
  outline-offset: 3px;
  transform: rotate(var(--photo-rotate)) translateY(-4px) scale(1.04);
  box-shadow:
    0 13px 24px rgba(69, 53, 43, 0.23),
    0 3px 6px rgba(69, 53, 43, 0.14);
}

.quote-photo img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  background: #f5f1e8;
}

.quote-photo::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: 8px;
  width: 22%;
  height: 1px;
  background: rgba(113, 134, 154, 0.32);
}

.decor-date {
  top: clamp(38px, 5vh, 58px);
  left: clamp(38px, 5vw, 84px);
  width: clamp(165px, 17vw, 275px);
  transform: rotate(-4deg);
  filter: drop-shadow(2px 5px 5px rgba(64, 50, 40, 0.18));
}

.decor-stamp {
  top: clamp(32px, 4vh, 50px);
  right: clamp(38px, 5vw, 84px);
  width: clamp(100px, 10vw, 150px);
  transform: rotate(4deg);
}

.decor-star {
  top: clamp(115px, 14vh, 150px);
  right: clamp(118px, 13vw, 205px);
  width: clamp(38px, 3.5vw, 58px);
  transform: rotate(-8deg);
}

.tv-shell {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.tv-screen {
  position: absolute;
  top: 17.7%;
  left: 9.4%;
  z-index: 3;
  width: 61.2%;
  height: 60.1%;
  overflow: hidden;
  border-radius: 12% / 10%;
  background: #17232c;
  clip-path: polygon(3% 2%, 95% 1%, 99% 7%, 100% 91%, 96% 98%, 4% 99%, 1% 93%, 0 8%);
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.55);
}

.tv-video-poster,
.tv-screen video {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.tv-video-poster {
  z-index: 1;
  opacity: 1;
  transition: opacity 180ms ease;
}

.tv-screen video {
  z-index: 2;
  opacity: 0;
  background: transparent;
  transition: opacity 180ms ease;
}

.tv-screen.has-video-frame video {
  opacity: 1;
}

.tv-screen.has-video-frame .tv-video-poster {
  opacity: 0;
}

.ending-copy:focus-visible {
  outline: 2px dashed rgba(125, 145, 163, 0.75);
  outline-offset: 8px;
}

body.replayable .ending-copy {
  cursor: pointer;
}

.video-modal[hidden] {
  display: none;
}

.video-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: clamp(20px, 5vw, 72px);
  background: rgba(32, 29, 28, 0.82);
  backdrop-filter: blur(8px);
}

.video-modal video {
  display: block;
  width: min(88vw, 1180px);
  max-height: 82vh;
  border: 10px solid #eee2c9;
  border-radius: 8px;
  background: #10171d;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
}

.modal-close {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  z-index: 41;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  color: #fff;
  background: rgba(0, 0, 0, 0.38);
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
}

.photo-modal[hidden] {
  display: none;
}

.photo-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: minmax(44px, 1fr) minmax(0, auto) minmax(44px, 1fr);
  align-items: center;
  gap: clamp(10px, 2.5vw, 32px);
  padding: clamp(58px, 7vw, 92px) clamp(16px, 4vw, 64px) clamp(24px, 5vw, 64px);
  background: rgba(32, 29, 28, 0.84);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.video-modal:focus,
.photo-modal:focus {
  outline: none;
}

.photo-modal-card {
  grid-column: 2;
  max-width: min(78vw, 980px);
  max-height: 84vh;
  margin: 0;
  padding: clamp(9px, 1.2vw, 16px) clamp(9px, 1.2vw, 16px) clamp(32px, 4vw, 52px);
  overflow: hidden;
  background: #fffdf7;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
}

.photo-modal-card img {
  display: block;
  max-width: min(72vw, 920px);
  max-height: calc(84vh - 76px);
  width: auto;
  height: auto;
  object-fit: contain;
  background: #f5f1e8;
}

.photo-modal-card figcaption {
  height: 0;
  color: #5f6870;
  font-family: var(--print);
  font-size: 14px;
  line-height: 32px;
  text-align: center;
  letter-spacing: 0.12em;
}

.photo-modal-nav {
  width: clamp(44px, 5vw, 60px);
  height: clamp(44px, 5vw, 60px);
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 50%;
  color: #fff;
  background: rgba(0, 0, 0, 0.32);
  font-size: clamp(34px, 4vw, 52px);
  line-height: 1;
  cursor: pointer;
}

.photo-modal-prev {
  justify-self: end;
}

.photo-modal-next {
  justify-self: start;
}

@media (max-aspect-ratio: 4 / 5) {
  .photo-modal {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 8px;
    padding: 68px 10px 24px;
  }

  .photo-modal-card {
    max-width: 100%;
  }

  .photo-modal-card img {
    max-width: 100%;
    max-height: calc(82vh - 70px);
  }
}

/* 窄电脑／接近方形窗口：元素重排，仍保持横向阅读。 */
@media (max-width: 1250px), (max-aspect-ratio: 4 / 3) {
  .ending-copy {
    top: 10%;
    width: min(72vw, 760px);
  }

  .ending-copy h1 {
    font-size: clamp(24px, 3.1vw, 38px);
  }

  .wish-health {
    top: 32%;
    left: 5%;
    width: clamp(250px, 31vw, 355px);
  }

  .wish-joy {
    top: 38%;
    right: 5%;
    width: clamp(285px, 35vw, 400px);
  }

  .tv-stage {
    top: 43%;
    width: clamp(370px, 46vw, 500px);
  }

  .wish-smile {
    bottom: 8%;
    left: 5%;
    width: clamp(235px, 30vw, 330px);
  }

  .wish-dream {
    bottom: 5%;
    right: 5%;
    width: clamp(295px, 38vw, 420px);
  }

}

/* 手机竖屏：独立纵向排版，不拉伸任何前景元素。 */
@media (max-aspect-ratio: 4 / 5) {
  #ending-bg {
    object-position: center;
  }

  .ending-copy {
    top: 14%;
    width: 88%;
  }

  .ending-copy h1 {
    font-size: clamp(23px, 4.45vw, 32px);
    letter-spacing: 0.16em;
  }

  .ending-copy p {
    font-size: clamp(11px, 2.08vw, 15px);
    letter-spacing: 0.32em;
  }

  .wish-health {
    top: 25%;
    left: 4%;
    width: 46%;
  }

  .wish-joy {
    top: 33%;
    right: 3%;
    width: 54%;
  }

  .tv-stage {
    top: 41%;
    width: 72%;
  }

  .wish-smile {
    top: 75%;
    bottom: auto;
    left: 4%;
    width: 46%;
  }

  .wish-dream {
    top: 84%;
    bottom: auto;
    right: 3%;
    width: 60%;
  }

  .decor-date {
    top: 4%;
    left: 4%;
    width: 31%;
  }

  .decor-stamp {
    top: 3.5%;
    right: 4%;
    width: 20%;
  }

  .decor-star {
    top: 9.5%;
    right: 19%;
    width: 7%;
  }

}

/* 很矮的横向浏览器：进一步压缩垂直间距。 */
@media (min-aspect-ratio: 4 / 5) and (max-height: 720px) {
  .ending-copy {
    top: 8%;
  }

  .wish-health {
    top: 34%;
  }

  .wish-joy {
    top: 43%;
  }

  .tv-stage {
    top: 40%;
    width: clamp(330px, 30vw, 455px);
  }

  .wish-smile {
    bottom: 5%;
  }

  .wish-dream {
    bottom: 3%;
  }
}

@media (max-width: 760px) {
  .video-modal {
    padding: 18px;
  }

  .video-modal video {
    width: 94vw;
    max-height: 86vh;
    border-width: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tv-video-poster,
  .tv-screen video {
    transition: none;
  }

  body.slide-leaving {
    animation: none;
  }
}
