/*
  Design system
  - One family, Archivo, used across its width axis: expanded for the wordmark, normal for
    interface text, semi-condensed tabular figures for every number (prices, sizes, P&L).
  - Slate night base with brass as the brand accent; teal and coral for long and short.
  - Structure comes from panel tone changes and thin rules, not boxes and badges.
*/
@font-face {
  font-family: 'Archivo';
  src: url('/fonts/archivo.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #131b25;          /* slate night: page and panel base */
  --panel: #18222e;       /* raised surfaces: inputs, menus, hovered rows */
  --panel-2: #1e2a38;     /* active controls */
  --line: #233040;        /* rules between panels */
  --line-2: #2f3f52;      /* control borders */
  --text: #dfe5eb;
  --muted: #8592a1;
  --faint: #5c6a7a;
  --brass: #e0a43a;       /* brand accent: primary actions, active tab */
  --brass-ink: #1b1406;
  --up: #3fb68b;
  --down: #e5604f;
  --up-bg: rgba(63, 182, 139, 0.13);
  --down-bg: rgba(229, 96, 79, 0.13);
  --accent: var(--brass);
  --warn: #e0a43a;
  --radius: 4px;
  --font: 'Archivo', system-ui, sans-serif;
  --brass-hover: #ebb24c;
  --up-ink: #06180f;
  --down-ink: #1d0703;
  --ticket-bg: #151e29;
  --text-soft: #c9d1da;
  --scrim: rgba(9, 13, 19, 0.65);
  --shadow: rgba(4, 8, 13, 0.55);
  --grid: #1a2430;
  --vol-up: rgba(63, 182, 139, 0.32);
  --vol-down: rgba(229, 96, 79, 0.32);
  color-scheme: dark;
}

/* Light: warm paper rather than pure white, with deeper accents so they hold contrast. */
:root[data-theme='light'] {
  --bg: #f5f3ee;
  --panel: #ece9e2;
  --panel-2: #e2ded5;
  --line: #dcd7cc;
  --line-2: #c8c1b3;
  --text: #17202b;
  --muted: #5d6874;
  --faint: #8b949e;
  --brass: #c4861a;
  --brass-ink: #1b1406;
  --brass-hover: #d29424;
  --up: #12825b;
  --down: #cc3d2c;
  --up-ink: #ffffff;
  --down-ink: #ffffff;
  --up-bg: rgba(18, 130, 91, 0.11);
  --down-bg: rgba(204, 61, 44, 0.10);
  --warn: #b5760f;
  --ticket-bg: #efece5;
  --text-soft: #2c3642;
  --scrim: rgba(23, 32, 43, 0.32);
  --shadow: rgba(40, 32, 18, 0.18);
  --grid: #e7e3da;
  --vol-up: rgba(18, 130, 91, 0.28);
  --vol-down: rgba(204, 61, 44, 0.26);
  color-scheme: light;
}

.theme-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: var(--radius); color: var(--muted); flex-shrink: 0; }
.theme-btn:hover { color: var(--text); background: var(--panel); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 13px/1.45 var(--font);
  font-stretch: 100%;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

/* Numbers: semi-condensed tabular figures, so columns align and the book stays dense. */
.num, .book-row, .trade-row, .tbl td, .stat-val, .input.num {
  font-family: var(--font);
  font-stretch: 87.5%;
  font-variant-numeric: tabular-nums;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 28px;
  height: 52px; padding: 0 18px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 2px; }
.brand-name { font-stretch: 125%; font-weight: 800; font-size: 16px; letter-spacing: -0.01em; }
.brand-name b { color: var(--brass); font-weight: 800; }
.nav { display: flex; gap: 2px; }
.nav-link { padding: 6px 10px; color: var(--muted); font-weight: 500; border-radius: var(--radius); }
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--text); font-weight: 600; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 32px; padding: 0 14px; border-radius: var(--radius); font-weight: 600;
}
.btn-primary { background: var(--brass); color: var(--brass-ink); }
.btn-primary:hover { background: var(--brass-hover); }
.btn-primary:disabled, .btn-long:disabled, .btn-short:disabled {
  background: var(--panel); color: var(--muted); cursor: not-allowed; box-shadow: inset 0 0 0 1px var(--line-2);
}
.btn-ghost { color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-block { width: 100%; height: 42px; font-size: 14px; }
.btn-long { background: var(--up); color: var(--up-ink); }
.btn-short { background: var(--down); color: var(--down-ink); }
.btn-long:hover, .btn-short:hover { filter: brightness(1.07); }

/* Feed status: a dot and a word, no badge. */
.pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500; color: var(--muted); }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-live i { background: var(--up); }
.pill-wait { color: var(--warn); }
.pill-down { color: var(--down); }

/* ---- market bar ---- */
.market-bar {
  display: flex; align-items: center; gap: 32px;
  padding: 10px 18px; border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap;
}
.market-btn {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px;
  border-radius: var(--radius); background: var(--panel);
}
.market-btn:hover { background: var(--panel-2); }
.coin-badge {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(224, 164, 58, 0.16); color: var(--brass); font-weight: 700; font-size: 12px;
}
.market-title { font-size: 16px; font-weight: 600; font-stretch: 112%; }
.market-title span { color: var(--muted); font-weight: 400; }
.tag { font-size: 12px; color: var(--muted); }
.stat { display: flex; flex-direction: column; gap: 1px; }
.stat-label { font-size: 11.5px; color: var(--muted); }
.stat-val { font-size: 13.5px; }
.stat-big .stat-val { font-size: 19px; font-weight: 600; }

/* ---- market menu ---- */
.market-menu {
  position: absolute; top: 106px; left: 18px; z-index: 20; width: 580px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px;
  box-shadow: 0 18px 48px var(--shadow); padding: 10px;
}
.input {
  width: 100%; height: 36px; padding: 0 10px; border-radius: var(--radius); border: 1px solid var(--line-2);
  background: var(--bg); color: var(--text); font: inherit; outline: none;
}
.input:focus { border-color: var(--brass); }
.menu-head, .menu-row { display: grid; grid-template-columns: 1.2fr 1.2fr 0.8fr 1fr 0.7fr; gap: 8px; padding: 7px 8px; }
.menu-head { color: var(--muted); font-size: 11.5px; margin-top: 8px; }
.menu-head span:not(:first-child), .menu-row span:not(:first-child) { text-align: right; }
.menu-list { max-height: 360px; overflow-y: auto; }
.menu-row { border-radius: var(--radius); cursor: pointer; }
.menu-row:hover, .menu-row.current { background: var(--panel-2); }

/* ---- layout ---- */
.grid {
  flex: 1; display: grid; gap: 1px; background: var(--line);
  grid-template-columns: minmax(0, 1fr) 300px 310px;
  grid-template-rows: minmax(420px, 1fr) 250px;
  grid-template-areas: 'chart book ticket' 'bottom bottom ticket';
}
.panel { background: var(--bg); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chart-panel { grid-area: chart; }
.book-panel { grid-area: book; }
.ticket-panel { grid-area: ticket; background: var(--ticket-bg); }
.bottom-panel { grid-area: bottom; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 42px; padding: 0 14px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.panel-head b { font-weight: 600; font-size: 14px; }
.tabs { justify-content: flex-start; gap: 18px; }
.tab { height: 100%; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--brass); }

.seg { display: inline-flex; gap: 2px; }
.seg-btn { padding: 5px 9px; border-radius: var(--radius); color: var(--muted); font-weight: 500; font-size: 12.5px; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--panel-2); color: var(--text); }
.seg-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.seg-full { display: flex; width: 100%; background: var(--bg); border-radius: var(--radius); padding: 3px; }
.seg-full .seg-btn { flex: 1; padding: 8px 0; font-size: 13.5px; }
.side-seg .long.active { background: var(--up-bg); color: var(--up); }
.side-seg .short.active { background: var(--down-bg); color: var(--down); }

.chart { flex: 1; min-height: 0; position: relative; }

/* ---- order book & trades ---- */
.tab-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.book-head, .book-row, .trade-row { display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 0 14px; }
.book-head { color: var(--muted); font-size: 11.5px; height: 28px; align-items: center; }
.book-head span:not(:first-child), .book-row span:not(:first-child), .trade-row span:not(:first-child) { text-align: right; }
.book-side { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.asks { justify-content: flex-end; }
.book-row { position: relative; height: 20px; align-items: center; font-size: 12.5px; }
.book-row .bar { position: absolute; top: 2px; bottom: 2px; right: 0; z-index: 0; }
.book-row span { position: relative; z-index: 1; }
.asks .book-row .px { color: var(--down); }
.bids .book-row .px { color: var(--up); }
.asks .bar { background: var(--down-bg); }
.bids .bar { background: var(--up-bg); }
.spread {
  display: flex; justify-content: space-between; align-items: center; height: 34px; padding: 0 14px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.spread #spread-mid { font-size: 16px; font-weight: 600; font-stretch: 87.5%; }
.trades { flex: 1; overflow-y: auto; }
.trade-row { height: 20px; align-items: center; font-size: 12.5px; }
.trade-row.flash { animation: flash 0.6s ease-out; }
@keyframes flash { from { background: var(--panel-2); } to { background: transparent; } }

/* ---- ticket ---- */
.ticket { padding: 14px; display: flex; flex-direction: column; gap: 13px; overflow-y: auto; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12.5px; }
.field-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.field-row b { color: var(--text); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 46px; text-align: right; font-size: 15px; height: 40px; }
.input-wrap .unit { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }
input[type=range] { width: 100%; accent-color: var(--brass); }
.preview { margin: 0; display: flex; flex-direction: column; gap: 6px; padding: 2px 0; }
.preview div { display: flex; justify-content: space-between; gap: 8px; }
.preview dt { color: var(--muted); }
.preview dd { margin: 0; text-align: right; }
.note { margin: 0; color: var(--faint); font-size: 12px; }
.account-box { display: flex; flex-direction: column; gap: 7px; padding-top: 14px; border-top: 1px solid var(--line); }
.link-btn { color: var(--brass); font-size: 12.5px; font-weight: 500; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.checks { display: flex; gap: 18px; }
.check { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; cursor: pointer; }
.check input { accent-color: var(--brass); }
.tpsl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tpsl .input-wrap .input { font-size: 13.5px; padding-right: 40px; }
.t-msg { margin: 0; font-size: 12.5px; padding: 9px 10px; border-radius: var(--radius); background: var(--panel); }
.t-msg.error { color: var(--down); background: var(--down-bg); }
.t-msg.ok { color: var(--up); background: var(--up-bg); }
.progress-wrap { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.progress { height: 4px; border-radius: 2px; background: var(--panel-2); overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--brass); transition: width 0.3s; }
.a-banner { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: var(--radius); font-size: 12.5px; margin-bottom: 4px; border-left: 3px solid currentColor; }
.a-banner.fail { background: var(--down-bg); color: var(--down); }
.a-banner.pass { background: var(--up-bg); color: var(--up); }
.a-banner.info { background: rgba(224, 164, 58, 0.12); color: var(--brass); }
.a-banner span { color: var(--text); }

/* ---- account switcher ---- */
.auth-group { display: inline-flex; align-items: center; gap: 10px; }
.acct-select {
  height: 32px; max-width: 270px; padding: 0 28px 0 10px; border-radius: var(--radius); border: 1px solid var(--line-2);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 500;
}

/* ---- bottom panel ---- */
.cnt { color: var(--muted); font-weight: 400; }
.bottom-body { flex: 1; overflow: auto; min-height: 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th {
  position: sticky; top: 0; background: var(--bg); color: var(--muted); font-weight: 500; font-size: 11.5px;
  text-align: right; padding: 9px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { text-align: right; padding: 8px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:hover td { background: var(--panel); }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl td.txt { font-stretch: 100%; }
.tbl .coin-cell { font-stretch: 100%; font-weight: 600; }
.tbl .coin-cell a:hover { text-decoration: underline; }
.mini-btn { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: var(--radius); background: var(--panel-2); color: var(--text); font-stretch: 100%; }
.mini-btn:hover { background: var(--line-2); }
.mini-btn.danger:hover { background: var(--down-bg); color: var(--down); }
.empty { flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 24px; text-align: center; }

/* ---- modal & toast ---- */
.modal { position: fixed; inset: 0; z-index: 50; background: var(--scrim); display: grid; place-items: center; padding: 16px; }
.modal-card { width: 380px; max-width: 100%; background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; font-size: 17px; }
.modal-head b { font-weight: 700; font-stretch: 112%; }
.center { text-align: center; margin: 0; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); padding: 9px 14px; border-radius: var(--radius); z-index: 60; }

body.paused .book-side, body.paused #spread-mid { opacity: 0.45; }
.btn, .pill, .topbar, .market-bar { white-space: nowrap; flex-shrink: 0; }

@media (prefers-reduced-motion: reduce) {
  .trade-row.flash { animation: none; }
  .progress div { transition: none; }
}

/* Desktop: the terminal fills the window; panels scroll inside themselves. */
@media (min-width: 1101px) {
  body.terminal { height: 100vh; overflow: hidden; }
  .grid { min-height: 0; grid-template-rows: minmax(0, 1fr) 250px; }
  .panel { overflow: hidden; }
  .ticket { flex: 1; min-height: 0; }
}
@media (max-width: 1100px) {
  .grid { grid-template-columns: minmax(0, 1fr) 310px; grid-template-rows: 460px 440px 240px; grid-template-areas: 'chart chart' 'book ticket' 'bottom bottom'; }
}
@media (max-width: 680px) {
  .topbar { gap: 4px 12px; padding: 8px 12px 0; height: auto; flex-wrap: wrap; }
  .nav { order: 3; width: calc(100% + 24px); margin: 0 -12px; padding: 2px 6px 6px; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { flex-shrink: 0; }
  #topbar .btn-ghost[data-auth], #user-email, .terminal #logout-btn { display: none; }
  .brand-name { font-size: 14px; }
  .acct-select { max-width: calc(100vw - 150px); }
  .terminal .pill > span { display: none; }
  .market-bar { gap: 20px; padding: 8px 12px; scrollbar-width: none; }
  .market-bar::-webkit-scrollbar { display: none; }
  #coin-kind { display: none; }
  .stat-big .stat-val { font-size: 17px; }
}
.market-cats { margin-top: 8px; }
.cat { font-size: 11px; color: var(--brass); margin-left: 4px; }

/* ---- phone terminal ---- */
@media (min-width: 681px) { .m-only, .m-tabs { display: none !important; } }
@media (max-width: 680px) {
  .d-only { display: none !important; }
  /* iOS zooms into inputs under 16px; keep everything typeable at 16px. */
  .input, .input-wrap .input, .tpsl .input-wrap .input, .acct-select { font-size: 16px; }

  .terminal { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  .grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: 'mtabs' 'chart' 'book' 'macct' 'bottom';
  }
  .m-tabs { grid-area: mtabs; display: flex; height: 40px; padding: 0 12px; gap: 20px; background: var(--bg); border-bottom: 1px solid var(--line); }
  .chart-panel, .book-panel { height: clamp(300px, 52vh, 520px); }
  body[data-mview='chart'] .book-panel, body[data-mview='book'] .chart-panel, body[data-mview='trades'] .chart-panel { display: none; }
  .chart-panel .panel-head { padding: 0 8px; }
  .chart-panel .panel-head .muted { display: none; }
  .book-panel .panel-head { display: none; }
  .book-side { flex: 1; }
  .book-head, .book-row, .trade-row { padding: 0 12px; }

  /* Account strip between the market view and positions. */
  .m-account { grid-area: macct; }
  .m-account .account-box { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; padding: 12px; border-top: 0; }
  .m-account .account-box > .field-row { flex-direction: column; align-items: flex-start; gap: 1px; font-size: 13px; }
  .m-account .account-box > .field-row > .muted { font-size: 11.5px; }
  .m-account .account-box > .field-row:has(#a-name) { display: none; }
  .m-account .a-banner, .m-account .progress-wrap { grid-column: 1 / -1; }

  /* Positions and orders. */
  .bottom-panel { min-height: 200px; }
  #bottom-tabs { overflow-x: auto; scrollbar-width: none; gap: 16px; padding: 0 12px; }
  #bottom-tabs::-webkit-scrollbar { display: none; }
  #bottom-tabs .tab { flex-shrink: 0; white-space: nowrap; }
  .bottom-body { overflow: visible; }
  .bottom-body > .tbl { display: block; overflow-x: auto; }

  /* Ticket as a bottom sheet. */
  .ticket-panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 46; max-height: 88vh;
    border-top: 1px solid var(--line-2); border-radius: 12px 12px 0 0;
    transform: translateY(105%); transition: transform 0.22s ease; visibility: hidden;
  }
  body.sheet-open .ticket-panel { transform: none; visibility: visible; }
  body.sheet-open { overflow: hidden; }
  .ticket-panel .panel-head { height: 48px; }
  .ticket { overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .sheet-backdrop { position: fixed; inset: 0; z-index: 45; background: var(--scrim); }
  .m-actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line);
  }
  .m-actions .btn { height: 44px; font-size: 15px; }
  body.sheet-open .m-actions { display: none; }

  /* Market picker as a bottom sheet. */
  .market-menu {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 47; width: auto; max-width: none;
    max-height: 80vh; display: flex; flex-direction: column; border-radius: 12px 12px 0 0;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .market-menu[hidden] { display: none; }
  .menu-list { max-height: none; flex: 1; min-height: 0; }
  body.menu-open::after { content: ''; position: fixed; inset: 0; z-index: 46; background: var(--scrim); }
  body.menu-open { overflow: hidden; }
  .menu-head, .menu-row { grid-template-columns: 1.3fr 1.1fr 0.8fr; padding: 10px 8px; }
  .menu-head span:nth-child(n+4), .menu-row span:nth-child(n+4) { display: none; }

  .modal { place-items: end center; padding: 0; }
  .modal-card { width: 100%; border-radius: 12px 12px 0 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* Position and order cards (phones). */
.cards { display: flex; flex-direction: column; }
.card { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.card-top { display: flex; align-items: baseline; gap: 8px; font-size: 13.5px; }
.card-coin { font-weight: 700; font-size: 15px; }
.card-pnl, .card-end { margin-left: auto; }
.card-pnl { font-weight: 600; font-size: 15px; }
.card-pnl small { font-size: 12px; font-weight: 500; }
.card-grid { margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; }
.card-grid dt { color: var(--muted); font-size: 11.5px; }
.card-grid dd { margin: 0; font-size: 13px; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card-actions .mini-btn { height: 36px; font-size: 13px; }


/* ======================= content pages ======================= */
.page { width: 100%; max-width: 1200px; margin: 0 auto; padding: 32px 24px 72px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-title { margin: 0; font-size: 30px; line-height: 1.1; font-weight: 700; font-stretch: 118%; letter-spacing: -0.01em; }
.lede { margin: 8px 0 0; color: var(--muted); font-size: 14.5px; max-width: 64ch; line-height: 1.55; }
.section-title { margin: 0 0 12px; font-size: 15px; font-weight: 650; font-stretch: 108%; }
.rule-top { border-top: 1px solid var(--line); padding-top: 22px; margin-top: 26px; }
.gate { padding: 56px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.gate .actions { display: flex; gap: 10px; }

/* affiliates, logged out */
.aff-promo { display: flex; flex-direction: column; gap: 28px; margin-top: 8px; }
.aff-promo .brass { color: var(--brass); }
.promo-hero { padding: 28px 0 4px; max-width: 760px; }
.promo-kicker { margin: 0 0 10px; font-size: 12px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brass); }
.promo-title { margin: 0; font-size: clamp(26px, 4.2vw, 40px); line-height: 1.08; font-weight: 750; font-stretch: 118%; letter-spacing: -0.015em; }
.promo-sub { margin: 14px 0 20px; font-size: 15.5px; line-height: 1.55; max-width: 62ch; }
.promo-hero .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.promo-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.promo-stats > div { padding: 18px 16px; display: flex; flex-direction: column; gap: 4px; border-left: 1px solid var(--line); }
.promo-stats > div:first-child { border-left: 0; padding-left: 0; }
.promo-stats b { font-size: 26px; font-weight: 750; font-stretch: 112%; font-variant-numeric: tabular-nums; }
.promo-stats span { font-size: 13px; color: var(--muted); }
.promo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.promo-grid article { padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.promo-grid h3 { margin: 0 0 8px; font-size: 15px; font-weight: 650; line-height: 1.3; }
.promo-grid p { margin: 0; font-size: 13.5px; line-height: 1.55; }
.promo-steps ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; counter-reset: step; }
.promo-steps li { counter-increment: step; display: flex; flex-direction: column; gap: 4px; padding-top: 12px; border-top: 2px solid var(--brass); font-size: 13.5px; line-height: 1.5; }
.promo-steps li b::before { content: counter(step) '. '; color: var(--brass); }
.aff-promo .gate { border-top: 1px solid var(--line); padding: 40px 16px 56px; }
@media (max-width: 900px) {
  .promo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .promo-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .promo-stats > div { padding: 14px 12px; }
  .promo-stats > div:nth-child(odd) { border-left: 0; padding-left: 0; }
  .promo-stats > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .promo-stats b { font-size: 22px; }
  .promo-grid, .promo-steps ol { grid-template-columns: 1fr; }
}

/* dashboard */
.dash { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 32px; align-items: start; }
.acct-list { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.acct-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; border-left: 2px solid transparent; }
.acct-item:hover { background: var(--panel); }
.acct-item.current { background: var(--panel); border-left-color: var(--brass); }
.acct-item .nm { font-weight: 600; }
.acct-item .st { font-size: 12px; }
.acct-item .eq { text-align: right; font-stretch: 87.5%; font-variant-numeric: tabular-nums; }
.acct-item .sub { color: var(--muted); font-size: 12px; }
.state-active { color: var(--up); }
.state-failed { color: var(--down); }
.state-passed { color: var(--brass); }
.state-closed { color: var(--muted); }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.detail-head h2 { margin: 0; font-size: 22px; font-weight: 700; font-stretch: 112%; }
.figures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin-top: 22px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.figure { padding: 14px 16px 14px 0; }
.figure + .figure { padding-left: 16px; border-left: 1px solid var(--line); }
.figure .k { color: var(--muted); font-size: 12px; }
.figure .v { font-size: 22px; font-weight: 600; font-stretch: 87.5%; font-variant-numeric: tabular-nums; margin-top: 2px; }
.meters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px; margin-top: 22px; }
.meter .row { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.meter .bar { height: 6px; background: var(--panel-2); border-radius: 3px; margin: 8px 0 6px; overflow: hidden; }
.meter .bar i { display: block; height: 100%; border-radius: 3px; }
.meter .note { color: var(--muted); font-size: 12px; }
.equity-chart { height: 260px; margin-top: 8px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-stretch: 87.5%; font-variant-numeric: tabular-nums; }

/* challenges */
.products { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.product { padding: 18px 18px 20px; text-align: left; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.product:last-child { border-right: 0; }
.product:hover { background: var(--panel); }
.product.current { background: var(--panel); box-shadow: inset 0 3px 0 var(--brass); }
.product .nm { font-size: 16px; font-weight: 700; font-stretch: 110%; }
.product .from { color: var(--muted); font-size: 12.5px; }
.product .sm { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.buy { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 40px; margin-top: 28px; align-items: start; }
.sizes { display: flex; flex-wrap: wrap; gap: 6px; }
.size-btn { padding: 9px 14px; border-radius: var(--radius); background: var(--panel); font-weight: 600; font-stretch: 87.5%; font-variant-numeric: tabular-nums; font-size: 14px; }
.size-btn:hover { background: var(--panel-2); }
.size-btn.current { background: var(--brass); color: var(--brass-ink); }
.rules-tbl { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 13.5px; }
.rules-tbl td { padding: 10px 0; border-bottom: 1px solid var(--line); }
.rules-tbl td:last-child { text-align: right; font-stretch: 87.5%; font-variant-numeric: tabular-nums; }
.rules-tbl td:first-child { color: var(--muted); }
.checkout { background: var(--panel); border-radius: 6px; padding: 22px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 16px; }
.checkout .price { font-size: 40px; font-weight: 700; font-stretch: 87.5%; font-variant-numeric: tabular-nums; line-height: 1; }
.checkout .price small { font-size: 14px; color: var(--muted); font-weight: 400; font-stretch: 100%; }
.checkout .line { display: flex; justify-content: space-between; font-size: 13px; }
.trial-strip { margin-top: 36px; padding: 18px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }

/* rulebook */
.rb { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 48px; align-items: start; }
.toc { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.toc a { color: var(--muted); padding: 4px 0; }
.toc a:hover { color: var(--text); }
.rb-body { max-width: 760px; }
.rb-body section { padding-bottom: 8px; scroll-margin-top: 16px; }
.rb-body h2 { font-size: 19px; font-weight: 700; font-stretch: 110%; margin: 30px 0 10px; }
.rb-body h2:first-child { margin-top: 0; }
.rb-body p, .rb-body li { color: var(--text-soft); line-height: 1.65; font-size: 14px; }
.rb-body ul { padding-left: 18px; }
.rb-body .tbl { margin: 10px 0 6px; }
.rb-body .tbl td.txt, .rb-body .tbl th { text-align: left; }
.rb-body .tbl td.txt { white-space: normal; }
.rb-body { min-width: 0; }
.tbl-wrap { overflow-x: auto; }
.rb-version { color: var(--muted); font-size: 12.5px; margin-top: 6px; }

/* markets page */
.mkt-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.mkt-tools .input { max-width: 280px; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th.sorted { color: var(--text); }
.tbl tr.link { cursor: pointer; }
.mkt-count { color: var(--muted); font-size: 12.5px; margin-left: auto; }

@media (max-width: 900px) {
  .dash, .buy, .rb, .two-col { grid-template-columns: 1fr; }
  .products { grid-template-columns: 1fr 1fr; }
  .product:nth-child(2) { border-right: 0; }
  .product:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .figures { grid-template-columns: 1fr 1fr; }
  .figure:nth-child(3) { border-left: 0; padding-left: 0; }
  .meters { grid-template-columns: 1fr; gap: 18px; }
  .toc { position: static; flex-direction: row; flex-wrap: wrap; gap: 4px 14px; }
  .page { padding: 24px 16px 56px; }
  .page-title { font-size: 25px; }
}
@media (max-width: 520px) {
  .products { grid-template-columns: 1fr; }
  .product { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* TP / SL editor */
.tpsl-pos { display: flex; flex-direction: column; gap: 6px; padding: 12px; background: var(--panel-2); border-radius: var(--radius); font-size: 12.5px; }
.tpsl-est { font-size: 12px; min-height: 15px; color: var(--muted); }
.tpsl-btn { font: inherit; font-size: 12.5px; color: var(--text); background: none; padding: 2px 0; border-bottom: 1px dashed var(--line-2); cursor: pointer; white-space: nowrap; }
.tpsl-btn:hover { color: var(--accent); border-color: var(--accent); }
.tpsl-btn.add { color: var(--muted); }
#chart.line-hover canvas, #chart.line-drag canvas { cursor: ns-resize !important; }

/* ---- phone content pages ---- */
.m-buybar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line-2);
}
.m-buybar > div { display: flex; flex-direction: column; gap: 1px; }
.m-buybar b { font-size: 18px; }
.m-buybar .btn { height: 42px; padding: 0 22px; font-size: 14.5px; }
@media (max-width: 680px) {
  .page { padding: 22px 16px 96px; }
  .page-title { font-size: 26px; }
  .lede { font-size: 14px; }
  /* Challenges: compact 2x2 picker, summary of the chosen product underneath. */
  .products { grid-template-columns: 1fr 1fr !important; }
  .product { padding: 12px 14px !important; }
  .product .sm { display: none; }
  .p-summary { margin: 10px 2px 0; line-height: 1.5; }
  .sizes { display: grid !important; grid-template-columns: repeat(3, 1fr); }
  .size-btn { width: 100%; }
  /* Markets: the columns that matter on a phone. */
  #mkt th:nth-child(n+5), #mkt td:nth-child(n+5) { display: none; }
  #mkt th, #mkt td { padding-left: 8px; padding-right: 8px; }
  #mkt td.coin-cell .muted { display: none; }
  .mkt-tools { flex-wrap: wrap; }
  .mkt-tools #q { flex: 1 1 100%; max-width: none; }
  .product { border-bottom: 1px solid var(--line); }
}

/* ---- affiliates ---- */
.share { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto; gap: 28px; align-items: start; padding: 20px; background: var(--panel); border-radius: 6px; }
.share .k { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.code-row { display: flex; align-items: center; gap: 10px; }
.code { font-size: 26px; font-weight: 700; font-stretch: 112%; letter-spacing: 0.04em; }
.code-row .input { flex: 1; min-width: 0; background: var(--bg); }
.code-form { display: flex; gap: 8px; margin-top: 10px; }
.code-form .input { max-width: 200px; text-transform: uppercase; letter-spacing: 0.04em; background: var(--bg); }
.share-terms { display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; padding-top: 22px; white-space: nowrap; }
.share-terms b { font-size: 15px; }
.figures.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.figure .sub { font-size: 11.5px; margin-top: 2px; }
.section-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.section-row .section-title { margin: 0; }
.bars { display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 3px; height: 120px; align-items: end; border-bottom: 1px solid var(--line); }
.bar-col { height: 100%; display: flex; align-items: flex-end; }
.bar-col i { display: block; width: 100%; min-height: 2px; background: var(--brass); border-radius: 2px 2px 0 0; opacity: 0.85; }
.bar-col:hover i { opacity: 1; }
.bars-axis { display: flex; justify-content: space-between; margin-top: 6px; }
.price-was { color: var(--muted); text-decoration: line-through; font-size: 18px; font-weight: 500; margin-left: 6px; }
.ref-row { display: flex; gap: 8px; }
.ref-row .input { flex: 1; text-transform: uppercase; letter-spacing: 0.03em; }
.ref-note { margin: 0; font-size: 12.5px; }
.ref-note.ok { color: var(--up); }
.ref-note.err { color: var(--down); }
@media (max-width: 900px) {
  .share { grid-template-columns: 1fr; gap: 18px; }
  .share-terms { padding-top: 0; white-space: normal; }
  .figures.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .figures.six .figure:nth-child(4) { border-left: 0; padding-left: 0; }
  .figures.six .figure:nth-child(n+4) { border-top: 1px solid var(--line); }
}
@media (max-width: 520px) {
  .figures.six { grid-template-columns: 1fr 1fr; }
  .figures.six .figure { border-left: 0 !important; padding-left: 0 !important; }
  .figures.six .figure:nth-child(even) { padding-left: 16px !important; border-left: 1px solid var(--line) !important; }
  .figures.six .figure:nth-child(n+3) { border-top: 1px solid var(--line); }
  .bars { gap: 2px; height: 90px; }
}

/* ---- commission wallet ---- */
.wallet { margin-top: 28px; }
.wallet .figures { margin-top: 0; }
.sub-title { font-size: 13.5px; font-weight: 650; margin: 22px 0 8px; }
.w-ledger { margin-top: 18px; }
.w-ledger summary { cursor: pointer; color: var(--muted); font-weight: 500; padding: 6px 0; }
.w-ledger summary:hover { color: var(--text); }
.status { font-weight: 600; }
.status.pending, .status.approved { color: var(--warn); }
.status.paid { color: var(--up); }
.status.rejected, .status.cancelled { color: var(--muted); }
.addr { font-family: var(--font); font-stretch: 87.5%; }
select.input { appearance: auto; }
.adm-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.adm-actions .input { height: 30px; width: 200px; font-size: 12.5px; }
@media (max-width: 680px) { .adm-actions .input { font-size: 16px; } }

/* ---- trader payouts ---- */
.status.review { color: var(--down); }
.payout-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.payout-head .section-title { margin: 0; }
.payout .figures { margin-top: 14px; }
.figure .sub { font-size: 12px; margin-top: 2px; }
.checklist { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.checklist li { display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: start; }
.checklist .mark { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; margin-top: 1px; }
.checklist .ok .mark { background: var(--up-bg); color: var(--up); }
.checklist .no .mark { background: var(--down-bg); color: var(--down); }
.checklist .detail { display: block; color: var(--muted); font-size: 12.5px; }
.flag-list { margin: 4px 0 0; padding-left: 16px; font-size: 12px; color: var(--down); text-align: left; white-space: normal; }
.flag-list span { color: var(--muted); }

/* ---- multi-challenge order ---- */
.qty-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; background: var(--bg); }
.stepper button { width: 34px; height: 34px; font-size: 16px; color: var(--text); }
.stepper button:hover { background: var(--panel-2); }
.stepper button:disabled { color: var(--faint); cursor: not-allowed; background: none; }
.stepper input { width: 44px; border: 0; border-left: 1px solid var(--line-2); border-right: 1px solid var(--line-2); text-align: center; background: transparent; color: var(--text); font: inherit; font-size: 14px; outline: none; }
.stepper.sm button { width: 28px; height: 28px; font-size: 14px; }
.stepper.sm input { width: 34px; font-size: 13px; }
.add-btn { height: 36px; box-shadow: inset 0 0 0 1px var(--line-2); color: var(--text); }
.order { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.order-head { display: flex; justify-content: space-between; align-items: center; }
.o-line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; font-size: 13px; }
.o-line .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.o-line .amt { min-width: 64px; text-align: right; }
.totals { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.total-line { font-size: 15px; font-weight: 650; }
.alloc { display: flex; flex-direction: column; gap: 6px; }
.alloc-bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; display: flex; }
.alloc-bar i { display: block; height: 100%; }
#a-used { background: var(--muted); }
#a-add { background: var(--brass); }
.alloc.over #a-add { background: var(--down); }
.alloc p { margin: 0; }
.alloc.over #a-note { color: var(--down); }

/* ---- account recovery and email ---- */
#auth-form[data-mode="signup"] .forgot-link { display: none; }
.narrow { max-width: 420px; margin: 6vh auto 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack .lede { margin: 0; }
.verify-bar { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 9px 16px; background: rgba(224, 164, 58, 0.14); border-bottom: 1px solid var(--line); font-size: 13px; }
.verify-bar .link-btn { font-size: 13px; }

/* ---- order status ---- */
.narrow.wide { max-width: 640px; }
.o-status { display: flex; gap: 14px; align-items: flex-start; }
.o-dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 12px; flex-shrink: 0; background: var(--warn); }
.o-dot.wait { animation: o-pulse 1.4s ease-in-out infinite; }
.o-dot.ok { background: var(--up); }
.o-dot.bad { background: var(--down); }
@keyframes o-pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .o-dot.wait { animation: none; } }
.o-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.o-steps li { padding: 10px 0 0; border-top: 3px solid var(--line); color: var(--muted); font-size: 13px; }
.o-steps li.done { border-color: var(--up); color: var(--text); }
.o-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.o-actions:empty { display: none; }
.o-accounts { display: flex; flex-direction: column; }
.o-account { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }

/* Payout certificates on the dashboard */
.certs { margin-top: 40px; padding-top: 28px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 20px; }
.certs-head { display: flex; flex-wrap: wrap; gap: 20px 40px; justify-content: space-between; align-items: flex-end; }
.certs-head p { margin: 6px 0 0; max-width: 56ch; }
.name-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.name-form .field { min-width: 240px; }
.cert-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.cert-item { display: flex; flex-direction: column; gap: 12px; padding: 14px; background: var(--panel); border-radius: var(--radius); }
.cert-item img { width: 100%; height: auto; display: block; border-radius: 3px; border: 1px solid var(--line); }
.cert-meta { display: flex; flex-direction: column; gap: 2px; }
.cert-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cert-empty { margin: 0; }

/* Logo (public/logo.js): follows the theme */
.brand .logo { height: 26px; width: auto; display: block; }
.brand [data-logo] { display: block; }
.logo-tile { fill: var(--bg); stroke: var(--line-2); }
.logo-ink { fill: var(--text); }
.logo-d { fill: var(--brass); }
