/* ================= Binance 行情 App —— 设计系统 ================= */
:root {
  --bg: #0b0e11;
  --bg-elev: #12161c;
  --surface: #161b22;
  --surface-2: #1d232c;
  --surface-3: #262d38;
  --border: rgba(132, 142, 156, 0.16);
  --border-strong: rgba(132, 142, 156, 0.3);
  --text: #eaecef;
  --text-dim: #a7b1bd;
  --muted: #6b7684;
  --accent: #f0b90b;
  --accent-2: #ffd45e;
  --up: #0ecb81;
  --down: #f6465d;
  --info: #4d9fff;
  --purple: #9b8cff;
  --pink: #e75bd0;
  --teal: #26d0a5;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
  overscroll-behavior: none;
}
body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(900px 420px at 12% -8%, rgba(240, 185, 11, 0.10), transparent 60%),
    radial-gradient(700px 380px at 92% 4%, rgba(77, 159, 255, 0.09), transparent 62%);
  pointer-events: none; z-index: 0;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: rgba(132,142,156,0.28); border-radius: 8px; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------------- App 外壳 ---------------- */
#app {
  position: relative; z-index: 1;
  /* 100dvh=当前可见视口高度：安卓 Chrome 横屏时地址栏会占掉一截，
     若用 100% / 100vh（较大视口）会让底部溢出被裁、K 线区被挤没 */
  height: 100%; height: 100dvh; display: flex; flex-direction: column;
}
.topbar {
  padding: calc(var(--safe-t) + 10px) 14px 10px;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, rgba(18,22,28,0.96), rgba(18,22,28,0.72));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-logo {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--accent), #d99e00);
  color: #17191d; font-weight: 800; font-size: 15px;
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(240,185,11,0.32);
}
.brand-title { font-weight: 700; letter-spacing: .2px; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.spacer { flex: 1; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim); transition: .18s;
}
.icon-btn:active { transform: scale(.94); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }
.dot-live { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); transition: .3s; }
.dot-live.on { background: var(--up); box-shadow: 0 0 8px var(--up); animation: pulse 2s infinite; }
.dot-live.err { background: var(--down); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ---------------- 视图容器 ---------------- */
.views { flex: 1; position: relative; min-height: 0; }
.view {
  position: absolute; inset: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  display: none;
}
.view.active { display: block; animation: fadeUp .26s ease both; }
.view.locked { overflow: hidden; padding-bottom: 0; display: none; }
.view.locked.active { display: flex; flex-direction: column; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

/* ---------------- 底部导航 ---------------- */
.tabbar {
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  /* 用「每个子元素一列、等宽、单行」代替写死列数：底部有 5 个 tab（行情/K线/提醒/交易/设置），
     之前写死 repeat(4,1fr) 会把第 5 个挤到第二行、掉出屏幕（手机上看不见「设置」，缩小才能看到）。
     auto-flow:column 对 tab 数量增减都自适应，避免再次踩坑。 */
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: rgba(18,22,28,0.94);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  position: relative; z-index: 6;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 10.5px; font-weight: 600;
  transition: color .2s; position: relative;
}
.tab svg { width: 21px; height: 21px; }
.tab.active { color: var(--accent); }
.tab.active::after {
  content: ""; position: absolute; top: 6px; width: 22px; height: 3px; border-radius: 3px;
  background: var(--accent); box-shadow: 0 0 10px rgba(240,185,11,.7);
}
.tab .badge {
  position: absolute; top: 6px; left: 50%; margin-left: 6px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--down); color: #fff; font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
}
.tab .badge:empty { display: none; }

/* ---------------- 通用组件 ---------------- */
.section { padding: 12px 14px 0; }
.section-head {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 2px 9px;
}
.section-head h2 { margin: 0; font-size: 13px; font-weight: 700; color: var(--text-dim); letter-spacing: .3px; }
.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-elev));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px;
}
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12.5px; font-weight: 600;
  transition: .18s; white-space: nowrap;
}
.chip.active {
  background: linear-gradient(135deg, rgba(240,185,11,0.18), rgba(240,185,11,0.06));
  border-color: rgba(240,185,11,0.55); color: var(--accent);
}
.chip.danger { color: var(--down); border-color: rgba(246,70,93,0.4); }
.chip:active { transform: scale(.96); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); font-weight: 600; font-size: 13.5px; transition: .18s;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #e0a800);
  color: #17191d; border-color: transparent;
  box-shadow: 0 6px 18px rgba(240,185,11,.28);
}
.btn.ghost { background: transparent; }
.btn.danger { color: var(--down); border-color: rgba(246,70,93,.35); background: rgba(246,70,93,.08); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 7px; font-size: 11.5px; font-weight: 700;
}
.pill.up { background: rgba(14,203,129,.13); color: var(--up); }
.pill.down { background: rgba(246,70,93,.13); color: var(--down); }
.pill.flat { background: rgba(132,142,156,.14); color: var(--text-dim); }
.muted { color: var(--muted); }
.dim { color: var(--text-dim); }
.up-t { color: var(--up); }
.down-t { color: var(--down); }

/* 搜索框 */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 9px 12px; margin: 12px 14px 0;
}
.search svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.search input { flex: 1; background: none; border: none; outline: none; font-size: 14px; min-width: 0; }
.search input::placeholder { color: var(--muted); }

/* ---------------- 行情列表 ---------------- */
.mkt-list { margin: 8px 0 0; }
.mkt-row {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 14px; transition: background .15s;
  border-bottom: 1px solid rgba(132,142,156,0.07);
}
.mkt-row:active { background: var(--surface); }
.star { flex: none; width: 26px; height: 26px; display: grid; place-items: center; color: var(--muted); }
.star.on { color: var(--accent); }
.star svg { width: 16px; height: 16px; }
.mkt-ico {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #10141a;
  background: linear-gradient(135deg, #2b3340, #3a4453);
  position: relative; overflow: hidden;
}
.mkt-ico span { position: relative; z-index: 1; }
.mkt-main { flex: 1; min-width: 0; }
.mkt-sym { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.mkt-sym small { font-weight: 600; color: var(--muted); font-size: 11px; }
.mkt-vol { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.mkt-right { text-align: right; flex: none; }
.mkt-price { font-weight: 700; font-size: 14px; }
.mkt-chg { margin-top: 3px; }
.mkt-chg .pill { min-width: 66px; justify-content: center; }

/* ---------------- 图表页 ---------------- */
.chart-head { padding: 10px 14px 8px; border-bottom: 1px solid var(--border); }
.chart-symbol {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
}
.chart-symbol .mkt-ico { width: 38px; height: 38px; font-size: 14px; }
.chart-sym-name { font-size: 16px; font-weight: 800; display: flex; align-items: center; gap: 6px; }
.chart-sym-name svg { width: 14px; height: 14px; color: var(--muted); }
.chart-price { font-size: 22px; font-weight: 800; margin-top: 1px; }
.chart-price-sub { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-top: 2px; }
.interval-bar { display: flex; gap: 6px; overflow-x: auto; padding: 9px 14px; scrollbar-width: none; }
.interval-bar::-webkit-scrollbar { display: none; }
/* 控制条（周期 + 锁定/手绘工具）：竖屏是两行，横屏合并成一行省高度 */
.ctrl-row { display: contents; }
#chartLockBar { padding: 8px 14px 0; flex: none; }
.iv {
  flex: none; padding: 5px 11px; border-radius: 8px; font-size: 12.5px; font-weight: 700;
  color: var(--text-dim); background: var(--surface); border: 1px solid transparent; transition: .16s;
}
.iv.active { color: var(--accent); background: rgba(240,185,11,.12); border-color: rgba(240,185,11,.4); }
/* min-height 用 min(320px, 40vh)：竖屏/桌面仍是 320px；横屏等矮视口自动降到 40vh，
   否则固定 320px 会把矮视口撑破、K 线下半部分被 overflow:hidden 裁掉（看不到「向下笔」等底部内容） */
.chart-wrap { position: relative; flex: 1; min-height: min(320px, 40vh); }
#chart { position: absolute; inset: 0; }
/* 手绘覆盖层（涂鸦笔 / 水平线）：盖在图表之上，未开工具时不拦截手势 */
.draw-layer {
  position: absolute; inset: 0; z-index: 2;
  pointer-events: none; touch-action: none;
}
/* 高性能(GPU)模式：把图表提升为独立合成层，强制硬件加速渲染，减少卡顿 */
#chart.gpu { transform: translateZ(0); backface-visibility: hidden; will-change: transform; }
.legend {
  position: absolute; top: 6px; left: 10px; z-index: 3;
  display: flex; flex-wrap: wrap; gap: 4px 10px; pointer-events: none;
  font-size: 11px; font-weight: 700;
}
.legend .lg { display: inline-flex; align-items: center; gap: 4px; }
.legend .lg i { width: 9px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .lg em { font-style: normal; color: var(--text-dim); font-weight: 600; }
.chart-tools {
  display: flex; gap: 8px; padding: 9px 14px calc(var(--safe-b) + 9px);
  border-top: 1px solid var(--border); background: rgba(18,22,28,.75); backdrop-filter: blur(10px);
}
.chart-tools .btn { flex: 1; padding: 10px 8px; font-size: 13px; }
.chart-tools .btn svg { width: 16px; height: 16px; }

/* 指标图例条 */
.ind-bar { display: flex; gap: 7px; overflow-x: auto; padding: 8px 14px; scrollbar-width: none; }
.ind-bar::-webkit-scrollbar { display: none; }
.ind-chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--border); font-size: 11.5px; font-weight: 700; color: var(--text-dim);
}
.ind-chip i { width: 8px; height: 8px; border-radius: 50%; }
.ind-chip .x { color: var(--muted); font-weight: 800; padding: 0 2px; }
.ind-chip.add { color: var(--accent); border-color: rgba(240,185,11,.4); }

/* 行情快照卡 */
.snap { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px 14px; }
.snap-cell { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 10px; }
.snap-cell .k { font-size: 10.5px; color: var(--muted); font-weight: 600; }
.snap-cell .v { font-size: 14px; font-weight: 800; margin-top: 2px; }

/* ---------------- 横屏（全屏）查看K线 ---------------- */
/* 全屏模式下铺满视口；设备支持全屏 API 时由其接管 */
#view-chart.landscape,
#view-chart:fullscreen {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg); padding: 0;
}
/* 横屏时让 K 线占满：隐藏快照卡与指标条，并把头部/控制条压到最扁 */
#view-chart.landscape {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  /* 底部给导航栏让出高度（横屏导航更矮），这样也能点「行情 / 提醒 / 设置」切换 */
  bottom: calc(46px + var(--safe-b));
}
#view-chart.landscape .snap,
#view-chart.landscape .ind-bar { display: none; }

/* 头部：单行紧凑 */
#view-chart.landscape .chart-head { padding: 4px 14px; }
#view-chart.landscape .chart-symbol { gap: 8px; }
#view-chart.landscape .chart-symbol .mkt-ico { width: 22px; height: 22px; font-size: 10px; border-radius: 6px; }
#view-chart.landscape .chart-sym-name { font-size: 13px; }
#view-chart.landscape .chart-price { font-size: 15px; margin-top: 0; }
#view-chart.landscape .chart-price-sub { display: none; }

/* 周期 + 工具合并成一行，整体扁一半 */
#view-chart.landscape .ctrl-row {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 5px 14px; overflow-x: auto; scrollbar-width: none;
}
#view-chart.landscape .ctrl-row::-webkit-scrollbar { display: none; }
#view-chart.landscape .ctrl-row .interval-bar,
#view-chart.landscape .ctrl-row .chip-row { padding: 0; overflow: visible; flex: none; }
/* 按钮补足高度：之前压到 33px（竖屏 41px）显得「缺高矮」，恢复到与竖屏相当的可点击高度 */
#view-chart.landscape .iv { padding: 6px 11px; font-size: 11.5px; }
#view-chart.landscape .chip { padding: 7px 12px; }

/* 图表本体与底部工具条 */
#view-chart.landscape .chart-wrap { min-height: 0; }
#view-chart.landscape .chart-tools { padding: 4px 14px calc(var(--safe-b) + 4px); }
#view-chart.landscape .chart-tools .btn { padding: 6px 8px; font-size: 12px; }
#view-chart.landscape .chart-tools .btn svg { width: 14px; height: 14px; }
#view-chart:fullscreen .chart-wrap { min-height: 0; }

/* 横屏时把底部导航抬到 K 线之上（保证切页可点），并压矮一点腾出高度 */
#app.landscape-mode .tabbar { z-index: 70; height: calc(46px + var(--safe-b)); }
#app.landscape-mode .tabbar .tab { font-size: 10px; gap: 2px; }
#app.landscape-mode .tabbar .tab svg { width: 18px; height: 18px; }

/* 显式进入横屏时，无论如何都铺满整屏（覆盖桌面端的 460px 限宽；手机同样受益） */
#app.landscape-mode { max-width: none; margin: 0; border-left: none; border-right: none; box-shadow: none; }

/* 设备无法锁定屏幕方向（如 iOS Safari 不支持 orientation.lock / 全屏）时的兜底：
   把 K 线视图整体旋转 90°，物理竖屏也能呈现真正的横屏宽高比，而不是「立着的全屏」。
   仅在 app.js 判定设备仍为竖屏时加 .rot90（安卓能正常转屏时不会命中）。 */
#view-chart.landscape.rot90 {
  top: 50%; left: 50%; right: auto; bottom: auto;
  width: 100vh; width: 100dvh;
  height: 100vw; height: 100dvw;
  transform: translate(-50%, -50%) rotate(-90deg);
  transform-origin: center center;
  padding: 0; z-index: 80;
}
/* 旋转兜底时占满整屏，隐藏竖屏底部导航，避免它在物理底边压住画面 */
#app.landscape-mode.rot90-mode .tabbar { display: none; }

/* ---------------- 手机物理横屏自适应（不点「横屏」按钮，直接转屏） ---------------- */
/* 矮视口基本就是手机横屏（桌面窗口高度普遍 > 520px，不受影响）：
   套用与「横屏」按钮一致的紧凑布局，并把纵向空间让给 K 线，避免竖屏版式被挤爆 */
/* 匹配条件放宽：触摸设备（pointer:coarse）在横屏时一律套用，不再只靠 max-height:520px
   （之前某些手机横屏视口高度 >520px，导致整块紧凑样式没生效 → 「没变」） */
@media (orientation: landscape) and (pointer: coarse), (orientation: landscape) and (max-height: 600px) {
  /* 横屏纵向空间极小（安卓 Chrome 还带地址栏）。顶部/底部/头部/控制条都是固定高度，
     加起来一旦超过视口，flex:1 的 K 线区就会被挤成 0（看起来「像一条线」）。
     因此这里把每一项都压到最扁，保证 K 线拿到足够高度。 */
  .topbar { padding-top: 2px; padding-bottom: 2px; }
  .topbar .brand-logo { width: 24px; height: 24px; font-size: 12px; border-radius: 7px; }
  .topbar .brand-title { font-size: 13px; }
  .topbar .brand-sub { display: none; }
  .topbar .icon-btn { width: 28px; height: 28px; border-radius: 9px; }
  .topbar .icon-btn svg { width: 15px; height: 15px; }
  .tabbar { height: calc(40px + var(--safe-b)); }
  .tabbar .tab { font-size: 9.5px; gap: 1px; }
  .tabbar .tab svg { width: 16px; height: 16px; }

  /* K 线页：头部单行紧凑，隐藏快照卡与指标条 */
  #view-chart .snap,
  #view-chart .ind-bar { display: none; }
  #view-chart .chart-head { padding: 3px 14px; }
  #view-chart .chart-symbol { gap: 8px; }
  #view-chart .chart-symbol .mkt-ico { width: 22px; height: 22px; font-size: 10px; border-radius: 6px; }
  #view-chart .chart-sym-name { font-size: 13px; }
  #view-chart .chart-price { font-size: 15px; margin-top: 0; }
  #view-chart .chart-price-sub { display: none; }

  /* 周期 + 工具合并成一行（竖屏是两行，横屏合并省高度） */
  #view-chart .ctrl-row {
    display: flex; align-items: center; gap: 8px; flex: none;
    padding: 3px 14px; overflow-x: auto; scrollbar-width: none;
  }
  #view-chart .ctrl-row::-webkit-scrollbar { display: none; }
  #view-chart .ctrl-row .interval-bar,
  #view-chart .ctrl-row .chip-row { padding: 0; overflow: visible; flex: none; }
  #view-chart .iv { padding: 5px 10px; font-size: 11.5px; }
  #view-chart .chip { padding: 6px 11px; }

  /* 关键：解除 320px 最小高度，把剩下的高度全给 K 线 */
  #view-chart .chart-wrap { min-height: 0; }
  #view-chart .chart-tools { padding: 3px 14px calc(var(--safe-b) + 3px); }
  #view-chart .chart-tools .btn { padding: 5px; font-size: 11.5px; }
  #view-chart .chart-tools .btn svg { width: 14px; height: 14px; }
}

/* ---------------- 横屏沉浸：K 线占满整屏 ---------------- */
/* 手机横屏是超宽矮屏（19.5:9~20:9 ≈ 2.2:1），纵向远比电脑（16:9/16:10）紧。
   用「宽高比 ≥19:10 且高度 ≤620px」识别手机横屏，电脑窗口不会命中：
   隐藏顶栏，「指标/大大的机会/创建提醒」收进「⋯」，把整屏高度都给 K 线。 */
.chart-menu-btn { display: none; }
.chart-menu-pop {
  position: fixed; z-index: 90; min-width: 150px; padding: 6px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px;
}
.chart-menu-pop button {
  display: flex; align-items: center; gap: 8px;
  text-align: left; padding: 10px 12px; border-radius: 8px;
  font-size: 13px; color: var(--text); white-space: nowrap;
}
.chart-menu-pop button:active { background: var(--surface-3); }

@media (orientation: landscape) and (min-aspect-ratio: 19/10) and (max-height: 620px) {
  .topbar { display: none; }
  #view-chart .chart-menu-btn {
    display: grid;
    position: absolute; top: 6px;
    right: calc(14px + env(safe-area-inset-right, 0px));
    width: 30px; height: 30px; border-radius: 9px;
    background: var(--surface-2); border: 1px solid var(--border);
  }
  /* 头部右侧给「⋯」让位，并收起收藏星标避免重叠 */
  #view-chart .chart-head { padding-right: 56px; }
  #view-chart .chart-head .star { display: none; }
  /* K线全屏时「⋯」右移，给右上角的「退出全屏」让位 */
  #view-chart.kfull .chart-menu-btn { right: calc(14px + env(safe-area-inset-right, 0px) + 104px); }
  /* 指标/大大的机会/创建提醒 收进「⋯」菜单，不再占一整行 */
  #view-chart .chart-tools { display: none; }
}

/* ---------------- K线全屏（独占整屏，保持当前方向） ---------------- */
/* 与「横屏」区分：这里不旋转，只把页面顶栏与底部导航藏起来，把整屏高度让给 K 线。
   #view-chart 脱离文档流固定铺满整屏，退出时再还原。 */
#app.kfull-mode .topbar,
#app.kfull-mode .tabbar { display: none; }

#view-chart.kfull {
  position: fixed; inset: 0; z-index: 80;
  background: var(--bg); padding: 0;
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
}
/* 收起快照卡与指标条，控制条并成一行，剩下的高度全给 K 线 */
#view-chart.kfull .snap,
#view-chart.kfull .ind-bar { display: none; }
#view-chart.kfull .chart-head { padding: 8px 14px 6px; padding-right: 108px; }
#view-chart.kfull .chart-head .star { display: none; }
#view-chart.kfull .ctrl-row {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 5px 14px; overflow-x: auto; scrollbar-width: none;
}
#view-chart.kfull .ctrl-row::-webkit-scrollbar { display: none; }
#view-chart.kfull .ctrl-row .interval-bar,
#view-chart.kfull .ctrl-row .chip-row { padding: 0; overflow: visible; flex: none; }
#view-chart.kfull .chart-wrap { min-height: 0; }

/* 退出全屏：悬浮右上角（全屏时才出现） */
#btnFullscreenExit {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  z-index: 90;
  display: none; align-items: center; gap: 5px;
  padding: 7px 12px; border-radius: 999px;
  background: rgba(28,34,43,.9); border: 1px solid var(--border-strong);
  color: var(--text); font-size: 12.5px; font-weight: 700;
  backdrop-filter: blur(8px); box-shadow: var(--shadow);
}
#btnFullscreenExit svg { width: 15px; height: 15px; }
#btnFullscreenExit:active { transform: scale(.95); }
#view-chart.kfull #btnFullscreenExit { display: inline-flex; }

/* ---------------- 提醒 ---------------- */
.seg { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin: 12px 14px 0; }
.seg button { flex: 1; padding: 8px; border-radius: 9px; font-weight: 700; font-size: 13px; color: var(--text-dim); }
.seg button.active { background: var(--surface-3); color: var(--text); }
.rule {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 13px 14px; border-bottom: 1px solid rgba(132,142,156,0.07);
}
.rule-main { flex: 1; min-width: 0; }
.rule-top { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.rule-sym { font-weight: 800; font-size: 14.5px; }
.tag {
  font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: var(--surface-3); color: var(--text-dim);
}
.tag.golden { background: rgba(14,203,129,.15); color: var(--up); }
.tag.death { background: rgba(246,70,93,.15); color: var(--down); }
.rule-desc { font-size: 12.5px; color: var(--text-dim); margin-top: 5px; }
.rule-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.switch { flex: none; width: 44px; height: 26px; border-radius: 999px; background: var(--surface-3); position: relative; transition: .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #7d8794; transition: .2s; }
.switch.on { background: rgba(240,185,11,.25); }
.switch.on::after { left: 21px; background: var(--accent); }
.alert-item { padding: 12px 14px; border-bottom: 1px solid rgba(132,142,156,0.07); display: flex; gap: 11px; align-items: flex-start; }
.alert-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; font-size: 16px; }
.alert-icon.golden { background: rgba(14,203,129,.14); }
.alert-icon.death { background: rgba(246,70,93,.14); }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 700; font-size: 13.5px; }
.alert-sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.alert-time { font-size: 11px; color: var(--muted); margin-top: 4px; }
.alert-resend {
  flex: none; align-self: center; padding: 6px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--border); transition: .15s;
}
.alert-resend:active { transform: scale(.95); }
.alert-resend:disabled { opacity: .55; }

/* ---------------- 「大大的机会」扫描 ---------------- */
.chip.hot, .btn.hot {
  background: linear-gradient(135deg, rgba(255,152,0,0.22), rgba(255,152,0,0.07));
  border-color: rgba(255,152,0,0.55); color: #ffb74d; font-weight: 700;
}
.opps-card { border-color: rgba(255,152,0,0.4); background: linear-gradient(180deg, rgba(255,152,0,0.09), transparent 72px); }
.opps-head { display: flex; align-items: center; gap: 10px; }
.opps-title { flex: 1; font-weight: 800; color: #ffb74d; font-size: 14px; }
.opps-close { color: var(--muted); font-size: 13px; padding: 2px 6px; }
.opps-range { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.opps-push { font-size: 11.5px; color: var(--text-dim); margin-top: 3px; }
.opps-list { margin-top: 10px; border-top: 1px solid var(--border); }
.opps-row { padding: 8px 0; border-bottom: 1px solid rgba(132,142,156,0.07); display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.opps-sym { font-weight: 700; font-size: 12.5px; }
.opps-desc { font-size: 11.5px; color: var(--text-dim); grid-column: 1; }
.opps-tags { grid-column: 2; grid-row: 1 / -1; align-self: center; display: flex; gap: 6px; }
.opps-time { grid-column: 1; font-size: 11px; color: var(--muted); }
.opps-detail-head { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 11.5px; font-weight: 700; color: var(--text-dim); }
.opps-detail { display: flex; align-items: center; gap: 7px; padding: 4px 0; font-size: 11.5px; color: var(--text-dim); border-bottom: 1px solid rgba(132,142,156,0.06); }
.opps-detail-txt { flex: 1; }
.opps-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.opps-dot.golden { background: var(--up); }
.opps-dot.death { background: var(--down); }
.opps-empty { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ---------------- 通知子类开关 ---------------- */
.filter-group { margin-bottom: 12px; }
.filter-group:last-child { margin-bottom: 0; }
.filter-title { font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.filter-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.filter-chip {
  padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  transition: .15s;
}
.filter-chip.on {
  background: linear-gradient(135deg, rgba(240,185,11,0.18), rgba(240,185,11,0.06));
  border-color: rgba(240,185,11,0.55); color: var(--accent);
}
.filter-chip:active { transform: scale(.96); }

/* ---------------- 表单 ---------------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-dim); margin-bottom: 6px; }
.input, select.input {
  width: 100%; padding: 11px 12px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); outline: none;
  font-size: 14px; transition: border-color .18s;
}
.input:focus { border-color: rgba(240,185,11,.55); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.5; }

/* ---------------- 底部抽屉 ---------------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40;
  opacity: 0; pointer-events: none; transition: opacity .25s; backdrop-filter: blur(2px);
}
.sheet-mask.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--bg-elev); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-top: 1px solid var(--border-strong);
  max-height: 86vh; display: flex; flex-direction: column;
  transform: translateY(102%); transition: transform .3s cubic-bezier(.32,.72,0,1);
  padding-bottom: var(--safe-b);
}
.sheet.show { transform: none; }
.sheet-grab { width: 40px; height: 4px; border-radius: 4px; background: var(--surface-3); margin: 9px auto 4px; }
.sheet-head { display: flex; align-items: center; padding: 8px 16px 12px; gap: 10px; border-bottom: 1px solid var(--border); }
.sheet-head h3 { margin: 0; font-size: 15.5px; font-weight: 800; flex: 1; }
.sheet-body { overflow-y: auto; padding: 14px 16px 20px; }
.sheet-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.sheet-foot .btn { flex: 1; }

.ind-group-title { font-size: 11.5px; font-weight: 800; color: var(--muted); letter-spacing: .5px; margin: 4px 0 9px; }
.ind-add-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 18px; }
.ind-add {
  padding: 10px 8px; border-radius: var(--radius-sm); background: var(--surface);
  border: 1px dashed var(--border-strong); font-size: 12.5px; font-weight: 700; color: var(--text-dim);
  text-align: center; transition: .18s;
}
.ind-add:active { background: var(--surface-2); color: var(--accent); border-color: rgba(240,185,11,.5); }
.ind-edit { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px; margin-bottom: 9px; }
.ind-edit-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.ind-edit-head .color { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ind-edit-head .name { font-weight: 800; font-size: 13.5px; flex: 1; }
.ind-edit-head .x { color: var(--muted); font-size: 18px; line-height: 1; padding: 0 3px; }
.mini-field { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.mini-field label { width: 88px; font-size: 12px; color: var(--text-dim); font-weight: 600; flex: none; }
.mini-field input, .mini-field select {
  flex: 1; padding: 8px 10px; border-radius: 8px; background: var(--surface-2);
  border: 1px solid var(--border); outline: none; font-size: 13px; min-width: 0;
}
.mini-field input:focus, .mini-field select:focus { border-color: rgba(240,185,11,.5); }

/* 颜色选择（MA / EMA 画线配色） */
.color-pick { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.color-pick .sw {
  width: 20px; height: 20px; border-radius: 50%; flex: none; cursor: pointer;
  border: 2px solid transparent; box-shadow: 0 0 0 1px rgba(132,142,156,.25); transition: .15s;
}
.color-pick .sw.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg-elev); transform: scale(1.06); }

/* 我的配置（指标整套保存 / 载入） */
.preset-save { display: flex; gap: 8px; margin-bottom: 10px; }
.preset-save .input { flex: 1; min-width: 0; }
.preset-save .btn { flex: none; white-space: nowrap; }
.preset-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px; margin-bottom: 8px;
}
.preset-info { flex: 1; min-width: 0; }
.preset-name { font-weight: 800; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.preset-row .x { color: var(--muted); font-size: 18px; line-height: 1; padding: 0 3px; flex: none; }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }

/* 触发统计（按交易对+周期分组计数） */
.stat-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(132,142,156,0.07); }
.stat-row:last-child { border-bottom: none; }
.stat-name { font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 7px; }
.stat-count { font-weight: 800; font-size: 14px; color: var(--accent); flex: none; }

/* 交易对选择列表 */
.pick-row { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid rgba(132,142,156,0.07); }
.pick-row .sym { font-weight: 700; flex: 1; }
.pick-row .pr { font-size: 12.5px; color: var(--text-dim); }

/* ---------------- 交易（币安 U 本位合约） ---------------- */
.trade-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.trade-sym {
  display: flex; align-items: center; gap: 5px;
  padding: 7px 11px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  font-weight: 800; font-size: 14px; color: var(--text);
  transition: .18s; flex: none;
}
.trade-sym:active { background: var(--surface-2); }
.trade-sym svg { width: 15px; height: 15px; color: var(--text-dim); }
.trade-px { flex: 1; min-width: 0; }
.trade-last { font-size: 19px; font-weight: 800; line-height: 1.15; }
.trade-px .hint { margin-top: 2px; }

.trade-acct { padding: 14px; }

.qty-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 9px; }
.qty-quick button {
  padding: 8px 0; border-radius: 9px; font-size: 12.5px; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  transition: .15s;
}
.qty-quick button:active { background: var(--surface-3); color: var(--accent); border-color: rgba(240,185,11,.5); }

.orow { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid rgba(132,142,156,0.07); }
.orow:last-child { border-bottom: none; }
.ogrow { flex: 1; min-width: 0; }

/* 交易页盈亏配色（num up / num down） */
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------------- 提示 / Toast ---------------- */
.toasts { position: fixed; left: 0; right: 0; top: calc(var(--safe-t) + 8px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  max-width: 92vw; padding: 10px 14px; border-radius: 12px;
  background: rgba(28,34,43,.97); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
  animation: toastIn .3s cubic-bezier(.32,.72,0,1);
}
.toast.golden { border-color: rgba(14,203,129,.55); }
.toast.death { border-color: rgba(246,70,93,.55); }
.toast.out { animation: toastOut .25s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) scale(.96) } to { opacity: 1; transform: none } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px) } }

/* 骨架屏 */
.skel { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0 } }
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }

/* ---------------- 新设备首次登录 ---------------- */
/* 新设备首次打开时的登录门；登录成功后本机记住，不再出现 */
.login-mask {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: calc(24px + var(--safe-t)) 24px calc(24px + var(--safe-b));
}
.login-box {
  width: 100%; max-width: 320px;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px 18px;
}
.login-brand { font-size: 20px; font-weight: 800; color: #f0b90b; text-align: center; }
.login-sub { font-size: 12px; color: var(--text-dim); text-align: center; margin-bottom: 6px; }
.login-input {
  width: 100%; box-sizing: border-box;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 11px 12px; font-size: 15px; font-family: inherit;
}
.login-input:focus { outline: none; border-color: #f0b90b; }
.login-err { color: #f6465d; font-size: 12px; min-height: 16px; }
.login-btn {
  width: 100%; border: 0; border-radius: 8px;
  background: #f0b90b; color: #14161a;
  font-size: 16px; font-weight: 700; padding: 12px;
  font-family: inherit;
}
.login-btn:disabled { opacity: .6; }
.empty svg { width: 42px; height: 42px; opacity: .4; margin-bottom: 10px; }

/* 桌面（鼠标设备）限宽居中，模拟手机。
   注意：必须限定 hover/pointer，否则手机横屏（宽度 ≥720px）也会被收窄成中间一条，
   看起来就是「K 线只剩中间一半」。 */
@media (min-width: 720px) and (hover: hover) and (pointer: fine) {
  body { background: #05070a; }
  #app {
    max-width: 460px; margin: 0 auto;
    border-left: 1px solid var(--border); border-right: 1px solid var(--border);
    box-shadow: 0 0 60px rgba(0,0,0,.6);
  }
  .sheet { max-width: 460px; margin: 0 auto; }
}
