:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #8c8c8c;
  --line: #ececec;
  --primary: #0d7a4f;
  --primary-dark: #0a5f3d;
  --up: #0d7a4f;
  --down: #e64545;
  --green: #0d7a4f;
  --red: #e64545;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  --safe-bottom: env(safe-area-inset-bottom);
  --nav-h: 48px;
  --tab-h: 52px;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: #fff;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.wrap {
  width: min(480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  padding: 0 0 calc(var(--tab-h) + var(--safe-bottom) + 12px);
  position: relative;
}

#app-view { min-height: 100vh; }

.page { display: block; }

.boot {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  background: #fff;
}

/* —— 登录（传统 App） —— */
body.is-login {
  background: #fff;
}

body.is-login .wrap {
  width: 100%;
  max-width: none;
  background: #fff;
  padding: 0;
}

body.is-login .boot {
  background: #fff;
}

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 28px calc(40px + env(safe-area-inset-bottom));
  background: #fff;
}

.gate-panel {
  width: min(360px, 100%);
}

.gate-brand {
  text-align: center;
  margin-bottom: 40px;
}

.gate-logo {
  display: block;
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 16px;
}

.gate-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.gate-form {
  margin: 0;
  display: grid;
  gap: 18px;
}

.gate-form label {
  display: block;
  margin: 0;
}

.gate-form label span {
  display: block;
  margin-bottom: 8px;
  color: #666;
  font-size: 13px;
}

.gate-form input,
input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  background: #fafafa;
  color: var(--ink);
}

.gate-form input:focus,
input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.gate-form button[type="submit"],
button[type="submit"],
#more,
.stack-form button[type="submit"] {
  width: 100%;
  height: 48px;
  margin-top: 8px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.gate-form button[type="submit"]:active,
button[type="submit"]:active {
  background: var(--primary-dark);
}

#more {
  margin-top: 8px;
  background: transparent;
  color: var(--primary);
  border: 1px solid #cfe3d8;
}

button:disabled { opacity: 0.55; cursor: default; }

.form-error, .block-error {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 13px;
}

label { display: block; margin-bottom: 14px; }

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

/* —— 顶栏 —— */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: 15;
  height: var(--nav-h);
  padding: 0 12px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.nav-title {
  margin: 0;
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-bar > .nav-title:first-child {
  text-align: left;
}

.nav-action,
.nav-back {
  flex-shrink: 0;
  min-width: 48px;
  height: 32px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
}

.nav-back {
  text-align: left;
  padding-left: 0;
}

.nav-spacer {
  min-width: 48px;
  flex-shrink: 0;
}

.updated {
  margin: 0;
  padding: 8px 16px 0;
  color: var(--muted);
  font-size: 12px;
}

/* —— 资产横幅 —— */
.asset-banner {
  margin: 0;
  padding: 18px 16px 16px;
  background: linear-gradient(160deg, #0f8a5a 0%, #0d7a4f 48%, #0a6340 100%);
  color: #fff;
}

.me-banner {
  margin-top: 0;
}

.banner-top .asset-head {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
}

.eye-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  padding: 2px;
  margin: 0;
  line-height: 1;
}

.eye-btn svg {
  display: block;
  width: 15px;
  height: 15px;
}

.pill {
  padding: 1px 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 11px;
}

.asset-value {
  margin: 10px 0 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: #fff;
}

.today-pnl {
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
}

.today-pnl.up,
.today-pnl.down,
.today-pnl.flat {
  color: rgba(255, 255, 255, 0.92);
}

.banner-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.banner-stat span {
  display: block;
  margin-bottom: 4px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

.banner-stat strong {
  display: block;
  font-size: 16px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.float-pnl,
.month-pnl-value,
.year-pnl-value {
  color: #fff !important;
}

/* —— 卡片 / 列表 —— */
.card {
  margin: 12px 12px 0;
  padding: 14px 14px 12px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: none;
}

.card > h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
}

.pnl-card { padding-bottom: 10px; }

.pnl-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.pnl-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
}

.month-nav button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
}

.month-nav button:disabled { opacity: 0.28; }

#month-label {
  min-width: 72px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-cell {
  aspect-ratio: 1 / 1.05;
  min-height: 0;
  padding: 5px 2px 4px;
  border-radius: 6px;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
}

.cal-cell.empty { visibility: hidden; }

.cal-day {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
}

.cal-pnl {
  max-width: 100%;
  padding: 0 1px;
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  text-align: center;
  word-break: break-all;
}

.cal-cell.up { background: #eaf7f0; }
.cal-cell.up .cal-day,
.cal-cell.up .cal-pnl { color: var(--up); }

.cal-cell.down { background: #fdecec; }
.cal-cell.down .cal-day,
.cal-cell.down .cal-pnl { color: var(--down); }

.cal-cell.future .cal-day,
.cal-cell.flat .cal-day { color: var(--muted); }

.cal-cell.today {
  box-shadow: inset 0 0 0 1.5px var(--primary);
}

.cal-cell.today.flat,
.cal-cell.today.future {
  box-shadow: inset 0 0 0 1.5px #999;
}

.asset {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.asset:first-child { border-top: 0; padding-top: 8px; }

.name { font-weight: 600; }

.usd, .amt {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.meta {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.empty, .end {
  color: var(--muted);
  font-size: 13px;
}

.end { text-align: center; margin: 12px 0 0; }

.amt.up { color: var(--up); }
.amt.down { color: var(--down); }
.amt.flat { color: var(--muted); }

/* —— 我的 —— */
.me-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.me-avatar {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  flex-shrink: 0;
}

.me-profile-text {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.me-profile-text strong {
  font-size: 17px;
  font-weight: 600;
}

.me-profile-text span {
  color: var(--muted);
  font-size: 13px;
}

.list-group {
  margin: 12px 12px 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.list-cell {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  text-align: left;
}

.list-cell:active { background: #f7f7f7; }

.list-cell + .list-cell {
  border-top: 1px solid var(--line);
}

.list-arrow {
  color: #c0c0c0;
  font-size: 20px;
  line-height: 1;
}

.sub-panel {
  min-height: calc(100vh - var(--tab-h) - var(--safe-bottom));
  background: var(--bg);
}

.sub-nav {
  position: sticky;
  top: 0;
}

.pad-x {
  padding-left: 16px;
  padding-right: 16px;
}

.pad-form {
  margin: 16px 12px 0;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.pad-form label { margin-bottom: 14px; }

.withdraw-list {
  padding: 12px 12px 0;
  display: grid;
  gap: 10px;
}

.withdraw-card {
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.withdraw-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.withdraw-card-top strong {
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.withdraw-method {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 4px;
  background: #f0f4f2;
  color: var(--primary);
  font-size: 12px;
}

.withdraw-time {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.withdraw-voucher-btn {
  margin-top: 12px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
}

.withdraw-voucher-btn:active { background: #f7f7f7; }

.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.82);
}

.img-lightbox[hidden] { display: none !important; }

.img-lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 80px);
  object-fit: contain;
  border-radius: 8px;
}

.img-lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

.danger-btn {
  display: block;
  width: calc(100% - 24px);
  height: 48px;
  margin: 16px 12px 0;
  border: 0;
  border-radius: 10px;
  background: #fff;
  color: var(--red);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--line);
}

.danger-btn:active { background: #fff5f5; }

.text-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  padding: 0;
}

.stack-form { margin-top: 8px; }

.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.info-row:first-of-type { border-top: 0; padding-top: 4px; }
.info-row span { color: var(--muted); }
.info-row strong { font-weight: 600; text-align: right; }

/* —— 行情 —— */
.market-card { padding-top: 10px; margin-top: 8px; }

.market-cols {
  display: grid;
  grid-template-columns: 36px minmax(0, 1.4fr) minmax(72px, 0.8fr) 78px;
  gap: 8px;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
  align-items: center;
}

.market-cols-spacer { min-height: 1px; }

.market-sort {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 0;
  margin: 0;
  text-align: left;
  line-height: 1.2;
}

.market-sort:nth-child(3),
.market-sort:nth-child(4) { text-align: right; }

.market-sort.active { color: var(--ink); font-weight: 600; }

.ticker {
  display: grid;
  grid-template-columns: 36px minmax(0, 1.4fr) minmax(72px, 0.8fr) 78px;
  gap: 8px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.ticker:active { opacity: 0.75; }
.ticker:first-child { border-top: 0; }

.ticker-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: #eef2f0;
}

.ticker-icon.fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  background: var(--primary);
}

.ticker-main { min-width: 0; }

.ticker-symbol-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.ticker-symbol {
  font-weight: 650;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticker-badge {
  flex-shrink: 0;
  padding: 1px 5px;
  border-radius: 3px;
  background: #f0f0f0;
  color: #888;
  font-size: 10px;
  line-height: 1.4;
}

.ticker-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticker-price { text-align: right; font-variant-numeric: tabular-nums; }

.ticker-last {
  font-weight: 650;
  font-size: 15px;
}

.ticker-usd {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.ticker-chg {
  justify-self: end;
  min-width: 72px;
  height: 28px;
  padding: 0 6px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.ticker-chg.up {
  background: #eaf7f0;
  color: var(--up);
}

.ticker-chg.down {
  background: #fdecec;
  color: var(--down);
}

.ticker-chg.flat {
  background: #f2f2f2;
  color: var(--muted);
}

.chart-card { padding-bottom: 12px; }

.chart-head {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.chart-last {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.chart-chg {
  margin: 6px 0 0;
  font-size: 14px;
  font-weight: 600;
}

.chart-chg.up, .chart-last.up { color: var(--up); }
.chart-chg.down, .chart-last.down { color: var(--down); }
.chart-chg.flat, .chart-last.flat { color: var(--muted); }

.chart-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  font-size: 12px;
}

.chart-stats span {
  display: block;
  color: var(--muted);
}

.chart-stats strong {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.bar-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.bar-tabs button {
  flex: 1;
  height: 36px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.bar-tabs button.active {
  background: transparent;
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.ma-line {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#kline-canvas {
  width: 100%;
  height: auto;
  display: block;
  background: #fafafa;
  border-radius: 6px;
}

/* —— 底栏 —— */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(480px, 100%);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding: 6px 0 var(--safe-bottom);
  background: #fff;
  border-top: 1px solid var(--line);
  z-index: 20;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: transparent;
  color: #999;
  font-size: 11px;
  padding: 0;
}

.tab-ico {
  width: 22px;
  height: 22px;
  display: block;
}

.tab.active {
  color: var(--primary);
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + var(--safe-bottom));
  max-width: min(400px, calc(100% - 32px));
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 520px) {
  body:not(.is-login) {
    background: #e8eaed;
  }
  body:not(.is-login) .wrap {
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
  }
}

@media (max-width: 380px) {
  .asset-value { font-size: 30px; }
  .banner-stat strong { font-size: 14px; }
  .banner-stat span { font-size: 11px; }
}
