/*
 * Black, white, and red where something falls short.
 *
 * Red is not decoration and never marks direction on its own. It marks a
 * SHORTFALL against what the price needs: the span between the spread and its
 * target, the dollars between consensus and required EPS, and an input that is
 * stale or missing. Everything else is ink on paper.
 *
 * Every measurement is a multiple of 8px, every rule is exactly 1px, and the
 * caliper strokes are snapped to half-pixels so hairlines land on the grid
 * rather than straddling it.
 */

:root {
  --paper: #ffffff;
  --sunk: #f2f2f2;

  --ink: #000000;
  --ink-body: #1a1a1a;
  --ink-2: #474747;
  /* The lightest text on the page. 4.76:1 on --sunk, so it holds AA even on
     the grey panels at 11px; anything lighter is for rules, not words. */
  --ink-3: #6b6b6b;

  --rule: #e2e2e2;

  --red: #d00000; /* fills, bars, marks */
  --red-ink: #a30000; /* text — darker, for contrast at small sizes */
  --overlay: rgb(0 0 0 / 0.05); /* the reconstructed-history wash on charts */

  color-scheme: light;

  --sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --s1: 8px;
  --s2: 16px;
  --s3: 24px;
  --s4: 32px;
  --s6: 48px;
  --s8: 64px;

  --gutter: clamp(20px, 4vw, 40px);
  --measure: 1120px;
}

/*
 * Dark is a straight inversion of the same system — no second palette, the
 * same nine tokens. Two things do not simply flip:
 *   - paper is near-black rather than #000, because pure black under pure
 *     white text halates badly at body size;
 *   - the red has to get LIGHTER, not darker, to hold contrast.
 */
:root[data-theme='dark'] {
  --paper: #0c0c0c;
  --sunk: #1c1c1c;

  --ink: #ffffff;
  --ink-body: #e6e6e6;
  --ink-2: #b0b0b0;
  --ink-3: #8c8c8c; /* 5.07:1 on --sunk */

  --rule: #2b2b2b;

  --red: #ff4a3d;
  --red-ink: #ff8b80;
  --overlay: rgb(255 255 255 / 0.07);

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink-body);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 24px;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--red-ink);
}

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

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

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

/* ── Masthead ─────────────────────────────────────────────────────────── */

.masthead {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s3);
  align-items: baseline;
  justify-content: space-between;
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--s3) var(--gutter);
  border-bottom: 1px solid var(--ink);
}

.masthead__mark {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  flex-wrap: wrap;
  margin: 0;
}

.masthead__title {
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.masthead__sub {
  font-size: 13px;
  color: var(--ink-2);
}

.masthead__state {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: var(--s1);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.masthead__state[data-state='open'] #session-label {
  color: var(--ink);
  font-weight: 500;
}

.masthead__state[data-state='error'] #session-label {
  color: var(--red-ink);
  font-weight: 500;
}

.masthead__sep {
  color: var(--rule);
}

.theme-toggle {
  appearance: none;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  height: 24px;
  padding: 0 10px;
  margin-left: var(--s2);
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}

.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--ink-3);
}

#updated-at {
  color: var(--ink-3);
  text-transform: none;
  letter-spacing: 0.02em;
}

/* ── Bands ────────────────────────────────────────────────────────────── */

main {
  max-width: var(--measure);
  margin: 0 auto;
}

.band {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--s4) var(--gutter) var(--s6);
  border-bottom: 1px solid var(--rule);
}

.band__head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s3);
}

.label {
  margin: 0;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ── The reading ──────────────────────────────────────────────────────── */

.signal {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  height: 24px;
  padding: 0 10px;
  border: 1px solid var(--ink);
  font-family: var(--mono);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  white-space: nowrap;
}

.signal[data-state='bearish'] {
  border-color: var(--red);
  background: var(--red);
  color: var(--paper);
}

.signal[data-state='bullish'] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.signal[data-state='unknown'] {
  border-color: var(--rule);
  color: var(--ink-3);
}

.reading__figures {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--s3) var(--s8);
  margin-bottom: var(--s6);
}

.headline {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: var(--s1);
  line-height: 0.82;
}

.headline__value {
  font-weight: 700;
  font-size: clamp(60px, 12vw, 116px);
  letter-spacing: -0.035em;
  color: var(--ink);
}

.headline[data-tone='negative'] .headline__value {
  color: var(--red);
}

.headline__unit {
  font-family: var(--mono);
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

/* Two rows, not three boxes side by side: every label shares row one and every
   value shares row two, so an operator set at a different size cannot drag its
   own label out of line the way bottom-aligned flex boxes did. */
.legs {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: auto auto;
  align-items: baseline;
  column-gap: var(--s3);
  row-gap: 2px;
  margin: 0 0 6px;
}

.leg {
  display: contents;
}

.leg dt {
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.leg dd {
  margin: 0;
  font-size: 22px;
  line-height: 28px;
  font-weight: 500;
  color: var(--ink);
}

.leg--op dd {
  color: var(--ink-3);
  font-weight: 400;
}

/* ── Signature: the caliper ───────────────────────────────────────────── */

.caliper {
  margin: 0;
}

.caliper svg {
  display: block;
  width: 100%;
  height: 72px;
}

.caliper__axis,
.caliper__tick--major {
  stroke: var(--ink);
  stroke-width: 1;
}

.caliper__tick {
  stroke: var(--ink-3);
  stroke-width: 1;
}

.caliper__zero {
  stroke: var(--ink);
  stroke-width: 1;
}

.caliper__tick-label {
  fill: var(--ink-3);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-anchor: middle;
}

/* The measured span. Red when the spread is short of target — that shortfall
   is the whole question — and plain ink when it has cleared it. */
.caliper__gap {
  fill: var(--red);
}

.caliper__gap[data-tone='over'] {
  fill: var(--ink);
}

.caliper__target {
  stroke: var(--ink);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

.caliper__marker {
  transition: transform 500ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.caliper__marker line {
  stroke: var(--ink);
  stroke-width: 1.5;
}

.caliper__marker path {
  fill: var(--ink);
}

.caliper__marker[data-tone='negative'] line {
  stroke: var(--red);
}

.caliper__marker[data-tone='negative'] path {
  fill: var(--red);
}

.caliper__key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  margin: var(--s2) 0 0;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.key b {
  font-weight: 500;
  color: var(--ink);
}

.key--rank {
  margin-left: auto;
  color: var(--ink-2);
}

.why {
  margin: var(--s3) 0 0;
  max-width: 68ch;
  font-size: 16px;
  line-height: 26px;
  color: var(--ink-body);
}

.why b {
  font-weight: 600;
  color: var(--ink);
}

.why .short {
  color: var(--red-ink);
  font-weight: 600;
}

/* Secondary readings sit below the verdict, at the weight the post gives them:
   footnotes to the nominal spread, not second headlines. */
.aside {
  margin-top: var(--s3);
  padding-top: var(--s2);
  border-top: 1px solid var(--rule);
}

.aside[hidden] {
  display: none;
}

.aside__key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s3);
  margin: 0;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.key--band {
  margin-left: auto;
  color: var(--ink-2);
}

.key--band[data-position='below'] {
  color: var(--red-ink);
}

.aside__note {
  margin: var(--s1) 0 0;
  max-width: 68ch;
  font-size: 13px;
  line-height: 20px;
  color: var(--ink-2);
}

/* ── Required vs consensus ────────────────────────────────────────────── */

.eps__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  justify-content: space-between;
  margin-bottom: var(--s1);
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.eps__key b {
  font-weight: 500;
  font-size: 13px;
  color: var(--ink);
}

.eps__key--req {
  text-align: right;
}

/* One track: ink up to consensus, then the tail to required. The tail is the
   number the verdict sentence names, drawn at the same scale. */
.eps__track {
  display: flex;
  width: 100%;
  height: 24px;
  background: var(--sunk);
}

.eps__fill,
.eps__tail {
  display: block;
  height: 100%;
  width: 0;
  transition: width 500ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.eps__fill {
  background: var(--ink);
}

.eps__tail[data-kind='short'] {
  background: var(--red);
}

.eps__tail[data-kind='surplus'] {
  background: repeating-linear-gradient(
    -45deg,
    var(--ink-3) 0 1px,
    transparent 1px 5px
  );
}

.eps__foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  justify-content: space-between;
  margin: var(--s1) 0 0;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

.eps__delta[data-kind='short'] {
  color: var(--red-ink);
}

.eps__delta[data-kind='surplus'] {
  color: var(--ink-2);
}

/* ── What would change the signal ─────────────────────────────────────── */

.approach[hidden] {
  display: none;
}

.approach__nearest {
  margin: 0;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.approach__nearest b {
  font-weight: 500;
  color: var(--ink);
}

.approach__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.approach__table th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 var(--s2) var(--s1) 0;
  border-bottom: 1px solid var(--ink);
  white-space: nowrap;
}

.approach__table td {
  padding: 10px var(--s2) 10px 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-2);
  white-space: nowrap;
}

/* The nearest route is the only one that matters most days. */
.approach__table tr[data-nearest='true'] td {
  color: var(--ink);
  font-weight: 500;
}

.approach__table td:last-child {
  color: var(--ink-3);
}

.approach__note {
  margin: var(--s3) 0 0;
  max-width: 78ch;
  font-size: 13px;
  line-height: 20px;
  color: var(--ink-2);
}

/* ── Charts ───────────────────────────────────────────────────────────── */

.ranges {
  display: flex;
  border: 1px solid var(--ink);
}

.ranges button {
  appearance: none;
  border: 0;
  border-left: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  height: 24px;
  padding: 0 10px;
  cursor: pointer;
}

.ranges button:first-child {
  border-left: 0;
}

.ranges button:hover {
  color: var(--ink);
}

.ranges button[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper);
}

.chart-title {
  margin: 0 0 var(--s2);
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.chart-title--second {
  margin-top: var(--s6);
}

.chart {
  width: 100%;
  min-height: 240px;
}

.chart-note {
  margin: var(--s1) 0 0;
  max-width: 78ch;
  font-size: 13px;
  line-height: 20px;
  color: var(--ink-2);
}

.chart-note[hidden] {
  display: none;
}

.chart--empty {
  display: grid;
  place-items: center;
  min-height: 240px;
  border: 1px solid var(--rule);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 13px;
}

.u-legend {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-2);
}

/* A short bar rather than a square: the swatch is a sample of the line it
   stands for, so solid / hollow / dashed are legible at a glance. */
.u-legend .u-marker {
  width: 20px;
  height: 10px;
  border-radius: 0;
  margin-right: 6px;
  vertical-align: -1px;
}

.u-select {
  background: var(--overlay);
}

.u-cursor-x,
.u-cursor-y {
  border-color: var(--ink-3) !important;
}

/* ── Inputs table ─────────────────────────────────────────────────────── */

/* The table keeps its columns on a phone and scrolls inside the band, rather
   than squashing or pushing the page sideways. */
.inputs__scroll {
  overflow-x: auto;
}

.inputs__table {
  width: 100%;
  min-width: 460px;
  border-collapse: collapse;
  font-size: 12px;
}

.inputs__table th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 var(--s2) var(--s1) 0;
  border-bottom: 1px solid var(--ink);
}

.inputs__table td {
  padding: 10px var(--s2) 10px 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-2);
  vertical-align: baseline;
  white-space: nowrap;
}

.inputs__table td:nth-child(2) {
  color: var(--ink);
  font-weight: 500;
}

.inputs__table tr[data-core='true'] td:first-child {
  color: var(--ink);
  font-weight: 500;
}

.badge {
  display: inline-block;
  margin-left: var(--s1);
  padding: 0 5px;
  font-size: 11px;
  line-height: 16px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.badge--stale {
  border: 1px solid var(--red);
  color: var(--red-ink);
}

.badge--failed {
  background: var(--red);
  color: var(--paper);
}

.inputs__eps {
  margin: var(--s3) 0 0;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}

/* ── Caveats ──────────────────────────────────────────────────────────── */

.caveats {
  border-bottom: 0;
  padding-bottom: var(--s8);
}

.lede {
  margin: 0 0 var(--s3);
  max-width: 72ch;
  font-size: 16px;
  line-height: 26px;
  color: var(--ink-body);
}

.caveats ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--s1);
  max-width: 78ch;
}

.caveats li {
  position: relative;
  padding-left: var(--s3);
  font-size: 14px;
  line-height: 22px;
  color: var(--ink-2);
}

.caveats ul > li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 11px;
  width: 12px;
  height: 1px;
  background: var(--ink-3);
}

.reading-label {
  margin-top: var(--s6);
  margin-bottom: var(--s3);
}

/* Numbered because the list is ordered by argument, not importance: the
   source first, then the critique, the construction it produced, the surveys.
   Bracketed so a [1] in the body matches [1] here. */
.refs {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: ref;
  display: grid;
  gap: var(--s3);
  max-width: 78ch;
}

.refs li {
  counter-increment: ref;
  position: relative;
  padding-left: var(--s4);
}

.refs li::before {
  content: '[' counter(ref) ']';
  position: absolute;
  left: 0;
  top: 2px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 18px;
  color: var(--ink-3);
}

.refs a {
  display: block;
  font-size: 15px;
  line-height: 22px;
  font-weight: 500;
  color: var(--ink);
}

.refs__cite {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.refs__why {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  line-height: 20px;
  color: var(--ink-2);
}

.refs li:target {
  outline: 1px solid var(--ink-3);
  outline-offset: 6px;
}

sup.fn {
  font-family: var(--mono);
  font-size: 0.72em;
  line-height: 0;
  vertical-align: super;
  margin-left: 1px;
}

/* The caliper key is already 11px; a relative size there would be unreadable. */
.key sup.fn {
  font-size: 10px;
  letter-spacing: 0;
}

sup.fn a {
  color: var(--ink-3);
  text-decoration: none;
}

sup.fn a:hover,
sup.fn a:focus-visible {
  color: var(--ink);
  text-decoration: underline;
}

/* Last line on the page: set off from the reading list by a rule, in the same
   quiet mono as the citations above it. */
.colophon {
  margin: var(--s6) 0 0;
  padding-top: var(--s2);
  border-top: 1px solid var(--rule);
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}

.colophon a {
  color: var(--ink-2);
}

/* ── Narrow screens ───────────────────────────────────────────────────── */

@media (max-width: 680px) {
  .legs {
    width: 100%;
    column-gap: var(--s2);
  }

  .key--rank,
  .key--band {
    margin-left: 0;
    width: 100%;
  }

  .inputs__table th:nth-child(3),
  .inputs__table td:nth-child(3) {
    display: none;
  }

  /* space-between needs ~340px for these two labels; below that they stack
     rather than colliding. */
  .eps__legend,
  .eps__foot {
    flex-direction: column;
    gap: 4px;
  }

  .eps__key--req,
  .eps__delta {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
