/* ============================================================
   WikiGame · Vue 风格多主题样式（自包含，零外部依赖）
   主题通过 <html data-theme="..."> 切换，全部颜色收敛为 CSS 变量
   ============================================================ */

/* ---------------- 主题 ---------------- */
:root,
html[data-theme="vue-light"] {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --fg: #213547;
  --fg-muted: #8494a7;
  --accent: #42b883;
  --accent-deep: #35495e;
  --accent-soft: rgba(66, 184, 131, 0.14);
  --border: #e5e9ef;
  --code-bg: #eef1f6;
  --code-fg: #476582;
  --quote-bg: rgba(66, 184, 131, 0.08);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --danger: #d9636e;
  color-scheme: light;
}

html[data-theme="vue-dark"] {
  --bg: #1b1f24;
  --bg-soft: #23282f;
  --fg: #dfe5ec;
  --fg-muted: #8b98a5;
  --accent: #42d392;
  --accent-deep: #63e6b3;
  --accent-soft: rgba(66, 211, 146, 0.16);
  --border: #2d3540;
  --code-bg: #262c34;
  --code-fg: #a3d9c2;
  --quote-bg: rgba(66, 211, 146, 0.08);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  --danger: #e8747a;
  color-scheme: dark;
}

html[data-theme="paper"] {
  --bg: #f6efe2;
  --bg-soft: #efe6d3;
  --fg: #4b4237;
  --fg-muted: #9a8b79;
  --accent: #b5713f;
  --accent-deep: #8a5427;
  --accent-soft: rgba(181, 113, 63, 0.14);
  --border: #e2d6bd;
  --code-bg: #ece2cb;
  --code-fg: #7a5a35;
  --quote-bg: rgba(181, 113, 63, 0.08);
  --shadow: 0 2px 10px rgba(120, 96, 60, 0.18);
  --danger: #b05f4a;
  color-scheme: light;
}

/* ---------------- 基础 ---------------- */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.7;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* 链接一律不做原生拖拽源：按住链接挪动超过 4px（Windows 拖拽阈值）这次点击就被判成
   "拖链接"，浏览器随即进入模态拖拽循环、整页输入冻死。机制详见 scripts.js 的 dragstart 拦截。
   正文里选中文字的拖动不受影响——只拦链接。 */
a {
  -webkit-user-drag: none;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: background-color 0.25s ease;
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  height: 60px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--fg);
  white-space: nowrap;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.brand-tag {
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 1px 10px;
}

/* 搜索框 */
.search {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.search input {
  width: min(420px, 100%);
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 9px 0 0 9px;
  border-right: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search input::placeholder {
  color: var(--fg-muted);
}

.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search button {
  padding: 8px 18px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 0 9px 9px 0;
  cursor: pointer;
  transition: background-color 0.2s;
}

.search button:hover {
  background: var(--accent-deep);
}

/* 主题切换 */
.theme-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.theme-switch button {
  width: 34px;
  height: 30px;
  font-size: 15px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.theme-switch button:hover {
  color: var(--fg);
}

.theme-switch button.active {
  background: var(--bg);
  color: var(--accent);
  box-shadow: var(--shadow);
}

/* 设置面板：装「主题」与「剧透模式」两组控件。
   桌面端容器不参与布局（display: contents），两组控件照旧平铺在顶栏里；
   移动端断点（见文件末尾）把它变成 ⚙ 打开的浮窗，顶栏因此只留 ☰ 与 ⚙ */
.settings-panel {
  display: contents;
}

.settings-title,
.settings-label,
.settings-state,
.settings-close,
.gear-btn {
  display: none;
}

/* ---------------- 布局 ---------------- */
.layout {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 80px;
  display: flex;
  align-items: flex-start;
  gap: 36px;
}

/* 侧栏 */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  position: sticky;
  top: 92px;
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 12px;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.sidebar-close:hover {
  background: var(--bg-soft);
  color: var(--fg);
}

.progress-badge {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 12px;
  letter-spacing: 0;
}

.page-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.group-header {
  margin: 16px 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--fg-muted);
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  transition: color 0.15s ease;
}

.group-header:first-child {
  margin-top: 0;
}

/* 展开 / 收起箭头，兼作可点的提示 */
.group-header::before {
  content: "▾";
  display: inline-block;
  width: 12px;
  margin-right: 2px;
  font-size: 9px;
  letter-spacing: 0;
}

.group-header.collapsed::before {
  content: "▸";
}

.group-header:hover {
  color: var(--fg);
}

/* 收起后，正读着的那一页就藏在这里——标题着色提醒 */
.group-header.has-current {
  color: var(--accent);
}

/* 收起的分组里还有没读过的条目：标题上直接标数量，形状与条目的"新"标记一致，
   免得"收起来 = 错过新内容" */
.group-header.collapsed.has-fresh::after {
  content: "新 " attr(data-fresh);
  margin-left: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 0 4px;
}

.page-item.in-collapsed {
  display: none;
}

.page-item {
  position: relative;
  display: block;
  padding: 7px 12px;
  font-size: 14px;
  color: var(--fg);
  text-decoration: none;
  border-radius: 8px;
  transition: background-color 0.15s, color 0.15s;
  user-select: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.page-item:hover {
  background: var(--bg-soft);
  color: var(--accent);
}

.page-item.current {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.page-item.current::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}

/* 可达但尚未访问过的页面：带"新"标记，提示玩家去阅读 */
.page-item.fresh::after {
  content: "新";
  float: right;
  margin-left: 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 0 4px;
}

/* ---------------- 内容区 ---------------- */
.content {
  flex: 1;
  min-width: 0;
}

.markdown-body {
  max-width: 760px;
  font-size: 16px;
  word-wrap: break-word;
}

.markdown-body .loading {
  color: var(--fg-muted);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 600;
  line-height: 1.35;
  margin: 1.6em 0 0.7em;
}

.markdown-body h1 {
  font-size: 30px;
  margin-top: 0.4em;
  padding-bottom: 0.4em;
  border-bottom: 1px solid var(--border);
}

.markdown-body h2 {
  font-size: 22px;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border);
}

.markdown-body h3 {
  font-size: 18px;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft);
  transition: border-color 0.15s;
}

.markdown-body a:hover {
  border-bottom-color: var(--accent);
}

.markdown-body p {
  margin: 0.9em 0;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  vertical-align: middle;
}

.markdown-body blockquote {
  margin: 1em 0;
  padding: 10px 18px;
  border-left: 3px solid var(--accent);
  background: var(--quote-bg);
  border-radius: 0 8px 8px 0;
  color: var(--fg-muted);
}

.markdown-body blockquote p {
  margin: 0.4em 0;
}

.markdown-body code {
  font-family: "SF Mono", "Fira Code", Consolas, "Courier New", monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 4px;
  padding: 0.15em 0.45em;
}

.markdown-body pre {
  background: var(--code-bg);
  border-radius: 10px;
  padding: 16px 18px;
  overflow: auto;
  line-height: 1.55;
}

.markdown-body pre code {
  background: transparent;
  color: var(--fg);
  padding: 0;
  font-size: 0.86em;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.6em;
  margin: 0.8em 0;
}

.markdown-body li {
  margin: 0.3em 0;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.markdown-body table {
  border-collapse: collapse;
  margin: 1em 0;
  width: 100%;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 7px 13px;
  text-align: left;
}

.markdown-body th {
  background: var(--bg-soft);
  font-weight: 600;
}

/* 进度卡片（游戏介绍页自动追加） */
.progress-card {
  margin-top: 40px;
  padding: 18px 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
}

.progress-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.progress-line {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-deep));
  transition: width 0.5s ease;
}

.progress-bar.achieved-bar {
  background: linear-gradient(90deg, #f0c14b, #c9971e);
}

.progress-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 0 2px;
}

.achieve-count {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  background: var(--accent-soft);
  padding: 1px 9px;
  border-radius: 999px;
  vertical-align: 2px;
}

.achieve-list {
  list-style: none;
  margin: 0 0 6px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.achieve-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.achieve-item.earned {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.achieve-item.locked {
  color: var(--fg-muted);
  border-style: dashed;
}

.achieve-item .achieve-icon {
  flex-shrink: 0;
  font-size: 13px;
}

.achieve-item .achieve-desc {
  margin-left: auto;
  font-size: 12px;
  color: var(--fg-muted);
}

.restart-btn {
  padding: 8px 18px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.restart-btn:hover {
  color: #fff;
  background: var(--accent);
}

/* 二次确认的待确认态：填充色提醒，再点一次才执行 */
.restart-btn.armed,
.reset-btn.armed {
  color: #fff;
  opacity: 1;
}

.restart-btn.armed {
  background: var(--accent);
}

.reset-btn.armed {
  background: var(--danger);
}

.progress-text {
  margin: 10px 0 14px;
  font-size: 14px;
  color: var(--fg-muted);
}

.progress-text b {
  color: var(--accent);
}

.reset-btn {
  padding: 8px 18px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  color: var(--danger);
  background: transparent;
  border: 1px solid var(--danger);
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.85;
  transition: background-color 0.15s, color 0.15s, opacity 0.15s;
}

.reset-btn:hover {
  color: #fff;
  background: var(--danger);
  opacity: 1;
}

/* ---------------- 剧透模式与提示块 ---------------- */
/* ```help 围栏渲染为提示块：剧透模式关闭（body.spoiler-off）时只显示占位条 */
.help-block {
  margin: 1em 0;
  border: 1px dashed var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.help-hint {
  display: none;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--fg-muted);
  cursor: pointer;
  user-select: none;
}

.help-hint:hover {
  color: var(--accent);
}

.help-body {
  padding: 6px 14px 10px;
  font-size: 14px;
  background: var(--code-bg);
  border-left: 3px solid var(--accent);
}

.help-body p {
  margin: 0.4em 0;
}

.help-body ul {
  margin: 0.4em 0;
  padding-left: 1.4em;
}

body.spoiler-off .help-hint {
  display: block;
}

body.spoiler-off .help-body {
  display: none;
}

/* ---------------- 提示条：多条同显，向上浮动、挨个消失 ---------------- */
#toast-box {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 80vw;
  z-index: 70;
  pointer-events: none;
}

.toast {
  max-width: 80vw;
  padding: 9px 20px;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 999px;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease both;
}

.toast.bye {
  animation: toast-out 0.32s ease both;
}

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

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

/* ---------------- 移动端 ---------------- */
.menu-btn,
.gear-btn {
  display: none;
  width: 34px;
  height: 34px;
  font-size: 17px;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--fg);
  cursor: pointer;
}

.build-stamp {
  padding: 10px 14px;
  font-size: 11px;
  color: var(--fg-muted);
  opacity: 0.7;
}

.backdrop {
  display: none;
}

@media (max-width: 768px) {
  .menu-btn,
  .gear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  /* 齿轮贴在顶栏首行右端（搜索独占第二行） */
  .gear-btn {
    margin-left: auto;
  }

  .topbar-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 16px;
    row-gap: 8px;
    gap: 12px;
  }

  .search {
    order: 3;
    flex-basis: 100%;
  }

  /* ⚙ 打开的浮窗：挂在顶栏下缘（.topbar 是 sticky，绝对定位以它为界），
     展开与收起只切 body.settings-open，控件本身始终在同一个 DOM 位置 */
  .settings-panel {
    display: none;
    position: absolute;
    top: 100%;
    right: 12px;
    width: min(272px, 86vw);
    padding: 12px 14px 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    animation: panel-in 0.18s ease both;
  }

  body.settings-open .settings-panel {
    display: block;
  }

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

  .settings-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--fg-muted);
  }

  .settings-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    font-size: 13px;
    letter-spacing: 0;
    line-height: 1;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--fg-muted);
    cursor: pointer;
  }

  .settings-close:hover {
    background: var(--bg-soft);
    color: var(--fg);
  }

  .settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
  }

  /* 标签占满左侧，控件靠右成列 */
  .settings-label {
    display: block;
    margin-right: auto;
    font-size: 14px;
    color: var(--fg);
  }

  .settings-state {
    display: inline-block;
    min-width: 30px;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--fg-muted);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 7px;
  }

  .settings-state.on {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: var(--accent);
  }

  /* 浮窗里没有 hover 提示：三个主题按钮改显文字标签（data-label）。
     只挑 #theme-switch——剧透开关也用 .theme-switch 这层壳，图标得留着 */
  .settings-panel #theme-switch button {
    width: auto;
    min-width: 50px;
    padding: 0 10px;
    font-size: 0;
  }

  .settings-panel #theme-switch button::after {
    content: attr(data-label);
    font-size: 13px;
  }

  .layout {
    flex-direction: column;
    padding: 20px 16px 60px;
    gap: 20px;
  }

  /* 侧栏变为抽屉：默认收起，body.sidebar-open 时滑入 */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 60;
    width: min(300px, 82vw);
    margin: 0;
    padding: 20px 16px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    top: 0;
    height: 100vh;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-close {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  body.sidebar-open .backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .markdown-body h1 {
    font-size: 25px;
  }

  /* 提示条：占满屏宽（留 12px 边距），位置在搜索输入框下方 */
  #toast-box {
    top: 176px;
    left: 12px;
    right: 12px;
    transform: none;
    max-width: none;
  }

  .toast {
    width: 100%;
    max-width: none;
    padding: 9px 14px;
    text-align: center;
    border-radius: 10px;
  }

  /* 引用块/提示文字：收紧内边距，给正文更多宽度 */
  .markdown-body blockquote {
    padding: 8px 12px;
  }
}
