/*
 * AVEFIG v3 · site-wide design system (2026-10)
 *
 * One look for every section: works, study data, notes, about.
 * Code-style type from fonts already on the reader's system (no web-font
 * request: the site is served from mainland China). CJK glyphs fall back to
 * the system sans because no monospace font covers them.
 *
 * Load order on every page:  <page/legacy css>  ->  /css/v3.css
 * The second half of this file maps the legacy avefig.css / styles.css /
 * tools.css variables onto the v3 tokens, so older pages inherit the same
 * palette and type without being rewritten.
 */

/* ---------- 1. Tokens ---------- */
:root {
  --bg: #f6f4ef; --surface: #ffffff; --ink: #1b1d1f; --muted: #5d6166; --line: #dcd8cf;
  --accent: #b5532a; --accent-soft: #f3e3d9; --ok: #2f6b45; --ok-soft: #e1efe5;
  --warn: #8a5a00; --warn-soft: #f6ebd3; --code: #efece5;
  --radius: 14px; --maxw: 1040px; --header-h: 56px;
  --font: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, "Liberation Mono",
          "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121315; --surface: #1b1d20; --ink: #ecebe7; --muted: #a3a7ad; --line: #2e3136;
    --accent: #e0855a; --accent-soft: #3a2519; --ok: #7cc79a; --ok-soft: #1c2d23;
    --warn: #e2b55f; --warn-soft: #33291a; --code: #24272b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121315; --surface: #1b1d20; --ink: #ecebe7; --muted: #a3a7ad; --line: #2e3136;
  --accent: #e0855a; --accent-soft: #3a2519; --ok: #7cc79a; --ok-soft: #1c2d23;
  --warn: #e2b55f; --warn-soft: #33291a; --code: #24272b;
  color-scheme: dark;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg) !important; color: var(--ink) !important;
  font: 15px/1.75 var(--font) !important; font-variant-ligatures: none;
}
html[data-lang="en"] [lang="zh"], html[data-lang="zh"] [lang="en"] { display: none !important; }
h1, h2, h3, h4 { font-family: var(--font) !important; letter-spacing: -.03em; color: var(--ink); }
a { color: var(--accent); }
button, input, select, textarea { font-family: inherit; }
code { background: var(--code); padding: 1px 6px; border-radius: 5px; font-size: .9em; }
img { max-width: 100%; height: auto; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* ---------- 3. Chrome: header / footer ---------- */
.v3-header {
  position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.v3-header .wrap { display: flex; align-items: center; gap: 16px; height: var(--header-h); }
.v3-brand { font-weight: 800; letter-spacing: .04em; text-decoration: none; color: var(--ink); white-space: nowrap; }
.v3-brand span { color: var(--accent); }
.v3-nav { display: flex; gap: 18px; font-size: 14px; margin-left: auto; }
.v3-nav a { color: var(--muted); text-decoration: none; white-space: nowrap; }
.v3-nav a:hover, .v3-nav a[aria-current="page"] { color: var(--ink); }
.v3-nav a[aria-current="page"] { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 6px; }
.toggles { display: flex; gap: 8px; }
.toggles button {
  font: inherit; font-size: 13px; padding: 4px 10px; border-radius: 999px; cursor: pointer;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
}
@media (max-width: 640px) {
  .v3-header .wrap { height: auto; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
  .v3-nav { order: 3; width: 100%; margin-left: 0; gap: 16px; overflow-x: auto; }
  .toggles { margin-left: auto; }
}
.v3-footer { padding: 40px 0 56px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; margin-top: 40px; }
.v3-footer p { margin: 0 0 8px; max-width: 860px; }
.v3-footer p.contact { color: var(--ink); font-size: 14px; margin-bottom: 14px; }
.v3-footer .beian { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.v3-footer .beian a { color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.v3-footer .beian img { width: 14px; height: 14px; }

/* project switcher used on work pages */
.projects { display: flex; gap: 4px; background: var(--code); border-radius: 999px; padding: 3px; font-size: 13px; font-weight: 700; }
.projects a { color: var(--muted); text-decoration: none; padding: 4px 12px; border-radius: 999px; white-space: nowrap; }
.projects a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }

/* breadcrumb */
.crumbs { font-size: 13px; color: var(--muted); padding: 18px 0 0; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }

/* ---------- 4. Components ---------- */
.hero { padding: 64px 0 36px; }
.eyebrow { color: var(--accent); font-weight: 600; font-size: 14px; letter-spacing: .08em; text-transform: uppercase; }
.hero h1, h1.v3 { font-size: clamp(30px, 5.6vw, 52px); line-height: 1.1; margin: 12px 0 18px; }
.lede { font-size: clamp(16px, 2vw, 19px); color: var(--muted); max-width: 760px; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 36px; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stat b { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 13px; }

section.v3 { padding: 52px 0; border-top: 1px solid var(--line); }
section.v3 h2 { font-size: clamp(22px, 3.2vw, 30px); margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 26px; max-width: 760px; }
section.v3 h3 { font-size: 17px; margin: 0 0 6px; }
section.v3 p { margin: 0 0 12px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 860px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card .tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-bottom: 10px; }
.card p { color: var(--muted); font-size: 14px; }
.card p:last-child { margin-bottom: 0; }
a.card { display: block; text-decoration: none; color: inherit; transition: border-color .15s; }
a.card:hover { border-color: var(--accent); }
a.card h3 { color: var(--ink); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.timeline { display: grid; gap: 12px; }
.step { display: grid; grid-template-columns: 64px 1fr; gap: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.step .k { font-weight: 800; font-size: 22px; color: var(--accent); }
.step p { color: var(--muted); font-size: 14px; margin: 0; }

.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.tablewrap table { width: 100%; border-collapse: collapse; font-size: 14px; }
.tablewrap th, .tablewrap td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tablewrap th { font-size: 13px; color: var(--muted); font-weight: 600; background: color-mix(in srgb, var(--surface) 70%, var(--bg)); }
.tablewrap tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; background: var(--code); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.bars { display: grid; gap: 14px; }
.bar { display: grid; grid-template-columns: 170px 1fr 64px; align-items: center; gap: 12px; font-size: 14px; }
@media (max-width: 560px) { .bar { grid-template-columns: 1fr 64px; } .bar .lab { grid-column: 1 / -1; } }
.track { height: 12px; background: var(--code); border-radius: 999px; overflow: hidden; }
.fill { height: 100%; background: var(--accent); border-radius: 999px; }
.fill.good { background: var(--ok); }
.bar .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

ul.limits { padding-left: 20px; margin: 0; }
ul.limits li { margin-bottom: 10px; }
pre.calc { background: var(--code); border-radius: 10px; padding: 14px; overflow-x: auto; font: inherit; font-size: 13px; line-height: 1.6; margin: 0 0 14px; }
figure.shot { margin: 0; padding: 12px; }
figure.shot img { display: block; width: 100%; height: auto; border-radius: 10px; }
figure.shot figcaption { color: var(--muted); font-size: 13px; margin-top: 10px; }
.notice { background: var(--warn-soft); color: var(--ink); border-radius: 10px; padding: 12px 14px; font-size: 14px; }

/* prose (notes, guides) */
.prose { max-width: 760px; }
.prose h2 { font-size: 22px; margin: 36px 0 10px; }
.prose h3 { font-size: 17px; margin: 26px 0 8px; }
.prose p, .prose li { color: var(--ink); }
.prose table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 16px 0; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.prose blockquote { margin: 16px 0; padding: 4px 16px; border-left: 3px solid var(--accent); color: var(--muted); }

/* ---------- 5. Legacy bridge ----------
 * avefig.css (v2) and styles.css (v1) keep their layouts; only their
 * colour and type variables are re-pointed at the v3 tokens.
 */
:root, :root[data-theme] {
  --av-navy-900: var(--ink); --av-navy-800: var(--ink); --av-navy-700: var(--accent); --av-navy-600: var(--accent);
  --av-navy-200: var(--line); --av-navy-100: var(--code); --av-navy-50: var(--bg);
  --av-gold-500: var(--accent-soft); --av-gold-600: var(--accent); --av-gold-100: var(--accent-soft);
  --av-ink: var(--ink); --av-ink-2: var(--muted); --av-ink-3: var(--muted);
  --av-line: var(--line); --av-line-2: var(--line); --av-bg: var(--surface); --av-bg-alt: var(--bg);
  --av-ok: var(--ok); --av-warn: var(--warn);
  --av-serif: var(--font); --av-sans: var(--font); --av-num: var(--font);
  --av-r-sm: 6px; --av-r-md: 10px; --av-r-lg: var(--radius);
  --av-shadow-1: none; --av-shadow-2: 0 0 0 1px var(--line);
  --av-header-h: var(--header-h);
  --primary-blue: var(--accent); --accent-gold: var(--accent-soft);
  --text-dark: var(--ink); --text-gray: var(--muted); --text-light: var(--surface);
  --bg-light: var(--bg); --bg-white: var(--bg); --bg-header: var(--bg); --bg-footer: var(--bg);
  --border-color: var(--line); --font-heading: var(--font); --font-body: var(--font);
  --shadow-sm: none; --shadow-md: 0 0 0 1px var(--line); --shadow-lg: 0 0 0 1px var(--line);
}
/* legacy hero banners used photo backgrounds with white text; flatten them */
.database-hero, .page-hero, .hero-section, .av-hero, .tools-hero, .intro-text-section {
  background: var(--surface) !important; background-image: none !important; color: var(--ink) !important;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.database-hero *, .page-hero *, .hero-section *, .av-hero *, .tools-hero *, .intro-text-section * { color: inherit !important; }
.av-btn--primary, .btn-primary, .cta-button { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff !important; }
/* retired v2 chrome, in case a page still carries an inline copy */
.av-header, .av-footer, .av-modal, [data-av-wechat], [data-av-xhs], .wechat-modal, .xhs-modal { display: none !important; }
