@font-face {
  font-family: "Chill ZhuoKai";
  src: url("./assets/font/ChillZhuoKai_R.otf") format("opentype");
  font-display: swap;
  font-weight: 400;
  font-style: normal;
}

:root {
  --paper: #ececea;
  --paper-deep: #d9dad8;
  --paper-dialogue: rgba(215, 216, 214, 0.96);
  --ink: #242523;
  --ink-soft: #626460;
  --line: rgba(36, 37, 35, 0.72);
  --font-main: "Chill ZhuoKai", "KaiTi", "STKaiti", "Kaiti SC", serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: #1d1c19;
  color: var(--ink);
  font-family: var(--font-main);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.stage {
  position: relative;
  width: min(100vw, calc(100dvh * 9 / 16));
  max-width: 540px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper) url("./assets/ui/ui_02_paper.png") center / cover;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

.page-frame {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: url("./assets/ui/ui_04_frame.png") center / 100% 100% no-repeat;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--paper) url("./assets/ui/ui_02_paper.png") center / cover;
}
.screen.is-active { display: flex; animation: screen-in 280ms ease-out; }

@keyframes screen-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.slip-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 1px;
  background: rgba(236, 237, 234, 0.94);
  color: var(--ink);
  font-size: clamp(18px, 4.2vw, 22px);
  line-height: 1.4;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
  cursor: pointer;
  transition: background-color 140ms, border-color 140ms, transform 120ms;
}
.slip-button:hover,
.slip-button:focus-visible {
  border-color: var(--ink);
  background: rgba(211, 213, 210, 0.96);
  outline: none;
}
.slip-button:active { transform: translateY(1px); }
.slip-button:disabled {
  color: rgba(98, 95, 87, 0.45);
  border-color: rgba(36, 35, 31, 0.22);
  cursor: default;
  transform: none;
}

/* 主界面 */
.screen--menu { justify-content: space-between; }
.menu-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  padding: calc(24px + env(safe-area-inset-top)) 36px calc(24px + env(safe-area-inset-bottom));
}
.menu-visual {
  position: absolute;
  inset: 0;
}
.menu-visual img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.menu-nav {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}
.menu-progress {
  margin-top: -6px;
  color: var(--ink-soft);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-align: center;
}
/* 剧情画面：纸纹常驻，一次只显示一个场景、人物或道具 */
.screen--game { background: var(--paper-deep); }
.scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--paper) url("./assets/ui/ui_02_paper.png") center / cover;
}
.visual-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-position: center center;
  opacity: 0;
  transition: opacity 260ms ease-out;
  pointer-events: none;
}
.visual-image.is-visible { opacity: 1; }
.visual-image[data-fit="cover"] { object-fit: cover; }
.visual-image[data-fit="contain"] { object-fit: contain; }
.scene[data-tone="night"] .visual-image { filter: brightness(0.78) grayscale(0.1); }
.scene[data-tone="cold"] .visual-image { filter: brightness(0.9) grayscale(0.12); }
.scene[data-tone="warm"] .visual-image { filter: grayscale(0.03) brightness(1.02); }

.scene-fx { position: absolute; inset: 0; pointer-events: none; }
.scene-fx[data-fx="fog"],
.scene-fx[data-fx="heavy-fog"] {
  background:
    radial-gradient(58% 24% at 28% 78%, rgba(236, 237, 234, 0.38), transparent 72%),
    radial-gradient(52% 23% at 74% 66%, rgba(236, 237, 234, 0.3), transparent 72%);
  animation: fx-drift 9s ease-in-out infinite alternate;
}
.scene-fx[data-fx="smoke"] {
  background: radial-gradient(35% 30% at 50% 69%, rgba(236, 237, 234, 0.42), transparent 72%);
  animation: fx-drift 6s ease-in-out infinite alternate;
}
.scene-fx[data-fx="falling"] { background: radial-gradient(70% 40% at 50% 40%, rgba(36, 35, 31, 0.15), transparent 75%); }
.scene-fx[data-fx="memory"] {
  background: linear-gradient(180deg, rgba(236, 237, 234, 0.02), rgba(36, 35, 31, 0.22));
  animation: fx-memory 1.6s ease-in-out infinite alternate;
}
.scene-fx[data-fx="ink"] { background: radial-gradient(80% 60% at 50% 50%, transparent 55%, rgba(36, 35, 31, 0.2)); }
@keyframes fx-drift { from { transform: translateX(-2.5%); } to { transform: translateX(2.5%); } }
@keyframes fx-memory { from { opacity: 0.5; } to { opacity: 1; } }

.game-topbar {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top));
  left: 18px;
  right: 18px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px 0;
}
.game-topbar__right { display: flex; align-items: center; gap: 8px; }
.topbar-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 4px 10px;
  border: 1px solid rgba(36, 35, 31, 0.38);
  border-radius: 1px;
  background: rgba(236, 237, 234, 0.82);
  color: var(--ink-soft);
  font-size: clamp(15px, 3.6vw, 18px);
  letter-spacing: 0.1em;
  cursor: pointer;
}
.topbar-button:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
.topbar-button:disabled { opacity: 0.42; cursor: default; }
.save-flash {
  padding: 3px 8px;
  border: 1px solid rgba(36, 35, 31, 0.3);
  background: rgba(236, 237, 234, 0.82);
  color: var(--ink-soft);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  animation: save-flash 1.4s ease-out forwards;
}
@keyframes save-flash {
  0% { opacity: 0; transform: translateY(-3px); }
  12%, 78% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

.narration-box,
.dialogue-box {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: calc(3.5% + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  height: auto;
  min-height: 120px;
  max-height: 30vh;
  padding: 18px 22px;
  font-size: clamp(18px, 4.2vw, 22px);
  line-height: 1.6;
  border-radius: 1px;
  cursor: pointer;
  animation: text-in 200ms ease-out;
}
.narration-box > p,
.dialogue-box > p {
  width: 100%;
  max-height: calc(30vh - 36px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.narration-box {
  border: 1px solid rgba(236, 237, 234, 0.46);
  background: rgba(27, 26, 23, 0.84);
  box-shadow: 0 2px 12px rgba(20, 18, 15, 0.34);
  color: #f4f4f1;
  letter-spacing: 0.06em;
}
.dialogue-box {
  border: 1px solid rgba(36, 35, 31, 0.72);
  background: var(--paper-dialogue);
  box-shadow: 0 3px 16px rgba(20, 18, 15, 0.3);
  color: var(--ink);
  letter-spacing: 0.05em;
}

.speaker-tag {
  position: absolute;
  top: -18px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 4px 14px;
  border: 1px solid rgba(36, 35, 31, 0.72);
  border-radius: 1px;
  background: rgba(236, 237, 234, 0.94);
  color: var(--ink);
  font-size: clamp(18px, 4.2vw, 22px);
  line-height: 1.2;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
}
.speaker-tag--player {
  top: -38px;
  right: auto;
  left: 14px;
  width: 66px;
  height: 42px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: url("./assets/ui/ui_03_player_fan.png") center / contain no-repeat;
}

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

.advance-hint {
  position: absolute;
  right: 9%;
  bottom: calc(4.1% + env(safe-area-inset-bottom));
  z-index: 19;
  color: rgba(244, 244, 241, 0.88);
  font-size: 0.74rem;
  letter-spacing: 0.2em;
  text-shadow: 0 1px 3px rgba(20, 18, 15, 0.6);
  animation: hint-breathe 1.6s ease-in-out infinite;
  pointer-events: none;
}
.screen--game[data-text-mode="dialogue"] .advance-hint {
  color: rgba(36, 35, 31, 0.72);
  text-shadow: none;
}
@keyframes hint-breathe { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

.choice-layer {
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 20%;
  z-index: 25;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.choice-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 64%;
  pointer-events: auto;
  animation: text-in 240ms ease-out;
}
.choice-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 1px;
  background: rgba(236, 237, 234, 0.94);
  color: var(--ink);
  font-size: clamp(18px, 4.2vw, 22px);
  line-height: 1.4;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
  cursor: pointer;
  transition: background-color 140ms, transform 120ms;
}
.choice-button:hover,
.choice-button:focus-visible {
  border-color: var(--ink);
  background: rgba(211, 213, 210, 0.96);
  outline: none;
}
.choice-button:active { transform: translateY(1px); }
.choice-button--primary::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 50%;
  width: 7px;
  height: 2px;
  background: var(--ink);
  transform: translateY(-50%);
}

/* 过往文字 */
.history-layer {
  position: absolute;
  inset: 0;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(32px + env(safe-area-inset-top)) 27px calc(32px + env(safe-area-inset-bottom));
  background: rgba(29, 28, 25, 0.62);
}
.history-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 82%;
  padding: 17px;
  border: 2px solid var(--ink);
  outline: 1px solid rgba(36, 35, 31, 0.55);
  outline-offset: -6px;
  background: var(--paper) url("./assets/ui/ui_02_paper.png") center / cover;
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 3px 12px;
  border-bottom: 1px solid rgba(36, 35, 31, 0.42);
}
.history-header h2 { font-size: 1.35rem; font-weight: 400; letter-spacing: 0.4em; text-indent: 0.4em; }
.history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 5px 4px;
  scrollbar-color: rgba(36, 35, 31, 0.4) transparent;
}
.history-item { padding: 9px 5px; border-bottom: 1px dashed rgba(36, 35, 31, 0.22); }
.history-item--dialogue { padding-left: 17px; }
.history-speaker { margin-bottom: 3px; color: var(--ink-soft); font-size: 0.76rem; letter-spacing: 0.2em; }
.history-text { color: var(--ink); font-size: 0.92rem; line-height: 1.75; letter-spacing: 0.04em; }
.history-empty { padding-top: 36px; color: var(--ink-soft); text-align: center; letter-spacing: 0.12em; }

/* 结局抽签 */
.ending-layer {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--paper) url("./assets/ui/ui_02_paper.png") center / cover;
  animation: screen-in 320ms ease-out;
}
.fortune-tube { width: 46%; max-width: 240px; }
.fortune-tube img { display: block; width: 100%; }
.fortune-tube.is-shaking { animation: tube-shake 1.65s ease-in-out; }
@keyframes tube-shake {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(-4deg) translateY(-2px); }
  30% { transform: rotate(3.5deg); }
  45% { transform: rotate(-3deg) translateY(-3px); }
  60% { transform: rotate(2.5deg); }
  75% { transform: rotate(-1.5deg); }
  88% { transform: rotate(1deg); }
}
.ending-result {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: none;
  height: 100%;
}
.ending-book {
  width: 100%;
  height: min(44dvh, 380px);
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 0 4px 18px rgba(36, 35, 31, 0.2);
  animation: text-in 380ms ease-out;
}
.ending-book img { display: block; width: 100%; height: 100%; object-fit: contain; }
.ending-slip,
.fortune-sign {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: min(61dvh, 520px);
  background: transparent;
  writing-mode: vertical-rl;
}
.ending-slip {
  margin-top: -10px;
  transform: translateY(12px) rotate(8deg);
  filter: drop-shadow(0 5px 4px rgba(24, 24, 22, 0.17));
  animation: slip-drop 480ms ease-out 180ms backwards;
}
.ending-result--sign-only .ending-slip {
  width: 72px;
  height: min(61dvh, 520px);
  margin-top: 10px;
}
.ending-slip-image,
.fortune-sign__image {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.ending-slip-title,
.fortune-sign__title {
  position: relative;
  z-index: 1;
  margin-top: 38%;
  color: var(--ink);
  font-size: clamp(16px, 3.8vw, 20px);
  line-height: 1.15;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
}
.ending-result:not(.ending-result--sign-only) .ending-slip {
  position: absolute;
  right: 12%;
  bottom: 46%;
  z-index: 3;
  width: 43px;
  height: 228px;
  margin: 0;
}
.ending-result:not(.ending-result--sign-only) .ending-slip-title { margin-top: 42%; font-size: 12px; }
@keyframes slip-drop {
  from { opacity: 0; transform: translateY(-32px) rotate(8deg); }
  to { opacity: 1; transform: translateY(12px) rotate(8deg); }
}
.ending-actions {
  position: absolute;
  left: 50%;
  bottom: 5.5%;
  z-index: 5;
  width: 70%;
  margin: 0;
  transform: translateX(-50%);
  animation: text-in 280ms ease-out 520ms backwards;
}
.ending-result:not(.ending-result--sign-only) .ending-book {
  position: absolute;
  inset: 7%;
  z-index: 1;
  width: auto;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: 0 4px 18px rgba(36, 35, 31, 0.16);
}
.ending-result:not(.ending-result--sign-only) .ending-book img { object-fit: cover; }
.ending-result:not(.ending-result--sign-only) .ending-actions {
  left: 50%;
  bottom: 5.5%;
  width: 70%;
}

/* 结局图鉴 */
.screen--gallery { padding: calc(20px + env(safe-area-inset-top)) 22px calc(20px + env(safe-area-inset-bottom)); }
.gallery-header { margin-bottom: 14px; text-align: center; }
.gallery-header h2 { font-size: 1.6rem; font-weight: 400; letter-spacing: 0.4em; text-indent: 0.4em; }
.gallery-count { margin-top: 4px; color: var(--ink-soft); font-size: 0.75rem; letter-spacing: 0.2em; }
.gallery-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-content: start;
  gap: 14px;
  min-height: 0;
  padding: 2px;
  overflow-y: auto;
}
.gallery-item {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 1px;
  background: rgba(236, 237, 234, 0.52);
  color: var(--ink);
  text-align: center;
  cursor: pointer;
}
.gallery-item:focus-visible { outline: 1px solid var(--ink); outline-offset: 2px; }
.gallery-item img { display: block; width: 100%; }
.gallery-item-title { margin-top: 6px; color: var(--ink); font-size: 0.88rem; letter-spacing: 0.2em; }
.gallery-item.is-locked { cursor: default; opacity: 0.64; }
.gallery-locked-face {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 3 / 4;
  border: 1px dashed rgba(36, 35, 31, 0.35);
  color: var(--ink-soft);
  font-size: 1rem;
  letter-spacing: 0.3em;
}
.fortune-sign--gallery {
  width: 42px;
  height: 150px;
  margin: 4px auto;
}
.fortune-sign { transform: translateY(5px) rotate(9deg); filter: drop-shadow(0 3px 3px rgba(24, 24, 22, 0.14)); }
.fortune-sign--gallery .fortune-sign__title { margin-top: 44%; font-size: 0.72rem; }
.gallery-back { width: 46%; margin-top: 14px; align-self: center; }
.gallery-detail {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(29, 28, 25, 0.6);
  animation: screen-in 200ms ease-out;
}
.gallery-detail-card {
  width: 78%;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--paper) url("./assets/ui/ui_02_paper.png") center / cover;
  text-align: center;
}
.gallery-detail-card > img { display: block; width: 100%; }
.gallery-detail-title { margin: 10px 0 12px; color: var(--ink); font-size: 1.1rem; letter-spacing: 0.35em; text-indent: 0.35em; }
.gallery-detail-sign { display: flex; justify-content: center; margin-bottom: 17px; }
.fortune-sign--detail { width: 64px; height: min(60dvh, 500px); }

@media (max-height: 700px) {
  .ending-result--sign-only .ending-slip { height: 420px; }
  .fortune-sign--detail { height: 400px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
