/* ==========================================================
   课件公共样式：配色、排版、卡片、按钮、步进器、键盘
   约定：正数 = 暖橙（热），负数 = 冷蓝（冷），零 = 紫
   ========================================================== */
:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f5f0e8;
  --ink: #1f2433;
  --ink-2: #5d6476;
  --ink-3: #9096a5;
  --line: #ebe4d8;

  --pos: #f76707;
  --pos-soft: #fff0e3;
  --neg: #1c7ed6;
  --neg-soft: #e5f1fd;
  --zero: #7048e8;
  --zero-soft: #f0ecff;
  --ok: #2b8a3e;
  --ok-soft: #e9f9ec;
  --bad: #e03131;
  --bad-soft: #fff0f0;
  --hl: #ffe066;

  --radius: 22px;
  --shadow: 0 1px 2px rgba(31, 36, 51, .04), 0 8px 28px rgba(31, 36, 51, .06);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", "Segoe UI", Roboto, sans-serif;
  --font-num: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c;
    --surface: #1c1f27;
    --surface-2: #242833;
    --ink: #eceef3;
    --ink-2: #a9afbd;
    --ink-3: #727888;
    --line: #2d313c;
    --pos: #ff922b;
    --pos-soft: #3a2614;
    --neg: #4dabf7;
    --neg-soft: #12293d;
    --zero: #9775fa;
    --zero-soft: #29213f;
    --ok: #51cf66;
    --ok-soft: #15301c;
    --bad: #ff6b6b;
    --bad-soft: #3a1a1a;
    --hl: #8a6d00;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.7 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: .01em; }
p { margin: .5em 0; }
a { color: inherit; }
button { font: inherit; color: inherit; }
b, strong { font-weight: 700; }
mark { background: var(--hl); color: inherit; border-radius: 4px; padding: 0 .1em; }

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

.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px; }
@media (max-width: 480px) { .wrap { padding: 0 10px; } }

/* ---------- 顶栏 + 章节导航 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 10px; height: 48px; }
.topbar .back { text-decoration: none; color: var(--ink-2); font-size: 14px; white-space: nowrap; padding: 6px 0; }
.topbar .title { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .progress { position: absolute; left: 0; bottom: -1px; height: 2px; width: 0; background: var(--ink); transition: width .1s linear; }
.secnav {
  display: flex; gap: 6px; overflow-x: auto; padding: 0 0 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.secnav::-webkit-scrollbar { display: none; }
.secnav a {
  flex: none; text-decoration: none; font-size: 13.5px; color: var(--ink-2);
  padding: 5px 12px; border-radius: 999px; background: var(--surface-2);
  transition: background .2s, color .2s;
}
.secnav a.active { background: var(--ink); color: var(--bg); }

/* ---------- 卡片 / 章节 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 22px;
  margin: 18px 0;
}
@media (max-width: 480px) { .card { padding: 20px 14px; border-radius: 18px; margin: 12px 0; } }
section.card { scroll-margin-top: 104px; }
.sec-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.sec-no {
  flex: none; width: 34px; height: 34px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--ink); color: var(--bg);
  font: 700 17px/1 var(--font-num);
}
.sec-head h2 { font-size: 22px; margin-top: 3px; }
.lead { color: var(--ink-2); margin: 4px 0 0; }
.sub { font-size: 17px; margin: 22px 0 8px; display: flex; align-items: center; gap: 8px; }
.sub::before { content: ""; width: 4px; height: 1em; border-radius: 2px; background: var(--ink); }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.center { text-align: center; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 20px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 16px; cursor: pointer; user-select: none;
  transition: transform .12s, background .2s, opacity .2s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.soft { background: var(--surface-2); border-color: transparent; }
.btn.sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }

.pill {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font: 600 15px/1 var(--font-num); cursor: pointer; touch-action: manipulation;
  transition: background .2s, border-color .2s;
}
.pill:active { transform: scale(.96); }
.pill.on { border-color: var(--ink); background: var(--surface-2); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* ---------- 数字着色 ---------- */
.n { font-family: var(--font-num); font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.n.pos { color: var(--pos); }
.n.neg { color: var(--neg); }
.n.zero { color: var(--zero); }
.op { margin: 0 .28em; color: var(--ink-2); font-weight: 600; font-family: var(--font-num); }
.n .op { color: inherit; }
.frac {
  display: inline-flex; flex-direction: column; align-items: stretch;
  vertical-align: middle; text-align: center; font-size: .78em; line-height: 1.12; margin: 0 .06em;
}
.frac > span:first-child { border-bottom: .09em solid currentColor; padding: 0 .18em .04em; }
.frac > span:last-child { padding-top: .04em; }
.sb {
  display: inline-grid; place-items: center; width: 1.45em; height: 1.45em; border-radius: 50%;
  font: 800 .95em/1 var(--font-num); color: #fff; vertical-align: -.2em;
}
.sb.pos { background: var(--pos); }
.sb.neg { background: var(--neg); }

/* 大号算式 */
.eq {
  font: 700 28px/1.35 var(--font-num); text-align: center; margin: 14px 0;
  min-height: 1.4em; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0 2px;
}
@media (max-width: 480px) { .eq { font-size: 24px; } }
.eq .q { color: var(--ink-3); }
.eq .res { display: inline-block; animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }

/* ---------- 步进器 ---------- */
.ctl { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ctl > span { font-size: 13px; color: var(--ink-2); }
.controls { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center; gap: 8px 10px; }
.controls > .op { font-size: 24px; padding-bottom: 8px; margin: 0; }
.stepper {
  display: inline-flex; align-items: stretch; height: 46px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow: hidden;
}
.stepper button {
  width: 40px; border: 0; background: var(--surface-2); font-size: 22px; font-weight: 600;
  cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.stepper button:active { background: var(--line); }
.stepper button:disabled { opacity: .3; cursor: default; }
.stepper output {
  min-width: 60px; display: flex; align-items: center; justify-content: center; padding: 0 4px;
  font: 700 22px/1 var(--font-num); white-space: nowrap;
}
@media (max-width: 400px) {
  .controls { gap: 8px 6px; }
  .controls > .op { font-size: 20px; }
  .stepper button { width: 36px; }
  .stepper output { min-width: 50px; font-size: 20px; }
  details.more { padding: 0 10px; }
}

/* ---------- 折叠块 ---------- */
details.more {
  margin-top: 16px; border-radius: 16px; background: var(--surface-2); padding: 0 16px;
}
details.more > summary {
  cursor: pointer; list-style: none; padding: 13px 0; font-weight: 600; display: flex; align-items: center; gap: 8px;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: "展开"; margin-left: auto; font-size: 13px; color: var(--ink-2); font-weight: 400; }
details.more[open] > summary::after { content: "收起"; }
details.more > .body { padding: 0 0 16px; }

/* ---------- 动画 ---------- */
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.rise { animation: rise .4s ease both; }
.shake { animation: shake .4s; }
.confetti { position: fixed; z-index: 99; width: 9px; height: 13px; border-radius: 2px; pointer-events: none; }

/* ---------- 数字键盘 ---------- */
.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 380px; margin: 0 auto; }
.keypad button {
  height: 52px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  font: 700 22px/1 var(--font-num); cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: transform .08s, background .15s;
}
.keypad button:active { transform: scale(.94); background: var(--surface-2); }
.keypad .k-fn { background: var(--surface-2); font-size: 18px; }
.keypad .k-ok { grid-column: span 2; background: var(--ink); color: var(--bg); border-color: var(--ink); font-family: var(--font); font-size: 18px; }

/* ---------- 页脚 ---------- */
.foot { text-align: center; color: var(--ink-3); font-size: 13px; padding: 28px 0 calc(36px + env(safe-area-inset-bottom)); }
