/* Cup trader. Phone first, desk second.

   The tokens are the board's, so the two apps read as one product. Anything
   that sends an order is green for a bid, red for an offer, and is never the
   same weight as a control that only reads. */

:root {
  color-scheme: dark;
  --paper: #0B0E13;
  --surface: #13171E;
  --surface-2: #1A1F28;
  --sunk: #1D242E;
  --ink: #E6EBF2;
  --muted: #8A94A6;
  --faint: #5A6472;
  --line: #252E3A;
  --line-2: #33404F;
  --dem: #4E8EE0;
  --rep: #E06050;
  --ok: #4CC88A;
  --warn: #E0A040;
  --bid: #4CC88A;
  --ask: #E06050;
  --live: #4CC88A;
  --f-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Source Sans 3", "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --tap: 44px;
  --r: 10px;
  --gut: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--f-body);
  overflow-wrap: break-word;
}

:focus-visible {
  outline: 2px solid var(--dem);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.bad { color: var(--rep); }
.good { color: var(--ok); }
.bid-ink { color: var(--bid); }
.ask-ink { color: var(--ask); }

/* ---- Header ------------------------------------------------------------ */

header.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(11, 14, 19, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.top-in {
  max-width: 1180px; margin: 0 auto;
  padding: 10px var(--gut);
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center;
}

.brand { margin-right: auto; display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font: 700 17px var(--f-display); letter-spacing: .01em; }
.brand .who { color: var(--muted); font: 500 12px var(--f-mono); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  font: 600 10px var(--f-display);
  letter-spacing: .09em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px;
  border: 1px solid var(--line-2); color: var(--muted);
  white-space: nowrap;
}
.badge.dry { border-color: #3C5A86; background: rgba(78, 142, 224, .14); color: #A9C8F2; }
.badge.live { border-color: #7A3630; background: rgba(224, 96, 80, .16); color: #F2B3A9; }
.badge.risk { border-color: #7A5A20; background: rgba(224, 160, 64, .16); color: #F0D2A0; }
a.badge.board { text-decoration: none; color: inherit; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); display: inline-block; }
.badge.link.up .dot { background: var(--live); }
.badge.link.down .dot { background: var(--rep); }

/* ---- Rail: cash and the clock ----------------------------------------- */

.rail {
  max-width: 1180px; margin: 0 auto;
  padding: 0 var(--gut) 10px;
  display: flex; flex-wrap: wrap; gap: 6px 22px; align-items: baseline;
}
.rail .cash { font: 600 22px var(--f-mono); font-variant-numeric: tabular-nums; }
.rail .cash small {
  font: 600 11px var(--f-display); color: var(--muted);
  letter-spacing: .08em; text-transform: uppercase; display: block;
}
.rail .clock { color: var(--muted); font: 500 12px var(--f-mono); margin-left: auto; text-align: right; }

/* ---- The arm switch ---------------------------------------------------- */

.arm-wrap { max-width: 1180px; margin: 0 auto; padding: 0 var(--gut) 12px; }

button.arm {
  width: 100%; min-height: 58px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink);
  text-align: left; transition: background .12s, border-color .12s;
}
button.arm .state { font: 700 16px var(--f-display); letter-spacing: .02em; }
button.arm .hint { font: 500 12px var(--f-mono); color: var(--muted); }
button.arm .pill {
  font: 700 11px var(--f-display); letter-spacing: .1em; text-transform: uppercase;
  border: 1px solid currentColor; border-radius: 999px; padding: 5px 11px; white-space: nowrap;
}
button.arm[aria-pressed="true"] {
  background: linear-gradient(180deg, rgba(76, 200, 138, .18), rgba(76, 200, 138, .08));
  border-color: #2F7A54;
}
button.arm[aria-pressed="true"] .state { color: var(--ok); }
button.arm[aria-pressed="true"] .pill { color: var(--ok); }
button.arm[aria-pressed="false"] .pill { color: var(--muted); }
button.arm:hover { border-color: var(--ink); }

/* ---- Layout ------------------------------------------------------------ */

main { max-width: 1180px; margin: 0 auto; padding: 16px var(--gut) 96px; }

.tabs {
  display: flex; gap: 8px; padding: 12px var(--gut) 0; flex-wrap: wrap;
}
.tabs button { min-height: 36px; }
.tabs button[aria-pressed="true"] {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
}
.lede { color: var(--muted); font-size: 14px; max-width: 70ch; margin-bottom: 14px; }
.race-split { display: grid; grid-template-columns: minmax(180px, 280px) 1fr; gap: 16px; align-items: start; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px;
}
.card .lb { font: 600 11px var(--f-display); letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.card .nm { font: 600 22px var(--f-mono); margin: 4px 0; }
.card .hint { color: var(--muted); font-size: 13px; }
.card input { width: 100%; margin-top: 8px; }
.race-row { width: 100%; text-align: left; margin-bottom: 6px; }
.race-row[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
@media (max-width: 800px) {
  .race-split { grid-template-columns: 1fr; }
}
.lede code, code {
  font: 500 12px var(--f-mono); color: var(--ink);
  background: var(--sunk); border-radius: 4px; padding: 1px 5px;
}

h2.head {
  font: 700 14px var(--f-display); letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); margin: 22px 0 10px;
}
h2.head:first-child { margin-top: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 8px; }
.filters .grow { flex: 1; min-width: 200px; }
.filters button[aria-pressed="true"] { background: var(--line-2); color: var(--ink); border-color: var(--ink); }

.empty {
  border: 1px dashed var(--line-2); border-radius: var(--r);
  padding: 28px 20px; text-align: center; color: var(--muted); font-size: 14px;
}

.acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---- Buttons ----------------------------------------------------------- */

button {
  font: 600 13px var(--f-display); letter-spacing: .02em;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: var(--sunk); color: var(--ink); cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
button:hover:not(:disabled) { border-color: var(--ink); }
button:disabled { opacity: .45; cursor: default; }
button.wide { width: 100%; }
button.tall { min-height: var(--tap); }
button.send { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.quiet { background: none; color: var(--muted); border-color: transparent; }
button.quiet:hover:not(:disabled) { color: var(--ink); border-color: var(--line-2); }
button.danger { color: #F2B3A9; border-color: #7A3630; background: rgba(224, 96, 80, .1); }
button.danger:hover:not(:disabled) { background: rgba(224, 96, 80, .2); border-color: var(--rep); }
button[aria-busy="true"] { position: relative; color: transparent !important; }
button[aria-busy="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: var(--ink); animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  button[aria-busy="true"]::after { animation: none; }
  * { transition: none !important; }
}

/* ---- Forms ------------------------------------------------------------- */

label.f {
  display: flex; flex-direction: column; gap: 5px;
  font: 600 11px var(--f-display); letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
label.f input, label.f select {
  background: var(--sunk); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 8px;
  padding: 0 11px; min-height: var(--tap);
  font: 500 15px var(--f-mono); width: 100%;
}

.switch {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  padding: .3rem .6rem; border: 1px solid var(--line); border-radius: 1rem;
  font-size: .8rem; background: none; color: inherit; min-height: 34px;
}
.switch[aria-pressed="true"] { border-color: #8bd17c; }
.switch i {
  width: .55rem; height: .55rem; border-radius: 50%;
  background: var(--line); display: block;
}
.switch[aria-pressed="true"] i { background: #8bd17c; }

/* ---- Tables ------------------------------------------------------------ */

.scroll { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 9px 11px; border-bottom: 1px solid var(--line); text-align: right;
  font: 500 12px var(--f-mono); font-variant-numeric: tabular-nums; white-space: nowrap;
}
th { color: var(--muted); font: 600 11px var(--f-display); letter-spacing: .04em; position: sticky; top: 0; background: var(--surface); }
tbody tr:last-child td { border-bottom: 0; }
th.left, td.left { text-align: left; }
td.wrap { white-space: normal; min-width: 200px; font: 400 13px/1.45 var(--f-body); color: var(--muted); }
tbody tr:hover td { background: #171C24; }
td .tag { border: 1px solid var(--line-2); border-radius: 4px; padding: 1px 5px; font-size: 11px; }
td .tag.mine { border-color: #2F5C86; color: #9FC4EE; }

td input[type="number"], td select {
  background: var(--sunk); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 8px;
  padding: 0 8px; min-height: 34px;
  font: 500 13px var(--f-mono); font-variant-numeric: tabular-nums;
}
td input[type="number"] { width: 5.2rem; text-align: right; }
td select { width: 5.2rem; }
td .row-acts { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
td .row-acts button { min-height: 34px; padding: 0 10px; }

/* ---- Toasts ------------------------------------------------------------ */

#toasts {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom));
  width: min(560px, calc(100vw - 24px));
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-left: 3px solid var(--muted); border-radius: 8px;
  padding: 11px 12px; display: flex; gap: 10px; align-items: flex-start;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .6); font-size: 14px;
}
.toast.bad { border-left-color: var(--rep); }
.toast.good { border-left-color: var(--ok); }
.toast .msg { flex: 1; min-width: 0; }
.toast button { min-height: 26px; padding: 0 8px; border: 0; background: none; color: var(--muted); font-size: 16px; }

/* ---- Confirm ----------------------------------------------------------- */

#modal {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(4, 6, 10, .7); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#modal .box {
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 12px; padding: 20px; width: min(440px, 100%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .7);
}
#modal h3 { font: 700 17px var(--f-display); margin-bottom: 9px; }
#modal p { color: var(--muted); font-size: 14px; line-height: 1.5; }
#modal .row { display: flex; gap: 9px; margin-top: 18px; }
#modal .row button { flex: 1; min-height: var(--tap); }

/* ---- Login ------------------------------------------------------------- */

/* Sign-in opens over the desk: reading needs no password, trading does. */
#login {
  position: fixed; inset: 0; z-index: 40; overflow: auto;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  padding: 14vh var(--gut) var(--gut);
}
#login > * { max-width: 380px; margin-left: auto; margin-right: auto; }
#login-cancel { margin-top: 12px; }
.portal { display: flex; gap: 6px; flex-wrap: wrap; }
/* A reader sees the controls; pressing one asks for the password. */
body.reader .arm-wrap .pill::after { content: " F512"; }
#login h1 { font: 700 26px var(--f-display); margin-bottom: 6px; }
#login p.sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
#login form { display: grid; gap: 12px; }
#login .err { color: var(--rep); font: 500 13px var(--f-mono); min-height: 20px; }

/* ---- Model weights and caps -------------------------------------------- */

.dials { display: grid; gap: 8px; margin: 8px 0 4px; }
.dial {
  display: grid; gap: 4px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface);
}
.dial .top { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; }
.dial .lb { font: 600 13px var(--f-display); color: var(--ink); text-transform: none; letter-spacing: 0; }
.dial .nm { font: 500 12px var(--f-mono); color: var(--faint); }
.dial .hint { font: 400 12px var(--f-body); color: var(--muted); }
.dial .ctl { display: grid; grid-template-columns: 1fr 5.2rem; gap: 10px; align-items: center; }
.dial input[type="range"] { width: 100%; accent-color: var(--dem); }
.dial input[type="number"] {
  background: var(--sunk); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 8px;
  padding: 0 8px; min-height: 34px;
  font: 500 13px var(--f-mono); font-variant-numeric: tabular-nums;
  width: 100%; text-align: right;
}
.dial.moved { border-color: var(--dem); }

@media (max-width: 640px) {
  .dial .ctl { grid-template-columns: 1fr; }
}

/* ---- External market links --------------------------------------------- */

a.ext-link {
  color: var(--muted); text-decoration: none; font-weight: 500;
  display: inline-block; padding: 0 2px;
}
a.ext-link:hover { color: var(--dem); text-decoration: underline; }

/* Order book: levels a take may reach, inside safety.max_take of the touch. */
td.in-band { background: var(--sunk); font-weight: 600; }
