:root {
  color-scheme: dark;
  --bg: #0d1219;
  --panel: #141b25;
  --raise: #1b2431;
  --line: #273343;
  --chalk: #c8d2de;
  --dim: #8d9aab;
  --faint: #5b6779;
  --up: #26a69a;
  --down: #ef5350;
  --accent: #c9a227;
  --overlay: rgba(13, 18, 25, .82);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

/* 白天模式：同一套变量换一组值，组件样式一行都不用改 */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f3ee;
  --panel: #ffffff;
  --raise: #f0ede6;
  --line: #e0dbd0;
  --chalk: #1d2731;
  --dim: #5e6975;
  --faint: #98a0a9;
  --up: #1e9468;
  --down: #cc4444;
  --accent: #b7800f;
  --overlay: rgba(255, 255, 255, .88);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--chalk); font-family: var(--sans);
  font-size: 13px; line-height: 1.5; overflow: hidden; -webkit-font-smoothing: antialiased;
  /* 竖直方向用 flex 分配：顶部读数栏多高，main 就占剩下的多少。
     写死 calc(100vh - 60px) 会在读数栏变高（窄屏换行）时把底部工具栏顶出视口。 */
  display: flex; flex-direction: column;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
.hidden { display: none !important; }
input, select, textarea {
  font: inherit; color: var(--chalk); background: var(--bg);
  border: 1px solid var(--line); border-radius: 4px; padding: 5px 7px; width: 100%;
}
textarea { resize: vertical; }

#top {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--panel); height: 48px;
}
.brand { font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.symbol { font-family: var(--mono); font-weight: 600; color: var(--chalk); white-space: nowrap; }
.tf { width: auto; min-width: 76px; }
.meta {
  color: var(--dim); font-family: var(--mono); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.spacer { margin-left: auto; }

main {
  display: grid; grid-template-columns: minmax(0, 1fr) 344px;
  flex: 1 1 auto; min-height: 0;
}
/* 网格子项默认 min-height:auto，会被内容撑破容器，把底部工具栏顶出视口 */
main > * { min-height: 0; }

/* 顶部总览读数：初始本金 / 账户权益 / 本局盈亏 ‖ 本场进度 … */
#readout {
  display: flex; align-items: baseline; gap: 26px; flex-wrap: nowrap; overflow-x: auto;
  padding: 12px 20px 10px; border-bottom: 1px solid var(--line); background: var(--panel);
  flex: none;
}

/* 登录界面：账号就是 KakaHouse 的账号（同一个 Supabase 项目） */
.auth {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; background: var(--bg);
}
.auth.hidden { display: none; }
.auth-box {
  width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px;
  padding: 26px 24px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}
.auth-title { font-size: 17px; font-weight: 600; }
.auth-note { font-size: 12px; line-height: 1.6; color: var(--dim); }
.auth-field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--dim); }
.auth-box.busy { opacity: .45; pointer-events: none; }
.auth-error { min-height: 16px; font-size: 12px; color: var(--down); }
.account {
  max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; color: var(--dim);
}
.metric { display: flex; flex-direction: column; gap: 1px; flex-shrink: 0; }
.metric b { font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; font-size: 17px; line-height: 1.15; }
.metric span { font-size: 11px; color: var(--dim); white-space: nowrap; }
.metric.lead b { font-size: 34px; line-height: .95; }
.metric.quiet b { font-size: 14px; color: var(--dim); }
.rsep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
.readout-actions {
  margin-left: auto; display: flex; align-items: center; gap: 8px; align-self: center; flex-shrink: 0;
}
/* 读数栏分组：桌面端全部展开，手机端用「指标」按钮折叠次要指标 */
.ro-group { display: flex; align-items: baseline; gap: 26px; }
.ro-more { display: none; }
/* 移动端专用控件，桌面端一律不显示 */
#btn-sheet, #btn-tools { display: none; }
.sheet-bar { display: none; }
.hints { display: none; }
.chart-col { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-width: 0; position: relative; }
#chart { width: 100%; min-height: 0; }

/* 每个面板左上角的标签，CoinGlass 同款 */
.pane-labels { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.pane-label {
  position: absolute; left: 10px; font-family: var(--mono); font-size: 10px;
  color: #7b879a; letter-spacing: .02em; background: var(--overlay);
  padding: 1px 4px; border-radius: 3px;
}

/* 画线工具条 + 覆盖在图区上的绘图层 */
.tools {
  position: absolute; top: 6px; right: 78px; z-index: 4;
  display: flex; align-items: center; gap: 4px;
  background: var(--overlay); border: 1px solid var(--line);
  border-radius: 5px; padding: 3px;
}

/* K 线左上角：代币名 + 周期选择 */
.chart-head {
  position: absolute; top: 6px; left: 10px; z-index: 4;
  display: flex; align-items: center; gap: 8px;
}
.chart-head .symbol { font-size: 13px; }
.chart-head .tf { background: var(--overlay); }
.tool {
  font-size: 11px; padding: 3px 7px; border-radius: 3px;
  border: 1px solid transparent; color: var(--dim);
}
.tool:hover { color: var(--chalk); border-color: var(--line); }
.tool.on { background: rgba(201, 162, 39, .16); border-color: var(--accent); color: var(--accent); }
.tsep { width: 1px; height: 16px; background: var(--line); margin: 0 2px; }
.draw-layer { position: absolute; pointer-events: none; z-index: 3; }

/* 下单 / 持仓面板 */
.trade-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.muted { color: var(--faint); font-size: 11px; margin-left: auto; }
.field-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.field-row label { width: 34px; color: var(--dim); font-size: 12px; flex: none; }
input[type="range"] { width: 100%; accent-color: var(--accent); padding: 0; }
.pct-row { display: flex; justify-content: space-between; font-size: 10px; color: var(--faint); margin: 2px 0 8px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); margin: 8px 0; }
.check input { width: auto; }
.trade-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.btn.long { background: #1f7a52; border-color: #1f7a52; color: #eafff5; font-weight: 600; }
.btn.short { background: #a3352f; border-color: #a3352f; color: #ffefee; font-weight: 600; }
.pos-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.fills { margin-top: 8px; font-family: var(--mono); font-size: 11px; color: var(--dim); }

/* 仓位历史：一笔仓位一张卡，和币安的口径一致 */
.history { margin-top: 10px; }
.hist { border: 1px solid var(--line); border-radius: 5px; padding: 8px 9px; margin-bottom: 8px; background: var(--raise); }
.hist-trigger { margin-top: 6px; font-family: var(--mono); font-size: 11px; color: var(--faint); }
.hist-round {
  flex: none; padding: 1px 6px; border: 1px solid var(--line); border-radius: 3px;
  font-size: 11px; color: var(--accent); white-space: nowrap;
}
.hist-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.hist-head b { font-family: var(--mono); font-size: 12px; }
.side-tag { font-size: 10px; padding: 1px 5px; border-radius: 3px; color: #fff; }
.side-tag.long { background: #1e9468; }
.side-tag.short { background: #cc4444; }
.hist .kv { font-size: 11px; }

/* 下单 / 持仓 / 账户的新排版（对齐参考产品的三段式布局） */
.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--line); margin: 4px 0 10px; }
.tab { font-size: 13px; padding-bottom: 7px; color: var(--dim); position: relative; }
.tab.on { color: var(--chalk); font-weight: 600; }
.tab.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent); }
.tab.off { color: var(--faint); cursor: not-allowed; }
.last-row { display: flex; justify-content: flex-end; gap: 6px; font-size: 12px; color: var(--faint); margin-bottom: 6px; }
.last-row b { color: var(--dim); font-family: var(--mono); font-weight: 500; }
.amount {
  display: flex; align-items: center; gap: 8px; padding: 0 10px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--raise);
}
.amount input { flex: 1; border: none; background: none; padding: 10px 0; font-size: 14px; }
.amount input:focus { outline: none; }
.amount span { color: var(--faint); font-size: 12px; white-space: nowrap; }
.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-row input { flex: 1; }
.slider-row span { font-size: 12px; color: var(--dim); font-family: var(--mono); min-width: 36px; text-align: right; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 12px; margin-top: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px 10px; margin-top: 9px; }
.cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cell span { font-size: 11px; color: var(--dim); white-space: nowrap; }
.cell b {
  font-family: var(--mono); font-weight: 500; font-size: 13px; color: var(--chalk);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell b.up { color: var(--up); }
.cell b.down { color: var(--down); }
.pos-head { display: flex; align-items: center; gap: 7px; margin-bottom: 2px; flex-wrap: wrap; }
.side-pill { font-size: 11px; padding: 2px 8px; border-radius: 3px; color: #fff; background: #1e9468; }
.side-pill.short { background: #cc4444; }
/* 持仓头部：方向标签和「全仓 Nx」统一成同一尺寸 —— 杠杆那个不该显得更大 */
.pos-head .side-pill,
.pos-head .chip {
  box-sizing: border-box;
  display: inline-flex; align-items: center; justify-content: center;
  height: 22px; padding: 0 9px; border-radius: 3px;
  font-size: 11px; line-height: 1;
}
.pos-head .side-pill { min-width: 34px; }
/* 浮动盈亏一长（几千刀 + 三位数百分比）就会把杠杆标签挤成两行，这里各自不许被压扁 */
.pos-head .chip, .pos-head .side-pill { flex: none; white-space: nowrap; }
.pnl { margin-left: auto; font-family: var(--mono); font-size: 15px; font-weight: 500; white-space: nowrap; }
.pnl.up { color: var(--up); }
.pnl.down { color: var(--down); }
.tpsl-row { display: flex; align-items: center; gap: 8px; margin-top: 11px; font-size: 12px; color: var(--dim); }
.tpsl-row b { margin-left: auto; font-family: var(--mono); color: var(--chalk); font-weight: 500; }
.btn.sq { padding: 8px 0; font-size: 12px; }
.btn.dark { background: #1f2937; border-color: #1f2937; color: #f5f7fa; }
.panel-foot { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 18px; }
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0, 0, 0, .45); }
.modal.hidden { display: none; }
.modal-box {
  width: min(560px, 92vw); max-height: 80vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 12px 14px; overflow: auto; }

/* 调整杠杆弹窗：大字倍数 + 滑杆 + 快捷档位，对齐交易所的下单体验 */
.lev-box { width: min(560px, 92vw); }
.lev-body { padding: 4px 22px 18px; }
.lev-value {
  text-align: center; font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 36px; line-height: 1; padding: 20px 0 16px;
}
.lev-body input[type="range"] { margin: 0 0 16px; }
/* 杠杆滑杆单独做样式：粗一点的轨道 + 金色圆钮，和交易所的手感一致 */
#lev-range { -webkit-appearance: none; appearance: none; height: 22px; background: transparent; }
#lev-range::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--line); }
#lev-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(201, 162, 39, .18);
}
#lev-range::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }
#lev-range::-moz-range-thumb { width: 16px; height: 16px; border: none; border-radius: 50%; background: var(--accent); }
.lev-presets { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; }
.lev-preset {
  padding: 9px 0; border: 1px solid var(--line); border-radius: 4px; white-space: nowrap;
  background: var(--raise); color: var(--dim); font-size: 11px;
  font-family: var(--mono); font-variant-numeric: tabular-nums;
}
.lev-preset:hover { color: var(--chalk); border-color: var(--dim); }
.lev-preset.on { border-color: var(--accent); color: var(--accent); background: rgba(201, 162, 39, .12); }
.lev-note { margin-top: 14px; font-size: 12px; line-height: 1.6; color: var(--dim); }
.lev-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 22px; border-top: 1px solid var(--line);
}
.lev-foot .btn { padding: 8px 26px; }

/* 左侧竖排画线工具栏：窄条、无边框、细线图标（对齐 TradingView 的观感） */
.chart-area { display: flex; min-height: 0; min-width: 0; }
#chart { flex: 1 1 auto; min-width: 0; padding-left: 0; }
.drawbar {
  position: static; flex: 0 0 46px; width: 46px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 8px; background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; overflow-x: hidden; scrollbar-width: none;
}
.drawbar::-webkit-scrollbar { width: 0; height: 0; }
.dtool {
  width: 36px; height: 34px; border: none; border-radius: 6px; background: none;
  color: var(--chalk); opacity: .68; display: grid; place-items: center; padding: 0;
  transition: background .12s, opacity .12s;
}
.dtool svg { width: 22px; height: 22px; }
.dtool:hover { background: var(--raise); opacity: 1; }
.dtool.on { background: var(--raise); opacity: 1; color: var(--accent); box-shadow: inset 0 0 0 1px var(--line); }
.dsep { width: 26px; height: 1px; background: var(--line); margin: 7px 0; }

/* 工具族槽位：右下角小三角表示可以展开 */
.dtool { position: relative; }
.dtool .more {
  position: absolute; right: 3px; bottom: 3px; width: 0; height: 0;
  border-left: 4px solid transparent; border-bottom: 4px solid currentColor; opacity: .5;
}
.flyout {
  /* Lightweight Charts 内部有 z-index:50 的绝对定位层，浮层必须压过它，
     否则工具栏展开的那一列会被图表吞掉点击。 */
  position: absolute; left: 46px; top: 0; z-index: 80; min-width: 172px; overflow: auto;
  max-height: min(70vh, 520px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 3px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
}
.flyout.hidden { display: none; }
.ftool {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 5px 8px;
  border: none; border-radius: 4px; background: none; color: var(--dim);
  font-size: 12px; text-align: left; white-space: nowrap;
}
.ftool svg { width: 18px; height: 18px; flex: none; }
.ftool:hover { background: var(--raise); color: var(--chalk); }
.ftool.on { color: var(--accent); background: var(--raise); }

/* 选中图形后的浮动工具条 + 样式面板（颜色 / 线宽 / 文字） */
.shapemenu {
  position: absolute; z-index: 81; display: flex; gap: 2px; padding: 3px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .28);
}
.shapemenu.hidden, .shapestyle.hidden { display: none; }
.shapemenu button {
  width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 4px; color: var(--dim);
}
.shapemenu button:hover { background: var(--raise); color: var(--chalk); }
.shapemenu svg { width: 16px; height: 16px; }
.shapestyle {
  position: absolute; z-index: 82; width: 198px; padding: 9px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .3);
}
.shapestyle .row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.shapestyle .row:last-child { margin-bottom: 0; }
.shapestyle .row > span { width: 28px; flex: none; color: var(--faint); font-size: 11px; }
.swatches, .widths { display: flex; gap: 5px; }
.sw { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; }
.sw.on { border-color: var(--chalk); }
.wd { width: 27px; height: 22px; display: grid; place-items: center; border-radius: 4px; background: var(--raise); }
.wd.on { box-shadow: inset 0 0 0 1px var(--accent); }
.wd i { display: block; width: 14px; background: var(--chalk); }
.mini {
  padding: 3px 9px; border-radius: 4px; background: var(--raise);
  font-size: 11px; color: var(--chalk);
}
.mini:hover { color: var(--accent); }

/* 面板标签：底色调成面板色，读起来是"标题"而不是压在数据上的文字 */
.pane-label {
  left: 48px; top: auto; background: var(--panel); padding: 1px 4px; border-radius: 2px;
  color: var(--faint); font-size: 10px; letter-spacing: .02em; opacity: .92;
}
.chart-head { left: 58px; }
.fillrow { display: flex; justify-content: space-between; gap: 6px; padding: 2px 0; border-bottom: 1px dashed rgba(39,51,67,.6); }

/* 当前委托：一笔挂单一张卡，和交易所的委托列表同口径 */
.orders { margin-top: 2px; }
.order-card {
  border: 1px solid var(--line); border-radius: 5px; padding: 7px 9px;
  margin-bottom: 6px; background: var(--raise);
}
.order-head { display: flex; align-items: center; gap: 8px; }
.order-head b { font-family: var(--mono); font-size: 13px; }
.order-head .mini { margin-left: 2px; }
.order-meta { margin-top: 4px; font-family: var(--mono); font-size: 11px; color: var(--faint); }
.panel h3 + input, .panel h3 + textarea { margin-bottom: 10px; }

/* 出任何错都要在图区里说清楚，不能只留一块黑屏 */
.fatal {
  position: absolute; inset: 0 0 46px 0; z-index: 5; overflow: auto;
  background: var(--panel); padding: 36px 40px;
}
.fatal.hidden { display: none; }
.fatal b { display: block; color: var(--down); font-size: 15px; margin-bottom: 10px; }
.fatal pre {
  font-family: var(--mono); font-size: 12px; color: var(--dim);
  white-space: pre-wrap; word-break: break-word; margin-bottom: 16px;
}

#transport {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-top: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
#transport select { width: auto; }
.bars { font-family: var(--mono); color: var(--dim); font-size: 12px; margin-left: auto; }
.flags { font-family: var(--mono); font-size: 11px; color: var(--accent); }

.btn {
  padding: 5px 11px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--raise); color: var(--chalk); white-space: nowrap;
}
.btn:hover { border-color: var(--dim); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #1a1509; border-color: var(--accent); font-weight: 600; }
.btn.primary:disabled { background: var(--raise); color: var(--dim); border-color: var(--line); }
.btn.wide { width: 100%; margin-top: 10px; padding: 8px; }

.panel {
  border-left: 1px solid var(--line); background: var(--panel);
  overflow-y: auto; padding: 14px;
}
.block { margin-bottom: 16px; }
.block.disabled { opacity: .45; pointer-events: none; }
.block.hidden { display: none; }
/* 右栏每个板块独立成卡：下单 / 持仓 / 委托 / 账户各自一块背景，扫读时不会串行 */
.panel > .block {
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
}
.panel > .block:last-of-type { margin-bottom: 0; }
h3 { font-size: 12px; color: var(--dim); font-weight: 600; margin-bottom: 8px; letter-spacing: .04em; }
.hint { font-size: 11px; color: var(--faint); margin-top: 6px; }
.warn { font-size: 11px; color: var(--down); margin-top: 6px; min-height: 14px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--raise); font-size: 12px;
}
.chip.on { border-color: var(--accent); color: var(--accent); }
.chip.long.on { border-color: var(--up); color: var(--up); }
.chip.short.on { border-color: var(--down); color: var(--down); }
.chip:disabled { opacity: .35; text-decoration: line-through; }

.row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.row label { width: 34px; color: var(--dim); font-size: 12px; flex: none; }
.mini {
  font-size: 11px; padding: 4px 7px; border: 1px solid var(--line);
  border-radius: 4px; background: var(--raise); color: var(--dim); white-space: nowrap;
}
.mini:hover { color: var(--chalk); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }

.kv { font-family: var(--mono); font-size: 12px; color: var(--dim); }
.kv div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed rgba(39,51,67,.6); }
.kv div > span { flex: none; padding-right: 10px; }
.kv div > b { text-align: right; }
.kv b { color: var(--chalk); font-weight: 500; }
.kv b.up { color: var(--up); }
.kv b.down { color: var(--down); }

.bot { margin-top: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--raise); }
.bot.hidden { display: none; }
.bot h4 { font-size: 12px; margin-bottom: 6px; color: var(--accent); }
.bot p { font-size: 11px; color: var(--dim); margin-top: 4px; }

.loading { color: var(--dim); font-size: 12px; padding: 8px 0; }
.loading.hidden { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--raise); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 14px; font-size: 12px; opacity: 0; transition: all .18s; pointer-events: none;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 980px) {
  main { grid-template-columns: 1fr; grid-template-rows: minmax(280px, 45vh) minmax(0, 1fr); }
  .panel { border-left: none; border-top: 1px solid var(--line); }
  /* 平板宽度放不下 7 个指标 + 4 个按钮，让它换行，不要横向溢出到看不见 */
  #readout { flex-wrap: wrap; overflow: visible; row-gap: 6px; }
  .ro-rest { flex-wrap: wrap; row-gap: 6px; }
  .readout-actions { margin-left: 0; }
}

/* ==================== 手机端 ====================
   竖屏手机的核心矛盾：图表和表单抢同一块竖向空间。做法是让图表占满，
   表单区块变成底部抽屉（默认收起，点「判断 / 下单」滑上来），底部操作条常驻。
   画线工具栏也收进抽屉，默认不占图宽。 */
@media (max-width: 820px) {
  body {
    height: 100dvh; font-size: 14px; overflow: hidden;
    -webkit-tap-highlight-color: transparent;
  }

  /* 顶部读数：只留三个主指标，其余点「指标」展开 */
  #readout {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 8px; padding: 8px 10px; overflow: visible; align-items: center;
  }
  .ro-lead { gap: 14px; min-width: 0; }
  .metric.lead b { font-size: 22px; }
  .metric b { font-size: 14px; }
  .metric span { font-size: 10px; }
  .ro-rest { display: none; grid-column: 1 / -1; flex-wrap: wrap; gap: 10px 16px; }
  #readout.more .ro-rest { display: flex; }
  .ro-rest .rsep { display: none; }
  .ro-more {
    display: inline-flex; align-items: center; padding: 6px 10px; border: 1px solid var(--line);
    border-radius: 4px; background: var(--raise); color: var(--dim); font-size: 12px; white-space: nowrap;
  }
  .readout-actions { grid-column: 1 / -1; margin: 0; flex-wrap: wrap; gap: 6px; }
  .readout-actions .btn { padding: 6px 10px; font-size: 12px; }
  #account { display: none; }

  /* 图表吃满剩余高度；右侧面板不再参与排版 */
  main { display: block; }
  .chart-col { height: 100%; }
  .chart-area { position: relative; }
  #chart { touch-action: none; }

  /* 画线工具：左侧滑出式抽屉，默认收起，把宽度全部让给 K 线 */
  .drawbar {
    position: absolute; left: 0; top: 0; bottom: 0; width: 56px; z-index: 22;
    transform: translateX(-102%); transition: transform .2s ease;
    padding: 8px 0; border-right: 1px solid var(--line); background: var(--panel);
  }
  .drawbar.open { transform: translateX(0); box-shadow: 6px 0 22px rgba(0, 0, 0, .38); }
  .dtool { width: 44px; height: 44px; }
  .dtool svg { width: 24px; height: 24px; }
  .flyout { left: 56px; max-height: 58vh; }
  .chart-head { left: 8px; }
  .pane-label { left: 8px; font-size: 9px; }

  /* 底部操作条：手指够得到的常驻区 */
  #transport {
    position: relative; z-index: 28;
    display: grid; grid-template-columns: auto auto auto minmax(0, 1fr);
    gap: 6px; padding: 7px 9px calc(7px + env(safe-area-inset-bottom, 0px));
  }
  #transport .btn { min-height: 40px; padding: 0 10px; font-size: 13px; }
  #transport .btn { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  #transport select { min-height: 40px; width: auto; }
  #btn-step { grid-column: 1; }
  #btn-play { grid-column: 2; }
  #speed { grid-column: 3; }
  #btn-sheet { grid-column: 4; display: inline-flex; align-items: center; justify-content: center; }
  #btn-decide, #btn-tools { display: inline-flex; align-items: center; min-height: 34px; font-size: 12px; }
  #btn-decide { grid-column: 1 / 3; }
  #btn-tools { grid-column: 3 / 5; }
  /* 根数 + 数据标记挤在一行里，行高比两行省 20 多像素 */
  #bars, #flags { grid-column: 1 / -1; font-size: 11px; line-height: 1.35; }
  .bars { margin-left: 0; }
  #flags { overflow-wrap: anywhere; }

  /* 右侧面板 → 底部抽屉 */
  .panel {
    position: fixed; left: 0; right: 0; bottom: var(--transport-h, 108px); z-index: 26;
    height: min(76dvh, 660px);
    border-left: none; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    padding: 0 12px calc(18px + env(safe-area-inset-bottom, 0px));
    /* 收起时必须连"贴住操作条"的那段高度一起挪走，不然会露出一截压住按钮 */
    transform: translateY(calc(100% + var(--transport-h, 108px)));
    transition: transform .24s ease;
    box-shadow: 0 -14px 34px rgba(0, 0, 0, .42);
    overscroll-behavior: contain;
  }
  .panel.open { transform: translateY(0); }
  /* 抽屉头是"抓手"：touch-action 关掉滚动手势，交给 JS 做下拉收起 */
  .sheet-bar {
    display: block; position: sticky; top: 0; z-index: 3; background: var(--panel);
    padding-top: 6px; touch-action: none;
  }
  .sheet-btn {
    display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 8px 4px 10px; border-bottom: 1px solid var(--line); text-align: left;
    cursor: grab;
  }
  .sheet-btn:active { cursor: grabbing; }
  .sheet-grip { width: 34px; height: 4px; border-radius: 2px; background: var(--line); flex: none; }
  .sheet-btn b { font-size: 14px; white-space: nowrap; }
  .sheet-note { color: var(--dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sheet-arrow { margin-left: auto; color: var(--dim); font-size: 11px; flex: none; }
  .panel > .block:first-of-type { margin-top: 10px; }
  /* 抽屉头是 sticky 的，锚点跳转要给它留出高度，不然标题会被盖住 */
  .panel > .block { scroll-margin-top: 56px; }

  /* 手机端输入一律 16px 起：iOS 聚焦时才不会自动放大整页 */
  input, select, textarea { font-size: 16px; min-height: 40px; }
  textarea { min-height: 66px; }
  .panel h3 { margin-top: 12px; }
  .panel h3 + input, .panel h3 + textarea { margin-bottom: 6px; }
  .chip { min-height: 38px; padding: 8px 12px; font-size: 13px; }
  .hints { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
  .hints .chip {
    background: transparent; color: var(--dim); font-size: 12px;
    min-height: 32px; padding: 5px 10px;
  }
  .hints .chip.on { border-color: var(--accent); color: var(--accent); background: var(--raise); }
  .btn, .mini { min-height: 38px; }
  .mini { font-size: 12px; padding: 6px 10px; }
  .trade-buttons { gap: 10px; }
  .trade-buttons .btn { min-height: 46px; font-size: 15px; }
  .pos-actions { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .pos-actions .btn { min-height: 44px; }
  .grid3 { grid-template-columns: repeat(2, 1fr); }
  .slider-row input[type="range"] { height: 32px; }
  .panel-foot { margin-bottom: 6px; }
}

/* 横屏手机：竖向空间只有 350~450px，抽屉放不下，退回「左图右栏」两列 */
@media (orientation: landscape) and (max-height: 560px) and (max-width: 1100px) {
  body { height: 100dvh; overflow: hidden; }
  /* 横屏只有 350~450px 高，读数栏只留三个主指标，把高度让给 K 线 */
  #readout { display: flex; flex-wrap: nowrap; overflow-x: auto; padding: 4px 12px; gap: 16px; }
  .ro-rest { display: none; }
  .ro-more { display: none; }
  .metric.lead b { font-size: 18px; }
  .metric b { font-size: 13px; }
  .readout-actions { margin-left: auto; flex-wrap: nowrap; }
  /* 单行两列：≤980 那套"上图下表"的行定义要一起覆盖，否则图表被压在 280px 的行里 */
  main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: minmax(0, 1fr); }
  .chart-col { height: 100%; }
  .drawbar {
    position: static; transform: none; width: 46px; flex: 0 0 46px;
    border-right: 1px solid var(--line); box-shadow: none;
  }
  .dtool { width: 36px; height: 34px; }
  .dtool svg { width: 22px; height: 22px; }
  .flyout { left: 46px; max-height: 70vh; }
  .chart-head { left: 58px; }
  .pane-label { left: 48px; font-size: 10px; }
  #transport { display: flex; flex-wrap: wrap; gap: 6px; padding: 7px 10px; }
  #transport .btn { min-height: 34px; padding: 0 10px; }
  #transport select { min-height: 34px; }
  #bars, #flags { grid-column: auto; }
  .bars { margin-left: auto; }
  #btn-sheet, #btn-tools { display: none; }
  .panel {
    position: static; transform: none; height: auto; max-height: none;
    border-radius: 0; border-top: none; border-left: 1px solid var(--line);
    padding: 12px; box-shadow: none; overscroll-behavior: auto;
  }
  .sheet-bar { display: none; }
  input, select, textarea { font-size: 16px; min-height: 38px; }
  .hints { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
  .hints .chip {
    background: transparent; color: var(--dim); font-size: 12px; min-height: 30px; padding: 4px 9px;
  }
  .hints .chip.on { border-color: var(--accent); color: var(--accent); background: var(--raise); }
}
