:root {
  color-scheme: light;
  --bg: var(--tg-theme-secondary-bg-color, #f5f6fa);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #18201c);
  --muted: var(--tg-theme-hint-color, #7b837f);
  --line: rgba(19, 31, 25, .09);
  --purple: #7357f4;
  --purple-2: #9b86ff;
  --green: #13986a;
  --red: #d85058;
  --shadow: 0 10px 30px rgba(32, 26, 80, .07);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 300px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus:not(:focus-visible) { outline: none; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
.hidden { display: none !important; }
.app-shell { max-width: 720px; min-height: 100dvh; margin: auto; padding: 0 16px calc(94px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(16px + env(safe-area-inset-top)) 2px 12px; }
.eyebrow, .panel-kicker { margin: 0 0 2px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 24px; letter-spacing: -.02em; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: -.01em; }
.icon-button { width: 42px; height: 42px; border: 0; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.icon-button svg, .filter-button svg, .bottom-nav svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button.loading svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice { margin: 0 0 12px; padding: 11px 13px; border-radius: 12px; background: #fff3dc; color: #895d0d; font-size: 13px; }
.notice.error { background: #ffe7e8; color: #9d3138; }
.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; overflow: hidden; }
.filter-button, .range-chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 11px; }
.filter-button { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.filter-button svg { width: 17px; }
.filter-count { display: grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--purple); color: white; font-size: 10px; }
.quick-ranges { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; }
.quick-ranges::-webkit-scrollbar { display: none; }
.range-chip { color: var(--muted); white-space: nowrap; }
.range-chip.active { border-color: rgba(115,87,244,.25); background: rgba(115,87,244,.11); color: var(--purple); font-weight: 700; }
.view { display: none; }
.view.active { display: block; }
.hero-card { position: relative; overflow: hidden; padding: 22px; border-radius: 22px; color: white; background: linear-gradient(135deg, var(--purple), var(--purple-2)); box-shadow: 0 16px 34px rgba(115,87,244,.24); }
.hero-card > *:not(.hero-orb) { position: relative; z-index: 1; }
.hero-orb { position: absolute; border-radius: 999px; background: rgba(255,255,255,.10); }
.orb-one { width: 170px; height: 170px; right: -55px; top: -70px; }
.orb-two { width: 80px; height: 80px; right: 75px; top: 30px; }
.hero-label { margin-bottom: 4px; color: rgba(255,255,255,.75); font-size: 13px; }
.hero-value { min-height: 44px; font-size: 32px; font-weight: 800; letter-spacing: -.035em; }
.currency-pills { display: flex; flex-wrap: wrap; gap: 5px; min-height: 22px; margin-top: 3px; }
.currency-pills span { padding: 3px 7px; border-radius: 8px; background: rgba(255,255,255,.14); color: rgba(255,255,255,.9); font-size: 10px; }
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 22px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.18); }
.hero-grid span { display: block; margin-bottom: 3px; color: rgba(255,255,255,.7); font-size: 12px; }
.hero-grid strong { font-size: 17px; }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.metric-card, .panel { border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.metric-card { padding: 15px; border-radius: 16px; }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card strong { display: block; margin: 3px 0 2px; font-size: 21px; letter-spacing: -.02em; overflow-wrap: anywhere; }
.metric-card small { font-size: 11px; }
.panel { margin-bottom: 12px; padding: 17px; border-radius: 18px; }
.panel-head, .section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.subtle, .result-count { color: var(--muted); font-size: 12px; }
.chart-wrap { position: relative; height: 165px; margin: 12px -2px -4px; }
#equityChart { width: 100%; height: 100%; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-area { fill: rgba(115,87,244,.10); }
.chart-line { fill: none; stroke: var(--purple); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.chart-zero { stroke: rgba(123,131,127,.4); stroke-dasharray: 4 4; }
.empty-state { display: grid; place-items: center; min-height: 120px; color: var(--muted); text-align: center; }
.dimensions-head { align-items: flex-end; margin-bottom: 8px; }
.segmented { display: flex; padding: 3px; border-radius: 11px; background: var(--bg); }
.segmented button { border: 0; border-radius: 8px; padding: 6px 10px; background: transparent; color: var(--muted); font-size: 12px; }
.segmented button.active { background: var(--surface); color: var(--purple); box-shadow: 0 2px 8px rgba(20,20,40,.08); font-weight: 700; }
.dimension-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.dimension-row:last-child { border-bottom: 0; padding-bottom: 2px; }
.dimension-name { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.dimension-value { font-weight: 800; }
.dimension-meta { color: var(--muted); font-size: 11px; }
.bar-track { height: 4px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: var(--purple); }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }
.section-title-row { padding: 6px 2px 12px; }
.result-count { padding: 5px 9px; border-radius: 9px; background: var(--surface); }
.trade-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sort-control { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.sort-control select { max-width: 134px; border: 1px solid var(--line); border-radius: 10px; padding: 7px 25px 7px 8px; background: var(--surface); }
.trade-list { display: grid; gap: 9px; }
.trade-card { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 5px 10px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.side-badge { grid-row: span 2; align-self: center; min-width: 38px; padding: 7px 5px; border-radius: 10px; text-align: center; font-size: 11px; font-weight: 800; }
.side-badge.buy { background: rgba(19,152,106,.11); color: var(--green); }
.side-badge.sell { background: rgba(216,80,88,.11); color: var(--red); }
.trade-symbol { min-width: 0; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trade-amount { text-align: right; font-weight: 800; }
.trade-meta, .trade-fee { color: var(--muted); font-size: 11px; }
.trade-fee { text-align: right; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 16px 0 4px; }
.pagination button { min-width: 38px; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--surface); }
.pagination button.active { border-color: var(--purple); background: var(--purple); color: white; }
.pagination button:disabled { opacity: .4; cursor: default; }
.bottom-nav { position: fixed; z-index: 20; left: 50%; bottom: 0; display: grid; grid-template-columns: 1fr 1fr; width: min(720px, 100%); padding: 7px 18px calc(7px + env(safe-area-inset-bottom)); transform: translateX(-50%); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 93%, transparent); backdrop-filter: blur(16px); }
.bottom-nav button { display: grid; justify-items: center; gap: 2px; border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.bottom-nav button.active { color: var(--purple); font-weight: 700; }
.bottom-nav svg { width: 22px; height: 22px; }
.filter-dialog { width: min(720px, 100%); max-height: 88dvh; margin: auto auto 0; padding: 0; border: 0; border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text); }
.filter-dialog::backdrop { background: rgba(10,15,12,.42); backdrop-filter: blur(2px); }
.filter-sheet { padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet-handle { width: 38px; height: 4px; margin: 0 auto 12px; border-radius: 4px; background: var(--line); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 20px; }
.text-button { border: 0; background: transparent; color: var(--purple); }
.filter-sheet > label, .date-grid label { display: grid; gap: 6px; margin: 11px 0; color: var(--muted); font-size: 12px; font-weight: 700; }
.filter-sheet select, .filter-sheet input { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px; background: var(--bg); color: var(--text); }
.date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 17px; }
.sheet-actions button { border-radius: 13px; padding: 12px; font-weight: 800; }
.secondary-button { border: 1px solid var(--line); background: var(--bg); }
.primary-button { border: 1px solid var(--purple); background: var(--purple); color: white; }

@media (min-width: 600px) {
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
  .hero-card { padding: 26px; }
}

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --bg: var(--tg-theme-secondary-bg-color, #101712); --surface: var(--tg-theme-bg-color, #17221b); --text: var(--tg-theme-text-color, #edf4ef); --muted: var(--tg-theme-hint-color, #91a097); --line: rgba(235,245,239,.1); --shadow: none; }
}

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