/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "STSong", "Songti SC", "Noto Serif SC", "Source Han Serif SC", "SimSun", "KaiTi", serif;
  background: #0d0b08;
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; overflow: hidden;
  user-select: none; -webkit-user-select: none;
}

/* ===== Game Container — 16:9 ===== */
#game {
  position: relative; width: 100vw; max-width: 1024px;
  aspect-ratio: 16 / 9; max-height: 100vh;
  overflow: hidden; background: #000;
  box-shadow: 0 0 60px rgba(0,0,0,0.6);
}

/* ===== Dual Background Layer ===== */
.bg-layer {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  transition: opacity 1.2s ease;
}
#bg-layer-0 { z-index: 0; }
#bg-layer-1 { z-index: 0; opacity: 0; }
.bg-layer.dim { filter: brightness(0.5); }

/* ===== Vignette ===== */
#vignette {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.5) 100%);
  transition: opacity 1.2s ease;
}

/* ===== Chapter Card ===== */
#chapter-card {
  position: absolute; inset: 0; z-index: 22;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  background: rgba(6,4,3,0.94);
  opacity: 0; pointer-events: none;
  transition: opacity 0.5s ease;
}
#chapter-card.show { opacity: 1; }
#chapter-card .cc-sub {
  font-size: 12px; color: #8a6a40; letter-spacing: 6px;
  margin-bottom: 16px;
  transform: translateY(20px); opacity: 0;
  transition: all 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
#chapter-card .cc-title {
  font-size: 32px; color: #e0c888; letter-spacing: 10px; font-weight: normal;
  transform: translateY(30px); opacity: 0;
  transition: all 0.7s 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}
#chapter-card.show .cc-sub,
#chapter-card.show .cc-title { transform: translateY(0); opacity: 1; }

/* ===== Character Layer ===== */
#char-layer { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.char-portrait {
  position: absolute; bottom: 0;
  height: 85%; width: auto;
  opacity: 0; filter: brightness(0.6);
  transition: opacity 0.5s ease, transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.5s ease;
}
.char-portrait.show { opacity: 1; filter: brightness(1); }
.char-portrait.left  { left: 4%;  transform: translateY(30px) translateX(-20px); }
.char-portrait.center { left: 50%; transform: translate(-50%, 0) translateY(30px); }
.char-portrait.right { right: 4%; transform: translateY(30px) translateX(20px); }
.char-portrait.left.show   { transform: translateY(0) translateX(0); }
.char-portrait.center.show { transform: translate(-50%, 0) translateY(0); }
.char-portrait.right.show  { transform: translateY(0) translateX(0); }

/* ===== Stats Panel ===== */
#stats-panel {
  position: absolute; top: 10px; right: 14px; z-index: 20;
  background: rgba(16,12,8,0.82); border: 1px solid #5a4a3a; border-radius: 5px;
  padding: 8px 12px; min-width: 130px;
  font-size: 11px; color: #b4a590;
  transition: opacity 0.5s;
}
#stats-panel.hidden { opacity: 0; pointer-events: none; }
.stats-title { text-align: center; font-size: 10px; letter-spacing: 2px; margin-bottom: 4px; color: #8a7a6a; }
#stats-panel .stat { display: flex; align-items: center; gap: 5px; margin: 4px 0; }
#stats-panel .stat-label { width: 52px; text-align: right; font-size: 10px; }
#stats-panel .stat-bar-wrap { flex: 1; height: 5px; background: rgba(255,255,255,0.08); border-radius: 3px; overflow: hidden; }
#stats-panel .stat-bar { height: 100%; border-radius: 3px; transition: width 0.8s ease; }
.bar-trust { background: linear-gradient(90deg, #b88630, #e0c060); }
.bar-law   { background: linear-gradient(90deg, #507a5a, #72a878); }
.bar-risk   { background: linear-gradient(90deg, #a03830, #d44840); }

/* ===== Scene Label ===== */
#scene-label {
  position: absolute; top: 10px; left: 16px; z-index: 15;
  color: #b4a590; font-size: 11px; letter-spacing: 2px;
  opacity: 0; transition: opacity 0.5s;
}
#scene-label.show { opacity: 0.7; }

/* ===== Text Box — vintage paper style ===== */
#text-box-wrap {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 10;
  padding: 18px 28px 22px;
  background: linear-gradient(transparent, rgba(10,7,4,0.94) 15%, rgba(10,7,4,0.97) 100%);
  min-height: 26%;
  display: flex; flex-direction: column; justify-content: flex-end;
  transition: transform 0.4s ease, opacity 0.4s ease;
  border-top: 1px solid rgba(100,70,30,0.12);
}
#text-box-wrap.paper {
  background:
    repeating-linear-gradient(0deg, transparent, transparent 18px, rgba(60,40,20,0.03) 18px, rgba(60,40,20,0.03) 19px),
    linear-gradient(transparent, rgba(10,7,4,0.94) 15%, rgba(10,7,4,0.97) 100%);
}
#text-box-wrap.hidden { transform: translateY(16px); opacity: 0; pointer-events: none; }

#speaker-tag {
  align-self: flex-start; margin-bottom: 8px;
  color: #e0c080; font-size: 13px;
  background: rgba(180,140,80,0.12); border-left: 2px solid rgba(180,140,80,0.5);
  padding: 3px 12px; letter-spacing: 1px;
}
#speaker-tag:empty { display: none; }

#dialog-text {
  color: #e6ddd0; font-size: 15px; line-height: 1.8;
  letter-spacing: 0.5px; min-height: 40px;
}
#dialog-text .highlight { color: #e8c860; text-shadow: 0 0 8px rgba(200,160,60,0.3); }

#indicator {
  align-self: flex-end; color: #7a6a5a; font-size: 11px;
  animation: blink 1.2s infinite; margin-top: 6px;
}
@keyframes blink { 50% { opacity: 0.25; } }

/* Text controls */
#text-controls {
  position: absolute; top: -30px; right: 12px;
  display: flex; gap: 4px; z-index: 11;
}
.tc-btn {
  width: 26px; height: 26px; border-radius: 3px;
  border: 1px solid rgba(100,70,30,0.3);
  background: rgba(14,10,6,0.7); color: #6a5a40;
  font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.tc-btn:hover { border-color: rgba(160,100,40,0.5); color: #a08050; }
.tc-btn.active { background: rgba(160,100,40,0.2); border-color: rgba(180,120,50,0.6); color: #d0a060; }

/* ===== Choice Panel ===== */
#choice-panel {
  position: absolute; bottom: 24%; left: 50%; z-index: 25;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  width: 70%; max-width: 500px;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
#choice-panel.hidden { opacity: 0; transform: translate(-50%, 16px); pointer-events: none; }

.choice-btn {
  padding: 12px 18px;
  background: linear-gradient(135deg, rgba(50,34,18,0.9), rgba(32,20,10,0.92));
  border: 1px solid #5a4028; border-radius: 3px;
  color: #d0b890; font-family: inherit; font-size: 14px;
  cursor: pointer; letter-spacing: 1px;
  transition: all 0.2s; text-align: left;
  position: relative;
}
.choice-btn:hover {
  background: linear-gradient(135deg, rgba(90,56,26,0.92), rgba(54,30,14,0.94));
  border-color: #a07038; color: #eedca8;
  transform: translateX(5px); box-shadow: 0 0 18px rgba(140,100,40,0.15);
}
.choice-btn .hint { display: block; font-size: 10px; color: #7a6a5a; margin-top: 3px; }
.choice-btn .choice-num {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 10px; color: #5a4a3a; border: 1px solid #3a2a18;
  border-radius: 3px; padding: 1px 6px;
}

/* ===== Title Screen ===== */
#title-screen {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  transition: opacity 0.8s ease;
}
#title-screen.hidden { opacity: 0; pointer-events: none; }
#title-screen .title-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  filter: brightness(0.65);
}
#title-screen h1 {
  position: relative; z-index: 2;
  font-size: 42px; font-weight: normal;
  color: #e8d0a0; letter-spacing: 10px;
  text-shadow: 0 2px 16px rgba(0,0,0,0.7);
  margin-bottom: 4px;
  animation: titleIn 1s cubic-bezier(0.16, 1, 0.3, 1);
}
#title-screen .subtitle {
  position: relative; z-index: 2;
  font-size: 13px; color: #b49870; letter-spacing: 5px;
  margin-bottom: 52px;
  animation: titleIn 1s 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}
#title-screen .start-btn {
  position: relative; z-index: 2;
  padding: 12px 56px;
  background: rgba(24,16,8,0.82); border: 1px solid #7a5a38;
  color: #d0b070; font-family: inherit; font-size: 18px;
  letter-spacing: 8px; cursor: pointer;
  transition: all 0.3s;
  animation: titleIn 1s 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
#title-screen .start-btn:hover {
  background: rgba(50,30,14,0.88); border-color: #c09040; color: #eed890;
  box-shadow: 0 0 32px rgba(140,80,32,0.25);
}
#title-screen .footnote {
  position: absolute; bottom: 20px; z-index: 2;
  font-size: 10px; color: #7a6a5a; letter-spacing: 2px;
}
@keyframes titleIn { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Ending Screen ===== */
#ending-screen {
  position: absolute; inset: 0; z-index: 30;
  background: rgba(8,6,4,0.93);
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  opacity: 0; pointer-events: none; transition: opacity 1s ease;
  padding: 30px;
}
#ending-screen.show { opacity: 1; pointer-events: auto; }
#ending-screen h2 {
  color: #e8d0a0; font-size: 26px; font-weight: normal;
  letter-spacing: 6px; margin-bottom: 12px;
  animation: titleIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
#ending-screen .ending-desc {
  color: #b49870; font-size: 14px; text-align: center;
  line-height: 2; max-width: 480px; margin-bottom: 8px;
}

/* Decision path */
#ending-path {
  display: flex; align-items: center; gap: 8px;
  margin: 16px 0; flex-wrap: wrap; justify-content: center;
}
.path-node {
  padding: 6px 14px; border-radius: 3px;
  font-size: 11px; color: #d0b880;
  background: rgba(40,28,16,0.6); border: 1px solid #5a3a20;
  letter-spacing: 1px; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.path-arrow { color: #5a4a3a; font-size: 14px; }
.path-final {
  padding: 6px 16px; border-radius: 3px;
  font-size: 12px; color: #e8d090; font-weight: bold;
  background: rgba(60,40,20,0.7); border: 1px solid #8a5a28;
  letter-spacing: 2px;
}

#ending-screen .ending-stats {
  color: #7a6a5a; font-size: 12px; margin: 10px 0 24px;
  text-align: center; line-height: 2;
}
#ending-screen .restart-btn {
  padding: 9px 38px; background: rgba(24,16,8,0.82);
  border: 1px solid #7a5a38; color: #d0b070;
  font-family: inherit; font-size: 14px; letter-spacing: 5px;
  cursor: pointer; transition: all 0.3s;
}
#ending-screen .restart-btn:hover {
  background: rgba(50,30,14,0.88); border-color: #c09040;
}

/* ===== Data Image ===== */
#data-img {
  position: absolute; top: 50%; left: 50%; z-index: 8;
  transform: translate(-50%, -50%) scale(0.9);
  max-width: 60%; max-height: 55%;
  border: 2px solid #5a3a20; border-radius: 4px; overflow: hidden;
  opacity: 0; pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
  background: #1a1410;
}
#data-img.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#data-img img { display: block; width: 100%; }
#data-img .cap {
  font-size: 10px; color: #9a7a50; padding: 5px 10px;
  text-align: center; background: rgba(0,0,0,0.7); letter-spacing: 1px;
}

/* ===== Data Badge ===== */
#data-badge {
  position: absolute; top: 14px; left: 50%; z-index: 12;
  transform: translateX(-50%);
  opacity: 0; pointer-events: none;
  transition: opacity 0.5s ease;
  font-size: 10px; color: #8a7a50;
  background: rgba(30,20,10,0.85); border: 1px solid #5a4020; border-radius: 3px;
  padding: 5px 14px; letter-spacing: 2px; text-align: center; max-width: 80%;
}
#data-badge.show { opacity: 1; }

/* ===== Archive Button ===== */
#archive-btn {
  position: absolute; top: 8px; left: 130px; z-index: 21;
  width: 28px; height: 28px; border-radius: 4px;
  border: 1px solid rgba(100,70,30,0.3);
  background: rgba(16,12,8,0.7); color: #8a6a40;
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.5s, border-color 0.2s;
}
#archive-btn.visible { opacity: 1; pointer-events: auto; }
#archive-btn:hover { border-color: rgba(180,120,50,0.6); color: #c09050; }

/* ===== Archive Overlay ===== */
#archive-overlay {
  position: absolute; inset: 0; z-index: 35;
  background: rgba(6,4,3,0.94);
  display: flex; flex-direction: column;
  padding: 30px; overflow-y: auto;
  opacity: 0; pointer-events: none; transition: opacity 0.4s ease;
}
#archive-overlay.show { opacity: 1; pointer-events: auto; }
#archive-overlay h3 { color: #e0c888; font-size: 16px; letter-spacing: 4px; margin-bottom: 16px; }
#archive-overlay .src-row { margin: 6px 0; font-size: 11px; color: #8a7a50; line-height: 1.8; }
#archive-overlay .src-label { color: #5a8a40; }
#archive-overlay .close-btn {
  margin-top: 20px; padding: 8px 28px;
  background: rgba(24,16,8,0.82); border: 1px solid #7a5a38; color: #d0b070;
  font-family: inherit; font-size: 13px; letter-spacing: 4px;
  cursor: pointer; align-self: center;
}

/* ===== Loading ===== */
#loading {
  position: absolute; inset: 0; z-index: 50;
  background: #0d0b08; display: flex;
  justify-content: center; align-items: center;
  color: #7a6a5a; font-size: 14px; letter-spacing: 4px;
  transition: opacity 0.5s;
}
#loading.hidden { opacity: 0; pointer-events: none; }

/* ===== Mobile ===== */
@media (max-width: 600px) {
  #game { aspect-ratio: auto; max-height: 100vh; }
  .char-portrait { height: 65%; }
  #text-box-wrap { min-height: 30%; padding: 14px 18px 16px; }
  #dialog-text { font-size: 13px; }
  #choice-panel { width: 86%; bottom: 28%; }
  #chapter-card .cc-title { font-size: 22px; letter-spacing: 6px; }
}
