:root {
  --bg: #0A0A0A;
  --surface: #141414;
  --surface-2: #121212;
  --surface-3: #1C1C1C;
  --border: #242424;
  --border-2: #2A2A2A;
  --text: #F2F2F2;
  --text-2: #CFCFCF;
  --muted: #A3A3A3;
  --accent: #9BD13B;
  --accent-text: #B7E36A;
  --accent-bg: #16220A;
  --accent-dim: #5E7F25;
  --accent-border: #3D5A12;
  --on-accent: #0A0A0A;
  --err-border: #E8604C;
  --err-text: #FF8A78;
  --err-bg: #2A1310;
  --warn-border: #E0A33A;
  --warn-text: #F2C46B;
  --warn-bg: #2A1F0A;
  --radius: 14px;
  --font: Inter, "Noto Sans SC", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --surface-2: #FFFFFF;
  --surface-3: #EFEFEC;
  --border: #E4E4E0;
  --border-2: #D6D6D1;
  --text: #141414;
  --text-2: #2E2E2E;
  --muted: #5F5F5A;
  --accent: #5C8A12;
  --accent-text: #3F6B00;
  --accent-bg: #EEF6DF;
  --accent-dim: #9DBB5F;
  --accent-border: #B5D07A;
  --on-accent: #FFFFFF;
  --err-border: #C8412D;
  --err-text: #B3321F;
  --err-bg: #FCEAE6;
  --warn-border: #C4861C;
  --warn-text: #8A5A00;
  --warn-bg: #FFF3DC;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; }
a { color: var(--accent-text); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code { background: var(--surface-3); padding: 1px 6px; border-radius: 6px; font-size: 0.9em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { max-width: 640px; margin: 0 auto; min-height: 100vh; position: relative; }
.page { padding-bottom: 96px; }
.page.has-nav { padding-bottom: 168px; }
.loading { padding: 40vh 20px 0; text-align: center; color: var(--muted); }

.pad { padding: 12px 20px; }
.pad-sm { padding: 12px 14px; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-lg { display: flex; flex-direction: column; gap: 22px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 2px; }
.grow { flex: 1; min-width: 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid2.tight { gap: 12px; flex: 1; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.center { text-align: center; }

.h1 { margin: 0; font-size: 24px; font-weight: 700; }
.label { margin: 0; font-size: 13px; color: var(--muted); font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.accent { color: var(--accent-text); }
.err { color: var(--err-text); }
.warn-text { color: var(--warn-text); }
.big { font-size: 26px; }

.home-head { padding: 24px 20px 8px; display: flex; justify-content: space-between; align-items: center; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px; border-bottom: 1px solid var(--border); }
.topbar-main { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.topbar-row { display: flex; justify-content: space-between; font-size: 14px; gap: 8px; }
.topbar-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; background: none; border: none; color: var(--text); border-radius: 12px; }
.icon-btn.round { border: 1px solid var(--border-2); background: var(--surface); border-radius: 22px; }
.icon-btn.accent { color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; }
.card.list { padding: 0; display: flex; flex-direction: column; }
.overview { display: flex; gap: 18px; align-items: center; }
.ring-bg { stroke: var(--border-2); }
.ring-fg { stroke: var(--accent); }
.ring-text { fill: var(--text); font-size: 20px; font-weight: 700; font-family: var(--font); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 20px; }
.stat small { font-size: 12px; color: var(--muted); font-weight: 400; }

.cta { width: 100%; border: none; background: var(--accent); color: var(--on-accent); border-radius: var(--radius); padding: 16px 18px; display: flex; justify-content: space-between; align-items: center; text-align: left; min-height: 64px; }
.cta-title { font-size: 16px; font-weight: 700; }
.cta-sub { font-size: 12px; opacity: 0.8; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; color: var(--text); display: flex; flex-direction: column; gap: 4px; min-height: 64px; }
.tile b { font-size: 15px; font-weight: 600; }
.accent-border { border-color: var(--accent-border); }

.banner { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--accent-bg); color: var(--accent-text); border: 1px solid var(--accent-border); font-size: 14px; min-height: 44px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.banner.static { font-size: 13px; }

.bar { position: relative; height: 6px; background: var(--border); border-radius: 3px; }
.bar.thin { height: 4px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: inherit; transition: width .3s; }
.bar-fill.dim { background: var(--accent-dim); }
.dom-row { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.dom-row.off { opacity: 0.5; }
.bar-row { display: grid; grid-template-columns: 32px 1fr 44px 52px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .bar { height: 10px; border-radius: 5px; }
.bar-row > span:nth-child(3) { text-align: right; }
.bar-row.off { opacity: 0.5; }
.ref { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--muted); opacity: .7; }

.seg { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; gap: 4px; }
.seg-btn { flex: 1; min-height: 40px; border: none; border-radius: 9px; background: none; color: var(--text-2); font-size: 14px; padding: 0 8px; }
.seg-btn.on { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.small-seg { padding: 3px; }
.small-seg .seg-btn { min-height: 34px; padding: 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text-2); font-size: 14px; }
.chip.sq { border-radius: 10px; padding: 0; }
.chip.on { border: 1.5px solid var(--accent); background: var(--accent-bg); color: var(--accent-text); }
.chip:disabled { opacity: 0.4; cursor: not-allowed; }
.stepper { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px; }
.stepper button { width: 44px; height: 44px; border-radius: 10px; border: none; background: var(--surface-3); font-size: 22px; }
.stepper b { font-size: 24px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; min-height: 52px; border-bottom: 1px solid var(--border); font-size: 14px; }
.switch-row:last-child { border-bottom: none; }
.switch-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.switch-row input[type="date"], .switch-row select { background: var(--surface-3); border: 1px solid var(--border-2); border-radius: 8px; padding: 8px 10px; min-height: 40px; }

.btn { min-height: 50px; border-radius: 12px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; padding: 0 16px; text-align: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.btn.danger { color: var(--err-text); border-color: var(--err-border); background: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; font-size: 13px; padding: 0 12px; }
.btn:disabled, .btn.disabled { opacity: 0.4; pointer-events: none; }
.file-btn { cursor: pointer; }
.link-btn { background: none; border: none; color: var(--err-text); font-size: 12px; padding: 4px; text-decoration: underline; }
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; max-width: 640px; margin: 0 auto; padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--border); }
.has-nav + .tabbar ~ .bottom-bar, .page.has-nav .bottom-bar { bottom: calc(72px + env(safe-area-inset-bottom)); }
.bottom-bar.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bottom-bar.grid3x { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 10px; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; max-width: 640px; margin: 0 auto; height: calc(72px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--bg); border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tabbar a { color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 11px; }
.tabbar a.on { color: var(--accent); }

.tags { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; }
.tag { padding: 4px 10px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border-2); font-size: 12px; }
.accent-tag { background: var(--accent-bg); color: var(--accent-text); border-color: var(--accent-border); }
.warn-tag { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); align-self: flex-start; }
.stem { margin: 0; font-size: 17px; line-height: 1.7; font-weight: 500; white-space: pre-line; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt { width: 100%; text-align: left; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text); border-radius: 12px; padding: 14px; display: flex; gap: 12px; align-items: flex-start; font-size: 15px; line-height: 1.55; min-height: 52px; }
.opt-letter { font-weight: 700; color: var(--muted); min-width: 14px; }
.opt-text { flex: 1; }
.opt .mark { flex: none; margin-top: 1px; }
.opt.selected { border: 1.5px solid var(--text-2); background: var(--surface-3); }
.opt.selected .opt-letter { color: var(--text); }
.opt.correct { border: 1.5px solid var(--accent); background: var(--accent-bg); }
.opt.correct .opt-letter, .opt.correct .mark { color: var(--accent-text); }
.opt.wrong { border: 1.5px solid var(--err-border); background: var(--err-bg); }
.opt.wrong .opt-letter, .opt.wrong .mark { color: var(--err-text); }
.opt[aria-disabled="true"] { cursor: default; }
.result-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 14px; border-radius: 12px; background: var(--surface); font-size: 14px; flex-wrap: wrap; }
.result-bar.ok { color: var(--accent-text); }
.exp { display: flex; gap: 10px; font-size: 14px; line-height: 1.65; color: var(--text-2); }
.exp-ok { background: var(--accent-bg); color: var(--text); border-radius: 10px; padding: 10px; }
.exp-letter { font-weight: 700; min-width: 16px; color: var(--muted); }
.supp p { margin: 0; }
.supp p:not(.small) { font-size: 14px; line-height: 1.7; color: var(--text-2); }
.crm { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; font-size: 13px; color: var(--text-2); }
.crm svg { color: var(--accent); flex: none; }
.note { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
.note textarea { min-height: 72px; background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 12px; color: var(--text); padding: 12px; font-size: 14px; resize: vertical; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 48px; border: none; border-bottom: 1px solid var(--border); background: none; color: var(--text); text-align: left; font-size: 14px; width: 100%; }
.list-row:last-child { border-bottom: none; }
.card.list-row { border: 1px solid var(--border); }

.exam-top { gap: 10px; }
.timer { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border-2); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 16px; }
.timer svg { color: var(--accent); }
.timer.warn { border-color: var(--warn-border); color: var(--warn-text); background: var(--warn-bg); }
.timer.warn svg { color: var(--warn-text); }
.flag-btn { min-height: 40px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text-2); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.flag-btn.on { border-color: var(--warn-border); background: var(--warn-bg); color: var(--warn-text); }
.answer-card { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; }
.cells { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; }
.cell { height: 34px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 11px; padding: 0; }
.cell.done { background: var(--accent-border); color: var(--text); border-color: var(--accent-border); }
[data-theme="light"] .cell.done { color: #1F3300; }
.cell.flag { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.cell.cur { outline: 2px solid var(--text); outline-offset: -2px; color: var(--text); }

.spark { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 4px; height: 110px; align-items: end; }
.day { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; font-size: 10px; color: var(--muted); }
.day-bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.errs { margin: 0; padding-left: 18px; color: var(--err-text); }

#toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 20; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* CRM 参考书：页码链接、选择文件弹层、App 内阅读器 */
.crm-link { background: none; border: none; padding: 2px 0; margin: 0 1px; font: inherit; color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.crm-link:hover { color: var(--accent); }
.crm-file { min-width: 0; overflow-wrap: anywhere; }
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.55); }
.sheet { position: fixed; z-index: 41; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(460px, calc(100% - 32px)); box-sizing: border-box; }
.sheet p { margin: 0; }
.sheet .link-btn { color: var(--muted); font-size: 14px; }
.crm-overlay { position: fixed; inset: 0; z-index: 50; background: var(--bg); }
.crm-overlay iframe { width: 100%; height: 100%; border: 0; display: block; }
body.no-scroll { overflow: hidden; }

/* 中 / EN 切换 */
.row-sm { display: inline-flex; align-items: center; gap: 8px; }
.lang-toggle { display: inline-flex; padding: 2px; border-radius: 999px; border: 1px solid var(--border-2); background: var(--surface-3); font-size: 12px; font-weight: 600; margin-left: auto; }
.lang-toggle span { padding: 3px 10px; border-radius: 999px; color: var(--muted); }
.lang-toggle span.on { background: var(--accent); color: var(--on-accent); }
.row-sm .lang-toggle { margin-left: 0; }
.stem[lang="en"] { hyphens: auto; }

/* Ask for Claude */
.ask { display: flex; flex-direction: column; gap: 6px; }
.ask-btn { gap: 8px; text-decoration: none; }
.ask-btn svg { color: var(--accent); }
.ask p { margin: 0; }
