:root[data-theme="dark"] {
  --bg: #0e1117;
  --chrome: #12161f;               /* 顶栏/工具栏/页脚的镶边底色：略浮于图表区 */
  --panel: #151b26;
  --panel-2: #1a2130;
  --border: #323c4d;
  --hover: #1c2432;
  --ctl-track: #151b26;  /* 分段控件轨道（暗色沿用 panel） */
  --ctl-active: #2a3448; /* 控件选中态底色（比 panel 明显亮一档） */
  --text: #e4e8f0;
  --sub: #8b93a1;
  --faint: #5c6470;
  --accent: #2e6bff;
  --up: #089981;
  --down: #f23645;
  --live: #22c55e;        /* 实时圆点（亮绿，两主题共用语义） */
  --invert-bg: #e4e8f0;   /* 图标按钮悬停反转（暗色转译：亮底翻黑） */
  --invert-fg: #0e1117;
  --shadow-active: none;
}

:root[data-theme="light"] {
  /* 数据终端语言原生 token：中性灰阶铺在白色之上 */
  --bg: #f9fafb;          /* gray-50 页面底 */
  --chrome: #ffffff;      /* 表面：栏、卡片 */
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --border: #e5e7eb;      /* gray-200 */
  --hover: #f3f4f6;       /* gray-100 */
  --ctl-track: #f3f4f6;   /* gray-100 分段控件轨道 */
  --ctl-active: #ffffff;  /* 分段激活 = 白色胶囊 + shadow-sm */
  --text: #111827;        /* gray-900 强调/数字 */
  --sub: #6b7280;         /* gray-500 弱化文字 */
  --faint: #9ca3af;       /* gray-400 */
  --accent: #2962ff;
  --up: #16a34a;          /* green-600 */
  --down: #dc2626;        /* red-600 */
  --live: #22c55e;        /* green-500 实时圆点 */
  --invert-bg: #000000;   /* 图标按钮悬停：黑底翻白 */
  --invert-fg: #ffffff;
  --shadow-active: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

:root {
  --ctl-h: 28px; /* 顶栏/工具栏所有控件的统一总高 */
  /* 数据终端语言：界面文字 = 系统无衬线，数字一律 = 系统等宽 */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
               "Liberation Mono", monospace;
  /* 圆角阶：标签/胶囊 6，按钮/分段 8，容器/浮层 12，圆点全圆 */
  --r-s: 6px;
  --r-m: 8px;
  --r-l: 12px;
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

[hidden] {
  display: none !important;
}

/* 焦点环：2px 中性灰（数据终端语言：无彩色焦点态） */
:focus-visible {
  outline: 2px solid var(--border);
  outline-offset: -1px;
}

::selection {
  background: rgba(46, 107, 255, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
}

/* ── 顶部信息栏 ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--chrome);
  border-bottom: 2px solid var(--border);
  flex: none;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  flex: none;
  display: block;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  line-height: 1.15;
}

/* 副标题：字距拉开的小号大写，交易台风格；英文界面下隐藏（与主名重复） */
.brand-sub {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--faint);
  white-space: nowrap;
  margin-top: 1px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* ── 右上角：语言双选滑块 + 主题图标按钮 ── */
.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

/* 语言按钮：与主题按钮同款方形图标按钮，字形显示当前语言
  （中文态「中」/ 英文态「EN」，与月亮/太阳的“显示当前态”一致） */
.icon-btn .glyph-zh,
.icon-btn .glyph-en {
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

html[lang="en"] .glyph-zh { display: none; }
html:not([lang="en"]) .glyph-en { display: none; }

.icon-btn {
  border-radius: var(--r-m);
  text-decoration: none; /* 链接形态（X / GitHub）与按钮同款 */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: var(--ctl-h);
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--sub);
  cursor: pointer;
}

.icon-btn {
  transition: color 0.12s ease, background-color 0.12s ease;
}

/* 数据终端语言标志性交互：图标按钮悬停反转（黑底翻白 / 暗色亮底翻黑） */
.icon-btn:hover {
  color: var(--invert-fg);
  background: var(--invert-bg);
  border-color: var(--invert-bg);
}

/* 主题按钮显示当前状态：深色 = 月亮，浅色 = 太阳 */
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="light"] .icon-moon { display: none; }

.stats {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.stats::-webkit-scrollbar {
  display: none;
}

/* 顶栏数值单元：标注在上、数值在下（专业行情工具惯例——先建立语境再读数），
   单元之间用细分隔线隔离 */
.stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  white-space: nowrap;
}

.stat + .stat {
  border-left: 1px solid var(--border);
  padding-left: 10px;
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sub);
}

/* 实时数据指示：常驻脉动圆点（指示灯语义），暗示该数值在动态更新 */
.live-dot {
  width: 5px;
  height: 5px;
  flex: none;
  border-radius: 50%;
  background: var(--live);
  animation: live-pulse 2.4s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.stat-value {
  display: flex;
  align-items: baseline;
  gap: 7px;
  /* 负外边距 + 内边距：闪烁底色向外渗出一圈，不挤动布局 */
  padding: 1px 5px;
  margin: -1px -5px;
  border-radius: var(--r-s);
}

/* 数值更新闪烁：变化瞬间底色亮起后淡出（价格按涨跌方向着色） */
@keyframes flash-neutral {
  0% { background: rgba(46, 107, 255, 0.30); }
  100% { background: transparent; }
}

@keyframes flash-up {
  0% { background: rgba(8, 153, 129, 0.32); }
  100% { background: transparent; }
}

@keyframes flash-down {
  0% { background: rgba(242, 54, 69, 0.32); }
  100% { background: transparent; }
}

.flash { animation: flash-neutral 0.9s ease-out; }
.flash-up { animation: flash-up 0.9s ease-out; }
.flash-down { animation: flash-down 0.9s ease-out; }

.price {
  font-family: var(--font-mono);
  font-size: 15px; /* 等宽主数值（term-data） */
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.chg {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chg.up { color: var(--up); }
.chg.down { color: var(--down); }

/* 狼波指数读数的颜色由 JS 按 waveColor(值) 动态设置——
   与折线/色标同一色谱，同一数值同一颜色 */

/* ── 顶栏中部：图表控件带（粒度/类型/坐标/标注，单顶栏布局） ──
   与品牌之间用细分隔线建立分区；放不下时自身横向滚动，不挤压两侧 */
.top-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  border-left: 1px solid var(--border);
  padding-left: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.top-controls::-webkit-scrollbar {
  display: none;
}

.top-controls > * {
  flex: none; /* 控件不许被压窄：放不下走横向滚动 */
}

.seg {
  border-radius: var(--r-m);
  /* 组内选项等宽（自动宽度 grid 的 1fr 列会统一到最宽项）：
     按钮宽度不随文字长短变化，Log 与 Linear 一样宽 */
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 2px;
  height: var(--ctl-h);
  background: var(--ctl-track);
  border: 1px solid var(--border);
  flex: none;
}

.seg button {
  border-radius: var(--r-s);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--sub);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  padding: 0 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.12s ease, background-color 0.12s ease;
}

.seg button:not(.active):hover {
  color: var(--text);
  background: var(--hover);
}

/* 选中态：抬起的白色胶囊（浅色带 shadow-sm；暗色以亮一档底色转译） */
.seg button.active {
  background: var(--ctl-active);
  color: var(--text);
  box-shadow: var(--shadow-active);
}

/* 独立开关按钮（标注显隐）：与分段控件分开，睁眼/闭眼表达开关状态 */
.toggle-btn {
  border-radius: var(--r-m);
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--ctl-h);
  padding: 0 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--sub);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  flex: none;
  transition: color 0.12s ease, background-color 0.12s ease;
}

.toggle-btn:hover {
  color: var(--text);
  background: var(--hover);
}

.toggle-btn.active {
  background: var(--ctl-active);
  color: var(--text);
}

.toggle-btn.active:hover {
  background: var(--ctl-active);
}

/* 纯图标开关的关闭态：图标压暗（配合非激活底色） */
.toggle-btn:not(.active) svg { opacity: 0.45; }

/* ── 底部区块刻度轴（主轴：区块高度，副行：对应≈日期） ── */
.block-axis {
  position: relative;
  height: 40px;
  border-top: 2px solid var(--border);
  background: var(--bg);
  overflow: hidden;
  flex: none;
}

/* 轴名标签：钉在区块轴左端，说明这根非常规主轴是什么 */
.bx-name {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  padding: 0 10px 0 14px;
  background: var(--bg);
  font-size: 10px;
  font-weight: 500;
  color: var(--faint);
  letter-spacing: 0.3px;
  z-index: 1;
  user-select: none;
}

.bx-label {
  font-family: var(--font-mono);
  position: absolute;
  top: 6px;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  user-select: none;
}

.bx-date {
  font-family: var(--font-mono);
  position: absolute;
  top: 22px;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  user-select: none;
}

.bx-tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 4px;
  background: var(--sub);
  opacity: 0.8;
}

/* 当前区块引导线（与 y 轴价格引导线对称）：贯穿两个面板的竖直虚线，
   颜色由 main.js 按主题色 COLORS.today 设置 */
.now-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed var(--sub);
  z-index: 3;
  pointer-events: none;
}

/* 底轴上的当前区块高度数值牌（常驻，反色高亮） */
.bx-now {
  font-family: var(--font-mono);
  border-radius: var(--r-s);
  position: absolute;
  top: 7px;
  transform: translateX(-50%);
  padding: 3px 8px;
  background: var(--sub);
  color: var(--bg);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  z-index: 1;
  pointer-events: none;
}

/* 十字线在轴上的浮标：高度 · 日期 */
.bx-cursor {
  font-family: var(--font-mono);
  border-radius: var(--r-s);
  position: absolute;
  top: 7px;
  transform: translateX(-50%);
  padding: 3px 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  z-index: 2;
  pointer-events: none;
}

/* ── 图表区 ── */
.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

.chart-host {
  position: relative;
  flex: 1;
  min-width: 0;
}

#chart {
  position: absolute;
  inset: 0;
}

/* ── 狼波指数色标（右侧垂直渐变条，蓝 0 = 熊底 → 红 1 = 牛顶） ── */
.wave-scale {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 10px 10px 10px 6px;
  border-left: 2px solid var(--border);
  user-select: none;
}

.ws-label {
  font-size: 11px;
  color: var(--sub);
  white-space: nowrap;
}

.ws-body {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 6px;
}

.ws-bar {
  border-radius: 3px;
  position: relative;
  width: 12px;
  height: 100%;
  border: 1px solid var(--border);
  /* 渐变底色由 main.js 按 WAVE_COLOR_STOPS 生成，与折线颜色严格一致 */
}

.ws-ticks {
  font-family: var(--font-mono);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin: -4px 0;
  font-size: 10px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.ws-ticks span {
  line-height: 1;
}

/* 当前指数游标：横线钉在色条上对应位置 */
/* 当前指数游标：圆形滑块拇指扣在渐变条上 */
.ws-marker {
  position: absolute;
  left: 50%;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--bg);
  pointer-events: none;
}

/* 副图（狼波指数窗格）显隐开关：浮在窗格右上角；窗格收起后退到图表右下角。
   高度 24px 是刻意的例外：浮在数据上方的迷你控件，比栏区控件紧凑一档 */
.phase-toggle {
  border-radius: var(--r-m);
  position: absolute;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--sub);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.phase-toggle {
  transition: color 0.12s ease, background-color 0.12s ease;
}

.phase-toggle:hover {
  color: var(--text);
  background: var(--hover);
}

.phase-toggle.active {
  background: var(--ctl-active);
  color: var(--text);
}

.phase-toggle.active:hover {
  background: var(--ctl-active);
}

.phase-toggle .icon-expand { display: none; }
.phase-toggle:not(.active) .icon-collapse { display: none; }
.phase-toggle:not(.active) .icon-expand { display: inline; }

.legend {
  position: absolute;
  top: 10px;
  left: 14px;
  z-index: 10;
  pointer-events: none;
  user-select: none;
  font-size: 12px;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.legend b {
  color: var(--text);
  font-weight: 600;
}

/* 主图价格读数：与副图指数读数同一套「名称 + 值」排版 */
.legend .legend-val {
  font-weight: 600;
  margin-left: 12px;
}

/* 副图标题行：与主图系列标识完全同一套排版（字体/字号/左距/留白），
   纵向位置由 JS 跟随副图面板顶部 */
.phase-legend .wave-text {
  font-weight: 600;
  margin-left: 12px;
}

/* ── 悬停信息卡：跟随十字线，聚合该位置的全部读数 ── */
.chart-tooltip {
  border-radius: var(--r-l);
  position: absolute;
  z-index: 15;
  min-width: 200px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  font-size: 12px;
  pointer-events: none;
  user-select: none;
}

.tt-head {
  padding-bottom: 7px;
  margin-bottom: 7px;
  border-bottom: 1px solid var(--border);
  color: var(--sub);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tt-head b {
  font-family: var(--font-mono);
  color: var(--text);
  font-weight: 700;
}

.tt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.tt-row:first-of-type {
  margin-top: 0;
}

.tt-chip {
  width: 3px;
  height: 12px;
  flex: none;
  border-radius: 999px; /* 两端全圆的胶囊形 */
}

.tt-label {
  color: var(--sub);
  white-space: nowrap;
}

.tt-val {
  font-family: var(--font-mono);
  margin-left: auto;
  padding-left: 18px;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── 提示与加载 ── */
.notice {
  border-radius: var(--r-l);
  position: absolute;
  top: 38px; /* 避开左上角 OHLC 读数行，窄窗口下不互相覆盖 */
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  max-width: calc(100% - 28px);
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

/* 关闭按钮：圆形热区（关闭钮的通用形态） */
.notice button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--sub);
  padding: 0;
}

.notice button {
  transition: color 0.12s ease, background-color 0.12s ease;
}

.notice button:hover {
  color: var(--text);
  background: var(--hover);
}

.notice button:active {
  color: var(--faint);
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  font-size: 13px;
  color: var(--sub);
}

.loading-brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
}

.loading-spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}



/* ── 指标说明弹窗 ── */
.about-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgb(0 0 0 / 0.55);
}

.about-modal {
  display: flex;
  flex-direction: column;
  width: min(680px, 100%);
  max-height: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-xl);
}

.about-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.about-head b { font-size: 14px; }

.about-body {
  padding: 16px 18px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.75;
  color: var(--sub);
}

.about-body section + section { margin-top: 16px; }

/* 小节标题与顶栏 stat 标签同一套排版（11px/700/大写/加宽字距） */
.about-body h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
}

.about-body p { margin: 0 0 8px; }
.about-body p:last-child { margin-bottom: 0; }
.about-body ul { margin: 0; padding-left: 18px; }
.about-body li { margin: 2px 0; }
.about-body b { color: var(--text); font-weight: 600; }

/* 数据终端语言：数字与符号一律等宽 */
.about-body code { font-family: var(--font-mono); color: var(--text); }

.about-formula {
  margin: 8px 0;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.9;
  color: var(--text);
  white-space: pre;
  overflow-x: auto;
  background: var(--ctl-track);
  border: 1px solid var(--border);
  border-radius: var(--r-m);
}

/* 中等宽度：副标题是品牌区最宽元素，收起为单顶栏腾出空间 */
@media (max-width: 1440px) {
  .brand-sub { display: none; }
}

/* ── 移动端 ── */
@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  .price { font-size: 18px; }

  .seg button { padding: 0 9px; }
  .toggle-btn { padding: 0 9px; }
  .wave-scale { display: none; }

  .legend {
    font-size: 10px;
    left: 12px;
  }
}
