/* Vector Garden — visual system.
   Colour comes from the EMPOWEREDAI site: warm charcoal, off-white, one rust accent.
   Three type voices: a condensed display face for the wordmark and canvas words only,
   a plain sans for controls and prose, and a monospace for every number. */
:root {
  color-scheme: dark;

  /* Colour */
  --black: #111214;
  --off-black: #17181b;
  --surface: #1e1f23;
  --white: #e8e6e1;
  --muted: #6a6870;
  --muted2: #9a9ba0;
  --accent: #c94a2a;
  --accent2: #e8603d;
  --hair: rgba(232, 230, 225, 0.09);
  --hair-strong: rgba(232, 230, 225, 0.2);

  /* Type */
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --sans: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  /* Space: a 4px grid */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  /* Shape and motion */
  --radius: 2px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --fast: 120ms;

  /* Layout */
  --bar-h: 52px;
  --rail-w: 232px;
  --inspector-w: 264px;
  --edge: 24px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--black);
  color: var(--white);
  font: 400 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

p, h1, h2, ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }

/* Shared voices */
.label, dt {
  font: 500 10.5px/1.2 var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted2);
}

.num { font-family: var(--mono); font-weight: 400; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.num__dim { color: var(--muted); }
.note { font-size: 12px; line-height: 1.45; color: var(--muted); }

:focus-visible { outline: 1.5px solid var(--white); outline-offset: 2px; }

/* ---------- A. Top bar ---------- */

.bar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--bar-h);
  padding: 0 var(--edge);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  column-gap: var(--s5);
  background: var(--black);
  border-bottom: 1px solid var(--hair);
  z-index: 3;
}

.bar__brand { display: flex; align-items: center; gap: var(--s4); min-width: 0; }

.wordmark { font: 800 19px/1 var(--display); letter-spacing: 0.1em; text-transform: uppercase; white-space: nowrap; }
.wordmark::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 10px; background: var(--accent2); }

/* Back to the main site: quiet, first in the bar, separated from the wordmark by a hairline. */
.bar__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding-right: var(--s4);
  border-right: 1px solid var(--hair-strong);
  font-size: 12.5px;
  color: var(--muted2);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--fast) var(--ease);
}

.bar__back svg { transition: transform var(--fast) var(--ease); }
.bar__back:hover { color: var(--white); }
.bar__back:hover svg { transform: translateX(-2px); }

.bar__meta { display: flex; align-items: center; gap: var(--s6); min-width: 0; }
.bar__meta > div { display: flex; align-items: baseline; gap: var(--s2); min-width: 0; }
.bar__meta dd { font: 400 12px/1.2 var(--mono); color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pill { display: inline-flex; align-items: center; gap: 7px; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); transition: background var(--fast) var(--ease); }
.pill[data-status="running"]::before { background: var(--accent2); box-shadow: 0 0 0 3px rgba(232, 96, 61, 0.2); }
.pill[data-status="paused"]::before { background: var(--white); }
.pill[data-status="terminated"]::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--white); }

.bar__tools { display: flex; align-items: center; gap: var(--s3); }

.seed { display: flex; align-items: center; gap: var(--s2); font: 500 10.5px/1 var(--sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted2); }

.seed input {
  width: 64px;
  height: 28px;
  padding: 0 var(--s2);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--white);
  font: 400 12px var(--mono);
  text-align: right;
  -moz-appearance: textfield;
  appearance: textfield;
  transition: border-color var(--fast) var(--ease);
}

.seed input:hover:not(:disabled) { border-color: var(--muted2); }
.seed input::-webkit-outer-spin-button, .seed input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.seed input:disabled { opacity: 0.4; }

.tool {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  height: 28px;
  padding: 0 var(--s3);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted2);
  font: 500 12.5px/1 var(--sans);
  cursor: pointer;
  transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}

.tool:hover { color: var(--white); border-color: var(--muted2); }
.tool:active { background: var(--surface); }
.tool[aria-expanded="true"] { color: var(--black); background: var(--white); border-color: var(--white); }

/* ---------- C1. Readout rail: unboxed, set directly on the sheet ---------- */

.rail {
  position: fixed;
  top: calc(var(--bar-h) + var(--s6));
  left: var(--edge);
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  z-index: 2;
}

.intro { font-size: 14px; line-height: 1.55; color: var(--muted2); max-width: 26ch; }

.readout { display: grid; gap: var(--s4); }
.meter { display: grid; gap: 6px; }
.meter > .num { font-size: 15px; line-height: 1; }
.num--xl { font-size: 44px !important; font-weight: 400; letter-spacing: -0.04em; line-height: 0.95 !important; }
.meter--score { grid-template-columns: 1fr; }
.meter__aside { font-size: 12px; color: var(--muted); }
.meter__aside .num { color: var(--muted2); }

.history { display: grid; gap: var(--s2); }
.chart { position: relative; height: 48px; touch-action: pan-y; }
#chart-svg { display: block; width: 100%; height: 100%; overflow: visible; }

.chart .target { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; vector-effect: non-scaling-stroke; }
.chart .baseline { stroke: var(--hair-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .best { fill: none; stroke: var(--accent2); stroke-width: 1.5; stroke-linejoin: miter; vector-effect: non-scaling-stroke; }
.chart .cursor { stroke: var(--hair-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .axis { fill: var(--muted); font: 400 9px var(--mono); }
.chart .dot--accepted { fill: var(--white); }
.chart .dot--rejected { fill: none; stroke: var(--muted); stroke-width: 1; }

.chart__tooltip {
  position: absolute;
  bottom: calc(100% + 4px);
  z-index: 2;
  padding: 5px var(--s2);
  border: 1px solid var(--hair-strong);
  background: var(--surface);
  font: 400 11px/1.3 var(--mono);
  white-space: nowrap;
  pointer-events: none;
}

/* What the loop is doing right now. */
.phase { display: flex; align-items: center; gap: var(--s2); min-height: 18px; font: 400 12px/1.3 var(--mono); color: var(--muted2); }
.phase::before { content: ""; flex: none; width: 7px; height: 7px; border: 1px solid var(--muted2); }
.phase[data-kind="accepted"] { color: var(--white); }
.phase[data-kind="accepted"]::before { border-color: var(--white); background: var(--white); }
.phase[data-kind="rejected"]::before { border-color: var(--accent2); }

/* How the run ended. Each reason has its own glyph and rule; only convergence gets the accent. */
.reason { display: grid; grid-template-columns: auto 1fr; column-gap: var(--s3); row-gap: var(--s1); padding-left: var(--s3); border-left: 2px solid var(--white); }
.reason__glyph { grid-row: 1 / span 2; align-self: start; margin-top: 3px; color: var(--white); }
.reason__title { font: 600 14px/1.3 var(--sans); color: var(--white); }
.reason__detail { grid-column: 2; font-size: 12.5px; line-height: 1.45; color: var(--muted2); }
.reason[data-reason="converged"] { border-left-color: var(--accent2); }
.reason[data-reason="converged"] .reason__glyph { color: var(--accent2); }
.reason[data-reason="max-iterations"] { border-left-style: dashed; }
.reason[data-reason="time-limit"] { border-left-style: dotted; }
.reason[data-reason="cancelled"] { border-left-color: var(--muted); }
.reason[data-reason="cancelled"] .reason__glyph, .reason[data-reason="cancelled"] .reason__title { color: var(--muted2); }

.error { padding-left: var(--s3); border-left: 2px solid var(--accent2); font-size: 12.5px; color: var(--white); }

/* Transport */
.transport { display: flex; gap: var(--s2); padding-bottom: var(--s5); border-bottom: 1px solid var(--hair); }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 36px;
  padding: 0 var(--s4);
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--white);
  font: 500 13.5px/1 var(--sans);
  cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.btn:hover { border-color: var(--white); }
.btn:active { transform: translateY(1px); background: var(--surface); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--primary { flex: 1; border-color: var(--accent); background: var(--accent); font-weight: 600; }
.btn--primary:hover { border-color: var(--accent2); background: var(--accent2); }
.btn--primary:active { background: var(--accent); }
.btn--quiet { padding: 0 var(--s2); border-color: transparent; color: var(--muted2); }
.btn--quiet:hover { border-color: transparent; color: var(--white); }

/* ---------- C2. Inspector ---------- */

.inspector {
  position: fixed;
  top: calc(var(--bar-h) + var(--s4));
  right: var(--edge);
  width: var(--inspector-w);
  max-height: calc(100% - var(--bar-h) - var(--s4) - 64px);
  overflow: hidden;
  background: var(--off-black);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  z-index: 2;
  animation: inspector-in 160ms var(--ease);
}

@keyframes inspector-in { from { opacity: 0; transform: translateY(-4px); } }

.inspector__section { display: grid; gap: var(--s3); padding: var(--s4); }
.inspector__section + .inspector__section { border-top: 1px solid var(--hair); }

.selection__title { display: flex; align-items: center; gap: var(--s2); font: 700 18px/1.1 var(--display); letter-spacing: 0.06em; text-transform: uppercase; }
.selection__title small { font: 400 12px var(--sans); letter-spacing: 0; text-transform: none; color: var(--muted2); }
.selection__list { display: grid; gap: 6px; }
.selection__list li { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: var(--s2); font-size: 13px; }
.selection__list .num { font-size: 12px; color: var(--muted2); }

.criteria { display: grid; gap: var(--s3); }
.criteria li { cursor: help; }
.criterion__head { display: flex; justify-content: space-between; align-items: baseline; }
.criterion__name { font-size: 13px; }
.criterion__weight { margin-left: 6px; font: 400 10.5px var(--mono); color: var(--muted); }
.criterion__value { font: 400 13px var(--mono); font-variant-numeric: tabular-nums; }
.criterion__track { position: relative; height: 2px; margin-top: 7px; background: var(--hair-strong); }
.criterion__fill { width: 0; height: 100%; background: var(--white); transition: width 200ms var(--ease); }
.criterion__tick { position: absolute; top: -3px; width: 1px; height: 8px; background: var(--muted2); transition: left 150ms var(--ease); }
.criterion__tick[data-accepted="true"] { background: var(--white); }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3); }
.facts > div { display: grid; gap: 5px; }
.facts dd { font-size: 14px; }

.topics { display: grid; grid-template-columns: 1fr 1fr; gap: 6px var(--s4); font-size: 13px; color: var(--muted2); }
.topics li { display: inline-flex; align-items: center; gap: var(--s2); }
.mark { flex: none; display: block; }

/* With a selection showing, the inspector has more to hold; shed in order of importance. */
@media (min-width: 861px) and (max-height: 880px) {
  .inspector:has(#selection-section:not([hidden])) .inspector__section--topics { display: none; }
}

@media (min-width: 861px) and (max-height: 740px) {
  .inspector:has(#selection-section:not([hidden])) .inspector__section--run { display: none; }
}

@media (min-width: 861px) and (max-height: 640px) {
  .inspector .note { display: none; }
  .inspector__section { gap: var(--s2); padding: var(--s3) var(--s4); }
  .inspector:has(#selection-section:not([hidden])) .inspector__section--breakdown { display: none; }
}

@media (min-width: 861px) and (max-height: 500px) {
  .inspector__section--run { display: none; }
}

/* ---------- View controls ---------- */

.view { position: fixed; right: var(--edge); bottom: var(--s4); display: flex; align-items: center; gap: var(--s4); z-index: 2; }
.view__hint { font-size: 12px; color: var(--muted); pointer-events: none; }

.zoom { display: flex; }
.zoom button { appearance: none; height: 26px; border: 0; background: transparent; color: var(--muted2); cursor: pointer; transition: color var(--fast) var(--ease), opacity var(--fast) var(--ease); }
.zoom button:hover:not(:disabled) { color: var(--white); }
.zoom button:disabled { opacity: 0.35; cursor: default; }
.zoom__btn { width: 26px; font: 400 16px/1 var(--sans); }
.zoom__level { width: 46px; font-size: 11px; }

.noscript { position: fixed; inset: auto 0 0 0; margin: 0; padding: 12px; text-align: center; background: var(--off-black); }

/* ---------- Medium widths: tighten before anything collides ---------- */

@media (max-width: 1180px) {
  .bar__meta .bar__dataset { display: none; }
}

@media (max-height: 620px) and (min-width: 861px) {
  .rail { top: calc(var(--bar-h) + var(--s4)); gap: var(--s4); }
  .history { display: none; }
  .num--xl { font-size: 34px !important; }
  .inspector__section--topics { display: none; }
}

@media (max-height: 460px) and (min-width: 861px) {
  .reason__detail { display: none; }
}

/* ---------- Narrow screens: the rail becomes a bottom sheet, the inspector stacks above it ---------- */

@media (max-width: 860px) {
  :root { --edge: 12px; --bar-h: 48px; }

  .bar { column-gap: var(--s3); }
  .seed, .bar__meta dt, .bar__back span { display: none; }
  .bar__back { width: 32px; height: 32px; justify-content: center; padding: 0 var(--s2) 0 0; }
  .bar__brand { gap: var(--s2); }
  .bar__meta { justify-content: flex-end; }
  .bar__meta dd { font-size: 11px; }
  .wordmark { font-size: 17px; }
  .tool { height: 32px; }

  .rail {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    padding: var(--s4) var(--edge) calc(var(--s4) + env(safe-area-inset-bottom, 0px));
    gap: var(--s3);
    background: var(--off-black);
    border-top: 1px solid var(--hair-strong);
  }

  .intro { max-width: none; font-size: 14px; }
  .readout { grid-template-columns: 1fr auto; align-items: end; gap: var(--s4); }
  .meter--score { grid-template-columns: auto 1fr; align-items: baseline; column-gap: var(--s3); }
  .meter--score .label { grid-column: 1 / -1; }
  .num--xl { font-size: 34px !important; }
  .history .label { display: none; }
  .chart { height: 32px; }
  .btn { height: 44px; }
  .transport { order: 9; padding: 0; border: 0; }

  .inspector {
    top: auto;
    left: 0;
    right: 0;
    bottom: var(--rail-h, 200px);
    width: auto;
    max-height: calc(100% - var(--bar-h) - var(--rail-h, 200px) - 56px);
    border-width: 1px 0 0 0;
    border-radius: 0;
  }

  .inspector__section { padding: var(--s3) var(--edge); gap: var(--s2); }
  .inspector__section--topics, .inspector .note { display: none; }
  .criteria { grid-template-columns: 1fr 1fr; gap: var(--s3) var(--s4); }
  .selection__list { grid-template-columns: 1fr 1fr; gap: 4px var(--s4); }

  .view { top: calc(var(--bar-h) + var(--s2)); bottom: auto; right: var(--s2); }
  .view__hint { display: none; }
  .zoom button { height: 32px; }
  .zoom__btn { width: 32px; }
}

@media (max-width: 860px) and (max-height: 620px) {
  .history { display: none; }
}

@media (max-width: 860px) and (max-height: 700px) {
  .inspector:has(#selection-section:not([hidden])) .inspector__section--breakdown,
  .inspector:has(#selection-section:not([hidden])) .inspector__section--run { display: none; }
}

@media (max-width: 860px) and (max-height: 560px) {
  body:has(.inspector:not([hidden])) .view { display: none; }
  .inspector__section--run { display: none; }
  .inspector { max-height: calc(100% - var(--bar-h) - var(--rail-h, 200px) - 4px); }
  .inspector__section { padding-top: var(--s2); padding-bottom: var(--s2); }
  .reason__detail { display: none; }
}

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