:root {
  color-scheme: dark;
  --ink: #000;
  --paper: #effcff;
  --rose: #5ab2ff;
  --gold: #1c68ff;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--paper);
  font-family: Georgia, "Times New Roman", "Songti SC", STSong, serif;
  overscroll-behavior: none;
}

.scene {
  position: fixed;
  inset: 0;
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 57%, rgba(19, 86, 205, 0.3), transparent 32%),
    #000;
}

#tree-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
}

#tree-canvas.is-dragging {
  cursor: grabbing;
}

.atmosphere {
  position: absolute;
  z-index: 0;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(70px);
  opacity: 0;
  animation: atmosphere-in 2.8s ease-out 0.7s forwards;
}

.atmosphere--rose {
  left: 50%;
  top: 48%;
  width: 34vw;
  height: 52vh;
  min-width: 240px;
  min-height: 320px;
  background: rgba(49, 143, 255, 0.16);
  transform: translate(-50%, -50%);
}

.atmosphere--gold {
  left: 50%;
  bottom: 6%;
  width: 42vw;
  height: 18vh;
  min-width: 260px;
  background: rgba(121, 207, 255, 0.11);
  transform: translateX(-50%);
}

.vignette {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.2) 72%, #000 105%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.2), transparent 20%, transparent 78%, #000 100%);
}

.scene-title {
  position: absolute;
  z-index: 4;
  top: 22px;
  left: 50%;
  width: min(92vw, 760px);
  text-align: center;
  pointer-events: none;
  transform: translateX(-50%);
  opacity: 0;
  animation: title-in 1.6s ease-out 0.35s forwards;
}

.scene-title h1 {
  margin: 0;
  color: #f1fbff;
  font-size: clamp(34px, 4.8vw, 68px);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.035em;
  text-shadow:
    0 0 2px rgba(255, 255, 255, 0.95),
    0 0 14px rgba(121, 207, 255, 0.52),
    0 0 42px rgba(49, 143, 255, 0.3);
}

.scene-title p {
  margin: clamp(10px, 1.5vh, 17px) 0 0;
  color: rgba(184, 228, 255, 0.66);
  font-family: "Courier New", monospace;
  font-size: clamp(7px, 0.66vw, 10px);
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-shadow: 0 0 12px rgba(121, 207, 255, 0.34);
}

.interaction-hint {
  position: absolute;
  z-index: 4;
  bottom: 20px;
  left: 50%;
  margin: 0;
  color: rgba(219, 244, 255, 0.32);
  font-family: "Courier New", monospace;
  font-size: 9px;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  pointer-events: none;
  transform: translateX(-50%);
  animation: hint-in 1.1s ease-out 5.8s both;
}

.memory-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.memory-photo {
  --card-width: clamp(52px, 4.9vw, 72px);
  --photo-tilt: 0deg;
  position: absolute;
  width: var(--card-width);
  margin: 0;
  padding: 1px 1px 7px;
  border: 1px solid rgba(171, 226, 255, 0.3);
  border-radius: 2px;
  background:
    linear-gradient(155deg, rgba(236, 251, 255, 0.94), rgba(183, 220, 241, 0.9));
  box-shadow:
    0 7px 18px rgba(0, 0, 0, 0.54),
    0 0 12px rgba(35, 137, 255, 0.16);
  color: #214f72;
  font-family: Georgia, "Times New Roman", "Songti SC", STSong, serif;
  cursor: zoom-in;
  pointer-events: auto;
  transform: translate(-50%, -50%) rotate(var(--photo-tilt));
  transform-origin: center;
  opacity: 0;
  visibility: hidden;
  transition:
    transform 280ms ease,
    box-shadow 280ms ease,
    border-color 280ms ease;
  animation: photo-reveal 1450ms cubic-bezier(0.22, 0.72, 0.2, 1)
    var(--photo-delay) forwards;
}

.memory-photo:hover,
.memory-photo:focus-visible {
  z-index: 2;
  border-color: rgba(207, 242, 255, 0.68);
  box-shadow:
    0 10px 25px rgba(0, 0, 0, 0.62),
    0 0 18px rgba(58, 169, 255, 0.27);
  transform: translate(-50%, -50%) rotate(var(--photo-tilt)) scale(1.045);
  outline: none;
}

.memory-photo__float {
  display: block;
  animation: photo-float var(--float-duration, 5.8s) ease-in-out
    var(--float-delay, 0s) infinite alternate;
}

.memory-photo__frame {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 1;
  border-radius: 2px;
  background:
    radial-gradient(circle at 48% 43%, rgba(97, 184, 255, 0.7), transparent 55%),
    #06111e;
}

.memory-photo__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.9) contrast(1.03) brightness(0.95);
}

.memory-photo__caption {
  position: absolute;
  right: 2px;
  bottom: 1px;
  left: 2px;
  overflow: hidden;
  color: rgba(24, 67, 98, 0.76);
  font-size: clamp(5px, 0.4vw, 6px);
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-photo.is-missing .memory-photo__float::before {
  position: absolute;
  inset: 7px 7px 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(123, 199, 255, 0.45);
  border-radius: 2px;
  background:
    radial-gradient(circle at center, rgba(57, 151, 255, 0.32), transparent 66%),
    #07111f;
  color: rgba(209, 241, 255, 0.82);
  content: "★";
  font-size: 25px;
}

.memory-viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 28px;
}

.memory-viewer[hidden] {
  display: none;
}

.memory-viewer__backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 48%, rgba(25, 92, 166, 0.2), transparent 44%),
    rgba(0, 4, 10, 0.9);
  backdrop-filter: blur(12px);
}

.memory-viewer__card {
  position: relative;
  max-width: min(780px, 76vw);
  max-height: 84vh;
  margin: 0;
  padding: 3px 3px 27px;
  border: 1px solid rgba(188, 229, 252, 0.34);
  border-radius: 3px;
  background:
    linear-gradient(155deg, rgba(244, 253, 255, 0.99), rgba(191, 223, 242, 0.98));
  box-shadow:
    0 34px 100px rgba(0, 0, 0, 0.82),
    0 0 58px rgba(58, 169, 255, 0.21);
  transform-origin: center;
  will-change: transform, opacity;
}

.memory-viewer__image {
  display: block;
  max-width: 100%;
  max-height: calc(84vh - 44px);
  border-radius: 2px;
  object-fit: contain;
  filter: saturate(0.94) contrast(1.02);
}

.memory-viewer__caption {
  position: absolute;
  right: 10px;
  bottom: 7px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #1d4b6d;
  font-size: clamp(12px, 1.1vw, 16px);
  letter-spacing: 0.08em;
  text-align: left;
}

.memory-viewer__caption-line {
  width: 28px;
  height: 1px;
  flex: 0 0 auto;
  background: rgba(48, 138, 211, 0.6);
}

.memory-viewer__close {
  position: absolute;
  z-index: 2;
  top: -17px;
  right: -17px;
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(196, 235, 255, 0.72);
  border-radius: 50%;
  background: rgba(4, 20, 36, 0.94);
  box-shadow: 0 0 22px rgba(56, 161, 255, 0.28);
  color: #eafaff;
  font: 25px/1 Georgia, serif;
  cursor: pointer;
}

.memory-viewer__close:hover,
.memory-viewer__close:focus-visible {
  border-color: #dff8ff;
  outline: none;
  box-shadow: 0 0 28px rgba(83, 188, 255, 0.52);
}

.noscript {
  position: absolute;
  z-index: 10;
  top: 50%;
  left: 50%;
  margin: 0;
  color: #fff;
  transform: translate(-50%, -50%);
}

@keyframes title-in {
  from {
    opacity: 0;
    transform: translate(-50%, -10px);
    filter: blur(5px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
    filter: blur(0);
  }
}

@keyframes atmosphere-in {
  to {
    opacity: 1;
  }
}

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

@keyframes photo-reveal {
  from {
    opacity: 0;
    filter: blur(3px);
    visibility: visible;
    transform: translate(-50%, calc(-50% + 18px)) rotate(var(--photo-tilt))
      scale(0.975);
  }
  to {
    opacity: 1;
    filter: blur(0);
    visibility: visible;
    transform: translate(-50%, -50%) rotate(var(--photo-tilt)) scale(1);
  }
}

@keyframes photo-float {
  from {
    transform: translateY(-1.5px) rotate(-0.12deg);
  }
  to {
    transform: translateY(2px) rotate(0.12deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .scene-title,
  .atmosphere,
  .interaction-hint,
  .memory-photo,
  .memory-photo__float {
    animation-duration: 0.01ms;
    animation-delay: 0ms;
  }
}
