:root {
  --paper: #f5ead0;
  --paper-deep: #e5d0a4;
  --ink: #2d241c;
  --muted-ink: #6f5a47;
  --vermilion: #8d2828;
  --vermilion-dark: #591818;
  --gold: #b88a3b;
  --gold-light: #e2c278;
  --jade: #477465;
  --shadow: 0 18px 50px rgb(45 27 16 / 24%);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #2c1b18; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  background:
    radial-gradient(circle at 20% 10%, rgb(226 194 120 / 16%) 0 1px, transparent 2px),
    radial-gradient(circle at 80% 70%, rgb(226 194 120 / 12%) 0 1px, transparent 2px),
    linear-gradient(145deg, #3c1718, #1e1513 62%, #32191a);
  background-size: 22px 22px, 29px 29px, auto;
}

button { font: inherit; }
.hidden { display: none !important; }

.page-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(30px, env(safe-area-inset-bottom));
}

.masthead {
  display: flex;
  align-items: center;
  gap: 13px;
  margin: 0 auto 18px;
  color: #f8eacc;
}

.masthead h1 { margin: 0; font-size: clamp(1.55rem, 6vw, 2.2rem); letter-spacing: .18em; }
.eyebrow { margin: 0 0 2px; color: var(--gold-light); font-size: .72rem; letter-spacing: .16em; }
.seal { display: grid; width: 48px; aspect-ratio: 1; place-items: center; border: 2px solid #edc978; color: #edc978; font-size: 1.45rem; transform: rotate(-3deg); }

.scroll-card {
  position: relative;
  overflow: hidden;
  padding: clamp(24px, 6vw, 46px);
  border: 1px solid #c59b56;
  border-radius: 3px;
  background:
    linear-gradient(90deg, rgb(126 73 34 / 7%) 1px, transparent 1px),
    radial-gradient(circle at 30% 20%, rgb(255 255 255 / 40%), transparent 30%),
    var(--paper);
  background-size: 5px 100%, auto, auto;
  box-shadow: inset 0 0 45px rgb(122 75 31 / 14%), var(--shadow);
}

.scroll-card::before,
.scroll-card::after { content: ""; position: absolute; left: 0; right: 0; height: 7px; background: linear-gradient(90deg, var(--vermilion-dark), var(--gold), var(--vermilion-dark)); }
.scroll-card::before { top: 0; }
.scroll-card::after { bottom: 0; }

.start-card { min-height: min(72vh, 680px); display: grid; align-content: center; text-align: center; }
.start-card h2, .settlement-card > h2 { margin: 8px 0 18px; color: var(--vermilion-dark); font-size: clamp(1.8rem, 7vw, 2.8rem); letter-spacing: .12em; }
.lead { font-size: 1.08rem; line-height: 2; }
.chapter-mark { margin: 0; color: var(--vermilion); font-size: .76rem; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; }

.imperial-button {
  min-height: 50px;
  padding: 12px 20px;
  border: 1px solid var(--gold);
  border-radius: 2px;
  font-weight: 700;
  letter-spacing: .08em;
  cursor: pointer;
  box-shadow: 0 5px 12px rgb(55 24 19 / 20%), inset 0 0 0 2px rgb(255 255 255 / 12%);
  transition: transform 160ms ease, filter 160ms ease;
}

.imperial-button:hover { filter: brightness(1.08); transform: translateY(-1px); }
.imperial-button:active { transform: translateY(1px); }
.imperial-button:focus-visible, .option-grid button:focus-visible, .text-button:focus-visible { outline: 3px solid var(--gold-light); outline-offset: 3px; }
.imperial-button:disabled { cursor: wait; opacity: .65; }
.primary-button { color: #fff7e8; background: linear-gradient(180deg, #a53737, var(--vermilion-dark)); }
.secondary-button { color: var(--vermilion-dark); background: linear-gradient(180deg, #f4e5bd, #d9bd7c); }
.start-card .imperial-button { width: min(100%, 320px); margin: 24px auto 0; }

.progress-panel { margin-bottom: 12px; padding: 13px 16px; border: 1px solid #8f6a3a; color: #f6e8c8; background: rgb(24 14 13 / 72%); }
.progress-copy { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: .8rem; letter-spacing: .08em; }
progress { width: 100%; height: 14px; border: 0; border-radius: 0; background: #281918; }
progress::-webkit-progress-bar { border: 1px solid #8e713a; background: repeating-linear-gradient(90deg, #2e201c 0 9.5%, #a37a3e 10%); }
progress::-webkit-progress-value { background: linear-gradient(90deg, #477465, #79a38f); box-shadow: inset 0 0 5px #d6e6c8; }
progress::-moz-progress-bar { background: linear-gradient(90deg, #477465, #79a38f); }

.question-card h2 { margin: 8px 0 14px; color: var(--vermilion-dark); }
.scene-text { font-size: 1.08rem; line-height: 1.9; }
.artifact-visual { margin: 20px 0; }
.artifact-image-frame {
  display: grid;
  min-height: 230px;
  margin-top: 8px;
  place-items: center;
  overflow: hidden;
  border: 1px solid #b9985a;
  background: linear-gradient(145deg, #e2cca0, #f8edcf);
  box-shadow: inset 0 0 24px rgb(75 47 24 / 14%);
}
.artifact-image-frame img {
  display: block;
  width: 100%;
  max-height: min(48vh, 430px);
  object-fit: contain;
}
.artifact-image-frame p { margin: 0; color: var(--muted-ink); }
.result-phase { scroll-margin-top: 16px; }
.result-artifact-visual { margin-top: 16px; }
.label { color: var(--vermilion); font-size: .75rem; font-weight: 700; letter-spacing: .15em; }
.choices-fieldset { margin: 24px 0 0; padding: 0; border: 0; }
.choices-fieldset legend { margin-bottom: 12px; font-size: 1.08rem; font-weight: 700; }
.option-grid { display: grid; gap: 10px; }
.option-grid button { min-height: 54px; padding: 12px 16px; border: 1px solid #b9985a; color: var(--ink); text-align: left; background: rgb(255 250 235 / 70%); box-shadow: 0 3px 8px rgb(66 42 22 / 10%); cursor: pointer; }
.option-grid button::before { content: "◆"; margin-right: 9px; color: var(--vermilion); font-size: .68rem; }
.option-grid button:disabled { color: var(--muted-ink); background: rgb(214 201 170 / 45%); cursor: not-allowed; }

.result-panel { margin-top: 22px; padding: 15px 18px; border: 1px solid currentColor; background: rgb(255 255 255 / 30%); }
.result-status { margin: 0 0 6px; font-size: 1.3rem; font-weight: 800; }
.correct { color: #315f4c; }
.incorrect { color: #962d2d; }
.knowledge-card { margin: 16px 0 20px; padding: 19px; border: 1px solid #ad8b50; background: #ead9b5; box-shadow: inset 0 0 20px rgb(119 78 35 / 13%); }
.knowledge-card h3 { margin: 5px 0 14px; color: var(--vermilion-dark); font-size: 1.35rem; }
.knowledge-card dl { margin: 0; }
.knowledge-card dl > div { display: grid; grid-template-columns: 5.3em 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px dashed rgb(111 90 71 / 35%); }
.knowledge-card dt { color: var(--vermilion); font-weight: 700; }
.knowledge-card dd { margin: 0; line-height: 1.65; }
#next-button { width: 100%; }

.settlement-card { text-align: center; }
.score-medallion { display: grid; width: 120px; aspect-ratio: 1; margin: 10px auto 18px; place-content: center; border: 2px solid var(--gold); border-radius: 50%; color: var(--vermilion-dark); background: radial-gradient(circle, #fff5d9, #dec181); box-shadow: 0 7px 20px rgb(83 44 22 / 25%), inset 0 0 0 6px #f5e6b8; }
.score-medallion strong { font-size: 2.7rem; line-height: .9; }
.score-medallion span { font-size: .85rem; }
.title-label { margin: 0; color: var(--muted-ink); font-size: .72rem; letter-spacing: .2em; }
.settlement-title { margin: 7px 0; color: var(--vermilion); font-size: clamp(1.55rem, 6vw, 2.3rem); }
.settlement-description { max-width: 34em; margin: 0 auto 22px; line-height: 1.8; }
.answer-columns { display: grid; gap: 14px; text-align: left; }
.answer-group { padding: 16px; border: 1px solid #bea065; background: rgb(255 251 237 / 48%); }
.answer-group h3 { margin: 0 0 10px; }
.answer-group ul { margin: 0; padding: 0; list-style: none; }
.answer-group li { padding: 8px 0 8px 1.2em; border-bottom: 1px dashed rgb(111 90 71 / 28%); line-height: 1.55; text-indent: -1.2em; }
.answer-group li::before { content: "·"; margin-right: .55em; color: var(--gold); font-weight: 900; }
.wrong-group h3 { color: #8d2828; }
.correct-group h3 { color: #315f4c; }
.history-meta { margin: 18px 0 0; color: var(--muted-ink); font-size: .78rem; }
.share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.share-actions .text-button, .bridge-status { grid-column: 1 / -1; }
.text-button { border: 0; color: #f2dcae; background: transparent; text-decoration: underline; cursor: pointer; }
.bridge-status { min-height: 1.4em; margin: 0; color: #f3dfb4; text-align: center; font-size: .82rem; }

.debug-panel { margin-top: 22px; padding: 12px; border: 1px dashed rgb(226 194 120 / 55%); color: #edd9ac; font-family: system-ui, sans-serif; font-size: .78rem; }
.debug-panel summary { cursor: pointer; }
.debug-panel button { margin: 8px 4px 4px 0; padding: 7px; }
.debug-panel pre { overflow: auto; white-space: pre-wrap; }

@media (min-width: 640px) {
  .page-shell { padding-inline: 28px; }
  .answer-columns { grid-template-columns: 1fr 1fr; align-items: start; }
}

@media (max-width: 420px) {
  .page-shell { padding-inline: 10px; }
  .masthead { padding-inline: 6px; }
  .scroll-card { padding: 25px 20px; }
  .progress-copy span:last-child { display: none; }
  .knowledge-card dl > div { grid-template-columns: 1fr; gap: 2px; }
  .share-actions { grid-template-columns: 1fr; }
  .share-actions .text-button, .bridge-status { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
