/* ═══ 伏嶽藏煙 · 前世書互動頁 ═══ */

:root {
  --ink: #05030d;
  --purple: #12091e;
  --gold: #f4bb32;
  --gold-dim: #a87f1f;
  --magenta: #ff2f94;
  --blue: #1c45ff;
  --green: #53f229;
  --paper: #f3e9d4;
  --paper-dim: #cbbfa4;
  --serif: "Noto Serif TC", "Songti TC", "PingFang TC", "Microsoft JhengHei", serif;
}

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

html, body {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }

#stage {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  background:
    radial-gradient(120% 60% at 50% -10%, var(--purple) 0%, transparent 60%),
    var(--ink);
}

/* ── scenes ── */
.scene {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  animation: scene-in 700ms ease both;
}
.scene.is-active { display: flex; }

@keyframes scene-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* ── type ── */
.kicker {
  font-size: 12px;
  letter-spacing: .5em;
  text-indent: .5em;
  color: var(--gold);
  text-transform: uppercase;
  text-align: center;
}
.h2 {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  line-height: 1.5;
  margin-top: 10px;
}
.micro-note {
  font-size: 12px;
  color: var(--paper-dim);
  text-align: center;
  letter-spacing: .1em;
}

/* ── buttons ── */
.btn {
  display: block;
  width: 100%;
  min-height: 52px;
  border-radius: 4px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .2em;
  text-indent: .2em;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 200ms ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .35; cursor: default; }

.btn-gold {
  border: 1px solid var(--gold);
  color: var(--ink);
  background: linear-gradient(180deg, #ffd769 0%, var(--gold) 55%, var(--gold-dim) 100%);
  box-shadow: 0 0 24px rgba(244, 187, 50, .35), inset 0 1px 0 rgba(255,255,255,.5);
}
.btn-outline {
  border: 1px solid var(--gold);
  color: var(--gold);
  background: transparent;
}

/* ═══ Scene 1 · 遇見 ═══ */
#scene-encounter { justify-content: flex-end; }

.hero-frame {
  position: absolute;
  inset: 0 0 auto 0;
  height: 62dvh;
  overflow: hidden;
}
.hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
  animation: hero-breathe 9s ease-in-out infinite alternate;
}
@keyframes hero-breathe {
  from { transform: scale(1); }
  to   { transform: scale(1.05); }
}
.hero-fade {
  position: absolute;
  inset: auto 0 0 0;
  height: 45%;
  background: linear-gradient(180deg, transparent 0%, var(--ink) 92%);
}

.encounter-copy {
  position: relative;
  z-index: 1;
  padding: 0 24px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.title {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: .12em;
  text-align: center;
  line-height: 1.15;
  color: var(--paper);
  text-shadow: 0 0 30px rgba(244, 187, 50, .45);
}
.title-sub {
  display: block;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .55em;
  text-indent: .55em;
  color: var(--gold);
  margin-top: 10px;
}
.spirit-line {
  font-size: 16px;
  line-height: 2;
  text-align: center;
  color: var(--paper);
  border-top: 1px solid rgba(244, 187, 50, .25);
  border-bottom: 1px solid rgba(244, 187, 50, .25);
  padding: 14px 0;
  animation: line-in 1.6s ease .3s both;
}
@keyframes line-in {
  from { opacity: 0; letter-spacing: .12em; }
  to   { opacity: 1; letter-spacing: normal; }
}

/* ═══ Scene 2 · 殘頁 ═══ */
#scene-fragments {
  padding: calc(28px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  gap: 18px;
}
.scene-head { display: flex; flex-direction: column; gap: 8px; }
.frag-progress {
  text-align: center;
  font-size: 13px;
  color: var(--gold);
  letter-spacing: .2em;
}

.frag-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}
.frag {
  border: 1px solid rgba(244, 187, 50, .3);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(18, 9, 30, .9), rgba(5, 3, 13, .9));
  overflow: hidden;
}
.frag.is-open { border-color: var(--gold); box-shadow: 0 0 18px rgba(244, 187, 50, .18); }

.frag-toggle {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 0 16px;
  background: none;
  border: 0;
  color: var(--paper);
  text-align: left;
}
.frag-seal {
  flex: 0 0 34px;
  height: 34px;
  border: 1px solid var(--magenta);
  border-radius: 50%;
  color: var(--magenta);
  font-size: 15px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.frag.is-seen .frag-seal {
  border-color: var(--gold);
  color: var(--ink);
  background: var(--gold);
}
.frag-label { flex: 1; font-size: 17px; font-weight: 700; letter-spacing: .1em; }
.frag-state { flex: 0 0 auto; color: var(--gold-dim); font-size: 13px; }
.frag-state::before { content: "未翻開"; }
.frag.is-seen .frag-state::before { content: "已翻開"; color: var(--green); }

.frag-body {
  display: none;
  padding: 0 16px 16px;
  flex-direction: column;
  gap: 12px;
}
.frag.is-open .frag-body { display: flex; }
.frag-body img {
  border-radius: 4px;
  border: 1px solid rgba(244, 187, 50, .35);
  max-height: 40dvh;
  width: 100%;
  object-fit: cover;
}
.frag-body p { font-size: 15px; line-height: 1.9; color: var(--paper); }
.frag-body em { color: var(--gold); font-style: normal; }
.frag-body strong { color: var(--magenta); font-weight: 700; }
.frag-text-only { padding: 6px 2px; }

/* ═══ Scene 3 · 法則 ═══ */
#scene-logic { justify-content: center; }
.logic-wrap {
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  text-align: center;
}
.logic-line { font-size: 26px; line-height: 1.8; }
.glow-gold { color: var(--gold); text-shadow: 0 0 22px rgba(244, 187, 50, .6); }
.glow-magenta { color: var(--magenta); text-shadow: 0 0 22px rgba(255, 47, 148, .55); }
.logic-sub { font-size: 15px; line-height: 2; color: var(--paper-dim); }
.logic-sub strong { color: var(--paper); }
.spirit-line-sm {
  font-size: 14px;
  color: var(--gold);
  letter-spacing: .05em;
}

/* ═══ Scene 4 · 暗頁題 ═══ */
#scene-quiz {
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  gap: 20px;
}
.quiz-head { display: flex; flex-direction: column; gap: 10px; }

.lamp-row { display: flex; justify-content: center; gap: 22px; }
.lamp {
  width: 22px;
  height: 28px;
  border: 1px solid var(--paper-dim);
  border-radius: 50% 50% 46% 46% / 42% 42% 56% 56%;
  background: rgba(243, 233, 212, .06);
  position: relative;
}
.lamp::after {
  content: "";
  position: absolute;
  inset: auto 50% -6px auto;
  transform: translateX(50%);
  width: 6px; height: 5px;
  background: var(--magenta);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  opacity: .6;
}
.lamp.is-lit {
  border-color: var(--gold);
  background: radial-gradient(circle at 50% 45%, #ffe9a8 0%, var(--gold) 70%);
  box-shadow: 0 0 16px rgba(244, 187, 50, .8);
}

.incense {
  height: 6px;
  border-radius: 3px;
  border: 1px solid rgba(244, 187, 50, .4);
  overflow: hidden;
  background: rgba(5, 3, 13, .8);
}
.incense-burn {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--magenta), var(--gold));
  transform-origin: left center;
}
.timer-note {
  text-align: center;
  font-size: 13px;
  letter-spacing: .15em;
  color: var(--paper-dim);
}
.timer-note.is-low { color: var(--magenta); }
#timer-seconds { color: var(--gold); font-weight: 700; font-size: 15px; }
.timer-note.is-low #timer-seconds { color: var(--magenta); }

.quiz-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border: 1px solid rgba(244, 187, 50, .35);
  border-radius: 8px;
  padding: 22px 18px;
  background:
    radial-gradient(140% 90% at 50% 0%, rgba(28, 69, 255, .12) 0%, transparent 55%),
    linear-gradient(180deg, rgba(18, 9, 30, .95), rgba(5, 3, 13, .95));
}
.quiz-no {
  font-size: 12px;
  letter-spacing: .4em;
  color: var(--gold);
  text-align: center;
}
.quiz-q {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.7;
  text-align: center;
}

.choices { display: flex; flex-direction: column; gap: 12px; margin-top: auto; }
.choice {
  min-height: 54px;
  padding: 12px 16px;
  border: 1px solid rgba(243, 233, 212, .4);
  border-radius: 4px;
  background: rgba(243, 233, 212, .04);
  color: var(--paper);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
  transition: border-color 150ms ease, background 150ms ease;
}
.choice:disabled { opacity: .5; }
.choice.is-correct {
  border-color: var(--green);
  color: var(--green);
  background: rgba(83, 242, 41, .08);
  box-shadow: 0 0 16px rgba(83, 242, 41, .25);
}
.choice.is-wrong {
  border-color: var(--magenta);
  color: var(--magenta);
  background: rgba(255, 47, 148, .08);
}

/* ═══ Scene 5 · 解印 ═══ */
#scene-unlock { justify-content: flex-end; }
.unlock-frame {
  position: absolute;
  inset: 0 0 auto 0;
  height: 52dvh;
  overflow: hidden;
}
.unlock-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
  animation: unlock-glow 3.4s ease-in-out infinite alternate;
}
@keyframes unlock-glow {
  from { filter: brightness(1); }
  to   { filter: brightness(1.18); }
}
.unlock-fade {
  position: absolute;
  inset: auto 0 0 0;
  height: 45%;
  background: linear-gradient(180deg, transparent 0%, var(--ink) 92%);
}
.unlock-copy {
  position: relative;
  z-index: 1;
  padding: 0 24px calc(26px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.unlock-lead { font-size: 16px; line-height: 1.9; }

.keyword-charm {
  position: relative;
  margin: 8px auto 0;
  padding: 26px 34px 18px;
  border: 1px solid var(--gold);
  border-radius: 6px;
  background:
    radial-gradient(120% 100% at 50% 0%, rgba(244, 187, 50, .24) 0%, transparent 62%),
    linear-gradient(180deg, rgba(24, 13, 22, .95), rgba(5, 3, 13, .95));
  box-shadow: 0 0 34px rgba(244, 187, 50, .34), inset 0 0 18px rgba(244, 187, 50, .08);
  animation: charm-in 700ms ease .12s both;
}
@keyframes charm-in {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: none; }
}
.charm-cord {
  position: absolute;
  top: -10px; left: 50%;
  transform: translateX(-50%);
  width: 20px; height: 20px;
  border: 2px solid var(--magenta);
  border-radius: 50%;
  background: var(--ink);
}
.keyword {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: .18em;
  text-indent: .18em;
  color: #ffe9a8;
  text-shadow: 0 0 12px rgba(244, 187, 50, .9), 0 0 32px rgba(244, 187, 50, .72);
  white-space: nowrap;
}
.charm-note { margin-top: 10px; font-size: 12px; color: var(--paper-dim); letter-spacing: .1em; }
.unlock-cta-text { font-size: 14px; line-height: 1.9; color: var(--paper-dim); }

/* ═══ 提示覆層 ═══ */
.veil {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(5, 3, 13, .88);
  backdrop-filter: blur(3px);
  animation: veil-in 250ms ease both;
}
.veil[hidden] { display: none; }
@keyframes veil-in { from { opacity: 0; } to { opacity: 1; } }

.hint-card {
  width: 100%;
  max-width: 340px;
  padding: 26px 22px;
  border: 1px solid var(--magenta);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--purple), var(--ink));
  box-shadow: 0 0 34px rgba(255, 47, 148, .3);
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}
.hint-title {
  font-size: 14px;
  letter-spacing: .3em;
  text-indent: .3em;
  color: var(--magenta);
}
.hint-text { font-size: 17px; line-height: 1.9; color: var(--paper); }

/* ═══ reduced motion ═══ */
@media (prefers-reduced-motion: reduce) {
  .scene, .spirit-line, .keyword-charm, .veil { animation: none; }
  .hero-img, .unlock-img { animation: none; }
  .incense-burn { transition: none !important; }
  .btn:active { transform: none; }
}

/* narrow phones */
@media (max-width: 360px) {
  .title { font-size: 34px; }
  .keyword { font-size: 27px; }
}
