:root {
  --bg-dark: #000000;
  --text-main: #ffffff;
  --text-muted: rgba(255, 255, 255, 0.6);
  --glass-bg: rgba(20, 20, 25, 0.45);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-shadow: 0 34px 80px rgba(0, 0, 0, 0.6);
  --accent: #ffffff;
  --accent-hover: rgba(255, 255, 255, 0.15);
  --radius-xl: 28px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --text-scale: 1;
}

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

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

/* ==========================================================================
   GAME LOBBY (MAIN MENU)
   ========================================================================== */
.game-lobby {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8vw 12vw;
  z-index: 100;
}

.lobby-background {
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: 
    linear-gradient(90deg, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.2) 50%, transparent 100%),
    url('../game.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  animation: bg-breathe 20s ease-in-out infinite alternate;
}

.lobby-background::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255,255,255,0.1) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.3;
}

@keyframes bg-breathe {
  0% { transform: scale(1); filter: brightness(0.9) saturate(1.1); }
  100% { transform: scale(1.08); filter: brightness(1.1) saturate(1.3); }
}

.ambient-glow {
  position: absolute;
  inset: 0;
  background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><filter id="noiseFilter"><feTurbulence type="fractalNoise" baseFrequency="0.7" numOctaves="4" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noiseFilter)"/></svg>');
  opacity: 0.08;
  mix-blend-mode: overlay;
  pointer-events: none;
}

.lobby-content {
  display: flex;
  flex-direction: column;
  gap: 80px;
  max-width: 800px;
  animation: slide-up-lobby 1.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes slide-up-lobby {
  from { opacity: 0; transform: translateY(60px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.title-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.title-section::before {
  content: '';
  position: absolute;
  left: -32px;
  top: 10px;
  bottom: 10px;
  width: 4px;
  background: linear-gradient(180deg, var(--text-main), transparent);
  border-radius: 4px;
  opacity: 0.8;
}

.game-title {
  font-size: clamp(64px, 7vw, 96px);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: #ffffff;
  text-shadow: 
    0 4px 32px rgba(0,0,0,0.8),
    0 0 80px rgba(255,255,255,0.1);
  font-family: "STSong", "SimSun", serif; /* 增加中文字体的电影感 */
}

.game-subtitle {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.6em;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  margin-left: 4px;
}

.main-menu {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: flex-start;
}

.menu-btn {
  appearance: none;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
  cursor: pointer;
  position: relative;
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: visible;
}

.menu-btn::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 2px;
  background: var(--text-main);
  transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 0 10px rgba(255,255,255,0.5);
}

.menu-btn:hover::before {
  width: 40px;
}

.menu-btn .btn-text {
  font-size: 32px;
  font-weight: 700;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0.1em;
  transition: all 0.4s ease;
  text-shadow: 0 4px 16px rgba(0,0,0,0.8);
}

.menu-btn .btn-en {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3em;
  color: var(--text-muted);
  opacity: 0;
  transform: translateX(-15px);
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.menu-btn:hover .btn-text {
  color: #ffffff;
  transform: translateX(36px);
  text-shadow: 0 0 24px rgba(255,255,255,0.4);
}

.menu-btn:hover .btn-en {
  opacity: 0.7;
  transform: translateX(40px);
}

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


/* ==========================================================================
   GAME PLAYER (VIDEO STAGE)
   ========================================================================== */
.game-player {
  position: absolute;
  inset: 0;
  background: var(--bg-dark);
  z-index: 200;
}

#story-video-bg {
  position: absolute;
  inset: -5%; /* extend slightly to hide blur edges */
  width: 110%;
  height: 110%;
  object-fit: cover;
  filter: blur(26px) brightness(0.3);
  z-index: 1;
  pointer-events: none;
}

.video-container {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#story-video {
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  background: transparent;
}

.freeze-canvas {
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  position: absolute;
  inset: 0;
  z-index: 3;
}

.freeze-bg-canvas {
  position: absolute;
  inset: -5%;
  width: 110%;
  height: 110%;
  object-fit: cover;
  filter: blur(26px) brightness(0.3);
  z-index: 1;
  pointer-events: none;
}

@keyframes ken-burns-breathe {
  0% { transform: scale3d(1, 1, 1); }
  100% { transform: scale3d(1.15, 1.15, 1); }
}

.ken-burns-active {
  animation: ken-burns-breathe 20s linear forwards;
  will-change: transform;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  perspective: 1000px;
}

/* ==========================================================================
   PLAYER HUD
   ========================================================================== */
.player-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 32px 40px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 10;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.6) 0%, transparent 100%);
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 20px;
  pointer-events: auto;
}

.icon-btn {
  appearance: none;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--glass-border);
  color: var(--text-main);
  width: 48px;
  height: 48px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

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

.status-indicators {
  display: flex;
  gap: 10px;
}

.status-badge {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--glass-border);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  backdrop-filter: blur(12px);
  color: var(--text-muted);
}

/* ==========================================================================
   OVERLAYS (CHOICES & ENDING)
   ========================================================================== */
.overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2); /* 降低全屏遮罩的暗度 */
  animation: fade-in 0.5s ease both;
}

.text-overlay {
  align-items: flex-end;
  padding-bottom: 220px; /* 向上提，留出底部选项面板的空间 */
  pointer-events: none; /* 让上层不影响画面点击 */
  background: linear-gradient(0deg, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 60%);
  z-index: 15; 
}

.text-panel {
  width: 100%;
  max-width: 900px;
  padding: 32px 40px;
  background: transparent; /* 去掉文本框自身的毛玻璃底色，与底部的渐变黑融合 */
  pointer-events: auto; /* 恢复点击 */
  cursor: pointer;
  position: relative;
  animation: slide-up-choice 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.text-panel.waiting-click::after {
  content: "点击继续 ▼";
  position: absolute;
  bottom: -30px;
  right: 20px;
  font-size: 14px;
  color: var(--text-muted);
  animation: bounce-hint 1.5s infinite;
  opacity: 0.8;
}

@keyframes bounce-hint {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(5px); }
}

.typewriter-text {
  font-size: calc(22px * var(--text-scale));
  line-height: 1.8;
  color: #f7fafc;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
  min-height: 80px; /* 保持一个最小高度避免抖动 */
  transition: font-size 0.3s ease;
}

.typewriter-text::after {
  content: '|';
  animation: blink 1s step-end infinite;
  margin-left: 4px;
  opacity: 0.8;
}

.typewriter-text.typing-done::after {
  display: none;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.bottom-overlay {
  align-items: flex-end;
  padding-bottom: 60px;
  background: transparent; /* 移除原本的渐变黑，因为 text-overlay 已经提供了足够的深色铺底 */
  pointer-events: none; /* 让上层不影响画面点击（如果需要的话），由子元素恢复 */
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.choices-panel {
  width: 100%;
  max-width: 1000px;
  padding: 0 40px;
  pointer-events: auto; /* 恢复子元素的点击 */
  animation: slide-up-choice 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes slide-up-choice {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: translateY(0); }
}

.bento-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--glass-shadow);
  padding: 48px;
  width: 100%;
  max-width: 640px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: pop-in 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.95) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.ending-info {
  text-align: center;
  margin-bottom: 24px;
}

.panel-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

.panel-desc {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

/* Choices */
.choice-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
}

.choice-card {
  appearance: none;
  background: rgba(20, 20, 25, 0.65);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-lg);
  padding: 24px 32px;
  color: var(--text-main);
  text-align: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 240px;
  max-width: 320px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.choice-card:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-4px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.choice-card:active {
  transform: translateY(0) scale(0.98);
}

.choice-card strong {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin: 0;
}

.choice-path {
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Actions */
.action-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
}

.action-btn {
  appearance: none;
  border: none;
  padding: 16px 32px;
  border-radius: var(--radius-pill);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-btn.primary {
  background: var(--text-main);
  color: var(--bg-dark);
}

.action-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(255, 255, 255, 0.2);
}

.action-btn:not(.primary) {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border: 1px solid var(--glass-border);
}

.action-btn:not(.primary):hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

.action-btn:active {
  transform: scale(0.96) !important;
}

/* ==========================================================================
   SETTINGS PANEL (GAME STYLE)
   ========================================================================== */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  animation: fade-in 0.3s ease both;
}

.settings-panel {
  width: 90%;
  max-width: 960px;
  height: 80vh;
  max-height: 720px;
  background: rgba(15, 15, 18, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255,255,255,0.1);
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 40px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(0, 0, 0, 0.2);
  gap: 20px;
}

.settings-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.2em;
  margin-left: 12px;
  font-weight: 500;
}

.settings-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.settings-sidebar {
  width: 200px;
  background: rgba(0, 0, 0, 0.2);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.settings-tab {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 16px 32px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  transition: all 0.3s ease;
}

.settings-tab::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--text-main);
  transform: scaleY(0);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-tab:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.settings-tab.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.settings-tab.active::before {
  transform: scaleY(1);
}

.tab-cn {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.tab-en {
  font-size: 10px;
  letter-spacing: 0.2em;
  opacity: 0.5;
}

.settings-content {
  flex: 1;
  padding: 32px 40px;
  overflow-y: auto;
}

.settings-tab-pane {
  display: none;
  flex-direction: column;
  gap: 40px;
  animation: fade-in 0.3s ease;
}

.settings-tab-pane.active {
  display: flex;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.group-title {
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 8px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.setting-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 20px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: background 0.3s ease;
  position: relative; /* 关键修复：让内部的绝对定位值相对卡片本身，而不是飘到面板外 */
}

.setting-card:hover {
  background: rgba(255, 255, 255, 0.06);
}

.setting-card-wide {
  grid-column: 1 / -1;
}

.setting-label {
  font-size: 16px;
  font-weight: 500;
}

.setting-value {
  position: absolute;
  right: 20px;
  top: 20px;
  font-size: 14px;
  font-family: monospace;
  color: var(--text-muted);
}

.setting-hint {
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.6;
}

.setting-slider {
  appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  outline: none;
  margin-top: 8px;
}

.setting-slider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-main);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  transition: transform 0.2s;
}

.setting-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.setting-toggle-card {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.toggle-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setting-toggle {
  appearance: none;
  width: 48px;
  height: 24px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  outline: none;
  transition: background 0.3s;
}

.setting-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.setting-toggle:checked {
  background: #4caf50;
}

.setting-toggle:checked::after {
  transform: translateX(24px);
}

.settings-actions {
  padding: 20px 40px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: 0;
  justify-content: flex-end;
}

@media (max-width: 768px) {
  .settings-layout {
    flex-direction: column;
  }
  .settings-sidebar {
    width: 100%;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0;
    overflow-x: auto;
  }
  .settings-tab {
    flex: 1;
    text-align: center;
    padding: 12px;
  }
  .settings-tab::before {
    width: 100%;
    height: 3px;
    bottom: 0;
    top: auto;
    transform: scaleX(0);
  }
  .settings-tab.active::before {
    transform: scaleX(1);
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-container {
  position: fixed;
  top: 40px;
  right: 40px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

/* 场景过渡黑屏 */
.transition-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.transition-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.toast {
  background: rgba(20, 20, 25, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* ==========================================================================
   MOBILE RESPONSIVENESS
   ========================================================================== */
@media (max-width: 768px) {
  .game-lobby {
    padding: 32px;
    align-items: flex-end;
    padding-bottom: 64px;
  }
  
  .game-title {
    font-size: 40px;
  }
  
  .bento-card {
    padding: 32px 24px;
  }
  
  .panel-title {
    font-size: 24px;
  }
  
  .player-hud {
    padding: 20px;
  }
  
  .status-indicators {
    display: none; /* Hide on mobile to save space */
  }

  .settings-panel {
    padding: 24px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .setting-card-wide {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .settings-overlay {
    padding: 16px;
  }

  .settings-header {
    flex-direction: column;
  }

  .settings-close-btn {
    align-self: flex-end;
  }

  .setting-card {
    padding: 18px;
  }

  .setting-label,
  .setting-value {
    font-size: 16px;
  }
}
