:root {
  --bg: #0a0710;
  --panel: rgba(16, 10, 22, 0.88);
  --panel-solid: #140e1c;
  --ink: #f0e6f4;
  --muted: #a090b0;
  --accent: #e07090;
  --accent-deep: #a04060;
  --accent-2: #9a7ec8;
  --gold: #d4b27a;
  --border: rgba(224, 112, 144, 0.38);
  --border-soft: rgba(255, 230, 245, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --text-size: 16px;
  /* 制作人挑定后：放到 assets/ui/title_bg.webp，或改此变量 */
  --title-bg-url: url("../assets/ui/title_bg.webp");
  font-family: "Noto Serif SC", "Songti SC", "PingFang SC", "Microsoft YaHei", serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  overflow: hidden; -webkit-tap-highlight-color: transparent;
}
#app { height: 100%; display: flex; flex-direction: column; position: relative; }

.screen { display: none; flex: 1; flex-direction: column; min-height: 0; }
.screen.active { display: flex; }

/* ========== Title ========== */
#screen-title {
  position: relative;
  align-items: stretch;
  justify-content: flex-end;
  overflow: hidden;
  padding: 0;
}
#screen-title .title-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-color: #0a0710;
  background-image:
    var(--title-bg-url, none),
    radial-gradient(ellipse at 50% 22%, rgba(160, 64, 96, 0.35), transparent 55%),
    linear-gradient(180deg, #1a0e22 0%, #0a0710 72%);
  background-size: cover, auto, auto;
  background-position: center top, center, center;
  background-repeat: no-repeat;
  transform: scale(1.02);
}
#screen-title .title-vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(6, 3, 10, 0.25) 0%, transparent 28%, rgba(6, 3, 10, 0.55) 58%, rgba(4, 2, 8, 0.92) 100%),
    radial-gradient(ellipse at 50% 40%, transparent 35%, rgba(0, 0, 0, 0.55) 100%);
}
#screen-title .title-grain {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.07;
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(255, 255, 255, 0.04) 2px,
    rgba(255, 255, 255, 0.04) 3px
  );
  mix-blend-mode: soft-light;
}
#screen-title .title-content {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 24px calc(36px + var(--safe-bottom));
  width: 100%;
}
.badge-18 {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: 14px;
  z-index: 4;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: rgba(10, 6, 14, 0.55);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.14em;
  font-weight: 600;
  backdrop-filter: blur(6px);
}
#screen-title .brand-mark {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.42em;
  color: var(--gold);
  text-indent: 0.42em;
  opacity: 0.9;
  text-transform: none;
}
#screen-title h1 {
  font-size: clamp(30px, 7.2vw, 44px);
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
  line-height: 1.25;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.65), 0 0 40px rgba(224, 112, 144, 0.18);
}
#screen-title .title-ornament {
  width: 72px;
  height: 1px;
  margin: 16px 0 14px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  position: relative;
}
#screen-title .title-ornament::before,
#screen-title .title-ornament::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  transform: translateY(-50%);
  opacity: 0.8;
}
#screen-title .title-ornament::before { left: -2px; }
#screen-title .title-ornament::after { right: -2px; }
#screen-title .tagline {
  color: rgba(224, 200, 220, 0.78);
  font-size: 13px;
  letter-spacing: 0.2em;
  margin-bottom: 28px;
}
.btn-row {
  display: flex;
  flex-direction: column;
  gap: 11px;
  width: min(300px, 82vw);
}
button, .btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(22, 12, 28, 0.82);
  color: var(--ink);
  padding: 13px 18px;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  letter-spacing: 0.08em;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .12s;
}
button:hover, .btn:hover {
  border-color: var(--accent);
  background: rgba(48, 24, 40, 0.95);
}
button:active { transform: scale(0.98); }
button.primary {
  background: linear-gradient(135deg, #7a3048 0%, #5a2868 55%, #3a2048 100%);
  border-color: rgba(224, 112, 144, 0.65);
  font-weight: 600;
  letter-spacing: 0.16em;
}
button.primary.btn-glow {
  box-shadow: 0 0 0 1px rgba(224, 112, 144, 0.15), 0 8px 28px rgba(160, 48, 80, 0.35);
}
button.btn-ghost {
  background: rgba(12, 8, 18, 0.55);
  border-color: rgba(255, 220, 235, 0.18);
  backdrop-filter: blur(8px);
}
button.btn-text {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  letter-spacing: 0.22em;
  padding: 8px;
  font-size: 13px;
}
button.btn-text:hover {
  color: var(--ink);
  background: transparent;
  border-color: transparent;
}
button:disabled { opacity: 0.38; cursor: not-allowed; transform: none; }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  background: rgba(20, 12, 28, 0.7);
}

/* ========== Volumes ========== */
#screen-volumes {
  padding: calc(14px + var(--safe-top)) 14px calc(18px + var(--safe-bottom));
  overflow: auto;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(139, 80, 120, 0.16), transparent 50%),
    linear-gradient(180deg, #120a18, #0a0710 80%);
}
.vol-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}
#screen-volumes h2 {
  margin: 2px 0 4px;
  font-size: 20px;
  letter-spacing: 0.12em;
}
#screen-volumes .hint {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
  letter-spacing: 0.04em;
}
.vol-list { display: flex; flex-direction: column; gap: 11px; }
.vol-card {
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 14px 14px 14px 12px;
  background:
    linear-gradient(135deg, rgba(36, 20, 40, 0.92), rgba(16, 10, 22, 0.92));
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
  position: relative;
  overflow: hidden;
}
.vol-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  opacity: 0.75;
}
.vol-card .vol-index {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 13px;
  letter-spacing: 0;
  color: var(--gold);
  background: rgba(212, 178, 122, 0.1);
  border: 1px solid rgba(212, 178, 122, 0.28);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.vol-card .meta { text-align: left; flex: 1; min-width: 0; }
.vol-card .meta strong {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vol-card .meta .status-row { display: flex; align-items: center; gap: 8px; }
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.06em;
  border: 1px solid transparent;
}
.pill-free {
  color: #8fe0b0;
  background: rgba(80, 160, 110, 0.12);
  border-color: rgba(125, 206, 160, 0.3);
}
.pill-lock {
  color: var(--accent);
  background: rgba(196, 92, 122, 0.12);
  border-color: rgba(196, 92, 122, 0.35);
}
.vol-card > button {
  flex-shrink: 0;
  padding: 9px 14px;
  font-size: 13px;
  border-radius: 10px;
}

/* ========== Settings ========== */
#screen-settings {
  padding: calc(14px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
  overflow: auto;
  background: linear-gradient(180deg, #120a18, #0a0710);
}
.settings-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.settings-header h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.12em;
}
.settings-card {
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  background: rgba(20, 12, 28, 0.88);
  overflow: hidden;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.settings-row:last-child { border-bottom: none; }
.settings-label { text-align: left; min-width: 0; }
.settings-label strong {
  display: block;
  font-size: 15px;
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}
.settings-label span {
  color: var(--muted);
  font-size: 12px;
}
.settings-note {
  color: var(--muted);
  font-size: 12px;
  margin: 14px 4px 0;
  letter-spacing: 0.04em;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(8, 4, 12, 0.5);
}
.seg button {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 8px 12px;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.seg button.on {
  background: linear-gradient(135deg, rgba(122, 48, 72, 0.85), rgba(90, 40, 104, 0.85));
  color: var(--ink);
}
.switch {
  position: relative;
  width: 46px;
  height: 28px;
  display: inline-block;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: rgba(40, 28, 48, 0.95);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  transition: .15s;
  cursor: pointer;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #c8b8d0;
  border-radius: 50%;
  transition: .15s;
}
.switch input:checked + .slider {
  background: rgba(160, 64, 96, 0.55);
  border-color: var(--border);
}
.switch input:checked + .slider::before {
  transform: translateX(18px);
  background: #f0d8e4;
}
.switch input:disabled + .slider {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ========== Play ========== */
#screen-play {
  position: relative;
  background: #000 center/cover no-repeat;
}
#bg-layer {
  position: absolute; inset: 0;
  background: #0c0a12 center/cover no-repeat;
  transition: opacity .25s;
}
.sprite-layer {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; align-items: flex-end; justify-content: center;
}
.sprite-slot {
  position: absolute; bottom: 22%; width: 36%; max-width: 220px;
  display: flex; flex-direction: column; align-items: center;
  transition: opacity .2s, transform .2s;
  opacity: 0;
}
.sprite-slot.show { opacity: 1; }
.sprite-slot.left { left: 4%; }
.sprite-slot.center { left: 50%; transform: translateX(-50%); }
.sprite-slot.right { right: 4%; left: auto; }
.sprite-slot img { width: 100%; height: auto; filter: drop-shadow(0 8px 16px rgba(0,0,0,.5)); }
.sprite-slot .name-tag {
  margin-top: -8px; font-size: 12px; color: var(--muted);
  background: rgba(0,0,0,.45); padding: 2px 8px; border-radius: 6px;
}

.top-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: linear-gradient(180deg, rgba(0,0,0,.62), transparent);
}
.top-bar .chapter-title {
  font-size: 12px;
  color: rgba(230, 210, 230, 0.75);
  letter-spacing: 0.08em;
  max-width: 48%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-bar .menu-btns { display: flex; gap: 6px; }
.top-bar button {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 9px;
  letter-spacing: 0.04em;
  background: rgba(12, 8, 16, 0.55);
  border-color: rgba(255, 220, 235, 0.16);
  backdrop-filter: blur(6px);
}

.dialogue {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  padding: 0 12px calc(14px + var(--safe-bottom));
}
.dialogue-box {
  position: relative;
  background: linear-gradient(180deg, rgba(22, 12, 30, 0.78), rgba(10, 6, 16, 0.9));
  border: 1px solid rgba(224, 112, 144, 0.28);
  border-radius: 16px;
  padding: 18px 16px 14px;
  min-height: 128px;
  backdrop-filter: blur(10px);
  cursor: pointer;
  user-select: none;
  box-shadow: 0 -4px 28px rgba(0, 0, 0, 0.35);
}
.speaker-bar {
  position: absolute;
  top: -12px;
  left: 14px;
  min-height: 0;
}
.speaker {
  display: inline-block;
  color: #fff;
  font-size: 13px;
  letter-spacing: 0.1em;
  padding: 4px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #7a3048, #4a2860);
  border: 1px solid rgba(224, 160, 180, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.speaker:empty { display: none; }
.text-body {
  font-size: var(--text-size);
  line-height: 1.7;
  min-height: 3.4em;
  white-space: pre-wrap;
  padding-top: 4px;
}
.click-hint {
  text-align: right;
  color: var(--muted);
  font-size: 11px;
  margin-top: 8px;
  opacity: .72;
  letter-spacing: 0.08em;
}
body.hide-click-hint .click-hint { visibility: hidden; }

.choices {
  display: none; flex-direction: column; gap: 9px; margin-bottom: 12px;
}
.choices.show { display: flex; }
.choices button {
  text-align: left;
  background: rgba(18, 10, 26, 0.92);
  border-color: rgba(224, 112, 144, 0.32);
  border-radius: 12px;
  padding: 12px 14px;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}
.choices button:hover {
  border-color: var(--accent);
  background: rgba(48, 24, 44, 0.95);
}

/* Unlock modal */
.modal-backdrop {
  display: none; position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,.68); align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
  width: min(420px, 100%); background: #16101f; border: 1px solid var(--border);
  border-radius: 16px; padding: 18px; max-height: 80vh; overflow: auto;
}
.modal h3 { margin: 0 0 8px; letter-spacing: 0.06em; }
.modal pre {
  background: #0c0a12; padding: 10px; border-radius: 8px; font-size: 11px;
  overflow: auto; color: #c8b8d8; white-space: pre-wrap;
}
.modal .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 28%; transform: translateX(-50%);
  background: rgba(40, 24, 48, .95); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; z-index: 30;
  opacity: 0; pointer-events: none; transition: opacity .2s;
  letter-spacing: 0.04em;
}
#toast.show { opacity: 1; }

@media (max-width: 520px) {
  .sprite-slot { width: 42%; bottom: 26%; }
  :root { --text-size: 15px; }
  body.font-sm { --text-size: 14px; }
  body.font-md { --text-size: 15px; }
  body.font-lg { --text-size: 17px; }
}
body.font-sm { --text-size: 14px; }
body.font-md { --text-size: 16px; }
body.font-lg { --text-size: 18px; }
