:root {
  --bg: #14080a;
  --bg-deep: #0a0406;
  --ink: #f3e6d2;
  --ink-dim: #c9b49a;
  --paper: #e8d2b0;
  --paper-ink: #2a1612;
  --cinnabar: #c42b2b;
  --cinnabar-deep: #7a1418;
  --gold: #d4af37;
  --gold-dim: #9a7b2f;
  --lantern: #e08a3c;
  --ash: #8a7a72;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --thumb: 56px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #070304;
  color: var(--ink);
  font-family: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "PingFang SC", "Hiragino Mincho ProN", serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
  min-height: 100dvh;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  appearance: none;
  cursor: pointer;
}

.phone {
  position: relative;
  width: min(100vw, 430px);
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(196, 43, 43, 0.22), transparent 50%),
    radial-gradient(90% 50% at 80% 100%, rgba(80, 20, 30, 0.45), transparent 55%),
    var(--bg);
  display: flex;
  flex-direction: column;
}

.phone[data-mood="rain"] { background:
  radial-gradient(100% 70% at 40% 0%, rgba(50, 70, 110, 0.28), transparent 50%),
  linear-gradient(180deg, #0c0a12, #14080a 55%, #1a0c10);
}
.phone[data-mood="village"] { background:
  radial-gradient(70% 50% at 20% 80%, rgba(224, 138, 60, 0.16), transparent 50%),
  linear-gradient(180deg, #1a0c0c, #14080a);
}
.phone[data-mood="workshop"] { background:
  radial-gradient(80% 60% at 70% 20%, rgba(212, 175, 55, 0.14), transparent 45%),
  linear-gradient(180deg, #1c1008, #120806);
}
.phone[data-mood="shrine"] { background:
  radial-gradient(90% 70% at 50% 0%, rgba(196, 43, 43, 0.35), transparent 55%),
  linear-gradient(180deg, #2a0a0c, #100406);
}
.phone[data-mood="river"] { background:
  radial-gradient(80% 50% at 50% 100%, rgba(40, 80, 90, 0.35), transparent 50%),
  linear-gradient(180deg, #0a1014, #0c0a10);
}
.phone[data-mood="dawn"] { background: linear-gradient(180deg, #3a2a22, #6a5340 70%, #c4a07a); }
.phone[data-mood="crimson"] { background: linear-gradient(180deg, #3a0608, #7a1218 80%, #1a0406); }
.phone[data-mood="ash"] { background: linear-gradient(180deg, #1a1616, #3a3330 80%, #121010); }
.phone[data-mood="ink"] { background: linear-gradient(180deg, #0a1218, #142028 70%, #0c1014); }

.grain, .vignette {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 8;
}

.grain {
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.vignette {
  box-shadow: inset 0 0 120px 24px rgba(0, 0, 0, 0.55);
}

.phone[data-mood="rain"]::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: repeating-linear-gradient(
    185deg,
    transparent 0 12px,
    rgba(210, 220, 240, 0.05) 12px 13px
  );
  animation: rain 0.9s linear infinite;
  opacity: 0.55;
}

@keyframes rain {
  to { transform: translateY(18px); }
}

.screen {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: calc(18px + var(--safe-t)) 20px 0;
}

.screen[hidden], .modal[hidden], [hidden] { display: none !important; }

.home-top {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px 8px 8px;
}

.series {
  margin: 0;
  letter-spacing: 0.42em;
  font-size: 12px;
  color: var(--gold);
  text-indent: 0.42em;
}

.seal {
  width: 72px;
  height: 72px;
  margin: 22px 0 16px;
  border: 3px solid var(--cinnabar);
  color: var(--cinnabar);
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 700;
  transform: rotate(-8deg);
  box-shadow: 0 0 0 4px rgba(196, 43, 43, 0.15);
  background: rgba(196, 43, 43, 0.08);
}

h1 {
  margin: 0;
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
}

.tagline {
  margin: 16px 28px 0;
  color: var(--ink-dim);
  line-height: 1.7;
  font-size: 15px;
}

.thumb-dock {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 0 calc(16px + var(--safe-b));
}

.btn {
  min-height: var(--thumb);
  border-radius: 14px;
  padding: 0 16px;
  width: 100%;
  letter-spacing: 0.08em;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(180deg, #d33a3a, var(--cinnabar-deep));
  color: #fff8ee;
  box-shadow: 0 8px 20px rgba(122, 20, 24, 0.35);
}

.btn-ghost {
  background: rgba(243, 230, 210, 0.08);
  border: 1px solid rgba(212, 175, 55, 0.28);
  color: var(--ink);
}

.btn-stub {
  min-height: 44px;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px dashed rgba(201, 180, 154, 0.35);
  color: var(--ash);
  letter-spacing: 0.04em;
}

.stub-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

.stub-note, .hint-foot {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--ash);
  line-height: 1.5;
}

.bar, .play-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-bottom: 8px;
}

.bar h2, .play-titles p {
  margin: 0;
}

.bar h2 { font-size: 18px; letter-spacing: 0.2em; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 26px;
  line-height: 1;
}

.bar-spacer { width: 44px; }

.chapter-list, .gallery-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-bottom: 12px;
}

.chapter-card, .gallery-card {
  text-align: left;
  padding: 16px 16px 14px;
  border-radius: 16px;
  background: rgba(243, 230, 210, 0.07);
  border: 1px solid rgba(212, 175, 55, 0.2);
}

.chapter-card[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.chapter-card .no { color: var(--gold); font-size: 12px; letter-spacing: 0.2em; margin: 0 0 6px; }
.chapter-card .name, .gallery-card .name { margin: 0; font-size: 22px; letter-spacing: 0.16em; }
.chapter-card .hint, .gallery-card .blurb { margin: 8px 0 0; color: var(--ink-dim); font-size: 13px; line-height: 1.6; }

.play-bar { justify-content: space-between; }
.play-titles { text-align: center; flex: 1; }
#chapter-label { font-size: 14px; letter-spacing: 0.28em; color: var(--gold); }

.candles {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}

.candles i {
  width: 7px;
  height: 14px;
  border-radius: 2px 2px 1px 1px;
  background: rgba(243, 230, 210, 0.2);
  position: relative;
}

.candles i.on { background: var(--cinnabar); box-shadow: 0 0 8px rgba(196, 43, 43, 0.7); }
.candles i.on::after {
  content: "";
  position: absolute;
  top: -5px;
  left: 1px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--lantern);
  box-shadow: 0 0 6px var(--lantern);
}

.story {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.speaker {
  margin: 4px 4px 8px;
  color: var(--gold);
  letter-spacing: 0.24em;
  font-size: 13px;
}

.paper {
  flex: 1;
  overflow: auto;
  background:
    linear-gradient(180deg, rgba(255, 244, 220, 0.96), rgba(226, 200, 160, 0.94));
  color: var(--paper-ink);
  border-radius: 16px;
  padding: 22px 20px;
  line-height: 1.95;
  font-size: 17px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

#story-text, #ending-text {
  margin: 0;
  white-space: pre-wrap;
}

.play-dock { padding-top: 10px; }

.choices { display: flex; flex-direction: column; gap: 10px; }

.choice {
  min-height: var(--thumb);
  border-radius: 14px;
  padding: 12px 16px;
  background: rgba(243, 230, 210, 0.1);
  border: 1px solid rgba(243, 230, 210, 0.18);
  text-align: left;
  line-height: 1.45;
  letter-spacing: 0.04em;
}

.choice:active { background: rgba(196, 43, 43, 0.28); }

.title-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding-bottom: calc(24px + var(--safe-b));
}

.title-card h2 {
  margin: 0;
  font-size: 40px;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
}

#card-hint { margin: 0 24px 24px; color: var(--ink-dim); }

.ending-top { text-align: center; padding: 12px 0 16px; }
.ending-top h2 { margin: 10px 0 0; font-size: 34px; letter-spacing: 0.18em; }
.ending-paper { flex: 1; margin-bottom: 8px; }

.gallery-card.locked { opacity: 0.4; }
.gallery-card .rank { margin: 0 0 6px; color: var(--gold); font-size: 12px; letter-spacing: 0.2em; }

.modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + var(--safe-b));
}

.modal-card {
  width: 100%;
  background: #1c1010;
  border: 1px solid rgba(212, 175, 55, 0.28);
  border-radius: 18px 18px 8px 8px;
  padding: 22px 18px 16px;
}

.modal-card h3 { margin: 8px 0 10px; font-size: 20px; }
.modal-card p { margin: 0 0 16px; color: var(--ink-dim); line-height: 1.7; }

@media (min-height: 780px) {
  h1 { font-size: 46px; }
  .paper { font-size: 18px; }
}
