:root {
  --night: oklch(0.24 0.055 16);
  --night-deep: oklch(0.18 0.043 18);
  --paper: oklch(0.965 0.018 72);
  --paper-edge: oklch(0.82 0.034 55 / 0.5);
  --ink: oklch(0.29 0.035 30);
  --muted: oklch(0.49 0.035 30);
  --red: oklch(0.43 0.13 22);
  --soft-red: oklch(0.67 0.075 18);
  --light: oklch(0.92 0.018 47);
  --line: oklch(0.67 0.055 27 / 0.35);
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  scroll-behavior: smooth;
  background: var(--night-deep);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--light);
  background:
    radial-gradient(circle at 82% 4%, oklch(0.48 0.09 19 / 0.25), transparent 30rem),
    var(--night-deep);
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", "SimSun", serif;
  overflow-x: hidden;
}

a { color: inherit; }

.js body:not(.is-open) { overflow: hidden; }

.qixi-shell {
  width: 100%;
  min-height: 100%;
}

.qixi-cover {
  min-height: 100dvh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: max(20px, env(safe-area-inset-top)) clamp(18px, 5vw, 54px) max(24px, env(safe-area-inset-bottom));
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.qixi-cover::before {
  content: "";
  position: absolute;
  z-index: -1;
  width: min(66vw, 760px);
  aspect-ratio: 1;
  right: min(-18vw, -120px);
  top: min(-20vw, -140px);
  border-radius: 999px;
  background: oklch(0.48 0.09 19 / 0.2);
  filter: blur(2px);
}

.quiet-nav {
  width: min(1120px, 100%);
  margin: 0 auto;
  min-height: 44px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  color: oklch(0.86 0.025 37 / 0.78);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.75rem;
}

.quiet-nav a,
.page-ending a {
  text-decoration: none;
  border-bottom: 1px solid oklch(0.82 0.04 33 / 0.42);
}

.quiet-nav a:focus-visible,
.start-reading:focus-visible,
.scroll-cue:focus-visible,
.page-ending a:focus-visible {
  outline: 3px solid var(--soft-red);
  outline-offset: 5px;
}

.qixi-hero {
  width: min(760px, 100%);
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(8px, 1.8vh, 18px);
  align-items: center;
  justify-items: center;
  padding: clamp(18px, 3.6vh, 38px) 0 0;
}

.hero-copy { text-align: center; }

.hero-copy > p:first-child {
  display: inline-block;
  margin: 0 0 12px;
  padding-bottom: 6px;
  color: oklch(0.79 0.065 26);
  border-bottom: 1px solid oklch(0.73 0.06 24 / 0.42);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.8rem;
}

.hero-copy h1 {
  max-width: none;
  margin: 0;
  color: oklch(0.94 0.025 46);
  font-size: clamp(2.45rem, 7vw, 4.9rem);
  line-height: 1.12;
  font-weight: 500;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.hero-intro {
  max-width: 34rem;
  margin: 16px auto 0;
  color: oklch(0.82 0.025 38 / 0.84);
  font-size: clamp(1rem, 2vw, 1.12rem);
  line-height: 1.9;
  text-wrap: pretty;
}

.start-reading {
  min-height: 44px;
  display: inline-grid;
  place-items: center;
  margin: clamp(10px, 1.8vh, 18px) auto 0;
  padding: 10px 20px;
  color: oklch(0.96 0.02 52);
  background: var(--red);
  border: 1px solid oklch(0.74 0.08 23 / 0.28);
  border-radius: 0;
  box-shadow: 0 7px 20px oklch(0.08 0.04 18 / 0.18);
  cursor: pointer;
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.9rem;
  text-decoration: none;
  transition:
    transform 140ms ease,
    background-color 220ms ease,
    box-shadow 220ms ease;
}

.start-reading:disabled { cursor: wait; }
.start-reading:active { transform: translateY(1px) scale(0.985); }

@media (hover: hover) {
  .start-reading:hover {
    background: oklch(0.48 0.14 22);
    box-shadow: 0 9px 24px oklch(0.08 0.04 18 / 0.26);
  }
}

.envelope-experience {
  width: 100%;
  min-width: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: end;
}

.envelope-stage {
  width: 100%;
  min-height: clamp(350px, 52vh, 560px);
  display: grid;
  place-items: end center;
  perspective: 1200px;
}

.envelope {
  position: relative;
  isolation: isolate;
  width: min(78vw, 420px);
  aspect-ratio: 1.55 / 1;
  margin-bottom: clamp(12px, 2vh, 24px);
  transform-style: preserve-3d;
  pointer-events: none;
}

.envelope-back,
.envelope-front,
.envelope-flap {
  position: absolute;
  inset: 0;
  background-color: var(--paper);
  background-image: url("../../assets/paper-texture.png");
  background-size: 540px auto;
}

.envelope-back {
  z-index: 0;
  border: 1px solid var(--paper-edge);
  box-shadow: 0 18px 32px oklch(0.07 0.035 18 / 0.34);
}

.envelope-letter {
  position: absolute;
  z-index: 2;
  left: 25%;
  bottom: 17%;
  width: 50%;
  transform: translateY(-30%);
  transform-origin: 50% 100%;
}

.bouquet { margin: 0; }

.bouquet img {
  display: block;
  width: 100%;
  aspect-ratio: 971 / 1619;
  object-fit: cover;
  border: 1px solid oklch(0.79 0.035 49 / 0.55);
  box-shadow: 0 12px 24px oklch(0.08 0.025 18 / 0.24);
}

.bouquet figcaption {
  margin: 12px 0 0;
  color: oklch(0.84 0.025 38 / 0.78);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.76rem;
  text-align: center;
}

.envelope-flap {
  z-index: 4;
  height: 57%;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: 50% 0;
  transform: rotateX(180deg);
  backface-visibility: hidden;
  border-top: 1px solid var(--paper-edge);
}

.envelope-front {
  z-index: 3;
  clip-path: polygon(0 0, 50% 44%, 100% 0, 100% 100%, 0 100%);
  border: 1px solid var(--paper-edge);
  filter: brightness(0.985);
}

.envelope-front::before,
.envelope-front::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 58%;
  height: 82%;
  border-top: 1px solid oklch(0.65 0.04 38 / 0.2);
}

.envelope-front::before {
  left: 0;
  transform: rotate(28deg) translate(-9%, 24%);
}

.envelope-front::after {
  right: 0;
  transform: rotate(-28deg) translate(9%, 24%);
}

.js .envelope-letter {
  opacity: 0;
  filter: blur(4px);
  transform: translateY(42%) scale(0.95);
}

.js .envelope-flap { transform: rotateX(0deg); }

.js .is-opening .envelope-flap,
.js .is-open .envelope-flap {
  z-index: 1;
  transform: rotateX(180deg);
  transition:
    transform 720ms var(--ease-out-quint),
    z-index 0s linear 360ms;
}

.js .is-opening .envelope-letter,
.js .is-open .envelope-letter {
  opacity: 1;
  filter: blur(0);
  transform: translateY(-30%) scale(1);
  transition:
    transform 1050ms var(--ease-out-expo) 480ms,
    opacity 500ms ease 470ms,
    filter 700ms ease 470ms;
}

.scroll-cue {
  width: fit-content;
  min-height: 44px;
  margin: 8px auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: oklch(0.84 0.025 38 / 0.78);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.78rem;
  text-decoration: none;
}

.scroll-cue[hidden] { display: none; }

.scroll-cue-mark {
  width: 9px;
  height: 9px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: rotate(45deg);
}

.js .scroll-cue:not([hidden]) {
  animation: cue-in 600ms var(--ease-out-quint) both;
}

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

@keyframes cue-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.qixi-letter {
  width: min(720px, 100%);
  margin: clamp(64px, 10vw, 112px) auto;
  padding: clamp(48px, 9vw, 84px) clamp(24px, 7vw, 64px) clamp(62px, 10vw, 96px);
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("../../assets/paper-texture.png");
  background-size: 540px auto;
  border: 1px solid var(--paper-edge);
  border-radius: 8px;
  box-shadow: 0 8px 8px oklch(0.08 0.025 18 / 0.24);
}

.letter-heading {
  margin-bottom: clamp(42px, 9vw, 70px);
  padding-bottom: 34px;
  border-bottom: 1px solid var(--line);
}

.letter-heading p {
  margin: 0 0 14px;
  color: var(--muted);
  font-family: "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 0.82rem;
}

.letter-heading h2 {
  margin: 0;
  color: var(--red);
  font-size: clamp(2.25rem, 7vw, 3.6rem);
  line-height: 1.2;
  font-weight: 500;
  text-wrap: balance;
}

.letter-body {
  max-width: 68ch;
  margin: 0 auto;
  font-size: clamp(1.04rem, 3.8vw, 1.18rem);
  line-height: 2.08;
  text-wrap: pretty;
}

.letter-body > p { margin: 0; }
.letter-body > p + p { margin-top: 1.08em; }

blockquote {
  margin: clamp(36px, 8vw, 54px) 0;
  padding: clamp(22px, 5vw, 32px);
  color: oklch(0.35 0.05 25);
  background: oklch(0.92 0.035 52 / 0.72);
  border: 1px solid oklch(0.67 0.06 31 / 0.3);
}

blockquote p { margin: 0; }

.confession {
  margin-block: clamp(42px, 9vw, 64px) !important;
  color: var(--red);
  font-size: clamp(2.2rem, 8vw, 4.3rem);
  line-height: 1.2;
  font-weight: 500;
  text-align: center;
}

.letter-ending {
  margin-top: clamp(56px, 11vw, 86px);
  padding-top: clamp(38px, 8vw, 56px);
  border-top: 1px solid var(--line);
}

.letter-ending p { margin: 0; }
.letter-ending p + p { margin-top: 1.08em; }
.letter-ending p:first-child { color: var(--red); font-size: 1.1em; }

.page-ending {
  width: min(720px, 100%);
  min-height: 44px;
  margin: clamp(36px, 8vw, 62px) auto 0;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  color: oklch(0.84 0.025 38 / 0.78);
  font-size: 0.84rem;
}

@media (max-width: 720px) {
  .quiet-nav { align-items: flex-start; }
  .quiet-nav span { max-width: 13em; text-align: right; }

  .qixi-hero {
    min-height: auto;
    gap: 4px;
    padding-top: clamp(14px, 3vh, 26px);
  }

  .hero-copy h1 { font-size: clamp(2.35rem, 11.5vw, 3.25rem); }

  .hero-intro {
    max-width: 22rem;
    font-size: 0.96rem;
    line-height: 1.72;
  }

  .envelope-stage {
    min-height: clamp(330px, 51vh, 440px);
  }

  .envelope {
    width: min(84vw, 350px);
    margin-bottom: 12px;
  }

  .envelope-letter {
    left: 25%;
    width: 50%;
  }

  .bouquet figcaption {
    font-size: 0.72rem;
  }

  .qixi-letter {
    width: calc(100% - 28px);
    border-radius: 6px;
    box-shadow: 0 6px 8px oklch(0.08 0.025 18 / 0.22);
  }

  .page-ending {
    width: calc(100% - 36px);
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  .start-reading,
  .envelope-flap,
  .envelope-letter,
  .scroll-cue {
    animation: none !important;
    transition: none !important;
  }
}
