/* =============================================================================
   Forward record — the strip of desk totals, and one card per strategy.

   Plain CSS, one file: no framework, no JavaScript, no CDN, no @import.
   Self-contained on purpose (tokens, page shell, record rules) so it is correct
   whether the record page links it alone or after sleeves.css — the shared
   ground is identical in both files, so load order does not matter.

   Reading order, top to bottom: totals -> which sleeve, its rank, why it is or
   is not ranked -> the shape of the record -> the numbers. Colour is a second
   cue only: the return is always present as text in the stats grid.
   ============================================================================= */

:root {
  --bg: #fbfbfa;
  --panel: #ffffff;
  --ink: #1b1b19;
  --muted: #6b6b66;
  --rule: #e2e2dd;
  --rule-strong: #c9c9c2;
  /* A definition boundary is quieter than the line it crosses and louder than a hairline: it has
     to be findable in both themes without competing with the equity curve. */
  --version-rule: #a8a8a0;

  --gain: #1f7a4d;
  --loss: #9c3325;
  --flat: #6b6b66;

  /* Chart weights live here so dark mode tunes them without a second block. */
  --area-opacity: 0.07;
  --baseline-opacity: 0.55;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --panel: #1a1a20;
    --ink: #e8e8e4;
    --muted: #9a9a94;
    --rule: #2c2c31;
    --rule-strong: #3d3d45;
    --version-rule: #5e5e68;

    --gain: #4fbf83;
    --loss: #e0796a;
    --flat: #9a9a94;

    --area-opacity: 0.11;
    --baseline-opacity: 0.45;
  }
}

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

body {
  margin: 0;
  padding: 24px;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.head { display: flex; align-items: baseline; gap: 16px; margin-bottom: 20px; }
.head h1 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.head .meta { margin: 0; color: var(--muted); font: 12px/1.4 var(--mono); }

/* ---- Global strip: the whole desk in one line -----------------------------------------------
   Hairline columns rather than whitespace alone, so five readings scan as a
   panel of instruments instead of a sentence. Total equity is the one figure
   set large; everything after it is a count and does not need to shout. */

.record-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  margin: 0 0 20px;
  border-bottom: 1px solid var(--rule-strong);
}

.record-strip-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  padding: 6px 20px;
  border-left: 1px solid var(--rule);
}

.record-strip-item:first-child { padding-left: 0; border-left: 0; }

.record-strip-item .k {
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.record-strip-item .v {
  font: 600 13.5px/1.15 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
/* A per-currency total is more than one claim: let the parts wrap as units, never split one. */
.record-strip-item .v.v-multi { white-space: normal; }
.total-part { display: inline-block; white-space: nowrap; }

.record-strip-item:first-child .v {
  font-size: 17px;
  letter-spacing: -0.02em;
}

/* ---- Cost toggles: what the record below is net of ---------------------------------------------
   Eight links, no JavaScript: one click adds or drops a cost and the page reloads. Two zones, so
   the row reads in the order the question is asked:

     1. the head — the basis in words ("net of …", or "gross"), and the way back to gross;
     2. the set  — the eight categories, counted (filled) or not (outline).

   A row of chips cannot say what the figures are net of on its own, which is why the basis stays
   in text rather than being left to the fills.

   Order is the enum's order, never the state: this page reloads on every click, so a chip that
   re-sorted itself would move out from under the pointer. State is carried by the fill, which
   survives the reload and is the same shape on every one of the eight. */

.record-toggles {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 0 0 14px;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--rule);
}

.record-toggles-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  min-width: 0;
}

.record-toggles-k {
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

/* The kicker labels the control; the basis is its value. Punctuation only, so the pair reads as
   one line ("COSTS: net of …") without a second element to wrap. */
.record-toggles-k::after {
  content: ":";
  letter-spacing: 0;
  margin-left: -0.09em; /* undo the tracking after the last letter */
}

.record-toggles-label {
  font: 500 12px/1.6 var(--mono);
  letter-spacing: -0.01em;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.record-toggle-set {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* A chip is one object: wrapping mid-name would break scanning, and no name is wide enough to
   overflow a 320px line. */
.record-toggle {
  display: inline-block;
  font: 11.5px/1 var(--mono);
  padding: 6px 9px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.record-toggle:hover { border-color: var(--rule-strong); color: var(--ink); }
.record-toggle:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Counted: inverted, the one strong mark in the strip, because it is the state a reader has to
   find at a glance. */
.record-toggle.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.record-toggle.on:hover { opacity: 0.88; }

/* Counted, but never recorded. It stays filled — the selection is a fact and must not look
   unselected — and the dashed edge marks the difference from a cost that can actually move the
   figure. Dashed is the same mark the card's caveat carries. */
.record-toggle.recordless { border-style: dashed; }
.record-toggle.on.recordless { border-color: var(--rule-strong); }

/* The way back to gross sits at the far end of the head, in the same box on every view. */
.record-toggle.reset {
  margin-left: auto;
  padding: 5px 10px;
  border-color: var(--rule-strong);
  color: var(--ink);
}
.record-toggle.reset:hover { border-color: var(--ink); background: var(--panel); }

/* The fill and the dash are the only visible marks for counted/not counted, so the word goes with
   them for anyone reading the page without seeing it. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- Cards ---------------------------------------------------------------------------------- */

.record-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

/* One tone per card, inherited by the svg inside it: the 2px top edge is the
   only place the whole card takes colour, which reads as a spine rather than a
   highlight. minmax(0,1fr) plus min-width:0 is what keeps cards from overflowing
   when a sleeve name or a money figure is long. */
.record-card {
  --tone: var(--flat);
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px 14px 13px;
  border: 1px solid var(--rule);
  border-top: 2px solid var(--tone);
  border-radius: 8px;
  background: var(--panel);
}

.record-card.gain { --tone: var(--gain); }
.record-card.loss { --tone: var(--loss); }
.record-card.flat { --tone: var(--flat); }

.record-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 8px;
  min-width: 0;
}

.record-card-head h3 {
  margin: 0;
  font: 600 13px/1.35 var(--mono);
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.record-rank {
  padding: 2px 6px 2px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  color: var(--muted);
  font: 10px/1.3 var(--mono);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Dashed edge for "unranked" is a shape difference, not just a colour one. */
.record-rank-none { border-style: dashed; }

/* The reason sits opposite the name: "not ranked: 10d < 60d" is the answer to
   the question the badge raises, so the two belong on the same line. */
.record-state {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-align: right;
}

/* ---- Curve ----------------------------------------------------------------------------------
   The wrapper owns the height; the svg owns the width. Nothing inside the chart
   carries a fixed size, so the only thing that changes between a 320px card and
   a 400px one is how far the line stretches. */

.record-curve-wrap {
  height: 128px;
  margin: 12px 0;
  /* The boundaries are positioned against this box, so it has to be the containing block. */
  position: relative;
}

svg.record-curve {
  --tone: var(--flat);
  display: block;
  width: 100%;
  height: 100%;
}

/* One short line under the plot, not inside it: the key that reads it, and the one that closes
   the readout. The full sentence is the plot's `aria-description`. */
.curve-hint {
  margin: -6px 0 10px;
  color: var(--muted);
  font: 9.5px/1.4 var(--mono);
  letter-spacing: 0.02em;
}

svg.record-curve.gain { --tone: var(--gain); }
svg.record-curve.loss { --tone: var(--loss); }
svg.record-curve.flat { --tone: var(--flat); }

/* preserveAspectRatio="none" stretches geometry, not stroke: without this the
   line would be 1.5 user-units thick and so thicken on every wider card. */
svg.record-curve .line {
  fill: none;
  stroke: var(--tone);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

/* A tint, not a fill: the shape is the message, the colour is the hint. */
svg.record-curve .area {
  fill: var(--tone);
  stroke: none;
  opacity: var(--area-opacity);
}

/* A flat record has no shape to shade, so its band gets out of the way. */
svg.record-curve.flat .area { opacity: calc(var(--area-opacity) * 0.6); }

/* ---- Axis ticks ------------------------------------------------------------------------------
   Three labels on the plot's own scale: the record's high, its middle and its low, compacted to
   the suffix the desk counts in (₹21.5L, $1.2M). Placed at the left edge, where the line starts at
   its baseline and the corners are the emptiest part of the plot.

   Not drawn inside the svg: that viewBox is stretched to the card width, which would smear the
   type differently on every card. A positioned overlay keeps one type size everywhere, and
   `pointer-events: none` keeps the plot's own pointer reading working through them. They are
   decoration — the exact figure for any point is what the readout prints, and the stats beside
   the curve are exact — so the whole group is hidden from the ear. */

.curve-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.curve-tick {
  position: absolute;
  left: 3px;
  padding: 0 3px;
  border-radius: 3px;
  background: var(--panel);
  color: var(--muted);
  font: 9.5px/1.2 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0.85;
}

.curve-tick-high { top: 1px; }
.curve-tick-mid { top: 50%; transform: translateY(-50%); }
.curve-tick-low { bottom: 1px; }

/* The starting value, so "below the line" means "below where this sleeve began". */
svg.record-curve .baseline {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 2 4;
  opacity: var(--baseline-opacity);
  vector-effect: non-scaling-stroke;
}

/* Drawn as a stroked dot with its radius reset, because a filled r=2.5 circle
   turns into an ellipse at any card width other than 640px. A constant-width
   stroke is the only part of the shape that does not stretch. */
svg.record-curve .marker {
  r: 1px;
  fill: none;
  stroke: var(--tone);
  stroke-width: 3.5;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* The server emits this instead of an svg when a sleeve has fewer than two
   valuations. It fills the same box so the stats grid below still lines up. */
.record-curve-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  margin: 0;
  padding: 0 16px;
  color: var(--muted);
  font: italic 12px/1.5 var(--sans);
  text-align: center;
}

/* ---- Definition boundaries on the curve -----------------------------------------------------
   A vertical rule where the strategy definition changed (ADR-0042). It is deliberately quiet —
   dashed, 1px, a grey rather than a tone — because the line is the record and the rule is a note
   about it: the seam must be findable without appearing to be a second series.

   Not drawn in the svg: that viewBox is stretched to the card width, which would smear a 1px stroke
   and stretch the label into a different shape on every card. A positioned overlay keeps one dash
   length and one type size at 320px and 1440px alike.

   The rule is never the only carrier of meaning. Its tag names what moved, its accessible name says
   the day and the transition, and the line under the curve states the count in text. */

.version-mark {
  position: absolute;
  inset-block: 0;
  width: 1px;
  /* Dashes as a gradient, not a border: a border's dashes scale with the element, and at 1px wide
     that turns into a dotted smear on a 2x display. */
  background-image: repeating-linear-gradient(
    to bottom,
    var(--version-rule) 0 3px,
    transparent 3px 7px
  );
}

.version-mark-tag {
  position: absolute;
  top: 0;
  padding: 1px 4px 2px;
  border-radius: 3px;
  background: var(--panel);
  color: var(--muted);
  font: 9.5px/1.35 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* A tag sits over the rule it names. Near an edge it opens inwards instead, so it never runs past
   the plot it annotates. */
.version-mark-tag.start { left: 0; }
.version-mark-tag.end { right: 0; }
.version-mark-tag.mid { left: 0; transform: translateX(-50%); }

/* A rule is a fact about the line, so it answers a pointer and takes focus like one. The 11px
   band is a hit area, not a wider rule: the element keeps its 1px width, so the dash pattern and
   the tag's position are unchanged at every card width. */
.version-mark { cursor: help; }
.version-mark::before {
  content: "";
  position: absolute;
  inset-block: 0;
  left: -5px;
  right: -5px;
}
.version-mark:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 1px;
}

/* ---- Reading a point: a guide, a dot, one line of text --------------------------------------
   The polyline is the shape of the record; the figure behind it is what the reader came for.
   Pointing at the plot — or focusing it and using the arrow keys — puts a vertical guide at the
   nearest vertex, a dot on the line, and a label naming the day, the equity and the change from
   the first point. The script positions all three from the polyline's own coordinates and clamps
   the label to the plot's own box, so the last point's label stops at the card edge instead of
   running past it.

   The label is a status region, so a screen reader hears the value change as the arrows move; it
   stays in the tree and is hidden by opacity alone, because a live region that is `hidden` is not
   announced. Without the script there is no guide, no dot, no label and no focus stop: the
   wrapper only becomes focusable once there is a reading to move through. */

.record-curve-wrap[data-curve] { touch-action: pan-y; }

.record-curve-wrap[data-curve]:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 4px;
}

.curve-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  /* Mid-grey rather than ink-at-low-opacity: the same weight against a white plot and a dark
     one, and never mistaken for the definition rule it may pass. */
  background: var(--muted);
  opacity: 0.6;
  pointer-events: none;
}

/* The dot is a ring, not a filled disc: the line it sits on stays visible through it, so the
   point reads as "on this vertex" rather than "here is another point". */
.curve-dot {
  position: absolute;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border: 1.5px solid var(--tone, var(--flat));
  border-radius: 50%;
  background: var(--panel);
  pointer-events: none;
}

/* Inverted on purpose: the one chip on the page that sits over a drawing rather than beside it.
   Shrink-to-fit up to the plot's width, so a long "definition changed" sentence wraps inside the
   card instead of crossing its edge. */
.curve-readout {
  position: absolute;
  z-index: 3;
  width: max-content;
  max-width: 100%;
  padding: 4px 7px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--bg);
  font: 500 11px/1.25 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
  pointer-events: none;
  /* No fade. It has to be invisible the instant it is not in use, and a transition on the one
     element that must never be seen idle is a way to be seen idle. */
  opacity: 0;
}

.curve-readout[data-on] { opacity: 1; }

/* The sentence under the curve: how many seams the return spans, and what is running now.
   Present on every record that has one, so the rules above are explained in words as well. */

.record-versions {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 1px 7px;
  min-width: 0;
  margin: 0 0 11px;
  color: var(--muted);
  font: 11px/1.45 var(--mono);
  letter-spacing: -0.01em;
}

.record-versions-k { white-space: nowrap; }

.record-versions-sep {
  color: var(--rule-strong);
  letter-spacing: 0;
}

.record-versions-now {
  min-width: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.record-versions-v { font-variant-numeric: tabular-nums; }

/* The model that answered, when a model swap is the most recent thing that moved. */
.record-versions-m { color: var(--muted); }

/* The last seam in the record's own words, inside the Basis fold. It sits under the method
   sentence because it qualifies the same figure: the return spans it. */
.record-versions-note {
  margin: 0.6em 0 0;
  color: var(--muted);
  font: 11.5px/1.5 var(--mono);
  overflow-wrap: anywhere;
}

/* ---- Stats: label above value, right-aligned stack ------------------------------------------
   `margin: auto 0 0` pins the grid to the bottom of the card, so every card in a
   row shows its numbers on one band even when a name or a reason wraps. Labels
   and values are both right-aligned, which makes the last digit of each column a
   vertical edge and keeps each label directly over its own number.

   The columns are not equal: the left one carries the two longest strings (a
   percentage and a money figure), the other two carry counts. Equal thirds make
   "INR -120433.55" overflow at the narrowest two-up width. */

.record-stats {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.05fr) minmax(0, 0.75fr);
  gap: 10px 12px;
  margin: auto 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
}

.record-stats > div {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.record-stats dt {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: right;
  /* A wrapped "max drawdown" is worse than a label that runs a few pixels into
     the gutter: the column keeps one line and the value underneath keeps its
     place even at the narrowest two-up width. */
  white-space: nowrap;
}

.record-stats dd {
  margin: 0;
  font: 500 12px/1.3 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  text-align: right;
  white-space: nowrap;
}

/* The return is the only figure allowed colour, and it is never the only cue:
   the sign is in the string, and the card's top edge carries the same tone. */
.record-stats > div:first-child dd {
  font-weight: 600;
  color: var(--tone);
}

/* A cost the desk never recorded is a caveat on the figures above it, not a figure
   of its own. It takes the whole width — which keeps the six numeric cells in the
   same three columns on every card, so two cards can be compared straight down the
   page — and it sits directly under the net line, because that is the number it
   says is understated. Dashed, the same mark the chips use for the same absence. */
.record-stats > .record-missing {
  grid-column: 1 / -1;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  margin-top: 2px;
  padding-top: 7px;
  border-top: 1px dashed var(--rule-strong);
}

.record-missing dt {
  text-align: left;
  white-space: nowrap;
}

.record-missing dd {
  font: 400 11px/1.4 var(--mono);
  color: var(--muted);
  text-align: left;
  /* The names are a list, not a figure: they may break rather than push the card
     wider than its column. */
  white-space: normal;
  overflow-wrap: anywhere;
}

/* ---- Responsive -----------------------------------------------------------------------------
   1 column, then 2, then 3. Three columns need ~1200px before a card is wide
   enough for six figures plus a money string; at 1100px two columns of 500px
   read better than three cramped ones. */

@media (min-width: 720px) {
  .record-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
}

@media (min-width: 1200px) {
  .record-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
}

@media (max-width: 719px) {
  body { padding: 16px; }
  .record-strip { margin-bottom: 16px; }
  .record-strip-item { padding: 5px 14px; }
  .record-card { padding: 11px 12px 12px; }
  .record-curve-wrap { height: 112px; }
  /* A phone's plot is ~260px wide; the label has to fit inside it, not spill past the card. */
  .curve-readout { font-size: 10.5px; padding: 3px 6px; }
  /* A phone taps these. Two pixels of padding is the difference between a chip
     and a target. */
  .record-toggle { padding: 8px 10px; }
  .record-toggle.reset { padding: 7px 10px; }
  .record-toggles { gap: 8px; }
}

/* Smallest phone in portrait: three stat columns cannot hold "INR 8915.20" and
   its label, so the grid drops to two columns and three rows rather than
   wrapping a value mid-number. */
@media (max-width: 380px) {
  .record-stats { grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.95fr); }
  .record-strip-item:first-child .v { font-size: 16px; }
}
