.viz-root {
  color-scheme: dark;
  --bg: #111214;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --muted: #8d8c84;
  --grid: #2c2c29;
  --series-1: #e0a43a;          /* accent (amber): buttons, sliders, the strategy line, the tuning period */
  --on-accent: #111214;
  --series-2: #8fa6c4;          /* the test period */
  --spy: #9a988f;
  --ctl: #9d93b8;               /* random-entry control portfolios */
  --red: #f0463c;
  --green: #22b464;
  --warn: #c98500;
  --tip-bg: rgba(20, 20, 19, .95);
  --scrim: rgba(0, 0, 0, .6);
  --split-fill: rgba(143, 166, 196, .07);
  /* K-line replay */
  --gold: #e8e4d8;              /* base geometry, pivot, exit marker */
  --ma10: #64b5f6;
  --ma20: #ba68c8;
  --ma50: #f5a742;
}
:root[data-theme="light"] .viz-root {
  color-scheme: light;
  --bg: #f3f0e8;
  --surface-1: #fffdf8;
  --surface-2: #efebe1;
  --text-primary: #1c2027;
  --text-secondary: #3b414b;
  --muted: #69707b;
  --grid: #e2ddd1;
  --series-1: #a8650d;
  --on-accent: #ffffff;
  --series-2: #4a6283;
  --spy: #8a877d;
  --ctl: #7b6f9c;
  --red: #d6402b;
  --green: #1f9d55;
  --warn: #b45309;
  --tip-bg: rgba(255, 253, 248, .97);
  --scrim: rgba(28, 32, 39, .45);
  --split-fill: rgba(74, 98, 131, .06);
  --gold: #3b414b;
  --ma10: #1e88e5;
  --ma20: #8e44ad;
  --ma50: #d97706;
}
/* up / down colours: Chinese convention (red up, green down) by default, "us" swaps them */
.viz-root { --up: var(--red); --down: var(--green); }
:root[data-updown="us"] .viz-root { --up: var(--green); --down: var(--red); }
.viz-root { --win: var(--up); --loss: var(--down); --pos: var(--up); --k-up: var(--up); --k-down: var(--down); }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text-primary); transition: background-color .3s, color .3s;
  font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif; }
header { padding: 18px 20px 8px; }
header h1 { padding-right: 150px; }
h1 { margin: 0; font-size: 30px; line-height: 1.25; letter-spacing: .02em; }
h1 small { font-size: 14px; color: var(--muted); font-weight: normal; margin-left: 10px; letter-spacing: 0; }

/* light / dark toggle (same look as the history-map sites) */
.theme-toggle { position: fixed; top: 16px; right: 16px; z-index: 30; display: grid; place-items: center;
  width: 40px; height: 40px; padding: 0; border: 1px solid var(--grid); border-radius: 50%;
  background: var(--surface-1); cursor: pointer; transition: border-color .2s; }
.theme-toggle:hover { border-color: var(--series-1); }
.theme-toggle:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.theme-toggle svg { width: 20px; height: 20px; fill: none; stroke: var(--text-primary); stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .i-moon { display: none; }
:root[data-theme="light"] .theme-toggle .i-sun { display: none; }
:root[data-theme="light"] .theme-toggle .i-moon { display: block; }
.updown-toggle { position: fixed; top: 16px; right: 64px; z-index: 30; height: 40px; padding: 0 12px; border-radius: 20px;
  border: 1px solid var(--grid); background: var(--surface-1); color: var(--text-primary); font-size: 13px; }
.updown-toggle:hover { border-color: var(--series-1); }
.updown-toggle .u { color: var(--up); } .updown-toggle .d { color: var(--down); }

/* folding: cards (<details class="fold">) and the parameter panel start closed on every visit; the closed panel
   shows only the "每笔风险" slider. The triangle turns from ▶ to ▼ when open. */
aside:not(.open) .adv { display: none !important; }
aside.open .folded-only { display: none !important; }
details.fold > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 8px; user-select: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary h2 { margin: 0; }
details.fold[open] > summary { margin-bottom: 8px; }
details.fold > summary::before, .fold-btn::before { content: "▶"; display: inline-block; flex: none; font-size: 10px;
  color: var(--muted); transition: transform .15s; }
details.fold[open] > summary::before, aside.open .fold-btn::before { transform: rotate(90deg); }
details.fold > summary:hover h2, .fold-btn:hover { color: var(--series-1); }
details.fold > summary:focus-visible, .fold-btn:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 4px; }
.fold-btn { display: flex; align-items: baseline; gap: 8px; width: 100%; margin: 0 0 8px; padding: 0 0 6px; background: none;
  color: var(--text-primary); font-size: 15px; font-weight: 600; text-align: left; border-radius: 0;
  border-bottom: 1px solid var(--grid); }
#summary .headline { font-size: 17px; line-height: 1.6; margin: 2px 0 12px; }
#summary .headline b { font-weight: 600; }
#summary .verdict { color: var(--text-secondary); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.mcard { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.mcard .k { font-size: 12.5px; color: var(--text-secondary); }
.mcard .v { font-size: 22px; font-weight: 600; margin: 2px 0; font-variant-numeric: tabular-nums; }
.mcard .s { font-size: 12px; color: var(--muted); }
#summary ul { margin: 12px 0 4px; padding-left: 18px; color: var(--text-secondary); font-size: 13px; }
#summary li { margin: 3px 0; }
.side-note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.crumb { margin: 0 0 2px; font-size: 13px; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--series-1); }
.warn { margin: 6px 0 0; color: var(--text-secondary); font-size: 13px; border-left: 3px solid var(--warn); padding-left: 8px; }
#app { display: grid; grid-template-columns: 340px 1fr; gap: 14px; padding: 8px 20px 30px; align-items: start; }
aside { position: sticky; top: 8px; max-height: calc(100vh - 16px); overflow-y: auto; background: var(--surface-1);
  border-radius: 8px; padding: 12px 14px; }
main { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface-1); border-radius: 8px; padding: 12px 16px; }
h2 { font-size: 15px; margin: 0 0 6px; }
h2 small, .muted { color: var(--muted); font-weight: normal; font-size: 12px; }
h3 { font-size: 13px; margin: 16px 0 6px; color: var(--text-secondary); border-bottom: 1px solid var(--grid); padding-bottom: 3px; }
button { background: var(--series-1); color: var(--on-accent); border: 0; border-radius: 6px; padding: 5px 10px; font: inherit; cursor: pointer; }
button.ghost, .presets button { background: var(--surface-2); color: var(--text-primary); }
.presets button.on { outline: 1px solid var(--series-1); }
.presets { display: flex; gap: 8px; }
.kinds { margin: 10px 0 0; display: flex; gap: 14px; font-size: 13px; }
.f { margin: 8px 0 2px; }
.f.off .fv { color: var(--muted); }
.f.na { opacity: .4; }
.fl { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-secondary); gap: 6px; }
.fv { color: var(--text-primary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fl span[title] { border-bottom: 1px dotted var(--muted); cursor: help; }
input[type=range] { width: 100%; margin: 2px 0 0; accent-color: var(--series-1); }
canvas.spark { display: block; width: 100%; height: 30px; cursor: crosshair; }
.sparktip { font-size: 11px; color: var(--muted); height: 14px; white-space: nowrap; overflow: hidden; }
.sel { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; font-size: 12.5px; color: var(--text-secondary); }
select { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--grid); border-radius: 5px; padding: 3px 6px; font: inherit; }
.hint { font-size: 12px; color: var(--muted); margin-top: 14px; }
.sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin: 0 3px 0 8px; }
.sw.s1 { background: var(--series-1); } .sw.s2 { background: var(--series-2); } .sw.spy { background: var(--spy); } .sw.ctl { background: var(--ctl); }
.sw.win { background: var(--win); height: 9px; } .sw.loss { background: var(--loss); height: 9px; }
.legend { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.ctl-toggle { cursor: pointer; white-space: nowrap; margin-left: 4px; }
.ctl-toggle input { margin: 0 0 0 4px; vertical-align: -2px; accent-color: var(--series-1); cursor: pointer; }
.ctl-toggle .sw { margin-left: 4px; }
.ctl-toggle:has(input:not(:checked)) { color: var(--muted); }
@media (max-width: 900px) { .ctl-toggle { white-space: normal; } }
.chartwrap { position: relative; }
.chartwrap canvas { display: block; width: 100%; }
.tip { position: absolute; pointer-events: none; background: var(--tip-bg); border: 1px solid var(--grid); border-radius: 6px;
  padding: 5px 8px; font-size: 12px; color: var(--text-primary); display: none; white-space: nowrap; z-index: 5; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
#stats table td, #stats table th { padding: 4px 10px; text-align: right; border-bottom: 1px solid var(--grid); }
#stats table th { color: var(--text-secondary); font-weight: normal; }
#stats table td:first-child, #stats table th:first-child { text-align: left; color: var(--text-secondary); }
#stats tr.big td { font-size: 17px; font-weight: 600; }
#stats tr.big td:first-child { font-size: 14px; font-weight: normal; }
#stats .sub { color: var(--muted); font-size: 12px; }
.pos { color: var(--pos); } .neg { color: var(--loss); }
#alerts p { margin: 6px 0 0; font-size: 13px; color: var(--text-secondary); }
#alerts p::before { content: "⚠ "; color: var(--warn); }
.tablewrap { max-height: 460px; overflow: auto; }
#trades th { position: sticky; top: 0; background: var(--surface-1); cursor: pointer; color: var(--text-secondary); font-weight: normal; }
#trades th, #trades td { padding: 3px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; font-size: 13px; }
#trades td:nth-child(2), #trades th:nth-child(2), #trades td:nth-child(3) { text-align: left; }
#trades tbody tr { cursor: pointer; }
#trades tbody tr:hover { background: var(--surface-2); }
#trades .dim { color: var(--muted); }
#compare table td, #compare table th { padding: 3px 6px; text-align: right; font-size: 12.5px; border-bottom: 1px solid var(--grid); }
#compare table th { color: var(--text-secondary); font-weight: normal; }
#compare table td:first-child { text-align: left; color: var(--text-secondary); white-space: nowrap; }
#compare table th { white-space: nowrap; }
#compare tr.cur td { background: var(--surface-2); color: var(--text-primary); }
#compare tr.sep td { border-bottom: 1px solid var(--muted); }
.about ul { margin: 0; padding-left: 18px; color: var(--text-secondary); font-size: 13px; }
.about li { margin: 4px 0; }
#kpanel { position: fixed; inset: 0; background: var(--scrim); z-index: 20; display: flex; align-items: center; justify-content: center; }
#kpanel[hidden] { display: none; }
.kbox { background: var(--surface-1); border-radius: 10px; width: min(1200px, 96vw); padding: 12px 16px; max-height: 96vh; overflow: auto; }
.khead { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
#kinfo { font-size: 13px; color: var(--text-secondary); }
#kinfo b { color: var(--text-primary); font-size: 15px; }
.kbtns { display: flex; gap: 8px; flex-shrink: 0; }
#kfeat { margin-top: 6px; }
/* strategy catalog (web/index.html) */
.catalog-intro { margin: 10px 0 0; color: var(--text-secondary); font-size: 13.5px; max-width: 820px; }
.catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; padding: 12px 20px 30px; }
.scard { display: flex; flex-direction: column; gap: 8px; background: var(--surface-1); border: 1px solid transparent; border-radius: 8px;
  padding: 14px 16px; color: var(--text-primary); text-decoration: none; transition: border-color .2s; }
a.scard:hover, a.scard:focus-visible { border-color: var(--series-1); outline: none; }
.scard h2 { font-size: 18px; margin: 0; }
.scard h2 small { margin-left: 6px; }
.scard .sdesc { margin: 0; color: var(--text-secondary); font-size: 13.5px; }
.scard .sverdict { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }
.scard .sverdict .k { font-size: 12.5px; color: var(--text-secondary); }
.scard .sverdict .v { font-size: 18px; font-weight: 600; margin: 1px 0; }
.scard .sverdict .s { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.scard .go { margin-top: auto; color: var(--series-1); font-size: 13.5px; }
.scard.soon { border: 1px dashed var(--grid); background: transparent; }
.scard.soon .go { color: var(--muted); }
@media (max-width: 900px) {
  #app { display: flex; flex-direction: column; padding: 8px 10px 30px; }
  main { display: contents; }
  #summary { order: 0; } aside { order: 1; } #eqCard { order: 2; } main > .card:not(#summary):not(#eqCard) { order: 3; }
  .updown-toggle { position: absolute; top: 14px; right: 60px; height: 36px; padding: 0 10px; }
  aside { position: static; max-height: none; width: 100%; }
  main > .card { width: 100%; }
  header { padding: 14px 12px 4px; }
  header h1 { padding-right: 140px; }
  h1 { font-size: 25px; }
  h1 small { display: block; margin: 2px 0 0; font-size: 13px; }
  .theme-toggle { position: absolute; top: 14px; right: 12px; }
  #stats table td, #stats table th { padding: 4px 5px; }
  .catalog { grid-template-columns: 1fr; padding: 8px 10px 30px; }
}
