:root {
  --bg-deep: #11161d;
  --glass: rgba(15, 22, 31, 0.86);
  --glass-border: rgba(255, 255, 255, 0.14);
  --ink-light: #f1eee4;
  --ink-dim: #b8b3a4;
  --gold: #f5b942;
  --emerald: #4ade80;
  --crimson: #f87171;
  --cyan: #67e8f9;
  --modal-bg: #fbf7ee;
  --modal-ink: #27221b;
  --modal-line: #ded4be;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg-deep); color: var(--ink-light); font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; line-height: 1.55; }
.hidden { display: none !important; }

/* Header HUD */
#vn-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(14, 20, 26, 0.94); border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(8px); padding: 8px 16px;
}
.vn-hdr-top { max-width: 1180px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.vn-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.vn-brand h1 { font-size: 16.5px; font-weight: 700; color: #fff; white-space: nowrap; }
.vn-sub-title { font-weight: 500; color: var(--gold); font-size: 14px; }
.vn-pill { font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: rgba(245, 185, 66, 0.16); color: var(--gold); border: 1px solid rgba(245, 185, 66, 0.4); white-space: nowrap; }
.vn-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.vn-btn {
  font: inherit; font-size: 12.5px; font-weight: 600; padding: 5px 10px; border-radius: 8px;
  border: 1px solid var(--glass-border); background: rgba(255, 255, 255, 0.08); color: var(--ink-light);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 4px;
  transition: background .15s, border-color .15s, transform .1s; white-space: nowrap;
}
.vn-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.3); }
.vn-btn:disabled { opacity: .42; cursor: not-allowed; }
.vn-btn.accent { background: rgba(56, 132, 74, 0.35); border-color: rgba(74, 222, 128, 0.45); color: #dcfce7; }
.vn-btn.primary { background: #2f6b47; border-color: #4ade80; color: #fff; font-weight: 700; }
.vn-btn.primary:hover:not(:disabled) { background: #3b8257; }
.vn-btn.ghost { background: rgba(255, 255, 255, 0.05); }
.vn-btn.sm { padding: 5px 11px; font-size: 12.5px; }
.vn-btn.icon-only { padding: 5px 8px; }
.vn-btn.active-bgm { border-color: var(--gold); color: var(--gold); }

.vn-stats-bar {
  max-width: 1180px; margin: 7px auto 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
}
.vn-stat-chip {
  background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.09); border-radius: 8px;
  padding: 4px 8px; display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.vn-stat-head { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 600; gap: 4px; }
.vn-stat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vn-stat-val { color: var(--gold); font-variant-numeric: tabular-nums; }
.vn-stat-track { height: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.vn-stat-fill { height: 100%; border-radius: 999px; background: #4ade80; transition: width .3s ease, background .3s; }
.vn-stat-fill.low { background: #f87171; }
.vn-stat-fill.mid { background: #fbbf24; }

/* Stage */
#vn-main { max-width: 1180px; margin: 12px auto 18px; padding: 0 16px; }
.vn-stage {
  position: relative; min-height: calc(100vh - 122px); border-radius: 16px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14); background: #0f1722;
  display: flex; flex-direction: column; justify-content: space-between;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}
.vn-bg-layer { position: absolute; inset: 0; z-index: 0; }
.vn-bg-img, .vn-bg-svg { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .35s ease; }

.vn-mood-overlay { position: absolute; inset: 0; pointer-events: none; }
.mood-dawn_mist { background: linear-gradient(180deg, rgba(16, 28, 45, 0.25) 0%, rgba(16, 28, 45, 0.6) 100%); }
.mood-warm_hearth { background: linear-gradient(180deg, rgba(40, 20, 10, 0.15) 0%, rgba(20, 12, 8, 0.65) 100%); }
.mood-night_hearth { background: linear-gradient(180deg, rgba(10, 12, 24, 0.4) 0%, rgba(10, 10, 16, 0.78) 100%); }
.mood-hospital { background: linear-gradient(180deg, rgba(185, 220, 240, 0.22) 0%, rgba(15, 23, 42, 0.78) 100%); filter: saturate(0.55) contrast(1.05); }
.mood-rain { background: linear-gradient(180deg, rgba(18, 28, 40, 0.16) 0%, rgba(12, 18, 28, 0.52) 100%); }
.mood-frost_night { background: linear-gradient(180deg, rgba(10, 19, 36, 0.18) 0%, rgba(8, 13, 24, 0.58) 100%); }
.mood-dusk { background: linear-gradient(180deg, rgba(45, 22, 24, 0.12) 0%, rgba(16, 14, 22, 0.55) 100%); }
.mood-golden_dawn { background: linear-gradient(180deg, rgba(251, 191, 36, 0.08) 0%, rgba(22, 18, 12, 0.48) 100%); }
.mood-tense_day, .mood-mist, .mood-night { background: linear-gradient(180deg, rgba(15, 23, 34, 0.12) 0%, rgba(12, 16, 24, 0.52) 100%); }

/* Toasts */
.vn-toasts {
  position: absolute; top: 58px; right: 16px; z-index: 6; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none;
}
.vn-toast {
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700;
  background: rgba(17, 24, 39, 0.92); color: #fef3c7; border: 1px solid rgba(245, 185, 66, 0.55);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45); animation: toastSlide 2.8s ease forwards;
}
.vn-toast.good { border-color: #4ade80; color: #bbf7d0; }
.vn-toast.bad { border-color: #f87171; color: #fecaca; }
@keyframes toastSlide {
  0% { opacity: 0; transform: translateY(-6px); }
  12% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px); }
}

.vn-loc-banner {
  position: relative; z-index: 2; padding: 12px 16px 0; display: flex; flex-direction: column; gap: 2px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85); pointer-events: none;
}
.vn-loc-name { font-size: 13.5px; font-weight: 700; color: #fde68a; }
.vn-loc-atmo { font-size: 12px; color: #e2e8f0; max-width: 680px; }

/* Character Stage */
.vn-cast {
  position: relative; z-index: 2; display: flex; justify-content: center; align-items: flex-end;
  gap: 22px; padding: 8px 18px 0; margin-bottom: -10px; min-height: 225px; pointer-events: none;
}
.vn-actor-slot {
  display: flex; flex-direction: column; align-items: center; transition: transform .25s ease, opacity .25s ease, filter .25s ease;
  opacity: 0.72; transform: scale(0.92); filter: brightness(0.84);
}
.vn-actor-slot.speaking { opacity: 1; transform: scale(1.04); filter: brightness(1.04) drop-shadow(0 8px 18px rgba(0, 0, 0, 0.65)); }
.vn-portrait-svg { width: 172px; height: 188px; display: block; }
.vn-actor-tag {
  margin-top: -12px; margin-bottom: 12px; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 700;
  background: rgba(15, 22, 31, 0.9); color: #f8fafc; border: 1px solid rgba(255, 255, 255, 0.22);
}

/* Dialogue Dock */
.vn-dialogue-dock {
  position: relative; z-index: 3; margin: 0 14px 14px; padding: 16px 20px 14px;
  background: var(--glass); border: 1px solid var(--glass-border); border-radius: 14px;
  backdrop-filter: blur(12px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.vn-speaker-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; min-height: 24px; }
.vn-spk-badge {
  font-size: 13px; font-weight: 800; padding: 2px 10px; border-radius: 6px;
  background: #2f6b47; color: #fff;
}
.vn-spk-badge.narrator { background: rgba(255, 255, 255, 0.12); color: #e2e8f0; font-weight: 600; }
.vn-spk-badge.inner { background: rgba(56, 189, 248, 0.18); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.4); }
.vn-expr-badge { font-size: 11.5px; color: var(--gold); font-weight: 600; }
.vn-stage-note { font-size: 13px; font-style: italic; color: #cbd5e1; margin-bottom: 6px; }
.vn-beat-text { font-size: 16.5px; line-height: 1.62; color: var(--ink-light); min-height: 54px; }
.vn-beat-text.inner-style { font-style: italic; color: #bae6fd; border-left: 3px solid #38bdf8; padding-left: 12px; }
.vn-beat-text.narrator-style { color: #e7e2d4; }

.vn-choices { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.vn-choice-btn {
  text-align: left; font: inherit; font-size: 14.5px; font-weight: 600; line-height: 1.42;
  padding: 11px 14px; border-radius: 10px; border: 1px solid rgba(245, 185, 66, 0.42);
  background: rgba(30, 41, 59, 0.85); color: #fef9ee; cursor: pointer;
  display: flex; align-items: flex-start; gap: 10px; transition: background .15s, border-color .15s, transform .1s;
}
.vn-choice-btn:hover { background: rgba(47, 107, 71, 0.65); border-color: #4ade80; transform: translateX(3px); }
.vn-choice-num {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 6px; background: rgba(245, 185, 66, 0.22);
  color: var(--gold); font-size: 12px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center;
}

.vn-dock-foot {
  display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1); gap: 8px;
}
.vn-beat-prog { font-size: 12px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.vn-foot-actions { display: flex; gap: 8px; }

/* Ending Card */
.vn-ending-card {
  margin-top: 14px; padding: 14px 16px; border-radius: 12px;
  background: rgba(245, 185, 66, 0.12); border: 1.5px solid rgba(245, 185, 66, 0.55);
}
.vn-ending-kicker { font-size: 12px; font-weight: 800; color: var(--gold); text-transform: uppercase; letter-spacing: .04em; }
.vn-ending-card h2 { font-size: 20px; color: #fff; margin: 4px 0 6px; }
.vn-ending-theme { font-style: italic; font-size: 14px; color: #fef3c7; margin-bottom: 12px; }
.vn-ending-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* Modals (Light legible parchment inside modal) */
#vn-modal { display: none; }
#vn-modal.open {
  display: flex; position: fixed; inset: 0; z-index: 40;
  background: rgba(8, 12, 18, 0.72); align-items: center; justify-content: center; padding: 16px;
}
.vn-dialog {
  background: var(--modal-bg); color: var(--modal-ink); border-radius: 14px; padding: 20px;
  width: 100%; max-width: 720px; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}
.vn-dialog:focus { outline: none; }
.vn-modal-hdr { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; border-bottom: 1px solid var(--modal-line); padding-bottom: 8px; }
.vn-modal-hdr h2 { font-size: 18px; }
.vn-mbtn {
  font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--modal-line); background: #fff; color: var(--modal-ink); cursor: pointer;
}
.vn-mbtn:hover:not(:disabled) { border-color: #2f6b47; background: #eef6e7; }
.vn-mbtn.primary { background: #2f6b47; border-color: #2f6b47; color: #fff; }
.vn-mbtn.danger { color: #b91c1c; border-color: #fca5a5; }
.vn-mbtn:disabled { opacity: .45; cursor: not-allowed; }

.tree-group { margin-bottom: 14px; }
.tree-group h3 { font-size: 14px; color: #5b5142; margin-bottom: 8px; }
.tree-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.tree-card {
  padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--modal-line); background: #fffdf8;
}
.tree-card.unlocked { border-color: #3f7a38; background: #eef6e7; }
.tree-card.locked { opacity: .74; background: #f3ede0; }
.tree-card b { display: block; font-size: 13.5px; margin-bottom: 3px; }
.tree-card small { display: block; font-size: 12px; color: #645949; line-height: 1.4; }
.node-dots { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.node-dot { font-size: 11px; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--modal-line); background: #f4eee2; color: #786d5c; }
.node-dot.seen { background: #dcfce7; border-color: #86efac; color: #166534; font-weight: 700; }

.save-list, .hist-list, .bf-list { display: flex; flex-direction: column; gap: 8px; }
.save-row, .hist-item, .bf-item {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--modal-line); background: #fffdf8; font-size: 13.5px;
}
.save-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.save-acts { display: flex; gap: 6px; }
.hist-item.choice { background: #fef3c7; border-color: #fcd34d; }
.hist-who { font-size: 11.5px; font-weight: 800; color: #365726; display: block; }

@media (max-width: 760px) {
  #vn-header { position: relative; padding: 6px 10px; }
  .vn-brand h1 { font-size: 14.5px; }
  .vn-sub-title { display: none; }
  .vn-stats-bar { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .vn-stat-chip { padding: 3px 5px; }
  .vn-stat-lbl { display: none; }
  #vn-main { padding: 0 8px; margin-top: 8px; }
  .vn-stage { min-height: calc(100dvh - 140px); border-radius: 12px; }
  .vn-cast { min-height: 150px; gap: 8px; margin-bottom: -8px; }
  .vn-portrait-svg { width: 118px; height: 128px; }
  .vn-dialogue-dock { margin: 0 8px 8px; padding: 12px 13px; }
  .vn-beat-text { font-size: 15px; }
  .vn-choice-btn { font-size: 13.5px; padding: 9px 10px; }
  .vn-btn { font-size: 11.5px; padding: 4px 7px; }
}
