:root {
  --gold: #c6a15a;
  --gold-dim: #8a6d3a;
  --ink: #f3e6cc;
  --ink-dim: #cbb896;
  --panel: rgba(12, 9, 7, 0.9);
  --panel-border: rgba(198, 161, 90, 0.55);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #070605;
  color: var(--ink);
  font-family: "Noto Serif CJK SC", "Noto Serif CJK", "Source Han Serif SC",
    "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  overflow: hidden;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  background: #100c09;
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
}

.bg-layer {
  position: absolute;
  inset: 0;
  background-color: #100c09;
  background-size: cover;
  background-position: center;
  transition: opacity 0.55s ease;
}

.bg-layer.off { opacity: 0; }
.bg-layer.on { opacity: 1; }

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 120px 24px rgba(0, 0, 0, 0.45);
  z-index: 2;
}

#sprites {
  position: absolute;
  inset: 0 0 22% 0;
  z-index: 3;
  pointer-events: none;
}

.sprite {
  position: absolute;
  bottom: -4%;
  height: 102%;
  width: auto;
  object-fit: contain;
  filter: brightness(0.72);
  opacity: 0;
  transform: translateX(-50%) translateY(12px);
  transition: opacity 0.4s ease, filter 0.35s ease, transform 0.45s ease, left 0.45s ease;
}

.sprite.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sprite.speaking {
  filter: brightness(1);
  z-index: 2;
}

.sprite.pos-left { left: 22%; }
.sprite.pos-center { left: 50%; }
.sprite.pos-right { left: 78%; }

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,0.4), transparent 80%);
}

#chapter-label {
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--gold);
  text-shadow: 0 1px 4px #000;
}

#btn-menu {
  pointer-events: auto;
  cursor: pointer;
  border: 1px solid var(--panel-border);
  background: rgba(16, 12, 9, 0.72);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.16em;
  padding: 6px 14px;
}

#btn-menu:hover { border-color: var(--gold); color: #fff; }

#textbox {
  position: absolute;
  left: 3.5%;
  right: 3.5%;
  bottom: 3%;
  z-index: 7;
  min-height: 26%;
  background: linear-gradient(180deg, rgba(18, 13, 10, 0.86), rgba(8, 6, 5, 0.94));
  border: 1px solid var(--panel-border);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 10px 30px rgba(0,0,0,0.35);
  padding: 28px 28px 22px;
}

#textbox.hidden, .hidden { display: none !important; }

#nameplate {
  position: absolute;
  top: -14px;
  left: 18px;
  min-width: 108px;
  text-align: center;
  padding: 3px 16px 4px;
  background: #16110d;
  border: 1px solid var(--gold);
  color: var(--gold);
  letter-spacing: 0.22em;
  font-size: 15px;
}

#dialogue {
  font-size: clamp(16px, 2.15vh, 22px);
  line-height: 1.75;
  color: var(--ink);
  min-height: 4.2em;
  white-space: pre-wrap;
}

#clicker {
  position: absolute;
  right: 16px;
  bottom: 10px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 9px solid var(--gold);
  animation: pulse 1s ease-in-out infinite;
}

#clicker.hidden { display: none; }

@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(3px); }
}

#choices {
  position: absolute;
  left: 50%;
  bottom: 34%;
  transform: translateX(-50%);
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(72%, 620px);
  pointer-events: auto;
}

.choice-btn {
  cursor: pointer;
  font: inherit;
  font-size: clamp(15px, 2vh, 19px);
  line-height: 1.5;
  text-align: left;
  color: var(--ink);
  background: rgba(20, 15, 11, 0.92);
  border: 1px solid var(--panel-border);
  padding: 12px 18px;
  letter-spacing: 0.04em;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}

.choice-btn:hover,
.choice-btn:focus {
  outline: none;
  border-color: var(--gold);
  color: #fff8e8;
  background: rgba(42, 30, 16, 0.95);
}

#title-layer, #chapter-card, #end-card, #load-layer, #menu-modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(6, 4, 3, 0.42);
}

#title-layer {
  background: transparent;
  cursor: default;
}

#title-layer .veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(6,4,3,0.25) 0%, rgba(6,4,3,0.55) 55%, rgba(6,4,3,0.82) 100%);
}

#title-layer .title-box {
  position: relative;
  z-index: 1;
  text-align: center;
  margin-top: 18%;
}

#title-layer h1 {
  font-size: clamp(36px, 7vh, 72px);
  font-weight: 500;
  letter-spacing: 0.28em;
  color: #f4e4c0;
  text-shadow: 0 2px 18px rgba(0,0,0,0.8);
  margin-left: 0.28em;
}

#title-layer .subtitle {
  margin-top: 14px;
  letter-spacing: 0.42em;
  color: var(--gold);
  font-size: 15px;
}

#title-layer .btns {
  margin-top: 42px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.menu-btn, .title-btn {
  cursor: pointer;
  font: inherit;
  letter-spacing: 0.24em;
  color: var(--ink);
  background: rgba(16, 12, 9, 0.78);
  border: 1px solid var(--panel-border);
  padding: 10px 36px;
  min-width: 200px;
  font-size: 16px;
}

.menu-btn:hover, .title-btn:hover {
  border-color: var(--gold);
  color: #fff;
}

#chapter-card .ch-num {
  letter-spacing: 0.4em;
  color: var(--gold);
  font-size: 14px;
  margin-bottom: 16px;
}

#chapter-card h2, #end-card h2 {
  font-size: clamp(28px, 5vh, 48px);
  font-weight: 500;
  letter-spacing: 0.22em;
  color: #f4e4c0;
  margin-left: 0.22em;
}

#chapter-card p, #end-card p {
  margin-top: 18px;
  color: var(--ink-dim);
  letter-spacing: 0.12em;
}

#end-card {
  background: rgba(6, 4, 3, 0.72);
  text-align: center;
  gap: 8px;
}

#menu-modal .panel, #load-layer .panel {
  background: rgba(14, 10, 8, 0.94);
  border: 1px solid var(--panel-border);
  padding: 28px 36px 24px;
  min-width: 280px;
  text-align: center;
}

#menu-modal h3, #load-layer h3 {
  letter-spacing: 0.28em;
  color: var(--gold);
  font-weight: 500;
  margin-bottom: 18px;
}

#menu-modal .col, #load-layer .col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

#load-layer {
  cursor: default;
  background: #0b0806;
}

#load-layer .load-msg {
  letter-spacing: 0.2em;
  color: var(--gold);
  font-size: 16px;
}

#toast {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: rgba(16,12,9,0.92);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  padding: 8px 16px;
  font-size: 14px;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

#toast.show { opacity: 1; }

#autotest-log {
  display: none;
  position: absolute;
  top: 0; left: 0;
  z-index: 50;
  max-height: 40%;
  overflow: auto;
  background: rgba(0,0,0,0.7);
  color: #9f9;
  font: 11px/1.4 monospace;
  padding: 8px;
  white-space: pre;
}
