/* The public statistics pages' styles (M-17 T7+T8).
 *
 * The reading column comes from pages/base.html (54rem, owner
 * 2026-10-06: one centred column, air left and right) — this file adds
 * only what charts need and widens nothing. The colour tokens are the
 * base template's :root variables, shared with every reading page.
 *
 * The chart canvases need explicit heights: ECharts measures its
 * container once at init, and a height:auto div collapses to zero and
 * renders nothing — a silent, blank-chart failure.
 */

.stx-sub {
  color: var(--muted);
  margin-top: -0.5rem;
}

.stx-frames {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 1rem 0 1.5rem;
}

.stx-frames a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.stx-frames a:hover {
  color: var(--accent);
}

.stx-frames a[aria-current] {
  color: var(--accent);
  font-weight: 600;
}

/* The week-comparison picker (M-17 T6): a plain form GET, the legacy
 * chart.asp interaction. Two labelled selects and a submit button, laid
 * out on one row that wraps on narrow screens; no width of its own —
 * the form sizes to its content inside the reading column. */

.stx-compare {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 1.5rem;
  margin: 1rem 0 1.5rem;
}

.stx-compare label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.stx-compare select {
  border: 1px solid var(--line);
  background: #fff;
  padding: 0.35rem 0.5rem;
  font: inherit;
  color: inherit;
}

.stx-compare button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 0.4rem 1rem;
  font: inherit;
  cursor: pointer;
}

.stx-compare button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

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

.stx-headline dl {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin: 1rem 0 1.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  background: #fff;
}

.stx-headline dl div {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.stx-headline dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.stx-headline dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* The six Dashboard tiles (owner, 2026-10-24: "a box with a medium sized
 * title, a central relevant number in big font, with the comparison and
 * additional values in smaller font to the side and below. The tile can
 * also have a half transparent background icon relevant to the topic").
 *
 * Grid, not flex (owner, 2026-10-25: "The tiles don't have an equal size.
 * Some are a bit wider than others."). This file used to hug every tile to
 * its own content, which is the 2026-10-06 content-sized-box rule; the
 * owner has now reversed that rule **for these tiles**, so the row is
 * sized by its columns instead of by the widest figure inside it. The
 * `1fr` is what makes the six equal: `auto-fit` picks however many tracks
 * fit the 54rem reading column and each track takes an equal share, so no
 * tile can end up wider than its neighbour at any viewport width.
 *
 * THE MEASURED LADDER (check-stats-page.mjs parses the four numbers out
 * of base.html's column and this rule rather than restating them, and
 * prints the line on every run): against 54rem max-width with 1.25rem
 * side padding, a 0.6rem gap and a 15rem track floor, the row is 1 column
 * below 530px, 2 columns from 530px, and 3 columns from 780px.
 *
 * Three is the CEILING, not a sample: the effective pitch is 15.6rem and
 * 54.6 / 15.6 = 3.5 exactly, so floor() gives 3 and no screen of any
 * width gets a 4th track. A 4th would need the column at 61.8rem or more.
 * That cap is the whole reason there is no orphan row -- six tiles land in
 * whole rows of 3+3, 2+2+2 or 1x6, and a lone leftover tile needs
 * exactly 5 columns (6 % 5 == 1), which this column cannot form. Five
 * tracks would need 77.4rem; widening base.html's column past that is the
 * change the checker's 280px..2400px sweep exists to catch.
 *
 * Read the figures off the checker's printed line, not off this comment.
 * This paragraph's first draft said 3.49 where the quotient is 3.5 -- the
 * exact kind of number that survives review as a requirement once it is
 * written down, which is why check-stats-page.mjs PRINTS the ladder and
 * the trend palette on every green run instead of only asserting them.
 *
 * `min(100%, 15rem)` rather than a bare 15rem because the track floor must
 * never exceed the container: if it did, the grid would overflow sideways
 * instead of wrapping to a new line. */
.stx-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 0.6rem;
  margin: 1.25rem 0 1.5rem;
}

.stx-tile {
  position: relative;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  background: #fff;
  /* Clips the watermark glyph, which is deliberately parked half outside
   * the box so it reads as a background rather than a second icon. */
  overflow: hidden;
}

.stx-tile__bg {
  position: absolute;
  right: -0.5rem;
  bottom: -0.6rem;
  /* 5.5rem, up from 4rem (owner, 2026-10-26: "the placement of the
   * icons is good, but they can be a bit bigger"). Only the box grows --
   * the corner anchor, the negative offsets and the 0.07 wash are all
   * untouched, so the glyph stays the watermark it was and simply stops
   * vanishing. The tile keeps overflow: hidden, so it clips at the corner
   * exactly as the old size did rather than bleeding into a neighbour. */
  width: 5.5rem;
  height: 5.5rem;
  /* 0.07 of --ink over white is ~#eceef1 against #fff — a watermark,
   * far below the figure's contrast, so it can never compete with the
   * number it sits behind. */
  opacity: 0.07;
  color: var(--ink);
  /* The glyph is decoration; it must not swallow clicks or be read out by
   * a screen reader alongside the title it duplicates. */
  pointer-events: none;
}

.stx-tile__title {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

.stx-tile__figure {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.stx-tile__change {
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
  color: var(--accent);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Trend coding (owner, 2026-10-25: "it would be good to color code the
 * tiles with a light green (positive development) or red (negative
 * development)").
 *
 * WHY THE HEXES ARE WRITTEN HERE AND NOT `var(--asrm-ok)`. The committed
 * status pair lives in tokens.css, and **no statistics page loads that
 * file** -- base.html carries its own inline `:root` with only --ink,
 * --muted, --accent and --line, and only map/shell.html links tokens.css.
 * Writing `var(--asrm-ok)` here would therefore resolve to *nothing* and
 * the tile would silently keep its old colour while a grep for the token
 * name still looked correct. These six values are local to the one file the
 * page actually loads.
 *
 * WHY THE SIGN IS THE CARRIER AND THE TINT IS NOT. Measured with this
 * repo's own Machado (2009) severity-1.0 matrices + CIE76 in D65 -- the
 * same math check-movements-chart.mjs pins, not an external validator --
 * the two tile backgrounds separate by only dE 0.8 under deuteranopia and
 * 2.7 under protanopia, against a JND of about 2.3. As a bare pair the
 * backgrounds are effectively invisible to a deuteranope, so a tile could
 * never mean "up" or "down" by its background alone. What carries the
 * direction is the delta line's own sign, which `deltaText` already
 * prints as an explicit "+"/"-"; the text inks below are chosen so that
 * line also separates from its background by a wide margin, and from each
 * other by dE 6.4 / 18.4 / 93.1. Colour is redundant with the sign, so
 * the tiles stay correct in forced-colours mode, where every background
 * here is dropped and the +/- is all that is left standing.
 *
 * Contrast on the finished tiles (WCAG 2.x, recomputed in the checker):
 * the change line is 6.01:1 on the green and 7.13:1 on the red; the title
 * and extra lines keep --muted at 5.53:1 / 5.39:1; the big figure keeps
 * --ink at 14.57:1 / 14.19:1. Nothing fell out of AA. The border is the
 * same hue at 55% toward white -- its job is only to keep a tinted tile
 * from butting into a neutral one, not to carry meaning, and it is
 * deliberately far weaker than the text.
 *
 * "Positive development" is read as the sign of `delta` (= this week
 * minus the compared week) for all six tile measures, every one of which
 * is "more is better". An inverse measure added to this row would have to
 * invert the mapping rather than inherit it.
 *
 * `:has()` paints the ancestor tile from the descendant's attribute so JS
 * never has to walk the tree -- but the change line's colour is set on the
 * `[data-trend]` element *itself*, not through `:has()`. A browser
 * without `:has()` loses only the background wash and still shows the
 * coloured, signed delta line; the meaning survives the degradation. */
.stx-tile__change[data-trend="up"] {
  color: #256b34;
}

.stx-tile__change[data-trend="down"] {
  color: #9b2226;
}

.stx-tile:has(.stx-tile__change[data-trend="up"]) {
  background: #f0f8f2;
  border-color: #acd7b4;
}

.stx-tile:has(.stx-tile__change[data-trend="down"]) {
  background: #fdf0f1;
  border-color: #f3adaf;
}

.stx-tile__extra {
  margin: 0.45rem 0 0;
  padding-top: 0.35rem;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.stx-chart {
  margin: 2rem 0;
}

.stx-canvas {
  height: 320px;
}

.stx-canvas--tall {
  height: 420px;
}

/* The choropleth (M-17 T10). It sits in the same shared reading column
 * as every other box on this page and widens nothing: MapLibre sizes to
 * its container, so the container owns the size and no width is set at
 * all. The height is explicit for the same reason the ECharts canvases
 * need one — a height:auto MapLibre container collapses and renders
 * nothing, silently.
 *
 * The tokens here are the base reading-page set (--muted, --line, #fff).
 * The map shell's --asrm-* dark palette is not loaded on this page, and
 * the ramp was measured against the white card, not the #222222 panel:
 * grading it against the wrong surface is exactly how a "dark = more"
 * claim can be inverted by a placement nobody checked. */

.stx-map-canvas {
  height: 380px;
  border: 1px solid var(--line);
  background: #fff;
}

.stx-map-readout {
  min-height: 1.4em;
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.stx-map-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1rem;
  margin: 0.75rem 0 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.stx-map-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.stx-map-swatch {
  width: 14px;
  height: 14px;
  display: inline-block;
  border: 1px solid var(--line);
}

/* "No data in this frame" is drawn as an empty box, not as a tenth
 * shade — absence has to look like absence. */
.stx-map-swatch--outline {
  background: transparent;
  border: 1px dashed var(--muted);
}

.stx-map-legend-item--unmapped {
  color: var(--muted);
  font-style: italic;
}

/* When the map cannot be drawn the canvas is hidden and the status line
 * carries the reason, so the section never leaves an empty bordered
 * rectangle that reads as "this country carried nothing". */
.stx-map--fallback .stx-map-canvas {
  display: none;
}

/* The world list on the /stats/ index (owner ruling, 2026-10-24).
 *
 * Each row is a box that sizes to its own content, in the same flex-wrap
 * row as the Dashboard tiles and for the same reason: the owner rejected
 * stretched boxes on 2026-10-06, and a grid would widen every world to
 * the longest name. The list is deliberately not a table — a world is one
 * entity with three links to the same place, not a row of comparable
 * columns, and no column here means anything across rows except the name.
 *
 * Nothing in these selectors touches the reading column: `main` stays
 * base.html's, and these boxes live inside it. */
.stx-worldlist {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  list-style: none;
  margin: 1.25rem 0 1.5rem;
  padding: 0;
}

.stx-world {
  flex: 0 1 auto;
  min-width: 13rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  background: #fff;
}

.stx-world__name {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.stx-world__meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stx-world__links {
  margin: 0.45rem 0 0;
  padding-top: 0.35rem;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
}
