/* 静态函数内页与目录页；复用 styles.css 中的设计变量。 */
.pg-body { background-attachment: fixed; }
.pg-body a { color: inherit; text-decoration: none; }
.pg-header { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: rgba(244, 241, 233, .92); backdrop-filter: blur(14px); }
.pg-header__inner { max-width: 1240px; height: 72px; margin: 0 auto; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.pg-brand { display: flex; align-items: center; gap: 11px; }
.pg-brand__mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: var(--rail); color: #d8ece0; font: 600 17px var(--font-mono); }
.pg-brand strong { display: block; color: var(--brand); font: 600 17px var(--font-display); letter-spacing: .04em; }
.pg-brand small { display: block; margin-top: 1px; color: var(--ink-3); font: 9px var(--font-mono); letter-spacing: .1em; }
.pg-topnav { display: flex; align-items: center; gap: 6px; }
.pg-topnav a { padding: 8px 13px; border-radius: 8px; color: var(--ink-2); font-size: 13px; }
.pg-topnav a:hover, .pg-topnav a[aria-current="page"] { color: var(--brand); background: var(--brand-tint); }
.pg-layout { max-width: 1240px; margin: 0 auto; padding: 26px 28px 72px; display: grid; grid-template-columns: minmax(0, 1fr) 238px; gap: 28px; align-items: start; }
.pg-main { min-width: 0; }
.function-article { overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--sh-sm); }
.function-hero { position: relative; padding: 38px 42px 34px; border-bottom: 1px solid var(--line); background: linear-gradient(135deg, rgba(230, 240, 233, .8), rgba(255, 253, 248, .3) 60%); }
.function-hero::after { content: "fx"; position: absolute; right: 34px; top: 24px; color: rgba(15, 81, 56, .06); font: 700 104px var(--font-display); pointer-events: none; }
.function-hero__meta { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.function-hero__meta a, .function-hero__meta span { padding: 3px 9px; border: 1px solid rgba(15, 81, 56, .14); border-radius: 999px; background: rgba(255, 255, 255, .55); color: var(--brand); font-size: 11px; }
.function-hero h1 { position: relative; z-index: 1; max-width: 760px; font: 600 clamp(28px, 4vw, 42px)/1.3 var(--font-display); letter-spacing: .02em; overflow-wrap: anywhere; }
.function-hero__cn { position: relative; z-index: 1; margin-top: 8px; color: var(--brand); font-size: 17px; font-weight: 600; }
.function-hero__desc { position: relative; z-index: 1; max-width: 720px; margin-top: 14px; color: var(--ink-2); font-size: 15px; line-height: 1.9; }
.article-section { padding: 30px 42px; border-bottom: 1px solid var(--line); }
.article-section h2 { margin-bottom: 18px; color: var(--ink); font: 600 21px var(--font-display); letter-spacing: .03em; }
.article-section > p { color: var(--ink-2); line-height: 1.9; }
.formula { margin: 0; padding: 19px 22px; overflow-x: auto; border-radius: 10px; background: var(--rail); color: #e0f1e6; font: 13px/1.8 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.formula--example { margin: 14px 0; background: #153d2f; }
.param-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.param-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.param-table th { padding: 11px 14px; background: var(--surface-2); color: var(--ink-3); text-align: left; font-size: 11px; font-weight: 600; white-space: nowrap; }
.param-table td { padding: 14px; border-top: 1px solid var(--line); color: var(--ink-2); line-height: 1.75; vertical-align: top; }
.param-table td:first-child { color: var(--brand); white-space: nowrap; }
.param-table td:nth-child(2) { white-space: nowrap; }
.example-box { padding: 16px 18px; border-left: 3px solid var(--brand-2); border-radius: 0 8px 8px 0; background: var(--brand-tint); }
.example-box strong { color: var(--brand); font-size: 12px; }
.example-box p { margin-top: 4px; color: var(--ink-2); }
.article-note { margin-top: 14px; font-size: 13px; }
.pitfall-list { display: grid; gap: 11px; }
.pitfall-list li { position: relative; padding: 13px 15px 13px 38px; border: 1px solid #ecd8c8; border-radius: 9px; background: var(--clay-tint); color: #6e4026; line-height: 1.75; }
.pitfall-list li::before { content: "!"; position: absolute; left: 14px; top: 14px; width: 16px; height: 16px; display: grid; place-items: center; border: 1px solid var(--clay); border-radius: 50%; color: var(--clay); font: 600 11px var(--font-mono); }
.related-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.related-grid a { display: flex; align-items: baseline; gap: 9px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); transition: border-color .18s, transform .18s; }
.related-grid a:hover { border-color: var(--brand-2); transform: translateY(-1px); }
.related-grid strong { color: var(--brand); font-family: var(--font-mono); }
.related-grid span { color: var(--ink-3); font-size: 12px; }
.article-footer { padding: 19px 42px; background: var(--surface-2); color: var(--ink-3); font-size: 11px; line-height: 1.8; }
.prev-next { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.prev-next a { padding: 14px 18px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 253, 248, .75); }
.prev-next a:last-child { text-align: right; }
.prev-next span { display: block; color: var(--ink-3); font-size: 11px; }
.prev-next strong { color: var(--brand); font-size: 13px; }
.pg-aside { position: sticky; top: 96px; display: grid; gap: 16px; }
.aside-card { padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 253, 248, .85); }
.aside-card h2 { margin-bottom: 12px; color: var(--ink-3); font: 10px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; }
.aside-card a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 8px; border-radius: 6px; color: var(--ink-2); font-size: 12px; }
.aside-card a:hover, .aside-card a[aria-current="true"] { background: var(--brand-tint); color: var(--brand); }
.aside-card a span { color: var(--ink-3); font-size: 10px; }
.pg-footer { max-width: 1240px; margin: 0 auto; padding: 24px 28px 36px; display: flex; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: 11px; }
.pg-footer a { color: var(--brand); }
.directory { max-width: 1240px; margin: 0 auto; padding: 26px 28px 64px; }
.directory-hero { padding: 34px 0 26px; }
.directory-hero > p { color: var(--brand); font: 10px var(--font-mono); letter-spacing: .2em; }
.directory-hero h1 { margin-top: 8px; font: 600 clamp(30px, 5vw, 46px) var(--font-display); letter-spacing: .05em; }
.directory-hero > span { display: block; margin-top: 10px; color: var(--ink-3); }
.category-jump { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 36px; }
.category-jump a { padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink-2); font-size: 12px; }
.category-jump a:hover { border-color: var(--brand-2); color: var(--brand); }
.directory-section { margin-top: 34px; scroll-margin-top: 92px; }
.directory-section__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line-strong); }
.directory-section__head h2 { font: 600 24px var(--font-display); letter-spacing: .04em; }
.directory-section__head span { color: var(--ink-3); font: 11px var(--font-mono); }
.directory-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.directory-card { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--sh-sm); transition: transform .18s, border-color .18s; }
.directory-card:hover { transform: translateY(-2px); border-color: var(--brand-2); }
.directory-card__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.directory-card__top strong { color: var(--brand); font: 600 16px var(--font-mono); overflow-wrap: anywhere; }
.directory-card__top small { flex: none; padding: 2px 6px; border-radius: 999px; background: var(--brand-tint); color: var(--brand); font-size: 9px; }
.directory-card > b { display: block; margin-top: 8px; font-size: 13px; }
.directory-card > p { min-height: 42px; margin-top: 6px; color: var(--ink-3); font-size: 11px; line-height: 1.8; }
.directory-card__link { display: block; margin-top: 12px; color: var(--brand); font-size: 11px; }
@media (max-width: 960px) {
  .pg-layout { grid-template-columns: minmax(0, 1fr); }
  .pg-aside { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .directory-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .pg-header__inner { height: 64px; padding: 0 16px; }
  .pg-brand strong { font-size: 14px; }
  .pg-brand small { display: none; }
  .pg-brand__mark { width: 32px; height: 32px; }
  .pg-topnav a { padding: 7px 8px; font-size: 11px; }
  .pg-layout, .directory { padding: 18px 14px 48px; }
  .function-hero, .article-section { padding: 24px 20px; }
  .function-hero::after { font-size: 76px; right: 18px; }
  .function-hero h1 { font-size: 28px; }
  .article-footer { padding: 17px 20px; }
  .related-grid, .directory-grid, .pg-aside { grid-template-columns: minmax(0, 1fr); }
  .directory-card > p { min-height: 0; }
  .prev-next { grid-template-columns: minmax(0, 1fr); }
  .prev-next a:last-child { text-align: left; }
  .param-table { min-width: 580px; }
  .pg-footer { padding: 20px 16px 28px; flex-direction: column; gap: 6px; }
}

/* ---------- 暗黑模式 ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111815;
    --paper-2: #18201c;
    --surface: #1a231d;
    --surface-2: #1e2922;
    --ink: #e6ece8;
    --ink-2: #b3bdb6;
    --ink-3: #7d8880;
    --line: #2a332c;
    --line-strong: #3a453c;
    --brand: #4db98a;
    --brand-2: #3fa877;
    --brand-tint: #1c3328;
    --clay: #d4844f;
    --clay-tint: #3a281b;
    --rail: #0c1a14;
    --rail-2: #102319;
    --rail-line: rgba(255, 255, 255, .08);
    --rail-text: #c6d3c9;
    --rail-dim: #7f968a;
    --sh-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 24px -18px rgba(0, 0, 0, .7);
    --sh-md: 0 2px 4px rgba(0, 0, 0, .4), 0 24px 48px -30px rgba(0, 0, 0, .75);
  }
}
[data-theme="dark"] {
  --paper: #111815;
  --paper-2: #18201c;
  --surface: #1a231d;
  --surface-2: #1e2922;
  --ink: #e6ece8;
  --ink-2: #b3bdb6;
  --ink-3: #7d8880;
  --line: #2a332c;
  --line-strong: #3a453c;
  --brand: #4db98a;
  --brand-2: #3fa877;
  --brand-tint: #1c3328;
  --clay: #d4844f;
  --clay-tint: #3a281b;
  --rail: #0c1a14;
  --rail-2: #102319;
  --rail-line: rgba(255, 255, 255, .08);
  --rail-text: #c6d3c9;
  --rail-dim: #7f968a;
  --sh-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 24px -18px rgba(0, 0, 0, .7);
  --sh-md: 0 2px 4px rgba(0, 0, 0, .4), 0 24px 48px -30px rgba(0, 0, 0, .75);
}
[data-theme="dark"] .pg-header { background: rgba(17, 24, 21, .92); }
[data-theme="dark"] .function-hero { background: linear-gradient(135deg, rgba(28, 51, 40, .7), rgba(26, 35, 29, .3) 60%); }
[data-theme="dark"] .function-hero::after { color: rgba(77, 185, 138, .08); }
[data-theme="dark"] .function-hero__meta a,
[data-theme="dark"] .function-hero__meta span { border-color: rgba(77, 185, 138, .25); background: rgba(28, 51, 40, .6); color: var(--brand); }
[data-theme="dark"] .formula--example { background: #102a1f; }
[data-theme="dark"] .pitfall-list li { border-color: #5a3d24; color: #e8c8a6; }
[data-theme="dark"] .prev-next a { background: rgba(26, 35, 29, .85); }
[data-theme="dark"] .aside-card { background: rgba(26, 35, 29, .85); }
[data-theme="dark"] body {
  background-image:
    radial-gradient(1100px 560px at 8% -8%, rgba(77, 185, 138, .08), transparent 62%),
    radial-gradient(900px 500px at 96% 4%, rgba(212, 132, 79, .05), transparent 60%),
    linear-gradient(to right, rgba(255, 255, 255, .03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, .03) 1px, transparent 1px);
}
