:root {
  color-scheme: dark;
  --bg: #0b0e13;
  --surface: #10141a;
  --surface-2: #161b23;
  --surface-3: #1e2530;
  --line: #242c38;
  --line-strong: #344052;
  --text: #dbe2ec;
  --muted: #8a97a9;
  --faint: #626f81;
  --accent: #7aa7ff;
  /* Bid and ask pass the CVD check on --surface (protan 14, deutan 11, normal 28). */
  --bid: #17a596;
  --ask: #e8604f;
  --bid-text: #4fd1c0;
  --ask-text: #ff8a7a;
  --bid-wash: rgba(23, 165, 150, .16);
  --ask-wash: rgba(232, 96, 79, .16);
  /* Size bars in the ladder: strong enough to read at a glance, text stays legible. */
  --bid-bar: rgba(23, 165, 150, .30);
  --ask-bar: rgba(232, 96, 79, .30);
  --warn: #e0a93b;
  --warn-wash: rgba(224, 169, 59, .14);
  --bad: #ff6b6b;
  --good: #4fd1c0;
  --wall: #e0a93b;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
/* Any display rule below would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--sans);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 3px 9px;
  cursor: pointer;
}
button:hover { background: var(--line-strong); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: #2c4f8f; border-color: #3f6ab8; }
button.primary:hover { background: #3a62ad; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); }
button.link:hover { text-decoration: underline; background: none; }
input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 3px 7px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 14px; }
h3 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
code, .mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.grow { flex: 1; }
.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.bid-text { color: var(--bid-text); }
.ask-text { color: var(--ask-text); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.nowrap { white-space: nowrap; }

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); letter-spacing: -.01em; font-size: 15px; }
.brand:hover { text-decoration: none; }
nav { display: flex; gap: 4px; }
nav a { color: var(--muted); padding: 3px 9px; border-radius: 4px; }
nav a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
nav a.active { color: var(--text); background: var(--surface-3); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.good { color: var(--good); }
.pill.warn { color: var(--warn); background: var(--warn-wash); }
.pill.bad { color: var(--bad); background: rgba(255, 107, 107, .12); }

.banner {
  padding: 8px 14px;
  background: var(--warn-wash);
  border-bottom: 1px solid var(--warn);
  color: #f2d596;
}
.banner.bad { background: rgba(255, 107, 107, .12); border-color: var(--bad); color: #ffc2c2; }
.banner code { background: rgba(0, 0, 0, .3); padding: 1px 4px; border-radius: 3px; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page { padding: 14px; max-width: 1180px; width: 100%; margin: 0 auto; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.card > header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
.empty { padding: 28px 14px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 14px; }
.error { color: var(--bad); }

table { border-collapse: collapse; width: 100%; }
th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 11px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
th.num { text-align: right; font-family: inherit; }
td { padding: 4px 8px; border-bottom: 1px solid rgba(36, 44, 56, .6); }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }

/* Search */
.search-box { display: flex; gap: 8px; margin-bottom: 12px; }
.search-box input { flex: 1; padding: 8px 11px; font-size: 15px; }
.search-box select { padding: 8px; }
.token-logo {
  width: 18px; height: 18px; border-radius: 50%; object-fit: cover; flex: none;
  background: var(--surface-3); display: inline-block; vertical-align: middle;
}
.token-logo.big { width: 26px; height: 26px; }
.tag {
  display: inline-block;
  padding: 0 5px;
  border-radius: 3px;
  font-size: 10px;
  line-height: 15px;
  background: var(--surface-3);
  color: var(--muted);
  white-space: nowrap;
}
.tag.good { color: var(--good); background: var(--bid-wash); }
.tag.warn { color: var(--warn); background: var(--warn-wash); }
.tag.bad { color: var(--bad); background: rgba(255, 107, 107, .12); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 1px 9px;
}
.copy { background: none; border: 0; padding: 0 2px; color: var(--faint); cursor: pointer; font-size: 11px; }
.copy:hover { color: var(--text); background: none; }

/* Book layout */
.book-page { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 8px 10px 10px; gap: 8px; }
.book-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.book-title { display: flex; align-items: center; gap: 8px; }
.stats { display: flex; gap: 16px; flex-wrap: wrap; margin-left: 8px; }
.stat { display: flex; flex-direction: column; line-height: 1.2; }
.stat label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat b { font: 500 13px var(--mono); }
button.refresh { align-self: center; min-width: 96px; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 3px 10px 4px;
  color: var(--muted);
}
.tab:hover { color: var(--text); background: none; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab small { color: var(--faint); margin-left: 3px; font-size: 10px; }
.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.controls label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; white-space: nowrap; }
.controls input[type="number"] { width: 76px; padding: 1px 5px; }
.controls select { padding: 1px 4px; }
.book-grid {
  display: grid;
  grid-template-columns: minmax(520px, 1.25fr) minmax(320px, 1fr) minmax(280px, .8fr);
  gap: 8px;
  flex: 1;
  min-height: 560px;
}
.col { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
.col > .card { display: flex; flex-direction: column; min-height: 0; }
.fill { flex: 1; }

/* Ladder */
.ladder { display: flex; flex-direction: column; flex: 1; min-height: 0; font: 12px/18px var(--mono); font-variant-numeric: tabular-nums; }
.ladder-head, .lvl {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr .9fr .9fr 1fr .9fr 28px 54px;
  column-gap: 6px;
  padding: 0 8px;
  align-items: center;
}
.ladder.usd-view .ladder-head, .ladder.usd-view .lvl { grid-template-columns: 1.15fr 1fr 1fr .95fr 1fr .95fr 28px 54px; }
.ladder.usd-view .q { display: none; }
.ladder-head { color: var(--muted); font: 500 11px/22px var(--sans); border-bottom: 1px solid var(--line); }
.ladder-head span, .lvl span { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ladder-head span:first-child, .lvl span:first-child { text-align: left; }
.side { flex: 1 1 0; overflow-y: auto; min-height: 0; }
.side.asks { display: flex; flex-direction: column-reverse; }
.side-inner { display: flex; flex-direction: column; }
.side.asks .side-inner { flex-direction: column-reverse; }
.lvl {
  position: relative;
  width: 100%;
  border: 0;
  border-radius: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}
.lvl > span { position: relative; z-index: 1; }
.lvl::before {
  content: "";
  position: absolute;
  top: 1px; bottom: 1px; right: 0;
  width: var(--w, 0%);
  background: var(--wash);
  border-radius: 2px 0 0 2px;
  transition: width .3s ease-out;
}
.lvl.ask { --wash: var(--ask-bar); }
.lvl.bid { --wash: var(--bid-bar); }
.lvl.ask .p { color: var(--ask-text); }
.lvl.bid .p { color: var(--bid-text); }
.lvl:hover { background: var(--surface-2); }
.lvl.selected { outline: 1px solid var(--accent); outline-offset: -1px; }
.lvl.wall { font-weight: 700; box-shadow: inset 3px 0 0 var(--wall); }
.lvl.wall .usd { color: var(--wall); }
.lvl.unfunded { background-image: repeating-linear-gradient(135deg, transparent 0 5px, rgba(138, 151, 169, .13) 5px 10px); color: var(--muted); }
.lvl.unfunded .p { opacity: .65; }
.lvl.flash { animation: flash .9s ease-out; }
@keyframes flash { from { background-color: rgba(122, 167, 255, .28); } to { background-color: transparent; } }
.lvl .marks { font-size: 9px; color: var(--muted); margin-left: 4px; letter-spacing: .02em; }
.midline {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 3px 8px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font: 500 12px var(--mono);
}

.chart-card canvas { display: block; width: 100%; height: 100%; }
.chart-wrap { position: relative; flex: 1; min-height: 150px; }
.legend { display: inline-flex; gap: 10px; color: var(--muted); font-size: 11px; margin-left: auto; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.legend i.line { height: 2px; vertical-align: 3px; width: 12px; border-radius: 1px; }
.tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 4px 7px;
  font-size: 11px;
  white-space: nowrap;
  z-index: 3;
}
.tip b { font: 600 12px var(--mono); }
.tip .key { display: inline-block; width: 10px; height: 2px; vertical-align: 3px; margin-right: 5px; }
.tip div { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }

/* Orders and feed */
.scroll { overflow: auto; flex: 1; min-height: 0; }
.orders td { font-size: 12px; vertical-align: top; }
.flag { display: inline-block; margin: 0 2px 2px 0; }
.feed { font-size: 12px; }
.feed-item {
  display: grid;
  grid-template-columns: 62px 1fr auto;
  gap: 2px 6px;
  padding: 4px 8px;
  border-bottom: 1px solid rgba(36, 44, 56, .6);
  align-items: baseline;
}
.feed-item.wall { box-shadow: inset 3px 0 0 var(--wall); background: var(--warn-wash); }
.feed-item .amount { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-item .when { color: var(--faint); font-size: 11px; white-space: nowrap; }
.feed-item .sub { grid-column: 2 / 4; color: var(--muted); font-size: 11px; display: flex; justify-content: space-between; gap: 6px; }
.kind { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.kind.fill, .kind.partial_fill { color: var(--good); }
.kind.cancel { color: var(--warn); }
.kind.expired, .kind.disappeared { color: var(--faint); }
.kind.new { color: var(--accent); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 10px; }
.form-grid .card { padding: 10px; }
.field { display: grid; grid-template-columns: 1fr 110px; gap: 8px; align-items: center; margin-top: 6px; }
.field input, .field select { width: 100%; }
.field small { display: block; color: var(--faint); font-size: 11px; }
.chain-row { padding: 6px 10px; border-bottom: 1px solid var(--line); }
.chain-row summary { cursor: pointer; display: flex; gap: 8px; align-items: center; }
.chain-row textarea { width: 100%; height: 84px; margin-top: 6px; font: 12px var(--mono); }
.notice { padding: 8px 10px; border-left: 3px solid var(--line-strong); background: var(--surface-2); margin: 8px 0; }
.notice.warn { border-color: var(--warn); }
.notice.bad { border-color: var(--bad); }
.meter { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

@media (max-width: 1180px) {
  /* One column: cards take their own height, and the page scrolls. */
  .book-page { flex: none; }
  .book-grid { display: flex; flex-direction: column; flex: none; min-height: 0; }
  .col { flex: none; }
  .col > .card { flex: none !important; }
  .ladder { height: 560px; flex: none; }
  .chart-wrap { flex: none; height: 220px; }
  .col .scroll { max-height: 420px; flex: none; }
}
@media (max-width: 640px) {
  .page, .book-page { padding: 8px; }
  .ladder-head, .lvl, .ladder.usd-view .ladder-head, .ladder.usd-view .lvl { grid-template-columns: 1.2fr 1fr 1fr 28px; }
  .ladder-head .opt, .lvl .opt { display: none; }
  .stats { margin-left: 0; }
  .book-title button { white-space: nowrap; }
  .search-box { flex-direction: column; }
  .top { flex-wrap: wrap; gap: 8px; }
}
