:root {
  /* 敦煌沙黃基底 */
  --ink-paper: #f0e3c4;
  --ink-paper-2: #e1d2a8;
  --ink-paper-3: #d4c08a;
  /* 文字 */
  --ink-black: #2a1f10;
  --ink-grey: #7a6443;
  /* 敦煌色系 */
  --dh-vermilion: #b54225;   /* 朱砂紅 */
  --dh-cinnabar:  #c75a3c;   /* 銀朱 */
  --dh-azure:     #2e5a86;   /* 石青 */
  --dh-malachite: #5e8a5a;   /* 石綠 */
  --dh-gold:      #c89540;   /* 藤黃 */
  --dh-ochre:     #a87838;   /* 土黃 */
  /* 語義別名（保持舊識別字） */
  --ink-red: var(--dh-vermilion);
  --font-serif: "Noto Serif TC", "Songti SC", serif;
  --font-sans: "Noto Sans TC", -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  color: var(--ink-black);
  font-family: var(--font-serif);
  background:
    radial-gradient(ellipse at top, rgba(200,149,64,0.10), transparent 60%),
    radial-gradient(ellipse at bottom right, rgba(181,66,37,0.06), transparent 50%),
    linear-gradient(180deg, var(--ink-paper) 0%, #ead8b0 100%);
  background-attachment: fixed;
}
button { font: inherit; cursor: pointer; }

#app { max-width: 1200px; margin: 0 auto; padding: 24px; min-height: 100vh; }

/* Page-level placeholders (filled in later tasks) */
.page-index, .page-play, .page-result {}

/* ---------- index.html ---------- */
.page-index header {
  text-align: center;
  padding: 56px 0 36px;
  margin-bottom: 40px;
  position: relative;
  border-bottom: none;
}
.page-index header::before,
.page-index header::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background:
    linear-gradient(90deg, transparent 0%, var(--dh-gold) 20%, var(--dh-vermilion) 50%, var(--dh-gold) 80%, transparent 100%);
}
.page-index header::before { top: 0; opacity: 0.6; }
.page-index header::after {
  bottom: 0;
  background:
    linear-gradient(90deg, transparent 0%, var(--ink-black) 18%, var(--dh-vermilion) 50%, var(--ink-black) 82%, transparent 100%);
  opacity: 0.5;
}

.title-vertical {
  font-size: 54px;
  font-weight: 700;
  letter-spacing: 14px;
  display: inline-block;
  position: relative;
  text-shadow:
    0 0 1px rgba(181,66,37,0.4),
    1px 1px 0 rgba(0,0,0,0.08);
  background: linear-gradient(180deg, var(--ink-black) 0%, #4a3220 70%, var(--dh-ochre) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.title-vertical::before {
  /* 左側雲紋裝飾 */
  content: "";
  position: absolute;
  left: -90px; top: 50%;
  width: 70px; height: 28px;
  transform: translateY(-50%);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 70 28'><g fill='none' stroke='%23b54225' stroke-width='1.6' stroke-linecap='round'><path d='M2 14 C 8 6, 18 6, 22 14 C 26 6, 36 6, 42 14 C 46 8, 56 8, 62 14'/><circle cx='66' cy='14' r='2.2' fill='%23c89540' stroke='none'/></g></svg>");
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0.85;
}
.title-vertical::after {
  /* 右側「皇帝」朱印含寶相花紋邊 */
  content: "皇帝";
  position: absolute;
  top: 20px; right: -64px;
  width: 46px; height: 46px;
  background:
    radial-gradient(circle at 50% 50%, var(--dh-vermilion) 0%, var(--dh-vermilion) 64%, #8a2f1c 100%);
  color: var(--ink-paper);
  -webkit-text-fill-color: var(--ink-paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  transform: rotate(-5deg);
  letter-spacing: 2px;
  box-shadow:
    inset 0 0 0 2px var(--ink-paper),
    inset 0 0 0 3px var(--dh-vermilion),
    1px 2px 0 rgba(0,0,0,0.2);
  font-weight: 700;
}

.page-index .subtitle {
  margin-top: 14px;
  color: var(--ink-grey);
  letter-spacing: 6px;
  font-size: 14px;
  position: relative;
  display: inline-block;
}
.page-index .subtitle::before,
.page-index .subtitle::after {
  content: "❖";
  color: var(--dh-gold);
  margin: 0 14px;
  font-size: 10px;
  vertical-align: middle;
  opacity: 0.7;
}

.emperor-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  margin-bottom: 40px;
}

.emperor-card {
  background: rgba(255, 250, 232, 0.6);
  border: 1px solid var(--ink-black);
  padding: 24px 20px 22px;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.emperor-card::before,
.emperor-card::after {
  /* 寶相花角飾 */
  content: "";
  position: absolute;
  width: 22px; height: 22px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'><g fill='none' stroke='%23c89540' stroke-width='0.9'><circle cx='11' cy='11' r='2.5' fill='%23b54225' stroke='none'/><path d='M11 4 Q 13 8 11 11 Q 9 8 11 4 M 11 18 Q 13 14 11 11 Q 9 14 11 18 M 4 11 Q 8 9 11 11 Q 8 13 4 11 M 18 11 Q 14 9 11 11 Q 14 13 18 11'/></g></svg>");
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0.85;
}
.emperor-card::before { top: 6px; left: 6px; }
.emperor-card::after { bottom: 6px; right: 6px; transform: rotate(180deg); }
.emperor-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(168,120,56,0.25);
}
.emperor-card .portrait-frame {
  width: 100%;
  aspect-ratio: 3/4;
  margin-bottom: 16px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  border: 1px solid rgba(168,120,56,0.4);
  background: #dfeaef;
}
.emperor-card .portrait-frame img {
  width: 100%; height: 100%; object-fit: cover;
}
.emperor-card .portrait-frame svg.chibi {
  width: 100%; height: 100%; display: block;
}
.emperor-card h2 { font-size: 26px; margin-bottom: 6px; }
.emperor-card .reign { font-size: 14px; color: var(--ink-grey); margin-bottom: 14px; letter-spacing: 2px; }
.emperor-card .intro { font-size: 16px; line-height: 1.75; min-height: 5em; margin-bottom: 18px; }

.btn-enter {
  background: var(--ink-black);
  color: var(--ink-paper);
  padding: 12px 32px;
  border: none;
  font-size: 17px;
  letter-spacing: 6px;
  font-family: var(--font-serif);
}
.btn-enter:hover { background: var(--ink-red); }

.footer-controls {
  position: fixed;
  bottom: 20px; right: 20px;
}
#btn-mute {
  background: var(--ink-paper-2);
  border: 1px solid var(--ink-black);
  width: 40px; height: 40px;
  font-size: 18px;
}

/* RWD */
@media (max-width: 1023px) {
  .emperor-list { grid-template-columns: 1fr; }
  .title-vertical { font-size: 36px; letter-spacing: 8px; }
}

/* ---------- play.html ---------- */
.page-play .top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--ink-black);
  padding-bottom: 12px;
  margin-bottom: 18px;
  gap: 16px;
  flex-wrap: wrap;
}

#phase-indicator {
  display: flex; align-items: center; gap: 14px;
  font-size: 17px;
  color: var(--ink-grey);
}
#phase-indicator .phase-name { color: var(--ink-black); font-size: 18px; letter-spacing: 2px; }
#phase-indicator .phase-dots { display: flex; gap: 6px; }
#phase-indicator .dot {
  width: 12px; height: 12px;
  border: 1px solid var(--ink-black);
  border-radius: 50%;
}
#phase-indicator .dot.active { background: var(--ink-black); }
#phase-indicator .reign-year {
  font-size: 16px;
  border-left: 1px solid var(--ink-grey);
  padding-left: 14px;
}

#stats-bar { display: flex; gap: 18px; }
.stat {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 64px;
}
.stat-label { font-size: 14px; color: var(--ink-grey); letter-spacing: 1px; }
.stat-bar {
  width: 64px; height: 7px;
  background: rgba(0,0,0,0.1);
}
.stat-bar > div {
  height: 100%;
  background: var(--ink-black);
  transition: width 0.5s ease-out;
}
.stat.warn .stat-bar > div { background: var(--ink-red); animation: pulse 1.4s infinite; }
.stat-val { font-size: 15px; font-weight: 700; }
@keyframes pulse { 0%,100%{opacity:.5} 50%{opacity:1} }

.scene {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 24px;
  border-top: 1px solid rgba(0,0,0,0.6);
  border-bottom: 1px solid rgba(0,0,0,0.6);
  padding: 22px 0;
  margin: 18px 0 24px;
  position: relative;
  min-height: 280px;
}

.scroll { position: relative; }
.scroll .stamp {
  position: absolute; top: 0; right: 0;
  width: 52px; height: 52px;
  background:
    radial-gradient(circle at 50% 50%, var(--dh-vermilion) 0%, var(--dh-vermilion) 66%, #8a2f1c 100%);
  color: var(--ink-paper);
  display: flex; align-items: center; justify-content: center;
  transform: rotate(-7deg);
  font-size: 14px; font-weight: 700;
  letter-spacing: 2px;
  box-shadow:
    inset 0 0 0 2px var(--ink-paper),
    inset 0 0 0 3px var(--dh-vermilion),
    1px 2px 0 rgba(0,0,0,0.22);
  cursor: pointer;
}
.scroll .stamp.hidden { display: none; }
.event-title {
  font-size: 30px; font-weight: 700;
  letter-spacing: 3px;
  margin-bottom: 14px;
  display: flex; align-items: baseline; gap: 14px;
}
.event-title .event-meta {
  font-size: 15px; color: var(--ink-grey); letter-spacing: 0;
}
.narrative {
  font-size: 18px; line-height: 1.9;
  text-indent: 2em;
}

#choices-area { display: flex; flex-direction: column; gap: 12px; }
.choice {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px;
  border: 1px solid var(--ink-black);
  background: rgba(255,255,255,0.4);
  font-size: 17px;
  font-family: var(--font-serif);
  transition: all 0.15s;
  text-align: left;
}
.choice:hover {
  background: var(--ink-red);
  color: var(--ink-paper);
  border-color: var(--ink-red);
}
.choice .shi-mark {
  font-size: 13px; padding: 4px 10px;
  border: 1px solid currentColor;
  letter-spacing: 2px;
}

@media (max-width: 1023px) {
  .page-play .top-bar { flex-direction: column; align-items: flex-start; }
  #stats-bar { width: 100%; overflow-x: auto; padding-bottom: 4px; }
  .scene { grid-template-columns: 1fr; gap: 16px; }
}

/* ---------- character ---------- */
.character {
  display: flex; flex-direction: column; align-items: center;
  position: relative;
  min-height: 240px;
}
.char-img-wrap { width: 180px; max-height: 240px; }
.char-img, .char-placeholder {
  width: 100%; height: auto;
  object-fit: contain;
  filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.15));
}
.char-name {
  margin-top: 10px;
  font-size: 19px;
  font-weight: 700;
  color: var(--ink-red);
  background: rgba(139,31,26,0.08);
  padding: 6px 18px;
  letter-spacing: 5px;
}
.speech {
  background: white;
  border: 1px solid var(--ink-black);
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 18px;
  line-height: 1.5;
  margin-bottom: 14px;
  position: relative;
  animation: pop 0.4s ease-out;
  max-width: 260px;
}
.speech::after {
  content: "";
  position: absolute; bottom: -7px; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid var(--ink-black);
}
@keyframes pop { from { transform: scale(0) } to { transform: scale(1) } }

/* Idle: subtle float */
.anim-idle .char-img-wrap,
.anim-speak .char-img-wrap { animation: idle 3s ease-in-out infinite; }
@keyframes idle { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-5px) } }

/* Speak: bob faster */
.anim-speak .char-img-wrap { animation: idle 1.4s ease-in-out infinite; }

/* Angry: shake */
.anim-angry .char-img-wrap { animation: shake 0.4s ease-in-out infinite; }
@keyframes shake {
  0%,100% { transform: rotate(-1.5deg) }
  50% { transform: rotate(1.5deg) }
}

/* Sad: drift down */
.anim-sad .char-img-wrap { animation: sad 3s ease-in-out infinite; }
@keyframes sad {
  0%,100% { transform: translateY(2px); filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.15)) brightness(0.95) }
  50% { transform: translateY(5px) }
}

/* Happy: bounce */
.anim-happy .char-img-wrap { animation: bounce 0.8s ease-in-out infinite; }
@keyframes bounce {
  0%,100% { transform: translateY(0) }
  40% { transform: translateY(-10px) }
}

/* Reactions (one-shot) */
.anim-bow .char-img-wrap { animation: bow 1s ease-out forwards; }
@keyframes bow {
  0% { transform: rotate(0) }
  60% { transform: rotate(28deg) }
  100% { transform: rotate(20deg) }
}

.anim-defeat .char-img-wrap { animation: defeat 1s ease-out forwards; }
@keyframes defeat {
  0% { transform: rotate(0); opacity: 1 }
  60% { transform: rotate(85deg) translateY(20px); opacity: 0.8 }
  100% { transform: rotate(90deg) translateY(30px); opacity: 0.5 }
}

/* No-animation accessibility class */
body.no-anim *, body.no-anim *::before, body.no-anim *::after {
  animation: none !important;
  transition: none !important;
}

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fade-in 0.3s;
}
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }

.modal {
  background: var(--ink-paper);
  border: 1px solid var(--ink-black);
  padding: 32px 28px 24px;
  max-width: 520px;
  width: 90%;
  position: relative;
  animation: modal-up 0.4s ease-out;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
@keyframes modal-up {
  from { transform: translateY(40px); opacity: 0 }
  to { transform: translateY(0); opacity: 1 }
}

.kc-modal .kc-stamp {
  position: absolute; top: 14px; right: 14px;
  width: 48px; height: 48px;
  background:
    radial-gradient(circle at 50% 50%, var(--dh-vermilion) 0%, var(--dh-vermilion) 66%, #8a2f1c 100%);
  color: var(--ink-paper);
  display: flex; align-items: center; justify-content: center;
  transform: rotate(-6deg);
  font-size: 14px; font-weight: 700;
  letter-spacing: 2px;
  box-shadow:
    inset 0 0 0 2px var(--ink-paper),
    inset 0 0 0 3px var(--dh-vermilion);
}

.kc-title {
  font-size: 26px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--ink-black);
  padding-bottom: 10px;
  padding-right: 60px;
}
.kc-body { font-size: 18px; line-height: 1.9; margin-bottom: 14px; }
.kc-source { font-size: 14px; color: var(--ink-grey); margin-bottom: 18px; font-style: italic; }

.historical-modal h3 { font-size: 22px; margin-bottom: 14px; border-bottom: 1px solid var(--ink-black); padding-bottom: 8px; }
.historical-body {
  font-size: 18px; line-height: 1.9;
  background: rgba(139,31,26,0.04);
  padding: 16px 18px;
  border-left: 3px solid var(--ink-red);
  margin-bottom: 18px;
}

.btn-close {
  background: var(--ink-black); color: var(--ink-paper);
  border: none;
  padding: 10px 28px;
  font-size: 16px;
  font-family: var(--font-serif);
  letter-spacing: 4px;
}
.btn-close:hover { background: var(--ink-red); }

/* ---------- result.html ---------- */
.page-result #result-card {
  background: rgba(255,255,255,0.4);
  border: 1px solid var(--ink-black);
  padding: 40px;
  margin-bottom: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}
.result-section-title {
  font-size: 20px;
  margin-bottom: 14px;
  letter-spacing: 4px;
  border-bottom: 1px solid var(--ink-black);
  padding-bottom: 8px;
}

.ending-stamp { text-align: center; grid-column: 1 / -1; }
.ending-stamp svg { display: block; margin: 0 auto; animation: stamp-press 0.6s ease-out; }
@keyframes stamp-press {
  0% { transform: scale(1.3) rotate(-15deg); opacity: 0 }
  60% { transform: scale(0.95) rotate(0deg); opacity: 1 }
  100% { transform: scale(1) rotate(-3deg) }
}
.ending-score { margin-top: 10px; font-size: 18px; letter-spacing: 4px; color: var(--ink-grey); }

#radar-chart svg.radar { display: block; }

.timeline-line {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.timeline-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.03);
  border-left: 2px solid var(--ink-red);
}
.timeline-dot {
  width: 30px; height: 30px;
  background: var(--ink-red); color: var(--ink-paper);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  border-radius: 50%;
  flex-shrink: 0;
}
.t-title { font-size: 16px; font-weight: 700; }
.t-choice { font-size: 14px; color: var(--ink-grey); margin-top: 3px; }

.result-controls {
  display: flex; gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
}
.result-controls button {
  background: var(--ink-black); color: var(--ink-paper);
  border: none;
  padding: 12px 26px;
  font-size: 17px;
  letter-spacing: 2px;
  font-family: var(--font-serif);
}
.result-controls button:hover { background: var(--ink-red); }

@media (max-width: 1023px) {
  .page-result #result-card { grid-template-columns: 1fr; padding: 24px; }
  #radar-chart svg { max-width: 100%; height: auto; }
}

.history-compare {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
  grid-column: 1 / -1;
}
.history-compare th, .history-compare td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}
.history-compare th {
  background: rgba(139,31,26,0.08);
  color: var(--ink-red);
  letter-spacing: 2px;
}
.history-compare td:first-child { font-weight: 700; }
.history-compare td:nth-child(3) { color: var(--ink-grey); }

#history-compare { grid-column: 1 / -1; }

#btn-settings {
  background: var(--ink-paper-2);
  border: 1px solid var(--ink-black);
  width: 40px; height: 40px;
  font-size: 16px;
}

#settings-panel {
  position: absolute; bottom: 50px; right: 0;
  background: var(--ink-paper);
  border: 1px solid var(--ink-black);
  padding: 16px;
  width: 200px;
  display: flex; flex-direction: column; gap: 8px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}
#settings-panel.hidden { display: none; }
#settings-panel label { display: flex; align-items: center; gap: 8px; }
#settings-panel input[type=range] { flex: 1; }
