/* ============================================================
   动态对冲 · 小学生也能懂 — 课程站点样式
   ============================================================ */

:root {
  /* 可通过 Nudge 调整的设计变量 */
  --site-bg: #f4efe4;
  --site-fg: #1c232a;
  --site-accent: #136b5a;
  --site-on-accent: #fbf8ef;
  --site-surface: #fffdf8;
  --site-muted: #66655d;
  --site-border: #ddd3c1;
  --site-font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --site-radius: 16px;
  --site-space: 1;
  --site-type: 1;
  --site-motion: 1;

  /* 派生变量 */
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 300px;
  --accent-ink: color-mix(in srgb, var(--site-accent) 82%, var(--site-fg));
  --accent-soft: color-mix(in srgb, var(--site-accent) 8%, var(--site-surface));
  --accent-line: color-mix(in srgb, var(--site-accent) 34%, var(--site-border));
  --sidebar-bg: color-mix(in srgb, var(--site-fg) 94%, #000);
  --sidebar-fg: color-mix(in srgb, var(--site-bg) 82%, #fff);
  --shadow: 0 22px 46px -30px rgba(24, 32, 30, 0.5);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --motion: calc(180ms * var(--site-motion, 1));
}

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

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

body {
  margin: 0;
  background: var(--site-bg);
  color: var(--site-fg);
  font-family: var(--site-font);
  font-size: calc(16px * var(--site-type, 1));
  line-height: 1.75;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body.nav-open { overflow: hidden; }

::selection {
  background: color-mix(in srgb, var(--site-accent) 24%, transparent);
}

a { color: var(--site-accent); }

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

.skip {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--site-accent);
  color: var(--site-on-accent);
  border-radius: 8px;
  transform: translateY(-160%);
  transition: transform var(--motion) var(--ease);
}
.skip:focus { transform: translateY(0); }

/* ---------- 顶部阅读进度 ---------- */

.read-progress {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: 3px;
  z-index: 70;
  background: var(--site-accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

/* ---------- 侧边栏 ---------- */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  transition: transform var(--motion) var(--ease);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 26px 24px 22px;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: calc(var(--site-radius) * 0.72);
  background: var(--site-accent);
  color: var(--site-on-accent);
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.brand-text { min-width: 0; }
.brand-title {
  display: block;
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: 0.03em;
  line-height: 1.3;
}
.brand-sub {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--sidebar-fg) 62%, transparent);
}

.nav {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 26px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); border-radius: 3px; }

.nav-group + .nav-group { margin-top: 18px; }

.nav-group-title {
  margin: 0;
  padding: 10px 12px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: color-mix(in srgb, var(--sidebar-fg) 55%, transparent);
}

.nav-link {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 12px;
  border-radius: calc(var(--site-radius) * 0.5);
  color: color-mix(in srgb, var(--sidebar-fg) 86%, transparent);
  text-decoration: none;
  font-size: 13.5px;
  line-height: 1.5;
  transition: background var(--motion) var(--ease), color var(--motion) var(--ease);
}
.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}
.nav-link[aria-current="page"] {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  font-weight: 600;
}
.nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--site-accent);
}

.nav-num {
  flex: none;
  width: 24px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: color-mix(in srgb, var(--sidebar-fg) 52%, transparent);
  padding-top: 1px;
}
.nav-link[aria-current="page"] .nav-num { color: color-mix(in srgb, var(--site-accent) 55%, #fff); }

.sidebar-foot {
  padding: 16px 24px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  line-height: 1.65;
  color: color-mix(in srgb, var(--sidebar-fg) 48%, transparent);
}

.nav-close {
  display: none;
  position: absolute;
  top: 18px;
  right: 14px;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: transparent;
  color: var(--sidebar-fg);
  font-size: 18px;
  cursor: pointer;
}

.nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(10, 16, 15, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--motion) var(--ease), visibility var(--motion);
  backdrop-filter: blur(2px);
}

/* ---------- 移动端顶栏 ---------- */

.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 45;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--site-bg) 88%, transparent);
  border-bottom: 1px solid var(--site-border);
  backdrop-filter: blur(14px);
}

.topbar-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--site-border);
  border-radius: 10px;
  background: var(--site-surface);
  color: var(--site-fg);
  cursor: pointer;
}
.topbar-btn svg { display: block; }

.topbar-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--serif);
  font-size: 15px;
}

/* ---------- 主体布局 ---------- */

.shell { padding-left: var(--sidebar-w); }

.main {
  display: grid;
  grid-template-columns: minmax(0, 760px) 206px;
  justify-content: center;
  gap: calc(58px * var(--site-space, 1));
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 48px 90px;
}

.column { min-width: 0; }

/* ---------- 首页 Hero ---------- */

.home-hero {
  position: relative;
  overflow: hidden;
  padding: calc(38px * var(--site-space, 1)) 0 calc(34px * var(--site-space, 1));
  border-bottom: 1px solid var(--site-border);
  margin-bottom: 8px;
}

.home-hero::before {
  content: "";
  position: absolute;
  inset: -10px -10px 0 -10px;
  background-image: radial-gradient(circle, var(--site-border) 1px, transparent 1.2px);
  background-size: 22px 22px;
  opacity: 0.55;
  -webkit-mask-image: linear-gradient(100deg, transparent 8%, #000 62%, #000);
  mask-image: linear-gradient(100deg, transparent 8%, #000 62%, #000);
  pointer-events: none;
}

.home-hero > * { position: relative; }

.hero-mark {
  position: absolute;
  right: -8px;
  top: 2px;
  font-family: var(--serif);
  font-size: clamp(120px, 18vw, 210px);
  line-height: 1;
  color: var(--site-accent);
  opacity: 0.08;
  pointer-events: none;
  user-select: none;
}

.kicker {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-ink);
}

.home-hero h1 {
  margin: 0;
  max-width: 15em;
  font-family: var(--serif);
  font-size: calc(50px * var(--site-type, 1));
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: 0.005em;
}

.home-hero .lede {
  max-width: 33em;
  margin: 20px 0 0;
  font-size: calc(17px * var(--site-type, 1));
  line-height: 1.85;
  color: var(--site-muted);
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px;
  border: 1px solid transparent;
  border-radius: calc(var(--site-radius) * 0.62);
  font-size: 14.5px;
  font-weight: 600;
  text-decoration: none;
  transition: transform var(--motion) var(--ease), box-shadow var(--motion) var(--ease),
    background var(--motion) var(--ease), border-color var(--motion) var(--ease);
}

.btn-primary {
  background: var(--site-accent);
  color: var(--site-on-accent);
  box-shadow: 0 14px 28px -16px color-mix(in srgb, var(--site-accent) 80%, transparent);
}
.btn-primary:hover { transform: translateY(-2px); }

.btn-ghost {
  border-color: var(--site-border);
  background: var(--site-surface);
  color: var(--site-fg);
}
.btn-ghost:hover { border-color: var(--accent-line); transform: translateY(-2px); }

.resume {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 18px;
  font-size: 13px;
  color: var(--site-muted);
  text-decoration: none;
  border-bottom: 1px dashed var(--site-border);
  padding-bottom: 2px;
}
.resume span { color: var(--accent-ink); font-weight: 600; }
.resume[hidden] { display: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin-top: 36px;
  border: 1px solid var(--site-border);
  border-radius: var(--site-radius);
  background: var(--site-border);
  overflow: hidden;
}

.stat {
  background: var(--site-surface);
  padding: 16px 18px;
}
.stat b {
  display: block;
  font-family: var(--serif);
  font-size: calc(26px * var(--site-type, 1));
  font-weight: 600;
  line-height: 1.2;
}
.stat span {
  display: block;
  margin-top: 3px;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--site-muted);
}

/* ---------- 内页 Hero ---------- */

.page-hero {
  position: relative;
  overflow: hidden;
  padding: calc(26px * var(--site-space, 1)) 0 calc(22px * var(--site-space, 1));
  border-bottom: 1px solid var(--site-border);
}

.hero-num {
  position: absolute;
  right: -6px;
  top: -26px;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(110px, 15vw, 170px);
  line-height: 1;
  color: var(--site-accent);
  opacity: 0.07;
  user-select: none;
  pointer-events: none;
}

.page-hero h1 {
  position: relative;
  margin: 0;
  max-width: 16em;
  font-family: var(--serif);
  font-size: calc(36px * var(--site-type, 1));
  font-weight: 650;
  line-height: 1.3;
}

.hero-meta {
  margin: 14px 0 0;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--site-muted);
}
.hero-meta .dot { margin: 0 8px; opacity: 0.5; }

/* ---------- 正文排版 ---------- */

.article {
  padding-top: calc(18px * var(--site-space, 1));
  font-size: calc(17px * var(--site-type, 1));
  line-height: 1.9;
  color: var(--site-fg);
  overflow-wrap: break-word;
}

.article > *:first-child { margin-top: 0; }

.article p { margin: 1.05em 0; }

.article h2 {
  position: relative;
  margin: calc(54px * var(--site-space, 1)) 0 16px;
  padding-top: 18px;
  border-top: 1px solid var(--site-border);
  font-family: var(--serif);
  font-size: calc(27px * var(--site-type, 1));
  font-weight: 650;
  line-height: 1.45;
  scroll-margin-top: 86px;
}
.article h2::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  width: 54px;
  height: 2px;
  background: var(--site-accent);
}

.article h3 {
  margin: 34px 0 10px;
  font-family: var(--serif);
  font-size: calc(20.5px * var(--site-type, 1));
  font-weight: 650;
  line-height: 1.5;
  color: var(--accent-ink);
  scroll-margin-top: 86px;
}

.anchor {
  margin-left: 0.35em;
  font-family: var(--mono);
  font-size: 0.62em;
  font-weight: 400;
  color: var(--site-accent);
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--motion) var(--ease);
}
h2:hover .anchor,
h3:hover .anchor,
.anchor:focus-visible { opacity: 0.65; }

.article strong { font-weight: 700; }

.article em { color: var(--accent-ink); }

.article a {
  color: var(--accent-ink);
  text-decoration-color: color-mix(in srgb, var(--site-accent) 40%, transparent);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
.article a:hover { text-decoration-color: var(--site-accent); }

.article ul,
.article ol {
  margin: 1em 0;
  padding-left: 1.5em;
}
.article li { margin: 0.38em 0; }
.article li::marker { color: var(--site-accent); }

.article hr {
  height: 1px;
  margin: calc(42px * var(--site-space, 1)) 0;
  border: 0;
  background: linear-gradient(90deg, transparent, var(--site-border) 18%, var(--site-border) 82%, transparent);
}

.article blockquote {
  margin: 26px 0;
  padding: 17px 22px;
  background: var(--accent-soft);
  border-left: 3px solid var(--site-accent);
  border-radius: 0 var(--site-radius) var(--site-radius) 0;
  color: color-mix(in srgb, var(--site-fg) 88%, var(--site-muted));
}
.article blockquote p { margin: 0.4em 0; }
.article blockquote p:first-child { margin-top: 0; }
.article blockquote p:last-child { margin-bottom: 0; }
.article blockquote strong { color: var(--site-fg); }

/* 表格 */

.table-wrap {
  margin: 28px 0;
  overflow-x: auto;
  border: 1px solid var(--site-border);
  border-radius: var(--site-radius);
  background: var(--site-surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset;
}

.article table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: calc(14.5px * var(--site-type, 1));
  line-height: 1.62;
}

.article th {
  padding: 11px 14px;
  background: color-mix(in srgb, var(--site-accent) 9%, var(--site-surface));
  border-bottom: 1px solid var(--site-border);
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.article td {
  padding: 11px 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--site-border) 70%, transparent);
  vertical-align: top;
}

.article tbody tr:last-child td { border-bottom: 0; }
.article tbody tr:nth-child(even) { background: color-mix(in srgb, var(--site-bg) 46%, transparent); }

/* 代码 */

.article code {
  padding: 0.12em 0.38em;
  border-radius: calc(var(--site-radius) * 0.3);
  background: color-mix(in srgb, var(--site-accent) 9%, var(--site-surface));
  color: var(--accent-ink);
  font-family: var(--mono);
  font-size: 0.87em;
  white-space: nowrap;
}

.article pre {
  margin: 26px 0;
  padding: 18px 20px;
  overflow-x: auto;
  border-radius: var(--site-radius);
  background: color-mix(in srgb, var(--site-fg) 94%, #000);
  color: color-mix(in srgb, var(--site-bg) 90%, #fff);
  box-shadow: var(--shadow);
  line-height: 1.7;
  tab-size: 2;
}

.article pre code {
  padding: 0;
  background: none;
  color: inherit;
  font-size: calc(13.5px * var(--site-type, 1));
  white-space: pre;
}

/* 练习答案折叠 */

.article details {
  margin: 12px 0 20px;
  padding: 0 18px;
  border: 1px solid var(--site-border);
  border-radius: calc(var(--site-radius) * 0.75);
  background: var(--site-surface);
  transition: border-color var(--motion) var(--ease), background var(--motion) var(--ease);
}

.article details[open] {
  padding-bottom: 14px;
  border-color: var(--accent-line);
  background: color-mix(in srgb, var(--site-accent) 4%, var(--site-surface));
}

.article summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  list-style: none;
  cursor: pointer;
  font-size: calc(14.5px * var(--site-type, 1));
  font-weight: 600;
  color: var(--accent-ink);
  user-select: none;
}
.article summary::-webkit-details-marker { display: none; }

.article summary::before {
  content: "＋";
  flex: none;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--site-accent) 12%, var(--site-surface));
  border: 1px solid var(--accent-line);
  font-size: 12px;
  font-weight: 400;
  line-height: 1;
  transition: transform var(--motion) var(--ease), background var(--motion) var(--ease);
}
.article details[open] summary::before {
  content: "－";
  background: var(--site-accent);
  color: var(--site-on-accent);
  border-color: var(--site-accent);
}

.article summary:hover::before { transform: scale(1.08); }

/* ---------- 本页目录 ---------- */

.toc {
  position: sticky;
  top: 28px;
  align-self: start;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
  padding-top: 10px;
  font-size: 12.5px;
  scrollbar-width: none;
}
.toc::-webkit-scrollbar { display: none; }

.toc-title {
  margin: 0 0 12px;
  padding-left: 14px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--site-muted);
}

.toc a {
  display: block;
  padding: 6px 0 6px 14px;
  border-left: 2px solid var(--site-border);
  color: var(--site-muted);
  text-decoration: none;
  line-height: 1.5;
  transition: color var(--motion) var(--ease), border-color var(--motion) var(--ease);
}
.toc a:hover { color: var(--accent-ink); }
.toc a.active {
  border-left-color: var(--site-accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* ---------- 上下课 ---------- */

.pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: calc(64px * var(--site-space, 1));
  padding-top: 28px;
  border-top: 1px solid var(--site-border);
}

.pager a {
  display: block;
  padding: 15px 18px;
  border: 1px solid var(--site-border);
  border-radius: calc(var(--site-radius) * 0.8);
  background: var(--site-surface);
  text-decoration: none;
  transition: transform var(--motion) var(--ease), border-color var(--motion) var(--ease),
    box-shadow var(--motion) var(--ease);
}
.pager a:hover {
  transform: translateY(-2px);
  border-color: var(--accent-line);
  box-shadow: var(--shadow);
}

.pager .lbl {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  color: var(--site-muted);
}
.pager .ttl {
  display: block;
  margin-top: 4px;
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.45;
  color: var(--site-fg);
}
.pager a.next { text-align: right; grid-column: 2; }
.pager a.next .lbl::after { content: " →"; }
.pager a.prev .lbl::before { content: "← "; }

.page-foot {
  margin-top: 46px;
  padding-top: 18px;
  border-top: 1px solid var(--site-border);
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--site-muted);
}
.page-foot p { margin: 0.35em 0; }

/* ---------- 响应式 ---------- */

@media (max-width: 1180px) {
  .main {
    grid-template-columns: minmax(0, 760px);
    gap: 0;
    padding-left: 40px;
    padding-right: 40px;
  }
  .toc { display: none; }
}

@media (max-width: 900px) {
  .read-progress { left: 0; }
  .shell { padding-left: 0; }
  .sidebar {
    width: min(86vw, 320px);
    transform: translateX(-104%);
    box-shadow: 30px 0 60px -30px rgba(0, 0, 0, 0.5);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-overlay { opacity: 1; visibility: visible; }
  .nav-close { display: flex; }
  .topbar { display: flex; }
  .main { padding: 26px 20px 68px; }
  .home-hero { padding-top: 26px; }
  .home-hero h1 { font-size: calc(35px * var(--site-type, 1)); }
  .page-hero h1 { font-size: calc(29px * var(--site-type, 1)); }
  .hero-num { font-size: 108px; top: -14px; }
  .article { font-size: calc(16px * var(--site-type, 1)); }
  .article h2 { font-size: calc(23px * var(--site-type, 1)); margin-top: 42px; }
  .article h3 { font-size: calc(19px * var(--site-type, 1)); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pager a.next { grid-column: 1; }
}

@media (max-width: 480px) {
  .home-hero h1 { font-size: calc(30px * var(--site-type, 1)); }
  .home-hero .lede { font-size: calc(15.5px * var(--site-type, 1)); }
  .cta-row .btn { width: 100%; justify-content: center; }
  .article blockquote { padding: 15px 17px; }
  .article table { min-width: 460px; }
  .stat { padding: 13px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- 打印 ---------- */

@media print {
  .sidebar,
  .topbar,
  .toc,
  .pager,
  .read-progress,
  .nav-overlay,
  .skip { display: none !important; }
  .shell { padding-left: 0; }
  .main { display: block; padding: 0; max-width: none; }
  body { background: #fff; }
  .article { font-size: 11pt; line-height: 1.6; }
  .article details { break-inside: avoid; }
  .article details > * { display: block; }
}
