:root {
  --bg-0: #05060b;
  --bg-1: #0b0d1a;
  --bg-2: #141328;
  --ink: #ece6d6;
  --ink-dim: #9a9384;
  --ink-fade: #5a5548;
  --accent: #d9a066;
  --accent-dim: #7a5d3f;
  --danger: #6b4a4a;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-slow: cubic-bezier(0.77, 0, 0.175, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% 20%, rgba(217, 160, 102, 0.08), transparent 50%),
    radial-gradient(ellipse at 50% 100%, rgba(40, 30, 60, 0.4), transparent 60%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  background-attachment: fixed;
  line-height: 1.9;
  letter-spacing: 0.05em;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ============ atmosphere layers ============ */

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0.18;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  animation: grainShift 8s steps(8) infinite;
}

@keyframes grainShift {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-3%, 2%); }
  40%  { transform: translate(2%, -1%); }
  60%  { transform: translate(-2%, 3%); }
  80%  { transform: translate(3%, -2%); }
  100% { transform: translate(0, 0); }
}

.dust {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image:
    radial-gradient(1px 1px at 17% 22%, rgba(236, 230, 214, 0.6), transparent 50%),
    radial-gradient(1px 1px at 73% 15%, rgba(236, 230, 214, 0.4), transparent 50%),
    radial-gradient(2px 2px at 42% 78%, rgba(236, 230, 214, 0.3), transparent 50%),
    radial-gradient(1px 1px at 88% 55%, rgba(236, 230, 214, 0.5), transparent 50%),
    radial-gradient(1px 1px at 25% 88%, rgba(236, 230, 214, 0.35), transparent 50%),
    radial-gradient(1px 1px at 60% 40%, rgba(236, 230, 214, 0.4), transparent 50%),
    radial-gradient(1px 1px at 10% 60%, rgba(236, 230, 214, 0.3), transparent 50%);
  background-size: 100% 100%;
  animation: dustFloat 40s linear infinite;
  opacity: 0.7;
}

@keyframes dustFloat {
  0%   { transform: translate3d(0, 0, 0); }
  50%  { transform: translate3d(-20px, -40px, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.7) 100%);
}

/* ============ stage & pages ============ */

.stage {
  position: relative;
  width: 100%;
  height: 100vh;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
}

.page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem 8rem;
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity 0.9s var(--ease-slow),
    transform 0.9s var(--ease-slow);
  pointer-events: none;
}

.page.is-active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.page.is-leaving {
  opacity: 0;
  transform: translateY(-16px);
}

.page.is-returning {
  opacity: 0;
  transform: translateY(-16px);
  animation: returnFlicker 0.6s var(--ease);
}

@keyframes returnFlicker {
  0%   { opacity: 0; filter: blur(4px); }
  30%  { opacity: 0.2; filter: blur(2px); }
  60%  { opacity: 0.1; filter: blur(3px); }
  100% { opacity: 0; filter: blur(0); }
}

/* ============ title ============ */

.title {
  font-weight: 300;
  font-size: clamp(2rem, 6vw, 4.5rem);
  text-align: center;
  letter-spacing: 0.15em;
  line-height: 1.5;
  color: var(--ink);
  text-shadow: 0 2px 30px rgba(217, 160, 102, 0.15);
}

.title__q,
.title__main,
.title__end {
  display: inline-block;
  opacity: 0;
}

body.is-ready .title__q,
body.is-ready .title__main,
body.is-ready .title__end {
  animation: fadeUp 1.4s var(--ease-slow) forwards;
}

body.is-ready .title__q   { animation-delay: 0.3s; }
body.is-ready .title__main{ animation-delay: 1.1s; }
body.is-ready .title__end { animation-delay: 2.0s; }

.half {
  font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
  color: var(--accent);
  font-weight: 400;
  font-size: 1.1em;
  margin: 0 0.1em;
  text-shadow: 0 0 20px rgba(217, 160, 102, 0.4);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.vinyl {
  margin-top: 3rem;
  width: 80px;
  height: 80px;
  position: relative;
  opacity: 0;
}

body.is-ready .vinyl {
  animation: fadeIn 2s var(--ease-slow) 2.8s forwards;
}

.vinyl__disc {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--accent) 0%, var(--accent) 8%, transparent 9%),
    repeating-radial-gradient(circle at center, rgba(255,255,255,0.03) 0 2px, transparent 2px 4px),
    radial-gradient(circle at center, #1a1a1a 0%, #0a0a0a 100%);
  border: 1px solid rgba(217, 160, 102, 0.2);
  animation: spin 8s linear infinite;
  box-shadow: 0 4px 30px rgba(0,0,0,0.8);
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.hint {
  margin-top: 3.5rem;
  font-size: 0.85rem;
  font-weight: 300;
  color: var(--ink-fade);
  letter-spacing: 0.2em;
  opacity: 0;
}

body.is-ready .hint {
  animation: fadeBreath 3s var(--ease-slow) 3.5s infinite;
}

@keyframes fadeBreath {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 0.7; }
}

.hint kbd {
  display: inline-block;
  padding: 0.1em 0.5em;
  margin: 0 0.2em;
  border: 1px solid var(--ink-fade);
  border-radius: 3px;
  font-family: inherit;
  color: var(--ink-dim);
  font-size: 0.9em;
}

/* ============ story page content ============ */

.story {
  max-width: 680px;
  text-align: center;
  font-size: clamp(1.1rem, 2vw, 1.5rem);
  font-weight: 300;
  line-height: 2.4;
  color: var(--ink);
}

.story__line {
  display: block;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 1s var(--ease-slow),
    transform 1s var(--ease-slow);
}

.page.is-active .story__line {
  opacity: 1;
  transform: translateY(0);
}

.story__line--quote {
  font-style: italic;
  color: var(--ink-dim);
  font-size: 0.95em;
}

.story__line--cite {
  display: block;
  font-size: 0.75em;
  color: var(--ink-fade);
  letter-spacing: 0.15em;
  margin-top: 0.5em;
}

.story__line--emphasis {
  color: var(--accent);
  font-weight: 400;
}

.story__line--whisper {
  color: var(--ink-dim);
  font-size: 0.9em;
  letter-spacing: 0.2em;
}

/* ============ navigation ============ */

.nav {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2rem;
  z-index: 20;
  padding: 0.75rem 1.5rem;
  border-radius: 100px;
  background: rgba(10, 10, 20, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(236, 230, 214, 0.05);
}

.nav__btn {
  background: transparent;
  border: none;
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition:
    color 0.4s var(--ease),
    opacity 0.4s var(--ease),
    transform 0.3s var(--ease);
}

.nav__btn:hover:not(:disabled) {
  color: var(--ink);
  transform: translateY(-1px);
}

.nav__btn:active:not(:disabled) {
  transform: translateY(0);
}

.nav__btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

.nav__btn--prev {
  color: var(--ink-fade);
  font-size: 0.75rem;
}

.nav__btn--prev:hover:not(:disabled) {
  color: var(--danger);
}

.nav__btn--next .arrow {
  transition: transform 0.3s var(--ease);
}

.nav__btn--next:hover:not(:disabled) .arrow {
  transform: translateX(3px);
}

.nav__progress {
  font-size: 0.7rem;
  color: var(--ink-fade);
  letter-spacing: 0.2em;
  font-variant-numeric: tabular-nums;
  min-width: 3.5em;
  text-align: center;
}

.arrow {
  font-size: 1.1em;
}

/* ============ back-chances counter ============ */

.chances {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.75rem;
  color: var(--ink-fade);
  letter-spacing: 0.15em;
  z-index: 20;
  transition: opacity 0.6s var(--ease);
}

.chances__dots {
  display: flex;
  gap: 0.3rem;
}

.chances .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(217, 160, 102, 0.4);
  transition: all 0.6s var(--ease);
}

.chances .dot.is-spent {
  background: transparent;
  border: 1px solid var(--ink-fade);
  box-shadow: none;
  opacity: 0.4;
}

.chances.is-exhausted {
  color: var(--danger);
  opacity: 0.6;
}

.chances.pulse {
  animation: chancePulse 0.8s var(--ease);
}

@keyframes chancePulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.08); color: var(--accent); }
  100% { transform: scale(1); }
}

/* ============ audio toggle ============ */

.audio-toggle {
  position: fixed;
  top: 2rem;
  right: 2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(10, 10, 20, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(236, 230, 214, 0.08);
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 1.1rem;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition:
    color 0.3s var(--ease),
    transform 0.3s var(--ease),
    border-color 0.3s var(--ease);
}

.audio-toggle:hover {
  color: var(--accent);
  border-color: rgba(217, 160, 102, 0.3);
  transform: scale(1.05);
}

.audio-toggle.is-playing .audio-toggle__icon {
  color: var(--accent);
  animation: notePulse 2s ease-in-out infinite;
}

@keyframes notePulse {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

.audio-toggle.is-muted {
  animation: mutedPulse 3s ease-in-out infinite;
}

.audio-toggle.is-muted .audio-toggle__icon {
  opacity: 0.55;
  color: var(--ink-dim);
}

.audio-toggle.is-muted::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 1px;
  background: var(--ink-dim);
  transform: translate(-50%, -50%) rotate(-45deg);
  opacity: 0.6;
}

@keyframes mutedPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 160, 102, 0); }
  50%      { box-shadow: 0 0 0 6px rgba(217, 160, 102, 0.1); }
}

/* ============ entry gate ============ */

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(217, 160, 102, 0.06), transparent 55%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  transition: opacity 1.2s var(--ease-slow);
}

.gate.is-leaving {
  opacity: 0;
  pointer-events: none;
}

.gate__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3.5rem;
  max-width: 90%;
}

.gate__brand {
  font-size: clamp(1.1rem, 2.2vw, 1.6rem);
  font-weight: 300;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
  text-align: center;
  opacity: 0;
  animation: fadeIn 1.4s var(--ease-slow) 0.2s forwards;
}

.gate__brand .half {
  color: var(--accent);
  font-size: 1.15em;
}

/* loader */

.gate__loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  opacity: 0;
  animation: fadeIn 1.2s var(--ease-slow) 0.8s forwards;
  transition: opacity 0.6s var(--ease);
}

.gate__loader.is-done {
  opacity: 0;
  pointer-events: none;
}

.gate__bar {
  width: 180px;
  height: 2px;
  background: rgba(236, 230, 214, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.gate__bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  box-shadow: 0 0 8px rgba(217, 160, 102, 0.4);
  transition: width 0.3s var(--ease);
}

.gate__label {
  font-size: 0.72rem;
  color: var(--ink-fade);
  letter-spacing: 0.25em;
  font-variant-numeric: tabular-nums;
}

/* enter button */

.gate__enter {
  position: relative;
  padding: 1rem 2.5rem;
  background: transparent;
  border: 1px solid rgba(217, 160, 102, 0.35);
  border-radius: 2px;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  letter-spacing: 0.3em;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  opacity: 0;
  transform: translateY(8px);
  animation: gateEnterReveal 1.5s var(--ease-slow) forwards;
  transition:
    color 0.4s var(--ease),
    border-color 0.4s var(--ease),
    background 0.4s var(--ease),
    transform 0.3s var(--ease);
}

.gate__enter::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 8px;
  background: radial-gradient(ellipse at center, rgba(217, 160, 102, 0.15), transparent 70%);
  opacity: 0;
  animation: gateGlow 3s ease-in-out 1.2s infinite;
  z-index: -1;
}

.gate__enter:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(217, 160, 102, 0.05);
  transform: translateY(-1px);
}

.gate__enter-sub {
  font-size: 0.65rem;
  color: var(--ink-fade);
  letter-spacing: 0.25em;
  font-weight: 300;
}

@keyframes gateEnterReveal {
  to { opacity: 1; transform: translateY(0); }
}

@keyframes gateGlow {
  0%, 100% { opacity: 0; }
  50%      { opacity: 1; }
}

/* hide ambient UI while gate is up */

body.is-gated .nav,
body.is-gated .chances,
body.is-gated .audio-toggle {
  opacity: 0;
  pointer-events: none;
}

.nav, .chances, .audio-toggle {
  transition: opacity 1s var(--ease-slow);
}

/* ============ responsive ============ */

@media (max-width: 640px) {
  .title { letter-spacing: 0.1em; }
  .chances { bottom: 5.5rem; right: 1rem; font-size: 0.65rem; }
  .audio-toggle { top: 1rem; right: 1rem; width: 36px; height: 36px; }
  .nav { bottom: 1rem; gap: 1rem; padding: 0.5rem 1rem; }
  .nav__btn .label { display: none; }
  .page { padding: 3rem 1.5rem 6rem; }
}

/* ============ reduced motion ============ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01s !important;
    transition-duration: 0.2s !important;
  }
  .vinyl__disc { animation: none; }
  .dust { display: none; }
}
