:root {
  /* diagonal 设计系统 */
  --paper: #FAFAF8;          /* 暖纸 */
  --ink: #1A1A1A;            /* 墨 */
  --ink-500: #57534E;        /* 次级文字 */
  --muted: #8A847B;          /* 弱化文字 */
  --red: #B33A2A;            /* 品牌红 */
  --red-soft: rgba(179, 58, 42, 0.10);
  --line: rgba(26, 26, 26, 0.12);   /* 发丝黑边 */
  --line-strong: rgba(26, 26, 26, 0.22);
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #FFFFFF;
  --bg: #FAFAF8;
  --text: var(--ink);
  --accent: var(--red);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#scene-root { position: fixed; inset: 0; z-index: 1; }
#scene-root canvas { display: block; }

/* 等宽眉标（对齐 diagonal 的 archive-text） */
.eyebrow {
  font-family: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 10px;
  color: var(--muted);
}

/* ---------------- 顶部栏（对齐 vacuum-salt NavBar） ---------------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  pointer-events: none;
}
#topbar .bar-inner {
  pointer-events: auto;
  background: rgba(255,255,255,0.8);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
#topbar .bar-row {
  max-width: 80rem; margin: 0 auto;
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand {
  display: flex; align-items: baseline; gap: 8px; min-width: 0;
  text-decoration: none; cursor: pointer;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.brand-word {
  font-weight: 700; font-size: 14px; letter-spacing: -0.02em;
  text-transform: uppercase; color: var(--ink);
  transition: color 0.18s ease;
}
.brand:hover .brand-word { color: var(--red); }
.brand-sub {
  font-size: 9px; color: var(--muted); line-height: 1;
  letter-spacing: 0.1em; text-transform: uppercase;
}
@media (max-width: 640px) { .brand-sub { display: none; } }

.legend { display: flex; gap: 14px; flex-wrap: wrap; }
.legend span {
  display: flex; align-items: center; gap: 6px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px; color: var(--ink-500); letter-spacing: 0.04em;
}
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 1px var(--line); }

/* 顶栏右侧控件组（仿 vacuum-salt：总览 / ⓘ / 中英药丸） */
.bar-right { display: flex; align-items: center; gap: 18px; }
.top-ctrls { display: flex; align-items: center; gap: 14px; }
.btn-top {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-500); background: none; border: none; cursor: pointer;
  padding: 0; transition: color 0.18s ease;
}
.btn-top:hover { color: var(--red); }
.btn-info { font-size: 13px; line-height: 1; }

/* 中英双语药丸开关 */
.lang-pill {
  display: flex; align-items: center; gap: 7px;
  background: none; border: none; cursor: pointer; padding: 0;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.lang-track {
  position: relative; width: 30px; height: 16px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: rgba(26,26,26,0.05);
  display: flex; align-items: center; padding: 0 2px;
}
.lang-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--red); transition: margin 0.22s ease;
}
.lang-pill[data-lang="en"] .lang-dot { margin-left: auto; }
.lang-pill .ct {
  font-size: 11px; font-weight: 700; color: var(--ink-500);
  min-width: 1.5rem; text-align: left; letter-spacing: 0.04em;
  transition: color 0.18s ease;
}
.lang-pill:hover .ct { color: var(--red); }

/* ---------------- 左侧导航 ---------------- */
#sidebar {
  position: fixed; top: 84px; left: 18px; z-index: 10;
  width: 232px;
  max-height: calc(100vh - 110px); overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 30px rgba(26,26,26,0.06);
}
.side-title {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10px; color: var(--muted); letter-spacing: 0.22em;
  text-transform: uppercase;
  margin-bottom: 10px; padding-left: 4px; font-weight: 600;
}
#nav-list { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  background: rgba(26,26,26,0.02);
  border: 1px solid transparent;
  color: var(--text); cursor: pointer; text-align: left;
  font-family: inherit; font-size: 14px;
  transition: all 0.18s ease;
}
.nav-item:hover { background: rgba(179,58,42,0.06); border-color: var(--line); }
.nav-item.active {
  background: var(--red-soft);
  border-color: rgba(179,58,42,0.45);
}
.nav-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px var(--line); }
.nav-idx { font-family: "JetBrains Mono", monospace; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-name { font-weight: 600; }
.side-tip {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted); line-height: 1.6;
}

/* ---------------- 右侧详情（可折叠抽屉：默认仅显示头部，点击展开） ---------------- */
#infopanel {
  position: fixed; top: 84px; right: 18px; z-index: 10;
  width: 320px; max-height: calc(100vh - 170px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 30px rgba(26,26,26,0.06);
  opacity: 0; transform: translateX(20px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
  display: flex; flex-direction: column;
  overflow: hidden; /* 折叠时由 .ip-body 高度控制 */
}
#infopanel.show { opacity: 1; transform: translateX(0); pointer-events: auto; }

/* 头部：横向排布，点击 / 键盘 / 拖拽皆可触发折叠 */
.ip-head {
  display: flex; gap: 12px; align-items: flex-start;
  flex: none; /* 头部固定高度，滚动交给 .ip-body */
  cursor: pointer;
  user-select: none; -webkit-user-select: none;
  touch-action: none; /* 头部只做拖拽/点击，不让浏览器横插滚动 */
  outline: none;
  padding: 4px 0;
  border-radius: 8px;
  transition: background 0.16s ease;
}
.ip-head:hover { background: rgba(26,26,26,0.03); }
.ip-head:focus-visible { background: rgba(179,58,42,0.06); box-shadow: 0 0 0 2px rgba(179,58,42,0.35); }
.ip-head-text { flex: 1; min-width: 0; }
.ip-color { width: 4px; align-self: stretch; border-radius: 4px; min-height: 46px; background: var(--red); flex: none; }
.ip-index {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px; color: var(--muted); letter-spacing: 0.22em; text-transform: uppercase;
}
.ip-head h2 { font-size: 20px; font-weight: 700; margin: 2px 0; font-family: "Newsreader","Noto Serif SC",serif; }
.ip-sub { font-family: "JetBrains Mono", monospace; font-size: 11px; color: var(--red); letter-spacing: 0.06em; }
.ip-sub:empty { display: none; }

/* 折叠 / 展开按钮：胶囊 + 雪佛龙 */
.ip-toggle {
  flex: none;
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 5px 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(26,26,26,0.03);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10px; letter-spacing: 0.1em;
  color: var(--ink-500);
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.ip-toggle:hover { color: var(--red); border-color: rgba(179,58,42,0.4); background: var(--red-soft); }
.ip-toggle-hint { display: inline-block; }
.ip-chevron { transition: transform 0.32s var(--ease-out); }
#infopanel.expanded .ip-toggle { color: var(--red); border-color: rgba(179,58,42,0.45); background: var(--red-soft); }
#infopanel.expanded .ip-chevron { transform: rotate(180deg); }
#infopanel.expanded .ip-toggle-hint { display: none; }

/* 抽屉主体：默认折叠（max-height 0），展开时放量并可上下滚动 */
.ip-body {
  flex: 1 1 auto;   /* 占据头部之外的剩余空间 */
  min-height: 0;    /* 关键：允许在 flex 容器内收缩并出现内部滚动 */
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin-top: 0;
  transition:
    max-height 0.42s var(--ease-out),
    opacity 0.28s ease,
    margin-top 0.42s var(--ease-out);
  -webkit-overflow-scrolling: touch;
}
#infopanel.expanded {
  overflow: hidden; /* 面板只做圆角裁切；滚动交给 .ip-body */
}
#infopanel.expanded .ip-body {
  max-height: 1800px; /* 足够大；面板 max-height 接管总高，.ip-body 内部滚动 */
  opacity: 1;
  margin-top: 6px;
  overflow-y: auto;   /* 展开后内容可上下滚动（手机端完整查看构件导览） */
}

/* 拖拽中的过渡：跟随手指，没有动效 */
#infopanel.dragging { transition: none; }
#infopanel.dragging .ip-body { transition: none; }
#infopanel.dragging .ip-chevron { transition: none; }

.ip-block { margin-bottom: 14px; }
.ip-block h3 {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px; color: var(--muted); letter-spacing: 0.18em; text-transform: uppercase;
  margin-bottom: 6px; font-weight: 600;
  display: flex; align-items: center; gap: 7px;
}
.ip-block h3::before { content: ""; width: 3px; height: 12px; background: var(--red); border-radius: 2px; }
.ip-block p { font-size: 13px; line-height: 1.7; color: var(--ink-500); }

.ip-reaction { display: flex; flex-direction: column; gap: 6px; }
.ip-reaction code {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px; color: var(--ink);
  background: var(--red-soft);
  border: 1px solid rgba(179,58,42,0.25);
  padding: 6px 9px; border-radius: 8px;
}
.ip-equip { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ip-equip li {
  font-size: 12px; color: var(--ink-500);
  padding: 6px 9px; background: rgba(26,26,26,0.03);
  border-radius: 8px; border: 1px solid var(--line);
}
.ip-params { display: flex; flex-wrap: wrap; gap: 6px; }
.ip-params span {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px; color: var(--red);
  padding: 4px 9px; border-radius: 20px;
  background: var(--red-soft); border: 1px solid rgba(179,58,42,0.3);
}
.ip-out { margin-bottom: 0; }
.ip-output {
  font-size: 14px; font-weight: 700; color: var(--ink);
  padding: 10px 12px; border-radius: 10px;
  background: rgba(26,26,26,0.04);
  border: 1px solid var(--line-strong);
}

/* ---------------- 开场遮罩 ---------------- */
#intro {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(250,250,248,0.9), rgba(245,243,238,0.97));
  backdrop-filter: blur(4px);
  transition: opacity 0.5s ease;
}
#intro.hidden { opacity: 0; pointer-events: none; }
.intro-card {
  width: min(520px, 86vw); text-align: center;
  padding: 38px 34px; border-radius: 22px;
  background: var(--panel-solid); border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(26,26,26,0.12);
}
.intro-mark {
  position: relative; overflow: hidden;
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 16px;
  display: grid; place-items: center; font-size: 32px; font-weight: 800; color: var(--ink);
  background:
    linear-gradient(125deg, transparent 44%, rgba(179,58,42,0.92) 47%, rgba(179,58,42,0.92) 51%, transparent 54%),
    #FFFFFF;
  border: 1px solid var(--line-strong);
  box-shadow: 0 8px 24px rgba(26,26,26,0.1);
}
.intro-card h2 {
  font-size: 23px; margin-bottom: 14px; letter-spacing: 0.5px;
  font-family: "Newsreader","Noto Serif SC",serif;
}
.intro-card p { font-size: 14px; line-height: 1.8; color: var(--ink-500); }
.intro-sub { margin-top: 12px; color: var(--muted); font-size: 13px; }
#intro-enter {
  margin-top: 22px; padding: 12px 30px; border: none; border-radius: 12px;
  font-family: inherit; font-size: 15px; font-weight: 700; color: #fff; cursor: pointer;
  background: var(--red);
  box-shadow: 0 8px 24px rgba(179,58,42,0.3); transition: transform 0.15s ease, background 0.15s ease;
}
#intro-enter:hover { transform: translateY(-2px); background: #9c3122; }

/* 滚动条（展开后 .ip-body 内部滚动） */
#infopanel.expanded .ip-body::-webkit-scrollbar { width: 6px; }
#infopanel.expanded .ip-body::-webkit-scrollbar-thumb { background: rgba(26,26,26,0.25); border-radius: 3px; }

/* ---------------- 响应式：竖屏 / 手机端 ----------------
   窄屏下把左侧「构件导览」挪到底部，变为始终可见的横向滚动导航条，
   避免桌面横屏才有、竖屏/手机端消失的问题；详情面板改为底部抽屉。
   顶栏的「总览 / ⓘ / 中英切换」保持可达。 */
@media (max-width: 860px) {
  .legend { display: none; }
  .bar-right { gap: 12px; }

  /* 左侧导航 → 底部横向导览条（常驻、可横滑） */
  #sidebar {
    top: auto; bottom: 0; left: 0; right: 0;
    width: auto; max-height: none;
    display: flex; flex-direction: row; align-items: center; gap: 8px;
    padding: 8px 12px;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    box-shadow: 0 -8px 30px rgba(26, 26, 26, 0.10);
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #sidebar::-webkit-scrollbar { display: none; }
  .side-title, .side-tip { display: none; }
  #nav-list { flex-direction: row; gap: 8px; flex: none; }
  .nav-item {
    flex: none; white-space: nowrap;
    padding: 8px 12px; font-size: 13px;
  }

  /* 详情面板 → 底部抽屉（浮在导览条之上，可上下滚动） */
  #infopanel {
    top: auto; bottom: 70px; left: 12px; right: 12px;
    width: auto; max-height: calc(64vh - 32px);
    border-radius: 16px 16px 0 0;
    padding: 12px 14px;
    transform: translateY(20px);
  }
  #infopanel.show { transform: translateY(0); }
  #infopanel.expanded .ip-body { max-height: 1600px; }
}

@media (max-width: 480px) {
  .bar-row { padding: 10px 14px; }
  .top-ctrls { gap: 10px; }
  .btn-top { font-size: 12px; }
  .lang-pill .ct { min-width: 1.2rem; }
  .nav-item { padding: 7px 10px; font-size: 12px; }
  #infopanel { max-height: calc(72vh - 32px); }
  #infopanel.expanded .ip-body { max-height: 1600px; }
}
