/*
 * Colours are declared for both schemes and every text pair below was checked
 * against WCAG 1.4.3 (4.5:1 for body text, 3:1 for large). The muted greys are
 * the ones that usually fail, so they are deliberately not as light as they
 * look like they should be.
 */
:root {
  --bg: #ffffff;
  --panel: #f7f8fa;
  --border: #d5d9e0;
  --text: #14161a;
  --muted: #555d6b; /* 7.0:1 on #f7f8fa */
  --accent: #8d3b00; /* 7.6:1 under white */
  --accent-text: #ffffff;
  --ok: #1b5e20;
  --err: #9c2221;
  --code-bg: #eef0f4;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1c1f25;
    --border: #333842;
    --text: #f2f4f7;
    --muted: #a8b0bd; /* 8.0:1 on #1c1f25 */
    --accent: #ffa726; /* 10.8:1 under black */
    --accent-text: #000000;
    --ok: #a5d6a7;
    --err: #eb9e9e;
    --code-bg: #23272f;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 1rem 4rem;
  background: var(--bg);
  color: var(--text);
  font:
    16px/1.6 system-ui,
    -apple-system,
    'Segoe UI',
    sans-serif;
}

main,
.hero,
footer {
  max-width: 62rem;
  margin: 0 auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- hero ---------- */

.hero {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
  padding: 2.5rem 0 1.5rem;
}

h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
}

.tagline {
  margin: 0.6rem 0 0;
  max-width: 44rem;
  color: var(--muted);
}

.install code {
  background: var(--code-bg);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.9rem;
}

.hero-links {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.hero-links a {
  color: var(--text);
}

.version {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---------- workspace: examples left, workbench right ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

/* Both columns scroll independently, so picking an example near the bottom of
   a long list does not push the results off screen. */
.examples,
.workbench {
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  position: sticky;
  top: 1rem;
}

.workbench {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* The engine controls, sitting between the query and its results so the
   causal chain is visible rather than asserted. */
.engine-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.7rem;
  margin-top: 0.7rem;
  padding: 0.6rem 0.7rem;
  background: var(--code-bg);
  border-radius: var(--radius);
  font-size: 0.8rem;
}

.engine-strip label {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
}

.engine-strip select {
  font-size: 0.78rem;
  padding: 0.2rem 0.35rem;
}

.engine-strip .toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  color: var(--text);
}

button.ghost {
  margin-left: auto;
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
  padding: 0.2rem 0.55rem;
  font-size: 0.76rem;
}

button.ghost:hover {
  color: var(--text);
  border-color: var(--accent);
}

.results-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.option-badges {
  display: contents;
}

/* Any option away from its default, named. Clicking an example replaces what
   you set by hand; without these the reset is invisible. */
.option-badge {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.results-label {
  margin-bottom: 0.35rem;
}

/* Which dataset is loaded. Switching it changes the COLUMNS, so a reader who
   clicks a dirty-data example and suddenly sees two columns needs to be told
   why rather than left to guess the table broke. */
.dataset-badge {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.dataset-badge.is-switched {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.results-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

@media (max-width: 62rem) {
  .workspace {
    grid-template-columns: 1fr;
  }
  /* Query first on a narrow screen — it is the thing you came to use. */
  .workbench {
    order: -1;
  }
  .examples,
  .workbench {
    max-height: none;
    position: static;
  }
}

/* ---------- panels ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.panel h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

details.panel > summary {
  cursor: pointer;
  list-style: revert;
}

details.panel > summary h2 {
  display: inline;
  margin: 0;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.4rem 0 1rem;
}

.field-label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0.9rem 0 0.35rem;
}

/* ---------- query ---------- */

.query-input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.query-input:focus-visible,
button:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.stats {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.6rem 0 0;
}

.caption {
  margin: 0.6rem 0 0;
  padding-left: 0.8rem;
  border-left: 3px solid var(--accent);
  font-size: 0.92rem;
}

.error {
  margin: 0.8rem 0 0;
  padding: 0.8rem;
  background: var(--code-bg);
  border-left: 3px solid var(--err);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: pre;
  overflow-x: auto;
  color: var(--text);
}

.error .err-meta {
  color: var(--err);
  display: block;
  margin-bottom: 0.4rem;
}

/* ---------- example accordion ---------- */

.group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: var(--bg);
}

.group > summary {
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.group > summary::-webkit-details-marker {
  display: none;
}

.group > summary::before {
  content: '▸';
  color: var(--muted);
  font-size: 0.8rem;
}

.group[open] > summary::before {
  content: '▾';
}

.group .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--muted);
}

.group-body {
  padding: 0 0.75rem 0.75rem;
}

.group-body p {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.chip {
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
}

.chip:hover {
  border-color: var(--accent);
}

.chip[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.chip.is-error::after {
  content: ' ⚠';
}

/* ---------- tables ---------- */

.table-scroll {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

th,
td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td.mono,
td.num {
  font-family: var(--mono);
}

.shape {
  font-size: 0.72rem;
  color: var(--muted);
  margin-left: 0.35rem;
}

.yes {
  color: var(--ok);
  font-weight: 600;
}

.no {
  color: var(--err);
}

/* ---------- code ---------- */

.code-block {
  background: var(--code-bg);
  padding: 0.8rem;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.82rem;
  overflow-x: auto;
  margin: 0;
  white-space: pre;
}

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

/* ---------- options ---------- */

.options-grid {
  display: grid;
  grid-template-columns: minmax(8rem, auto) 1fr;
  gap: 0.6rem 1rem;
  align-items: center;
}

.options-grid label {
  font-family: var(--mono);
  font-size: 0.85rem;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
}

select,
input[type='number'] {
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ---------- misc controls ---------- */

button {
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
}

textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.7rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
}

.row-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.inline-error {
  color: var(--err);
  font-size: 0.85rem;
}

.race-controls {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}

.race-controls label {
  font-family: var(--mono);
  font-size: 0.85rem;
}

footer {
  padding-top: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

footer a,
.muted a {
  color: var(--text);
}

@media (max-width: 40rem) {
  .options-grid {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }
  .panel {
    padding: 1rem;
  }
}

/* ---------- options documentation ---------- */

.options-doc {
  margin: 0;
  font-size: 0.88rem;
}

.options-doc dt {
  font-family: var(--mono);
  font-weight: 600;
  margin-top: 0.8rem;
}

.options-doc dd {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.verdict-key {
  margin: 0.4rem 0 1rem;
  padding-left: 1.1rem;
}

.verdict-key li {
  margin-bottom: 0.35rem;
}

.verdict-key strong {
  color: var(--text);
}

/* Two explicit rows, and a label glued to its control. Left to plain wrapping,
   "onValueError" ended up on one line with its select on the next. */
.engine-strip {
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
}

.engine-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.9rem;
}

.opt {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.engine-strip input[type='text'] {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.2rem 0.4rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
