:root {
  --bg0: #0b1015;
  --bg1: #141b22;
  --bg2: #1a232d;
  --line: #2a3746;
  --text: #eef3f8;
  --muted: #8fa3b5;
  --accent: #2bb3a0;
  --ok: #5dce8a;
  --warn: #e0a24a;
  --danger: #e06a6a;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --pad: max(12px, env(safe-area-inset-left));
  --pad-r: max(12px, env(safe-area-inset-right));
  --pad-b: max(16px, env(safe-area-inset-bottom));
  --tap: 44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html {
  margin: 0;
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(43, 179, 160, 0.16), transparent 55%),
    radial-gradient(700px 360px at 100% 0%, rgba(224, 162, 74, 0.08), transparent 50%),
    var(--bg0);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
  overflow-x: clip;
  width: 100%;
}
/* 仅锁底层滚动；勿设 touch-action:none（会继承并禁掉详情区内滑动） */
body.history-open {
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: max(10px, env(safe-area-inset-top)) var(--pad-r) 10px var(--pad);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 16, 21, 0.92);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.03em;
  font-weight: 700;
}
.brand h1 span { color: var(--accent); }
.brand p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.trade-board-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
}
#tradeBoardUpdated {
  font-size: 0.72rem;
  color: var(--muted);
  max-width: 42vw;
  text-align: right;
  line-height: 1.3;
}
#tradeBoardUpdated.log-alive { color: var(--ok); }
#tradeBoardUpdated.log-slow { color: var(--warn); }
#tradeBoardUpdated.log-stale,
#tradeBoardUpdated.log-missing { color: var(--danger); }
.meta-actions {
  display: flex;
  gap: 0.4rem;
}

.main {
  padding: 12px var(--pad-r) var(--pad-b) var(--pad);
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.panel {
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 12px 16px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.btn {
  border: 1px solid var(--line);
  background: var(--bg0);
  color: var(--text);
  border-radius: 10px;
  min-height: 36px;
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s, transform .1s;
  user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn.ghost { background: transparent; }
.btn.primary {
  background: linear-gradient(180deg, #2bb3a0, #1f8f80);
  border-color: #2bb3a0;
  color: #041412;
  font-weight: 650;
  width: 100%;
  min-height: var(--tap);
  margin-top: 0.4rem;
  font-size: 1rem;
}

.login-body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 20px var(--pad) var(--pad-b);
}
.login-wrap { width: min(400px, 100%); }
.login-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.35rem 1.15rem 1.45rem;
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  border: 1px solid var(--line);
  border-radius: 16px;
}
.login-panel h1 { margin: 0; font-size: 1.35rem; }
.login-panel h1 span { color: var(--accent); }
.login-panel > p {
  margin: -0.25rem 0 0.1rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.login-panel label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.login-panel input {
  min-height: var(--tap);
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg0);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 避免 iOS 自动放大 */
}
.login-panel input:focus {
  outline: 2px solid rgba(43, 179, 160, 0.35);
  border-color: var(--accent);
}
.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid rgba(224, 106, 106, 0.35);
  border-radius: 10px;
  background: rgba(224, 106, 106, 0.08);
}

.trade-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.trade-summary > div {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(10, 14, 18, 0.55);
  border: 1px solid rgba(45, 59, 74, 0.7);
}
.trade-summary > div:first-child {
  grid-column: 1 / -1;
  background: rgba(43, 179, 160, 0.08);
  border-color: rgba(43, 179, 160, 0.28);
}
.trade-summary label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.trade-summary strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  word-break: break-all;
}
.trade-summary > div:first-child strong { font-size: 1.45rem; }
.trade-summary .flow-sub {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.trade-summary .side-buy { color: var(--ok); }
.trade-summary .side-sell { color: var(--danger); }

.trade-assets {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: none;
  overflow: visible;
}
.trade-asset {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto;
  column-gap: 10px;
  row-gap: 2px;
  padding: 12px;
  min-height: var(--tap);
  border-radius: 12px;
  background: rgba(10, 14, 18, 0.45);
  border: 1px solid rgba(45, 59, 74, 0.65);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.trade-asset:active { background: rgba(43, 179, 160, 0.08); }
.trade-asset.active {
  border-color: var(--accent);
  background: rgba(43, 179, 160, 0.1);
}
.trade-asset.usdt-only { cursor: default; }
.trade-asset.usdt-only:active { background: rgba(10, 14, 18, 0.45); }
.trade-asset .sym {
  grid-column: 1;
  grid-row: 1;
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-weight: 600;
}
.trade-asset.active .sym { color: var(--accent); }
.trade-asset .val {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  font-size: 1.12rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: right;
}
.trade-asset .sub {
  grid-column: 1;
  grid-row: 2;
  font-size: 0.72rem;
  color: var(--muted);
}
.trade-asset .flow-preview {
  grid-column: 1 / -1;
  grid-row: 3;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  line-height: 1.35;
}
.trade-asset .flow-preview .side-buy { color: var(--ok); }
.trade-asset .flow-preview .side-sell { color: var(--danger); }
.trade-asset .profit-up { color: var(--ok); }
.trade-asset .profit-down { color: var(--danger); }
.trade-asset .chev {
  display: none;
}
.trade-empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 1rem 0.25rem;
  text-align: center;
}

.trade-history {
  margin-top: 12px;
  border-radius: 14px;
  background: rgba(10, 14, 18, 0.35);
  border: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}
.trade-history[hidden] { display: none !important; }
.trade-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  flex-shrink: 0;
}
.trade-history-head strong {
  font-size: 1rem;
  flex: 1;
  min-width: 0;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trade-history-head .btn-back {
  flex-shrink: 0;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 0.65rem;
}
.trade-history-head .head-spacer {
  flex-shrink: 0;
  width: var(--tap);
  height: 1px;
  visibility: hidden;
}
.trade-history-scroll {
  min-width: 0;
  max-width: 100%;
}
.trade-history-meta {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
  margin-bottom: 0.55rem;
  word-break: break-word;
}

/* 手机：币种详情全屏 H5 页；整页滚动更稳（避免嵌套 overflow + touch 被禁） */
@media (max-width: 719px) {
  .trade-history {
    position: fixed;
    inset: 0;
    z-index: 40;
    margin: 0;
    border-radius: 0;
    border: none;
    padding:
      max(8px, env(safe-area-inset-top))
      var(--pad-r)
      var(--pad-b)
      var(--pad);
    background: var(--bg0);
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .trade-history-head {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0 calc(-1 * var(--pad-r)) 8px calc(-1 * var(--pad));
    padding: 4px var(--pad-r) 10px var(--pad);
    border-bottom: 1px solid var(--line);
    background: rgba(11, 16, 21, 0.96);
    backdrop-filter: blur(10px);
  }
  .trade-history-scroll {
    overflow: visible;
    padding-bottom: 8px;
  }
  .trade-curve-wrap,
  .trade-flow,
  .trade-history-list {
    max-width: 100%;
    min-width: 0;
  }
  .trade-curve-scroll {
    touch-action: pan-x;
  }
  .trade-hist-card .row1,
  .trade-hist-card .row2 {
    flex-wrap: wrap;
  }
  .trade-hist-card .time,
  .trade-hist-card .muted {
    max-width: 100%;
    overflow-wrap: anywhere;
  }
}

.trade-flow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}
.trade-flow > div {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(15, 20, 25, 0.65);
  border: 1px solid rgba(45, 59, 74, 0.65);
}
.trade-flow label {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  margin-bottom: 0.12rem;
}
.trade-flow strong {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.trade-flow .side-buy { color: var(--ok); }
.trade-flow .side-sell { color: var(--danger); }

.trade-curve-wrap { margin: 0 0 10px; }
.trade-curve-legend {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.trade-curve-legend .lg-hint {
  width: 100%;
  margin-left: 0;
  opacity: 0.85;
}
.trade-curve-legend .lg-net::before,
.trade-curve-legend .lg-buy::before,
.trade-curve-legend .lg-sell::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 3px;
  margin-right: 0.28rem;
  vertical-align: middle;
  border-radius: 2px;
}
.trade-curve-legend .lg-net::before { background: var(--accent); }
.trade-curve-legend .lg-buy::before { background: var(--ok); width: 8px; height: 8px; border-radius: 50%; }
.trade-curve-legend .lg-sell::before { background: var(--danger); width: 8px; height: 8px; border-radius: 50%; }
.trade-curve-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  cursor: grab;
  background: #080c10;
  border: 1px solid var(--line);
  border-radius: 10px;
  scrollbar-width: thin;
  user-select: none;
  max-width: 100%;
  width: 100%;
}
.trade-curve-scroll.dragging { cursor: grabbing; }
.trade-curve {
  height: 160px;
  display: block;
  min-width: 100%;
}
.trade-curve .grid { stroke: rgba(45, 59, 74, 0.7); stroke-width: 1; stroke-dasharray: 3 4; }
.trade-curve .net-line { fill: none; stroke: var(--accent); stroke-width: 2; }
.trade-curve .dot-buy { fill: var(--ok); }
.trade-curve .dot-sell { fill: var(--danger); }
.trade-curve .label {
  fill: var(--muted);
  font-size: 10px;
  font-family: var(--mono);
}

.trade-history-list {
  max-height: none;
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: var(--font);
  font-size: 0.82rem;
  line-height: 1.4;
}
.trade-hist-card {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15, 20, 25, 0.7);
  border: 1px solid rgba(45, 59, 74, 0.65);
}
.trade-hist-card .row1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.trade-hist-card .side {
  font-weight: 700;
  font-size: 0.88rem;
}
.trade-hist-card .side-buy { color: var(--ok); }
.trade-hist-card .side-sell { color: var(--danger); }
.trade-hist-card .time {
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}
.trade-hist-card .row2 {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-variant-numeric: tabular-nums;
}
.trade-hist-card .amt { font-weight: 650; }
.trade-hist-card .muted { color: var(--muted); font-size: 0.72rem; }

/* 宽屏略放大留白，仍保持 H5 卡片风格 */
@media (min-width: 720px) {
  .main { padding-top: 18px; }
  .trade-summary { grid-template-columns: repeat(4, 1fr); }
  .trade-summary > div:first-child { grid-column: auto; }
  .trade-assets {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .trade-flow { grid-template-columns: repeat(4, 1fr); }
  .trade-curve { height: 180px; }
  .trade-curve-legend .lg-hint {
    width: auto;
    margin-left: auto;
  }
}
