:root {
  --bg: #11131a;
  --panel: #181b24;
  --panel-2: #1e222d;
  --line: #2a2f3c;
  --text: #e4e7ee;
  --muted: #8b93a7;
  --accent: #6aa9ff;
  --edge: #46d18a;
  --noise: #8b93a7;
  --negative: #e2685f;
  --insufficient: #5a6176;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem 1.5rem 4rem;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  max-width: 1180px;
  margin-inline: auto;
}

h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 0.95rem; margin: 0; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.sub { color: var(--muted); margin: 0.35rem 0 0; }
header { margin-bottom: 1.5rem; }
.mono { font-family: var(--mono); font-size: 0.85rem; }
.muted { color: var(--muted); font-weight: 400; }
.hidden { display: none !important; }

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

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}

.actions { display: flex; gap: 0.5rem; }

button {
  font: inherit;
  font-size: 0.875rem;
  border-radius: 7px;
  border: 1px solid var(--line);
  padding: 0.45rem 0.95rem;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0b1017; font-weight: 600; }
button.link { background: none; border: none; color: var(--accent); padding: 0 0 0 0.5rem; font-size: 0.75rem; text-transform: none; letter-spacing: 0; }

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.6rem 0.9rem;
  margin-bottom: 1rem;
}
.controls label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.controls input, .controls select {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
}
.controls input:focus, .controls select:focus { outline: none; border-color: var(--accent); }
/* A unit sits beside its input rather than wrapping under it. */
.unit-field { display: flex; align-items: center; gap: 0.4rem; }
.unit-field input { flex: 1 1 auto; min-width: 0; width: 100%; }
.unit { text-transform: none; letter-spacing: 0; white-space: nowrap; }

/* Open while runs can be started; a published copy closes it so its results come first. */
.settings > summary {
  cursor: pointer;
  width: max-content;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}
.settings:not([open]) > summary { margin-bottom: 0; }

.group { border: 1px solid var(--line); border-radius: 8px; padding: 0.75rem 0.9rem; margin: 0 0 0.75rem; }
.group legend { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 0 0.35rem; }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.chip[aria-pressed="true"] { background: rgba(106,169,255,0.14); border-color: var(--accent); color: var(--text); }
.chip.control[aria-pressed="true"] { background: rgba(139,147,167,0.18); border-color: var(--muted); }

.hint, .note { font-size: 0.8rem; color: var(--muted); margin: 0.6rem 0 0; }
.note { background: rgba(226,104,95,0.1); border-left: 2px solid var(--negative); padding: 0.5rem 0.7rem; border-radius: 0 5px 5px 0; margin: 0 0 0.75rem; }

.banner { border-radius: 8px; padding: 0.7rem 0.95rem; margin-bottom: 1.1rem; font-size: 0.875rem; }
.banner.error { background: rgba(226,104,95,0.14); border: 1px solid var(--negative); }
.banner.info { background: rgba(106,169,255,0.12); border: 1px solid var(--accent); }

.progress { margin-bottom: 1rem; }
.bar { height: 5px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
#bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
#progress-text { color: var(--muted); margin: 0.4rem 0 0; }

.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.tab {
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--panel-2); border-color: var(--line); color: var(--text); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 0.82rem; }
th, td { text-align: right; padding: 0.4rem 0.55rem; white-space: nowrap; border-bottom: 1px solid var(--line); }
th:nth-child(2), td:nth-child(2) { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--panel); }
th:hover { color: var(--text); }
tbody tr:hover { background: var(--panel-2); }
tr.control td { color: var(--muted); }
tr.control td:nth-child(2) { color: var(--text); }
.star { color: var(--accent); }

.verdict { font-size: 0.68rem; letter-spacing: 0.06em; padding: 0.12rem 0.45rem; border-radius: 4px; }
.verdict.EDGE { background: rgba(70,209,138,0.18); color: var(--edge); }
.verdict.NOISE { background: rgba(139,147,167,0.16); color: var(--noise); }
.verdict.NEGATIVE { background: rgba(226,104,95,0.16); color: var(--negative); }
.verdict.INSUFFICIENT { background: rgba(90,97,118,0.2); color: var(--insufficient); }

.pos { color: var(--edge); }
.neg { color: var(--negative); }
.na { color: var(--insufficient); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 0.75rem; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.75rem; }
.stat b { display: block; font-family: var(--mono); font-size: 1.15rem; font-weight: 600; }
.stat span { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 1.25rem; }
figure { margin: 0; }
figcaption { font-size: 0.78rem; color: var(--text); margin-bottom: 0.5rem; }
figcaption .muted { display: block; font-size: 0.72rem; margin-top: 0.15rem; }
svg { width: 100%; height: auto; display: block; }
svg text { font-family: var(--mono); font-size: 9px; fill: var(--muted); }

.legend { font-size: 0.75rem; color: var(--muted); margin: 0.9rem 0 0; line-height: 1.9; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin: 0 0.3rem 0 0.9rem; }
.dot:first-child { margin-left: 0; }
.dot.edge { background: var(--edge); }
.dot.noise { background: var(--noise); }
.dot.negative { background: var(--negative); }
.dot.insufficient { background: var(--insufficient); }

footer { color: var(--muted); font-size: 0.78rem; margin-top: 1.5rem; }

/* Drill-down: a leaderboard row expands into its equity curve and trades. */
tbody tr[data-pattern] { cursor: pointer; }
tbody tr.picked { background: rgba(106,169,255,0.1); box-shadow: inset 2px 0 0 var(--accent); }
#detail .table-wrap { max-height: 26rem; overflow-y: auto; }
#detail th, #detail td { text-align: right; }
#detail th:nth-child(1), #detail td:nth-child(1),
#detail th:nth-child(2), #detail td:nth-child(2),
#detail th:nth-child(10), #detail td:nth-child(10) { text-align: left; }
#detail-who { font-family: var(--mono); text-transform: none; letter-spacing: 0; }

/* Evidence tables scroll within their panels on narrow screens. */
.controls > label, figure, .chart-grid > *, .stat-grid > * { min-width: 0; }
.controls input, .controls select { max-width: 100%; }
.group { min-width: 0; }
/* Phones: two settings per row, and less padding around everything. */
@media (max-width: 560px) {
  body { padding: 1.25rem 0.75rem 3rem; }
  .panel { padding: 0.9rem 0.85rem; }
  .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  #bar-fill { transition: none; }
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

a { color: var(--accent); }

/* Header sort controls and row pickers: real buttons that read as table text. */
.cell-button {
  all: unset;
  cursor: pointer;
  min-height: 24px;
  display: inline-flex;
  align-items: center;
}
.cell-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
