/* ============================================================
   内容页样式：页头区、筛选栏、图鉴网格、文档排版、表格
   仅在 index.html 之外的页面引入。
   ============================================================ */

/* ── 页面头部 ── */
.page-head {
  padding-block: clamp(36px, 6vw, 64px) clamp(22px, 3vw, 34px);
  border-bottom: 1px solid var(--rule);
}
.page-head h1 { font-size: var(--step-4); margin-top: 10px; }
.page-head .lede { margin-top: 14px; }

/* ── 工具栏（搜索 + 筛选） ── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  padding-block: 18px;
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 57px;
  z-index: 10;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
}

.search {
  flex: 1 1 220px;
  min-width: 0;
  max-width: 340px;
  font-family: var(--body);
  font-size: 14.5px;
  font-weight: 300;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 9px 12px;
}
.search::placeholder { color: var(--ink-3); }

.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--body);
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--rule-2);
  border-radius: 100px;
  padding: 6px 13px;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.chip:hover { background: var(--paper-3); color: var(--ink); }
.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.count {
  margin-inline-start: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .06em;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── 空状态 ── */
.empty {
  padding: 60px 0 72px;
  text-align: center;
  color: var(--ink-3);
}
.empty p { font-size: 15px; }
.empty .empty-hint { margin-top: 8px; font-family: var(--mono); font-size: 12px; }

/* ── 成就网格 ── */
.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  margin-block: 26px 0;
}
.ach {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  background: var(--paper);
  padding: 15px 16px;
}
.ach-icon {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  image-rendering: auto;
  border-radius: var(--radius);
  background: var(--paper-3);
}
.ach-body { min-width: 0; }
.ach-name {
  font-family: var(--display);
  font-weight: 600;
  font-size: 15.5px;
  line-height: 1.3;
}
.ach-desc {
  margin-top: 4px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-2);
}
.ach-api {
  margin-top: 7px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .04em;
  color: var(--ink-3);
  word-break: break-all;
}

/* ── 分组标题 ── */
.group-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-top: 44px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent);
}
.group-head h2 { font-size: var(--step-2); }
.group-head .group-n {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* ── 图鉴：食物与昆虫卡片 ── */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: var(--gap);
  margin-top: 26px;
}
.card {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-head { display: flex; gap: 13px; align-items: center; }
.card-icon {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  object-fit: contain;
}
.card-icon-blank {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border: 1px dashed var(--rule-2);
  border-radius: var(--radius);
}
.card-title { min-width: 0; flex: 1 1 auto; }
.card-title h3 { font-size: var(--step-1); line-height: 1.25; }
.card-title .card-en {
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--ink-3);
}

/* 数据行：等宽数字对齐 */
.spec { display: grid; gap: 0; }
.spec-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 13.5px;
  border-top: 1px solid var(--rule);
}
.spec-row:first-child { border-top: 0; }
.spec-row dt { color: var(--ink-3); }
.spec-row dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-align: end;
}

/* 营养配比条：把三种营养的相对比例画出来 */
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 52px 1fr 42px; gap: 9px; align-items: center; }
.bar-row .bar-label { font-size: 12px; color: var(--ink-3); }
.bar-track { height: 7px; background: var(--paper-3); border-radius: 100px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 100px; }

/* 宽度用离散类而非内联 style —— 严格 CSP 会拦截 style 属性的写入
   （包括 element.style 赋值），所以宽度必须来自样式表。
   5% 一档对「偏糖还是偏蛋白」的判读足够精确。 */
.w-0 { width: 0; }
/* 微量：占比不到 2.5% 会被量化成 0，但值本身非零（如肉干的糖 25/1485）。
   给一条最小可见的细缝，别让真实数据看起来像「没有」。 */
.w-trace { width: 3px; }
.w-5 { width: 5%; }   .w-10 { width: 10%; }  .w-15 { width: 15%; }
.w-20 { width: 20%; } .w-25 { width: 25%; }  .w-30 { width: 30%; }
.w-35 { width: 35%; } .w-40 { width: 40%; }  .w-45 { width: 45%; }
.w-50 { width: 50%; } .w-55 { width: 55%; }  .w-60 { width: 60%; }
.w-65 { width: 65%; } .w-70 { width: 70%; }  .w-75 { width: 75%; }
.w-80 { width: 80%; } .w-85 { width: 85%; }  .w-90 { width: 90%; }
.w-95 { width: 95%; } .w-100 { width: 100%; }
.bar-starch { background: var(--accent); }
.bar-sugar { background: var(--gold); }
.bar-protein { background: var(--combat); }
.bar-row .bar-val {
  font-family: var(--mono);
  font-size: 11.5px;
  text-align: end;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

/* 吸引关系：食物 -> 昆虫 */
.attract-head { margin-bottom: 6px; }
.attract { display: flex; flex-wrap: wrap; gap: 5px; }
.attract-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--ink-2);
  background: var(--paper-3);
  border-radius: 100px;
  padding: 3px 9px 3px 4px;
}
.attract-item img { width: 17px; height: 17px; object-fit: contain; }
.attract-none { font-size: 12.5px; color: var(--ink-3); font-style: italic; }

/* ── 文档页：侧边目录 + 正文 ── */
.doc-layout {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  gap: clamp(28px, 4vw, 56px);
  align-items: start;
  padding-block: clamp(28px, 4vw, 48px);
}
.toc { position: sticky; top: 80px; }
.toc h2 {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.toc ol { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 2px; }
.toc a {
  display: block;
  font-size: 13.5px;
  color: var(--ink-2);
  text-decoration: none;
  padding: 5px 9px;
  border-inline-start: 2px solid var(--rule);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.toc a:hover { background: var(--paper-3); color: var(--ink); border-inline-start-color: var(--accent); }
.toc a.is-active {
  color: var(--ink);
  background: var(--paper-3);
  border-inline-start-color: var(--brand);
  font-weight: 500;
}

.doc { max-width: 74ch; }
.doc section + section { margin-top: 52px; }
.doc h2 {
  font-size: var(--step-3);
  scroll-margin-top: 84px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}
.doc h3 { font-size: var(--step-1); margin-top: 32px; scroll-margin-top: 84px; }
.doc p { margin-top: 13px; color: var(--ink-2); }
.doc ul, .doc ol { margin-top: 13px; padding-inline-start: 1.35em; color: var(--ink-2); }
.doc li + li { margin-top: 6px; }
.doc strong { color: var(--ink); font-weight: 500; }
.doc code {
  background: var(--paper-3);
  border-radius: 3px;
  padding: 1.5px 5px;
  color: var(--ink);
  font-size: .88em;
  /* 正文里的 res:// 路径和 CSV 表头是长串无空格文本，窄屏放不下会顶破页面
     （320px 视口实测溢出 32px）。允许在任意字符处断行。 */
  overflow-wrap: anywhere;
}

/* 代码块：横向滚动收在自己容器里 */
.code {
  margin-top: 16px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow-x: auto;
}
.code pre { margin: 0; padding: 15px 17px; }
.code code {
  background: none;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--ink);
  white-space: pre;
}
.code-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 8px 17px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-3);
}

/* 表格：宽内容自己滚 */
.table-wrap {
  margin-top: 18px;
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
thead th {
  text-align: start;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--paper-3);
  padding: 9px 13px;
  white-space: nowrap;
}
tbody td {
  padding: 10px 13px;
  border-top: 1px solid var(--rule);
  color: var(--ink-2);
  vertical-align: top;
}
tbody td code { white-space: nowrap; }
tbody tr:hover { background: var(--paper-2); }

/* 提示框：用左边框区分，不用 emoji */
.note {
  margin-top: 18px;
  padding: 14px 17px;
  background: var(--paper-2);
  border-inline-start: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.note p { margin-top: 0; font-size: 14px; }
.note p + p { margin-top: 9px; }
.note-warn { border-inline-start-color: var(--combat); }
.note-title {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}

@media (max-width: 860px) {
  /* minmax(0, 1fr) 而不是 1fr：网格项默认 min-width: auto，
     目录变成横向滚动条后会把整列撑到内容宽度（实测 375px 视口溢出 640px），
     必须允许列收缩到 0 才能让 overflow-x 真的生效。 */
  .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .toc {
    position: static;
    min-width: 0;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 18px;
  }
  .toc ol {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    margin-inline: calc(var(--pad) * -1);
    padding-inline: var(--pad);
    scrollbar-width: none;
  }
  .toc ol::-webkit-scrollbar { display: none; }
  .toc a { border-inline-start: 0; border-bottom: 2px solid var(--rule); white-space: nowrap; }
  .toc a.is-active { border-inline-start: 0; border-bottom-color: var(--brand); }
}

@media (max-width: 720px) {
  .toolbar { top: 0; position: static; }
}
