/* ==========================================================================
   设计变量
   ========================================================================== */
:root {
  --bg: #0a0e14;
  --bg-glow: #1a1030;
  --surface: #111823;
  --surface-2: #0b121b;
  --line: #1e293b;
  --line-soft: #16202e;
  --text: #e2e8f0;
  --text-dim: #8b9bb4;
  --text-mute: #64748b;
  --up: #22c55e;
  --down: #f43f5e;
  --gold: #fbbf24;
  --accent: #f472b6;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

/* ==========================================================================
   基础
   ========================================================================== */
*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1000px 560px at 72% -12%, var(--bg-glow), transparent 62%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.55 var(--sans);
}

h1, h2, h3, p, dl, dt, dd { margin: 0; }

button { font: inherit; }

/* ==========================================================================
   工具类
   ========================================================================== */
.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.dim { color: var(--text-dim); }
.small { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ==========================================================================
   按钮 / 表单控件
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: #243044;
  color: var(--text);
  cursor: pointer;
  transition: filter .15s ease, background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.14); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text-dim);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: #2f4056;
}

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-primary {
  background: linear-gradient(180deg, #db2777, #9d174d);
  color: #fff;
}
.btn-buy {
  background: linear-gradient(180deg, #1a7f4b, #14532d);
  color: #dcfce7;
}
.btn-sell {
  background: linear-gradient(180deg, #a51f3c, #7f1d1d);
  color: #ffe4e6;
}

.btn:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input,
select {
  width: 100%;
  padding: 9px 10px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
}
input::placeholder { color: #4b5b70; }
input:disabled {
  background: #0a0f16;
  color: #4b5b70;
}

/* ==========================================================================
   登录页
   ========================================================================== */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(384px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
}

.login-card h1 {
  font-size: 26px;
  letter-spacing: .5px;
}
.login-card h1 span { color: var(--accent); }

.login-note {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-mute);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ==========================================================================
   顶栏
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 18px calc(12px + 3px);
  background: rgba(10, 14, 20, .9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 800;
  letter-spacing: .5px;
  white-space: nowrap;
}
.brand span { color: var(--accent); }

.ticker {
  flex: 1 1 220px;
  min-width: 0;
  font-size: 12px;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.acct {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
.acct > div { display: grid; gap: 2px; }
.acct dt {
  font-size: 11px;
  color: var(--text-mute);
  white-space: nowrap;
}
.acct dd {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.goal-track {
  flex-basis: 100%;
  height: 3px;
  border-radius: 999px;
  background: #1b2334;
  overflow: hidden;
}
.goal-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width .5s ease;
}

/* ==========================================================================
   布局
   ========================================================================== */
.layout {
  max-width: 1320px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.grid-main {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, .95fr);
  gap: 14px;
  align-items: start;
}

.panel {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.panel-head h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .6px;
  color: var(--text-dim);
}

/* ==========================================================================
   货币对选择 / 行情
   ========================================================================== */
.pairs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.pair-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
}
.pair-chip:hover {
  border-color: #33465f;
  color: var(--text);
}
.pair-chip.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  color: var(--text);
}
.pair-code { font-size: 12px; letter-spacing: .3px; }
.pair-price { font-size: 12px; color: var(--text-mute); }
.pair-chip.is-active .pair-price { color: var(--text); }

.chart-wrap {
  position: relative;
  height: 300px;
}
#chart {
  display: block;
  width: 100%;
  height: 100%;
}

.quote {
  display: flex;
  flex-wrap: wrap;
  gap: 26px;
  margin-top: 12px;
}
.quote > div { display: grid; gap: 2px; }
.quote dt { font-size: 11px; color: var(--text-mute); }
.quote dd { font-size: 20px; font-weight: 700; }

/* ==========================================================================
   下单面板
   ========================================================================== */
.form { display: grid; gap: 10px; }

.field { display: grid; gap: 4px; }
.field > label { font-size: 12px; color: var(--text-mute); }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.lot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.lot-chips button {
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #16202e;
  color: var(--text-dim);
  cursor: pointer;
}
.lot-chips button:hover {
  color: var(--text);
  border-color: #33465f;
}

.trade-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 2px;
}
.trade-actions .btn {
  padding: 12px 10px;
  font-size: 14px;
  font-weight: 600;
}

.hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-mute);
}
.hint-warn { color: #fda4af; }

/* ==========================================================================
   表格
   ========================================================================== */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  padding: 0 8px 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .5px;
  text-align: left;
  white-space: nowrap;
  color: var(--text-mute);
  border-bottom: 1px solid var(--line);
}

tbody td {
  padding: 8px;
  white-space: nowrap;
  border-bottom: 1px solid var(--line-soft);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #0e1621; }

td.empty {
  padding: 20px 8px;
  text-align: center;
  color: var(--text-mute);
}

/* ==========================================================================
   排行榜
   ========================================================================== */
tr.is-me { background: #17202f; }
tr.is-me:hover { background: #1b2637; }

.rank-1 { color: var(--gold); font-weight: 700; }
.rank-2 { color: #cbd5e1; font-weight: 600; }
.rank-3 { color: #d97706; font-weight: 600; }

.tag-you {
  margin-left: 5px;
  padding: 0 5px;
  font-size: 10px;
  color: var(--accent);
  border: 1px solid #7f2f52;
  border-radius: 999px;
}

.badge-blown { color: var(--down); }

/* ==========================================================================
   Toast
   ========================================================================== */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  display: grid;
  gap: 8px;
  max-width: min(340px, calc(100vw - 32px));
}

.toast {
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  background: #1b2536;
  border: 1px solid #334155;
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5);
  animation: toast-in .18s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ==========================================================================
   响应式
   ========================================================================== */
@media (max-width: 960px) {
  .grid-main { grid-template-columns: 1fr; }
  .chart-wrap { height: 240px; }
}

@media (max-width: 620px) {
  .layout { padding: 10px; }
  .topbar {
    gap: 10px;
    padding: 10px 12px calc(10px + 3px);
  }
  .acct { gap: 14px; }
  .acct dd { font-size: 13px; }
  .quote { gap: 18px; }
  .quote dd { font-size: 17px; }
  .trade-actions .btn {
    padding: 11px 6px;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* 杠杆 / 金额快捷选择 */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-row button {
  padding: 4px 12px; font-size: 12px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px;
  background: #16202e; color: var(--text-dim);
}
.chip-row button:hover { color: var(--text); border-color: #33465f; }
.chip-row button.is-active {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
/* 保证金预警条 */
.risk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #fde68a;
  background: #2a2410;
  border: 1px solid #7c5a12;
  border-radius: var(--radius-md);
}
.risk-bar.is-urgent {
  color: #fecaca;
  background: #2b1114;
  border-color: #7f1d1d;
}
.risk-bar .spacer { flex: 1 1 0; min-width: 0; }
.risk-bar input { width: 160px; }
.risk-bar .btn { white-space: nowrap; }

.warn-text { color: #fbbf24; }

/* 市场快讯 */
.news-feed {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

.news-item {
  padding: 8px 12px;
  background: #0d1520;
  border-left: 3px solid var(--line);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.news-item.is-fresh {
  background: #141d2c;
  border-left-color: var(--accent);
}
.news-item[data-size="xxl"] {
  background: #24131a;
  border-left-color: var(--down);
}

.news-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.news-tag {
  padding: 0 6px;
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid #33465f;
  border-radius: 999px;
}
.news-item[data-size="xxl"] .news-tag {
  color: #fecaca;
  border-color: #7f1d1d;
}

.news-title { font-weight: 600; }

.news-body {
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
}

.news-impact {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
  font-size: 11px;
  font-family: var(--mono);
}
.news-chip.news-up { color: var(--up); }
.news-chip.news-down { color: var(--down); }
.btn.is-muted {
  color: var(--text-mute);
  border-color: var(--line);
}
/* 交易记录 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(134px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.stat {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}
.stat > span { font-size: 11px; color: var(--text-mute); }
.stat > b { font-size: 15px; font-weight: 600; }
.stat-bar {
  height: 3px;
  margin-top: 4px;
  border-radius: 999px;
  background: #1b2334;
  overflow: hidden;
}
.stat-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transition: width .4s ease;
}
.reason {
  padding: 0 6px;
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.reason-stopout { color: #fbbf24; border-color: #7c5a12; }
.reason-bust { color: var(--down); border-color: #7f1d1d; }
.trade-more {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
.trade-more .btn[hidden] { display: none; }
/* 用户主页 */
.player span[data-user] {
  cursor: pointer;
}
.player span[data-user]:hover {
  color: var(--accent);
  text-decoration: underline;
}

.profile-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 7, 11, .74);
  backdrop-filter: blur(3px);
}

.profile-card {
  width: min(760px, 100%);
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .65);
  overflow: hidden;
}

.profile-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.profile-head h2 {
  font-size: 20px;
  letter-spacing: .5px;
}

.profile-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
  display: grid;
  gap: 14px;
}

.profile-section > h3 {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .6px;
  color: var(--text-mute);
}

#pCurve {
  display: block;
  width: 100%;
  height: 120px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

body.no-scroll { overflow: hidden; }