:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #5b6270;
  --border: #e1e4ea;
  --accent: #1b5fd6;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefc;
  --good: #137a4b;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --text: #e8eaef;
    --muted: #a0a7b4;
    --border: #2b303b;
    --accent: #6ea0ff;
    --accent-ink: #0b1020;
    --accent-soft: #1b2640;
    --good: #4cc38a;
    --warn: #f0b552;
    --warn-soft: #2e2413;
    --bad: #ff7a6e;
    --bad-soft: #3a1c1a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --text: #e8eaef;
  --muted: #a0a7b4;
  --border: #2b303b;
  --accent: #6ea0ff;
  --accent-ink: #0b1020;
  --accent-soft: #1b2640;
  --good: #4cc38a;
  --warn: #f0b552;
  --warn-soft: #2e2413;
  --bad: #ff7a6e;
  --bad-soft: #3a1c1a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html:lang(en) [data-lang="zh"],
html:lang(zh) [data-lang="en"] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 .5rem; }
h2 { font-size: 1.45rem; margin: 2.2rem 0 .8rem; }
h3 { font-size: 1.1rem; margin: 1.4rem 0 .5rem; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 760px; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header .wrap { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); margin-right: auto; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: .95rem;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.header-actions { display: flex; gap: 6px; }
.theme-btn, .lang-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font: inherit; font-size: .9rem; line-height: 1.2;
}
.lang-btn { font-weight: 700; min-width: 52px; }
.lang-btn:hover, .theme-btn:hover { border-color: var(--accent); color: var(--accent); }
.subnav { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 8px; }
.subnav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: .9rem; }
.subnav a[aria-current="page"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* Hero */
.hero { padding: 56px 0 32px; }
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 680px; }
.eyebrow { color: var(--accent); font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }

/* Layout */
main { padding-bottom: 48px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card h3 { margin-top: 0; }
.card p { color: var(--muted); margin: .4rem 0; }
a.card { text-decoration: none; color: inherit; display: block; transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--accent); transform: translateY(-2px); }

.btn {
  display: inline-block; padding: 10px 16px; border-radius: 10px; text-decoration: none; font-weight: 600;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; font: inherit; font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.tag {
  display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); margin: 2px 4px 2px 0;
}
.tag.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.notice {
  border-left: 4px solid var(--warn); background: var(--warn-soft); padding: 12px 16px; border-radius: 8px; margin: 16px 0;
}
.notice.bad { border-color: var(--bad); background: var(--bad-soft); }
.notice.info { border-color: var(--accent); background: var(--accent-soft); }
.notice p { margin: .3rem 0; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; align-items: center; }
.filters input[type="search"], .filters select {
  font: inherit; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-width: 0;
}
.filters input[type="search"] { flex: 1 1 240px; }
.count { color: var(--muted); font-size: .9rem; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

/* Prose */
.prose { max-width: 760px; }
.prose p, .prose li { color: var(--text); }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin: .3rem 0; }
.prose blockquote { margin: 1rem 0; padding: 8px 16px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 8px; }
.toc { font-size: .95rem; }
.toc a { text-decoration: none; }

/* Steps */
.steps { counter-reset: step; list-style: none; padding: 0; }
.steps > li {
  counter-increment: step; position: relative; padding: 14px 16px 14px 56px; margin: 10px 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.steps > li::before {
  content: counter(step); position: absolute; left: 14px; top: 14px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: .9rem;
}

/* Tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin: 16px 0; }
.tabs button {
  font: inherit; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted);
}
.tabs button[aria-selected="true"] { color: var(--accent); border-color: var(--accent); font-weight: 600; }
[role="tabpanel"][hidden] { display: none; }

/* Forms / calculators */
.calc { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.calc label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.calc input, .calc select {
  font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 100%;
}
.result { font-size: 1.05rem; margin-top: 12px; }
.result strong { font-size: 1.35rem; }
.stat-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-top: 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.stat .k { font-size: .8rem; color: var(--muted); }
.stat .v { font-size: 1.25rem; font-weight: 700; }
canvas { width: 100%; max-width: 100%; height: 240px; display: block; margin-top: 12px; }

dl.glossary dt { font-weight: 700; margin-top: 14px; }
dl.glossary dd { margin: 4px 0 0; color: var(--muted); }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 28px 0 40px; color: var(--muted); font-size: .9rem; background: var(--surface); }
.site-footer .cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.site-footer a { color: var(--muted); }

@media (max-width: 640px) {
  .site-header { position: static; }
  .site-header .wrap { gap: 8px; padding-top: 8px; padding-bottom: 8px; }
  .header-actions { order: 2; }
  .nav { order: 3; width: 100%; margin-left: -8px; }
  .hero { padding: 32px 0 16px; }
  .nav a { padding: 6px 8px; font-size: .9rem; }
}
