/* =============================================================================
   设计令牌（Design Tokens）—— 科尔沁叙事民歌民族交融要素标释语料库
   品牌视觉规范 v2.0：配色 / 字体 / 图标 / 间距 / 圆角 / 阴影 / 动效
   ========================================================================== */
:root {
  /* ---------- 品牌主色（Brand Primary）：学术靛蓝，延续原平台 #1f4e79 ---------- */
  --brand-50:  #eef4fa;
  --brand-100: #d6e4f0;
  --brand-200: #adc9e1;
  --brand-300: #7ea7cd;
  --brand-400: #4d80b3;
  --brand-500: #2c5e8c;
  --brand-600: #1f4e79;   /* 主色 */
  --brand-700: #1a3d60;   /* 深色/页脚 */
  --brand-800: #16344f;
  --brand-900: #102538;

  /* ---------- 品牌辅色（Brand Accent）：草原金，用于强调与学术标记 ---------- */
  --gold-50:  #fdf8ec;
  --gold-100: #f8ecd2;
  --gold-200: #efd79f;
  --gold-300: #e2bc68;
  --gold-400: #d3a24a;
  --gold-500: #c8a45c;    /* 辅色 */
  --gold-600: #a8843c;
  --gold-700: #7d6129;

  /* ---------- 草原青（Secondary Identity）---------- */
  --grass-100: #d8f0e9;
  --grass-300: #8dd3bd;
  --grass-500: #128c73;
  --grass-700: #0b5f4f;

  /* ---------- 要素类型语义色（数据可视化固定色板）---------- */
  --type-vocab:    #d97706;  /* 词汇借用  amber */
  --type-custom:   #2563eb;  /* 文化习俗  blue  */
  --type-name:     #7c3aed;  /* 命名文化  violet*/
  --type-religion: #0d9488;  /* 宗教礼仪  teal  */
  --type-vocab-bg:    #fef3c7;
  --type-custom-bg:   #dbeafe;
  --type-name-bg:     #ede9fe;
  --type-religion-bg: #ccfbf1;
  --type-vocab-fg:    #b45309;
  --type-custom-fg:   #1d4ed8;
  --type-name-fg:     #6d28d9;
  --type-religion-fg: #0f766e;

  /* ---------- 标释高亮（marker）配色：底色 / 文字 / 描边 ----------
     正文里的内联高亮要同时满足两点：一眼可辨、且对比度达 WCAG AA（≥4.5:1）。
     下面每组前景色对各自底色的对比度均 ≥ 7:1，正文小字也清晰。 */
  --hl-vocab-bg:      #fde9b8;  --hl-vocab-fg:      #8a4b09;  --hl-vocab-line:      #d97706;
  --hl-custom-bg:     #d5e6fd;  --hl-custom-fg:     #1b3f9e;  --hl-custom-line:     #2563eb;
  --hl-name-bg:       #e6dffd;  --hl-name-fg:       #54239f;  --hl-name-line:       #7c3aed;
  --hl-religion-bg:   #c3f5ea;  --hl-religion-fg:   #0d5b52;  --hl-religion-line:   #0d9488;

  /* ---------- 状态色：背景与正文前景成对使用，保证深浅主题均达 AA ---------- */
  --success: #059669; --success-bg: #d1fae5; --success-fg: #047857;
  --warning: #d97706; --warning-bg: #fef3c7; --warning-fg: #92400e;
  --danger:  #dc2626; --danger-bg:  #fee2e2; --danger-fg:  #991b1b;
  --info:    #0284c7; --info-bg:    #e0f2fe; --info-fg:    #075985;

  /* ---------- 中性色阶（Slate）---------- */
  --n-0:   #ffffff;
  --n-25:  #fbfcfd;
  --n-50:  #f8fafc;
  --n-100: #f1f5f9;
  --n-200: #e2e8f0;
  --n-300: #cbd5e1;
  --n-400: #94a3b8;
  --n-500: #64748b;
  --n-600: #475569;
  --n-700: #334155;
  --n-800: #1e293b;
  --n-900: #0f172a;

  /* ---------- 语义化表面（随主题切换）---------- */
  --bg-app:        #f1f5f9;
  --bg-surface:    #ffffff;
  --bg-surface-2:  #f8fafc;
  --bg-inset:      #f1f5f9;
  --bg-header:     linear-gradient(120deg, #1a3d60 0%, #1f4e79 55%, #2c5e8c 100%);
  --bg-hover:      rgba(31, 78, 121, .06);
  --bg-active:     rgba(31, 78, 121, .12);
  --text-primary:  #1e293b;
  --text-secondary:#475569;
  --text-muted:    #64748b;
  --text-inverse:  #ffffff;
  --text-on-brand: #e8f0f8;
  --border:        #e2e8f0;
  --border-strong: #cbd5e1;
  --border-focus:  #2c5e8c;
  --grid-line:     #e8edf3;

  /* 交互组件语义色对：不要在组件中另写深色前景色 */
  --brand-soft-bg: var(--brand-50);
  --brand-soft-fg: var(--brand-700);
  --gold-soft-bg: var(--gold-100);
  --gold-soft-fg: var(--gold-700);
  --button-primary-bg: var(--brand-600);
  --button-primary-fg: #ffffff;
  --button-primary-hover: var(--brand-700);
  --text-on-gold: #0b1420;
  --text-placeholder: var(--n-500);
  --header-placeholder: #ffffff;
  --player-text-muted: #cbd5e1;

  /* ---------- 字体 ---------- */
  --font-sans: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Source Han Sans SC",
               "Noto Sans SC", "Segoe UI", system-ui, -apple-system, sans-serif;
  /* 蒙古文：回鹘式蒙古文（传统蒙古文）字形。
     内蒙古自治区通用的是「回鹘式蒙古文」，字形标准以蒙科立系列为准，
     故首选 Menk Qagan Tig（正文）/ Menk Qagan StdEx Tig（标准长体）。
     内置 webfont（MenkQaganTig/MenkQaganStdExTig）保证服务器与他人机器上字形一致，
     系统字体作为回退；Noto Sans Mongolian 放最后（其字形与回鹘式规范有差异，仅作兜底）。
     拉丁/西里尔转写字符不在蒙古文字体覆盖范围内，自动落到系统 UI 字体。 */
  --font-mn: "MenkQaganTig", "Menk Qagan Tig", "MenkQaganStdExTig", "Menk Qagan StdEx Tig",
            "Mongolian Baiti", "Menksoft Mongolian", "Sarasa Mongolian JCSI",
            "Noto Sans Mongolian", "Microsoft YaHei", "PingFang SC",
            "Segoe UI", Arial, sans-serif;
  --font-serif: "Source Han Serif SC", "Noto Serif SC", "Songti SC", Georgia, serif;
  --font-mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", Consolas, "Courier New", monospace;

  /* 字号阶梯（1.125 模块化比率，基准 14px 企业级密度）。
     每级直接乘 --a11y-scale；仅缩放 html 的 rem 基准无法影响这些 px 令牌。 */
  --fs-2xs: calc(11px * var(--a11y-scale)); --fs-xs: calc(12px * var(--a11y-scale));
  --fs-sm: calc(13px * var(--a11y-scale)); --fs-base: calc(14px * var(--a11y-scale));
  --fs-md: calc(15px * var(--a11y-scale)); --fs-lg: calc(16px * var(--a11y-scale));
  --fs-xl: calc(18px * var(--a11y-scale)); --fs-2xl: calc(20px * var(--a11y-scale));
  --fs-3xl: calc(24px * var(--a11y-scale)); --fs-4xl: calc(28px * var(--a11y-scale));
  --fs-5xl: calc(34px * var(--a11y-scale));
  --lh-tight: 1.25; --lh-base: 1.55; --lh-loose: 1.75;
  /* 蒙古文连写的上下笔画需要额外行距；--lh-mn-tight 用于表格/标签等紧凑场景 */
  --lh-mn: 1.95; --lh-mn-tight: 1.7;
  --fw-normal: 400; --fw-medium: 500; --fw-semibold: 600; --fw-bold: 700;

  /* ---------- 间距（4px 基准）---------- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 40px;
  --sp-9: 48px; --sp-10: 64px;

  /* ---------- 圆角 ---------- */
  --radius-xs: 4px; --radius-sm: 6px; --radius-md: 10px;
  --radius-lg: 14px; --radius-xl: 18px; --radius-2xl: 24px; --radius-pill: 999px;

  /* ---------- 阴影（分层 elevation）---------- */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, .12), 0 4px 8px rgba(15, 23, 42, .06);
  --shadow-xl: 0 24px 48px rgba(15, 23, 42, .18);
  --shadow-brand: 0 6px 16px rgba(31, 78, 121, .28);
  --ring: 0 0 0 3px rgba(44, 94, 140, .28);

  /* ---------- 动效 ---------- */
  --dur-fast: 120ms; --dur-base: 180ms; --dur-slow: 260ms; --dur-xslow: 360ms;
  --ease-std: cubic-bezier(.4, 0, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);

  /* ---------- 布局尺寸 ---------- */
  --header-h: 56px;
  --sidebar-w: 236px;
  --sidebar-w-collapsed: 68px;
  --footer-h: 34px;
  --content-max: 1440px;

  /* ---------- 层级 ---------- */
  --z-base: 1; --z-sticky: 100; --z-header: 200; --z-drawer: 400;
  --z-modal: 500; --z-toast: 600; --z-tooltip: 700;

  /* ---------- 无障碍：字号缩放系数 ---------- */
  --a11y-scale: 1;
}

/* ---------------------------------------------------------------- 深色模式 */
[data-theme="dark"] {
  --brand-600: #3b7cb8;
  --brand-500: #4d8ec9;
  --bg-app: #0b1420;
  --bg-surface: #111c2b;
  --bg-surface-2: #16243a;
  --bg-inset: #0e1826;
  --bg-header: linear-gradient(120deg, #0e2237 0%, #132f4a 55%, #1a3d60 100%);
  --bg-hover: rgba(148, 187, 224, .10);
  --bg-active: rgba(148, 187, 224, .16);
  --text-primary: #e6edf6;
  --text-secondary: #b4c3d4;
  --text-muted: #8ba0b8;
  --border: #22334a;
  --border-strong: #2f4460;
  --border-focus: #6aa8dd;
  --grid-line: #1e2f45;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .5);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
  --shadow-lg: 0 14px 34px rgba(0, 0, 0, .55);
  --ring: 0 0 0 3px rgba(106, 168, 221, .35);
  --type-vocab-bg: #4a3208; --type-custom-bg: #16345e;
  --type-name-bg: #2e2158;  --type-religion-bg: #0d3b36;
  --type-vocab-fg: #e2bc68; --type-custom-fg: #93c5fd;
  --type-name-fg: #c4b5fd;  --type-religion-fg: #5eead4;
  --brand-soft-bg: #16345e; --brand-soft-fg: var(--brand-200);
  --gold-soft-bg: #4a3208; --gold-soft-fg: var(--gold-200);
  /* 深色主题的 brand-600 与白字仅 4.41:1，按钮单独使用更深的品牌底色。 */
  --button-primary-bg: #2c5e8c; --button-primary-fg: #ffffff;
  --button-primary-hover: #1f4e79;
  --text-placeholder: #a8b8c9;
  /* 深色主题下的高亮配色：深底 + 亮字，保持 ≥7:1 对比度 */
  --hl-vocab-bg:      #4a3208;  --hl-vocab-fg:      #fcd34d;  --hl-vocab-line:      #b45309;
  --hl-custom-bg:     #16345e;  --hl-custom-fg:     #a5c8fd;  --hl-custom-line:     #2563eb;
  --hl-name-bg:       #2e2158;  --hl-name-fg:       #cbb8fe;  --hl-name-line:       #7c3aed;
  --hl-religion-bg:   #0d3b36;  --hl-religion-fg:   #7ff0dc;  --hl-religion-line:   #0d9488;
  --success-bg: #0f3f31; --warning-bg: #4a3208; --danger-bg: #4c1618; --info-bg: #0d3550;
  --success-fg: #a7f3d0; --warning-fg: #fde68a; --danger-fg: #fecaca; --info-fg: #bae6fd;
}

/* ---------------------------------------------------------------- 高对比度模式 */
[data-contrast="high"] {
  --border: #64748b; --border-strong: #334155;
  --text-secondary: #1e293b; --text-muted: #334155;
  --shadow-sm: 0 0 0 1px var(--border-strong);
}
[data-theme="dark"][data-contrast="high"] {
  --border: #94a3b8; --border-strong: #cbd5e1;
  --text-secondary: #f1f5f9; --text-muted: #cbd5e1;
}

/* =============================================================================
   基础重置与排版
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  font-size: calc(14px * var(--a11y-scale));
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* 不使用 optimizeLegibility：其字距/连字调整会打断蒙古文的 init/medi/fina 连写，
     导致蒙文字形被拆开。视觉效果由各语言栈自身的字距规则负责。 */
  text-rendering: auto;
  overflow: hidden;
}

h1, h2, h3, h4, h5 { font-weight: var(--fw-semibold); line-height: var(--lh-tight); color: var(--text-primary); }
h1 { font-size: var(--fs-3xl); } h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }  h4 { font-size: var(--fs-md); }
p { line-height: var(--lh-base); }
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { list-style: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
table { border-collapse: collapse; width: 100%; }
code, kbd { font-family: var(--font-mono); }

/* 焦点可见性：先给旧浏览器提供 :focus 降级；支持 :focus-visible 时
   再取消鼠标/触摸焦点的边框，键盘焦点始终清晰可见（WCAG 2.4.7）。 */
:focus {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* 仅屏幕阅读器可见 */
.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;
}
.skip-link {
  position: absolute; left: var(--sp-4); top: -60px; z-index: var(--z-tooltip);
  background: var(--button-primary-bg); color: var(--button-primary-fg); padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-md); font-size: var(--fs-sm); font-weight: var(--fw-medium);
  transition: top var(--dur-base) var(--ease-std);
}
.skip-link:focus { top: var(--sp-3); }

/* 滚动条（桌面端精细化） */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: var(--radius-pill);
  border: 2px solid var(--bg-app);
}
::-webkit-scrollbar-thumb:hover { background: var(--n-500); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* 减少动效（WCAG 2.3.3 / prefers-reduced-motion） */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
[data-motion="off"], [data-motion="off"] *,
[data-motion="off"] *::before, [data-motion="off"] *::after {
  animation-duration: .001ms !important; transition-duration: .001ms !important;
  scroll-behavior: auto !important;
}

/* 打印样式 */
@media print {
  .app-header, .app-sidebar, .app-footer, .no-print { display: none !important; }
  body { overflow: visible; background: #fff; }
  .app-main { padding: 0; overflow: visible; }
}

/* ---------------------------------------------------------------- 蒙古文 */
/* 排版规则已迁移至 mongolian.css（内置 Noto Sans Mongolian + 横排连写）。
   此处仅保留令牌引用，避免两处规则冲突。 */

/* ---------------------------------------------------------------- 通用工具类 */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2, .clamp-3 {
  display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden;
}
.clamp-2 { -webkit-line-clamp: 2; }
.clamp-3 { -webkit-line-clamp: 3; }
.mono { font-family: var(--font-mono); }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); }
.gap-6 { gap: var(--sp-6); }
.grid { display: grid; }
.hide { display: none !important; }
