:root, [data-theme="dark"] {
  --bg: #131722; --panel: #1e222d; --line: #2a2e39; --text: #d1d4dc; --muted: #787b86;
  --hover: #2a2e39; --accent: #2962ff; --up: #26a69a; --down: #ef5350;
}
[data-theme="light"] {
  --bg: #ffffff; --panel: #f8f9fd; --line: #e0e3eb; --text: #131722; --muted: #787b86;
  --hover: #f0f3fa; --accent: #2962ff; --up: #089981; --down: #f23645;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button {
  background: transparent; color: var(--text); border: 0; border-radius: 4px;
  padding: 5px 8px; font: inherit; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--hover); }
button.on { color: var(--accent); background: var(--hover); }

#top {
  display: flex; align-items: center; gap: 4px; padding: 4px 8px;
  border-bottom: 1px solid var(--line); background: var(--bg); flex-wrap: nowrap; overflow-x: auto;
  scrollbar-width: none;
}
#top::-webkit-scrollbar { display: none; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; margin-right: 6px; }
.logo { color: var(--accent); font-size: 16px; }
.sym-btn { font-weight: 700; }
.seg { display: flex; border-left: 1px solid var(--line); padding-left: 4px; margin-left: 2px; }
.seg button { padding: 5px 7px; }
.spacer { flex: 1; }

.dd { position: relative; border-left: 1px solid var(--line); padding-left: 4px; margin-left: 2px; }
.menu {
  display: none; position: fixed; z-index: 30; min-width: 190px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.menu.open { display: block; }
.menu label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.menu label:hover { background: var(--hover); }
.menu .sw { width: 10px; height: 10px; border-radius: 2px; }

main { flex: 1; display: flex; min-height: 0; }
#tools {
  display: flex; flex-direction: column; gap: 2px; padding: 6px 4px;
  border-right: 1px solid var(--line); background: var(--bg);
}
#tools button { width: 32px; height: 32px; padding: 0; font-size: 15px; }

#grid { flex: 1; display: grid; gap: 1px; background: var(--line); min-width: 0; }
#grid.l1 { grid-template: 1fr / 1fr; }
#grid.l2 { grid-template: 1fr / 1fr 1fr; }
#grid.l4 { grid-template: 1fr 1fr / 1fr 1fr; }
.panel { position: relative; background: var(--bg); min-width: 0; min-height: 0; outline: 1px solid transparent; outline-offset: -1px; }
#grid.multi .panel.active { outline-color: var(--accent); }
.panel .cv { position: absolute; inset: 0; }
.panel.drawing .cv { cursor: crosshair; }
.ph {
  position: absolute; z-index: 5; top: 6px; left: 8px; right: 70px;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; pointer-events: none;
  font-size: 12px;
}
.ph .sym { font-weight: 700; font-size: 13px; }
.ph .ivl { color: var(--muted); }
.ph .tag { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: var(--hover); color: var(--muted); }
.ph .tag.live { color: var(--up); }
.ph .ohlc { color: var(--muted); font-variant-numeric: tabular-nums; }
.ph .ohlc b { font-weight: 500; }
.ph .legend { flex-basis: 100%; display: flex; gap: 10px; font-size: 11px; font-variant-numeric: tabular-nums; }
.up { color: var(--up) !important; } .down { color: var(--down) !important; }

#watch { width: 260px; border-left: 1px solid var(--line); display: flex; flex-direction: column; background: var(--bg); }
.wh { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; font-weight: 700; border-bottom: 1px solid var(--line); }
.wcols, .wrow { display: grid; grid-template-columns: 1.2fr 1fr .8fr 18px; gap: 4px; padding: 6px 10px; align-items: center; }
.wcols { color: var(--muted); font-size: 11px; }
.wcols span:nth-child(n+2), .wrow span:nth-child(2), .wrow span:nth-child(3) { text-align: right; }
#wl { overflow-y: auto; flex: 1; }
.wrow { cursor: pointer; font-variant-numeric: tabular-nums; }
.wrow:hover { background: var(--hover); }
.wrow.sel { background: var(--hover); box-shadow: inset 2px 0 var(--accent); }
.wrow .s { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.wrow .s small { display: block; font-weight: 400; color: var(--muted); font-size: 10px; }
.wrow .x { visibility: hidden; padding: 0 2px; color: var(--muted); }
.wrow:hover .x { visibility: visible; }

#hint {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 12px;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
#hint.show { opacity: 1; }

.modal { display: none; position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); align-items: flex-start; justify-content: center; padding: 60px 16px; }
.modal.open { display: flex; }
.box { width: 100%; max-width: 520px; max-height: 70vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.sh { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; font-weight: 700; }
#q { margin: 0 12px 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; outline: none; }
#q:focus { border-color: var(--accent); }
#results { overflow-y: auto; }
.res { display: flex; justify-content: space-between; padding: 9px 14px; cursor: pointer; }
.res:hover, .res.hl { background: var(--hover); }
.res .k { font-weight: 700; }
.res .d { color: var(--muted); font-size: 12px; }

@media (max-width: 760px) {
  .brand .name { display: none; }
  #watch { position: fixed; right: 0; top: 41px; bottom: 0; z-index: 25; transform: translateX(100%); transition: transform .2s; box-shadow: -8px 0 24px rgba(0,0,0,.3); }
  #watch.open { transform: none; }
  #layouts { display: none; }
  #tools { padding: 4px 2px; }
  #tools button { width: 28px; height: 28px; font-size: 13px; }
  .ph { right: 60px; }
}
@media (min-width: 761px) { #wlBtn { display: none; } }
