/* ===================================================================
   給 Karen · 時光機
   一頁式 scrollytelling：門檻 → 定向 → 逐章上升 → 高潮 → 留白 → 離場
=================================================================== */

:root {
  --ink: #2a2724;
  --ink-soft: #6b6560;
  --paper: #faf8f5;
  --paper-raised: #ffffff;
  --line: rgba(42, 39, 36, 0.1);
  --accent: #8a8578;
  --tint: #f5f3ef;
  --serif: "Songti TC", "Noto Serif TC", "PingFang TC", serif;
  --sans: "PingFang TC", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img, video { max-width: 100%; display: block; }

/* ---------- fixed UI: progress + chapter tag ---------- */

#progress-track {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--line);
  z-index: 100;
}
#progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent-live, #8a8578);
  transition: width 0.1s linear, background 0.4s var(--ease);
}
#chapter-tag {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 100;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  background: rgba(250, 248, 245, 0.75);
  backdrop-filter: blur(6px);
  padding: 6px 12px;
  border-radius: 100px;
  opacity: 0;
  transition: opacity 0.4s var(--ease), color 0.4s var(--ease);
  pointer-events: none;
}
#chapter-tag.visible { opacity: 1; }

/* ---------- hero ---------- */

#hero {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8vh 6vw;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(138,133,120,0.10), transparent 60%),
    var(--paper);
}
.hero-inner { max-width: 640px; }
.hero-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.35em;
  color: var(--ink-soft);
  margin: 0 0 20px;
}
#hero-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.6rem, 9vw, 4.6rem);
  margin: 0 0 18px;
  letter-spacing: 0.02em;
  opacity: 0;
  transform: translateY(14px);
  animation: rise 1s var(--ease) 0.2s forwards;
}
.hero-subtitle {
  font-size: clamp(0.95rem, 2.2vw, 1.15rem);
  color: var(--ink-soft);
  margin: 0;
  opacity: 0;
  transform: translateY(14px);
  animation: rise 1s var(--ease) 0.45s forwards;
}
.scroll-cue {
  margin: 64px auto 0;
  width: 22px; height: 36px;
  border: 1.5px solid var(--line);
  border-radius: 100px;
  position: relative;
  opacity: 0;
  animation: rise 1s var(--ease) 0.8s forwards;
}
.scroll-cue span {
  position: absolute;
  top: 7px; left: 50%;
  width: 3px; height: 7px;
  margin-left: -1.5px;
  border-radius: 100px;
  background: var(--ink-soft);
  animation: cue-bob 1.8s ease-in-out infinite;
}
@keyframes cue-bob {
  0%, 100% { transform: translateY(0); opacity: 1; }
  50% { transform: translateY(9px); opacity: 0.3; }
}
@keyframes rise {
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- prose sections (opening / closing) ---------- */

.prose-section {
  max-width: 620px;
  margin: 0 auto;
  padding: 18vh 8vw;
  text-align: center;
}
.prose-text {
  font-family: var(--serif);
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  line-height: 2;
  color: var(--ink);
  white-space: pre-line;
  margin: 0;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 1s var(--ease), transform 1s var(--ease);
}
.prose-text.in-view { opacity: 1; transform: translateY(0); }

/* ---------- chapter intro (threshold cut) ---------- */

.chapter-intro {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8vh 6vw;
  position: relative;
  background: var(--tint);
  overflow: hidden;
}
.chapter-intro::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 65%);
  opacity: 0;
  transition: opacity 1.2s var(--ease);
}
.chapter-intro.in-view::before { opacity: 1; }

.chapter-index {
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--accent);
  margin: 0 0 22px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.8s var(--ease), transform 0.8s var(--ease);
}
.chapter-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2rem, 7vw, 3.4rem);
  margin: 0 0 14px;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.9s var(--ease) 0.1s, transform 0.9s var(--ease) 0.1s;
}
.chapter-subtitle {
  font-size: clamp(0.85rem, 2vw, 1rem);
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.9s var(--ease) 0.25s, transform 0.9s var(--ease) 0.25s;
}
.chapter-intro.in-view .chapter-index,
.chapter-intro.in-view .chapter-title,
.chapter-intro.in-view .chapter-subtitle {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- moments ---------- */

.chapter-body {
  padding: 6vh 0 10vh;
  background: var(--paper);
}

.moment {
  max-width: 760px;
  margin: 0 auto;
  padding: 7vh 6vw;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.moment-frame {
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  background: var(--paper-raised);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 18px 40px -22px rgba(42,39,36,0.28);
  opacity: 0;
  transform: translateY(28px) scale(0.98);
  transition: opacity 0.9s var(--ease), transform 0.9s var(--ease);
}
.moment.in-view .moment-frame {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.moment-media {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.moment-media::-webkit-scrollbar { display: none; }
.moment-media > .media-item {
  flex: 0 0 100%;
  scroll-snap-align: center;
  display: flex;
}
.moment-media img,
.moment-media video {
  width: 100%;
  height: auto;
  object-fit: cover;
}

.media-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}
.media-dots span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--line);
}
.media-dots span.active { background: var(--accent); }

.video-wrap { position: relative; width: 100%; }
.video-wrap .play-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(0,0,0,0.12);
}
.video-wrap .play-hint svg { width: 52px; height: 52px; opacity: 0.92; }
.video-wrap video[data-playing="true"] + .play-hint,
.video-wrap.playing .play-hint { opacity: 0; }

.moment-caption {
  margin-top: 20px;
  text-align: center;
  max-width: 560px;
}
.moment-caption p {
  font-family: var(--serif);
  font-size: clamp(1.02rem, 2.6vw, 1.2rem);
  line-height: 1.85;
  color: var(--ink);
  margin: 0 0 6px;
}
.moment-caption p:last-child { margin-bottom: 0; }
.moment-date {
  display: inline-block;
  margin-top: 14px;
  font-size: 11.5px;
  letter-spacing: 0.1em;
  color: var(--accent);
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

/* portrait vs landscape framing */
.moment-frame[data-orientation="portrait"] .moment-media img,
.moment-frame[data-orientation="portrait"] .moment-media video {
  max-height: 78vh;
  object-fit: contain;
  background: #111;
  margin: 0 auto;
}

/* ---------- rest (climax breathing room) ---------- */

#rest {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: #0f1417;
  color: #f4f1ec;
  overflow: hidden;
}
#rest img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.55;
  transform: scale(1.04);
  transition: opacity 1.6s var(--ease), transform 3s var(--ease);
}
#rest.in-view img { opacity: 0.55; transform: scale(1); }
#rest blockquote {
  position: relative;
  z-index: 1;
  font-family: var(--serif);
  font-size: clamp(1.8rem, 6vw, 3rem);
  text-align: center;
  margin: 0;
  padding: 0 8vw;
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 1.2s var(--ease) 0.3s, transform 1.2s var(--ease) 0.3s;
  text-shadow: 0 2px 30px rgba(0,0,0,0.5);
}
#rest.in-view blockquote { opacity: 1; transform: translateY(0); }

/* ---------- closing ---------- */

#closing {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10vh 6vw;
  background: linear-gradient(180deg, #0f1417, #1a2126);
  color: #f4f1ec;
}
.closing-inner { max-width: 640px; }
#closing .hero-eyebrow { color: rgba(244,241,236,0.55); }
#closing-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2rem, 6vw, 3rem);
  margin: 0 0 26px;
}
#closing .prose-text { color: #f4f1ec; }

/* ---------- chapter mood variants ---------- */

.chapter[data-mood="prologue"] { --accent: #8a8578; --tint: #f5f3ef; }
.chapter[data-mood="night"]    { --accent: #5b5f97; --tint: #f1f1f7; }
.chapter[data-mood="meet"]     { --accent: #d98e4a; --tint: #fdf3e6; }
.chapter[data-mood="urban"]    { --accent: #4a6fa5; --tint: #eef3f8; }
.chapter[data-mood="mountain"] { --accent: #b5651d; --tint: #faf1e8; }
.chapter[data-mood="soft"]     { --accent: #b5748a; --tint: #faf0f3; }
.chapter[data-mood="festive"]  { --accent: #b8862b; --tint: #fbf1e4; }
.chapter[data-mood="sage"]     { --accent: #5f7a61; --tint: #f0f4f0; }
.chapter[data-mood="home"]     { --accent: #c99b5b; --tint: #faf6ec; }
.chapter[data-mood="vibrant"]  { --accent: #c1543f; --tint: #fdf1ec; }
.chapter[data-mood="deep"]     { --accent: #7a3b46; --tint: #f7eef0; }
.chapter[data-mood="dawn"]     { --accent: #3f7ea6; --tint: #eef7fb; }

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .moment { padding: 5vh 5vw; }
  .prose-section { padding: 14vh 7vw; }
}

@media (prefers-reduced-motion: reduce) {
  .moment-frame, .prose-text, .chapter-index, .chapter-title, .chapter-subtitle,
  #hero-title, .hero-subtitle, .scroll-cue, #rest img, #rest blockquote {
    animation: none !important;
    transition: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}
