:root {
  color-scheme: dark;
  --bg: #0a0b0d;
  --surface: #111316;
  --surface-2: #17191d;
  --line: #282b31;
  --line-soft: #1d2025;
  --text: #f4f5f7;
  --muted: #8e949e;
  --green: #30d892;
  --red: #ff6575;
  --cyan: #55c7f3;
  --amber: #f4b860;
  --blue: #3984ff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  min-width: 280px;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

.app-shell {
  width: min(100%, 680px);
  min-height: 100dvh;
  margin: 0 auto;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 28px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  padding: max(12px, env(safe-area-inset-top)) 18px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(10, 11, 13, .94);
  backdrop-filter: blur(18px);
}

.brand-lockup { display: flex; align-items: center; gap: 11px; }
.brand-lockup h1 { margin: 0; font-size: 18px; line-height: 1; font-weight: 850; }
.environment { margin-top: 6px; color: var(--muted); font-size: 10px; font-weight: 700; }
.live-dot { display: inline-block; width: 6px; height: 6px; margin-right: 4px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(48,216,146,.1); }
.live-dot.offline { background: var(--red); box-shadow: 0 0 0 4px rgba(255,101,117,.1); }

.brand-mark, .loading-mark {
  display: flex;
  align-items: end;
  gap: 3px;
  width: 32px;
  height: 32px;
  padding: 7px;
  border: 1px solid #3a3e45;
  border-radius: 7px;
  background: #15171a;
}
.brand-mark span, .loading-mark span { width: 4px; border-radius: 1px; background: var(--cyan); }
.brand-mark span:nth-child(1), .loading-mark span:nth-child(1) { height: 8px; }
.brand-mark span:nth-child(2), .loading-mark span:nth-child(2) { height: 16px; background: var(--green); }
.brand-mark span:nth-child(3), .loading-mark span:nth-child(3) { height: 12px; background: var(--amber); }

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}
.icon-button svg { width: 17px; height: 17px; }
.icon-button.loading svg { animation: spin .8s linear infinite; }

main { padding: 14px 14px calc(88px + var(--safe-bottom)); }
.view { display: none; min-height: calc(100dvh - 176px); }
.view.active { display: block; animation: enter .2s ease-out; }

.balance-panel {
  padding: 18px 16px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.panel-kicker, .eyebrow { color: var(--muted); font-size: 10px; font-weight: 800; }
.balance-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.balance-line strong { min-width: 0; font-size: 32px; line-height: 1; font-variant-numeric: tabular-nums; }
.pnl-badge { flex: none; padding: 6px 8px; border-radius: 5px; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pnl-badge.positive { color: var(--green); background: rgba(48,216,146,.1); }
.pnl-badge.negative { color: var(--red); background: rgba(255,101,117,.1); }
.pnl-badge.neutral { color: var(--muted); background: #1d2024; }
.balance-meta { display: flex; gap: 20px; margin-top: 14px; color: var(--muted); font-size: 11px; }
.balance-meta b { margin-left: 4px; color: #c9cdd4; font-weight: 650; }
.chart-wrap { position: relative; height: 126px; margin: 13px -16px 0; border-top: 1px solid var(--line-soft); }
#equityChart { width: 100%; height: 100%; display: block; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #565c66; font-size: 10px; font-weight: 800; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 10px 0 22px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.metric-block { min-width: 0; padding: 13px 12px; border-right: 1px solid var(--line); }
.metric-block:last-child { border-right: 0; }
.metric-block span { display: block; color: var(--muted); font-size: 9px; font-weight: 800; }
.metric-block strong { display: block; overflow: hidden; margin-top: 7px; font-size: 16px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin: 0 2px 10px; }
.section-heading h2 { margin: 0; font-size: 18px; line-height: 1.1; }
.section-heading > span { color: var(--muted); font-size: 11px; }
.section-heading .eyebrow { display: block; margin-bottom: 6px; }
.sticky-heading { min-height: 45px; align-items: center; }

.mode-list { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.mode-row { display: grid; grid-template-columns: 35px 1fr auto; align-items: center; gap: 11px; min-height: 64px; padding: 11px 13px; border-bottom: 1px solid var(--line-soft); }
.mode-row:last-child { border-bottom: 0; }
.mode-icon { display: grid; place-items: center; width: 34px; height: 34px; color: var(--cyan); border-radius: 7px; background: rgba(85,199,243,.09); }
.mode-icon svg { width: 17px; }
.mode-row:nth-child(2) .mode-icon { color: var(--amber); background: rgba(244,184,96,.09); }
.mode-row:nth-child(3) .mode-icon { color: var(--blue); background: rgba(57,132,255,.09); }
.mode-row:nth-child(4) .mode-icon { color: var(--red); background: rgba(255,101,117,.09); }
.mode-row:nth-child(5) .mode-icon { color: var(--green); background: rgba(48,216,146,.09); }
.mode-copy strong { display: block; font-size: 13px; }
.mode-copy { min-width: 0; }
.mode-copy span { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; line-height: 1.3; overflow-wrap: anywhere; }
.state-pill { padding: 5px 7px; color: var(--green); border: 1px solid rgba(48,216,146,.25); border-radius: 5px; font-size: 9px; font-weight: 850; }
.state-pill.offline { color: var(--red); border-color: rgba(255,101,117,.25); }
.state-pill.off { color: var(--muted); border-color: var(--line); }
.state-pill.signals { color: var(--amber); border-color: rgba(244,184,96,.25); }

.stack-list { display: grid; gap: 8px; }
.list-row { padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.row-top, .row-bottom, .position-prices { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.symbol-lockup { display: flex; align-items: center; gap: 9px; min-width: 0; }
.symbol-lockup > div:last-child { min-width: 0; }
.coin-mark { display: grid; place-items: center; flex: none; width: 30px; height: 30px; color: #090a0b; border-radius: 50%; background: var(--amber); font-size: 10px; font-weight: 900; }
.symbol-lockup strong { display: block; font-size: 13px; }
.symbol-lockup span { display: -webkit-box; max-width: min(54vw, 360px); overflow: hidden; margin-top: 3px; color: var(--muted); font-size: 9px; line-height: 1.35; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.direction { font-size: 10px; font-weight: 850; }
.direction.long, .positive-text { color: var(--green) !important; }
.direction.short, .negative-text { color: var(--red) !important; }
.row-pnl { text-align: right; font-size: 14px; font-weight: 850; font-variant-numeric: tabular-nums; }
.row-pnl small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; font-weight: 600; }
.position-prices { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 10px; }
.position-prices b { color: #cdd0d5; font-weight: 650; }
.row-bottom { margin-top: 9px; color: var(--muted); font-size: 10px; }
.setup-label { overflow: hidden; max-width: 70%; white-space: nowrap; text-overflow: ellipsis; }
.empty-state { display: grid; place-items: center; min-height: 230px; color: var(--muted); text-align: center; }
.empty-state svg { width: 30px; height: 30px; margin-bottom: 10px; color: #50555e; }
.empty-state strong { display: block; color: #c8ccd2; font-size: 13px; }
.empty-state span { display: block; margin-top: 5px; font-size: 10px; }

.segmented { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: #0e1012; }
.segment { height: 26px; padding: 0 10px; color: var(--muted); border: 0; border-radius: 5px; background: transparent; font-size: 9px; font-weight: 850; }
.segment.active { color: var(--text); background: #25282e; }
.forward-strip { display: flex; gap: 6px; margin-bottom: 9px; overflow-x: auto; scrollbar-width: none; }
.forward-chip { flex: none; padding: 7px 9px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-size: 9px; }
.forward-chip b { margin-left: 4px; color: var(--text); }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(100%, 680px);
  height: calc(66px + var(--safe-bottom));
  padding: 7px 8px var(--safe-bottom);
  transform: translateX(-50%);
  border-top: 1px solid var(--line);
  background: rgba(14, 16, 18, .97);
  backdrop-filter: blur(18px);
}
.nav-item { position: relative; display: grid; place-items: center; align-content: center; gap: 4px; min-width: 0; color: #737984; border: 0; background: transparent; font-size: 9px; font-weight: 700; }
.nav-item svg { width: 18px; height: 18px; }
.nav-item.active { color: var(--blue); }
.nav-count { position: absolute; top: 2px; left: calc(50% + 7px); min-width: 14px; height: 14px; padding: 0 3px; color: white; border: 2px solid #0e1012; border-radius: 8px; background: var(--red); font-size: 8px; line-height: 10px; }
.nav-count:empty, .nav-count[data-count="0"] { display: none; }

.loading-screen { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; align-content: center; gap: 13px; background: var(--bg); transition: opacity .25s ease, visibility .25s ease; }
.loading-screen.hidden { opacity: 0; visibility: hidden; }
.loading-screen strong { font-size: 14px; }
.loading-mark { width: 40px; height: 40px; animation: pulse 1s ease-in-out infinite; }
.toast { position: fixed; left: 50%; bottom: calc(78px + var(--safe-bottom)); z-index: 60; max-width: calc(100% - 32px); padding: 10px 12px; color: var(--text); border: 1px solid var(--line); border-radius: 7px; background: #1a1d21; font-size: 11px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { transform: translateY(-3px); opacity: .72; } }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }

@media (min-width: 540px) {
  main { padding-inline: 20px; }
  .metric-block { padding-inline: 16px; }
}

@media (max-width: 330px) {
  .balance-line strong { font-size: 27px; }
  .balance-meta { gap: 10px; }
  .metric-block { padding-inline: 8px; }
  .metric-block strong { font-size: 14px; }
  .nav-item span { font-size: 8px; }
}

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