:root {
  color-scheme: dark;
  --bg: #090d10;
  --surface: #11171d;
  --surface-2: #172028;
  --surface-3: #0d1318;
  --line: #25313b;
  --line-strong: #394956;
  --text: #f6f8fa;
  --muted: #8f9da8;
  --soft: #c9d2d9;
  --green: #4ee28a;
  --cyan: #47d5c5;
  --amber: #f2bd55;
  --red: #ff7373;
  --violet: #9d8cff;
  --shadow: rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  background: radial-gradient(circle at 50% 0, rgba(71, 213, 197, 0.12), transparent 34%), var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  width: min(100%, 540px);
  height: 100dvh;
  margin: 0 auto;
  background: linear-gradient(180deg, rgba(18, 26, 32, 0.96), #090d10 42%);
  overflow: hidden;
}

.app-topbar {
  height: 82px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow,
.section-head p,
.wallet-profile span,
small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 23px;
  line-height: 1.05;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.text-button,
.primary-wide,
.wallet-add-card button,
.card-action {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.icon-button {
  padding: 0 10px;
  font-size: 12px;
}

.icon-button.primary,
.primary-wide,
.wallet-add-card button,
.card-action.primary {
  border-color: transparent;
  background: var(--cyan);
  color: #04110f;
  font-weight: 800;
}

.text-button {
  flex: 0 0 auto;
  padding: 0 10px;
  color: var(--cyan);
  background: rgba(71, 213, 197, 0.08);
}

.screen {
  position: absolute;
  inset: 82px 0 calc(72px + env(safe-area-inset-bottom));
  display: none;
  padding: 0 14px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.screen.active {
  display: block;
}

.hero-card,
.section-block,
.wallet-add-card,
.wallet-profile,
.recommend-card,
.wallet-card,
.trade-card,
.position-card,
.event-card,
.empty-state,
.metric-pill {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 23, 29, 0.94);
  box-shadow: 0 18px 44px var(--shadow);
}

.hero-card {
  padding: 16px;
  background:
    linear-gradient(135deg, rgba(71, 213, 197, 0.2), rgba(157, 140, 255, 0.12) 42%, rgba(17, 23, 29, 0.98) 78%),
    var(--surface);
}

.hero-row,
.section-head,
.card-top,
.wallet-line,
.trade-meta,
.event-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hero-row span,
.metric-pill span,
.detail-summary span {
  color: var(--muted);
  font-size: 12px;
}

.hero-row b,
.status-pill,
.side-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(71, 213, 197, 0.11);
  color: var(--cyan);
  font-size: 12px;
}

.hero-card > strong {
  display: block;
  margin-top: 10px;
  font-size: 42px;
  line-height: 0.96;
}

.hero-card > p {
  margin-top: 8px;
  color: var(--soft);
  font-size: 13px;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.hero-metrics div,
.metric-pill {
  min-width: 0;
  padding: 10px;
  background: rgba(9, 13, 16, 0.42);
}

.hero-metrics span,
.hero-metrics small {
  display: block;
  overflow-wrap: anywhere;
}

.hero-metrics strong {
  display: block;
  margin-top: 6px;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.section-block {
  margin-top: 12px;
  padding: 14px;
}

.section-head {
  margin: 14px 0 10px;
}

.section-block .section-head {
  margin-top: 0;
}

.sticky-head {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 -14px 10px;
  padding: 12px 14px;
  background: rgba(9, 13, 16, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(37, 49, 59, 0.72);
}

.recommend-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(252px, 82%);
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-snap-type: x mandatory;
}

.recommend-list,
.wallet-stack,
.trade-stack,
.compact-stack,
.event-stack {
  display: grid;
  gap: 10px;
}

.recommend-card {
  scroll-snap-align: start;
  padding: 13px;
  background: linear-gradient(180deg, rgba(23, 32, 40, 0.98), rgba(13, 19, 24, 0.98));
}

.score-ring {
  min-width: 58px;
  min-height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(78, 226, 138, 0.38);
  border-radius: 50%;
  color: var(--green);
  font-size: 18px;
  font-weight: 850;
  background: rgba(78, 226, 138, 0.08);
}

.recommend-card h3,
.wallet-card h3,
.trade-card h3,
.position-card h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.recommend-card p,
.wallet-card p,
.trade-card p,
.position-card p,
.event-card p {
  margin: 7px 0 0;
  color: var(--soft);
  font-size: 13px;
  line-height: 1.35;
}

.recommend-card .mini-note {
  color: var(--muted);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 11px;
}

.metric-pill strong,
.detail-summary strong {
  display: block;
  margin-top: 5px;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.card-actions,
.wallet-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.card-action {
  padding: 0 10px;
  font-size: 13px;
}

.card-action.danger {
  color: var(--red);
}

.wallet-add-card {
  padding: 13px;
  margin-bottom: 14px;
}

.wallet-add-card label {
  display: block;
  margin-bottom: 9px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 750;
}

.wallet-add-card div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.wallet-add-card input {
  min-width: 0;
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text);
  outline: none;
}

.wallet-add-card input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(71, 213, 197, 0.14);
}

.wallet-add-card button {
  padding: 0 14px;
}

.wallet-card,
.trade-card,
.position-card,
.event-card {
  padding: 13px;
}

.wallet-card.selected,
.trade-card.selected {
  border-color: rgba(71, 213, 197, 0.72);
}

.wallet-line small,
.trade-meta small {
  overflow-wrap: anywhere;
}

.segmented {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(9, 13, 16, 0.92);
  backdrop-filter: blur(12px);
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--surface-2);
  color: var(--text);
}

.wallet-profile {
  padding: 14px;
}

.wallet-profile h2 {
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.wallet-profile p {
  margin: 6px 0 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.primary-wide {
  width: 100%;
}

.primary-wide:disabled,
button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.detail-summary div {
  min-height: 62px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
}

.side-pill.buy {
  color: var(--green);
  background: rgba(78, 226, 138, 0.1);
}

.side-pill.sell {
  color: var(--amber);
  background: rgba(242, 189, 85, 0.11);
}

.side-pill.unknown {
  color: var(--violet);
  background: rgba(157, 140, 255, 0.12);
}

.profit-positive {
  color: var(--green);
}

.profit-negative {
  color: var(--red);
}

.profit-muted {
  color: var(--muted);
}

.trade-card {
  border-left: 3px solid var(--line-strong);
}

.trade-card.buy {
  border-left-color: var(--green);
}

.trade-card.sell {
  border-left-color: var(--amber);
}

.event-tag {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--soft);
  font-size: 12px;
}

.event-tag.dry_run_buy,
.event-tag.live_buy,
.event-tag.dry_run_sell,
.event-tag.live_sell {
  color: var(--green);
}

.event-tag.skip,
.event-tag.blocked,
.event-tag.config_error {
  color: var(--red);
}

.empty-state {
  min-height: 118px;
  display: grid;
  place-items: center;
  padding: 18px;
  text-align: center;
}

.empty-state strong {
  display: block;
}

.empty-state p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.bottom-nav {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(9, 13, 16, 0.95);
  backdrop-filter: blur(16px);
}

.bottom-nav button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.bottom-nav button.active {
  background: var(--surface-2);
  color: var(--cyan);
  font-weight: 800;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  background: rgba(0, 0, 0, 0.52);
}

.sheet-backdrop.show {
  display: block;
}

.trade-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 41;
  width: min(100%, 540px);
  max-height: 72dvh;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #10171d;
  transform: translate(-50%, 110%);
  transition: transform 180ms ease;
  overflow-y: auto;
}

.trade-sheet.show {
  transform: translate(-50%, 0);
}

.sheet-handle {
  width: 42px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: var(--line-strong);
}

.sheet-close {
  float: right;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.sheet-grid {
  clear: both;
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.sheet-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
}

.sheet-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.sheet-grid strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 60;
  width: min(500px, calc(100vw - 28px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #162129;
  color: var(--text);
  box-shadow: 0 18px 44px var(--shadow);
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

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

@media (min-width: 820px) {
  body {
    display: grid;
    place-items: center;
    padding: 24px;
  }

  .app-shell {
    height: min(900px, calc(100dvh - 48px));
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 26px 80px var(--shadow);
  }
}

@media (max-width: 380px) {
  .hero-card > strong {
    font-size: 34px;
  }

  .hero-metrics,
  .metric-row,
  .detail-summary {
    grid-template-columns: 1fr;
  }

  .wallet-add-card div,
  .card-actions,
  .wallet-actions {
    grid-template-columns: 1fr;
  }
}
