/* 数学自习室 v1.3.1 — 玩转数学 · 双主题 */
:root, [data-theme="dark"] {
  --bg: #0e1420;
  --panel: #161e2e;
  --panel2: #1d2739;
  --ink: #ece7da;
  --sub: #96a0b5;
  --amber: #ffb454;
  --amber-ink: #2a1a04;
  --amber-soft: rgba(255, 180, 84, .13);
  --line: #243048;
  --green: #43d19e;
  --green-soft: rgba(67, 209, 158, .13);
  --red: #ff6b6b;
  --red-soft: rgba(255, 107, 107, .13);
  --navbg: rgba(14, 20, 32, .88);
}
[data-theme="light"] {
  --bg: #f4efe4;
  --panel: #fffdf6;
  --panel2: #f0e9d8;
  --ink: #2b2822;
  --sub: #837d6f;
  --amber: #b25e00;
  --amber-ink: #fffdf6;
  --amber-soft: rgba(178, 94, 0, .10);
  --line: #e4dbc8;
  --green: #0f9d63;
  --green-soft: rgba(15, 157, 99, .12);
  --red: #d64545;
  --red-soft: rgba(214, 69, 69, .10);
  --navbg: rgba(244, 239, 228, .92);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(72px + env(safe-area-inset-bottom)); }
a { color: var(--amber); }
button { font-family: inherit; }

/* ---------- 首页头部 ---------- */
.hero { padding: 26px 2px 14px; background: radial-gradient(560px 180px at 18% -10%, var(--amber-soft), transparent 72%); }
.hero .brandrow { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 42px; height: 42px; border-radius: 13px;
  background: var(--amber); color: var(--amber-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; font-weight: 800; flex: 0 0 42px;
}
.hero h1 { font-size: 22px; margin: 0; letter-spacing: 1px; }
.hero .sub { font-size: 12.5px; color: var(--sub); margin-top: 2px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.chip {
  font-size: 12px; padding: 4px 11px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--sub);
}
.chip b { color: var(--amber); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- 卡片 ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin: 12px 0; }
.card h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--sub); font-size: 13.5px; line-height: 1.6; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel2);
  color: var(--ink); border-radius: 12px; padding: 10px 14px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform .08s ease;
}
.btn.primary { background: var(--amber); border-color: transparent; color: var(--amber-ink); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; padding: 12px; font-size: 15px; }
.btn:active { transform: scale(.985); }
.btn.danger { color: var(--red); }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row .btn { flex: 1; }

/* ---------- 章节 ---------- */
.chap-head { display: flex; align-items: center; gap: 11px; }
.chap-idx {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 34px;
  background: var(--panel2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--amber); font-size: 15px;
}
.chap-name { font-weight: 700; font-size: 16px; line-height: 1.3; }
.chap-tag { font-size: 11px; color: var(--sub); margin-top: 2px; }
.chap-head .stars { margin-left: auto; color: var(--amber); font-size: 13px; letter-spacing: 2px; white-space: nowrap; }
.chap-blurb { font-size: 13px; color: var(--sub); margin-top: 8px; }
.chap-meta { font-size: 12px; color: var(--sub); margin-top: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; }

/* ---------- 顶栏 / 进度 ---------- */
.top { display: flex; align-items: center; gap: 10px; padding: 14px 0 4px; }
.back {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 34px;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  font-size: 17px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.top h2 { font-size: 16.5px; margin: 0; font-weight: 700; }
.top .cnt { margin-left: auto; color: var(--sub); font-size: 13px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.progress { height: 4px; background: var(--panel2); border-radius: 99px; overflow: hidden; margin: 8px 0 14px; }
.progress i { display: block; height: 100%; width: 0; background: var(--amber); border-radius: 99px; transition: width .25s ease; }

/* ---------- 题目 ---------- */
.qchips { display: flex; gap: 6px; flex-wrap: wrap; }
.qchip {
  font-size: 11px; color: var(--sub); background: var(--panel2);
  border: 1px solid var(--line); padding: 2px 9px; border-radius: 99px; display: inline-block;
}
.qchip.adv { color: var(--amber); }
.qtext { font-size: 19px; line-height: 1.62; font-weight: 650; margin: 12px 0 16px; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; text-align: left; width: 100%;
  padding: 13px 14px; border-radius: 14px; background: var(--panel);
  border: 1.5px solid var(--line); color: var(--ink);
  font-size: 16px; line-height: 1.5; cursor: pointer;
  transition: transform .08s ease;
}
.opt:active { transform: scale(.99); }
.opt .key {
  flex: 0 0 26px; height: 26px; border-radius: 8px; margin-top: 1px;
  background: var(--panel2); color: var(--sub);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; font-family: ui-monospace, Menlo, Consolas, monospace;
}
.opt.ok { border-color: var(--green); background: var(--green-soft); }
.opt.ok .key { background: var(--green); color: #fff; }
.opt.bad { border-color: var(--red); background: var(--red-soft); }
.opt.bad .key { background: var(--red); color: #fff; }
.opt.dim { opacity: .5; }
.opt.shake { animation: shake .3s ease; }

.feedback {
  margin-top: 14px; border-left: 3px solid var(--amber);
  background: var(--panel2); border-radius: 12px; padding: 14px;
  animation: rise .25s ease;
}
.feedback.ok { border-color: var(--green); }
.feedback.bad { border-color: var(--red); }
.fb-head { font-weight: 700; margin-bottom: 6px; font-size: 14.5px; }
.fb-head.ok { color: var(--green); }
.fb-head.bad { color: var(--red); }
.fb-expl { font-size: 14.5px; line-height: 1.68; }
.hist {
  margin-top: 10px; font-size: 12.5px; color: var(--sub); line-height: 1.65;
  border-top: 1px dashed var(--line); padding-top: 8px;
}
.think {
  margin-top: 8px; font-size: 12.5px; line-height: 1.7; color: var(--amber);
  border-top: 1px dashed var(--line); padding-top: 8px;
}
#view .next-wrap { margin-top: 14px; }

/* ---------- 结算 ---------- */
.result { text-align: center; padding: 28px 0 8px; animation: rise .3s ease; }
.result .big { font-size: 46px; font-weight: 800; font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--amber); line-height: 1.1; }
.result .lbl { color: var(--sub); font-size: 13.5px; margin-top: 6px; }

/* ---------- 考点 / 史话 ---------- */
.pts { margin: 10px 0 0; padding: 0; list-style: none; }
.pts li { position: relative; padding: 9px 0 9px 22px; font-size: 14.5px; line-height: 1.66; border-bottom: 1px dashed var(--line); }
.pts li:last-child { border-bottom: 0; }
.pts li::before {
  content: ''; position: absolute; left: 4px; top: 17px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--amber);
}
.story h2 { font-size: 20px; margin: 10px 0 12px; line-height: 1.4; }
.story .body { font-size: 16px; line-height: 1.95; text-align: justify; }
.story .src { font-size: 12px; color: var(--sub); margin-top: 16px; }

.empty { text-align: center; padding: 40px 18px; color: var(--sub); font-size: 14px; line-height: 1.9; }

/* ---------- 每日典故 ---------- */
.lore-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mini-btn {
  font-size: 12px; color: var(--amber); background: none;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 11px; cursor: pointer; white-space: nowrap;
}
.lore-txt { font-size: 14px; line-height: 1.78; margin-top: 8px; }

/* ---------- 我的 ---------- */
.title-name { font-size: 23px; font-weight: 800; color: var(--amber); }
.bar { height: 6px; background: var(--panel2); border-radius: 99px; margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--amber); border-radius: 99px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; padding: 10px 0; background: transparent; border: 0; color: var(--sub); font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--amber); color: var(--amber-ink); font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stat b { font-size: 21px; display: block; font-family: ui-monospace, Menlo, Consolas, monospace; }
.stat span { font-size: 12px; color: var(--sub); }
.about p { font-size: 12.5px; color: var(--sub); line-height: 1.7; margin: 6px 0; }

/* ---------- 底部导航 ---------- */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 560px; margin: 0 auto; display: flex;
  background: var(--navbg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; background: none; border: 0; color: var(--sub);
  padding: 9px 0 7px; font-size: 11px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; position: relative;
}
.nav-btn svg { width: 21px; height: 21px; }
.nav-btn.on { color: var(--amber); }
.nav-badge {
  position: absolute; top: 3px; right: calc(50% - 20px);
  min-width: 16px; height: 16px; border-radius: 99px;
  background: var(--red); color: #fff; font-size: 10px; line-height: 16px;
  padding: 0 4px; font-weight: 700;
}

/* ---------- 动画 ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

@media (min-width: 600px) {
  .hero { padding-top: 38px; }
}

/* ---------- 学习范围 ---------- */
.chap-off { opacity: .55; }
.scope-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; font-size: 13px; color: var(--sub);
}
.scope-chip {
  appearance: none; border: 1px solid var(--line); background: var(--panel2);
  color: var(--ink); border-radius: 999px; padding: 6px 15px;
  font-size: 13px; cursor: pointer; font-family: inherit;
}
.scope-chip.on { background: var(--amber); color: var(--amber-ink); border-color: transparent; font-weight: 700; }

/* ---------- 打开即推（底部弹层） ---------- */
.scrim { position: fixed; inset: 0; z-index: 90; background: rgba(5, 9, 17, .55); animation: fade .22s ease; }
[data-theme="light"] .scrim { background: rgba(43, 40, 34, .32); }
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 95;
  width: 100%; max-width: 560px;
  background: var(--panel); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 84vh; overflow: auto;
  animation: sheetup .3s cubic-bezier(.2, .8, .3, 1);
}
.sheet .grab { width: 38px; height: 4px; border-radius: 99px; background: var(--line); margin: 0 auto 14px; }
.sheet .qtext { font-size: 17px; margin: 10px 0 12px; }
.sheet .row { margin-top: 14px; }
@keyframes sheetup { from { transform: translate(-50%, 48px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .scrim, .sheet { animation: none; } }
.scrim.noanim, .sheet.noanim { animation: none; }

/* ---------- v1.4.0 图形层：内联 SVG 图像与图形试验台 ---------- */
.zx-fig { margin: 10px 2px 2px; background: var(--panel2); border-radius: 10px; padding: 8px 6px 4px; }
.zx-fig .plot, .lab-svg { width: 100%; height: auto; display: block; }
.fig-cap { color: var(--sub); font-size: 12px; line-height: 1.55; padding: 7px 4px 2px; }
.plot text, .lab-svg text { font-family: inherit; }
.plot .grid-line, .lab-svg .grid-line { stroke: var(--line); stroke-width: .6; opacity: .5; }
.plot .axis, .lab-svg .axis { stroke: var(--sub); stroke-width: 1.1; opacity: .95; }
.plot .asym, .lab-svg .asym { stroke: var(--sub); stroke-width: 1; stroke-dasharray: 4 4; opacity: .6; fill: none; }
.plot .c-amber, .lab-svg .c-amber { stroke: var(--amber); stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.plot .c-green, .lab-svg .c-green { stroke: var(--green); stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.plot .c-sub, .lab-svg .c-sub { stroke: var(--sub); stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.plot .c-ghost, .lab-svg .c-ghost { stroke: var(--sub); stroke-width: 1.4; fill: none; stroke-dasharray: 5 5; opacity: .65; }
.plot .d-amber, .lab-svg .d-amber { fill: var(--amber); stroke: var(--panel2); stroke-width: 1.5; }
.plot .d-sub, .lab-svg .d-sub { fill: var(--sub); }
.plot .t-amber, .lab-svg .t-amber { fill: var(--amber); font-size: 11px; }
.plot .t-sub, .lab-svg .t-sub { fill: var(--sub); font-size: 11px; }
.plot .t-green, .lab-svg .t-green { fill: var(--green); font-size: 11px; }
.lab-svg { background: var(--panel2); border-radius: 10px; }
.krow { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.krow .klabel { color: var(--sub); font-size: 13px; }
.krow input[type=range] { flex: 1; accent-color: var(--amber); margin: 0; min-width: 0; }
.krow .val { color: var(--amber); font-weight: 600; font-variant-numeric: tabular-nums; font-size: 13px; min-width: 5.8em; text-align: right; white-space: nowrap; }
.lab-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.lab-chip { appearance: none; border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 999px; padding: 7px 13px; font-size: 13px; font-family: inherit; cursor: pointer; white-space: nowrap; }
.lab-chip[aria-pressed="true"] { background: var(--amber); color: var(--amber-ink); border-color: var(--amber); font-weight: 600; }

/* ---------- v1.5.0 详细图文讲解 ---------- */
.wstep { display: flex; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); margin-top: 10px; }
.wstep.on { border-color: var(--amber); background: var(--amber-soft); }
.wstep-i { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--panel2); color: var(--sub); font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; margin-top: 2px; }
.wstep.on .wstep-i { background: var(--amber); color: var(--amber-ink); }
.wstep-b { flex: 1; min-width: 0; font-size: 14px; line-height: 1.65; }
.wdis { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13px; line-height: 1.6; color: var(--sub); }
.wdis:last-child { border-bottom: none; }
.wkey { flex: none; border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; font-size: 12px; color: var(--amber); height: fit-content; margin-top: 1px; }
.wrong-row { padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; color: var(--sub); }
.wrong-row.tappable { color: var(--ink); cursor: pointer; }
.wrong-row.tappable:active { background: var(--amber-soft); }

/* ---------- v1.7.2 底部恒定播放条 ---------- */
.xw-bar {
  position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 45;
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 7px 12px;
  background: var(--navbg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.xw-big {
  flex: none; width: 46px; height: 46px; border-radius: 50%;
  background: var(--amber); color: var(--amber-ink);
  border: 0; font-size: 15px; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; appearance: none; -webkit-appearance: none;
  transition: transform .12s ease;
}
.xw-big:active { transform: scale(.93); }
.xw-bar .lab-chip { padding: 6px 10px; font-size: 12px; }
.xw-cnt { color: var(--ink); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 3.4em; text-align: center; }
.xw-spacer { height: calc(64px + env(safe-area-inset-bottom)); }
