:root {
  --bg: #eef1f5;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8b9098;
  --muted-2: #a3a8b0;
  --line: #eceff3;
  --green: #1aa36e;
  --green-bg: #e8f6ef;
  --green-bd: #bfe8d2;
  --red: #e55353;
  --red-bg: #fdecee;
  --red-bd: #f5c4c8;
  --gold: #e7c37a;
  --gold-bg: #f6ead0;
  --gold-text: #8a6a2f;
  --shadow: 0 4px 18px rgba(31, 37, 48, 0.05);
  --radius: 16px;
  --font: "Noto Sans CJK SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  overflow: hidden;
}
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px 24px 10px;
  min-height: 0;
}
header.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 76px;
  flex: 0 0 76px;
  padding: 0 4px 10px;
}
header.topbar img.logo {
  width: 70px; height: 70px; border-radius: 16px;
  object-fit: cover; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
header.topbar h1 {
  margin: 0; font-size: 42px; font-weight: 700; letter-spacing: 0.02em;
}
header.topbar .views {
  margin-left: auto;
  display: flex; gap: 6px;
}
header.topbar .views button, .file-btn {
  border: 0; background: transparent; color: var(--muted);
  font-family: inherit; font-size: 12px; cursor: pointer;
  padding: 6px 10px; border-radius: 8px;
}
header.topbar .views button.active { color: var(--text); background: #fff; box-shadow: var(--shadow); }
.app-hidden-hud .hud, body.hide-hud .hud { display: none !important; }
#hud.hide, body.hide-hud #hud { display: none !important; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#view-replay, #view-equity, #view-analysis {
  flex: 1; min-height: 0; display: none; flex-direction: column;
}
#view-replay.active, #view-equity.active, #view-analysis.active { display: flex; }

.replay-row {
  flex: 1; min-height: 0;
  display: flex; gap: 16px;
}
.chart-card {
  flex: 1 1 68%;
  min-width: 0;
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
#main-chart { position: absolute; inset: 0; }
.chart-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.clock {
  position: absolute; left: 22px; top: 16px;
  font-size: 18px; color: #6d737c; font-weight: 500; z-index: 4;
  pointer-events: none;
}
.news-bar {
  position: absolute; left: 22px; top: 48px;
  z-index: 4; display: inline-flex; align-items: center; gap: 10px;
  background: #111b2c; color: #fff; border-radius: 10px;
  padding: 6px 14px 6px 6px; font-size: 15px; line-height: 1.2;
  width: max-content; max-width: calc(100% - 300px);
  white-space: nowrap; overflow: hidden; pointer-events: none;
  box-shadow: 0 2px 10px rgba(17, 27, 44, 0.18);
}
.news-bar .tag {
  background: #6a509e; color: #fff; font-size: 13px; font-weight: 600;
  padding: 5px 10px; border-radius: 7px; flex: 0 0 auto; letter-spacing: 0.02em;
}
.news-bar .time {
  color: #9aa3ad; font-size: 13px; font-weight: 500;
  flex: 0 0 auto; font-variant-numeric: tabular-nums;
}
.news-bar .title { font-weight: 700; color: #fff; font-size: 15px; }
.news-bar .detail { color: #b0b6bf; margin-left: 2px; font-weight: 400; font-size: 14px; }
.news-bar[hidden] { display: none !important; }
.watermark {
  position: absolute; left: 50%; top: 48%;
  transform: translate(-50%, -50%);
  font-size: 88px; font-weight: 600; color: rgba(30,32,36,0.07);
  letter-spacing: 0.04em; white-space: nowrap; user-select: none; z-index: 2;
  pointer-events: none;
}
.entry-label, .liq-badge, .liq-callout, .tp-label, .week-low, .week-pct {
  position: absolute; z-index: 5; pointer-events: none; white-space: nowrap;
}
.marker-no {
  position: absolute; z-index: 5;
  width: 20px; height: 20px; border-radius: 5px;
  color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transform: translate(-50%, -50%);
}
.marker-no.long { background: var(--green); }
.marker-no.short { background: var(--red); }
.entry-label {
  background: var(--green); color: #fff;
  font-size: 11px; line-height: 1.25;
  padding: 4px 8px; border-radius: 4px;
  transform: translate(10px, -50%);
}
.entry-label.short { background: var(--red); }
.tp-label {
  background: var(--green); color: #fff;
  font-size: 11px; line-height: 1.25;
  padding: 4px 8px; border-radius: 4px;
}
.liq-badge {
  background: var(--red); color: #fff;
  font-size: 12px; font-weight: 600;
  padding: 5px 8px; border-radius: 6px;
}
.liq-callout {
  background: var(--red); color: #fff;
  font-size: 11px; line-height: 1.3;
  padding: 5px 8px; border-radius: 6px;
}
.week-low {
  background: #f0c14b; color: #3c2e0a;
  font-size: 11px; font-weight: 600;
  padding: 4px 8px; border-radius: 4px;
}
.week-pct {
  background: #f0c14b; color: #3c2e0a;
  font-size: 11px; font-weight: 600;
  padding: 3px 7px; border-radius: 12px;
}
.price-tag {
  position: absolute; right: 64px; z-index: 5;
  background: #1a1a1a; color: #fff;
  font-size: 14px; font-weight: 600;
  padding: 3px 9px; border-radius: 3px 0 0 3px;
  transform: translateY(-50%);
}
.sibling-card {
  position: absolute; left: 16px; top: 72px; z-index: 6;
  width: 230px; pointer-events: none;
  background: #fff; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  border: 1px solid var(--red-bd);
  overflow: hidden;
}
.sibling-card.flat { border-color: var(--green-bd); }
.sibling-card header {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px 0; font-size: 12px; font-weight: 600;
}
.sibling-card header .qty { color: var(--muted); font-weight: 500; }
.sibling-card header .pnl { margin-left: auto; }
.sibling-card header .pnl.pos { color: var(--green); }
.sibling-card header .pnl.neg { color: var(--red); }
#sibling-chart { height: 88px; }

.right-col {
  flex: 0 0 32%;
  max-width: 620px;
  min-width: 420px;
  display: flex; flex-direction: column; gap: 12px;
  min-height: 0;
}
.case-pill {
  align-self: stretch;
  background: var(--gold-bg);
  color: var(--gold-text);
  font-size: 20px; font-weight: 600;
  text-align: center;
  border-radius: 12px;
  padding: 8px 16px;
  box-shadow: var(--shadow);
}
.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px 18px;
}
.trader-card {
  display: flex; align-items: center; gap: 14px;
}
.trader-card img.avatar {
  width: 68px; height: 68px; border-radius: 50%; object-fit: cover;
  background: #c47a54;
}
.trader-card .name { font-size: 32px; font-weight: 700; flex: 1; }
.trader-card .acct { text-align: right; }
.trader-card .acct .wallet {
  font-size: 16px; color: #444;
}
.trader-card .acct .wallet b { font-size: 28px; font-weight: 700; color: var(--text); }
.trader-card .acct .wd { font-size: 15px; color: var(--muted); margin-top: 2px; }

.pos-card { padding: 14px 18px 12px; border: 1px solid transparent; }
.pos-card.long { background: var(--green-bg); border-color: #d7efe3; }
.pos-card.short { background: var(--red-bg); border-color: #f6d5d8; }
.pos-card.flat { background: #fff; }
.pos-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.pos-head .title { font-size: 34px; font-weight: 700; }
.pos-card.long .pos-head .title { color: var(--green); }
.pos-card.short .pos-head .title { color: var(--red); }
.pos-card.flat .pos-head .title { color: #888; font-size: 28px; }
.pos-head .lev { font-size: 22px; font-weight: 600; color: #3a3a3a; }
.pos-row, .flat-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 18px; padding: 4px 0; color: #4a4f57;
}
.pos-row .k { color: #7a818b; }
.pos-row .v { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 500; }
.pos-row.upnl { margin-top: 8px; padding-top: 6px; font-size: 18px; }
.pos-row.upnl .k { font-size: 18px; }
.pos-row.upnl .v { font-size: 32px; font-weight: 700; }
.pos-row.upnl .v.pos { color: var(--green); }
.pos-row.upnl .v.neg { color: var(--red); }
.flat-body { color: #555; font-size: 16px; line-height: 1.7; }
.flat-body .path { color: var(--green); font-weight: 600; }
.flat-realized { display: flex; justify-content: space-between; align-items: baseline; margin-top: 14px; }
.flat-realized .k { color: #888; }
.flat-realized .v { font-size: 32px; font-weight: 700; color: var(--green); }

.daily-card { padding: 12px 14px 10px; flex: 0 0 auto; }
.daily-head { display: flex; justify-content: space-between; font-size: 16px; color: var(--muted); margin-bottom: 6px; }
#daily-chart { height: 160px; position: relative; }
.daily-frame {
  position: absolute; top: 8px; bottom: 22px;
  background: rgba(232, 196, 110, 0.22);
  border: 1px solid rgba(210, 168, 70, 0.55);
  border-radius: 3px; pointer-events: none; z-index: 2;
}

.log-card { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 16px 10px; }
.log-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.log-head .t { font-size: 22px; font-weight: 700; }
.log-head .sum { font-size: 15px; color: var(--muted); }
.log-list { overflow: auto; flex: 1; min-height: 0; }
.log-row {
  display: grid;
  grid-template-columns: 118px 62px 1fr auto;
  gap: 8px; align-items: center;
  font-size: 16px; padding: 9px 8px;
  border-radius: 6px; color: #333;
}
.log-row.latest { background: #f7f1e4; }
.log-row .tm { color: #666; font-variant-numeric: tabular-nums; }
.log-row .tag {
  display: inline-block; text-align: center;
  color: #fff; font-size: 13px; font-weight: 600;
  border-radius: 4px; padding: 3px 4px;
}
.log-row .tag.long, .log-row .tag.tp { background: var(--green); }
.log-row .tag.short { background: var(--red); }
.log-row .tag.eth { background: #d6a84b; }
.log-row .tag.wd, .log-row .tag.adj { background: #8a8f98; }
.log-row .mid { color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-row .right { color: #555; font-variant-numeric: tabular-nums; text-align: right; }
.log-row .right.pos { color: var(--green); font-weight: 600; }

footer.bottom {
  flex: 0 0 40px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  color: var(--muted-2); font-size: 14px;
}
footer.bottom .social {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; gap: 7px; color: #7a7f86; font-size: 12px;
}
footer.bottom .social svg { width: 16px; height: 16px; display: block; }

#hud {
  position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%);
  z-index: 20;
  background: rgba(255,255,255,0.94);
  border: 1px solid #e3e6eb;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex; align-items: center; flex-wrap: wrap; justify-content: center;
  gap: 8px;
  font-size: 12px;
  max-width: calc(100vw - 32px);
}
#hud button, #hud select, #hud input {
  font-family: inherit; font-size: 12px;
  border: 1px solid #dde1e6; background: #fff;
  border-radius: 6px; padding: 4px 8px; cursor: pointer;
}
#hud input[type="datetime-local"] { width: 196px; }
#hud input[type="number"] { width: 92px; cursor: text; }
#hud .hint { color: var(--muted); font-size: 11px; margin-left: 4px; }

/* Equity */
.page-title { font-size: 20px; font-weight: 600; color: #333; padding: 4px 8px 8px; }
#equity-chart { flex: 1; min-height: 0; position: relative; background: #fff; border-radius: 16px; }
.eq-ann {
  position: absolute; z-index: 4; pointer-events: none; white-space: nowrap;
  font-weight: 700;
}
.eq-ann.peak { color: var(--green); font-size: 22px; }
.eq-ann.wd {
  background: #c9952e; color: #fff; font-size: 13px;
  padding: 3px 8px; border-radius: 4px;
}

/* Analysis */
.an-head { display: flex; align-items: center; gap: 10px; padding: 0 8px 8px; }
.an-head h2 { margin: 0; font-size: 22px; }
.an-badge { background: var(--gold-bg); color: var(--gold-text); font-size: 12px; padding: 3px 10px; border-radius: 10px; }
.an-sum { margin-left: auto; font-size: 14px; color: #444; }
.an-sum .gap { color: var(--red); font-weight: 700; margin-left: 8px; }
.ladder-wrap, .compare-wrap {
  background: #fff; border-radius: 16px; padding: 14px 18px; box-shadow: var(--shadow);
}
.ladder-wrap { margin-bottom: 12px; }
.ladder-wrap h3, .compare-wrap h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; color: #555; }
.ladder {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 8px; height: 180px; position: relative;
}
.ladder-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; }
.ladder-item .box {
  width: 78%; border-radius: 6px 6px 2px 2px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px; text-align: center;
  min-height: 28px;
}
.ladder-item .box.gold { background: #c9a04a; }
.ladder-item .box.green { background: var(--green); }
.ladder-item .sub { font-size: 10px; color: var(--muted); margin-top: 6px; text-align: center; line-height: 1.3; }
.ladder-callout {
  position: absolute; right: 8px; top: 0;
  background: #f3e6c4; color: #8a6a2f;
  font-size: 11px; padding: 3px 8px; border-radius: 6px;
}
#compare-chart { height: 260px; position: relative; }
.an-footnote { font-size: 11px; color: var(--muted); padding: 8px 8px 0; }
.cmp-end {
  position: absolute; right: 16px; z-index: 3; font-weight: 700; pointer-events: none;
}
.cmp-end.pub { color: var(--green); }
.cmp-end.net { color: #222; }
.gap-box {
  position: absolute; right: 18px; bottom: 40px; z-index: 3;
  background: #fdecee; color: var(--red);
  border: 1px solid #f3c4c8; border-radius: 8px;
  padding: 8px 10px; font-size: 12px; width: 160px;
}
.gap-box b { display: block; font-size: 20px; }

.chart-card.has-news .sibling-card { top: 104px; }
#main-chart { z-index: 1; background: transparent !important; }
#main-chart canvas { background: transparent !important; }
.future-shade {
  position: absolute; top: 0; right: 0; bottom: 0;
  background: #f3f2f6;
  z-index: 0;
  pointer-events: none;
}
.tv-lightweight-charts { overflow: hidden; }

#drop-mask {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: rgba(17, 27, 44, 0.45);
  align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 600; letter-spacing: 0.04em;
  pointer-events: none;
}
body.drag-over #drop-mask { display: flex; }
#hud .file-btn, #btn-import-binance {
  font-family: inherit; font-size: 12px; cursor: pointer;
  border: 1px solid #dde1e6; background: #fff;
  border-radius: 6px; padding: 4px 8px;
}
#hud-status { color: var(--muted); font-size: 11px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-card.has-news .sibling-card { top: 108px; }
