/* Le Signal — one instrument, one instruction. */

:root {
  --bg: #0e1420;
  --panel: #161e2e;
  --panel-2: #121927;
  --line: #26314a;
  --ink: #e8edf5;
  --muted: #8a94a8;
  --dim: #5d6778;
  --on: #3fb577;
  --on-dim: rgba(63, 181, 119, 0.12);
  --off: #e05252;
  --off-dim: rgba(224, 82, 82, 0.12);
  --s-strategy: #3987e5;
  --s-nogate: #d95926;
  --s-mix: #199e70;
  --s-ese: #c98500;
  --s-invested: #55617a;
  --display: "Archivo", sans-serif;
  --body: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }
.dim { color: var(--muted); font-weight: 400; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

a { color: var(--s-strategy); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--s-strategy); outline-offset: 3px; border-radius: 2px; }

/* ---------- masthead ---------- */
.masthead {
  max-width: 1060px; margin: 0 auto; padding: 20px 24px 0;
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
}
.brand { display: flex; align-items: baseline; gap: 8px; font-family: var(--mono); font-size: 13px; }
.brand-mark { width: 9px; height: 9px; border-radius: 2px; background: var(--s-strategy); align-self: center; }
.brand-name { color: var(--ink); font-weight: 500; letter-spacing: 0.04em; }
.brand-sep { color: var(--dim); }
.brand-page { color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.asof { font-size: 12px; color: var(--muted); }
.mast-right { display: flex; align-items: baseline; gap: 12px; }
#theme-toggle, #refresh {
  font-size: 15px; line-height: 1; color: var(--muted);
  background: none; border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 9px; cursor: pointer;
}
#theme-toggle:hover, #refresh:hover { color: var(--ink); }
#refresh.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- light theme ---------- */
[data-theme="light"] {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --panel-2: #edf0f6;
  --line: #d9dfe9;
  --ink: #17212f;
  --muted: #5b6577;
  --dim: #8b95a7;
  --on: #1c9959;
  --on-dim: rgba(28, 153, 89, 0.10);
  --off: #cf3f3f;
  --off-dim: rgba(207, 63, 63, 0.08);
  --s-strategy: #226dbe;
  --s-ese: #a96f00;
  --s-invested: #7c8698;
}
[data-theme="light"] .flap.on,
[data-theme="light"] .flap.off,
[data-theme="light"] .state-on .verdict,
[data-theme="light"] .state-off .verdict { text-shadow: none; }
[data-theme="light"] .chart .tip { background: #ffffff; }
[data-theme="light"] .brush input[type="month"] { color-scheme: light; }

main { max-width: 1060px; margin: 0 auto; padding: 0 24px 40px; }

/* ---------- hero: the instrument ---------- */
.hero { padding: 22px 0 12px; text-align: left; }
.eyebrow {
  font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}
.verdict {
  font-family: var(--display); font-weight: 900;
  font-size: clamp(36px, 7vw, 76px);
  line-height: 0.95; letter-spacing: -0.015em;
  margin: 0 0 10px -2px; text-transform: uppercase;
}
.verdict .flap { display: inline-block; }
.state-on .verdict { color: var(--on); text-shadow: 0 0 60px rgba(63, 181, 119, 0.25); }
.state-off .verdict { color: var(--off); text-shadow: 0 0 60px rgba(224, 82, 82, 0.25); }
@media (prefers-reduced-motion: no-preference) {
  .verdict .flap { animation: settle 0.55s cubic-bezier(0.2, 0.9, 0.3, 1) both; transform-origin: 50% 0; }
  @keyframes settle { from { transform: rotateX(80deg); opacity: 0; } to { transform: rotateX(0); opacity: 1; } }
}
.verdict-sub { font-size: 15px; color: var(--muted); margin-bottom: 6px; }
.verdict-sub strong { color: var(--ink); font-weight: 500; }
.verdict-action { font-size: 18px; font-weight: 600; max-width: 560px; }
.state-on .verdict-action em { color: var(--on); font-style: normal; }
.state-off .verdict-action em { color: var(--off); font-style: normal; }

/* ---------- charts ---------- */
.chart-block { margin-top: 12px; }
.chart-block h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.chart { position: relative; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart-tall { }
.chart-caption { font-size: 12px; color: var(--muted); margin-top: 5px; }
.k { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin: 0 3px; }
.k-spx { background: var(--s-strategy); }
.k-sma { background: var(--s-mix); }

.tooltip {
  position: absolute; pointer-events: none; z-index: 3;
  background: #0b101b; border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; font-family: var(--mono); font-size: 12px; line-height: 1.6;
  color: var(--ink); white-space: nowrap; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  display: none;
}
.tooltip .tt-date { color: var(--muted); }
.tooltip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend .sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

/* ---------- cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px 22px 16px; margin-top: 16px;
}
.card h2 {
  font-family: var(--display); font-weight: 800; font-size: 20px;
  letter-spacing: -0.01em; margin-bottom: 10px;
}
.card h3 { font-size: 15px; font-weight: 600; margin: 30px 0 10px; }

/* rule card */
.rule-list { list-style: none; counter-reset: rule; padding: 0; }
.rule-list li {
  counter-increment: rule;
  display: grid; grid-template-columns: 44px 1fr; gap: 0 16px;
  padding: 16px 0; border-top: 1px solid var(--line);
}
.rule-list li::before {
  content: counter(rule, decimal-leading-zero);
  font-family: var(--mono); font-size: 13px; color: var(--dim);
  padding-top: 3px; grid-row: span 4;
}
.rule-list strong { display: block; font-weight: 600; }
.rule-list strong.off { margin-top: 8px; }
.rule-list span { display: block; color: var(--muted); font-size: 14px; margin-top: 2px; }

.tickers { width: 100%; border-collapse: collapse; margin-top: 22px; font-size: 14px; }
.tickers th {
  text-align: left; font-family: var(--mono); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--dim);
  padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line);
}
.tickers td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line); }
.tickers td.mono { color: var(--s-strategy); }
.tickers tr.alt td { color: var(--muted); font-size: 13px; border-bottom: none; padding-top: 14px; }

/* evidence */
.lede { color: var(--muted); max-width: 72ch; }
.lede strong { color: var(--ink); }

.data-table { margin-top: 14px; }
.data-table summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.data-table table { width: 100%; border-collapse: collapse; margin-top: 10px; font-family: var(--mono); font-size: 12px; }
.data-table th, .data-table td { text-align: right; padding: 5px 10px; border-bottom: 1px solid var(--line); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table thead th { color: var(--dim); font-weight: 500; }

.roll-wrap { overflow-x: auto; }
.roll { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
.roll th {
  font-family: var(--mono); font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--dim); text-align: right;
  padding: 8px 14px 8px 0; border-bottom: 1px solid var(--line);
}
.roll th:first-child { text-align: left; }
.roll td { padding: 10px 14px 10px 0; border-bottom: 1px solid var(--line); text-align: right; font-family: var(--mono); font-size: 13px; }
.roll td:first-child { text-align: left; font-family: var(--body); font-size: 14px; }
.roll .pos { color: var(--on); }
.roll .neg { color: var(--off); }
.roll .hl td { background: rgba(57, 135, 229, 0.07); }

.footnote { font-size: 13px; color: var(--muted); margin-top: 16px; max-width: 72ch; }

.colophon { margin-top: 44px; padding-top: 20px; border-top: 1px solid var(--line); }
.colophon p { font-size: 12px; color: var(--dim); max-width: 80ch; margin-bottom: 6px; }
.colophon a { color: var(--muted); }

@media (max-width: 640px) {
  .card { padding: 22px 18px; }
  .hero { padding-top: 40px; }
  .rule-list li { grid-template-columns: 34px 1fr; }
  .tickers { font-size: 13px; }
}

/* ---------- dashboard controls ---------- */
.controls {
  display: grid; gap: 18px 26px; margin-top: 30px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 18px;
}
.ctl.wide { grid-column: 1 / -1; }
.ctl label {
  display: block; font-family: var(--mono); font-size: 11px; font-weight: 500;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); margin-bottom: 6px;
}
.ctl-row { display: flex; align-items: center; gap: 12px; }
.ctl-row output { font-size: 14px; color: var(--ink); min-width: 74px; text-align: right; }
.ctl input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none; height: 3px;
  background: var(--line); border-radius: 2px; outline: none;
}
.ctl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 20px; height: 20px;
  border-radius: 50%; background: var(--s-strategy); border: 3px solid var(--panel);
  box-shadow: 0 0 0 1px var(--s-strategy); cursor: pointer;
}
.ctl input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--s-strategy);
  border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--s-strategy); cursor: pointer;
}
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  font-family: var(--body); font-size: 13px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 13px; cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: rgba(57,135,229,0.14); border-color: var(--s-strategy); color: var(--ink); }
.seg.muted { opacity: .4; pointer-events: none; }

/* ---------- stat tiles ---------- */
.card-head { margin-bottom: 18px; }
.card-head h2 { margin-bottom: 4px; }
.card-head p { font-size: 13px; }
.stats { display: grid; gap: 1px; grid-template-columns: repeat(3, 1fr); background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(6, 1fr); } }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--panel-2); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.stat-k { font-size: 12px; color: var(--muted); }
.stat-v { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; }
.stat-s { font-size: 11px; color: var(--dim); }
.stat.good .stat-v { color: var(--on); }
.stat.bad .stat-v { color: var(--off); }
.verdict-warning {
  margin-top: 12px; padding: 10px 14px; font-size: 14px; line-height: 1.6;
  background: var(--off-dim); border-left: 3px solid var(--off); border-radius: 0 8px 8px 0;
}
.verdict-warning b { color: var(--ink); font-weight: 600; }

/* ---------- policy menu table ---------- */
.table-wrap { overflow-x: auto; margin-top: 16px; }
.menu { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
.menu th {
  font-family: var(--mono); font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--dim); text-align: right;
  padding: 8px 14px 8px 0; border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none;
}
.menu th:hover { color: var(--ink); }
.menu th.sorted { color: var(--s-strategy); }
.menu th:first-child { text-align: left; }
.menu td { padding: 6px 14px 6px 0; border-bottom: 1px solid var(--line); text-align: right; font-size: 13px; }
.menu td:first-child { text-align: left; font-family: var(--body); font-size: 14px; }
.menu tr { cursor: pointer; }
.menu tbody tr:hover td { background: rgba(255,255,255,0.03); }
.menu tr.cur td { background: rgba(57,135,229,0.10); color: var(--ink); }
.menu tr:focus-visible { outline: 2px solid var(--s-strategy); }

/* ---------- chart tooltip ---------- */
.chart .tip {
  position: absolute; top: 8px; pointer-events: none; z-index: 3;
  background: #0b101b; border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 9px; font-family: var(--mono); font-size: 11.5px; line-height: 1.55;
  color: var(--ink); white-space: nowrap; box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.chart .tip span { display: block; color: var(--muted); }
.chart .tip b { color: var(--ink); font-weight: 500; }
.chart .tip i { display: inline-block; width: 8px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart text.ax { fill: var(--muted); font-family: var(--mono); font-size: 11px; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y pinch-zoom; }
.chart .tip { max-width: calc(100% - 8px); white-space: normal; }

/* ---------- pulse strip ---------- */
.pulse {
  display: grid; gap: 1px; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  background: var(--line); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; margin-top: 12px;
}
.pulse .stat { min-height: 84px; }
.pulse .stat-v { font-size: 19px; }
.stat.warn .stat-v { color: var(--s-ese); }

/* ---------- period brush ---------- */
.brush { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 2px; }
.brush-lbl {
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim);
}
.brush input[type="month"] {
  font-family: var(--mono); font-size: 13px; color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 10px; color-scheme: dark;
}
.brush input[type="month"]:focus-visible { outline: 2px solid var(--s-strategy); }
#brush-reset {
  font-family: var(--body); font-size: 12px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 12px; cursor: pointer;
}
#brush-reset:hover { color: var(--ink); }
#equity-chart, #dd-chart, #gate-chart { cursor: crosshair; touch-action: pan-y pinch-zoom; }
.chart .sel {
  position: absolute; top: 0; bottom: 0; z-index: 2;
  background: rgba(57, 135, 229, 0.14);
  border-left: 1px solid var(--s-strategy); border-right: 1px solid var(--s-strategy);
  pointer-events: none;
}
.live-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--on); margin-left: 5px; vertical-align: middle;
}

.compare { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 8px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--body); font-size: 12.5px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 11px; cursor: pointer; transition: border-color .12s, color .12s;
}
.chip:hover { color: var(--ink); }
.chip.on { color: var(--ink); }
.chip.on.c0 { border-color: #d95926; background: rgba(217, 89, 38, 0.12); }
.chip.on.c1 { border-color: #199e70; background: rgba(25, 158, 112, 0.12); }

/* ---------- misc ---------- */
.flap.on { color: var(--on); text-shadow: 0 0 60px rgba(63,181,119,.25); }
.flap.off { color: var(--off); text-shadow: 0 0 60px rgba(224,82,82,.25); }
.card > .dim { font-size: 14px; max-width: 78ch; }
.caveats ul { list-style: none; padding: 0; }
.caveats li { padding: 12px 0; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.caveats li strong { color: var(--ink); font-weight: 600; }
footer { max-width: 1060px; margin: 0 auto; padding: 0 24px 30px; }
footer p { font-size: 11.5px; color: var(--dim); }

@media (max-width: 640px) {
  .controls { padding: 18px 16px; gap: 16px; }
  .stat-v { font-size: 20px; }
  .verdict { font-size: clamp(34px, 11vw, 56px); }
}

/* ---------- phone: readable text, thumb-sized controls, no sideways scroll ---------- */
@media (max-width: 640px) {
  main { padding: 0 16px 60px; }
  .masthead { padding: 16px 16px 0; }
  footer { padding: 0 16px 30px; }
  .card { padding: 18px 14px; }
  .card h2 { font-size: 21px; }
  .card > .dim, .card-head p { font-size: 13px; }

  /* controls sized for a thumb, not a cursor */
  .controls { padding: 16px 14px; gap: 14px; }
  .seg { gap: 8px; }
  .seg button { min-height: 40px; padding: 9px 14px; font-size: 14px; flex: 1 1 auto; }
  .ctl input[type="range"] { height: 6px; }
  .ctl input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; }
  .ctl input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; }
  .ctl-row output { font-size: 15px; min-width: 84px; }

  /* the menu keeps its sortable headers but drops to four columns so a row
     fits the screen — comparison across policies is the whole point of it */
  .table-wrap { overflow: visible; }
  .menu { min-width: 0; font-size: 13px; table-layout: fixed; }
  .menu th { font-size: 10px; padding: 8px 6px 8px 0; letter-spacing: 0.04em; }
  .menu td { padding: 9px 6px 9px 0; font-size: 13px; }
  .menu td.mono, .menu th:not(:first-child) { white-space: nowrap; }
  .menu td:first-child, .menu th:first-child { white-space: normal; line-height: 1.25; width: 38%; }
  .menu th[data-col="meanIrr"], .menu td:nth-child(3),
  .menu th[data-col="worst"], .menu td:nth-child(5) { display: none; }

  .stat { padding: 10px 10px; }
  .stat-k { font-size: 11px; }
  .stat-s { font-size: 10px; }
  .chart .tip { font-size: 11px; padding: 6px 8px; }
}

/* masthead and period brush: stop them colliding on a phone */
@media (max-width: 640px) {
  .masthead { align-items: center; gap: 10px; }
  .brand { font-size: 12px; white-space: nowrap; }
  .brand-page, .brand-sep, .asof-long { display: none; }
  .mast-right { display: flex; align-items: center; gap: 10px; }
  .asof { font-size: 11px; white-space: nowrap; }

  /* label then field on one line, the reset button spanning underneath */
  .brush { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; }
  .brush input[type="month"] { width: 100%; min-height: 40px; font-size: 14px; }
  .brush #brush-reset { grid-column: 1 / -1; min-height: 38px; }
}

/* ---------- period: quick ranges first, exact dates folded away ---------- */
.brush { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin: 8px 0 4px; }
.brush .quick { flex-wrap: wrap; }
.brush .exact > summary {
  cursor: pointer; list-style: none; font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim);
  padding: 4px 0; min-height: 28px; display: inline-flex; align-items: center;
}
.brush .exact > summary::-webkit-details-marker { display: none; }
.brush .exact > summary::before { content: "▸ "; margin-right: 4px; }
.brush .exact[open] > summary::before { content: "▾ "; }
.brush .exact > summary:hover { color: var(--ink); }
.brush-fields { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; padding-top: 8px; }
.brush-fields #brush-reset { grid-column: 1 / -1; justify-self: start; }

@media (max-width: 640px) {
  .brush { width: 100%; }
  .brush .quick { width: 100%; }
  .brush .quick button { flex: 1 1 auto; white-space: nowrap; padding: 9px 10px; }
  .brush .exact { width: 100%; }
  .brush-fields { grid-template-columns: auto 1fr; }
  .brush-fields input[type="month"] { width: 100%; min-height: 40px; font-size: 14px; }
  .brush-fields #brush-reset { min-height: 38px; }
}
.seg button:disabled { opacity: .35; cursor: not-allowed; }
.seg button:disabled:hover { color: var(--muted); }
