:root {
  --ink: #161413;
  --paper: #f4ead0;
  --page: #fff8e8;
  --gold: #d6aa4f;
  --red: #a6453e;
  --green: #315f56;
  --blue: #305b76;
  --violet: #56426d;
  --line: rgba(244, 234, 208, 0.28);
  --shadow: rgba(0, 0, 0, 0.36);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #171615;
  color: var(--paper);
}

body,
button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  overflow-x: hidden;
}

.stage {
  position: relative;
  min-height: 100vh;
  padding: 28px;
}

.scene-media,
.scene-media img,
.scene-vignette {
  position: fixed;
  inset: 0;
}

.scene-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.04);
  filter: saturate(0.9) contrast(1.08);
  transition: opacity 360ms ease, transform 700ms ease;
}

.scene-vignette {
  background:
    radial-gradient(circle at 26% 18%, rgba(214, 170, 79, 0.2), transparent 28%),
    linear-gradient(90deg, rgba(17, 15, 15, 0.9), rgba(17, 15, 15, 0.55) 45%, rgba(17, 15, 15, 0.84)),
    linear-gradient(180deg, rgba(17, 15, 15, 0.16), rgba(17, 15, 15, 0.92));
}

.book-surface,
.bottom-layer {
  position: relative;
  z-index: 1;
  width: min(1280px, 100%);
  margin: 0 auto;
}

.book-surface {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 300px;
  min-height: calc(100vh - 150px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(22, 20, 19, 0.92), rgba(44, 35, 28, 0.9) 28%, rgba(255, 248, 232, 0.95) 28.2%, rgba(255, 248, 232, 0.95) 73%, rgba(27, 24, 24, 0.94) 73.2%),
    var(--page);
  box-shadow: 0 28px 80px var(--shadow);
  overflow: hidden;
  transform-origin: left center;
  animation: bookOpen 900ms cubic-bezier(0.2, 0.78, 0.18, 1) both;
}

.book-index,
.page-panel,
.archive-panel {
  min-width: 0;
  padding: 22px;
}

.book-index,
.archive-panel {
  color: var(--paper);
}

.page-panel {
  position: relative;
  color: var(--ink);
  background:
    linear-gradient(rgba(166, 69, 62, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(166, 69, 62, 0.035) 1px, transparent 1px);
  background-size: 24px 24px;
  overflow: hidden;
}

.page-panel::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 22px;
  width: 1px;
  background: rgba(166, 69, 62, 0.26);
}

.page-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 0%, rgba(255, 248, 232, 0.82) 48%, rgba(22, 20, 19, 0.18) 52%, transparent 100%);
  opacity: 0;
  transform: translateX(-70%) skewX(-8deg);
}

.page-panel.is-turning::after {
  animation: pageTurn 520ms cubic-bezier(0.28, 0.72, 0.22, 1) both;
}

.system-label {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.mark-head {
  display: flex;
  gap: 12px;
  align-items: center;
}

.mark-head img {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 2px solid rgba(214, 170, 79, 0.74);
  object-fit: cover;
}

h1,
h2,
h3,
p {
  letter-spacing: 0;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 29px;
}

.chapter-list {
  display: grid;
  gap: 10px;
  margin: 28px 0;
}

.chapter-list button {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 4px 12px;
  min-height: 72px;
  padding: 12px;
  border: 1px solid rgba(244, 234, 208, 0.22);
  border-radius: 7px;
  background: rgba(244, 234, 208, 0.08);
  color: var(--paper);
  text-align: left;
}

.chapter-list button.is-active {
  background: rgba(214, 170, 79, 0.22);
  border-color: rgba(214, 170, 79, 0.8);
}

.chapter-list span {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--red);
  font-weight: 900;
}

.chapter-list strong,
.chapter-list small {
  min-width: 0;
}

.chapter-list small {
  color: rgba(244, 234, 208, 0.72);
}

.memory-meter {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(244, 234, 208, 0.22);
  border-radius: 7px;
}

.memory-meter div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

meter {
  width: 100%;
}

.page-head {
  margin: 12px 0 22px;
  padding-left: 22px;
}

.page-head h2 {
  font-size: clamp(34px, 7vw, 76px);
  line-height: 1;
}

.page-head p:last-child {
  max-width: 680px;
  margin: 12px 0 0;
  font-size: 17px;
  line-height: 1.8;
  color: #5b5148;
}

.dialogue-box {
  position: relative;
  margin: 0 0 22px 22px;
  padding: 18px;
  border: 1px solid rgba(166, 69, 62, 0.22);
  border-radius: 8px;
  background: rgba(255, 248, 232, 0.78);
  box-shadow: 0 12px 36px rgba(42, 31, 25, 0.1);
}

.speaker {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 14px;
  font-weight: 900;
}

#npcLine,
#questText,
#mediaCue,
#mediaStatus,
#keywordReply {
  line-height: 1.85;
}

#npcLine {
  margin: 0;
  font-size: 19px;
  color: #2f2926;
}

.prop-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 22px 22px;
}

.prop-row button,
.choice-list button {
  min-width: 0;
  border: 1px solid rgba(49, 95, 86, 0.25);
  border-radius: 8px;
  background: rgba(49, 95, 86, 0.08);
  color: var(--ink);
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.prop-row button {
  display: grid;
  gap: 8px;
  min-height: 128px;
  padding: 14px;
}

.prop-row button:hover,
.choice-list button:hover,
.prop-row button:focus-visible,
.choice-list button:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(49, 95, 86, 0.72);
  background: rgba(49, 95, 86, 0.14);
  outline: none;
}

.prop-row strong {
  font-size: 17px;
}

.prop-row span {
  color: #665b51;
  font-size: 14px;
  line-height: 1.7;
}

.choice-area {
  margin-left: 22px;
}

.choice-list {
  display: grid;
  gap: 10px;
}

.choice-list button {
  padding: 14px 16px;
  min-height: 56px;
  font-weight: 800;
}

.keyword-box,
.unlock-box,
.asset-preview {
  border: 1px solid rgba(244, 234, 208, 0.2);
  border-radius: 8px;
  padding: 14px;
  background: rgba(244, 234, 208, 0.07);
}

.keyword-box + .unlock-box,
.unlock-box + .asset-preview {
  margin-top: 14px;
}

.keyword-box label {
  display: block;
  margin-bottom: 10px;
  color: rgba(244, 234, 208, 0.86);
  line-height: 1.65;
}

.keyword-input-row {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 8px;
}

.keyword-input-row input,
.keyword-input-row button {
  min-height: 46px;
  border-radius: 7px;
  border: 1px solid rgba(244, 234, 208, 0.24);
}

.keyword-input-row input {
  min-width: 0;
  padding: 0 12px;
  background: rgba(255, 248, 232, 0.92);
  color: var(--ink);
}

.keyword-input-row button {
  background: var(--gold);
  color: #1d1712;
  font-weight: 900;
}

#keywordReply {
  min-height: 44px;
  margin: 10px 0 0;
  color: rgba(244, 234, 208, 0.88);
}

.unlocked-list {
  display: grid;
  gap: 10px;
}

.fragment {
  display: grid;
  gap: 5px;
  padding: 10px;
  border-radius: 7px;
  background: rgba(255, 248, 232, 0.08);
  color: rgba(244, 234, 208, 0.84);
  line-height: 1.6;
}

.fragment strong {
  color: var(--gold);
}

.asset-preview figure {
  margin: 0;
}

.asset-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(244, 234, 208, 0.18);
}

.asset-preview figcaption {
  margin-top: 8px;
  color: rgba(244, 234, 208, 0.72);
  font-size: 13px;
  line-height: 1.6;
}

.bottom-layer {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.1fr) 220px;
  gap: 14px;
  margin-top: 14px;
}

.bottom-layer > div {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 15, 15, 0.76);
  backdrop-filter: blur(10px);
}

.bottom-layer h3,
.bottom-layer p {
  margin-top: 0;
}

.bottom-layer code {
  display: block;
  width: 100%;
  padding: 10px;
  overflow-wrap: anywhere;
  border-radius: 7px;
  background: rgba(244, 234, 208, 0.1);
  color: var(--gold);
}

.media-controls {
  display: grid;
  gap: 10px;
}

.media-controls audio,
.media-controls video {
  width: 100%;
  border-radius: 8px;
}

.media-controls video {
  max-height: 220px;
  background: #0b0b0b;
}

.site-index {
  position: relative;
  z-index: 1;
  width: min(960px, calc(100% - 36px));
  margin: 0 auto;
  padding: 56px 0;
}

.site-index h1 {
  font-size: clamp(36px, 8vw, 72px);
}

.site-index p {
  max-width: 720px;
  line-height: 1.8;
  color: rgba(244, 234, 208, 0.82);
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  margin-top: 26px;
}

.character-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(244, 234, 208, 0.08);
  color: var(--paper);
  text-decoration: none;
}

.character-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 7px;
  object-fit: cover;
}

.character-card strong {
  font-size: 20px;
}

.character-card span {
  color: rgba(244, 234, 208, 0.72);
  line-height: 1.7;
}

@keyframes bookOpen {
  from {
    opacity: 0;
    transform: perspective(1200px) rotateY(-14deg) translateY(20px);
  }
  to {
    opacity: 1;
    transform: perspective(1200px) rotateY(0deg) translateY(0);
  }
}

@keyframes pageTurn {
  0% {
    opacity: 0;
    transform: translateX(-70%) skewX(-8deg);
  }
  35% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(70%) skewX(-8deg);
  }
}

@media (max-width: 1080px) {
  .book-surface {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .archive-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr 220px;
    gap: 14px;
  }

  .keyword-box + .unlock-box,
  .unlock-box + .asset-preview {
    margin-top: 0;
  }

  .bottom-layer {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .stage {
    padding: 12px;
  }

  .book-surface,
  .archive-panel,
  .bottom-layer,
  .prop-row {
    grid-template-columns: 1fr;
  }

  .book-surface {
    min-height: auto;
    background:
      linear-gradient(180deg, rgba(22, 20, 19, 0.95), rgba(44, 35, 28, 0.92) 23%, rgba(255, 248, 232, 0.96) 23.2%, rgba(255, 248, 232, 0.96) 68%, rgba(27, 24, 24, 0.96) 68.2%),
      var(--page);
  }

  .book-index,
  .page-panel,
  .archive-panel {
    padding: 18px;
  }

  .chapter-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 18px 0;
  }

  .chapter-list button {
    grid-template-columns: 1fr;
    min-height: 118px;
  }

  .chapter-list span {
    grid-row: auto;
  }

  .page-head,
  .dialogue-box,
  .choice-area,
  .prop-row {
    margin-left: 0;
    padding-left: 0;
  }

  .page-panel::before {
    display: none;
  }

  .page-head h2 {
    font-size: 42px;
  }

  #npcLine {
    font-size: 17px;
  }

  .prop-row button {
    min-height: 108px;
  }

  .asset-preview img {
    aspect-ratio: 16 / 10;
  }
}

@media (max-width: 420px) {
  .chapter-list {
    grid-template-columns: 1fr;
  }

  .page-head h2 {
    font-size: 36px;
  }
}
