/* ==========================================================================
   QuantaForge · 格物天枢 — Design Tokens (Physics Focus Studio Aesthetic)
   - Light (Default): Warm Paper Editorial (#F7F6F2 / #FFFFFF / #141416 / #0E7490)
   - Dark           : Linear Obsidian Craft (#090A0F / #11131B / #F4F4F6 / #38BDF8)
   - 60 / 30 / 10 Spectral Cyan & Cherenkov Blue Discipline · Tabular Numbers
   ========================================================================== */

:root,
html[data-theme="light"] {
  color-scheme: light;

  /* 60/30 Paper & Ink Neutrals */
  --af-bg: #F7F6F2;
  --af-surface: #FFFFFF;
  --af-surface-2: #F1EFEA;
  --af-surface-hover: #EAE7DF;
  --af-border: rgba(24, 24, 27, 0.08);
  --af-border-strong: rgba(24, 24, 27, 0.14);

  --af-ink: #141416;
  --af-ink-2: #5A5A66;
  --af-ink-3: #838390;

  /* 10% Sole Physics Brand Accent (Spectral Deep Cyan) */
  --af-accent: #0E7490;
  --af-accent-solid: #0E7490;
  --af-accent-hover: #155E75;
  --af-accent-fg: #FFFFFF;
  --af-accent-soft: rgba(14, 116, 144, 0.08);
  --af-accent-border: rgba(14, 116, 144, 0.24);

  /* Functional Semantic Status */
  --af-emerald: #0F766E;
  --af-emerald-soft: rgba(15, 118, 110, 0.09);
  --af-emerald-border: rgba(15, 118, 110, 0.26);

  --af-amber: #B45309;
  --af-amber-soft: rgba(180, 83, 9, 0.09);
  --af-amber-border: rgba(180, 83, 9, 0.26);

  --af-crimson: #BE123C;
  --af-crimson-soft: rgba(190, 18, 60, 0.08);
  --af-crimson-border: rgba(190, 18, 60, 0.26);

  /* Restrained Elevation */
  --af-shadow-xs: 0 1px 2px rgba(20, 20, 22, 0.04);
  --af-shadow-sm: 0 1px 2px rgba(20, 20, 22, 0.04), 0 6px 20px rgba(20, 20, 22, 0.04);
  --af-shadow-md: 0 4px 14px rgba(20, 20, 22, 0.06), 0 16px 36px -14px rgba(20, 20, 22, 0.08);
  --af-shadow-stage: 0 24px 56px -22px rgba(15, 18, 32, 0.34), 0 2px 8px rgba(15, 18, 32, 0.08);
  --af-shadow-drawer: -12px 0 44px rgba(15, 18, 32, 0.14);

  /* Formula & Code Surfaces */
  --af-formula-bg: #FAF9F6;
  --af-code-bg: #F3F2EC;
  --af-svg-grid: rgba(24, 24, 27, 0.06);
  --af-svg-edge: rgba(24, 24, 27, 0.16);
  --af-svg-node-bg: #FFFFFF;

  /* V10 Compatibility Aliases */
  --v10-bg: var(--af-bg);
  --v10-surface: var(--af-surface);
  --v10-surface-2: var(--af-surface-2);
  --v10-surface-hover: var(--af-surface-hover);
  --v10-border: var(--af-border);
  --v10-border-strong: var(--af-border-strong);
  --v10-ink: var(--af-ink);
  --v10-ink-2: var(--af-ink-2);
  --v10-ink-3: var(--af-ink-3);
  --v10-accent: var(--af-accent);
  --v10-accent-solid: var(--af-accent-solid);
  --v10-accent-hover: var(--af-accent-hover);
  --v10-accent-soft: var(--af-accent-soft);
  --v10-accent-border: var(--af-accent-border);
  --v10-emerald: var(--af-emerald);
  --v10-amber: var(--af-amber);
  --v10-crimson: var(--af-crimson);

  /* Typography & Radii */
  --af-font-sans: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --af-font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Monaco, Consolas, monospace;
  --af-font-serif: "Newsreader", "Songti SC", "Noto Serif SC", Georgia, serif;

  --af-radius-sm: 8px;
  --af-radius-md: 12px;
  --af-radius-lg: 16px;
  --af-radius-xl: 20px;

  --af-topbar-h: 56px;
  --af-shell-max: 1320px;
}

html[data-theme="dark"] {
  color-scheme: dark;

  /* Linear Obsidian Craft */
  --af-bg: #090A0F;
  --af-surface: #11131B;
  --af-surface-2: #171A25;
  --af-surface-hover: #1E2231;
  --af-border: rgba(255, 255, 255, 0.08);
  --af-border-strong: rgba(255, 255, 255, 0.15);

  --af-ink: #F4F4F6;
  --af-ink-2: #8F95A3;
  --af-ink-3: #636978;

  /* Sole Physics Brand Accent (Cherenkov Ice Blue) */
  --af-accent: #38BDF8;
  --af-accent-solid: #0284C7;
  --af-accent-hover: #0369A1;
  --af-accent-fg: #FFFFFF;
  --af-accent-soft: rgba(56, 189, 248, 0.14);
  --af-accent-border: rgba(56, 189, 248, 0.30);

  /* Semantic Status */
  --af-emerald: #2DD4BF;
  --af-emerald-soft: rgba(45, 212, 191, 0.13);
  --af-emerald-border: rgba(45, 212, 191, 0.30);

  --af-amber: #F59E0B;
  --af-amber-soft: rgba(245, 158, 11, 0.13);
  --af-amber-border: rgba(245, 158, 11, 0.30);

  --af-crimson: #FB7185;
  --af-crimson-soft: rgba(251, 113, 133, 0.13);
  --af-crimson-border: rgba(251, 113, 133, 0.30);

  --af-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.36);
  --af-shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.34);
  --af-shadow-md: 0 8px 28px rgba(0, 0, 0, 0.48);
  --af-shadow-stage: 0 24px 64px -20px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(255, 255, 255, 0.06);
  --af-shadow-drawer: -16px 0 56px rgba(0, 0, 0, 0.64);

  --af-formula-bg: #141722;
  --af-code-bg: #151824;
  --af-svg-grid: rgba(255, 255, 255, 0.055);
  --af-svg-edge: rgba(255, 255, 255, 0.16);
  --af-svg-node-bg: #161925;
}

/* ==================== BASE RESETS & TYPOGRAPHY ==================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--af-font-sans);
  font-size: 14.5px;
  line-height: 1.6;
  background: var(--af-bg);
  color: var(--af-ink);
  overflow-x: clip;
  min-height: 100vh;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(ellipse 68% 36% at 50% -14%, rgba(56, 189, 248, 0.09), transparent 68%),
    var(--af-bg);
}

body.af-drawer-lock {
  overflow: hidden;
}

a {
  color: var(--af-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font-family: inherit;
  color: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--af-accent);
  outline-offset: 2px;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* KaTeX polish & safe overflow */
.katex {
  font-size: 1.04em;
}

.katex-display {
  margin: 0.75em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 2px;
  max-width: 100%;
}

.katex-display > .katex {
  white-space: nowrap;
}

/* Subtle custom scrollbars */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--af-border-strong);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--af-ink-3);
}
