:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-2: #f2f1ec;
  --ink: #111111;
  --ink-2: #55544f;
  --muted: #8a8983;
  --line: #e9e8e2;
  --gain: #0b7a3a;
  --loss: #c0352e;
  --warn: #9a5b00;
  --gain-bg: #e6f4ea;
  --loss-bg: #fbe9e7;
  --warn-bg: #fdf1dc;
  --btn: #111111;
  --btn-ink: #ffffff;
  --shadow: 0 1px 2px rgba(17, 17, 17, .04), 0 8px 24px rgba(17, 17, 17, .04);
  --radius: 20px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0c;
    --surface: #171716;
    --surface-2: #222220;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #8f8e87;
    --line: #2a2a28;
    --gain: #4cc97a;
    --loss: #ef7b74;
    --warn: #f0b44c;
    --gain-bg: #12301e;
    --loss-bg: #3a1a18;
    --warn-bg: #3a2c12;
    --btn: #f0efec;
    --btn-ink: #111111;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1040px; margin: 0 auto; padding: 20px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo svg { width: 30px; height: 30px; display: block; }
.logo rect { fill: var(--ink); }
.logo path { stroke: var(--bg); stroke-width: 2.6; stroke-linecap: round; fill: none; }
.wordmark { font-weight: 650; font-size: 18px; letter-spacing: -.02em; }
.chips { display: flex; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.live .dot { background: var(--gain); box-shadow: 0 0 0 3px var(--gain-bg); }
.chip.down .dot { background: var(--loss); }

/* page */
.page { max-width: 1040px; margin: 0 auto; padding: 8px 24px 64px; }

.hero { padding: 28px 0 24px; }
.label { color: var(--ink-2); font-size: 15px; }
.balance {
  font-size: clamp(40px, 7vw, 60px); font-weight: 550; letter-spacing: -.035em;
  line-height: 1.1; margin-top: 6px;
}
.change { margin-top: 8px; font-size: 15px; color: var(--ink-2); }
.change .up { color: var(--gain); font-weight: 550; }
.change .down { color: var(--loss); font-weight: 550; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 12px 40px; margin-top: 22px; }
.hero-stats div, .kpis div { display: flex; flex-direction: column; }
.k { color: var(--muted); font-size: 13px; }
.v { font-size: 17px; font-weight: 550; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 22px 18px;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card h2 { font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.sub { color: var(--ink-2); font-size: 14px; margin-top: 2px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 4px 11px; border-radius: 999px; font-size: 13px; font-weight: 550;
  background: var(--surface-2); color: var(--ink-2);
}
.pill.ok { background: var(--gain-bg); color: var(--gain); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--loss-bg); color: var(--loss); }

/* chart */
.chart-card { padding: 16px 16px 8px; }
.chart-head { display: flex; justify-content: flex-end; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 550; color: var(--ink-2); cursor: pointer;
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chart { position: relative; height: 220px; margin-top: 8px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: url(#fade); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .dot { fill: var(--ink); stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; top: 0; pointer-events: none; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: 10px; padding: 6px 10px;
  font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; }

/* actions */
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0; }
.btn {
  border-radius: 999px; padding: 11px 20px; font-weight: 600; font-size: 15px; cursor: pointer;
  border: 1px solid transparent; transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--btn); color: var(--btn-ink); }
.btn.secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--ink-2); }
.btn.danger { color: var(--loss); }
.btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.banner {
  border-radius: 14px; padding: 12px 16px; margin: -6px 0 18px; font-size: 14px;
  background: var(--warn-bg); color: var(--warn);
}
.banner.bad { background: var(--loss-bg); color: var(--loss); }
.banner button { margin-left: 8px; }

/* layout */
.grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }

.kpis { display: flex; gap: 32px; padding: 4px 0 14px; border-bottom: 1px solid var(--line); }

/* positions */
.positions, .checks, .activity, .mm-list { list-style: none; margin: 0; padding: 0; }
.pos { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); align-items: center; }
.pos:last-child { border-bottom: 0; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 650; font-size: 12px; letter-spacing: -.01em;
}
.pos .name { font-weight: 600; }
.pos .meta { color: var(--ink-2); font-size: 13px; margin-top: 1px; }
.pos .right { text-align: right; }
.pos .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.pos .apr { font-size: 13px; margin-top: 1px; font-variant-numeric: tabular-nums; }
.apr.up { color: var(--gain); }
.apr.down { color: var(--loss); }
.pos .bars { grid-column: 2 / 4; display: flex; gap: 18px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.pos.off { opacity: .62; }
.meter { display: inline-flex; align-items: center; gap: 6px; }
.meter i { display: inline-block; width: 64px; height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter b { display: block; height: 100%; border-radius: 4px; background: var(--gain); }
.meter.warn b { background: var(--warn); }
.meter.bad b { background: var(--loss); }

/* checks */
.check { display: grid; grid-template-columns: 24px 1fr; gap: 10px; padding: 9px 0; align-items: start; }
.icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.icon.ok { background: var(--gain-bg); color: var(--gain); }
.icon.warn { background: var(--warn-bg); color: var(--warn); }
.icon.breach { background: var(--loss-bg); color: var(--loss); }
.check .msg { font-size: 14px; }

/* activity */
.ev { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.ev:last-child { border-bottom: 0; }
.ev .t { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ev .kind { font-size: 12px; color: var(--muted); display: block; }
.ev.funding .kind { color: var(--gain); }
.ev.risk .kind, .ev.error .kind, .ev.adl .kind { color: var(--loss); }
.ev.warn .kind { color: var(--warn); }

/* market making */
.gate { font-size: 14px; color: var(--ink-2); padding: 0 0 8px; }
.mm-row { display: grid; grid-template-columns: 70px 1fr 120px; gap: 10px; align-items: center; padding: 7px 0; font-size: 13px; }
.mm-row .coin { font-weight: 600; }
.ci { position: relative; height: 18px; }
.ci .zero { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--muted); }
.ci .range { position: absolute; top: 8px; height: 3px; border-radius: 3px; background: var(--surface-2); }
.ci .pt { position: absolute; top: 5px; width: 9px; height: 9px; border-radius: 50%; transform: translateX(-50%); background: var(--ink-2); }
.ci .pt.neg { background: var(--loss); }
.ci .pt.pos { background: var(--gain); }
.mm-row .num { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.footnote, .foot { color: var(--muted); font-size: 12px; margin-top: 10px; }
.foot { text-align: center; margin-top: 32px; }

/* dialog, toast */
dialog { border: 0; border-radius: 20px; padding: 0; background: var(--surface); color: var(--ink); max-width: 420px; width: calc(100% - 32px); }
dialog:has(.review) { max-width: 600px; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dialog { padding: 24px; }
.dialog h3 { font-size: 20px; letter-spacing: -.01em; }
.dialog p { color: var(--ink-2); margin-top: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

@media (max-width: 520px) {
  .topbar, .page { padding-left: 16px; padding-right: 16px; }
  .card { padding: 18px 16px 14px; border-radius: 18px; }
  .hero-stats { gap: 12px 28px; }
  .kpis { gap: 22px; }
  .actions .btn { flex: 1 1 auto; }
  .mm-row { grid-template-columns: 56px 1fr 92px; }
}

/* ---------------------------------------------------------------- navigation */
.nav { display: flex; gap: 4px; margin-left: 18px; }
.nav a { color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 550; padding: 6px 12px; border-radius: 999px; }
.nav a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); border: 1px solid var(--line); }
.chip.linkish { cursor: pointer; font: inherit; font-size: 13px; }
.chip.linkish:hover { color: var(--ink); }
@media (max-width: 520px) { .nav { margin-left: 8px; } .nav a { padding: 6px 9px; } #chip-mode { display: none; } }

/* ---------------------------------------------------------------- forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 550; }
.field small, .field-row small { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input[type="text"], input[type="password"], input[type="number"], input:not([type]), select {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; width: 100%; min-width: 0;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
input:disabled, select:disabled { opacity: .55; }
.form-error { color: var(--loss); font-size: 14px; }
.hint, .muted { color: var(--muted); font-size: 13px; }
.btn.wide { width: 100%; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.fields { display: flex; flex-direction: column; }
.field-row { display: grid; grid-template-columns: 1fr 180px; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.field-row:last-child { border-bottom: 0; }
.field-row label { display: flex; flex-direction: column; gap: 2px; font-size: 14.5px; }
.with-unit { position: relative; }
.with-unit input { padding-right: 30px; text-align: right; font-variant-numeric: tabular-nums; }
.with-unit input[type="text"] { text-align: left; padding-right: 12px; }
.with-unit span { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; gap: 8px; } }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + i { background: var(--gain); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------------------------------------------------------------- settings */
.hero.slim { padding: 18px 0 18px; }
.title { font-size: clamp(30px, 5vw, 40px); font-weight: 600; letter-spacing: -.03em; }
.coins { display: flex; flex-direction: column; }
.coin-row { display: grid; grid-template-columns: 40px 1fr 44px 84px 150px 28px; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.coin-row.off .avatar, .coin-row.off .coin-name { opacity: .55; }
.coin-name { display: flex; flex-direction: column; }
.coin-name small { color: var(--warn); font-size: 12px; }
.coin-row select { padding: 8px 10px; font-size: 14px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; border-radius: 8px; line-height: 1; padding: 2px 6px; }
.icon-btn:hover { color: var(--loss); background: var(--loss-bg); }
@media (max-width: 620px) {
  .coin-row { grid-template-columns: 36px 1fr 44px 28px; grid-template-areas: "a n s x" "a l m m"; }
  .coin-row .avatar { grid-area: a; } .coin-row .coin-name { grid-area: n; } .coin-row .switch { grid-area: s; }
  .coin-row select[data-k="leverage"] { grid-area: l; } .coin-row select[data-k="mode"] { grid-area: m; } .coin-row .icon-btn { grid-area: x; }
}
.add-coin, .inline-form { display: flex; gap: 10px; margin-top: 14px; align-items: center; }
.add-coin input, .inline-form input { flex: 1; }
.add-coin .btn, .inline-form .btn { white-space: nowrap; flex: none; padding: 10px 16px; }
.add-coin input { text-transform: uppercase; }
.add-coin input::placeholder { text-transform: none; }
.subsection { padding: 16px 0 6px; border-top: 1px solid var(--line); margin-top: 8px; }
.subsection:first-of-type { border-top: 0; }
.subsection h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.row-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li small { display: block; color: var(--muted); font-size: 12.5px; }
details summary { list-style: none; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
details summary::-webkit-details-marker { display: none; }
details summary h2::after { content: " ›"; color: var(--muted); }
details[open] summary h2::after { content: " ⌄"; }
details .fields { margin-top: 10px; }

.savebar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10; width: min(640px, calc(100% - 32px));
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--ink); color: var(--bg); border-radius: 999px; padding: 8px 8px 8px 22px; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.savebar .btn.ghost { color: var(--bg); opacity: .8; }
.savebar .btn.primary { background: var(--bg); color: var(--ink); }
main.settings { padding-bottom: 110px; }

.review { list-style: none; padding: 0; margin: 14px 0 6px; max-height: 50vh; overflow: auto; }
.review li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.review .chg { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.notes { margin: 6px 0 0; padding-left: 18px; font-size: 14px; color: var(--ink-2); }
.notes.bad li { color: var(--loss); }
.review li { grid-template-columns: minmax(0, 1fr) auto auto; }
.review li > span:first-child { overflow-wrap: anywhere; }
.review .pill { justify-self: end; }
@media (max-width: 520px) { .review li { grid-template-columns: 1fr auto; } .review .pill { grid-column: 2; } }

/* ---------------------------------------------------------------- sign-in page */
.auth-page { min-height: 100vh; display: grid; place-items: center; }
.auth-wrap { width: min(420px, calc(100% - 32px)); padding: 40px 0; }
.auth-brand { justify-content: center; margin-bottom: 22px; }
.auth-card { padding: 30px 28px 26px; }
.auth-card h1 { font-size: 26px; letter-spacing: -.02em; font-weight: 600; }
.auth-card .sub { margin: 6px 0 22px; }
.auth-card code { font-size: 12px; }
