:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #2b3a55;
  --ink-soft: #5a6b85;
  --line: #e2e8f2;
  --accent: #3a567f;
  --accent-soft: #e8eefb;
  --danger: #c0392b;
  --ok: #2e8b74;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}

.hidden { display: none !important; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.stage-badge {
  font-size: 13px; padding: 4px 10px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent);
}
.osc-badge {
  font-size: 13px; padding: 4px 10px; border-radius: 20px;
  background: #fdeceb; color: var(--danger); animation: pulse 1.2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.55} }
.tide-badge {
  font-size: 13px; padding: 4px 10px; border-radius: 20px; font-weight: 700;
  background: var(--danger); color: #fff; animation: tidePulse 1.0s infinite;
}
@keyframes tidePulse { 0%,100%{opacity:.82} 50%{opacity:1} }
.spacer { flex: 1; }

.btn {
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: #fff; color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 12px; margin: 3px 4px 3px 0; }
.export-row { display: flex; gap: 8px; margin-top: 8px; }
.export-row .btn { flex: 1; }
.btn.primary { background: var(--ok); border-color: var(--ok); }
.btn.active { outline: 2px solid #f0a500; outline-offset: 1px; }

/* Turnstile 人机验证 widget 容器 */
.cf-turnstile { margin-top: 8px; min-height: 4px; }

/* 布局 */
.layout { display: flex; gap: 14px; padding: 14px; align-items: stretch; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.stage-wrap { position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden; }
#field {
  display: block; width: 100%; max-width: 900px; aspect-ratio: 900/640;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 4px 18px rgba(40,60,90,.06); cursor: crosshair;
  touch-action: none; user-select: none; -webkit-user-select: none;
}

/* 撤销浮条：播种后 5s 内可撤销刚落下的符号 */
.undo-bar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 18px;
  display: flex; align-items: center; gap: 12px; z-index: 5;
  background: rgba(43,58,85,.95); color: #fff; padding: 8px 14px;
  border-radius: 999px; font-size: 13px; box-shadow: 0 6px 18px rgba(40,60,90,.22);
}
.undo-bar.hidden { display: none; }
.undo-bar .undo-count { opacity: .8; font-variant-numeric: tabular-nums; }
.undo-bar button {
  background: #fff; color: #2b3a55; border: none; border-radius: 999px;
  padding: 5px 14px; font-size: 13px; cursor: pointer;
}
.undo-bar button:disabled { opacity: .4; cursor: default; }

/* 二次确认弹窗（复用 .modal 基础样式） */
#confirmModal .modal-card { max-width: 360px; text-align: center; }
#confirmModal .modal-actions { justify-content: center; }
.heat-overlay { position: absolute; left: 0; top: 0; width: 100%; max-width: 900px; aspect-ratio: 900/640; pointer-events: none; border-radius: 12px; }

.event-toast {
  position: absolute; left: 16px; bottom: 16px; right: 16px;
  background: rgba(43,58,85,.92); color: #fff; padding: 10px 14px;
  border-radius: 10px; font-size: 13px; opacity: 0; transform: translateY(8px);
  transition: opacity .3s, transform .3s; pointer-events: none;
}
.event-toast.show { opacity: 1; transform: translateY(0); }
.tool-hint {
  position: absolute; left: 16px; top: 12px;
  background: rgba(255,255,255,.9); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 8px; font-size: 12px; color: var(--ink-soft);
}

/* 侧栏：固定宽度、独立滚动区，画布不再被 13 个面板顶出视口 */
.sidebar { flex: 0 0 320px; display: flex; flex-direction: column; gap: 12px; max-height: 100%; overflow-y: auto; padding-right: 4px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.panel h3 { margin: 0 0 10px; font-size: 14px; color: var(--ink); }

.gauge { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px; }
.gauge label { width: 84px; color: var(--ink-soft); }
.gauge .bar { flex: 1; height: 9px; background: #eef1f7; border-radius: 6px; overflow: hidden; }
.gauge .fill { display: block; height: 100%; width: 0; border-radius: 6px; transition: width .25s; }
.fill.entropy { background: #e08a3c; }
.fill.mip { background: #3a567f; }
.fill.health { background: var(--ok); }
.fill.order { background: #8a6fd6; }
.fill.tension { background: #3a86ff; transition: width .15s linear, background .3s linear; }
.gauge b { width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

/* 生态榜 */
.panel.leaderboard .lb-name { width: 100%; margin-bottom: 6px; }
.panel.leaderboard .lb-actions { display: flex; gap: 8px; margin: 4px 0 10px; }
.panel.leaderboard .lb-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.lb-row { display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 2px 8px; padding: 6px 9px; border-radius: 8px; background: var(--accent-soft); }
.lb-rank { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
.lb-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: var(--accent); font-variant-numeric: tabular-nums; }
.lb-sub { grid-column: 1 / -1; font-size: 11px; color: var(--ink-soft); }
.mip-line { display: flex; justify-content: space-between; align-items: center; font-size: 11px; margin: -2px 0 8px; padding-left: 92px; }
.mip-formula { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.mip-status { font-weight: 600; padding: 1px 8px; border-radius: 10px; }
.mip-status.ok { color: var(--ok); background: rgba(46,139,116,.12); }
.mip-status.over { color: var(--danger); background: rgba(192,57,43,.12); }
.kv { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-soft); padding: 3px 0; }
.kv b { color: var(--ink); }

.tools .tool-block { margin-bottom: 10px; }
.tool-title { font-size: 12px; color: var(--ink-soft); margin-bottom: 5px; }
.glyph-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.glyph-btn {
  width: 38px; height: 38px; font-size: 18px; border: 1px solid var(--line);
  background: #fff; border-radius: 8px; cursor: pointer; color: var(--ink);
}
.glyph-btn.active { border-color: var(--accent); background: var(--accent-soft); }
.muted { color: var(--ink-soft); font-size: 11px; display: block; margin-top: 3px; }
.btn.tool { width: 100%; background: #fff; color: var(--accent); border-color: var(--line); }
.btn.tool.locked { opacity: .45; cursor: not-allowed; filter: grayscale(.6); }
.glyph-btn:disabled { opacity: .4; cursor: not-allowed; }

.tree svg { display: block; width: 100%; }
.obs-slider { width: 100%; margin-top: 6px; }

/* 成就面板 */
.ach-list { display: flex; flex-direction: column; gap: 5px; min-height: 24px; }
.ach-item {
  font-size: 12px; padding: 5px 9px; border-radius: 8px;
  background: #f1f3f8; color: #aab2c2; border: 1px dashed var(--line);
}
.ach-item.on { background: #fff7e6; color: #a9721a; border: 1px solid #f0d79a; }

/* 隐性目标面板 */
.goal-list { display: flex; flex-direction: column; gap: 5px; min-height: 24px; }
.goal-item {
  font-size: 12px; padding: 5px 9px; border-radius: 8px;
  background: #f3eefb; color: #6b3fa0; border: 1px solid #d9c7ef;
  animation: goalIn .4s ease;
}
@keyframes goalIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* 诗意事件日志 */
.poem-log { display: flex; flex-direction: column; gap: 4px; max-height: 120px; overflow: hidden; }
.poem-log-row {
  font-size: 11.5px; line-height: 1.4; color: var(--ink-soft);
  padding: 4px 7px; border-radius: 7px; background: #f7f9fc;
  border-left: 2px solid var(--accent);
}

/* 横幅 / 弹窗 */
.banner {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 14px 18px; border-radius: 12px;
  max-width: 560px; display: flex; gap: 12px; align-items: center;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); z-index: 30;
}
.banner-text { font-size: 13px; line-height: 1.5; white-space: pre-line; }

.modal {
  position: fixed; inset: 0; background: rgba(30,40,60,.45);
  display: flex; align-items: center; justify-content: center; z-index: 40;
}
.modal-card {
  background: #fff; border-radius: 14px; padding: 24px; width: 420px; max-width: 90vw;
  max-height: 92vh; overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal-card h3 { margin: 0 0 8px; }
.seed-code {
  font-family: "SFMono-Regular", Consolas, monospace; font-size: 26px; letter-spacing: 4px;
  background: var(--accent-soft); color: var(--accent); padding: 14px; text-align: center;
  border-radius: 10px; margin: 14px 0; user-select: all;
}
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.seed-input {
  width: 100%; margin-top: 10px; padding: 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; letter-spacing: 2px; text-align: center;
}

/* 文明观察镜 · 历史回放抽屉 */
.replay-card { width: 460px; max-width: 92vw; }
.replay-bar { margin: 14px 0 6px; }
.replay-bar input[type="range"] { width: 100%; accent-color: var(--accent); }
.replay-meta { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; margin-bottom: 10px; }
.replay-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.replay-log-title { font-size: 12px; color: var(--ink-soft); margin: 6px 0 6px; font-weight: 600; }
.replay-log { max-height: 200px; overflow-y: auto; border-top: 1px solid var(--line); padding-top: 8px; }

/* 环境系数 K 滑块 */
.k-gauge { margin-top: 8px; }
.k-gauge label { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: var(--ink-soft); }
.k-gauge label b { color: var(--accent); font-size: 13px; }
.k-gauge input[type="range"] { width: 100%; margin-top: 6px; accent-color: var(--accent); }
.k-gauge .muted { display: block; margin-top: 2px; }

/* 种子弹窗：分享码行 */
.share-row { display: flex; gap: 8px; margin: 12px 0 2px; align-items: center; }
.share-row .seed-input { margin-top: 0; font-size: 11px; letter-spacing: 0; text-align: left; flex: 1; }

/* 种子弹窗：分享二维码 */
.qr-wrap { display: flex; flex-direction: column; align-items: center; margin: 14px 0 4px; }
.qr-canvas {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; max-width: 100%; height: auto; image-rendering: pixelated;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#btnDownloadQR { margin: 4px 0 2px; }
#seedQrNote { text-align: center; max-width: 320px; margin: 8px 0 0; }

/* 崩溃诗歌 · 独立弹窗（仪式感） */
.poem-card {
  width: 520px; max-width: 92vw; text-align: center;
  border: 1px solid var(--accent);
  background: linear-gradient(180deg, #fbfcff, #f1f5fc);
  animation: poemIn .5s ease;
}
@keyframes poemIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.poem-eyebrow { font-size: 12px; letter-spacing: 3px; color: var(--accent); opacity: .8; }
.poem-text {
  font-family: "Songti SC", "SimSun", "Noto Serif SC", serif; font-size: 17px; line-height: 2;
  white-space: pre-line; color: var(--ink); margin: 16px 4px 22px;
}
/* 终诗逐句浮现字幕动画 */
.poem-line { opacity: 0; animation: poemRise .7s ease forwards; }
.poem-line--gap { height: .55em; }
@keyframes poemRise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .poem-line { animation: none; opacity: 1; }
}
.poem-actions { justify-content: center; }
.poem-diag {
  font-size: 12px; line-height: 1.7; color: var(--ink-soft);
  background: rgba(58,86,127,.06); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; margin: 4px 4px 18px; text-align: left;
}
.poem-diag b { color: var(--ink); }
.poem-diag .warn { color: var(--danger); }

/* 文明编年史（元叙事层） */
.chron-list { display: flex; flex-direction: column; gap: 7px; max-height: 230px; overflow-y: auto; }
.chron-item {
  font-size: 12px; padding: 7px 10px; border-radius: 9px;
  background: linear-gradient(180deg, #f7f4ff, #f1ecfb);
  border: 1px solid #e4dcf5; border-left: 3px solid #6b3fa0;
  animation: chronIn .45s ease;
}
@keyframes chronIn { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }
.chron-title { font-weight: 700; color: #5a2f8f; margin-bottom: 2px; letter-spacing: .3px; }
.chron-verse { color: var(--ink-soft); line-height: 1.5; }
/* 嵌套子章：主章的隐晦注脚，缩进显示 */
.chron-subs { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.chron-sub {
  font-size: 11.5px; padding: 4px 8px; border-radius: 7px;
  background: rgba(107,63,160,.05); border-left: 2px solid rgba(107,63,160,.35);
  margin-left: 8px; animation: chronIn .4s ease;
}
.chron-sub .chron-title { font-weight: 600; color: #7a4fb0; font-size: 11.5px; }

/* 隐性目标：揭示诗句（机械 label 作小字副标题） */
.goal-verse { display: block; }
.goal-sub { font-size: 10.5px; color: #8a6fb0; margin-top: 3px; opacity: .85; }

/* 教学关聚光灯引导 */
.tutorial-modal { background: transparent; z-index: 100; }
.tut-spot {
  position: fixed; border-radius: 14px; pointer-events: none; z-index: 1;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(30,40,60,.5);
  transition: left .25s ease, top .25s ease, width .25s ease, height .25s ease;
}
.tut-arrow {
  position: fixed; transform: translateX(-50%); pointer-events: none; z-index: 1;
  background: var(--accent); color: #fff; font-size: 12px; padding: 4px 10px;
  border-radius: 8px; white-space: nowrap; box-shadow: 0 4px 14px rgba(40,60,90,.25);
  animation: arrowBounce 1.1s infinite;
}
@keyframes arrowBounce { 0%,100%{ transform: translateX(-50%) translateY(0); } 50%{ transform: translateX(-50%) translateY(-8px); } }
.tut-card { position: relative; z-index: 2; width: 460px; max-width: 92vw; }
.tut-eyebrow { font-size: 12px; letter-spacing: 3px; color: var(--accent); opacity: .8; margin-bottom: 10px; }
.tut-text { font-size: 14px; line-height: 1.7; white-space: pre-line; color: var(--ink); min-height: 104px; }
.tut-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 10px; }
.tut-step { font-size: 12px; color: var(--ink-soft); }
.tut-actions { flex: 1; justify-content: flex-end; }

/* 符号图鉴 */
.codex-list { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.codex-cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 18px; border: 1px solid var(--line); border-radius: 8px;
  background: #f7f9fc; color: var(--ink); position: relative;
}
.codex-cell.locked { color: #c4ccda; background: #fbfcfe; border-style: dashed; }
.codex-cell .cnt { position: absolute; right: 3px; bottom: 1px; font-size: 9px; color: var(--ink-soft); }
.codex-cell { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.codex-cell:hover:not(.locked) { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(40,60,90,.16); border-color: var(--accent); }
.codex-cell.locked { cursor: help; }

/* 图鉴按类别视觉区分：衍生符号以金色虚线 + 角标突出「复合重逢」，变异/奇变以描边色区分 */
.codex-cell.cat-derived {
  border-style: dashed; border-color: #e0a23a;
  background: linear-gradient(180deg, rgba(224,162,58,.12), rgba(224,162,58,.05));
}
.codex-cell.cat-derived.locked { color: #c4ccda; background: #fbfcfe; }
.codex-cell.cat-mutant { border-color: #b06ad8; }
.codex-cell.cat-exotic { border-color: #d88a2a; box-shadow: inset 0 0 0 1px rgba(216,138,42,.25); }
.codex-cell:hover:not(.locked).cat-derived { border-color: #e0a23a; box-shadow: 0 4px 12px rgba(224,162,58,.22); }
.codex-cell:hover:not(.locked).cat-mutant { border-color: #b06ad8; box-shadow: 0 4px 12px rgba(176,106,216,.22); }
.codex-cell:hover:not(.locked).cat-exotic { border-color: #d88a2a; box-shadow: 0 4px 12px rgba(216,138,42,.22); }
.ck-badge {
  position: absolute; left: 3px; top: 1px; font-size: 9px; line-height: 1;
  padding: 1px 3px; border-radius: 6px; color: #8a5e12;
  background: rgba(224,162,58,.18); border: 1px solid rgba(224,162,58,.4);
}
.codex-cell.locked .ck-badge { opacity: .45; }

/* 图鉴详情弹窗（点击符号格查看来历诗句） */
.codex-modal .codex-card { width: 360px; max-width: 92vw; text-align: center; }
.codex-glyph-big { font-size: 64px; line-height: 1; color: var(--accent); margin-bottom: 10px; }
.codex-meta { margin-bottom: 12px; }
.ck-name { font-size: 15px; font-weight: 700; color: var(--ink); }
.ck-tags { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
.ck-cat, .ck-rar, .ck-ach { font-size: 11px; padding: 2px 9px; border-radius: 10px; }
.ck-cat { background: var(--accent-soft); color: var(--accent); }
.ck-rar.rar-common { background: #eef1f7; color: #6b7a93; }
.ck-rar.rar-rare { background: #fdf0e4; color: #c07a1f; }
.ck-rar.rar-legend { background: #f3eafc; color: #7a3fb0; }
.ck-ach { background: #fff7e6; color: #a9721a; border: 1px solid #f0d79a; }
.ck-count { font-size: 12px; color: var(--ink-soft); }
.codex-lore {
  font-family: "Songti SC", "SimSun", "Noto Serif SC", serif; font-size: 15px; line-height: 1.9;
  white-space: pre-line; color: var(--ink);
  background: rgba(58,86,127,.05); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 14px;
}
.codex-actions { justify-content: center; }
/* 图鉴详情：变异/奇变「如何诞生」玩法说明块 */
.ck-born {
  margin-top: 10px; padding: 10px 12px; font-size: 12px; line-height: 1.7;
  color: var(--ink-soft); background: rgba(58,86,127,.05);
  border: 1px dashed var(--line); border-radius: 10px; text-align: left;
}

/* 生态复盘 */
.recap-body { display: flex; flex-direction: column; gap: 3px; }
.recap-block {
  margin: 12px 0; padding: 12px 14px; background: rgba(58,86,127,.05);
  border: 1px solid var(--line); border-radius: 10px;
}
.recap-block h4 { margin: 0 0 8px; font-size: 13px; color: var(--ink); }
.recap-block .kv { font-size: 12px; }
.recap-spark { width: 100%; height: 46px; display: block; margin-top: 8px; }

/* 响应式：窄屏（如笔记本竖屏 / 平板 / 手机）改为纵向堆叠，整页滚动，画布自适应收窄 */
@media (max-width: 880px) {
  body { overflow: hidden; }
  .layout { flex-direction: column; align-items: stretch; overflow-y: auto; }
  .stage-wrap { width: 100%; flex: 0 0 auto; }
  .sidebar { width: 100%; flex: 0 0 auto; max-height: none; overflow: visible; padding-right: 0; }
}

/* 扫码复现弹窗 */
.scan-card { width: 380px; max-width: 92vw; text-align: center; }
.scan-video {
  display: block; width: 100%; max-width: 320px; margin: 10px auto;
  aspect-ratio: 4 / 3; background: #0e1320; border-radius: 10px; object-fit: cover;
}
.scan-status { font-size: 13px; color: var(--ink); margin: 6px 0; min-height: 18px; }
#scanHint { margin-top: 6px; }
