:root {
  --ink: #29231f;
  --muted: #796e65;
  --line: rgba(92, 73, 57, 0.16);
  --accent: #9c6b5c;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: #e7e6e4;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: 'Songti SC', 'STSong', 'Noto Serif CJK SC', 'Source Han Serif SC', Georgia, serif;
  text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }
button, input { font: inherit; }

.gate-shell,
.letter-shell {
  position: relative;
  min-height: 100svh;
  background: #eee8df;
}

.gate-shell {
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 16%, rgba(218, 164, 139, 0.3), transparent 31rem),
    radial-gradient(circle at 82% 82%, rgba(115, 141, 160, 0.2), transparent 34rem),
    linear-gradient(145deg, #f3ece3 0%, #e9e4df 50%, #dce3e6 100%);
}

.gate-glow {
  position: fixed;
  border-radius: 999px;
  filter: blur(18px);
  pointer-events: none;
}

.gate-glow-one {
  width: 280px;
  height: 280px;
  top: -100px;
  left: -70px;
  background: rgba(214, 148, 121, 0.22);
}

.gate-glow-two {
  width: 340px;
  height: 340px;
  right: -110px;
  bottom: -140px;
  background: rgba(113, 142, 160, 0.18);
}

.gate-card {
  position: relative;
  width: min(100%, 440px);
  padding: clamp(34px, 7vw, 52px);
  border: 1px solid rgba(255, 255, 255, 0.66);
  border-radius: 28px;
  background: rgba(255, 252, 247, 0.78);
  box-shadow: 0 30px 90px rgba(77, 61, 49, 0.15);
  backdrop-filter: blur(24px);
}

.gate-kicker {
  margin: 0 0 16px;
  color: var(--accent);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.22em;
}

.eyebrow {
  margin: 0 0 16px;
  color: var(--accent);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(15px, 2.6vw, 18px);
  font-weight: 650;
  letter-spacing: 0.18em;
}

.gate-card h1 {
  margin: 0;
  font-size: clamp(27px, 7vw, 37px);
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.38;
}

.gate-intro {
  margin: 14px 0 30px;
  color: var(--muted);
  font-size: 15px;
}

.gate-form { display: grid; gap: 12px; }

.gate-form label {
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.08em;
}

.gate-form input {
  width: 100%;
  height: 50px;
  border: 1px solid rgba(92, 73, 57, 0.2);
  border-radius: 13px;
  outline: none;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.gate-form input:focus {
  border-color: rgba(156, 107, 92, 0.72);
  box-shadow: 0 0 0 4px rgba(156, 107, 92, 0.1);
}

.gate-form button {
  height: 50px;
  margin-top: 4px;
  border: 0;
  border-radius: 13px;
  background: #403731;
  color: #fffaf4;
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.gate-form button:disabled { cursor: not-allowed; opacity: 0.58; }

.gate-message {
  min-height: 20px;
  margin: 0;
  color: #a24e46;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
}

.letter-shell {
  --scroll-progress: 0;
  isolation: isolate;
  overflow: clip;
  padding: 82px 16px clamp(42px, 9vw, 110px);
}

.background-layer,
.paper-texture {
  position: fixed;
  inset: 0;
  z-index: -3;
  pointer-events: none;
}

.background-warm {
  background:
    radial-gradient(circle at 15% 8%, rgba(222, 157, 127, 0.34), transparent 34rem),
    radial-gradient(circle at 86% 34%, rgba(234, 203, 166, 0.3), transparent 36rem),
    linear-gradient(150deg, #f5eee5 0%, #eee4da 48%, #e8dfd7 100%);
  opacity: calc(1 - var(--scroll-progress) * 0.72);
}

.background-cool {
  background:
    radial-gradient(circle at 12% 70%, rgba(117, 144, 158, 0.22), transparent 36rem),
    radial-gradient(circle at 88% 90%, rgba(94, 116, 137, 0.26), transparent 34rem),
    linear-gradient(155deg, #e8e8e4 0%, #dce4e7 48%, #ccd6dc 100%);
  opacity: calc(var(--scroll-progress) * 0.92);
}

.paper-texture {
  z-index: -2;
  opacity: 0.2;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.17) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.12) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(to bottom, black, transparent 72%);
}

.reading-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  height: 3px;
  background: rgba(255, 255, 255, 0.32);
}

.reading-progress span {
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left;
  background: linear-gradient(90deg, #bd806d, #728c9c);
}

.letter-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: min(100%, 1040px);
  margin: 0 auto 16px;
  padding: 0 6px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 15px;
  font-weight: 650;
}

.toolbar-label { color: rgba(59, 50, 44, 0.56); letter-spacing: 0.08em; }

.toolbar-link {
  border: 0;
  color: rgba(59, 50, 44, 0.7);
  cursor: pointer;
}

.toolbar-link { padding: 8px 0; background: transparent; }
.toolbar-link:hover { text-decoration: underline; text-underline-offset: 4px; }

.letter-paper {
  position: relative;
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: clamp(42px, 8vw, 82px) clamp(20px, 3vw, 34px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.letter-heading h1 {
  margin: 0;
  font-size: clamp(22px, 4vw, 30px);
  font-weight: 600;
  letter-spacing: 0.05em;
}

.heading-rule {
  display: block;
  width: 96px;
  height: 1px;
  margin: 24px 0 40px;
  background: var(--accent);
}

.letter-copy {
  font-size: clamp(17px, 2.3vw, 19px);
  line-height: 2.05;
  letter-spacing: 0.025em;
  user-select: text;
}

.letter-copy p {
  margin: 0 0 1.5em;
  color: var(--ink);
  -webkit-text-fill-color: currentColor;
  white-space: pre-line;
  text-wrap: pretty;
}
.letter-copy p:last-child { margin-bottom: 0; }

.story-scene {
  position: relative;
  width: min(1040px, calc(100vw - 32px));
  margin: clamp(46px, 7vw, 76px) 50% clamp(28px, 5vw, 48px);
  background: transparent;
  transform: translateX(-50%);
  content-visibility: auto;
  contain-intrinsic-size: 1040px 585px;
}

.story-scene::before {
  display: none;
}

.story-scene img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1672 / 941;
  object-fit: contain;
  -webkit-mask-image: url('./illustrations/edge-fade-mask.png?v=20260824-0013');
  -webkit-mask-position: center;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-image: url('./illustrations/edge-fade-mask.png?v=20260824-0013');
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: 100% 100%;
}

.story-scene--joined {
  margin-top: clamp(-24px, -2vw, -10px);
}

.story-scene--dark img {
  filter: brightness(1.035) saturate(0.92);
}

.story-scene + p {
  position: relative;
  z-index: 1;
  margin-top: -0.85em;
  text-shadow: none;
}

.next-letter,
.second-letter-footer {
  margin-top: clamp(52px, 10vw, 88px);
  padding-top: clamp(30px, 6vw, 44px);
  border-top: 1px solid var(--line);
  text-align: center;
}

.next-letter p {
  margin: 0 0 10px;
  color: var(--accent);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(17px, 2.6vw, 20px);
  font-weight: 500;
  letter-spacing: 0.03em;
  line-height: 1.8;
}

.music-player {
  position: fixed;
  z-index: 50;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.music-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  width: 0;
  height: 58px;
  max-width: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 19px;
  padding: 0;
  background: rgba(255, 252, 247, 0.93);
  box-shadow: 0 14px 40px rgba(62, 51, 43, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateX(12px) scale(0.96);
  transform-origin: right center;
  backdrop-filter: blur(18px);
  transition:
    width 260ms ease,
    max-width 260ms ease,
    padding 260ms ease,
    opacity 180ms ease,
    transform 260ms ease;
}

.music-player.is-expanded .music-panel {
  width: min(300px, calc(100vw - 82px));
  max-width: min(300px, calc(100vw - 82px));
  padding: 0 12px 0 16px;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0) scale(1);
}

.music-meta {
  min-width: 0;
  padding-right: 8px;
}

.music-title,
.music-artist {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.music-title {
  color: #3e342e;
  font-size: 13px;
  font-weight: 680;
  letter-spacing: 0.02em;
}

.music-artist {
  margin-top: 3px;
  color: rgba(62, 52, 46, 0.56);
  font-size: 10px;
  letter-spacing: 0.04em;
}

.music-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}

.music-controls button,
.music-toggle {
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.music-controls button {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: transparent;
  color: rgba(62, 52, 46, 0.72);
}

.music-controls button:hover { background: rgba(156, 107, 92, 0.1); }
.music-controls svg { width: 19px; height: 19px; fill: currentColor; }

.music-controls .music-play {
  width: 32px;
  height: 32px;
  background: #403731;
  color: #fffaf4;
}

.music-controls .music-play:hover { background: #574941; }
.icon-pause { display: none; }
.music-player.is-playing .icon-play { display: none; }
.music-player.is-playing .icon-pause { display: block; }

.music-progress {
  position: absolute;
  right: 15px;
  bottom: 7px;
  left: 16px;
  height: 2px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(92, 73, 57, 0.1);
}

.music-progress i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #bd806d, #728c9c);
  transform: scaleX(0);
  transform-origin: left;
}

.music-toggle {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(64, 55, 49, 0.94);
  color: #fffaf4;
  box-shadow: 0 10px 32px rgba(62, 51, 43, 0.22);
  transition: transform 180ms ease, background 180ms ease;
  backdrop-filter: blur(14px);
}

.music-toggle:hover { background: #574941; transform: translateY(-1px); }
.music-toggle:active { transform: translateY(0) scale(0.96); }

.music-disc {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 250, 244, 0.3);
  border-radius: 50%;
}

.music-disc svg { width: 17px; height: 17px; fill: currentColor; }

.music-player.is-playing .music-disc {
  animation: music-pulse 2.8s ease-in-out infinite;
}

@keyframes music-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 250, 244, 0.08); }
  50% { box-shadow: 0 0 0 5px rgba(255, 250, 244, 0.12); }
}

.next-letter button,
.second-letter-footer button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  margin-top: 24px;
  border: 0;
  border-radius: 999px;
  padding: 0 24px;
  background: #403731;
  color: #fffaf4;
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

::selection { background: rgba(203, 149, 124, 0.3); }

@media (max-width: 560px) {
  .gate-card { border-radius: 22px; }
  .letter-shell { padding: 74px 12px 38px; }
  .letter-toolbar { padding-inline: 0; }
  .letter-paper {
    padding-inline: 12px;
  }
  .letter-copy { line-height: 1.95; }
  .letter-copy p { text-wrap: wrap; }
  .story-scene {
    width: calc(100vw - 24px);
    margin-top: 2.5em;
    margin-bottom: 1.9em;
    contain-intrinsic-size: 388px 218px;
  }
  .story-scene::before {
    inset: -22px -18px -58px;
    filter: blur(28px) saturate(0.76);
    opacity: 0.14;
  }
  .story-scene--dark::before { opacity: 0.055; }
  .music-player {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
  }
  .music-player.is-expanded .music-panel {
    width: min(274px, calc(100vw - 72px));
    max-width: min(274px, calc(100vw - 72px));
  }
  .music-toggle { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
