/* ===== 全局基础 ===== */
:root {
  --bg: #0d1117;
  --bg-soft: #161b27;
  --bg-card: #1a2233;
  --border: #2a3550;
  --text: #e6ebf5;
  --text-dim: #93a1bd;
  --accent: #6c8cff;
  --accent-2: #a06cff;
  --accent-3: #4cd9c0;
  --warm: #ffb454;
  --danger: #ff6c7a;
  --grad: linear-gradient(135deg, #6c8cff, #a06cff);
  --radius: 14px;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  line-height: 1.7;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== 首页 Hero ===== */
.hero {
  text-align: center;
  padding: 72px 24px 48px;
  background:
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(108, 140, 255, 0.22), transparent),
    radial-gradient(ellipse 40% 40% at 80% 0%, rgba(160, 108, 255, 0.15), transparent);
}
.hero h1 {
  font-size: 42px;
  letter-spacing: 2px;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 14px;
}
.hero p { color: var(--text-dim); font-size: 17px; max-width: 640px; margin: 0 auto; }
.hero .badges { margin-top: 20px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.hero .badges span {
  font-size: 13px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 14px; background: rgba(26, 34, 51, 0.6);
}

/* ===== 分类与卡片 ===== */
.container { max-width: 1180px; margin: 0 auto; padding: 0 24px 80px; }

.category { margin-top: 56px; }
.category-header { display: flex; align-items: baseline; gap: 14px; margin-bottom: 8px; }
.category-header h2 { font-size: 26px; }
.category-header .en { color: var(--text-dim); font-size: 14px; letter-spacing: 1px; }
.category-desc { color: var(--text-dim); font-size: 14.5px; margin-bottom: 22px; }
.category-header .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--grad); align-self: center;
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }

.card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  color: var(--text);
  position: relative;
  overflow: hidden;
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 10px 30px rgba(108, 140, 255, 0.18);
  text-decoration: none;
}
.card .icon {
  width: 44px; height: 44px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: #fff;
  background: var(--grad);
  margin-bottom: 14px;
}
.card h3 { font-size: 18px; margin-bottom: 6px; }
.card .card-en { font-size: 12.5px; color: var(--text-dim); letter-spacing: 0.5px; display: block; margin-bottom: 10px; }
.card p { font-size: 14px; color: var(--text-dim); line-height: 1.65; }
.card .tags { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.card .tags span {
  font-size: 12px; color: var(--accent-3);
  background: rgba(76, 217, 192, 0.08);
  border: 1px solid rgba(76, 217, 192, 0.25);
  padding: 2px 10px; border-radius: 999px;
}

footer.site-footer {
  text-align: center; color: var(--text-dim); font-size: 13px;
  padding: 40px 0; border-top: 1px solid var(--border);
}

/* ===== 主题页 ===== */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.9);
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(8px);
}
.topbar .back {
  font-size: 14px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 12px; white-space: nowrap;
}
.topbar .back:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.topbar h1 { font-size: 19px; }
.topbar .cat-tag {
  font-size: 12px; color: var(--accent-3);
  border: 1px solid rgba(76, 217, 192, 0.35); border-radius: 999px;
  padding: 2px 12px; white-space: nowrap;
}
.topbar .en-sub { color: var(--text-dim); font-size: 13px; }

.topic-layout {
  max-width: 1180px; margin: 0 auto;
  padding: 26px 24px 60px;
  display: grid; grid-template-columns: 1fr 330px; gap: 22px;
  align-items: start;
}
@media (max-width: 940px) {
  .topic-layout { grid-template-columns: 1fr; }
  .panel { position: static; }
}

.stage-wrap {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
#stage {
  min-height: 440px;
  padding: 24px;
  display: flex; align-items: center; justify-content: center;
}
#stage svg { max-width: 100%; height: auto; display: block; }

/* 控制条 */
.controls {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.controls button, .controls select {
  background: #232d45; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 14px; font-size: 13.5px; cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.controls button:hover:not(:disabled) { background: #2c3a5a; border-color: var(--accent); }
.controls button:disabled { opacity: 0.4; cursor: not-allowed; }
.controls #btn-play { background: var(--grad); border: none; min-width: 86px; font-weight: 600; }
.controls #btn-play:hover { filter: brightness(1.12); background: var(--grad); }
.controls select { padding: 6px 8px; }

.progress {
  flex: 1; min-width: 120px; height: 6px;
  background: #232d45; border-radius: 999px; overflow: hidden;
}
#progress-bar {
  height: 100%; width: 0%;
  background: var(--grad); border-radius: 999px;
  transition: width 0.3s ease;
}
#step-indicator { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* 解说面板 */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  position: sticky; top: 82px;
}
.panel h2 { font-size: 17px; margin-bottom: 10px; color: var(--accent); }
.panel #step-desc { font-size: 14.5px; color: var(--text); line-height: 1.8; min-height: 120px; }
.panel #step-desc code {
  background: #232d45; padding: 1px 7px; border-radius: 5px;
  font-size: 13px; color: var(--warm);
}
.glossary { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 16px; }
.glossary h3 { font-size: 14px; color: var(--text-dim); margin-bottom: 10px; }
.glossary dl { font-size: 13.5px; }
.glossary dt { color: var(--accent-3); font-weight: 600; margin-top: 10px; }
.glossary dt .en { color: var(--text-dim); font-weight: 400; font-size: 12px; margin-left: 6px; }
.glossary dd { color: var(--text-dim); margin-top: 2px; line-height: 1.65; }

/* ===== 主题页底部：上一篇 / 下一篇 导航 ===== */
.topic-nav {
  max-width: 1180px; margin: 0 auto; padding: 0 24px 50px;
  display: flex; justify-content: space-between; gap: 16px;
}
.topic-nav a {
  flex: 1; max-width: 48%;
  display: block; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 20px; color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
}
.topic-nav a:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.topic-nav .dir { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 4px; }
.topic-nav .name { font-size: 15px; color: var(--accent); }
.topic-nav .next { text-align: right; margin-left: auto; }
.topic-nav .placeholder { visibility: hidden; }

/* ===== 舞台内通用动画 ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes popIn {
  0% { opacity: 0; transform: scale(0.6); }
  70% { transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@keyframes dashFlow {
  to { stroke-dashoffset: -20; }
}

.anim-in { animation: fadeUp 0.45s ease both; }
.anim-fade { animation: fadeIn 0.5s ease both; }
.anim-pop { animation: popIn 0.4s ease both; }
.anim-pulse { animation: pulse 1.2s ease-in-out infinite; }

/* SVG 通用元素：类只提供默认值，元素自身的 fill / font-size 属性优先 */
.svg-label, .svg-label-dim, .svg-label-small { font-family: inherit; }
.svg-label:not([fill]) { fill: var(--text); }
.svg-label:not([font-size]) { font-size: 13px; }
.svg-label-dim:not([fill]) { fill: var(--text-dim); }
.svg-label-dim:not([font-size]) { font-size: 12px; }
.svg-label-small:not([fill]) { fill: var(--text-dim); }
.svg-label-small:not([font-size]) { font-size: 10.5px; }
.flow-line {
  stroke: var(--accent); stroke-width: 2; fill: none;
  stroke-dasharray: 6 5; animation: dashFlow 0.8s linear infinite;
}

/* ===== 移动端适配（≤640px） ===== */
@media (max-width: 640px) {
  /* 首页 */
  .hero { padding: 48px 16px 32px; }
  .hero h1 { font-size: 29px; letter-spacing: 1px; }
  .hero p { font-size: 15px; }
  .hero .badges { gap: 8px; margin-top: 16px; }
  .container { padding: 0 14px 60px; }
  .category { margin-top: 40px; }
  .category-header h2 { font-size: 21px; }
  .cards { grid-template-columns: 1fr; }
  .card { padding: 18px; }

  /* 主题页顶栏：隐藏英文副题，标题超长时省略 */
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .en-sub { display: none; }
  .topbar .cat-tag { margin-left: auto; }
  .topbar .back { padding: 4px 9px; font-size: 13px; }

  .topic-layout { padding: 16px 12px 40px; gap: 16px; }

  /* 舞台：SVG 保持原始尺寸，横向滑动查看（缩放会小到看不清） */
  #stage {
    min-height: 300px;
    padding: 14px;
    overflow-x: auto;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }
  #stage svg { max-width: none; flex-shrink: 0; margin: 0 auto; }

  /* 控制条更紧凑 */
  .controls { padding: 10px 12px; gap: 8px; }
  .controls button, .controls select { padding: 6px 10px; font-size: 12.5px; }
  .controls #btn-play { min-width: 72px; }
  .progress { min-width: 90px; }

  /* 解说面板 */
  .panel { padding: 16px; }
  .panel #step-desc { min-height: 0; }

  /* 底部上一篇/下一篇：纵向排列 */
  .topic-nav { flex-direction: column; padding: 0 12px 40px; gap: 10px; }
  .topic-nav a { max-width: 100%; padding: 12px 16px; }
  .topic-nav .next { text-align: left; }
  .topic-nav .placeholder { display: none; }
}
