:root {
  /* surfaces: near-black with a faint cool tint */
  --bg: #08090b;
  --bg-2: #0c0d10;
  --panel: #101115;
  --panel-2: #14161a;
  --raised: #191b20;
  --hover: #20232a;
  --border: #1d2026;
  --border-2: #282c34;
  --line: rgba(255, 255, 255, 0.06);
  /* text */
  --text: #f3f3f4;
  --text-2: #bfc1c8;
  --muted: #8a8e98;
  --faint: #5b5f69;
  /* market colours */
  --bid: #3ecf8e;
  --bid-dim: rgba(62, 207, 142, 0.1);
  --bid-strong: rgba(62, 207, 142, 0.2);
  --ask: #f2667a;
  --ask-dim: rgba(242, 102, 122, 0.1);
  --ask-strong: rgba(242, 102, 122, 0.2);
  /* brand: a soft gold, used sparingly */
  --accent: #e3b261;
  --accent-dim: rgba(227, 178, 97, 0.12);
  --amber: #e9bf6a;
  --amber-dim: rgba(233, 191, 106, 0.11);
  --info: #8fb8ff;
  --info-dim: rgba(143, 184, 255, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.25);
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.003em;
}
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.pos-c { color: var(--bid); }
.neg-c { color: var(--ask); }
.bid-c { color: var(--bid); }
.ask-c { color: var(--ask); }

/* ---------- Inputs & buttons ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label {
  font-size: 12px; font-weight: 500; letter-spacing: 0; color: var(--muted);
}
.input, input:not([type]), input[type="text"], input[type="number"], input[type="password"], input[type="email"], input[type="search"], textarea, select {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  width: 100%;
  min-width: 0;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input[type="number"] { font-family: var(--mono); font-variant-numeric: tabular-nums; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input:focus, textarea:focus, select:focus { border-color: #4a4f5a; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06); }
input:hover:not(:focus), textarea:hover:not(:focus), select:hover:not(:focus) { border-color: #333842; }
input.bid-in:focus { border-color: var(--bid); box-shadow: 0 0 0 3px var(--bid-dim); }
input.ask-in:focus { border-color: var(--ask); box-shadow: 0 0 0 3px var(--ask-dim); }
textarea { resize: vertical; min-height: 60px; }
input::placeholder, textarea::placeholder { color: var(--faint); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--border-2);
  background: var(--raised);
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s, opacity 0.15s;
  user-select: none;
  color: var(--text);
}
a.btn { text-decoration: none; }
.btn:hover { background: var(--hover); border-color: #343842; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn .ic { flex: none; }
/* primary: quiet white, the premium default */
.btn.primary { background: #f3f3f4; border-color: #f3f3f4; color: #0a0b0d; font-weight: 600; }
.btn.primary:hover { background: #ffffff; border-color: #ffffff; }
.btn.gold { background: var(--accent); border-color: var(--accent); color: #1b1408; font-weight: 600; }
.btn.gold:hover { background: #ecbf73; border-color: #ecbf73; }
.btn.buy { background: #1f9d68; border-color: #1f9d68; color: #fff; font-weight: 600; }
.btn.buy:hover { background: #26b276; border-color: #26b276; }
.btn.sell { background: #d0465b; border-color: #d0465b; color: #fff; font-weight: 600; }
.btn.sell:hover { background: #e05367; border-color: #e05367; }
.btn.buy:disabled, .btn.sell:disabled, .btn.primary:disabled { box-shadow: none; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--raised); color: var(--text); }
.btn.outline-bid { background: var(--bid-dim); border-color: rgba(62,207,142,.3); color: var(--bid); }
.btn.outline-bid:hover { background: var(--bid-strong); }
.btn.outline-ask { background: var(--ask-dim); border-color: rgba(242,102,122,.3); color: var(--ask); }
.btn.outline-ask:hover { background: var(--ask-strong); }
.btn.danger { color: var(--ask); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.lg { padding: 12px 20px; font-size: 15px; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--raised); color: var(--text); border-color: var(--border-2); }
.icon-btn.x:hover { color: var(--ask); }

/* stepper input: [-][input][+] */
.stepper { display: flex; align-items: stretch; }
.stepper input { border-radius: 0; text-align: center; border-left: 0; border-right: 0; }
.stepper button {
  width: 34px; flex: none; background: var(--raised); border: 1px solid var(--border-2); color: var(--text-2);
  cursor: pointer; font-size: 16px; line-height: 1;
}
.stepper button:hover { background: var(--hover); color: var(--text); }
.stepper button:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.stepper button:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.stepper:focus-within button { border-color: #4a4f5a; }
.stepper.bid:focus-within button { border-color: var(--bid); }
.stepper.ask:focus-within button { border-color: var(--ask); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; letter-spacing: 0;
  background: var(--raised); color: var(--text-2); border: 1px solid var(--border-2);
}
.chip.live { background: var(--bid-dim); color: var(--bid); border-color: rgba(62,207,142,.28); }
.chip.live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--bid); animation: pulse 1.6s infinite; }
.chip.closed { background: var(--amber-dim); color: var(--amber); border-color: rgba(233,191,106,.28); }
.chip.settled { background: var(--raised); color: var(--text-2); border-color: var(--border-2); }
.chip.pending { color: var(--muted); }
.chip.pro { background: var(--accent-dim); color: var(--accent); border-color: rgba(227,178,97,.3); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; flex: none; }
.dot.on { background: var(--bid); box-shadow: 0 0 0 3px var(--bid-dim); }

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.025) inset;
  min-width: 0;
  display: flex; flex-direction: column;
}
.panel-h {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--text-2);
  min-height: 44px;
}
.panel-h .sub { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); font-size: 12.5px; }
.panel-b { padding: 16px; }
.empty { padding: 26px 16px; text-align: center; color: var(--faint); font-size: 13px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 18px;
  border-bottom: 1px solid var(--border); background: var(--bg-2);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; display: inline-grid; place-items: center; flex: none;
  background: linear-gradient(180deg, #23262d, #15171b); border: 1px solid #2e323a;
  color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.06) inset;
}
.brand-mark svg { width: 16px; height: 16px; }
.brand-mark svg path:nth-child(-n+2) { stroke: var(--accent); }
.topbar .spacer { flex: 1; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.code-badge {
  font-family: var(--mono); font-weight: 600; letter-spacing: 0.14em; padding: 4px 10px; font-size: 13px;
  border-radius: 7px; background: var(--raised); border: 1px solid var(--border-2);
}

/* ---------- Timer ---------- */
.timer {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 8px; border-radius: 999px;
  background: var(--raised); border: 1px solid var(--border-2); font-family: var(--mono); font-weight: 600;
  font-size: 18px; font-variant-numeric: tabular-nums;
}
.timer svg { width: 26px; height: 26px; transform: rotate(-90deg); }
.timer .track { stroke: var(--border-2); }
.timer .prog { stroke: var(--bid); transition: stroke-dashoffset .25s linear, stroke .3s; }
.timer.warn { color: var(--amber); } .timer.warn .prog { stroke: var(--amber); }
.timer.crit { color: var(--ask); animation: pulse 1s infinite; } .timer.crit .prog { stroke: var(--ask); }
.timer.done { color: var(--muted); }

/* ---------- Order book ladder ---------- */
.book { display: flex; flex-direction: column; flex: 1; min-height: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; }
.book-cols, .book-row {
  display: grid; grid-template-columns: 44px 1fr 74px 1fr 44px; align-items: center;
}
.book-cols { padding: 8px 10px; font-family: var(--sans); font-size: 11px; font-weight: 500; letter-spacing: .02em; color: var(--faint); border-bottom: 1px solid var(--border); }
.book-cols > div:nth-child(2) { text-align: right; padding-right: 10px; }
.book-cols > div:nth-child(3) { text-align: center; }
.book-cols > div:nth-child(4) { padding-left: 10px; }
.book-cols > div:last-child, .book-row > .mine-r { text-align: right; }
.book-side { overflow-y: auto; scrollbar-width: thin; flex: 1 1 0; min-height: 60px; }
.book-side.asks { display: flex; flex-direction: column; }
.book-side.asks .inner { margin-top: auto; }
.book-row { padding: 0 10px; height: 26px; position: relative; cursor: pointer; border-radius: 4px; }
.book-row:hover { background: rgba(255,255,255,.04); }
.book-row .bar { position: absolute; top: 3px; bottom: 3px; border-radius: 3px; pointer-events: none; }
.book-row.bidrow .bar { right: calc(50% + 37px); background: var(--bid-dim); }
.book-row.askrow .bar { left: calc(50% + 37px); background: var(--ask-dim); }
.book-row > div { position: relative; z-index: 1; }
.book-row .qty-l { text-align: right; padding-right: 10px; color: var(--bid); font-weight: 600; }
.book-row .qty-r { padding-left: 10px; color: var(--ask); font-weight: 600; }
.book-row .price { text-align: center; font-weight: 600; color: var(--text); border-radius: 5px; padding: 2px 0; }
.book-row.bidrow .price { background: var(--bid-dim); }
.book-row.askrow .price { background: var(--ask-dim); }
.book-row.best .price { outline: 1px solid currentColor; }
.book-row.bidrow.best .price { color: var(--bid); }
.book-row.askrow.best .price { color: var(--ask); }
.book-row .mine-l, .book-row .mine-r { font-size: 11px; color: var(--amber); font-weight: 600; }
.book-row .who { font-family: var(--sans); font-size: 10.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-row.flash { animation: rowflash .45s ease-out; }
@keyframes rowflash { from { background: rgba(255,255,255,.07) } to { background: transparent } }
.spread-row {
  display: flex; justify-content: center; align-items: center; gap: 14px; padding: 7px 10px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--bg-2);
  font-size: 12px; color: var(--muted); font-family: var(--sans);
}
.spread-row b { font-family: var(--mono); color: var(--text); font-weight: 600; }
.book-empty { padding: 14px; text-align: center; font-family: var(--sans); font-size: 12px; color: var(--faint); }

/* ---------- BBO tiles ---------- */
.bbo { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.bbo-tile {
  border-radius: var(--radius); padding: 12px 16px; border: 1px solid var(--border);
  background: var(--panel); position: relative; overflow: hidden; cursor: pointer;
  transition: border-color .15s;
}
.bbo-tile:hover { border-color: var(--border-2); }
.bbo-tile .lbl { font-size: 12px; font-weight: 500; letter-spacing: 0; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.bbo-tile .px { font-family: var(--mono); font-size: 34px; font-weight: 600; line-height: 1.15; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.bbo-tile .sz { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.bbo-tile.bid .px { color: var(--bid); }
.bbo-tile.ask .px { color: var(--ask); }
.bbo-tile.bid { background: linear-gradient(180deg, var(--bid-dim), transparent 70%), var(--panel); }
.bbo-tile.ask { background: linear-gradient(180deg, var(--ask-dim), transparent 70%), var(--panel); }
.bbo-tile.up { animation: flashUp .7s ease-out; }
.bbo-tile.down { animation: flashDown .7s ease-out; }
@keyframes flashUp { from { box-shadow: inset 0 0 0 1px var(--bid), 0 0 0 3px var(--bid-dim) } to { box-shadow: none } }
@keyframes flashDown { from { box-shadow: inset 0 0 0 1px var(--ask), 0 0 0 3px var(--ask-dim) } to { box-shadow: none } }
.bbo-mid {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border);
  min-width: 108px; text-align: center;
}
.bbo-mid .k { font-size: 11px; font-weight: 500; color: var(--faint); }
.bbo-mid .v { font-family: var(--mono); font-weight: 600; font-size: 15px; }

/* ---------- Chart ---------- */
.chart-wrap { position: relative; flex: 1; min-height: 220px; }
.chart-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.chart-legend { display: flex; gap: 12px; font-size: 11px; color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }
.chart-legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* ---------- Tables (tape, orders, leaderboard) ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  position: sticky; top: 0; background: var(--panel); z-index: 1;
  text-align: left; font-size: 11.5px; font-weight: 500; letter-spacing: 0;
  color: var(--faint); padding: 9px 12px; border-bottom: 1px solid var(--border);
}
.tbl td { padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.lb-note { margin: 0; padding: 10px 14px 12px; font-size: 12.5px; color: var(--faint); line-height: 1.5; }
.tbl td.num, .tbl th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.tbl tr.mine td { background: rgba(233,191,106,.05); }
.tbl tr.mine td:first-child { box-shadow: inset 2px 0 0 var(--amber); }
.tbl tr.new td { animation: rowflash .8s ease-out; }
.tbl .who { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.scroll { overflow: auto; scrollbar-width: thin; min-height: 0; }
.side-tag { font-weight: 600; font-size: 11px; letter-spacing: .04em; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  pointer-events: auto; max-width: 400px; padding: 11px 15px; border-radius: 10px;
  background: rgba(26, 28, 33, 0.96); border: 1px solid var(--border-2); box-shadow: 0 16px 40px rgba(0,0,0,.5);
  backdrop-filter: blur(8px);
  font-size: 13px; display: flex; gap: 10px; align-items: flex-start;
  animation: toastIn .18s ease-out;
}
.toast.err { border-color: rgba(242,102,122,.5); }
.toast.err::before { content: "!"; flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--ask); color: #fff; font-weight: 600; font-size: 12px; display: grid; place-items: center; }
.toast.buy { border-color: rgba(62,207,142,.5); }
.toast.sell { border-color: rgba(242,102,122,.5); }
.toast .tag { font-weight: 600; font-size: 11px; padding: 2px 6px; border-radius: 4px; }
.toast.buy .tag { background: var(--bid); color: #062115; }
.toast.sell .tag { background: var(--ask); color: #2a0910; }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .25s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(4,5,7,.7); backdrop-filter: blur(6px); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--border-2); border-radius: 16px; box-shadow: 0 40px 100px rgba(0,0,0,.6); }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.modal-b { padding: 20px; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

/* ---------- Center cards (join, lobby) ---------- */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 30px; box-shadow: 0 40px 100px rgba(0,0,0,.4); }
.card h1 { font-size: 26px; margin: 14px 0 4px; letter-spacing: -0.03em; font-weight: 600; }
.card p.lead { color: var(--muted); margin: 0 0 22px; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-family: var(--mono); font-size: 22px !important; text-align: center; font-weight: 600; padding: 12px !important; }
.err-text { color: var(--ask); font-size: 13px; min-height: 18px; }
.rules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.rules > div { background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; }
.rules .k { font-size: 11px; color: var(--faint); font-weight: 500; }
.rules .v { font-family: var(--mono); font-weight: 600; margin-top: 2px; }

kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border-radius: 4px; background: var(--raised); border: 1px solid var(--border-2); border-bottom-width: 2px; color: var(--text-2); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #262931; border-radius: 8px; }
::selection { background: rgba(227, 178, 97, 0.28); }

/* medals: small numbered discs instead of emoji */
.medal { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-size: 10.5px; font-weight: 600; font-family: var(--mono); vertical-align: -3px; margin-left: 4px; color: #0b0c0e; }
.medal.m1 { background: linear-gradient(180deg, #f0cf86, #c99a45); }
.medal.m2 { background: linear-gradient(180deg, #e3e5ea, #a9adb6); }
.medal.m3 { background: linear-gradient(180deg, #e2a77b, #a8693f); }
.ic { display: inline-block; vertical-align: -3px; flex: none; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- guided tour ---------- */
.tour-block { position: fixed; inset: 0; z-index: 90; }
.tour-spot { position: fixed; z-index: 91; border-radius: 12px; pointer-events: none; box-shadow: 0 0 0 9999px rgba(4, 5, 7, 0.74); outline: 1px solid rgba(227, 178, 97, 0.7); transition: left .25s ease, top .25s ease, width .25s ease, height .25s ease; }
.tour-card { position: fixed; z-index: 92; background: var(--panel); border: 1px solid var(--border-2); border-radius: 14px; padding: 18px 18px 14px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); transition: left .25s ease, top .25s ease; }
.tour-n { font-family: var(--mono); font-size: 11.5px; color: var(--accent); }
.tour-t { font-weight: 600; font-size: 16px; letter-spacing: -0.015em; margin: 6px 0 6px; }
.tour-x { color: var(--text-2); font-size: 14px; line-height: 1.55; }
.tour-x b { color: var(--text); font-weight: 600; }
.tour-b { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.tour-skip { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; padding: 0; }
.tour-skip:hover { color: var(--text); }
