:root {
  color-scheme: dark;
  --bg: #070b11;
  --card: #121922;
  --sunken: #0c1118;
  --line: #243041;
  --text: #f3f6fb;
  --muted: #8d9aab;
  --faint: #667588;
  --blue: #c5d4ff;
  --blue-ink: #1a2433;
  --green: #3dbe7a;
  --green-dim: #143528;
  --red: #e08a8a;
  --red-dim: #3a2428;
  --amber: #e2b340;
  --amber-bg: #1a1408;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

a { color: #9eb6ff; }
button, input, select { font: inherit; }
td, .price, .price-cell, .now { font-variant-numeric: tabular-nums; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  padding: 0.65rem 1.25rem;
  background: rgba(7, 11, 17, 0.94);
  border-bottom: 1px solid #1a2330;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-right: 0.75rem;
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
}

.mark {
  width: 1.7rem;
  height: 1.7rem;
  display: inline-grid;
  place-items: center;
  border-radius: 0.45rem;
  background: #1c2636;
  color: #9eb6ff;
}

.mark svg { width: 0.95rem; height: 0.95rem; fill: currentColor; }

.nav { display: flex; flex-wrap: wrap; gap: 0.15rem; min-width: 0; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
}
.nav a.on { background: #1c2633; color: var(--text); }
.nav a:hover { color: var(--text); }

.session {
  margin: 0 0.6rem 0 auto;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
}

.avatar {
  width: 1.45rem;
  height: 1.45rem;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: #243044;
  color: var(--text);
  font-size: 0.75rem;
}

.banner {
  margin: 0;
  padding: 0.38rem 1.4rem;
  background: var(--amber-bg);
  color: var(--amber);
  font-size: 0.82rem;
}

.dot {
  display: inline-block;
  width: 0.42rem;
  height: 0.42rem;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(226, 179, 64, 0.15);
}

.dot.live { background: var(--green); box-shadow: 0 0 0 3px rgba(61, 190, 122, 0.15); }

main {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.15rem 0 3rem;
  min-width: 0;
}

h1 { margin: 0; font-size: 1.7rem; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 0.98rem; }
.lead { color: var(--muted); margin: 0.35rem 0 1rem; }
.k { color: var(--faint); font-size: 0.75rem; margin: 0 0 0.2rem; }
.meta, .hint, .note, .card-note { color: var(--muted); font-size: 0.8rem; }
.card-note { font-weight: 400; margin: 0; max-width: 36rem; }
.error { color: #ffb4b4; }
.now { font-weight: 650; }

.page-head, .card-head, .sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-head { margin-bottom: 1rem; }
.back { margin: 0 0 0.45rem; }
.back a { color: var(--muted); text-decoration: none; }
.back a::before { content: "‹ "; }

.toolbar, .sheet, .card, .profile, .login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.toolbar { padding: 0.9rem 1rem 1rem; margin-bottom: 0.9rem; }
.switch-row { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: center; margin-bottom: 0.85rem; }
.tabs, .chips, .filters, .pager-links, .row-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }
.filters { align-items: end; }
.filters .hint { margin: 0 0 0.45rem auto; }

.tab, .chip, button, .btn, .dead {
  border: 1px solid var(--line);
  background: #1a2330;
  color: var(--text);
  border-radius: 10px;
  padding: 0.42rem 0.85rem;
  text-decoration: none;
  cursor: pointer;
}

.tab, .chip { border-radius: 999px; }
.tab.active { background: #1c6b45; border-color: #1c6b45; color: white; }
.chip.active { background: #243044; border-color: #3a4c63; color: white; }
button.primary, .login-card button {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--blue-ink);
  font-weight: 650;
}
button.danger { background: var(--red-dim); border-color: #6e3a42; color: #f0b4b4; }
.dead { color: var(--faint); }

label { display: grid; gap: 0.28rem; color: var(--muted); font-size: 0.78rem; min-width: 0; }
label input, label select, .input-unit input { width: 100%; min-width: 0; }
.grow { flex: 1; min-width: 10rem; }
.check { display: flex; flex-direction: row; align-items: center; gap: 0.4rem; color: var(--text); padding-bottom: 0.45rem; }
.check input { width: 1rem; height: 1rem; accent-color: #7ea2ff; }

input, select {
  background: var(--sunken);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}

.input-unit {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding-right: 0.7rem;
}
.input-unit input { border: 0; background: transparent; width: 100%; min-width: 0; }
.input-unit span { color: var(--faint); }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

th, td { padding: 0.75rem 0.85rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--faint); font-weight: 600; font-size: 0.75rem; }
tr:last-child td { border-bottom: 0; }
.ad-row { cursor: pointer; }
.ad-row:hover td { background: #17202b; }
.ad-row.open td { border-bottom-color: transparent; background: #101820; }
.panel td { background: #101820; }
.muted { color: var(--muted); }
.nick { color: var(--text); font-weight: 650; text-decoration: none; }
.price-cell { font-weight: 650; }

.rank { white-space: nowrap; color: var(--muted); }
.chev {
  display: inline-block;
  width: 0.38rem;
  height: 0.38rem;
  margin-right: 0.55rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-0.1rem);
}
.ad-row.open .chev { transform: rotate(-135deg) translateY(-0.05rem); }

.tag, .pay, .side, .src, .history-source {
  display: inline-block;
  margin: 0.1rem 0.2rem 0.1rem 0;
  padding: 0.08rem 0.42rem;
  border-radius: 6px;
  background: #1c2633;
  color: #c5d0dc;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  vertical-align: middle;
}
.tag { background: #243654; color: #9eb6ff; text-transform: uppercase; }
.side.sell { background: var(--green-dim); color: #8ed7ae; }
.side.buy { background: var(--red-dim); color: var(--red); }
.src-walk .history-source, .src-walk .src { background: var(--green-dim); color: #8ed7ae; }
.src-api .history-source, .src-api .src { background: #243654; color: #9eb6ff; }
.src-control .history-source, .src-control .src { background: #2e2816; color: var(--amber); }
.src-sim .history-source, .src-sim .src { background: #2a2440; color: #c4b0f0; }

.state::before {
  content: "";
  display: inline-block;
  width: 0.42rem;
  height: 0.42rem;
  margin-right: 0.35rem;
  border-radius: 50%;
  background: currentColor;
}
.state.live { color: var(--green); }
.state.warn { color: var(--amber); }
.state.off { color: var(--muted); }
.kind { color: var(--faint); font-size: 0.75rem; }

.expand {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr auto;
  gap: 1.1rem;
  padding: 0.2rem 0.2rem 0.45rem;
}
.expand-actions { display: grid; gap: 0.45rem; align-content: start; }
.facts p { margin: 0.35rem 0; }
.trade {
  background: transparent;
  border: 1px solid #2f6b4f;
  color: #8ed7ae;
  width: auto;
  max-width: 100%;
  white-space: normal;
}
.expand-actions .trade { width: 100%; }
.trade.sell { border-color: #6b3838; color: var(--red); }
.trade:disabled { opacity: 1; cursor: not-allowed; }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; color: var(--muted); }

.sheet { padding: 0.95rem 1rem 1rem; margin-top: 0.9rem; }
.sheet.bare { padding: 0; overflow: hidden; }
.sheet table, .scroll table { border: 0; border-radius: 0; background: transparent; }
.scroll { width: 100%; max-width: 100%; overflow-x: auto; }
.scroll table { min-width: 760px; }
.sheet-head { margin-bottom: 0.7rem; }
.sheet-head a { text-decoration: none; }

.ad-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(260px, 0.85fr);
  gap: 0.9rem;
  align-items: start;
}
.ad-no { margin: 0; text-align: right; font-weight: 650; }
.price { margin: 0.1rem 0 0; font-size: 2.4rem; font-weight: 650; letter-spacing: -0.03em; }
.price span { font-size: 1rem; color: var(--muted); font-weight: 500; }
.price-block, .stat-grid, .terms-grid { display: flex; justify-content: space-between; gap: 1rem; }
.price-type { text-align: right; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem 1rem;
  margin: 0.9rem 0;
  padding: 0.9rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.terms-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 0.8rem; margin-top: 0.8rem; }
.reply { margin: 0; padding: 0.6rem 0.7rem; border: 1px solid var(--line); border-radius: 10px; }
.calc-card { display: grid; gap: 0.7rem; }
.rate { margin: 0; color: var(--muted); }

.profile {
  display: grid;
  grid-template-columns: 1.4fr repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  align-items: center;
  padding: 0.95rem 1.1rem;
  margin-bottom: 0.9rem;
}
.profile h2 { margin-bottom: 0.2rem; }
.profile p { margin: 0; }

.chart { width: 100%; height: 180px; display: block; }
.chart polyline { fill: none; stroke: #8eb4ff; stroke-width: 2; }
.chart .grid { stroke: #243041; stroke-width: 1; }

.console {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.9rem;
  align-items: start;
}
.stack { display: grid; gap: 0.9rem; min-width: 0; }
.card { padding: 0.9rem 1rem 1rem; }
.card.wide { grid-column: 1 / -1; }
.card form { margin-top: 0.7rem; }
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem 1rem;
  margin-top: 0.85rem;
}
.stats p { margin: 0; }
.split, .fields, .ref-row, .key-row, .comp {
  display: flex;
  gap: 0.55rem;
  align-items: end;
  flex-wrap: wrap;
}
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); align-items: end; }
.split > label, .ref-row > label { flex: 1; min-width: 8rem; }
.split pre, .split .meta { flex-basis: 100%; }
.key-row, .comp, .ref-row {
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  max-width: 100%;
}
.key-row { align-items: flex-start; }
.key-meta {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  max-width: 100%;
}
.key-meta form, .row-actions form { margin: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; min-width: 0; }
.key-meta pre { flex: 1 0 100%; margin-top: 0.35rem; }
.key-meta pre:empty { display: none; }
.comp { display: grid; grid-template-columns: minmax(0, 1fr); }
.comp form { margin: 0; }
.comp .row-actions { grid-column: 1 / -1; }
.walk-pair { padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.pair-name { margin: 0 0 0.4rem; font-weight: 650; }
.walk-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: end;
}
.walk-start, .walk-stop, .walk-step { display: contents; }
.f-step { order: 1; }
.f-interval { order: 2; }
.f-seed { order: 3; }
.f-steps { order: 4; }
.b-start { order: 5; }
.b-stop { order: 6; }
.b-advance { order: 7; }

pre, #request-log {
  margin: 0.65rem 0 0;
  padding: 0.55rem 0.7rem;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.75rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-width: 100%;
  min-height: 2.2rem;
}
#request-log:empty { min-height: 0; padding: 0; border: 0; }
.log-table { border: 0; background: transparent; }
#request-log td { border-bottom: 1px solid var(--line); padding: 0.38rem 0.35rem; }
#request-log td.ok { color: var(--green); }
#request-log td.bad { color: #e07070; }

.miss { max-width: 28rem; margin: 3rem auto; padding: 1.4rem; }
.status { color: #9eb6ff; font-size: 2rem; margin: 0; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 56px 56px;
}
.login-card { width: min(420px, calc(100% - 2rem)); padding: 1.5rem 1.45rem 1.2rem; }
.login-card h1 { font-size: 1.7rem; margin: 0.8rem 0 0.35rem; }
.login-card p { color: var(--muted); }
.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}
.login-card form { display: grid; gap: 0.8rem; margin-top: 1rem; }
.login-card .note { margin: 1rem 0 0; padding-top: 0.85rem; border-top: 1px solid var(--line); font-size: 0.8rem; }

.toolbar, .sheet, .card, .profile, .expand, .ad-layout, .price-block, .filters {
  min-width: 0;
  max-width: 100%;
}
.expand > *, .ad-layout > *, .profile > *, .stats > * { min-width: 0; }
.meta, .ad-no, td, .nick, code { overflow-wrap: anywhere; }
.card-head, .sheet-head, .page-head { align-items: flex-start; }
.card form, .ref-row, .split { min-width: 0; max-width: 100%; }
.walk-grid label, .walk-grid button { min-width: 0; }
.profile { grid-template-columns: minmax(0, 1.4fr) repeat(4, minmax(0, 1fr)); }
.doc-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; margin-top: 0.8rem; }
.doc-table { min-width: 640px; }
.sample { line-height: 1.55; }
code { font-size: 0.86em; }

@media (max-width: 980px) {
  .console, .ad-layout, .profile, .expand, .stat-grid, .terms-grid, .doc-grid { grid-template-columns: 1fr; }
  .price-type, .ad-no { text-align: left; }
  .session { margin-left: 0; }
}

@media (min-width: 720px) {
  .comp { grid-template-columns: minmax(0, 1fr) minmax(120px, 220px); }
}
