:root {
  --bg: #0f1115; --card: #181b22; --line: #262a33; --text: #e8e9ec; --muted: #8b90a0;
  --gold: #e3b341; --buy: #26a69a; --sell: #ef5350; --warn: #f0a020; --ok: #5fe0a8; --bad: #ff8a80;
  --nav-h: 56px; --ticket-h: 64px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* header / view / tab bar stacked in one screen-high column, so nothing overlaps on any phone */
body {
  margin: 0; height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text); overscroll-behavior: none;
  font: 15px/1.45 -apple-system, system-ui, Roboto, "Segoe UI", sans-serif;
}
a { color: var(--gold); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
input:focus { outline: 2px solid var(--gold); border-color: transparent; }

/* header */
.top {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.logo {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
  background: var(--gold); color: #1a1400; font-weight: 800;
}
.quote { flex: 1; display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; font-weight: 600; }
.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--line); white-space: nowrap; }
.pill.protected { background: #123a2a; color: var(--ok); }
.pill.starting, .pill.connecting { background: #3a3012; color: var(--gold); }
.pill.login_failed, .pill.offline { background: #3a1416; color: var(--bad); }

.view { flex: 1; min-height: 0; overflow-y: auto; width: 100%; max-width: 640px; margin: 0 auto; }
.view[hidden] { display: none; }
.pad { padding: 16px 16px 24px; }
h1 { font-size: 22px; margin: 8px 0; }
h2 { font-size: 15px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.error { color: var(--bad); }
.warn { margin: 8px 12px; padding: 8px 10px; border-radius: 8px; background: #3a2a10; color: var(--warn); font-size: 13px; }

/* buttons */
.btn { flex: 1; padding: 13px 16px; font-weight: 600; border-radius: 10px; }
.btn.wide { width: 100%; }
.btn.gold { background: var(--gold); color: #1a1400; }
.btn.buy { background: var(--buy); color: #fff; }
.btn.sell { background: var(--sell); color: #fff; }
.btn.ghost { border: 1px solid var(--line); }
.btn.danger { background: #3a1416; color: var(--bad); }
.btn:disabled { opacity: .55; }
.chip { padding: 6px 10px; border-radius: 99px; border: 1px solid var(--line); font-size: 12px; }

/* sign in */
form label { display: block; margin: 12px 0; font-size: 13px; color: var(--muted); }
form input { display: block; width: 100%; margin-top: 4px; padding: 12px; font-size: 16px; }

/* chart tab */
#tab-chart { display: flex; flex-direction: column; overflow: hidden; }
#tab-chart[hidden] { display: none; }
.tfbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { padding: 5px 11px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--line); color: var(--text); }
.kscore { display: flex; gap: 6px; font-size: 12px; font-weight: 700; }
.kscore span { padding: 3px 8px; border-radius: 6px; background: var(--card); }
.kscore .b { color: var(--buy); } .kscore .s { color: var(--sell); }
#chart { flex: 1; min-height: 220px; touch-action: none; }   /* the chart handles its own gestures; lets line drags keep the pointer */
.ticket { display: flex; gap: 8px; align-items: stretch; padding: 8px 12px; border-top: 1px solid var(--line); }
.side { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 10px; padding: 6px; color: #fff; }
.side small { font-size: 11px; font-weight: 700; opacity: .85; }
.side b { font-size: 17px; font-variant-numeric: tabular-nums; }
.side.sell { background: var(--sell); }
.side.buy { background: var(--buy); }
.lot { display: grid; grid-template-columns: 30px 64px 30px; grid-template-rows: auto auto; gap: 4px; align-items: center; justify-items: center; }
.lot button { width: 30px; height: 34px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); font-size: 18px; }
.lot input { width: 64px; height: 34px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.limit-toggle { grid-column: 1 / -1; font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.limit-row { display: flex; gap: 8px; align-items: center; padding: 0 12px 10px; }
.limit-row[hidden] { display: none; }
.limit-row input { width: 100px; padding: 6px 8px; text-align: center; font-variant-numeric: tabular-nums; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 0; border-top: 1px solid var(--line); font-size: 14px; }
.list li:first-child { border-top: 0; }
.empty { color: var(--muted); font-size: 13px; }
.side-BUY, .side-BUY_LIMIT { color: var(--buy); font-weight: 700; }
.side-SELL, .side-SELL_LIMIT { color: var(--sell); font-weight: 700; }
.pos { display: flex; justify-content: space-between; gap: 8px; }
.pl { font-variant-numeric: tabular-nums; font-weight: 700; }
.up { color: var(--buy); } .down { color: var(--sell); }
.acts { display: flex; gap: 8px; margin-top: 8px; }
.acts .btn { padding: 8px; font-size: 13px; }
.feed li { font-size: 13px; }
.kind { font-size: 11px; font-weight: 700; text-transform: uppercase; margin-right: 6px; }
.kind.guard { color: var(--ok); } .kind.fail { color: var(--bad); } .kind.rating { color: var(--gold); }
.kind.setup { color: #8ab4ff; } .kind.order { color: #c39bff; }
.feed time { display: block; color: var(--muted); font-size: 11px; }

/* account */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h2 { margin-top: 0; }
.kv { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.kv li { display: flex; justify-content: space-between; padding: 4px 0; }
.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scores th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding-bottom: 6px; }
.scores td { padding: 4px 0; }
.bar { position: relative; height: 18px; width: 90%; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; }
.bar.buy i { background: var(--buy); } .bar.sell i { background: var(--sell); }
.bar span { position: relative; font-size: 12px; padding-left: 6px; font-weight: 600; }
.attrib { margin-top: 20px; text-align: center; }

/* bottom nav */
.tabs {
  flex: none; display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--bg); border-top: 1px solid var(--line);
}
.tabs[hidden] { display: none; }
.tabs button { flex: 1; font-size: 13px; font-weight: 600; color: var(--muted); }
.tabs button.on { color: var(--gold); }

/* sheet + toast */
.sheet { position: fixed; inset: 0; z-index: 5; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; }
.sheet[hidden] { display: none; }
.sheet-body {
  width: 100%; max-width: 640px; margin: 0 auto; max-height: 85dvh; overflow: auto; background: var(--card);
  border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.verdict { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.verdict b { font-size: 13px; padding: 4px 10px; border-radius: 6px; }
.verdict .GOOD { background: #123a2a; color: var(--ok); }
.verdict .CAUTION { background: #3a3012; color: var(--gold); }
.verdict .POOR { background: #3a1416; color: var(--bad); }
.reasons { margin: 6px 0 12px; padding-left: 18px; font-size: 14px; }
.levels-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; font-size: 13px; }
.levels-grid div { background: var(--bg); border-radius: 8px; padding: 6px; text-align: center; font-variant-numeric: tabular-nums; }
.levels-grid small { display: block; color: var(--muted); font-size: 11px; }
.better { border: 1px solid var(--gold); border-radius: 10px; padding: 10px; margin-bottom: 12px; font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); z-index: 6;
  padding: 12px 14px; border-radius: 10px; background: #22262f; border: 1px solid var(--line); font-size: 14px;
}
.toast.ok { border-color: var(--buy); } .toast.bad { border-color: var(--sell); }
.limit-toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--gold); background: none; border: 0; }

/* server picker */
.picker { position: relative; }
.picker-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 4; max-height: 50dvh; overflow-y: auto;
  margin: 0; padding: 4px 0; list-style: none; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.picker-list[hidden] { display: none; }
.picker-list li { padding: 10px 12px; cursor: pointer; color: var(--text); }
.picker-list li + li { border-top: 1px solid var(--line); }
.picker-list li:active, .picker-list li:hover { background: var(--line); }
.picker-list b { display: block; font-size: 15px; font-weight: 600; }
.picker-list small { color: var(--muted); font-size: 12px; }
.picker-list .typed b { color: var(--gold); }
