:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e4e6eb;
  --text: #1d2129;
  --muted: #86909c;
  --accent: #1e6fff;
  --up: #d92e2e;
  --down: #1aaa5b;
  --warn-bg: #fff7e6;
  --warn-bd: #ffd591;
  --note-bg: #eef4ff;
  --tip-bg: #e9f9f0;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 8px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.12);
  --radius: 8px;
}
:root.dark {
  --bg: #0f1216;
  --surface: #1a1f26;
  --border: #2a313a;
  --text: #e6e8eb;
  --muted: #8a93a0;
  --accent: #5a8dff;
  --up: #ff5b5b;
  --down: #2bcf7a;
  --warn-bg: #2a2113;
  --warn-bd: #5c4a1f;
  --note-bg: #13203a;
  --tip-bg: #122a1f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 1px 8px rgba(0,0,0,.2);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; display: inline-block; }
.up { color: var(--up); }
.down { color: var(--down); }
a { color: var(--accent); }

/* =========================== Topbar =========================== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  box-shadow: var(--shadow);
}
.topbar .wrap {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; flex-wrap: wrap;
}
.logo { margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; }

.topnav { display: flex; gap: 4px; flex: 1; }
.navlink {
  position: relative;
  padding: 8px 14px; border: none; background: transparent; cursor: pointer;
  font-size: 14px; color: var(--muted); border-radius: var(--radius);
}
.navlink:hover { color: var(--text); background: var(--bg); }
.navlink.active { color: var(--accent); font-weight: 600; background: var(--note-bg); }
.badge {
  background: var(--up); color: #fff; font-size: 11px; font-weight: 600;
  border-radius: 999px; padding: 0 6px; margin-left: 2px; vertical-align: 1px;
}

.meta { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.hello { color: var(--muted); font-size: 13px; }
.hello b { color: var(--text); }
.auth-btn, .meta button {
  padding: 7px 12px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.auth-btn:hover, .meta button:hover { background: var(--bg); }

/* =========================== 登录门禁 =========================== */
.gate {
  min-height: calc(100vh - 110px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px;
}
.gate-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px; padding: 32px 28px;
}
.gate-title { margin: 0 0 6px; font-size: 24px; text-align: center; }
.gate-sub { margin: 0 0 24px; color: var(--muted); text-align: center; font-size: 13px; }
.gate-note { margin: 18px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

/* =========================== 表单 =========================== */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); }
.field input {
  padding: 9px 11px; font-size: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); outline: none; font-family: inherit;
}
.field input:focus { border-color: var(--accent); }
.form-err { margin: 2px 0 10px; font-size: 13px; color: var(--up); min-height: 18px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button.primary {
  padding: 9px 18px; font-size: 14px; cursor: pointer; font-family: inherit;
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 500;
}
button.primary:hover { opacity: .9; }
button.link {
  background: transparent; border: none; color: var(--accent); cursor: pointer;
  padding: 8px 4px; font-size: 13px; font-family: inherit;
}
button.link:hover { text-decoration: underline; }

/* =========================== 学习布局 =========================== */
#app { padding-top: 20px; padding-bottom: 24px; }
.learn-layout { display: grid; grid-template-columns: 264px 1fr; gap: 24px; align-items: start; }

.chapter-nav {
  position: sticky; top: 78px;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow);
}
.chap-link {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px; border: none; background: transparent; cursor: pointer;
  border-radius: 6px; color: var(--text); font-family: inherit; position: relative;
}
.chap-link:hover { background: var(--bg); }
.chap-link.active { background: var(--note-bg); }
.chap-link.active .chap-text b { color: var(--accent); }
.chap-emoji { font-size: 18px; flex-shrink: 0; }
.chap-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.chap-text b { font-size: 13px; font-weight: 600; }
.chap-text small { color: var(--muted); font-size: 11px; }
.dot-read { margin-left: auto; color: var(--down); font-size: 9px; }

.chapter-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 32px; box-shadow: var(--shadow);
  min-width: 0;
}
.chap-h { margin: 0 0 20px; font-size: 24px; }
.chapter-body h3 { font-size: 18px; margin: 28px 0 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.chapter-body h4 { font-size: 15px; margin: 20px 0 8px; color: var(--accent); }
.chapter-body p { margin: 10px 0; }
.chapter-body ul, .chapter-body ol { margin: 10px 0; padding-left: 22px; }
.chapter-body li { margin: 5px 0; }
.chapter-body b { font-weight: 600; }

/* 章节内表格 */
.ctab { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 13px; }
.ctab th, .ctab td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.ctab thead th { background: var(--bg); color: var(--muted); font-weight: 600; }
.ctab td:first-child { white-space: nowrap; }

/* 提示框 */
.note, .warn, .tip {
  margin: 14px 0; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); font-size: 13.5px;
}
.note { background: var(--note-bg); border-color: var(--accent); }
.warn { background: var(--warn-bg); border-color: var(--warn-bd); }
.tip  { background: var(--tip-bg);  border-color: var(--down); }

.checklist { counter-reset: ck; list-style: none; padding-left: 0; }
.checklist li { position: relative; padding-left: 30px; margin: 8px 0; }
.checklist li::before {
  counter-increment: ck; content: counter(ck);
  position: absolute; left: 0; top: 1px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

/* 盈亏图 */
.payoff { width: 100%; max-width: 380px; height: auto; display: block; margin: 6px 0 4px; }
.payoff .ax, .payoff .zero { stroke: var(--muted); stroke-width: 1; }
.payoff .zero { stroke-dasharray: 3 3; opacity: .7; }
.payoff .strike { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: .55; }
.payoff .curve { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.payoff .be { fill: var(--up); }
.payoff .lbl { fill: var(--muted); font-size: 10px; }
.payoff .lbl.up { fill: var(--down); }
.payoff .lbl.down { fill: var(--up); }

/* 章节底部导航 */
.chap-foot {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--border);
}
.chap-move {
  padding: 8px 12px; font-size: 13px; cursor: pointer; font-family: inherit;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); max-width: 45%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chap-move:hover { border-color: var(--accent); color: var(--accent); }
.chap-quiz { white-space: nowrap; }

/* =========================== 测验 =========================== */
.view-h { margin: 4px 0 6px; font-size: 22px; }
.view-sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.view-actions { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }

.quiz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.quiz-card {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; color: var(--text); font-family: inherit;
  box-shadow: var(--shadow);
}
.quiz-card:hover { border-color: var(--accent); transform: translateY(-1px); transition: .12s; }
.quiz-card.feature { border-color: var(--accent); background: var(--note-bg); }
.quiz-card.warn-card { border-color: var(--warn-bd); background: var(--warn-bg); }
.qc-emoji { font-size: 26px; }
.qc-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.qc-main b { font-size: 15px; }
.qc-main small { color: var(--muted); font-size: 12px; margin-top: 2px; }
.qc-go { color: var(--accent); font-size: 13px; white-space: nowrap; }

/* 答题区 */
.quiz-runner, .quiz-result {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
  max-width: 720px; margin: 0 auto;
}
.quiz-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.quiz-name { font-weight: 600; color: var(--text); }
.quiz-bar { height: 4px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.quiz-bar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.q-stem { font-size: 16px; font-weight: 500; margin-bottom: 16px; line-height: 1.55; }
.q-opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); cursor: pointer; color: var(--text); font-family: inherit; font-size: 14px;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt-key {
  width: 24px; height: 24px; flex-shrink: 0; border-radius: 50%;
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface);
}
.opt.correct { border-color: var(--down); background: var(--tip-bg); }
.opt.correct .opt-key { background: var(--down); color: #fff; border-color: var(--down); }
.opt.wrong { border-color: var(--up); background: color-mix(in srgb, var(--up) 12%, transparent); }
.opt.wrong .opt-key { background: var(--up); color: #fff; border-color: var(--up); }

.q-feedback { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius); font-size: 13.5px; line-height: 1.55; }
.q-feedback.ok { background: var(--tip-bg); border: 1px solid var(--down); }
.q-feedback.no { background: var(--warn-bg); border: 1px solid var(--warn-bd); }
.q-feedback .explain { color: var(--text); }
.q-actions { margin-top: 18px; text-align: right; }

/* 成绩 */
.result-card { text-align: center; padding: 16px; border-radius: var(--radius); }
.result-card.ok  { background: var(--tip-bg); }
.result-card.mid { background: var(--warn-bg); }
.result-card.no  { background: color-mix(in srgb, var(--up) 10%, transparent); }
.result-score { font-size: 56px; font-weight: 700; color: var(--accent); line-height: 1; }
.result-score small { font-size: 24px; color: var(--muted); font-weight: 500; }
.result-grade { margin: 12px 0 22px; font-size: 16px; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.result-actions button:not(.primary):not(.link) {
  padding: 9px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer; font-family: inherit; font-size: 14px;
}

/* =========================== 错题本 =========================== */
.empty { padding: 48px 24px; text-align: center; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.wrong-list { display: flex; flex-direction: column; gap: 14px; }
.wrong-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.wrong-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.wrong-src { font-size: 12px; color: var(--muted); background: var(--bg); padding: 2px 8px; border-radius: 999px; }
.wrong-opts { list-style: none; padding: 0; margin: 8px 0; }
.wrong-opts li { padding: 5px 10px; border-radius: 6px; margin: 3px 0; }
.wrong-opts li.ans { background: var(--tip-bg); color: var(--text); font-weight: 600; border: 1px solid var(--down); }
.wrong-explain { font-size: 13px; color: var(--muted); margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.wrong-explain b { color: var(--text); }

/* =========================== Footer =========================== */
.foot { margin: 8px auto 24px; color: var(--muted); font-size: 12px; text-align: center; }

/* =========================== 模拟交易 =========================== */
.empty.small { padding: 24px; font-size: 13px; }
.sim-h { font-size: 16px; margin: 26px 0 10px; }
.sim-h small { color: var(--muted); font-weight: 400; font-size: 12px; }

/* 账户条 */
.acct {
  display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.acct-stats { display: flex; flex-wrap: wrap; gap: 22px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat label { font-size: 11px; color: var(--muted); }
.stat b { font-size: 15px; font-variant-numeric: tabular-nums; }
.stat.big b { font-size: 22px; }
.stat b small { font-size: 12px; font-weight: 500; }
.acct-ctrl { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.simday { font-size: 13px; color: var(--muted); }
.simday b { color: var(--text); font-size: 15px; }
.adv-group { display: flex; align-items: center; gap: 6px; }
.adv-label { font-size: 12px; color: var(--muted); }
.adv-group button {
  padding: 6px 12px; font-size: 13px; cursor: pointer; font-family: inherit;
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--note-bg); color: var(--accent); font-weight: 500;
}
.adv-group button:hover { background: var(--accent); color: #fff; }

/* 市场卡片 */
.mkt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.mkt-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.mkt-head { display: flex; justify-content: space-between; align-items: baseline; }
.mkt-sym { font-size: 16px; }
.mkt-name { color: var(--muted); font-size: 12px; margin-left: 6px; }
.mkt-iv { font-size: 11px; color: var(--muted); background: var(--bg); padding: 1px 7px; border-radius: 999px; }
.mkt-px { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 0; font-variant-numeric: tabular-nums; }
.mkt-px .px { font-size: 19px; font-weight: 600; }
.mkt-px span:last-child { font-size: 12px; }
.spark { width: 100%; height: 34px; display: block; margin: 4px 0 10px; }
.spark polyline { fill: none; stroke-width: 1.6; }
.spark.up polyline { stroke: var(--down); }     /* 涨用绿（A股惯例与本站 down=绿一致） */
.spark.down polyline { stroke: var(--up); }
.mkt-trade { width: 100%; padding: 8px; font-size: 13px; }

/* 持仓 / 成交表 */
.sim-table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.sim-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.sim-table th, .sim-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.sim-table thead th { background: var(--bg); color: var(--muted); font-weight: 500; font-size: 12px; }
.sim-table tbody tr:last-child td { border-bottom: none; }
.sim-table .num { text-align: right; }
.mini { padding: 4px 10px; font-size: 12px; cursor: pointer; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font-family: inherit; }
.close-pos:hover { border-color: var(--up); color: var(--up); }

/* 通用弹窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; z-index: 100; overflow-y: auto; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 440px; padding: 22px; position: relative; }
.modal-card h3 { margin: 0 0 14px; font-size: 18px; }
.modal-card .close { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border: none; background: transparent; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; border-radius: 4px; }
.modal-card .close:hover { background: var(--border); color: var(--text); }

/* 期权链 */
.chain-card { max-width: 540px; }
.chain-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px; padding-right: 30px; }
.chain-spot { font-size: 13px; color: var(--muted); }
.stock-row { font-size: 12px; color: var(--muted); margin: 12px 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stock-row .mini.buy { border-color: var(--down); color: var(--down); }
.stock-row .mini.sell { border-color: var(--up); color: var(--up); }
.exp-tabs { display: flex; gap: 6px; margin: 10px 0 4px; }
.exp-tab { padding: 5px 12px; font-size: 13px; cursor: pointer; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--muted); font-family: inherit; }
.exp-tab.active { background: var(--note-bg); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chain-tip { font-size: 11.5px; color: var(--muted); margin: 6px 0 4px; }
.chain-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.chain-table th { font-size: 12px; color: var(--muted); font-weight: 500; padding: 6px; border-bottom: 1px solid var(--border); }
.chain-table td { padding: 0; border-bottom: 1px solid var(--border); text-align: center; }
.callcell, .putcell { cursor: pointer; padding: 8px 6px; }
.callcell { background: linear-gradient(90deg, color-mix(in srgb, var(--down) 8%, transparent), transparent); }
.putcell { background: linear-gradient(270deg, color-mix(in srgb, var(--up) 8%, transparent), transparent); }
.callcell:hover { background: color-mix(in srgb, var(--down) 22%, transparent); }
.putcell:hover { background: color-mix(in srgb, var(--up) 22%, transparent); }
.callcell b, .putcell b { display: block; font-size: 14px; }
.callcell small, .putcell small { color: var(--muted); font-size: 10px; }
.strikecell { font-weight: 600; background: var(--bg); width: 80px; }
.chain-table tr.atm .strikecell { color: var(--accent); }
.chain-table tr.atm td { box-shadow: inset 0 0 0 9999px color-mix(in srgb, var(--accent) 5%, transparent); }

/* 下单票据 */
.ticket-card { max-width: 380px; }
.side-toggle { display: flex; gap: 0; margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.side-toggle button { flex: 1; padding: 10px; border: none; background: var(--surface); color: var(--muted); cursor: pointer; font-family: inherit; font-size: 14px; }
.side-toggle button.active.buy { background: var(--down); color: #fff; }
.side-toggle button.active.sell { background: var(--up); color: #fff; }
.quote-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.ticket-est { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; padding: 12px; background: var(--bg); border-radius: var(--radius); }
.ticket-est > div { display: flex; justify-content: space-between; font-size: 13px; }
.ticket-est b { font-variant-numeric: tabular-nums; }
.ticket-warn { font-size: 12px; background: var(--warn-bg); border: 1px solid var(--warn-bd); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }

/* =========================== 响应式 =========================== */
@media (max-width: 820px) {
  .topbar .wrap { gap: 10px; }
  .logo { font-size: 16px; width: 100%; }
  .topnav { order: 3; flex-basis: 100%; }
  .meta { order: 2; }
  .learn-layout { grid-template-columns: 1fr; }
  .chapter-nav { position: static; flex-direction: row; overflow-x: auto; }
  .chap-link { flex-shrink: 0; min-width: 150px; }
  .chap-text small { display: none; }
  .chapter-body { padding: 20px 18px; }
  .chapter-body h3 { font-size: 16px; }
}
@media (max-width: 480px) {
  .ctab { font-size: 12px; }
  .ctab th, .ctab td { padding: 6px 7px; }
  .result-score { font-size: 44px; }
}
