/* ==========================================================================
   GaoShu-Review Base Styles: Reset, Theme Tokens, Typography & Callouts
   ========================================================================== */

:root {
  /* 核心教材学术配色 */
  --c-primary: #2563eb;
  --c-primary-hover: #1d4ed8;
  --c-primary-weak: #dbeafe;
  --c-success: #16a34a;
  --c-success-weak: #dcfce7;
  --c-warning: #d97706;
  --c-warning-weak: #fef3c7;
  --c-danger: #dc2626;
  --c-danger-weak: #fee2e2;
  --c-purple: #7c3aed;
  --c-purple-weak: #ede9fe;

  /* 纸张质感背景与中性色 */
  --c-bg: #f8fafc;
  --c-surface: #ffffff;
  --c-surface-2: #f1f5f9;
  --c-text: #1e293b;
  --c-text-2: #64748b;
  --c-border: #e2e8f0;

  /* 圆角与柔和阴影 */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 28px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.06);

  /* 布局尺寸变量 */
  --topbar-h: 56px;
  --sidebar-w: 220px;
  --sidebar-rail-w: 64px;
  --bottomnav-h: 60px;

  /* 字体栈 */
  --font-sans: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;

  /* 字号阶梯：对应 12 / 14 / 16 / 20 / 24 / 32px（在 16px 基准下） */
  --fs-12: 0.75rem;
  --fs-14: 0.875rem;
  --fs-16: 1rem;
  --fs-20: 1.25rem;
  --fs-24: 1.5rem;
  --fs-32: 2rem;
}

[data-theme="dark"] {
  --c-primary: #3b82f6;
  --c-primary-hover: #60a5fa;
  --c-primary-weak: #1e3a8a;
  --c-success: #22c55e;
  --c-success-weak: rgba(34, 197, 94, 0.16);
  --c-warning: #f59e0b;
  --c-warning-weak: rgba(245, 158, 11, 0.16);
  --c-danger: #ef4444;
  --c-danger-weak: rgba(239, 68, 68, 0.18);
  --c-purple: #a78bfa;
  --c-purple-weak: rgba(167, 139, 250, 0.18);

  --c-bg: #0f172a;
  --c-surface: #1e293b;
  --c-surface-2: #0b1220;
  --c-text: #e2e8f0;
  --c-text-2: #94a3b8;
  --c-border: #334155;

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.22);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* 字号阶梯响应设置 */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

html[data-fontsize="small"] {
  font-size: 14px;
}

html[data-fontsize="medium"] {
  font-size: 16px;
}

html[data-fontsize="large"] {
  font-size: 18px;
}

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

body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
ul,
ol,
dl,
dd,
figure,
blockquote {
  margin: 0;
}

ul[role="list"],
ol[role="list"] {
  list-style: none;
  padding: 0;
}

body {
  min-height: 100vh;
  background-color: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: var(--fs-16);
  line-height: 1.75;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img,
svg,
canvas {
  max-width: 100%;
}

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

a {
  color: var(--c-primary);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--c-primary-hover);
}

code,
pre,
kbd,
.font-mono {
  font-family: var(--font-mono);
}

code {
  font-size: 0.9em;
  padding: 0.12em 0.38em;
  border-radius: 4px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: var(--fs-12);
  line-height: 1.4;
  color: var(--c-text-2);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-bottom-width: 2px;
  border-radius: 4px;
}

/* 键盘可访问性焦点环 */
:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

#view:focus {
  outline: none;
}

/* 标题与排版层级 */
h1 { font-size: var(--fs-24); line-height: 1.35; font-weight: 700; }
h2 { font-size: var(--fs-20); line-height: 1.4; font-weight: 700; }
h3 { font-size: 1.125rem; line-height: 1.45; font-weight: 600; }
h4 { font-size: var(--fs-16); line-height: 1.5; font-weight: 600; }

/* KaTeX 公式排版增强 */
.katex {
  font-size: 1.06em;
}

.katex-display {
  font-size: 1.15em;
  margin: 12px 0;
  padding: 6px 4px;
  overflow-x: auto;
  overflow-y: hidden;
}

/* 教材风格语义色块：定义(蓝) / 定理(紫) / 注意(橙) / 例题(绿) */
.semantic-block,
.callout {
  position: relative;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}

.semantic-block-title,
.callout-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: var(--fs-16);
  margin-bottom: 8px;
}

.callout-definition,
.block-definition {
  border-left-color: var(--c-primary);
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.05) 0%, var(--c-surface) 30%);
}
.callout-definition .callout-title,
.block-definition .semantic-block-title {
  color: var(--c-primary);
}

.callout-theorem,
.block-theorem {
  border-left-color: var(--c-purple);
  background: linear-gradient(90deg, rgba(124, 58, 237, 0.05) 0%, var(--c-surface) 30%);
}
.callout-theorem .callout-title,
.block-theorem .semantic-block-title {
  color: var(--c-purple);
}

.callout-warning,
.callout-pitfall,
.block-pitfall {
  border-left-color: var(--c-warning);
  background: linear-gradient(90deg, rgba(217, 119, 6, 0.07) 0%, var(--c-surface) 32%);
}
.callout-warning .callout-title,
.callout-pitfall .callout-title,
.block-pitfall .semantic-block-title {
  color: var(--c-warning);
}

.callout-example,
.block-example {
  border-left-color: var(--c-success);
  background: linear-gradient(90deg, rgba(22, 163, 74, 0.05) 0%, var(--c-surface) 30%);
}
.callout-example .callout-title,
.block-example .semantic-block-title {
  color: var(--c-success);
}

/* 搜索高亮 */
mark,
.search-hl {
  background: rgba(245, 158, 11, 0.28);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

/* 通用辅助类 */
.text-muted { color: var(--c-text-2); }
.text-primary { color: var(--c-primary); }
.text-success { color: var(--c-success); }
.text-warning { color: var(--c-warning); }
.text-danger { color: var(--c-danger); }

.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;
}
