:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #18202b;
  --line: #233041;
  --text: #e8edf2;
  --muted: #8d9aa8;
  --accent: #f5b544;
  --accent-ink: #1a1204;
  --bull: #2fd07a;
  --bear: #ff5a5f;
  --warn: #f5b544;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f4ef;
    --panel: #ffffff;
    --panel-2: #f1eee7;
    --line: #e2ddd2;
    --text: #1b2027;
    --muted: #6a7480;
    --accent: #c98a12;
    --accent-ink: #ffffff;
    --bull: #13955a;
    --bear: #d63c42;
    --shadow: 0 8px 24px rgba(30, 25, 10, .08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--bull); }
.down { color: var(--bear); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* ---- shell ---- */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 230px; flex: none; padding: 22px 14px; border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.brand img { width: 30px; height: 30px; }
.navbtn {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px;
  border: 0; background: none; cursor: pointer; text-align: left; color: var(--muted); font-weight: 550;
}
.navbtn svg { width: 21px; height: 21px; flex: none; }
.navbtn:hover { background: var(--panel-2); color: var(--text); }
.navbtn.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.main { flex: 1; min-width: 0; padding: 26px 28px 60px; max-width: 1060px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.top h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.tabbar { display: none; }

@media (max-width: 860px) {
  .side { display: none; }
  .main { padding: calc(14px + env(safe-area-inset-top)) 16px calc(92px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar .navbtn {
    flex: 1; flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 11px; justify-content: center;
    align-items: center; background: none;
  }
  .tabbar .navbtn.on { background: none; }
}

/* ---- cards & bits ---- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; font-weight: 650; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr; } }
.tile { background: var(--panel-2); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-family: var(--mono); font-size: 18px; font-weight: 650; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 650;
  padding: 3px 9px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap;
}
.badge.real { background: color-mix(in srgb, var(--bear) 18%, transparent); color: var(--bear); }
.badge.paper { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.badge.live { background: color-mix(in srgb, var(--bull) 16%, transparent); color: var(--bull); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 11px; padding: 9px 14px;
  cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; justify-content: center;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bear); border-color: color-mix(in srgb, var(--bear) 45%, transparent); }
.btn.block { width: 100%; padding: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.seg { display: inline-flex; background: var(--panel-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: none; padding: 7px 13px; border-radius: 9px; cursor: pointer; font-weight: 600;
  color: var(--muted); font-size: 13.5px;
}
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.seg.modes button.on[data-v="real"] { background: var(--bear); color: #fff; }
.seg.modes button.on[data-v="paper"] { background: var(--accent); color: var(--accent-ink); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: none; border-radius: 999px; padding: 6px 12px; cursor: pointer;
  font-size: 13px; color: var(--muted); font-weight: 600;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=number], input[type=tel] {
  width: 100%; padding: 12px 13px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--panel-2); outline: none; font-size: 16px;
}
input:focus { border-color: var(--accent); }
.check { display: flex; gap: 9px; align-items: center; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.switch { position: relative; width: 46px; height: 27px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 21px; height: 21px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--bull); }
.switch input:checked + span::after { transform: translateX(19px); }

/* ---- lists ---- */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 12.5px; color: var(--muted); }
.item .r { text-align: right; font-family: var(--mono); white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 26px 10px; font-size: 14px; }

/* ---- dashboard ---- */
.hero {
  position: relative; overflow: hidden;
  background:
    radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 55%),
    var(--panel);
}
.hero .who { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 750;
  background: var(--accent); color: var(--accent-ink); flex: none;
}
.bignum { font-family: var(--mono); font-size: clamp(34px, 9vw, 52px); font-weight: 750; letter-spacing: -.02em; margin: 6px 0 2px; }
.flow { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 12px; padding: 12px 14px; }
.flow .arrow { color: var(--muted); }
.chart { width: 100%; height: 150px; display: block; }

/* ---- auth ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 22px 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 26px 22px; }
.auth h1 { font-size: 22px; margin: 6px 0 4px; }
.auth .qr { background: #fff; border-radius: 12px; padding: 10px; width: 220px; margin: 8px auto; }
.auth .qr svg { width: 100%; height: auto; display: block; }
.err { color: var(--bear); font-size: 13.5px; min-height: 18px; }
.feedbar { background: color-mix(in srgb, var(--bear) 13%, transparent); color: var(--bear);
  border: 1px solid color-mix(in srgb, var(--bear) 40%, transparent); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 14px; font-size: 14px; line-height: 1.45; }
.steps { color: var(--muted); font-size: 13.5px; padding-left: 18px; margin: 6px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text);
  padding: 22px; max-width: 420px; width: calc(100% - 32px); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h3 { margin: 0 0 8px; }

/* Analyze type-ahead */
.sugbox {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: var(--shadow); overflow: hidden; max-height: 300px; overflow-y: auto;
}
.sug { padding: 11px 13px; cursor: pointer; font-weight: 600; font-family: var(--mono); }
.sug:hover, .sug.on { background: var(--panel-2); color: var(--accent); }

/* Growth chart: amount axis, plot with crosshair tooltip, date axis */
.gchart { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; row-gap: 6px; }
.gy { height: 170px; display: flex; flex-direction: column; justify-content: space-between; text-align: right;
  font: 11px var(--mono); color: var(--muted); margin: -6px 0; }
.gplot { position: relative; height: 170px; cursor: crosshair; touch-action: pan-y; outline: none; border-radius: 6px; }
.gplot:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.gplot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.gdot { position: absolute; width: 8px; height: 8px; border-radius: 50%; transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px var(--panel); pointer-events: none; }
.ghot { width: 12px; height: 12px; display: none; z-index: 3; }
.gcross { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--muted); opacity: .55; display: none;
  pointer-events: none; z-index: 2; }
.gtip { position: absolute; display: none; z-index: 4; pointer-events: none; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px;
  box-shadow: var(--shadow); font-size: 12px; line-height: 1.45; color: var(--text); }
.gtip .gtv { font: 700 15px var(--mono); }
.gx { position: relative; height: 16px; font: 11px var(--mono); color: var(--muted); }
.gx span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.gx span:first-child { transform: none; }
.gx span:last-child:not(:first-child) { transform: translateX(-100%); }

/* Analyze price chart: plot + right price axis, crosshair tooltip */
.cchart { display: grid; grid-template-columns: 1fr auto; column-gap: 10px; row-gap: 6px; }
.cplot { position: relative; height: 180px; cursor: crosshair; touch-action: pan-y; outline: none; border-radius: 6px; }
.cplot:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.cplot svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.cy { position: relative; height: 180px; min-width: 64px; font: 11px var(--mono); color: var(--muted); }
.cy span { position: absolute; right: 0; transform: translateY(-50%); white-space: nowrap; }
.cy span.last { color: var(--text); font-weight: 700; background: var(--panel); padding: 1px 3px; border-radius: 4px; }
