/* ===================================================
   字狱·明史 - 视觉小说引擎样式
   暗色主题 · 中式悬疑风格
   =================================================== */

/* ---------- 基础重置 ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* 色板 */
  --color-bg:          #0a0a0f;
  --color-dark:        #111118;
  --color-panel:       rgba(15, 12, 10, 0.92);
  --color-border:      #8b6914;
  --color-border-glow: #c49b2a;
  --color-gold:        #d4a843;
  --color-gold-dim:    #9a7a30;
  --color-red:         #8b1a1a;
  --color-blood:       #6b0f0f;
  --color-blood-bright:#c0392b;
  --color-text:        #e8e0d4;
  --color-text-dim:    #9a9080;
  --color-text-dark:   #4a4540;
  --color-white:       #f0ebe0;

  /* 尺寸 */
  --dialog-height: 220px;
  --char-height: 85vh;
  --font-main: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'SimSun', serif;
  --font-ui: 'Noto Serif SC', 'Source Han Serif SC', 'SimSun', serif;

  /* 动画时长 */
  --fade-fast: 0.3s;
  --fade-normal: 0.6s;
  --fade-slow: 1.2s;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--color-bg);
  font-family: var(--font-main);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ---------- 画面容器 ---------- */
.screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.screen.active {
  display: flex;
}

/* ===================================================
   标题画面
   =================================================== */
#title-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

.title-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(139, 26, 26, 0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 50% 70%, rgba(139, 105, 20, 0.08) 0%, transparent 50%);
  z-index: 1;
}

.title-content {
  position: relative;
  z-index: 2;
  text-align: center;
  animation: titleFadeIn 2s ease-out;
}

@keyframes titleFadeIn {
  0% { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}

.title-main {
  font-size: clamp(3rem, 8vw, 6rem);
  font-weight: 900;
  color: var(--color-blood-bright);
  text-shadow:
    0 0 20px rgba(192, 57, 43, 0.4),
    0 0 60px rgba(139, 26, 26, 0.2),
    0 2px 4px rgba(0,0,0,0.8);
  letter-spacing: 0.3em;
  margin-bottom: 1rem;
  /* 模拟毛笔字的不规则感 */
  font-style: normal;
}

.title-subtitle {
  font-size: clamp(1rem, 2.5vw, 1.4rem);
  color: var(--color-gold-dim);
  letter-spacing: 0.5em;
  margin-bottom: 4rem;
  opacity: 0.8;
}

.title-menu {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.title-btn {
  font-family: var(--font-ui);
  font-size: clamp(1rem, 2vw, 1.2rem);
  color: var(--color-gold);
  background: transparent;
  border: 1px solid var(--color-border);
  padding: 0.8rem 3rem;
  cursor: pointer;
  letter-spacing: 0.3em;
  transition: all var(--fade-fast) ease;
  position: relative;
  min-width: 220px;
}

.title-btn:hover {
  color: var(--color-white);
  border-color: var(--color-border-glow);
  background: rgba(139, 105, 20, 0.1);
  box-shadow: 0 0 20px rgba(196, 155, 42, 0.15);
}

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

.title-version {
  position: absolute;
  bottom: 1rem;
  right: 1.5rem;
  font-size: 0.75rem;
  color: var(--color-text-dark);
  z-index: 2;
}

/* ===================================================
   游戏画面
   =================================================== */
#game-screen {
  display: none;
  flex-direction: column;
  background: var(--color-bg);
}

/* ---------- 背景层 ---------- */
.bg-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: opacity var(--fade-slow) ease;
  z-index: 1;
}

.bg-layer.fade-out {
  opacity: 0;
}

.bg-layer.fade-in {
  opacity: 1;
}

/* 默认暗色背景（无背景图时的fallback） */
.bg-layer::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: var(--color-bg);
  z-index: -1;
}

/* ---------- 角色层 ---------- */
.character-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.char-slot {
  position: absolute;
  bottom: 0;
  height: var(--char-height);
  width: 35%;
  max-width: 400px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: bottom center;
  transition: opacity var(--fade-normal) ease, transform var(--fade-normal) ease;
  opacity: 0;
  transform: translateY(20px);
}

.char-slot.visible {
  opacity: 1;
  transform: translateY(0);
}

.char-slot.dimmed {
  opacity: 0.4;
  filter: brightness(0.5) saturate(0.3);
}

.char-left   { left: 2%; }
.char-center { left: 50%; transform: translateX(-50%); }
.char-right  { right: 2%; }
.char-center.visible { transform: translateX(-50%) translateY(0); }
.char-center.dimmed  { transform: translateX(-50%); filter: brightness(0.5) saturate(0.3); }

/* ---------- 特效层 ---------- */
.effect-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}

/* 闪白 */
.flash-white {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: white;
  animation: flashAnim 0.5s ease-out forwards;
}

@keyframes flashAnim {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* 闪黑 */
.flash-black {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: black;
  animation: flashBlackAnim 0.8s ease-out forwards;
}

@keyframes flashBlackAnim {
  0% { opacity: 0.95; }
  100% { opacity: 0; }
}

/* 屏幕震动 */
@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-8px, -4px); }
  20% { transform: translate(6px, 6px); }
  30% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -6px); }
  50% { transform: translate(-2px, 4px); }
  60% { transform: translate(6px, -2px); }
  70% { transform: translate(-4px, -4px); }
  80% { transform: translate(2px, 6px); }
  90% { transform: translate(-6px, 2px); }
}

.shake-active {
  animation: screenShake 0.5s ease-in-out;
}

/* 字蚀效果 - 文字模糊消散 */
.char-erosion .dialog-text span {
  animation: textErode 2s ease-out forwards;
}

@keyframes textErode {
  0% { opacity: 1; filter: blur(0); transform: translateX(0); }
  30% { filter: blur(1px); }
  60% { opacity: 0.6; filter: blur(3px); transform: translateX(-5px) rotate(-1deg); }
  100% { opacity: 0; filter: blur(8px); transform: translateX(-20px) rotate(-3deg); }
}

/* 血迹文字效果 */
.blood-text .dialog-text {
  color: var(--color-blood-bright);
  text-shadow:
    0 0 10px rgba(192, 57, 43, 0.5),
    0 0 30px rgba(139, 26, 26, 0.3);
}

/* 雨滴效果容器 */
.rain-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  overflow: hidden;
}

.rain-drop {
  position: absolute;
  top: -20px;
  width: 2px;
  background: linear-gradient(transparent, rgba(180, 200, 220, 0.4));
  animation: rainFall linear infinite;
}

@keyframes rainFall {
  0% { transform: translateY(-20px); }
  100% { transform: translateY(100vh); }
}

/* ===================================================
   对话框
   =================================================== */
.dialog-layer {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 10;
  padding: 0 2% 2%;
}

.dialog-box {
  position: relative;
  background: linear-gradient(
    180deg,
    rgba(10, 8, 6, 0.88) 0%,
    rgba(15, 12, 10, 0.95) 100%
  );
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1.2rem 1.8rem 1rem;
  min-height: var(--dialog-height);
  cursor: pointer;
  box-shadow:
    0 -2px 20px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(212, 168, 67, 0.1);
}

.dialog-box::before {
  content: '';
  position: absolute;
  top: -1px; left: -1px; right: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--color-gold), transparent);
  opacity: 0.6;
}

.speaker-name {
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  font-weight: 700;
  color: var(--color-gold);
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(139, 105, 20, 0.3);
  letter-spacing: 0.15em;
  min-height: 1.5em;
}

.speaker-name:empty {
  display: none;
}

.dialog-text {
  font-size: clamp(0.9rem, 1.8vw, 1.05rem);
  line-height: 1.8;
  color: var(--color-text);
  min-height: 3em;
  letter-spacing: 0.05em;
  word-break: break-all;
}

/* 打字光标 */
.dialog-text .typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--color-gold);
  margin-left: 2px;
  animation: blink 0.8s infinite;
  vertical-align: text-bottom;
}

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

.click-indicator {
  position: absolute;
  bottom: 0.8rem;
  right: 1.2rem;
  font-size: 0.8rem;
  color: var(--color-gold-dim);
  animation: indicatorBounce 1.2s ease-in-out infinite;
  opacity: 0;
  transition: opacity var(--fade-fast);
}

.click-indicator.visible {
  opacity: 1;
}

@keyframes indicatorBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}

/* ===================================================
   选项
   =================================================== */
.choice-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 8, 0.5);
  padding: 2rem;
}

.choice-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 600px;
  width: 100%;
}

.choice-text {
  text-align: center;
  font-size: 1.1rem;
  color: var(--color-text-dim);
  margin-bottom: 1rem;
  letter-spacing: 0.1em;
}

.choice-btn {
  font-family: var(--font-ui);
  font-size: clamp(0.95rem, 2vw, 1.1rem);
  color: var(--color-text);
  background: linear-gradient(
    135deg,
    rgba(20, 18, 14, 0.9) 0%,
    rgba(30, 26, 20, 0.9) 100%
  );
  border: 1px solid var(--color-border);
  padding: 1rem 2rem;
  cursor: pointer;
  letter-spacing: 0.15em;
  transition: all var(--fade-fast) ease;
  position: relative;
  text-align: center;
  /* 古典卷轴风格 */
  border-radius: 2px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}

.choice-btn::before,
.choice-btn::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-color: var(--color-gold-dim);
  opacity: 0.5;
}

.choice-btn::before {
  top: -1px; left: -1px;
  border-top: 2px solid;
  border-left: 2px solid;
}

.choice-btn::after {
  bottom: -1px; right: -1px;
  border-bottom: 2px solid;
  border-right: 2px solid;
}

.choice-btn:hover {
  color: var(--color-gold);
  border-color: var(--color-border-glow);
  background: linear-gradient(
    135deg,
    rgba(30, 26, 20, 0.95) 0%,
    rgba(45, 38, 28, 0.95) 100%
  );
  box-shadow:
    0 0 20px rgba(196, 155, 42, 0.15),
    0 2px 10px rgba(0,0,0,0.4);
  transform: translateX(5px);
}

.choice-btn:active {
  transform: translateX(5px) scale(0.98);
}

/* ===================================================
   快捷栏
   =================================================== */
.quick-bar {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: linear-gradient(180deg, rgba(0,0,0,0.4) 0%, transparent 100%);
  opacity: 0;
  transition: opacity var(--fade-fast);
}

.quick-bar:hover,
.quick-bar.visible {
  opacity: 1;
}

.quick-btn {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: var(--color-text-dim);
  background: rgba(15, 12, 10, 0.7);
  border: 1px solid rgba(139, 105, 20, 0.3);
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  letter-spacing: 0.1em;
  transition: all var(--fade-fast);
}

.quick-btn:hover {
  color: var(--color-gold);
  border-color: var(--color-border);
}

.quick-btn.active {
  color: var(--color-blood-bright);
  border-color: var(--color-red);
}

/* ===================================================
   覆盖层（存档/状态/线索/设置/日志）
   =================================================== */
.overlay-screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay-backdrop {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(5, 5, 8, 0.85);
}

.overlay-panel {
  position: relative;
  z-index: 1;
  background: linear-gradient(
    180deg,
    rgba(18, 15, 12, 0.98) 0%,
    rgba(12, 10, 8, 0.98) 100%
  );
  border: 1px solid var(--color-border);
  padding: 2rem;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}

.panel-title {
  font-size: 1.3rem;
  color: var(--color-gold);
  text-align: center;
  letter-spacing: 0.3em;
  margin-bottom: 1.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid rgba(139, 105, 20, 0.3);
}

.panel-close {
  display: block;
  margin: 1.5rem auto 0;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  color: var(--color-text-dim);
  background: transparent;
  border: 1px solid var(--color-text-dark);
  padding: 0.5rem 2rem;
  cursor: pointer;
  letter-spacing: 0.2em;
  transition: all var(--fade-fast);
}

.panel-close:hover {
  color: var(--color-gold);
  border-color: var(--color-border);
}

/* ---------- 存档槽位 ---------- */
.save-slots {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.save-slot {
  display: flex;
  align-items: center;
  padding: 0.8rem 1rem;
  background: rgba(20, 18, 14, 0.8);
  border: 1px solid rgba(139, 105, 20, 0.2);
  cursor: pointer;
  transition: all var(--fade-fast);
}

.save-slot:hover {
  border-color: var(--color-border);
  background: rgba(30, 26, 20, 0.9);
}

.save-slot-num {
  font-size: 1.5rem;
  color: var(--color-gold-dim);
  width: 3rem;
  text-align: center;
  flex-shrink: 0;
}

.save-slot-info {
  flex: 1;
  margin-left: 0.8rem;
}

.save-slot-node {
  font-size: 0.9rem;
  color: var(--color-text);
  margin-bottom: 0.2rem;
}

.save-slot-time {
  font-size: 0.75rem;
  color: var(--color-text-dim);
}

.save-slot-empty {
  color: var(--color-text-dark);
  font-style: italic;
}

.save-slot-delete {
  font-size: 0.8rem;
  color: var(--color-red);
  background: transparent;
  border: 1px solid var(--color-red);
  padding: 0.2rem 0.6rem;
  cursor: pointer;
  margin-left: 0.5rem;
  opacity: 0.6;
  transition: opacity var(--fade-fast);
}

.save-slot-delete:hover {
  opacity: 1;
}

/* ---------- 状态面板 ---------- */
.status-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.status-item {
  padding: 0.6rem 0.8rem;
  background: rgba(20, 18, 14, 0.6);
  border-left: 2px solid var(--color-border);
}

.status-label {
  font-size: 0.75rem;
  color: var(--color-text-dim);
  margin-bottom: 0.3rem;
  letter-spacing: 0.1em;
}

.status-value {
  font-size: 1rem;
  color: var(--color-gold);
}

.status-value.danger {
  color: var(--color-blood-bright);
}

.status-value.safe {
  color: #4a9;
}

/* ---------- 线索面板 ---------- */
.evidence-content {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.evidence-item {
  padding: 0.6rem 0.8rem;
  background: rgba(20, 18, 14, 0.6);
  border-left: 2px solid var(--color-gold-dim);
}

.evidence-item-name {
  font-size: 0.95rem;
  color: var(--color-gold);
  margin-bottom: 0.2rem;
}

.evidence-item-desc {
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

.evidence-empty {
  text-align: center;
  color: var(--color-text-dark);
  font-style: italic;
  padding: 2rem;
}

/* ---------- 设置面板 ---------- */
.settings-content {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.setting-label {
  font-size: 0.9rem;
  color: var(--color-text);
  width: 120px;
  flex-shrink: 0;
}

.setting-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--color-text-dark);
  outline: none;
  border-radius: 2px;
}

.setting-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--color-gold);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(212, 168, 67, 0.4);
}

.setting-row input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--color-gold);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* ---------- 日志面板 ---------- */
.log-content {
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.log-entry {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid rgba(139, 105, 20, 0.1);
}

.log-speaker {
  font-size: 0.8rem;
  color: var(--color-gold-dim);
  margin-bottom: 0.2rem;
}

.log-text {
  font-size: 0.9rem;
  color: var(--color-text-dim);
}

/* ===================================================
   结局画面
   =================================================== */
#ending-screen {
  display: none;
  align-items: center;
  justify-content: center;
}

.ending-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at center, rgba(15, 12, 10, 0.95), var(--color-bg));
  z-index: 1;
}

.ending-content {
  position: relative;
  z-index: 2;
  text-align: center;
  animation: titleFadeIn 2s ease-out;
  max-width: 600px;
  padding: 2rem;
}

.ending-route {
  font-size: 1rem;
  color: var(--color-text-dim);
  letter-spacing: 0.3em;
  margin-bottom: 1rem;
}

.ending-title {
  font-size: clamp(2rem, 5vw, 3rem);
  color: var(--color-blood-bright);
  margin-bottom: 2rem;
  text-shadow: 0 0 20px rgba(192, 57, 43, 0.3);
}

.ending-text {
  font-size: 1rem;
  color: var(--color-text);
  line-height: 1.8;
  margin-bottom: 3rem;
  opacity: 0.8;
}

/* ===================================================
   自定义滚动条
   =================================================== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-text-dark);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-gold-dim);
}

/* ===================================================
   响应式适配
   =================================================== */
@media (max-width: 768px) {
  :root {
    --dialog-height: 180px;
    --char-height: 70vh;
  }

  .dialog-box {
    padding: 1rem 1.2rem 0.8rem;
    margin: 0 0.5rem;
  }

  .dialog-text {
    font-size: 0.85rem;
    line-height: 1.7;
  }

  .choice-btn {
    font-size: 0.9rem;
    padding: 0.8rem 1.2rem;
  }

  .quick-btn {
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
  }

  .overlay-panel {
    padding: 1.5rem;
    width: 95%;
    max-height: 85vh;
  }

  .status-content {
    grid-template-columns: 1fr;
  }

  .char-slot {
    width: 40%;
  }

  .title-main {
    letter-spacing: 0.15em;
  }
}

@media (max-width: 480px) {
  :root {
    --dialog-height: 160px;
  }

  .dialog-box {
    padding: 0.8rem 1rem;
  }

  .speaker-name {
    font-size: 0.85rem;
  }

  .dialog-text {
    font-size: 0.8rem;
    line-height: 1.6;
  }

  .choice-container {
    gap: 0.7rem;
  }

  .choice-btn {
    font-size: 0.85rem;
    padding: 0.7rem 1rem;
  }
}

/* ===================================================
   过渡动画辅助
   =================================================== */
.hidden { display: none !important; }

.fade-in {
  animation: fadeIn var(--fade-normal) ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-out {
  animation: fadeOut var(--fade-normal) ease forwards;
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}
