/* ============================================================
   迷雾庄园 · 沉浸式样式
   暗色维多利亚氛围 / 雾气 / 烛光 / 打字机 / 选项卡片
   ============================================================ */

:root {
  --bg: #0d0b14;
  --bg-soft: #15121f;
  --ink: #e8e2d4;        /* 羊皮纸色正文 */
  --ink-dim: #9a9180;
  --gold: #c9a96a;       /* 烛光金 */
  --gold-soft: #8a7444;
  --crimson: #6b2737;    /* 暗红 */
  --border: rgba(201, 169, 106, 0.25);
  --shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  --serif: "Georgia", "Songti SC", "STSong", "SimSun", serif;
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.9;
  overflow-x: hidden;
}

body {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

/* ---------- 雾气背景 ---------- */
.fog {
  position: fixed;
  inset: -50%;
  background: radial-gradient(ellipse at center, rgba(201,169,106,0.05) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
  animation: drift 40s linear infinite;
}
.fog-2 {
  background: radial-gradient(ellipse at center, rgba(107,39,55,0.06) 0%, transparent 55%);
  animation: drift 55s linear infinite reverse;
  animation-delay: -10s;
}
@keyframes drift {
  0%   { transform: translate(0, 0) rotate(0deg); }
  50%  { transform: translate(4%, 3%) rotate(8deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

/* ---------- 烛光 ---------- */
.candle {
  position: fixed;
  bottom: 8%;
  width: 280px;
  height: 70vh;
  background: radial-gradient(ellipse at bottom, rgba(201,169,106,0.18) 0%, transparent 65%);
  pointer-events: none;
  z-index: 0;
  animation: flicker 3.2s ease-in-out infinite;
}
.candle-l { left: -60px; }
.candle-r { right: -60px; animation-delay: -1.4s; }
@keyframes flicker {
  0%, 100% { opacity: 0.85; transform: scaleY(1); }
  25%      { opacity: 1;    transform: scaleY(1.03); }
  50%      { opacity: 0.7;  transform: scaleY(0.98); }
  75%      { opacity: 0.95; transform: scaleY(1.02); }
}

/* ---------- 主容器 ---------- */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 680px;
  background: linear-gradient(180deg, var(--bg-soft) 0%, rgba(13,11,20,0.92) 100%);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: var(--shadow);
  padding: 48px 32px 40px;
  min-height: 60vh;
}

/* ---------- 标题屏 ---------- */
.title-screen {
  text-align: center;
  animation: fadeIn 1.2s ease;
}
.kicker {
  color: var(--gold);
  letter-spacing: 0.3em;
  font-size: 0.8rem;
  margin-bottom: 18px;
}
.title {
  font-size: clamp(2.6rem, 8vw, 4rem);
  font-weight: 400;
  letter-spacing: 0.15em;
  color: var(--ink);
  margin-bottom: 14px;
  text-shadow: 0 0 30px rgba(201,169,106,0.3);
}
.subtitle {
  color: var(--ink-dim);
  font-size: 1.05rem;
  margin-bottom: 40px;
  font-style: italic;
}
.btn-primary {
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-soft) 100%);
  color: #1a1408;
  border: none;
  padding: 14px 44px;
  font-family: var(--serif);
  font-size: 1.05rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  border-radius: 2px;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
  box-shadow: 0 4px 20px rgba(201,169,106,0.3);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(201,169,106,0.45); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.hint {
  margin-top: 24px;
  color: var(--ink-dim);
  font-size: 0.85rem;
}

/* ---------- 游戏屏 ---------- */
.game-screen { animation: fadeIn 0.6s ease; }
.chapter {
  color: var(--gold);
  letter-spacing: 0.2em;
  font-size: 0.82rem;
  margin-bottom: 22px;
  text-align: center;
  min-height: 1.2em;
}
.story-text {
  color: var(--ink);
  font-size: 1.08rem;
  white-space: pre-wrap;
  min-height: 6em;
  margin-bottom: 28px;
  text-align: justify;
}
/* 打字机光标 */
.story-text::after {
  content: "▍";
  color: var(--gold);
  animation: blink 0.9s step-end infinite;
  opacity: 0;
}
.story-text.typing::after { opacity: 1; }
@keyframes blink { 50% { opacity: 0; } }

.options { display: flex; flex-direction: column; gap: 14px; }
.option-card {
  display: block;
  width: 100%;
  text-align: left;
  background: rgba(201,169,106,0.04);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold-soft);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.7;
  padding: 16px 20px;
  cursor: pointer;
  border-radius: 2px;
  opacity: 0;
  transform: translateY(8px);
  transition: background 0.25s, border-color 0.25s, transform 0.25s, opacity 0.4s;
}
.option-card.show { opacity: 1; transform: translateY(0); }
.option-card:hover {
  background: rgba(201,169,106,0.1);
  border-left-color: var(--gold);
  transform: translateX(4px);
}
.option-card:disabled { cursor: default; opacity: 0.35; }
.option-card.chosen {
  background: rgba(201,169,106,0.14);
  border-left-color: var(--gold);
}

/* 反馈小段 */
.feedback {
  color: var(--ink-dim);
  font-style: italic;
  font-size: 0.98rem;
  margin: 4px 0 28px;
  padding-left: 16px;
  border-left: 2px solid var(--crimson);
  animation: fadeIn 0.8s ease;
}

/* 进度 */
.progress {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 36px;
}
.progress-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(201,169,106,0.2);
  transition: background 0.3s;
}
.progress-dot.done { background: var(--gold); }
.progress-dot.current { background: var(--ink); box-shadow: 0 0 8px var(--gold); }

/* ---------- 结局屏 ---------- */
.result-screen {
  text-align: center;
  animation: fadeIn 1s ease;
}
.ending-title {
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.2em;
  color: var(--ink);
  margin-bottom: 24px;
  text-align: center;
}
.ending-text {
  color: var(--ink-dim);
  font-size: 1.02rem;
  white-space: pre-wrap;
  text-align: justify;
  min-height: 8em;
  margin-bottom: 32px;
  line-height: 2;
}
.ending-text.typing::after {
  content: "▍";
  color: var(--gold);
  animation: blink 0.9s step-end infinite;
}

/* MBTI 区（结局正文完成后淡入） */
.mbti-box {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 1.2s ease, transform 1.2s ease;
  pointer-events: none;
}
.mbti-box.mbti-show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.mbti-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 auto 26px;
  max-width: 420px;
}
.mbti-divider::before,
.mbti-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-soft), transparent);
}
.mbti-divider span {
  color: var(--gold);
  font-size: 0.8rem;
  letter-spacing: 0.25em;
  white-space: nowrap;
}
.mbti-code {
  font-size: clamp(3rem, 12vw, 5rem);
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--gold);
  margin: 12px 0 6px;
  text-shadow: 0 0 40px rgba(201,169,106,0.5);
  animation: glow 2.4s ease-in-out infinite;
}
@keyframes glow {
  0%, 100% { text-shadow: 0 0 30px rgba(201,169,106,0.4); }
  50%      { text-shadow: 0 0 55px rgba(201,169,106,0.7); }
}
.mbti-name {
  color: var(--ink);
  font-size: 1.4rem;
  letter-spacing: 0.15em;
  margin-bottom: 28px;
}
.mbti-role {
  color: var(--gold);
  font-style: italic;
  font-size: 1.05rem;
  margin-bottom: 18px;
  padding: 0 8px;
}
.mbti-desc {
  color: var(--ink-dim);
  font-size: 1rem;
  margin-bottom: 28px;
  padding: 0 8px;
  text-align: justify;
}

/* ---------- 四维度倾向条 ---------- */
.mbti-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
  margin: 0 auto 36px;
  padding: 0 8px;
}
.mbti-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: default;
}
.bar-side {
  width: 20px;
  color: var(--ink-dim);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-align: center;
  transition: color 0.3s, text-shadow 0.3s;
}
/* 测出的一侧：金色高亮 */
.bar-side.side-win {
  color: var(--gold);
  text-shadow: 0 0 10px rgba(201,169,106,0.5);
  font-weight: bold;
}
.bar-track {
  position: relative;
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(201,169,106,0.15);
  overflow: hidden;
}
.bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background: linear-gradient(90deg, var(--gold-soft), var(--gold));
  opacity: 0.85;
}
/* 蓝金线别下倾向条跟随主题色 */
body.tint-blue .bar-side.side-win {
  color: #a8c4e8;
  text-shadow: 0 0 10px rgba(120,160,220,0.5);
}
body.tint-blue .bar-fill {
  background: linear-gradient(90deg, #5a7ab0, #a8c4e8);
}
body.tint-gold .bar-fill {
  background: linear-gradient(90deg, var(--gold-soft), #e6be64);
}
.result-actions { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.btn-ghost {
  background: transparent;
  color: var(--gold);
  border: 1px solid var(--gold-soft);
  padding: 14px 32px;
  font-family: var(--serif);
  font-size: 1.05rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.2s, color 0.2s;
}
.btn-ghost:hover { background: rgba(201,169,106,0.12); color: var(--ink); }

/* ---------- 页脚 ---------- */
.footer {
  position: relative;
  z-index: 1;
  margin-top: 24px;
  color: var(--ink-dim);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  opacity: 0.7;
}

/* ---------- 通用 ---------- */
.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 响应式 ---------- */
@media (max-width: 540px) {
  .app { padding: 32px 20px 28px; }
  .story-text { font-size: 1rem; }
  .option-card { font-size: 0.95rem; padding: 14px 16px; }
  .candle { width: 180px; }
}

/* ---------- 减弱动效（可访问性）：尊重系统偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  /* 持续氛围动画全部暂停（雾/烛光/光标闪烁/MBTI glow 呼吸） */
  .fog, .fog-2, .candle,
  .story-text.typing::after, .ending-text.typing::after,
  .mbti-code { animation: none; }
  /* 震屏/骤暗等一次性强动效直接取消 */
  .app.fx-shatter { animation: none; }
  /* 一次性过渡收短（选项淡入/卡片过渡） */
  .option-card, .btn-primary, .btn-ghost, .mbti-box, .bar-side { transition: none; }
}

/* ============================================================
   隐藏结局版新增样式
   ============================================================ */

/* ---------- 结局图鉴 ---------- */
.gallery-wrap {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.gallery-label {
  color: var(--ink-dim);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
}
.gallery {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.gallery-slot {
  min-width: 52px;
  padding: 6px 10px;
  text-align: center;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  border: 1px solid var(--border);
  border-radius: 2px;
  background: rgba(201,169,106,0.03);
  cursor: default;
  transition: all 0.3s;
}
.gallery-slot.unlocked {
  color: var(--gold);
  border-color: var(--gold-soft);
  background: rgba(201,169,106,0.1);
  text-shadow: 0 0 12px rgba(201,169,106,0.4);
}
/* 隐藏结局槽：即便解锁也保留神秘感 */
.gallery-slot:nth-child(4):not(.unlocked) {
  border-style: dashed;
  opacity: 0.6;
}

/* ---------- 16 型名片夹 ---------- */
.cards-label {
  color: var(--ink-dim);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  margin-top: 8px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  justify-content: center;
  max-width: 460px;
  margin-top: 4px;
}
.card-slot {
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  font-family: Georgia, serif;
  color: var(--ink-dim);
  opacity: 0.45;
  border: 1px dashed var(--border);
  border-radius: 2px;
  padding: 4px 0;
  cursor: default;
  transition: all 0.3s;
  user-select: none;
}
.card-slot.unlocked {
  color: var(--gold);
  border: 1px solid var(--gold-soft);
  background: rgba(201,169,106,0.08);
  text-shadow: 0 0 10px rgba(201,169,106,0.35);
  opacity: 1;
}
.card-slot.unlocked:hover {
  background: rgba(201,169,106,0.16);
}
@media (max-width: 540px) {
  .cards { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; max-width: 100%; }
  .card-slot { font-size: 0.6rem; padding: 3px 0; }
}

/* ---------- 隐藏选项（金色） ---------- */
.option-card.option-hidden {
  border-left: 3px solid var(--gold);
  background: linear-gradient(90deg, rgba(201,169,106,0.12), rgba(201,169,106,0.03));
  text-shadow: 0 0 14px rgba(201,169,106,0.35);
}
.option-card.option-hidden:hover {
  background: linear-gradient(90deg, rgba(201,169,106,0.2), rgba(201,169,106,0.06));
}

/* ---------- 交互隐喻效果 ---------- */
/* 碎瓷：震屏 + 骤暗 */
@keyframes shatterShake {
  0%   { transform: translate(0, 0); }
  15%  { transform: translate(-5px, 2px); }
  30%  { transform: translate(4px, -3px); }
  45%  { transform: translate(-3px, -2px); }
  60%  { transform: translate(3px, 2px); }
  75%  { transform: translate(-2px, 1px); }
  100% { transform: translate(0, 0); }
}
.app.fx-shatter {
  animation: shatterShake 0.5s ease, shatterDark 0.7s ease;
}
@keyframes shatterDark {
  0%   { filter: brightness(0.4); }
  100% { filter: brightness(1); }
}

/* B线烛光转蓝 */
body.tint-blue .candle {
  background: radial-gradient(ellipse at bottom, rgba(90,140,200,0.22) 0%, transparent 65%);
}
body.tint-blue .app {
  border-color: rgba(120,160,220,0.3);
}
body.tint-blue .chapter,
body.tint-blue .story-text::after {
  color: #a8c4e8;
}
body.tint-blue .option-card {
  border-left-color: #5a7ab0;
}
body.tint-blue .option-card:hover {
  background: rgba(120,160,220,0.1);
  border-left-color: #a8c4e8;
}

/* D线金色调 */
body.tint-gold .candle {
  background: radial-gradient(ellipse at bottom, rgba(230,190,100,0.28) 0%, transparent 65%);
}
body.tint-gold .app {
  border-color: rgba(230,190,100,0.4);
}
body.tint-gold .mbti-code,
body.tint-gold .chapter {
  text-shadow: 0 0 40px rgba(230,190,100,0.6);
}

/* ============================================================
   完整功能版新增样式（设置/历史/撤销/键盘/存档续玩）
   ============================================================ */

/* ---------- 右上角工具条 ---------- */
.toolbar {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  display: flex;
  gap: 8px;
}
.tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(21,18,31,0.85);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.25s;
  backdrop-filter: blur(4px);
}
.tool-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 16px rgba(201,169,106,0.25);
}
.tool-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201,169,106,0.12);
}

/* ---------- 遮罩面板 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 6, 12, 0.75);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.25s ease;
}
.panel {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, var(--bg-soft) 0%, #100d19 100%);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: var(--shadow);
  padding: 28px 26px;
}
.panel-wide { max-width: 520px; }
.panel-title {
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  color: var(--gold);
  text-align: center;
  margin-bottom: 22px;
}
.panel-body { display: flex; flex-direction: column; gap: 18px; }
.panel-tip {
  color: var(--ink-dim);
  font-size: 0.78rem;
  line-height: 1.8;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 4px;
}
.panel-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}
.panel-actions .btn-primary,
.panel-actions .btn-ghost { padding: 10px 24px; font-size: 0.95rem; }

/* ---------- 设置行 ---------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.setting-label {
  color: var(--ink);
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}

/* 分段选择器（打字速度） */
.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.segmented button {
  background: transparent;
  border: none;
  color: var(--ink-dim);
  font-family: var(--serif);
  font-size: 0.85rem;
  padding: 7px 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active {
  background: rgba(201,169,106,0.15);
  color: var(--gold);
}

/* 开关 */
.toggle {
  position: relative;
  width: 52px;
  height: 28px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(201,169,106,0.05);
  cursor: pointer;
  transition: all 0.25s;
}
.toggle-knob {
  position: absolute;
  top: 3px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: all 0.25s;
}
.toggle.on {
  background: rgba(201,169,106,0.25);
  border-color: var(--gold-soft);
}
.toggle.on .toggle-knob {
  left: 26px;
  background: var(--gold);
  box-shadow: 0 0 10px rgba(201,169,106,0.5);
}

/* ---------- 历史记录 ---------- */
.history-list {
  list-style: none;
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 8px;
}
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: var(--gold-soft); border-radius: 2px; }
.history-chapter {
  color: var(--gold);
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  margin: 14px 0 6px;
}
.history-chapter:first-child { margin-top: 0; }
.history-item {
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.8;
  white-space: pre-wrap;
  margin-bottom: 4px;
}
.history-item.history-dim { color: var(--ink-dim); font-style: italic; }
.history-chosen {
  color: var(--gold);
  font-size: 0.85rem;
  margin: 4px 0 10px;
  padding-left: 12px;
  border-left: 2px solid var(--gold-soft);
}

/* ---------- 撤销栏 ---------- */
.undo-bar {
  margin-top: 18px;
  text-align: center;
  animation: fadeIn 0.5s ease;
}
.link-btn {
  background: none;
  border: none;
  color: var(--ink-dim);
  font-family: var(--serif);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  transition: color 0.2s;
}
.link-btn:hover { color: var(--gold); }

/* ---------- 键盘序号 ---------- */
.opt-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-right: 10px;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--ink-dim);
  font-size: 0.72rem;
  font-family: Georgia, serif;
  vertical-align: 1px;
  flex-shrink: 0;
}
.option-card { display: flex; align-items: baseline; }

/* ---------- 标题屏按钮组 ---------- */
.title-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.gallery-wrap .link-btn { margin-top: 6px; }
