:root {
  --bg: #0b0e11;
  --panel: #161a1e;
  --panel2: #1e2329;
  --line: #2b3139;
  --text: #eaecef;
  --muted: #848e9c;
  --green: #0ecb81;
  --red: #f6465d;
  --yellow: #f0b90b;
  --green-bg: rgba(14, 203, 129, 0.12);
  --red-bg: rgba(246, 70, 93, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: var(--text); }
h2 { margin: 16px 0 4px; font-size: 20px; }
h3 { margin: 0 0 12px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.up { color: var(--green); }
.down { color: var(--red); }
.num { font-variant-numeric: tabular-nums; }

#app { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; }
#view-top, #view-me { padding: 0 14px 20px; }

/* ---------- header ---------- */
.top { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 10px 12px 6px; align-items: center; }
.top-left { display: flex; align-items: center; gap: 8px; }
.lang-top { background: var(--panel2); border-radius: 12px; padding: 3px 8px; font-size: 12px; color: var(--text); }
.lang-sheet button { display: block; width: 100%; text-align: left; padding: 12px 6px; border-bottom: 1px solid var(--line); font-size: 15px; }
.lang-sheet button.active { color: var(--yellow); font-weight: 600; }
.symbol-btn { font-size: 17px; font-weight: 700; text-align: left; padding: 0; }
.symbol-btn small { font-size: 10px; color: var(--muted); background: var(--panel2); padding: 1px 4px; border-radius: 3px; vertical-align: middle; }
.top-price { text-align: right; }
.big { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.top-stats { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 11px; font-variant-numeric: tabular-nums; }

.intervals { display: flex; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--line); }
.intervals button { padding: 6px 8px; color: var(--muted); font-size: 12px; }
.intervals button.active { color: var(--text); font-weight: 600; }
.chart { height: 280px; }

/* ---------- book + form ---------- */
.trade-grid { display: grid; grid-template-columns: 44% 56%; border-top: 1px solid var(--line); }
.book { padding: 8px 6px 8px 10px; font-size: 11.5px; font-variant-numeric: tabular-nums; min-width: 0; }
.book-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 10.5px; margin-bottom: 4px; }
.levels > div { position: relative; display: flex; justify-content: space-between; padding: 1.5px 2px; cursor: pointer; }
.levels > div i { position: absolute; right: 0; top: 0; bottom: 0; z-index: 0; }
.levels > div span { position: relative; z-index: 1; }
.asks span:first-child { color: var(--red); }
.bids span:first-child { color: var(--green); }
.asks i { background: var(--red-bg); }
.bids i { background: var(--green-bg); }
.book-mid { font-size: 16px; font-weight: 700; padding: 5px 2px; }
.book-tabs { display: flex; gap: 4px; margin-top: 6px; }
.mini { padding: 3px 8px; border-radius: 4px; color: var(--muted); background: var(--panel); font-size: 11px; }
.mini.active { color: var(--text); background: var(--panel2); }
.tape > div { display: grid; grid-template-columns: 1fr 1fr auto; gap: 4px; padding: 1.5px 0; }
.tape > div span:nth-child(2) { text-align: right; }
.tape > div span:last-child { color: var(--muted); }

.order-form { padding: 8px 10px 10px 6px; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.row { display: flex; }
.gap { gap: 6px; }
.chip { background: var(--panel2); border-radius: 4px; padding: 4px 10px; font-size: 12px; }
.seg { display: flex; background: var(--panel); border-radius: 6px; padding: 2px; }
.seg button { flex: 1; padding: 5px 0; border-radius: 5px; color: var(--muted); font-size: 12px; }
.seg button.active { background: var(--panel2); color: var(--text); font-weight: 600; }
.field { display: flex; align-items: center; background: var(--panel2); border-radius: 6px; padding: 0 8px; height: 36px; border: 1px solid transparent; }
.field:focus-within { border-color: var(--yellow); }
.field span { color: var(--muted); font-size: 11px; white-space: nowrap; margin-right: 6px; }
.field input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; text-align: right; font-variant-numeric: tabular-nums; }
.field.disabled input { color: var(--muted); }
.pcts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.pcts button { background: var(--panel); border-radius: 4px; padding: 4px 0; font-size: 11px; color: var(--muted); }
.pcts button.active { color: var(--text); background: var(--panel2); }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.check input { accent-color: var(--yellow); margin: 0; }
#tpsl { display: flex; flex-direction: column; gap: 6px; }
.info { font-size: 11px; display: flex; flex-direction: column; gap: 2px; }
.info div { display: flex; justify-content: space-between; }
.info span { color: var(--muted); }
.info b { font-weight: 500; font-variant-numeric: tabular-nums; }

.btn { width: 100%; border-radius: 6px; padding: 10px 0; font-weight: 700; font-size: 14px; display: flex; flex-direction: column; align-items: center; }
.btn small { font-weight: 400; font-size: 10.5px; opacity: 0.85; }
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.5; }
.btn.buy { background: var(--green); color: #fff; }
.btn.sell { background: var(--red); color: #fff; }
.btn.ghost { background: var(--panel2); color: var(--red); margin-top: 16px; }

/* ---------- bottom panel ---------- */
.panel { border-top: 6px solid var(--panel); }
.tabs { display: flex; gap: 16px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tabs button { padding: 10px 0; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--yellow); font-weight: 600; }
.ptab { padding: 0 12px; min-height: 120px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

.pos { border-bottom: 1px solid var(--line); padding: 12px 0; }
.pos-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.pos-head b { font-size: 14px; }
.tag { font-size: 10.5px; padding: 1px 5px; border-radius: 3px; font-weight: 600; }
.tag.long { background: var(--green-bg); color: var(--green); }
.tag.short { background: var(--red-bg); color: var(--red); }
.tag.gray { background: var(--panel2); color: var(--muted); }
.pos-pnl { display: flex; justify-content: space-between; margin-bottom: 8px; }
.pos-pnl .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.grid3 > div:nth-child(3n + 2) { text-align: center; }
.grid3 > div:nth-child(3n) { text-align: right; }
.grid3 span { display: block; color: var(--muted); font-size: 10.5px; }
.pos-actions { display: flex; gap: 6px; margin-top: 10px; }
.pos-actions button { flex: 1; background: var(--panel2); border-radius: 4px; padding: 6px 0; font-size: 12px; }

.hist { display: grid; grid-template-columns: 1fr auto; padding: 9px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; gap: 2px; }
.hist .r { text-align: right; }

/* ---------- leaderboard / profile ---------- */
.lb { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.lb.me { background: var(--panel); margin: 0 -14px; padding: 10px 14px; }
.lb .rank { font-weight: 700; color: var(--muted); }
.lb .r { text-align: right; }
.card { background: var(--panel); border-radius: 10px; padding: 14px; margin-top: 12px; }
.huge { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.stats > div { background: var(--panel); border-radius: 8px; padding: 10px; }
.stats span { display: block; color: var(--muted); font-size: 11px; }
.stats b { font-size: 15px; font-variant-numeric: tabular-nums; }
.season-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.season-top b { font-size: 15px; text-transform: capitalize; }
.season-card p { margin: 6px 0 10px; }
.season-me { display: flex; gap: 24px; font-variant-numeric: tabular-nums; }
.season-me span { display: block; }
.season-me b { font-size: 18px; }
.prev-card b { text-transform: capitalize; }
.prev-row { display: flex; justify-content: space-between; padding: 6px 0 0; font-variant-numeric: tabular-nums; }
#leaderboard { margin-top: 8px; }
.langs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.langs button { background: var(--panel2); border-radius: 6px; padding: 6px 10px; font-size: 12px; color: var(--muted); }
.langs button.active { color: var(--bg); background: var(--yellow); font-weight: 600; }
.tips ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.tips li { margin: 4px 0; }

/* ---------- nav, sheets, toasts ---------- */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.bottom-nav button { flex: 1; padding: 7px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); transition: color 0.15s; }
.bottom-nav button span { font-size: 10.5px; }
.bottom-nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.15s; }
.bottom-nav svg .f { fill: transparent; transition: fill 0.15s; }
.bottom-nav button.active { color: var(--yellow); }
.bottom-nav button.active svg { transform: translateY(-1px); }
.bottom-nav button.active svg .f { fill: rgba(240, 185, 11, 0.22); }

/* ---------- portfolio ---------- */
#view-portfolio { padding: 0 14px 20px; }
.pf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 14px; font-variant-numeric: tabular-nums; }
.pf-grid span { display: block; color: var(--muted); font-size: 11px; }
.pf-grid b { font-size: 14px; font-weight: 600; }
.pf-bar-label { display: flex; justify-content: space-between; margin-top: 14px; font-size: 11px; color: var(--muted); }
.pf-bar-label b { color: var(--text); font-weight: 500; }
.pf-bar, .liq-bar { height: 5px; background: var(--panel2); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.pf-bar i, .liq-bar i { display: block; height: 100%; width: 0; background: var(--green); border-radius: 3px; transition: width 0.3s; }
.pf-bar i.warn, .liq-bar i.warn { background: var(--yellow); }
.pf-bar i.danger, .liq-bar i.danger { background: var(--red); }
.liq-bar { margin: 10px 0 6px; }
.pf-section { margin: 20px 0 8px; font-size: 15px; }
#pf-filter { margin-bottom: 4px; }
#pf-filter b { margin-left: 5px; font-weight: 500; font-size: 10.5px; color: var(--muted); }
.link { color: var(--yellow); font-size: 12px; padding: 0; }
.btn.neutral { background: var(--panel2); color: var(--text); margin-top: 16px; }

/* ---------- shop ---------- */
#view-shop { padding: 0 14px 20px; }
.shop-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-variant-numeric: tabular-nums; }
.shop-sum span { display: block; }
.shop-sum b { font-size: 15px; }
.shop-sum > div:last-child { grid-column: 1 / -1; }
.cats { display: flex; gap: 6px; overflow-x: auto; margin: 14px 0 10px; padding-bottom: 2px; }
.cats button { flex: none; background: var(--panel); border-radius: 14px; padding: 6px 12px; font-size: 12px; color: var(--muted); }
.cats button.active { background: var(--yellow); color: var(--bg); font-weight: 600; }
/* With a mouse there is no horizontal swipe, so all category tabs wrap onto several rows. */
@media (hover: hover) and (pointer: fine) { .cats { flex-wrap: wrap; overflow-x: visible; } }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.shop-item { background: var(--panel); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.shop-item.owned { outline: 1px solid rgba(14, 203, 129, 0.5); }
.shop-icon { font-size: 34px; line-height: 1; }
.shop-photo { margin: -12px -12px 0; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 10px 10px 0 0; background: var(--panel2); }
.shop-photo img { width: 100%; height: 100%; object-fit: contain; padding: 6px; box-sizing: border-box; display: block; }
.shop-credit { font-size: 9px; color: var(--muted); line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; text-decoration: none; }
.shop-name { font-weight: 600; min-height: 34px; }
.shop-price { font-variant-numeric: tabular-nums; color: var(--yellow); }
.shop-item .tag { align-self: flex-start; }
.shop-item.limited { background: linear-gradient(160deg, rgba(240, 185, 11, 0.12), var(--panel) 55%); }
.tag.rare { background: rgba(240, 185, 11, 0.15); color: var(--yellow); }
.shop-item .btn { padding: 7px 0; font-size: 12.5px; margin-top: auto; }
.btn.ghost-sm { background: var(--panel2); color: var(--text); padding: 7px 0; font-size: 12px; margin-top: auto; }

/* ---------- level & tasks ---------- */
.level-card .pf-bar i { background: var(--yellow); }
.quest { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.quest-mark { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 12px; }
.quest.done .quest-mark { background: var(--green); border-color: var(--green); color: #fff; }
.quest.done b { color: var(--muted); }
.quest-xp { color: var(--yellow); font-size: 12px; font-variant-numeric: tabular-nums; }
.check.notify { margin-top: 8px; color: var(--text); }
.lvl { font-size: 10px; color: var(--yellow); background: rgba(240, 185, 11, 0.12); border-radius: 3px; padding: 0 4px; margin-left: 4px; }

/* ---------- tour ---------- */
.tour { position: fixed; inset: 0; z-index: 40; }
.tour-hole { position: fixed; border-radius: 8px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.72); border: 2px solid var(--yellow); transition: all 0.25s ease; pointer-events: none; }
.tour-card { position: fixed; left: 12px; right: 12px; background: var(--panel2); border-radius: 12px; padding: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6); max-width: 480px; margin: 0 auto; }
.tour-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tour-top b { font-size: 15px; }
.tour-card p { margin: 8px 0 12px; color: #c7ccd3; line-height: 1.45; }
.tour-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.tour-actions .btn { width: auto; padding: 9px 18px; }

.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 20; display: flex; align-items: flex-end; }
.sheet-body { background: var(--panel); width: 100%; border-radius: 14px 14px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; max-height: 80vh; overflow: auto; }
.sym-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); text-align: left; width: 100%; font-variant-numeric: tabular-nums; }
.sym-row b { font-size: 14px; }
.sym-row .chg { min-width: 64px; text-align: right; }
.lev-value { text-align: center; font-size: 22px; }
.lev-value b { font-size: 32px; }
input[type="range"] { width: 100%; accent-color: var(--yellow); }

#toasts { position: fixed; top: 10px; left: 10px; right: 10px; z-index: 30; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: var(--panel2); border-left: 3px solid var(--yellow); padding: 10px 12px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5); animation: tin 0.2s ease-out; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes tin { from { transform: translateY(-10px); opacity: 0; } }

@media (min-width: 720px) {
  #app { max-width: 720px; margin: 0 auto; }
  .chart { height: 380px; }
}

/* Chart toolbar, indicator menu and drawing overlay */
.chart-bar { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); gap: 6px; flex-wrap: wrap; }
.chart-bar .intervals { border-bottom: 0; }
.chart-tools { display: flex; gap: 4px; padding: 3px 8px; overflow-x: auto; }
.chart-tools .mini { white-space: nowrap; }
.chart-tools .mini.active, .chart-tools .mini.on { color: var(--bg); background: var(--yellow); font-weight: 600; }
.chart { position: relative; }
.chart.with-osc { height: 360px; }
.chart-overlay { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; }
.ind-group { margin: 14px 0 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.ind { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.ind input { margin-top: 3px; accent-color: var(--yellow); }
.ind small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* Trade review */
.hist.tap { cursor: pointer; }
.hist.tap:active { background: var(--panel); }
.rv-head { margin-bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.rv-grid { background: var(--panel2); border-radius: 8px; padding: 4px 10px; }
.rv-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.rv-row:last-child { border-bottom: 0; }
.rv-row span { color: var(--muted); }
.rv-tips-title { display: block; margin: 14px 0 6px; }
.rv-tips { margin: 0 0 8px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.rv-tip { padding: 8px 10px; border-radius: 6px; background: var(--panel2); border-left: 3px solid var(--muted); font-size: 12.5px; }
.rv-tip.bad { border-left-color: var(--red); }
.rv-tip.warn { border-left-color: var(--yellow); }
.rv-tip.good { border-left-color: var(--green); }

/* Invite card */
.ref-link { margin-top: 10px; padding: 8px 10px; background: var(--panel2); border-radius: 6px; font-size: 12px; word-break: break-all; user-select: all; }
.ref-card .muted.small + .muted.small, #ref-stats { margin-top: 6px; }
