:root {
  --bg-deep: #0b0c0d;
  --bg-panel: #141618;
  --bg-card: #1b1e21;
  --border-subtle: rgba(255, 255, 255, 0.11);
  --text-main: #ece9e1;
  --text-muted: #9a968b;
  --accent-moss: #5c6b53;
  --accent-khaki: #b39f7d;
  --accent-danger: #c63b3b;
}

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

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
}

.hidden {
  display: none !important;
}

.theater-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px 16px 12px;
  gap: 8px;
  background: radial-gradient(circle at 50% 35%, #191b1c 0%, #090a0b 75%);
}

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-danger);
  box-shadow: 0 0 8px var(--accent-danger);
  animation: pulseDot 1.6s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.85); }
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03));
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 4px 12px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}

.pill-btn:hover {
  background: linear-gradient(180deg, rgba(212, 189, 140, 0.18), rgba(255, 255, 255, 0.06));
  border-color: rgba(212, 189, 140, 0.45);
  transform: translateY(-1px);
}

.pill-btn:active {
  transform: scale(0.98);
}

.badge {
  background: rgba(198, 59, 59, 0.28);
  color: #f6bcbc;
  border: 1px solid rgba(218, 86, 86, 0.5);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}

/* Stage wrapper */
.stage-wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.cinema-stage {
  position: relative;
  width: 100%;
  max-width: min(1220px, calc((100vh - 118px) * 16 / 9));
  aspect-ratio: 16 / 9;
  background: #0e0f10;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  cursor: pointer;
}

#sceneCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Subtle film grain + vignette */
.grain-overlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
  opacity: 0.09;
  background-image: radial-gradient(rgba(255,255,255,0.45) 0.6px, transparent 0.6px);
  background-size: 3px 3px;
  mix-blend-mode: overlay;
}

.vignette-overlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.78) 100%);
  transition: box-shadow 0.4s ease;
}

.vignette-overlay.danger {
  box-shadow: inset 0 0 110px rgba(175, 22, 22, 0.55);
}

.letterbox-top, .letterbox-bottom {
  pointer-events: none;
  position: absolute;
  left: 0;
  right: 0;
  height: 5.5%;
  background: #060708;
  z-index: 3;
}

.letterbox-top { top: 0; }
.letterbox-bottom { bottom: 0; }

/* Stage HUD */
.stage-hud-top {
  pointer-events: none;
  position: absolute;
  top: 7.5%;
  left: 2.5%;
  right: 2.5%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 6;
}

.scene-tag {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(236, 233, 225, 0.72);
  background: rgba(8, 9, 10, 0.6);
  padding: 4px 9px;
  border-left: 2px solid var(--accent-danger);
}

.clue-toast {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.25s, transform 0.25s;
  background: rgba(20, 23, 21, 0.92);
  border: 1px solid var(--accent-khaki);
  color: #f3e9d2;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 4px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
}

.clue-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Subtitles (matching reference screenshot!) */
.subtitle-layer {
  pointer-events: none;
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 7.5%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  z-index: 7;
}

.speaker-tag {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: #ded6c1;
  background: rgba(12, 13, 14, 0.82);
  border: 1px solid rgba(222, 214, 193, 0.28);
  padding: 2px 10px;
  border-radius: 3px;
}

.subtitle-text {
  font-size: clamp(16px, 2.0vw, 23px);
  font-weight: 700;
  line-height: 1.42;
  color: #ffffff;
  letter-spacing: 0.03em;
  text-shadow:
    -2px -2px 0 #000,
     2px -2px 0 #000,
    -2px  2px 0 #000,
     2px  2px 0 #000,
     0px -2px 0 #000,
     0px  2px 0 #000,
    -2px  0px 0 #000,
     2px  0px 0 #000,
     0px  4px 10px rgba(0, 0, 0, 0.9);
  max-width: 94%;
}

.advance-cue {
  font-size: 11px;
  color: rgba(236, 233, 225, 0.65);
  letter-spacing: 0.08em;
  margin-top: 2px;
  animation: bobCue 1.4s infinite ease-in-out;
}

@keyframes bobCue {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(2px); opacity: 0.95; }
}

/* Title / Ending / Keypad Overlays */
.title-overlay,
.ending-overlay,
.keypad-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 9, 10, 0.72);
  backdrop-filter: blur(2px);
  cursor: default;
}

.title-card,
.ending-card {
  width: min(600px, 90%);
  background: rgba(17, 19, 20, 0.95);
  border: 2px solid rgba(205, 196, 174, 0.28);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.9);
  padding: 28px 32px;
  text-align: center;
}

.title-eyebrow {
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--accent-danger);
  font-weight: 700;
  margin-bottom: 10px;
}

.title-card h1 {
  font-size: clamp(26px, 3.4vw, 38px);
  letter-spacing: 0.2em;
  margin-bottom: 14px;
  color: #f2ede2;
}

.title-desc {
  font-size: 14px;
  line-height: 1.75;
  color: #c7c1b3;
  margin-bottom: 16px;
}

.title-meta {
  display: flex;
  justify-content: center;
  gap: 10px;
  font-size: 12px;
  color: var(--accent-khaki);
  margin-bottom: 22px;
}

.title-btns,
.ending-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.primary-btn {
  background: linear-gradient(180deg, #9d2e2e, #761f1f);
  color: #faf6ee;
  border: 1px solid #d96464;
  border-radius: 6px;
  padding: 11px 24px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(156, 36, 36, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 0.12s, filter 0.15s;
}

.primary-btn:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.primary-btn:active {
  transform: scale(0.98);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.38);
  transform: translateY(-1px);
}

.title-hint {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Timed Decision Overlay */
.choice-overlay {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 8% 8%;
  background: rgba(8, 9, 10, 0.45);
  cursor: default;
}

.timer-wrap {
  width: min(560px, 86%);
  margin-bottom: 14px;
}

.timer-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #f0a7a7;
  margin-bottom: 5px;
  text-shadow: 0 2px 6px #000;
}

.timer-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #b83232, #e46757);
  transition: width 0.08s linear;
}

.choice-prompt {
  font-size: clamp(15px, 1.8vw, 20px);
  font-weight: 700;
  color: #f5f0e6;
  text-shadow: 0 2px 10px #000, 0 0 2px #000;
  margin-bottom: 16px;
  text-align: center;
}

.choice-list {
  width: min(640px, 92%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.choice-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 18px 14px 22px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(22, 25, 27, 0.94), rgba(13, 15, 17, 0.94));
  border: 1.4px solid rgba(198, 182, 150, 0.38);
  color: #f5f1e8;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.72), inset 4px 0 0 #c6ad82;
  transition: transform 0.14s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.16s, background 0.16s, box-shadow 0.18s;
}

.choice-btn.choice-danger {
  background: linear-gradient(135deg, rgba(50, 18, 20, 0.94), rgba(26, 11, 13, 0.94));
  border-color: rgba(222, 95, 95, 0.56);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.72), inset 4px 0 0 #df5858;
}

.choice-btn:hover {
  background: linear-gradient(135deg, rgba(46, 44, 34, 0.96), rgba(24, 24, 20, 0.96));
  border-color: #ecd39c;
  box-shadow: 0 12px 30px rgba(212, 189, 140, 0.22), inset 5px 0 0 #f2dcad;
  transform: translateX(5px);
}

.choice-btn:active {
  transform: translateX(3px) scale(0.992);
}

.choice-btn.choice-danger:hover {
  border-color: #f27474;
  background: linear-gradient(135deg, rgba(78, 24, 26, 0.96), rgba(38, 12, 14, 0.96));
  box-shadow: 0 12px 30px rgba(218, 62, 62, 0.32), inset 5px 0 0 #f48686;
}

.choice-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.choice-medallion {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
  color: #ebd9b5;
  background: rgba(198, 173, 130, 0.14);
  border: 1px solid rgba(198, 173, 130, 0.55);
}

.choice-btn.choice-danger .choice-medallion {
  color: #f7b2b2;
  background: rgba(215, 68, 68, 0.22);
  border-color: rgba(235, 118, 118, 0.65);
}

.choice-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.choice-tag {
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(198, 173, 130, 0.35);
  color: #d6c29d;
  white-space: nowrap;
}

.choice-btn.choice-danger .choice-tag {
  background: rgba(205, 58, 58, 0.22);
  border-color: rgba(225, 102, 102, 0.45);
  color: #f2abab;
}

.choice-keycap {
  font-family: Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(14, 16, 18, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #c5bea9;
}

/* Keypad Modal */
.keypad-card {
  width: min(320px, 86%);
  background: #17191b;
  border: 2px solid #59554b;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.92);
}

.keypad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}

.keypad-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.keypad-display {
  background: #0a0c0a;
  border: 1px solid #3c463d;
  color: #8cc295;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 26px;
  letter-spacing: 0.28em;
  text-align: center;
  padding: 10px 0;
  margin-bottom: 12px;
}

.keypad-display.error {
  color: #e46b6b;
  border-color: #9e3333;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.keypad-grid button {
  padding: 12px 0;
  font-size: 16px;
  font-weight: 700;
  background: #25282a;
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.14);
  cursor: pointer;
}

.keypad-grid button:hover {
  background: #35393b;
}

.keypad-grid .key-enter {
  background: #485e47;
  border-color: #718f6f;
}

/* Ending Card */
.ending-type {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--accent-danger);
  margin-bottom: 8px;
}

.ending-type.good {
  color: #96be8b;
}

.ending-card h2 {
  font-size: 26px;
  margin-bottom: 12px;
}

.ending-card p {
  font-size: 14px;
  line-height: 1.75;
  color: #cbc5b7;
  margin-bottom: 16px;
}

.ending-stats {
  font-size: 12px;
  color: var(--accent-khaki);
  margin-bottom: 20px;
}

/* Player Bar */
.player-bar {
  width: 100%;
  max-width: min(1220px, calc((100vh - 118px) * 16 / 9));
  background: rgba(18, 20, 22, 0.94);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 6px 12px 8px;
  flex-shrink: 0;
}

.progress-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 7px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #5d6f56, #c63b3b);
  transition: width 0.25s ease;
}

.player-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ctrl-left, .ctrl-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, transform 0.1s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(212, 189, 140, 0.38);
}

.icon-btn:active {
  transform: scale(0.97);
}

.beat-counter {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: var(--text-muted);
}

.toggle-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, color 0.14s;
}

.toggle-chip.active {
  color: #e6f0df;
  background: rgba(92, 107, 83, 0.35);
  border-color: rgba(140, 166, 125, 0.55);
}

#volumeSlider {
  width: 72px;
  accent-color: #8c9e82;
  cursor: pointer;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 7, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-panel {
  width: min(640px, 92vw);
  max-height: 82vh;
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.9);
}

.modal-wide {
  width: min(1040px, 96vw);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-size: 15px;
}

.modal-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.close-x {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}

.close-x:hover {
  color: var(--text-main);
}

.clues-grid {
  padding: 16px 18px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.clue-card {
  background: var(--bg-card);
  border: 1px solid rgba(205, 196, 174, 0.22);
  border-radius: 6px;
  padding: 12px 14px;
}

.clue-card h4 {
  font-size: 14px;
  color: var(--accent-khaki);
  margin-bottom: 6px;
}

.clue-card p {
  font-size: 12.5px;
  line-height: 1.55;
  color: #ccc6b9;
}

.clues-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Story Tree */
.tree-scroll {
  overflow: auto;
  padding: 20px;
}

.tree-canvas {
  position: relative;
  width: 970px;
  height: 520px;
  margin: 0 auto;
  background: #101214;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
}

.tree-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.tree-node {
  position: absolute;
  width: 136px;
  padding: 8px 10px;
  border-radius: 5px;
  background: #1d2022;
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 12px;
  transform: translate(-50%, -50%);
  transition: transform 0.12s, border-color 0.15s;
}

.tree-node.visited {
  cursor: pointer;
  border-color: rgba(179, 159, 125, 0.55);
}

.tree-node.visited:hover {
  transform: translate(-50%, -53%);
  border-color: #f0d7a7;
  background: #272b2d;
}

.tree-node.current {
  border-color: #d65151;
  box-shadow: 0 0 14px rgba(214, 81, 81, 0.45);
}

.tree-node.locked {
  opacity: 0.45;
  border-style: dashed;
}

.tree-node.ending {
  border-color: rgba(150, 190, 139, 0.45);
}

.tree-node-tag {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.tree-node-title {
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
}
