/* 缠论研习 —— 视觉规格
   与 M0 预览页保持同一套色板，避免出现两套设计语言。
   涨红跌绿为中国市场惯例，不随系统主题反转。 */

:root {
  --bg: #f4f4f1;
  --panel: #ffffff;
  --line: #dcdad1;
  --line-soft: #eae8e0;
  --ink: #232320;
  --ink-2: #6b6a62;
  --ink-3: #9b9a90;
  --accent: #1a5fa8;
  --accent-soft: #e7f0fa;
  --up: #c8443c;
  --down: #1f8a54;
  --zs-line: #8a6d3b;
  --zs-fill: rgba(138, 109, 59, 0.07);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- 顶栏 ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 50px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--ink);
  user-select: none;
  white-space: nowrap;
}
.brand b { color: var(--accent); font-weight: 600; }

.search { position: relative; width: 240px; }
.search input {
  width: 100%;
  height: 30px;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  transition: border-color .15s, background .15s;
}
.search input:focus { border-color: var(--accent); background: #fff; }
.search input::placeholder { color: var(--ink-3); }

/* 搜索结果：绝对定位，不撑开布局 */
.hits {
  position: absolute;
  top: 34px;
  left: 0;
  right: 0;
  max-height: 300px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 50;
  display: none;
}
.hits.on { display: block; }
.hits .hit {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--line-soft);
}
.hits .hit:last-child { border-bottom: 0; }
.hits .hit:hover, .hits .hit.sel { background: var(--accent-soft); }
.hits .hit .c { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.hits .hit .n { font-weight: 500; }
.hits .empty { padding: 12px 10px; color: var(--ink-3); }

/* 周期切换 */
.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}
.seg button {
  width: 38px;
  height: 28px;
  background: #fff;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 13px;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--bg); color: var(--accent); }
.seg button.on { background: var(--accent); color: #fff; }

.spacer { flex: 1; }

.caliber {
  font-size: 11.5px;
  color: var(--ink-3);
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
  user-select: none;
}

/* 题库入口：与口径标签同一行的轻链接，不做成按钮，避免抢主图注意力 */
.quizlink {
  font-size: 11.5px;
  color: var(--accent);
  text-decoration: none;
  padding: 3px 9px;
  border: 1px solid var(--accent-soft);
  border-radius: 999px;
  background: var(--accent-soft);
  white-space: nowrap;
  transition: all .15s;
}
.quizlink:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- 指标开关 ---------- */
.tools {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  /* 工具条现在有 9 个开关，hint 再长也不能把 chip 挤变形 */
  flex: 0 0 auto;
  white-space: nowrap;
  height: 26px;
  padding: 0 10px;
  font-size: 12.5px;
  color: var(--ink-2);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: all .12s;
  user-select: none;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on {
  color: #0d3f70;
  background: var(--accent-soft);
  border-color: #a9c8e6;
}
.chip .sw {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}
.chip[data-k="bi"] .sw { background: var(--up); }
.chip[data-k="seg"] .sw { background: var(--accent); }
.chip[data-k="zs"] .sw { background: var(--zs-line); }
/* 段中枢色块与 overlay 里的 zsSegLine 保持一致，开关和图上颜色要对得上 */
.chip[data-k="zsseg"] .sw { background: #6b4fa8; }
.chip[data-k="fx"] .sw { background: #8b5cf6; }
/* 买卖点色块取「买红」，与图上买点圆圈同色 */
.chip[data-k="bs"] .sw { background: #c8443c; }
/* 解释层是个独立功能，不用 [data-k]（它不控制 overlay） */
.chip#explainToggle .sw { background: #2f7d6b; }
/* 回放＝时间轴，用蓝色；区间套＝两个级别的套叠，用紫（与段中枢同族但更亮） */
.chip#replayToggle .sw { background: #1a5fa8; }
.chip#nestToggle .sw { background: #6b4fa8; }
/* MACD 与 DIF 线的蓝同色，暗示「副图那两条线就是这套指标」 */
.chip#macdToggle .sw { background: #1a5fa8; }
.chip:disabled { opacity: .45; cursor: not-allowed; }
.chip:disabled:hover { border-color: var(--line); color: var(--ink-2); }
.chip .tag {
  font-size: 10px;
  color: var(--ink-3);
  background: var(--bg);
  border-radius: 3px;
  padding: 0 4px;
}

.hint {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-left: 4px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 图表 ---------- */
main {
  display: flex;
  flex: 1;
  min-height: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
/* .chart-wrap 必须是定位祖先：加载遮罩 .mask 是 absolute inset:0，
   若它找不到定位祖先，会盖满整个视口（连顶栏一起白掉）。 */
.chart-wrap { position: relative; flex: 1; min-width: 0; }
#chart { position: absolute; inset: 0; }

/* ---------- 解释层 ---------- */
/* 常驻右栏而不是浮动 tooltip：解释文本 10 行以上，跟着鼠标飘会盖住 K 线，
   而且一动就消失读不完。宽度固定 336px，隐藏时显式改 display。 */
.explain {
  width: 336px;
  flex: 0 0 336px;
  padding: 12px 14px 24px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: #fcfcfb;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--ink);
  scrollbar-width: thin;
}
.explain.off { display: none; }

.ex-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.ex-badge {
  display: inline-block;
  min-width: 26px;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  white-space: nowrap;
}
.ex-title { font-size: 14px; font-weight: 600; }
.ex-sub {
  font-size: 11.5px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  margin-bottom: 10px;
}

.ex-h {
  margin: 12px 0 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .6px;
  color: var(--ink-3);
}
.ex-p { margin: 3px 0; }
.ex-p b { font-weight: 600; }

.ex-step {
  display: flex;
  gap: 7px;
  margin: 5px 0;
}
.ex-step .n {
  flex: 0 0 16px;
  height: 16px;
  margin-top: 2.5px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 10px;
  line-height: 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.ex-step .c { flex: 1; }

.ex-kv {
  display: flex;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px dashed var(--line-soft);
}
.ex-kv .k { flex: 0 0 74px; color: var(--ink-3); }
.ex-kv .v { flex: 1; font-variant-numeric: tabular-nums; }

.ex-note {
  margin: 8px 0 0;
  padding: 7px 9px;
  background: #f6f5f0;
  border-left: 2px solid var(--line);
  color: var(--ink-2);
  font-size: 11.5px;
  line-height: 1.6;
}

.ex-empty {
  color: var(--ink-3);
  font-size: 12px;
  padding-top: 6px;
  line-height: 1.8;
}
.ex-empty .lead { color: var(--ink-2); font-weight: 500; margin-bottom: 6px; }
.ex-empty kbd {
  display: inline-block;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  font: inherit;
  font-size: 11px;
  color: var(--ink-2);
}

/* ---------- 状态栏 ---------- */
.status {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 30px;
  padding: 0 16px;
  font-size: 11.5px;
  color: var(--ink-2);
  background: var(--panel);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
}
.status .k { color: var(--ink-3); }
.status .v { color: var(--ink); font-variant-numeric: tabular-nums; }
.status .warn { color: #a8560f; }

/* ---------- 底部操作带 ---------- */
/* 回放与区间套都挂在图下方：它们操作的是「图上正在看的那一段」，
   放到顶栏会离视线太远；放进右栏又会挤压解释层。 */
.dock { display: none; flex-shrink: 0; background: var(--panel); }
.dock.on { display: block; }

.transport, .nestbar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: 40px;
  border-top: 1px solid var(--line);
}
.transport.on, .nestbar.on { display: flex; }

.tbtn {
  height: 26px;
  min-width: 30px;
  padding: 0 9px;
  font-size: 12px;
  color: var(--ink-2);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  transition: all .12s;
}
.tbtn:hover { border-color: var(--accent); color: var(--accent); }
.tbtn.play { min-width: 40px; font-size: 13px; }
.tbtn.play.on { color: #0d3f70; background: var(--accent-soft); border-color: #a9c8e6; }

.trange {
  flex: 1;
  min-width: 120px;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}
.trange:disabled { opacity: .4; cursor: default; }

.tinfo {
  font-size: 12px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 150px;
}
.tinfo b { color: var(--ink); font-weight: 600; }

.tlab {
  font-size: 11.5px;
  color: var(--ink-3);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.tsel {
  height: 26px;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 4px;
}

/* 区间套：横向滚动的判定列表 */
.nesthead {
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
  padding-right: 6px;
  border-right: 1px solid var(--line-soft);
}
.nesthead b { color: var(--ink); font-weight: 600; }
.nesthead .warn { color: #a8560f; }
.nswitch { margin-left: 8px; color: var(--ink-3); font-size: 11.5px; cursor: pointer; }
.nswitch input { vertical-align: -2px; margin-right: 3px; }

.nestlist {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 6px 0;
}
.nchip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 9px;
  font-size: 11.5px;
  color: var(--ink-2);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.nchip:hover { border-color: var(--accent); color: var(--accent); }
/* 共振的条目用红色左边框，和画布上的红竖带对应 */
.nchip.hot { border-left: 3px solid var(--up); }
.nchip .hot {
  font-style: normal;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: var(--up);
  border-radius: 3px;
  padding: 0 4px;
}
.nchip .nr { color: var(--ink-3); }
.nchip em { font-style: normal; color: #0d3f70; font-size: 10.5px; }
.nempty { font-size: 12px; color: var(--ink-3); }

/* 加载遮罩 */
.mask {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .72);
  z-index: 20;
  font-size: 13px;
  color: var(--ink-2);
}
.mask.on { display: flex; }

/* 致命错误提示（自诊断用） */
.fatal {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 40px;
  padding: 10px 14px;
  background: #fff4f2;
  border: 1px solid #e5b3ac;
  border-radius: 8px;
  color: #8d2b20;
  font-size: 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  z-index: 999;
  display: none;
}
.fatal.on { display: block; }

/* ---------- 窄屏适配 ---------- */
@media (max-width: 980px) {
  .brand { display: none; }
  .caliber { display: none; }
  .hint { display: none; }
  .search { width: 170px; }
  /* 窄屏把解释层改成浮层：挤压图表会让 K 线挤成一堆，得不偿失 */
  main { position: relative; }
  .explain {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 300px;
    z-index: 30;
    box-shadow: -8px 0 22px rgba(0, 0, 0, 0.09);
  }
}
@media (max-width: 640px) {
  .bar { gap: 8px; padding: 0 10px; }
  .search { width: 120px; }
  .seg button { width: 30px; }
  .tools { padding: 0 10px; gap: 6px; overflow-x: auto; }
  .chip { padding: 0 8px; flex: 0 0 auto; }
  .status { gap: 10px; padding: 0 10px; }
  /* 窄屏放不下速度/起点选择：只留播放、单步、进度条，起点在宽屏再设 */
  .transport { padding: 0 10px; gap: 6px; flex-wrap: nowrap; overflow-x: auto; }
  .tlab, .tinfo { display: none; }
  .nesthead { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
}
