/* ============================================================
   core.css —— 全站基础：主题令牌、字体、重置、通用组件
   三套主题只换令牌，不换版式。
   ============================================================ */

/* ---------- 主题令牌 ---------- */
/* paper：练习册纸感（默认） */
html[data-theme="paper"] {
  --ground: #f4efe6;
  --surface: #fffcf4;
  --surface-2: #ece4d6;
  --surface-3: #e1d6c4;
  --ink: #1f2a24;
  --ink-soft: #55645b;
  --track: #d8cdbb;
  --accent: #2e7d5b;
  --accent-soft: #2e7d5b1a;
  --accent-2: #c0396b;
  --accent-2-soft: #c0396b1a;
  --accent-3: #d99518;
  --accent-3-soft: #d9951829;
  --on-accent: #fffdf7;
  --tint: #ffeed2;
  --focus: #2e7d5b;
  --grid: #00000000;
}

/* chalk：黑板 / 晚自习 */
html[data-theme="chalk"] {
  --ground: #1c2620;
  --surface: #243029;
  --surface-2: #2c3a32;
  --surface-3: #36463c;
  --ink: #f1ede0;
  --ink-soft: #b3c0b6;
  --track: #47564b;
  --accent: #7fd1a8;
  --accent-soft: #7fd1a826;
  --accent-2: #f2a3be;
  --accent-2-soft: #f2a3be26;
  --accent-3: #f2d06b;
  --accent-3-soft: #f2d06b26;
  --on-accent: #18211b;
  --tint: #3a4a3f;
  --focus: #7fd1a8;
  --grid: #ffffff0a;
}

/* sky：晴空 / 课本 */
html[data-theme="sky"] {
  --ground: #e8efee;
  --surface: #f9fcfb;
  --surface-2: #dde9e7;
  --surface-3: #cfe0dd;
  --ink: #17272c;
  --ink-soft: #4c6169;
  --track: #c5d5d2;
  --accent: #16697a;
  --accent-soft: #16697a1a;
  --accent-2: #b4436c;
  --accent-2-soft: #b4436c1a;
  --accent-3: #c98a12;
  --accent-3-soft: #c98a1229;
  --on-accent: #f7fbfb;
  --tint: #d9e9ec;
  --focus: #16697a;
  --grid: #00000000;
}

/* ---------- 字体 ---------- */
:root {
  --font-display: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", serif;
  --font-text: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;

  --r-frame: 16px;
  --r-item: 12px;
  --gap: 14px;

  --w-wrap: 1120px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 背景水印：固定在视口中央的大字，只作为底纹，永远不参与交互与点选 */
body::before {
  content: "@数学徐老师";
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: clamp(44px, 11vw, 132px);
  font-weight: 600;
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: var(--ink);
  opacity: 0.05;
  transform: rotate(-18deg);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

/* 深色主题下浅色字要稍微提亮，否则水印几乎看不见 */
html[data-theme="chalk"] body::before {
  opacity: 0.09;
}

/* 页面内容整体压在背景水印之上 */
.home,
.lesson {
  position: relative;
  z-index: 1;
}

/* 页脚水印与版权：两页共用一套排版 */
.foot-mark {
  margin: 16px 0 4px;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.foot-copy {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  letter-spacing: 0.02em;
  opacity: 0.85;
}

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

/* hidden 属性要压过组件的 display 设定（按钮、提示条等） */
[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

/* 浏览器自带表面也接管 */
::selection {
  background: var(--accent);
  color: var(--on-accent);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

html {
  scrollbar-color: var(--track) transparent;
  caret-color: var(--accent);
}

/* ---------- 排版 ---------- */
h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.25;
  margin: 0;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(30px, 6.2vw, 40px);
}

h2 {
  font-size: clamp(19px, 4.4vw, 22px);
}

p {
  margin: 0;
}

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

/* 分数组件：HTML 排版，不用图片，不随屏幕缩放 */
.frac {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  text-align: center;
  vertical-align: -0.35em;
  line-height: 1.12;
  margin: 0 0.12em;
  font-size: 0.96em;
}

.frac > span:first-child {
  border-bottom: 1.5px solid currentColor;
  padding: 0 0.22em 0.06em;
}

.frac > span:last-child {
  padding: 0.06em 0.22em 0;
}

/* 聚焦/强调用的浅底 */
.tint {
  background: var(--tint);
  border-radius: 6px;
  padding: 0 0.28em;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-item);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: background-color 0.16s ease, transform 0.16s ease, opacity 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: var(--surface-3);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.42;
  cursor: default;
  transform: none;
}

.btn--primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn--primary:hover {
  background: var(--accent);
  filter: brightness(1.06);
}

.btn--quiet {
  background: transparent;
  color: var(--ink-soft);
  padding: 0 10px;
}

.btn--quiet:hover {
  background: var(--surface-2);
  color: var(--ink);
}

/* ---------- 分段控件 ---------- */
.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-2);
  border-radius: calc(var(--r-item) + 3px);
  gap: 2px;
}

.seg > button {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-item);
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.seg > button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
}

/* ---------- 主题切换器 ---------- */
.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 999px;
}

.theme-switch > button {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--swatch);
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.theme-switch > button:hover {
  transform: scale(1.08);
}

.theme-switch > button[aria-checked="true"] {
  border-color: var(--ink);
}

/* ---------- 小标记 ---------- */
.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

.chip--accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
