:root {
  color-scheme: dark;
  --bg: #0e1624;
  --bg-deep: #080e18;
  --card: #172234;
  --card-2: #1d2b40;
  --line: #31435a;
  --ink: #e9f0fa;
  --muted: #8fa1b9;
  --green: #46ddb5;
  --green-deep: #122b2b;
  --red: #ff8f99;
  --red-deep: #2c1d28;
  --amber: #f1c97a;
  --shadow: rgba(0, 0, 0, .36);
  --radius: 20px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--bg-deep); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 2%, rgba(70, 221, 181, .10), transparent 27rem),
    radial-gradient(circle at 100% 18%, rgba(255, 143, 153, .08), transparent 24rem),
    linear-gradient(155deg, #0e1624 0%, #0b1320 55%, #080e18 100%);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}
.ambient {
  position: fixed;
  border-radius: 999px;
  filter: blur(80px);
  opacity: .15;
  pointer-events: none;
}
.ambient-a { width: 15rem; height: 15rem; background: var(--green); top: -8rem; left: -6rem; }
.ambient-b { width: 13rem; height: 13rem; background: var(--red); right: -7rem; top: 28rem; }

.app {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  position: relative;
}
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 18px;
}
.topbar h1, h2, p { margin: 0; }
.topbar h1 { font-size: clamp(1.55rem, 7vw, 2.15rem); letter-spacing: -.04em; margin-top: 3px; }
.eyebrow {
  color: var(--green);
  font-size: .68rem;
  font-weight: 750;
  letter-spacing: .19em;
}
.top-actions { display: flex; align-items: center; gap: 8px; padding-top: 4px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(23, 34, 52, .78);
  font-size: .72rem;
  white-space: nowrap;
}
.badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 4px rgba(241,201,122,.1); }
.badge.online { color: var(--green); border-color: rgba(70,221,181,.38); }
.badge.online i { background: var(--green); box-shadow: 0 0 0 4px rgba(70,221,181,.12); }
.badge.offline { color: var(--red); border-color: rgba(255,143,153,.32); }
.badge.offline i { background: var(--red); box-shadow: 0 0 0 4px rgba(255,143,153,.1); }
.icon-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
}

.account-strip, .quote-card, .card, .position-card {
  border: 1px solid rgba(72, 95, 122, .52);
  background: linear-gradient(150deg, rgba(23, 34, 52, .96), rgba(18, 28, 43, .96));
  box-shadow: 0 16px 45px var(--shadow);
}
.account-strip {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 15px;
  border-radius: 15px;
  margin-bottom: 12px;
}
.account-main { display: flex; flex-direction: column; min-width: 0; }
.account-main strong { font-size: .9rem; margin-top: 2px; }
.align-right { text-align: right; }
.label {
  color: var(--muted);
  font-size: .64rem;
  font-weight: 650;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.small { font-size: .72rem; margin-top: 3px; }
.muted { color: var(--muted); }

.quote-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  position: relative;
}
.quote-card::after {
  content: "";
  position: absolute;
  width: 6rem;
  height: 6rem;
  border: 1px solid rgba(70,221,181,.16);
  border-radius: 50%;
  right: 28%;
  top: -4rem;
}
.symbol { display: block; font-size: 1.34rem; letter-spacing: -.02em; margin-top: 2px; }
.quote-values { display: flex; gap: 18px; }
.quote-values div { text-align: right; }
.quote-values strong { display: block; margin-top: 3px; font-variant-numeric: tabular-nums; }

.card { border-radius: var(--radius); padding: 18px; margin-bottom: 12px; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-head h2 { font-size: 1.14rem; margin-top: 3px; letter-spacing: -.02em; }
.section-head.compact { margin-bottom: 12px; }
.side-caption { color: var(--green); font-size: .74rem; padding-top: 4px; }

.target-bar {
  padding: 10px 12px;
  margin-bottom: 16px;
  border: 0;
  border-left: 3px solid var(--green);
  border-radius: 4px 10px 10px 4px;
  background: linear-gradient(90deg, rgba(70,221,181,.12), rgba(70,221,181,.025));
  color: var(--green);
  font-size: .74rem;
  font-weight: 650;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.wide-field { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field span { color: var(--muted); font-size: .73rem; }
.field em { font-style: normal; color: #71849d; }
input {
  width: 100%;
  min-height: 45px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #101b2a;
  color: var(--ink);
  padding: 0 12px;
  font-variant-numeric: tabular-nums;
}
input::placeholder { color: #60738c; }
input:focus { border-color: var(--green); background: #122033; }

.level-rail {
  margin-top: 17px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.rail-head {
  display: flex;
  justify-content: space-between;
  padding: 9px 12px;
  color: var(--muted);
  background: rgba(8, 14, 24, .45);
  font-size: .66rem;
  letter-spacing: .04em;
}
.level-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 66px 14px;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid rgba(49, 67, 90, .58);
}
.level-row b { font-size: .73rem; color: var(--muted); }
.level-row input { min-height: 37px; border-radius: 8px; padding: 0 9px; }
.level-row .pct { text-align: right; }
.level-row > span { color: var(--muted); font-size: .7rem; }
.all-remaining {
  grid-column: 3 / 5;
  text-align: right;
  color: var(--green) !important;
}
.rr-meter {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  margin-top: 12px;
  border-radius: 11px;
  background: rgba(70, 221, 181, .06);
  border: 1px solid rgba(70, 221, 181, .18);
  color: var(--green);
  font-size: .76rem;
}
.rr-meter.low { color: var(--amber); background: rgba(241,201,122,.07); border-color: rgba(241,201,122,.24); }
.rr-meter.neutral { color: var(--muted); background: rgba(143,161,185,.04); border-color: var(--line); }
.flow-copy { color: var(--muted); font-size: .68rem; line-height: 1.55; margin-top: 9px; }
.form-error { min-height: 1.2em; margin-top: 7px; color: var(--red); font-size: .72rem; line-height: 1.45; }

.button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 16px;
  color: var(--ink);
  background: #1b2a40;
  font-weight: 760;
  transition: transform .12s ease, filter .12s ease;
}
.button:active { transform: translateY(1px); filter: brightness(.92); }
.button.pressed, .text-button.pressed, .icon-button.pressed { transform: scale(.97); filter: brightness(.9); }
.button.is-busy { position: relative; color: transparent !important; }
.button.is-busy::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: calc(50% - 8px);
  top: calc(50% - 8px);
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: button-spin .7s linear infinite;
}
.button:disabled { opacity: .38; cursor: not-allowed; }
.button.primary { background: var(--green); color: #071611; border-color: transparent; }
.button.buy { background: var(--green); color: #071611; border-color: transparent; }
.button.sell { background: var(--red); color: #261014; border-color: transparent; }
.button.apply { background: #273951; border-color: #3a526e; }
.button.ghost { color: var(--muted); background: transparent; }
.button.danger { color: var(--red); }
.button.wide { width: 100%; }
.action-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 8px; }
#apply { margin-top: 9px; }

.position-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 12px; }
.position-card { border-radius: var(--radius); padding: 16px; min-width: 0; }
.buy-card { background: linear-gradient(145deg, rgba(18,43,43,.98), rgba(18,31,45,.98)); }
.sell-card { background: linear-gradient(145deg, rgba(44,29,40,.98), rgba(29,26,39,.98)); }
.position-card.selected { border-color: rgba(70,221,181,.68); box-shadow: 0 0 0 1px rgba(70,221,181,.14), 0 16px 45px var(--shadow); }
.sell-card.selected { border-color: rgba(255,143,153,.62); }
.position-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.position-head h2 { font-size: 1rem; margin-top: 2px; }
.pill {
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(8,14,24,.46);
  color: var(--muted);
  font-size: .66rem;
}
.pill.live { color: var(--green); }
.pill.pending { color: var(--amber); }
.position-title { display: block; font-size: 1.13rem; margin-top: 15px; }
.position-card p { color: var(--muted); font-size: .7rem; line-height: 1.55; margin-top: 6px; min-height: 2.2em; }
.stage-row { display: flex; gap: 6px; margin-top: 13px; }
.stage {
  flex: 1;
  text-align: center;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: .66rem;
}
.stage.done { color: #071611; background: var(--green); border-color: transparent; }
.sell-card .stage.done { background: var(--red); color: #261014; }
.mini-actions { display: flex; gap: 6px; margin-top: 12px; }
.text-button {
  flex: 1;
  min-height: 34px;
  border: 1px solid rgba(72,95,122,.72);
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font-size: .72rem;
}
.text-button.danger { color: var(--red); }

.status-card p { color: var(--muted); line-height: 1.55; font-size: .8rem; min-height: 2.5em; }
.ea-error {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 143, 153, .4);
  border-radius: 10px;
  background: rgba(255, 143, 153, .08);
  color: var(--red);
  font-size: .76rem;
  line-height: 1.5;
}
.action-footer { display: flex; gap: 8px; margin-top: 14px; }
.action-footer .button { flex: 1; }
.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 3px 0;
  color: #687c95;
  font-size: .67rem;
}
.footer b { color: var(--muted); font-weight: 600; letter-spacing: .06em; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}
.login-card {
  width: min(100%, 430px);
  padding: clamp(24px, 7vw, 38px);
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(150deg, rgba(23,34,52,.98), rgba(13,22,35,.98));
  box-shadow: 0 30px 100px rgba(0,0,0,.5);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--green), #72c6d9 50%, var(--red));
}
.brandmark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: var(--green);
  color: #071611;
  font-weight: 900;
  font-size: 1.4rem;
  margin-bottom: 22px;
  box-shadow: 0 10px 35px rgba(70,221,181,.18);
}
.login-card h1 { font-size: clamp(1.8rem, 8vw, 2.4rem); letter-spacing: -.05em; margin-top: 7px; }
.login-copy { color: var(--muted); line-height: 1.7; font-size: .84rem; margin: 13px 0 20px; }
.login-card form { display: grid; gap: 10px; }
.login-card label { color: var(--muted); font-size: .74rem; }
.login-card input { min-height: 50px; letter-spacing: .12em; font-weight: 700; }
.security-note {
  display: flex;
  gap: 9px;
  margin-top: 18px;
  padding: 11px 12px;
  border-radius: 11px;
  background: rgba(8,14,24,.42);
  color: #71849d;
  font-size: .7rem;
  line-height: 1.55;
}
.shield { color: var(--green); }
.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .75rem;
  cursor: pointer;
}
.remember-row input {
  width: 16px;
  min-height: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--green);
}
.forget-button {
  justify-self: center;
  border: 0;
  padding: 4px 8px;
  background: transparent;
  color: #71849d;
  font-size: .68rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.order-book { padding: 16px; }
.order-list { display: grid; gap: 10px; }
.order-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
  background: rgba(8, 14, 24, .36);
}
.order-item.buy { border-left: 3px solid var(--green); }
.order-item.sell { border-left: 3px solid var(--red); }
.order-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.order-identity { display: flex; align-items: center; gap: 8px; min-width: 0; }
.order-side {
  padding: 4px 7px;
  border-radius: 6px;
  font-size: .64rem;
  font-weight: 800;
  background: rgba(70,221,181,.13);
  color: var(--green);
}
.order-side.sell { background: rgba(255,143,153,.12); color: var(--red); }
.order-ticket { color: var(--muted); font-size: .67rem; font-variant-numeric: tabular-nums; }
.order-profit { font-weight: 760; font-variant-numeric: tabular-nums; white-space: nowrap; }
.order-profit.positive { color: var(--green); }
.order-profit.negative { color: var(--red); }
.order-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px 10px;
  margin-top: 12px;
}
.order-metric span { display: block; color: var(--muted); font-size: .61rem; }
.order-metric strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}
.order-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(49,67,90,.55);
  color: #71849d;
  font-size: .63rem;
}
.order-subtitle { margin: 15px 0 8px; color: var(--muted); font-size: .72rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translate(-50%, 25px);
  width: min(calc(100% - 32px), 520px);
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(15,25,39,.96);
  color: var(--ink);
  box-shadow: 0 14px 50px rgba(0,0,0,.44);
  font-size: .78rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { color: var(--red); border-color: rgba(255,143,153,.34); }
.toast.success { color: var(--green); border-color: rgba(70,221,181,.34); }

@keyframes button-spin { to { transform: rotate(360deg); } }

@media (min-width: 640px) {
  .position-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1.25fr 1fr 1fr; }
  .wide-field { grid-column: auto; }
}
@media (max-width: 390px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .quote-values { gap: 11px; }
  .quote-values strong { font-size: .9rem; }
  .top-actions .icon-button { padding: 0 8px; }
  .card { padding: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
