/* ==========================================================================
   格物学堂 · 站点样式
   --------------------------------------------------------------------------
   纯手写 CSS：不引任何外部字体 / 框架 / 图标库，断网也能正常显示。
   配色分两套：浅色（纸感）与深色（夜读），由 <html data-theme> 切换。
   课程各自的强调色不走全局变量，而是由卡片上的 --c / --c2 就地定义，
   这样以后加新科目，只要在 courses.js 里给一个新色值，整张卡片就换色。
   ========================================================================== */

/* ===================== 设计令牌 ===================== */
:root {
  --paper:      #f6f4ef;
  --paper-2:    #efece4;
  --surface:    #ffffff;
  --surface-2:  #fbf9f5;
  --ink:        #191c22;
  --ink-2:      #454c58;
  --muted:      #7c8493;
  --line:       #e6e1d7;
  --line-2:     #f0ece3;
  --brand:      #3f3ac9;
  --brand-2:    #6f63f0;
  --brand-soft: #eeecfb;
  --gold:       #c98a12;

  --shadow-s: 0 1px 2px rgba(28, 25, 18, .05), 0 2px 6px rgba(28, 25, 18, .045);
  --shadow-m: 0 2px 4px rgba(28, 25, 18, .05), 0 12px 28px rgba(28, 25, 18, .075);
  --shadow-l: 0 4px 10px rgba(28, 25, 18, .06), 0 26px 60px rgba(28, 25, 18, .12);

  --r-s: 10px; --r-m: 16px; --r-l: 24px;
  --maxw: 1160px;
  --header-h: 66px;
  --ease: cubic-bezier(.22, .68, .3, 1);
}

[data-theme="dark"] {
  --paper:      #0d0f14;
  --paper-2:    #12151c;
  --surface:    #161a22;
  --surface-2:  #1b202a;
  --ink:        #e9ecf2;
  --ink-2:      #b9c0cc;
  --muted:      #8b93a3;
  --line:       #262c38;
  --line-2:     #1e232d;
  --brand:      #9d9bff;
  --brand-2:    #7c8cff;
  --brand-soft: #1e2135;
  --gold:       #e5b24c;

  --shadow-s: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-m: 0 2px 6px rgba(0, 0, 0, .42), 0 14px 34px rgba(0, 0, 0, .38);
  --shadow-l: 0 4px 12px rgba(0, 0, 0, .5), 0 30px 70px rgba(0, 0, 0, .5);
}

/* ===================== 基础 ===================== */
* { box-sizing: border-box; }
/* hidden 必须永远生效：下面 .viewer 等元素自带 display，
   没有这条规则，hidden 会被作者样式盖掉，元素就“藏不住”了。 */
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 18px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.75 "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  overflow-x: hidden;
  transition: background .35s var(--ease), color .35s var(--ease);
}
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .2px; line-height: 1.35; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 6px; }

/* ===================== 背景层 =====================
   ① .aurora  柔和色块（压淡，只做氛围）
   ② .bg-grid 方格纸：细格 24px + 粗格 120px，工程制图底纹
   ③ .bg-art  学术水印：体心立方晶胞、制冷循环 T–s 图、两门课的真实公式
   三层都是 fixed，滚动时像水印一样不动；全部纯 CSS / 内联 SVG，无外部请求。 */
.bg { position: fixed; inset: 0; z-index: -3; overflow: hidden; pointer-events: none; }

.aurora { position: absolute; inset: 0; }
.aurora i { position: absolute; display: block; border-radius: 50%; filter: blur(80px); opacity: .34; }
.aurora .b1 { width: 44vw; height: 44vw; top: -16vw; left: -10vw;  background: radial-gradient(circle, #6f63f0 0%, transparent 68%); animation: drift 26s var(--ease) infinite alternate; }
.aurora .b2 { width: 38vw; height: 38vw; top: 2vw;  right: -12vw; background: radial-gradient(circle, #1f7ae0 0%, transparent 68%); animation: drift 32s var(--ease) infinite alternate-reverse; }
.aurora .b3 { width: 32vw; height: 32vw; top: 52vh; left: 28vw; background: radial-gradient(circle, #e07a1f 0%, transparent 70%); opacity: .2; animation: drift 38s var(--ease) infinite alternate; }
[data-theme="dark"] .aurora i { opacity: .2; }
[data-theme="dark"] .aurora .b3 { opacity: .12; }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(4vw, 5vh, 0) scale(1.16); }
}

.bg-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(to right,  color-mix(in srgb, var(--ink) 9%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--ink) 9%, transparent) 1px, transparent 1px),
    linear-gradient(to right,  color-mix(in srgb, var(--ink) 4%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--ink) 4%, transparent) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  /* 标题区淡出，正文区域保持干净 */
  -webkit-mask-image: radial-gradient(118% 76% at 50% 6%, transparent 0%, #000 48%);
  mask-image: radial-gradient(118% 76% at 50% 6%, transparent 0%, #000 48%);
}

.bg-art { position: absolute; inset: 0; width: 100%; height: 100%; color: var(--ink); }
.bg-art .ba-line { fill: none; stroke: currentColor; stroke-width: 1.1; opacity: .13; }
.bg-art .ba-dash { stroke-dasharray: 6 5; stroke-width: .9; opacity: .75; }
.bg-art .ba-dot  { fill: currentColor; opacity: .15; }
.bg-art .ba-lbl  { fill: currentColor; font: 11.5px "Songti SC", "SimSun", serif; letter-spacing: 2px; opacity: .12; }
.bg-art .ba-fml  { fill: currentColor; font: 15px "Cambria Math", "Times New Roman", "Songti SC", serif; letter-spacing: .4px; opacity: .11; }
.bg-art .ba-sym  { fill: currentColor; font: 62px "Cambria Math", "Times New Roman", "Songti SC", serif; opacity: .055; }
[data-theme="dark"] .bg-art .ba-lbl { opacity: .16; }
[data-theme="dark"] .bg-art .ba-fml { opacity: .15; }
[data-theme="dark"] .bg-art .ba-sym { opacity: .085; }
[data-theme="dark"] .bg-art .ba-line { opacity: .18; }
[data-theme="dark"] .bg-art .ba-dot { opacity: .2; }

/* ===================== 顶栏 ===================== */
.site-head {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(1.5) blur(12px);
  -webkit-backdrop-filter: saturate(1.5) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color .3s var(--ease), background .3s var(--ease);
}
.site-head.stuck { border-bottom-color: var(--line); }
.head-in {
  max-width: var(--maxw); margin: 0 auto; height: var(--header-h);
  padding: 0 22px; display: flex; align-items: center; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark {
  width: 34px; height: 34px; flex: none; display: block;
  filter: drop-shadow(0 4px 10px rgba(24, 20, 64, .28));
}
.brand-txt { display: flex; flex-direction: column; line-height: 1.2; }
.brand-txt b { font-size: 16px; letter-spacing: 1px; }
.brand-txt span { font-size: 10px; letter-spacing: 2.4px; color: var(--muted); text-transform: uppercase; }

.nav { display: flex; align-items: center; gap: 4px; }
.nav a {
  padding: 7px 12px; border-radius: 8px; font-size: 14.5px; color: var(--ink-2);
  transition: background .18s, color .18s;
}
.nav a:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink); }
.head-tools { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
  transition: border-color .18s, color .18s, transform .18s;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 17px; height: 17px; }
[data-theme="dark"] .icon-btn .sun { display: block; }
[data-theme="dark"] .icon-btn .moon { display: none; }
.icon-btn .sun { display: none; }
.icon-btn .moon { display: block; }

/* ===================== 通用容器 ===================== */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 22px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; letter-spacing: 2px; color: var(--muted); text-transform: uppercase;
}
.eyebrow::before { content: ""; width: 22px; height: 1px; background: currentColor; opacity: .6; }
.sec-title { font-size: clamp(20px, 2.6vw, 25px); letter-spacing: 1px; margin-bottom: 20px; }

/* ===================== 标题区 ===================== */
.hero { padding: clamp(48px, 8vw, 96px) 0 clamp(26px, 4vw, 40px); }
.hero-slim { text-align: center; }
.hero-slim .wrap { display: flex; flex-direction: column; align-items: center; }
.hero-slim h1 {
  margin: 16px 0 0;
  font-size: clamp(40px, 7vw, 66px); letter-spacing: 8px; line-height: 1.12; text-indent: 8px;
  background: linear-gradient(100deg, var(--brand) 0%, var(--brand-2) 45%, #e07a1f 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-motto { margin-top: 12px; font: 400 clamp(16px, 2vw, 20px)/1.6 "Songti SC", "SimSun", serif; letter-spacing: 5px; color: var(--gold); }
.hero-desc { margin-top: 14px; max-width: 34ch; color: var(--ink-2); font-size: 15.5px; }
.hero-cta { margin-top: 26px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: center; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 12px 22px; border-radius: 13px; font-size: 15px; font-weight: 600;
  border: 1px solid transparent; transition: transform .18s var(--ease), box-shadow .22s, background .2s, border-color .2s;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%); color: #fff;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 32%, transparent);
}
.btn-primary:hover { box-shadow: 0 10px 26px color-mix(in srgb, var(--brand) 42%, transparent); transform: translateY(-2px); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn .k { font-size: 11.5px; opacity: .72; font-weight: 500; }

/* ===================== 数据总览 ===================== */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--r-m); overflow: hidden;
  box-shadow: var(--shadow-s);
}
.stat { background: var(--surface); padding: 20px 16px; text-align: center; }
.stat b { display: block; font-size: clamp(24px, 3vw, 32px); font-weight: 700; letter-spacing: .5px; font-variant-numeric: tabular-nums; }
.stat span { display: block; margin-top: 4px; font-size: 12.5px; color: var(--muted); letter-spacing: .6px; }

/* ===================== 课程卡片 ===================== */
.courses { padding: clamp(44px, 6vw, 76px) 0 clamp(40px, 6vw, 72px); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }

.course {
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l);
  box-shadow: var(--shadow-s); padding: 26px 26px 24px;
  transition: transform .28s var(--ease), box-shadow .28s var(--ease), border-color .28s;
}
.course::before {
  content: ""; position: absolute; inset: 0 0 auto; height: 5px;
  background: linear-gradient(90deg, var(--c), var(--c2) 70%, color-mix(in srgb, var(--c) 40%, transparent));
}
.course::after {
  content: ""; position: absolute; right: -70px; top: -90px; width: 260px; height: 260px;
  border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--c) 16%, transparent), transparent 70%);
  pointer-events: none; transition: opacity .3s;
}
.course:hover { transform: translateY(-5px); box-shadow: var(--shadow-l); border-color: color-mix(in srgb, var(--c) 34%, var(--line)); }

.cc-top { position: relative; display: flex; align-items: center; gap: 14px; }
.cc-ic {
  width: 52px; height: 52px; flex: none; border-radius: 15px; display: grid; place-items: center;
  color: #fff; background: linear-gradient(135deg, var(--c), var(--c2));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--c) 32%, transparent);
}
.cc-ic svg { width: 29px; height: 29px; }
.cc-tt { flex: 1; min-width: 0; }
.cc-tt h3 { font-size: 21px; letter-spacing: .5px; }
.cc-tt p { margin-top: 4px; font-size: 13px; color: var(--muted); }

.cc-metrics {
  position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 22px;
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: var(--r-s); padding: 12px 6px;
}
.cc-metrics li { text-align: center; border-right: 1px solid var(--line-2); }
.cc-metrics li:last-child { border-right: 0; }
.cc-metrics b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; letter-spacing: .3px; }
.cc-metrics span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 1px; }

.cc-acts { position: relative; display: flex; gap: 10px; margin-top: 22px; }
.cc-acts .btn { flex: 1; }
.cc-acts .btn-ghost { flex: 0 0 auto; }
.course .btn-primary { background: linear-gradient(135deg, var(--c), var(--c2)); box-shadow: 0 6px 18px color-mix(in srgb, var(--c) 30%, transparent); }
.course .btn-primary:hover { box-shadow: 0 10px 26px color-mix(in srgb, var(--c) 40%, transparent); }

/* 出场动画 */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity .7s var(--ease), transform .7s var(--ease); }
.reveal.in { opacity: 1; transform: none; }

/* ===================== 页脚 ===================== */
.site-foot { border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.foot-in {
  max-width: var(--maxw); margin: 0 auto; padding: 28px 22px 38px;
  display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: center; justify-content: center;
}
.foot-in p { font-size: 13px; color: var(--muted); line-height: 1.9; }
.foot-brand { display: flex; align-items: center; gap: 13px; }
.foot-brand img { flex: none; display: block; border-radius: 10px; }
.foot-in .sig { font: 400 17px/1.4 "Songti SC", "SimSun", serif; letter-spacing: 3px; color: var(--ink); }

/* ===================== 课程阅读器 ===================== */
.viewer {
  position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column;
  background: var(--paper); animation: viewerIn .3s var(--ease);
}
@keyframes viewerIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.viewer-bar {
  flex: none; height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 12px 0 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 12px rgba(0, 0, 0, .05);
}
.vb-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 13px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  font-size: 14px; color: var(--ink-2); white-space: nowrap;
  transition: border-color .18s, color .18s, background .18s;
}
.vb-btn:hover { border-color: var(--c); color: var(--c); background: var(--surface); }
.vb-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; }
.vb-title .bar2 { width: 3px; height: 17px; border-radius: 2px; background: linear-gradient(var(--c), var(--c2)); flex: none; }
.vb-title b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vb-title span { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
@media (max-width: 760px) { .vb-title span { display: none; } }
.vb-stage { position: relative; flex: 1; min-height: 0; background: var(--paper); }
.vb-stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: var(--paper); }

.vb-load {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: var(--paper); z-index: 2; padding: 30px;
}
.vb-load .box { max-width: 380px; }
.spinner {
  width: 38px; height: 38px; margin: 0 auto 18px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--c); animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.vb-load b { display: block; font-size: 16px; }
.vb-load p { margin-top: 8px; font-size: 13px; color: var(--muted); line-height: 1.8; }
.vb-load.hide { opacity: 0; pointer-events: none; transition: opacity .3s; }

/* ===================== 响应式 ===================== */
@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .nav { display: none; }
}
@media (max-width: 560px) {
  :root { --header-h: 58px; }
  .wrap { padding: 0 16px; }
  .head-in { padding: 0 16px; }
  .hero-slim h1 { letter-spacing: 5px; text-indent: 5px; }
  .hero-desc { max-width: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat { padding: 16px 10px; }
  /* 5 项排 2 列会空出一格，让最后一项独占整行 */
  .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .course { padding: 22px 18px 20px; border-radius: var(--r-m); }
  .cc-metrics { grid-template-columns: repeat(2, 1fr); row-gap: 12px; }
  .cc-metrics li:nth-child(2n) { border-right: 0; }
  .cc-acts { flex-direction: column; }
  .cc-acts .btn { width: 100%; }
  .vb-btn .txt { display: none; }
  .vb-btn { padding: 0 11px; }
}

/* ===================== 打印 / 动效偏好 ===================== */
@media print {
  .site-head, .viewer-bar, .aurora, .hero-cta { display: none !important; }
  body { background: #fff; }
  .course { break-inside: avoid; box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .reveal { opacity: 1; transform: none; }
}
