/* CryptoFreedom — trading terminal
 *
 * Design notes, so later edits keep the intent:
 *
 * - Ground is deep slate-blue ink, not black, with desaturated teal/clay for
 *   bid/ask. Screen-bright green-on-black is the reflex for trading UIs and it
 *   makes every venue look identical; muted complements let the one saturated
 *   thing on the page (the unit bar) actually read as the focus.
 * - EVERY number is tabular monospace. In a depth ladder, digits that do not
 *   align are a usability bug, not a style preference.
 * - System font stacks only. No web-font request: a third-party font call in a
 *   trading interface is one more origin that can see your session.
 * - The signature is the unit bar: a 0->1 track segmented by outcome price. The
 *   outcomes partition probability, so it fills to exactly 1.00 when priced and
 *   is visibly short when the book is one-sided. Nothing else on the page shouts.
 */

:root {
  --ground: #12161c;
  --panel: #1a2029;
  --panel-2: #212936;
  --rule: #2b3441;
  --ink: #e9ecf1;
  --muted: #8b96a5;
  --bid: #4db6a0;
  --ask: #d98a6a;
  --warn: #d9b96a;
  --danger: #d96a6a;

  --seg-0: #4db6a0;
  --seg-1: #6a92d9;
  --seg-2: #b78ad9;
  --seg-3: #d9b96a;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 6px;
  --gap: 1rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: #8fb4e8; text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: var(--mono); font-size: 0.9em; color: var(--muted); }

/* --- Chrome ------------------------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.85rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
}
.bar .spacer { flex: 1; }
.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-size: 1.05rem;
}
.bar nav { display: flex; gap: 1rem; }
.bar nav a { color: var(--muted); }
.bar nav a:hover { color: var(--ink); text-decoration: none; }
.balance { font-family: var(--mono); color: var(--bid); font-variant-numeric: tabular-nums; }
.who { color: var(--muted); }

.cta {
  background: var(--bid);
  color: #0d1418;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius);
  border: 0;
  font: 600 0.9rem var(--sans);
  cursor: pointer;
}
.cta:hover { filter: brightness(1.08); text-decoration: none; }

button.link {
  background: none;
  border: 0;
  color: #8fb4e8;
  cursor: pointer;
  font: inherit;
  padding: 0;
}
button.link:hover { text-decoration: underline; }

.inline { display: inline; }

main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

h1 { font-size: 1.5rem; letter-spacing: -0.02em; margin: 0 0 0.35rem; }
h2 { font-size: 1rem; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); margin: 0 0 0.75rem; }

.hint { color: var(--muted); font-size: 0.86rem; margin: 0.5rem 0 0; }
.slug { color: var(--muted); font-family: var(--mono); font-size: 0.8rem; margin-left: 0.5rem; }

footer {
  border-top: 1px solid var(--rule);
  padding: 1rem 1.25rem;
  color: var(--muted);
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

/* --- Notices ------------------------------------------------------------ */

.notice {
  padding: 0.6rem 1.25rem;
  font-size: 0.86rem;
  border-bottom: 1px solid var(--rule);
}
.notice.sandbox { background: #1b2430; color: var(--muted); }
.notice.warn { background: #2c2617; color: var(--warn); }
.notice.danger { background: #2e1c1c; color: var(--danger); }

/* --- Tables ------------------------------------------------------------- */

.grid { width: 100%; border-collapse: collapse; }
.grid th {
  text-align: left;
  font: 600 0.72rem var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
}
.grid td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--rule); }
.grid tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

.state {
  font: 600 0.68rem var(--mono);
  letter-spacing: 0.06em;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  border: 1px solid var(--rule);
  color: var(--muted);
}
.state-open { color: var(--bid); border-color: color-mix(in srgb, var(--bid) 40%, transparent); }
.state-halted, .state-closed { color: var(--warn); }
.state-resolved { color: #8fb4e8; }

/* --- The market head and the unit bar ----------------------------------- */

.market-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--gap);
  flex-wrap: wrap;
}
.sum { text-align: right; }
.sum-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.sum-value { font: 600 1.35rem var(--mono); font-variant-numeric: tabular-nums; }

/* The signature element. */
.unit-bar {
  display: flex;
  height: 2.75rem;
  margin: 1.1rem 0 0.4rem;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--rule);
}
.unit-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-width: 0;
  font: 600 0.78rem var(--mono);
  color: #0d1418;
  white-space: nowrap;
  overflow: hidden;
  transition: flex-basis 240ms ease;
}
.unit-seg.seg-0 { background: var(--seg-0); }
.unit-seg.seg-1 { background: var(--seg-1); }
.unit-seg.seg-2 { background: var(--seg-2); }
.unit-seg.seg-3 { background: var(--seg-3); }
.unit-seg .code { letter-spacing: 0.06em; }
/* The remainder is deliberately empty rather than shaded: an unpriced market
   should look unfinished, because it is. */
.unit-gap {
  flex: 1 1 auto;
  background: repeating-linear-gradient(
    135deg, transparent 0 6px, rgba(255, 255, 255, 0.04) 6px 12px
  );
}
.unit-scale {
  display: flex;
  justify-content: space-between;
  font: 0.7rem var(--mono);
  color: var(--muted);
  margin-bottom: 1.5rem;
}

/* --- Outcomes ----------------------------------------------------------- */

.outcomes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: var(--gap);
}
.outcome {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem;
}
.outcome.won { border-color: color-mix(in srgb, var(--bid) 55%, transparent); }
.outcome header { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.outcome h2 { color: var(--ink); text-transform: none; letter-spacing: -0.01em; font-size: 1.05rem; margin: 0; }
.mid-value { font: 600 1.15rem var(--mono); font-variant-numeric: tabular-nums; }
.badge {
  font: 600 0.68rem var(--mono);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  margin-left: 0.4rem;
}
.badge.win { background: var(--bid); color: #0d1418; }
.badge.lose { background: var(--panel-2); color: var(--muted); }
.position { color: var(--muted); font-size: 0.82rem; margin: 0.35rem 0 0.75rem; font-family: var(--mono); }

.ladder { width: 100%; border-collapse: collapse; margin: 0.5rem 0 1rem; }
.ladder th {
  font: 600 0.66rem var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-align: left;
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--rule);
}
.ladder td {
  padding: 0.22rem 0.4rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.ladder .bid, td.buy { color: var(--bid); }
.ladder .ask, td.sell { color: var(--ask); }

/* --- Order ticket ------------------------------------------------------- */

.ticket { border-top: 1px solid var(--rule); padding-top: 0.85rem; }
.ticket .row { display: flex; gap: 0.6rem; margin-bottom: 0.6rem; }
.ticket label, .auth label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  font: 0.72rem var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
input, select {
  background: var(--ground);
  border: 1px solid var(--rule);
  color: var(--ink);
  border-radius: 4px;
  padding: 0.45rem 0.55rem;
  font: 0.95rem var(--mono);
  font-variant-numeric: tabular-nums;
  width: 100%;
}
select { font-family: var(--sans); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid #8fb4e8;
  outline-offset: 2px;
}

.ticket .actions { gap: 0.6rem; }
.ticket button {
  flex: 1;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.5rem;
  font: 600 0.9rem var(--sans);
  cursor: pointer;
}
button.buy { background: var(--bid); color: #0d1418; }
button.sell { background: var(--ask); color: #1a0f0a; }
button.buy:hover, button.sell:hover { filter: brightness(1.08); }

.inline-form { display: flex; gap: 0.4rem; align-items: center; }
.inline-form input { width: 5.5rem; }
.inline-form button, .faucet button {
  background: var(--panel-2);
  border: 1px solid var(--rule);
  color: var(--ink);
  border-radius: 4px;
  padding: 0.45rem 0.7rem;
  font: 600 0.85rem var(--sans);
  cursor: pointer;
}
.inline-form button:hover { border-color: var(--muted); }

/* --- Panels ------------------------------------------------------------- */

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--gap); margin-top: var(--gap); }
.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: var(--gap);
}
.panels .panel { margin-top: 0; }
.panel .row { display: flex; gap: 1rem; flex-wrap: wrap; }

.faucet { display: flex; align-items: center; gap: 0.75rem; margin: 0.5rem 0 0; }
.faucet .hint { margin: 0; }

.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

.auth { max-width: 380px; margin: 2rem auto; }
.auth form { display: flex; flex-direction: column; gap: 0.85rem; margin-top: 1rem; }
.auth .cta { padding: 0.6rem; }

@media (max-width: 640px) {
  .bar { flex-wrap: wrap; gap: 0.75rem; }
  .unit-seg .code { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Said once, about the whole market, rather than repeated on every card. */
.rules {
  color: var(--muted);
  font-size: 0.86rem;
  max-width: 68ch;
  margin: 0 0 1.5rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--rule);
}

/* --- Charts -------------------------------------------------------------- */

.chart {
  height: 240px;
  margin: 0.5rem 0 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
/* An empty chart says so. A blank box reads as a broken widget rather than as a
   market that has not traded yet. */
.chart.is-empty::after,
.chart.is-error::after {
  position: absolute;
  inset: 0;
  /* Above the chart canvas, which positions its own layers. */
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 0.8rem var(--mono);
  color: var(--muted);
  background: var(--panel);
  padding: 0 1rem;
  text-align: center;
}
.chart.is-empty::after { content: "no trades yet"; }
.chart.is-error::after { content: "price history unavailable"; }
.chart-fallback { display: block; padding: 1rem; color: var(--muted); font-size: 0.82rem; }

/* --- Pre-trade preview --------------------------------------------------- */

.preview-slot { min-height: 2.5rem; margin-top: 0.6rem; }
.preview-hint, .preview-error {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.4rem 0 0;
}
.preview-error { color: var(--warn); }

.preview {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.6rem;
  margin: 0.5rem 0 0;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--rule);
  font-size: 0.82rem;
}
.preview > div { display: grid; grid-template-columns: subgrid; grid-column: 1 / -1; }
.preview > div.wide { grid-template-columns: 1fr; }
.preview dt { color: var(--muted); }
.preview dd {
  margin: 0;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.preview dd.gain { color: var(--bid); }
.preview dd.lose { color: var(--ask); }
.preview .muted { color: var(--muted); font-family: var(--sans); }
.preview > div.wide dd { font-family: var(--sans); color: var(--muted); }

/* --- Stop orders --------------------------------------------------------- */

.stop-panel { margin-top: 0.75rem; border-top: 1px solid var(--rule); padding-top: 0.6rem; }
.stop-panel > summary {
  cursor: pointer;
  font: 600 0.72rem var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  list-style: none;
}
.stop-panel > summary::marker, .stop-panel > summary::-webkit-details-marker { display: none; }
.stop-panel > summary::before { content: "+ "; }
.stop-panel[open] > summary::before { content: "− "; }
.stop-panel > summary:hover { color: var(--ink); }
.stop-panel .ticket { border-top: 0; padding-top: 0.6rem; }
.status-armed { color: var(--warn); }

/* --- Admin console -------------------------------------------------------
   Deliberately plain. This is a page two people read carefully before one of
   them clicks Approve, so the values need to be legible rather than styled. */

.stack { display: flex; flex-direction: column; gap: 0.7rem; max-width: 28rem; margin-top: 0.5rem; }
.stack label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.82rem; color: var(--muted); }
.stack input, .stack select {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}
.stack .cta { align-self: flex-start; }

.violations { margin: 0.5rem 0 0; padding-left: 1.1rem; color: var(--warn); font-size: 0.85rem; }
.violations li { margin-bottom: 0.25rem; }

.stack textarea {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  resize: vertical;
}
.stack > .hint { margin: -0.35rem 0 0; }
