/* ==========================================================================
   FinLearn 基础层（Base / Reset / Accessibility）
   依赖：tokens.css
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + var(--space-6));
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) { color-scheme: dark; }
}

html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  font-weight: var(--weight-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: clip;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  color: var(--color-heading);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

h1 { font-family: var(--font-display); font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-lg); line-height: var(--leading-snug); }
h4 { font-size: var(--text-md); }

p {
  margin: 0;
  text-wrap: pretty;
}

a {
  color: var(--color-accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--color-accent-hover);
}

ul, ol {
  margin: 0;
  padding-left: 1.25em;
}

li + li {
  margin-top: var(--space-1);
}

img, svg, video, canvas {
  display: block;
  max-width: 100%;
}

img {
  height: auto;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

hr {
  height: 1px;
  margin: var(--space-8) 0;
  border: 0;
  background: var(--color-border);
}

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

mark {
  padding: 0 0.25em;
  border-radius: var(--radius-xs);
  background: var(--gold-100);
  color: var(--gold-700);
}

::selection {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

/* ---- 焦点可见性（统一焦点环，键盘用户始终可见）---- */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ---- 跳到主内容 ---- */
.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-skip);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  transform: translateY(calc(-100% - var(--space-4)));
  transition: transform var(--dur-base) var(--ease-out);
}

.skip-link:focus {
  transform: translateY(0);
  color: var(--color-primary-contrast);
}

/* ---- 屏幕阅读器专用 ---- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- 页面骨架 ---- */
.shell {
  width: 100%;
  max-width: var(--shell-max);
  margin-inline: auto;
  padding-inline: var(--shell-pad);
}

.page {
  display: block;
  min-height: 60vh;
}

.page-head {
  padding: var(--space-16) 0 var(--space-10);
  border-bottom: 1px solid var(--color-border);
  background:
    linear-gradient(180deg, var(--color-surface-alt) 0%, var(--color-bg) 100%);
}

.page-head__eyebrow {
  margin-bottom: var(--space-3);
}

.page-head h1 {
  /* 26ch 对中文长标题太窄（16 字标题会被挤成两行且断在词中），放宽到 40ch 并让换行更平衡 */
  max-width: 40ch;
  text-wrap: balance;
}

.page-head__lead {
  max-width: var(--measure);
  margin-top: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-md);
}

.page-head__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-6);
  color: var(--color-text-subtle);
  font-size: var(--text-sm);
}

.section {
  padding: var(--space-16) 0;
}

.section--tight {
  padding: var(--space-12) 0;
}

.section--tinted {
  background: var(--color-surface-alt);
  border-block: 1px solid var(--color-border);
}

.section__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-8);
  margin-bottom: var(--space-8);
}

.section__head-text {
  max-width: 52ch;
}

.section__note {
  max-width: 34ch;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  color: var(--color-accent);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: var(--radius-pill);
}

.lede {
  color: var(--color-text-muted);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
}

.muted { color: var(--color-text-muted); }
.subtle { color: var(--color-text-subtle); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.center { text-align: center; }

.prose {
  max-width: var(--measure);
  color: var(--color-text);
  line-height: var(--leading-relaxed);
}

.prose > * + * {
  margin-top: var(--space-4);
}

.prose h2,
.prose h3 {
  margin-top: var(--space-8);
}

.prose ul,
.prose ol {
  color: var(--color-text);
}

.prose li::marker {
  color: var(--color-accent);
  font-weight: var(--weight-bold);
}

/* ---- 动效降级 ---- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  :root {
    --color-bg: #fff;
    --color-surface: #fff;
    --color-surface-alt: #fff;
  }
  .site-header,
  .site-footer,
  .skip-link,
  .toast-stack,
  .btn,
  .chat-form,
  .filter-bar {
    display: none !important;
  }
  .section,
  .page-head {
    padding-block: var(--space-4);
    break-inside: avoid;
  }
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: var(--text-xs);
    color: #555;
  }
  .card,
  .panel {
    box-shadow: none !important;
    border-color: #ccc !important;
  }
}
