/* 印 The end. A dark shrine: a shaft of light on the seal, faint stone and water lines, and a giant 重 drifting
   behind everything (drawn in the original but hidden there). The title on the left, the broken
   memory seal in the middle, the call to action on the right. The seal's shards are spread by one
   variable, --relic-break (1 = broken, 0 = whole). */

.end {
  position: relative;
  min-height: 690px;
  isolation: isolate;
  background: var(--surface-shrine);
  color: #e1e8d6;
}
.end-stage {
  position: relative;
  padding: 118px var(--pad) 64px;
  overflow: clip;
  isolation: isolate;
  background: var(--surface-shrine);
  color: #e1e8d6;
}

/* ---------- Atmosphere (behind everything) ---------- */
.end-atmosphere {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 53% 45%, #567d5740 0%, #18352c30 24%, transparent 57%),
    linear-gradient(110deg, #09120f, #11271c 58%, #08120f);
}
.end-mark {
  /* 重, the first kanji of kasane, rising and settling as the seal assembles */
  position: absolute;
  right: -3%;
  top: -6%;
  font: 800 var(--text-glyph) / 1 var(--font-display);
  color: #cfe6c2;
  opacity: 0.045;
  transform: translateY(var(--mark-y, 0px)) rotate(var(--mark-r, 0deg));
}
.end-stone {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.025;
  filter: grayscale(1) contrast(1.25) blur(1px);
  mix-blend-mode: screen;
  transform: scale(1.22);
  mask-image: linear-gradient(180deg, transparent, #000 28%, #000 72%, transparent);
}
.end-water {
  /* reflection lines: stripes laid flat with a 3D rotateX, faded at the edges with a mask */
  position: absolute;
  left: -20%;
  right: -20%;
  height: 46%;
  bottom: -21%;
  transform: perspective(500px) rotateX(62deg);
  background:
    repeating-linear-gradient(0deg, transparent 0 20px, #9bbe9825 21px, transparent 22px 43px),
    linear-gradient(90deg, transparent, #6e997d15, transparent);
  mask-image: radial-gradient(ellipse, #000 0%, transparent 66%);
  opacity: 0.65;
}

/* ---------- Layout: title, seal, call to action ---------- */
.end-layout {
  display: grid;
  grid-template-columns: 0.9fr 1.08fr 0.88fr;
  gap: 26px;
  align-items: center;
  margin-top: 42px;
}
.end h2 {
  position: relative;
  z-index: 2;
  perspective: 1000px;
}
.end-detail {
  position: relative;
  z-index: 2;
  max-width: 360px;
  clip-path: inset(var(--end-cut, 0%) 0 0 0); /* unmasked from the top */
  transform: translateY(var(--end-rise, 0px)); /* and rising (lost in v1 to a .reveal rule) */
}
.end-detail .line {
  margin-bottom: 20px;
  color: #e3ead8;
}
.end-detail > p:not(.line) {
  max-width: 320px;
  margin-bottom: 28px;
  color: #a9baab;
}
.end-fine {
  margin-top: 14px;
  font-size: var(--text-small);
  color: #7f978a;
}

/* ---------- The colophon: the page's last lines, at the foot of its last frame ----------
   No footer below the ending: once the seal is whole, there is nothing left to scroll to. */
.end-colophon {
  position: relative;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 6px;
  margin-top: 46px;
  padding-top: 16px;
  border-top: 1px solid #a7c0a72b;
  text-align: center;
}
.end-colophon-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 34px;
  color: #c9d3c3;
}
.end-colophon-note {
  font-size: var(--text-small);
  color: #7f978a;
}

/* ---------- The memory seal: an SVG drawing with a 3D canvas on top once it's ready ---------- */
.end-relic {
  position: relative;
  margin: 0;
  min-width: 0;
  perspective: 1000px;
  align-self: center;
}

/* ---------- The light: a shaft falling on the seal from an opening above ----------
   Gradients only. A cone (a conic gradient whose apex sits above the frame) with a brighter core
   and a glow where it enters, faded along its length by a mask. Dust drifts up through it, a pool of
   light lies on the plinth where it lands, and it breathes slowly. It hangs from the seal itself, so
   it follows the seal on every layout, and leans a little as the seal assembles (--shrine-light). */
.end-beam {
  position: absolute;
  left: 50%;
  bottom: 16%; /* the plinth */
  z-index: -1;
  width: min(980px, 170vw);
  height: 170vh;
  pointer-events: none;
  transform-origin: 50% 100%; /* it pivots on the plinth, so the light always lands on the seal */
  transform: translateX(-50%) rotate(var(--shrine-light, 0deg));
  background:
    radial-gradient(ellipse 18% 6% at 50% 0, #f2ffeae6, transparent 75%),
    conic-gradient(from 176deg at 50% 0, transparent 0deg, #f4ffee5c 4deg, transparent 8deg),
    conic-gradient(
      from 167deg at 50% 0,
      transparent 0deg,
      #d4f2c81e 4deg,
      #e0f8d444 9deg,
      #eefee670 13deg,
      #e0f8d444 17deg,
      #d4f2c81e 22deg,
      transparent 26deg
    );
  -webkit-mask-image: linear-gradient(#000 0%, #000 45%, #0009 80%, transparent 100%);
  mask-image: linear-gradient(#000 0%, #000 45%, #0009 80%, transparent 100%);
  animation: beam-breathe 7s ease-in-out infinite alternate;
}
@keyframes beam-breathe {
  from {
    opacity: 0.82;
  }
  to {
    opacity: 1;
  }
}
/* dust in the light: two dotted layers drifting up at different speeds, seen only inside the cone */
.end-dust {
  position: absolute;
  inset: 0;
  overflow: hidden;
  -webkit-mask-image: conic-gradient(from 167deg at 50% 0, transparent 0deg, #000 7deg, #000 19deg, transparent 26deg);
  mask-image: conic-gradient(from 167deg at 50% 0, transparent 0deg, #000 7deg, #000 19deg, transparent 26deg);
}
.end-dust::before,
.end-dust::after {
  content: "";
  position: absolute;
  inset: 0 0 -100%;
  background:
    radial-gradient(circle at 24px 40px, #f2ffe8d0 1.2px, transparent 2px),
    radial-gradient(circle at 120px 150px, #f2ffe8a0 1px, transparent 1.6px),
    radial-gradient(circle at 190px 80px, #f2ffe8c0 1.4px, transparent 2.2px),
    radial-gradient(circle at 70px 210px, #f2ffe890 0.9px, transparent 1.5px);
  background-size: 240px 260px;
  animation: dust-rise 34s linear infinite;
}
.end-dust::after {
  background-size: 330px 380px;
  opacity: 0.55;
  filter: blur(0.8px);
  animation-duration: 52s;
}
@keyframes dust-rise {
  to {
    transform: translateY(-50%);
  }
}
/* the pool of light on the plinth, behind the 3D seal (its canvas is transparent) */
.end-pool {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 4%;
  height: 24%;
  background: radial-gradient(closest-side, #e2fad27a, #9cd49a33 50%, transparent);
  filter: blur(6px);
  pointer-events: none;
}
/* and a faint haze over the top of the seal, so the shards look lit from above */
.end-relic::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -20%;
  width: 70%;
  height: 90%;
  background: radial-gradient(closest-side, #e6ffdc1c, transparent); /* soft on every side, no edge */
  transform: translateX(-50%);
  pointer-events: none;
}
.relic-trigger {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  text-align: left;
  color: #adcaab;
}
.relic-space {
  position: relative;
  transform: perspective(1000px) rotateY(var(--relic-turn, 0deg));
  transition: filter 0.4s;
}
.relic-trigger:is(:hover, :focus-visible) .relic-space {
  filter: brightness(1.2);
}
.relic-art {
  display: block;
  width: 100%;
  height: clamp(350px, 48svh, 540px);
  overflow: visible;
  filter: drop-shadow(0 17px 15px #0005);
}
.relic-hover {
  animation: relic-breathe 7s ease-in-out infinite;
  animation-play-state: paused;
}
.shrine-awake .relic-hover {
  animation-play-state: running; /* it only breathes while on screen */
}
@keyframes relic-breathe {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}
/* Each shard has its own direction (--shard-x/y/r in the SVG); --relic-break scales them all. */
.sigil-part {
  transform: translate3d(calc(var(--shard-x) * var(--relic-break, 0)), calc(var(--shard-y) * var(--relic-break, 0)), 0)
    rotate(calc(var(--shard-r) * var(--relic-break, 0)));
  transform-origin: 200px 255px;
}
.relic-inscription {
  opacity: calc(0.25 + var(--relic-assembled, 1) * 0.75);
  filter: drop-shadow(0 0 5px #bde7a2);
}
.seal-scene-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
}
.scene-ready .seal-scene-canvas {
  opacity: 1;
}
.scene-ready .relic-art {
  visibility: hidden;
}
.scene-ready .relic-space {
  transform: none !important;
}
.scene-ready .relic-trigger:is(:hover, :focus-visible) .relic-space {
  filter: brightness(1.07);
}
.relic-caption {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 12%;
  padding-top: 14px;
  color: #c9dcc0;
}
.relic-caption .icon {
  width: 20px;
  height: 20px;
  color: var(--shu);
}

/* ---------- Tall desktop: the shrine pins and centres ---------- */
@media (min-width: 761px) and (min-height: 780px) {
  .end-stage {
    position: sticky;
    top: 0;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    padding-bottom: 26px;
  }
  /* the chapter sits in the middle of the frame, the colophon at its foot */
  .end-stage > .chapter-mark,
  .end-colophon {
    margin-top: auto;
  }
}

/* ---------- Tablet: seal on the right, title and copy stacked on the left ---------- */
@media (min-width: 761px) and (max-width: 1100px) {
  .end-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "title relic" "detail relic";
    gap: 30px 50px;
    margin-top: 34px;
  }
  .end h2 {
    grid-area: title;
  }
  .end-detail {
    grid-area: detail;
  }
  .end-relic {
    grid-area: relic;
  }
  .relic-art {
    height: 470px;
  }
}

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  .end {
    min-height: 0;
    scroll-margin-top: 70px;
  }
  .end-stage {
    padding: 84px 22px 56px;
  }
  .end-layout {
    grid-template-columns: 1fr;
    gap: 28px;
  }
  .end-relic {
    width: 100%;
    max-width: 340px;
    justify-self: center;
  }
  .relic-art {
    height: 360px;
  }
  .end-detail {
    max-width: none;
  }
  .end .btn {
    width: 100%;
  }
  .end-water {
    bottom: -11%;
    height: 28%;
  }
  .end-mark {
    top: 18%;
  }
  .end-colophon {
    margin-top: 56px;
  }
  .end-colophon-actions {
    flex-direction: column;
    align-items: center;
  }
}

/* ---------- Reduced motion: the seal whole and still ---------- */
html:is(.reduced, .compact-layout) .end-stage {
  position: relative;
  min-height: 0;
}
html:is(.reduced, .compact-layout) main .end-detail {
  transform: none !important;
  clip-path: none !important;
  opacity: 1 !important;
}
html:is(.reduced, .compact-layout) :is(.sigil-part, .relic-space, .end-mark) {
  transform: none !important;
}
html:is(.reduced, .compact-layout) .relic-hover {
  animation: none !important;
}
@media (prefers-reduced-motion: reduce) {
  .relic-hover {
    animation: none;
  }
  .sigil-part,
  .relic-space {
    transform: none !important;
  }
}
