/* ============================================================
   Near misses: what a survival table adds on top of ../styles.css.
   Built 2026-09-28 with the South Korea page. Every near-miss page
   links ../styles.css first and this file second, and nothing here
   redefines a rule a death page depends on: every selector below is
   either new or scoped under body.near-miss.

   The survival treatment, in four parts:
     1. Cells before the turn and in the turn column use the death
        ramp (sev-0 to sev-3, cream to oxblood) from styles.css.
     2. The turn column (th.turn, td.turn) gets a heavy ink rule on
        its left, a teal header and a stamp naming what stopped it,
        in one of six fixed words: parties, courts, voters, soldiers,
        protest, legislature.
     3. Cells after the turn use a second ramp (rec-0 to rec-3) that
        runs from cream to teal instead of to oxblood, so the eye
        reads a peak and a way back down. Same 0 to 3 scale, same
        meaning per step; only the ink changes.
     4. A bar strip above the table (.rise-fall) draws the total of
        the five rows per column. A death draws bars that climb to
        the right; a near miss draws bars that climb and then fall.
   Palette is the page's own: teal #17705F is the recovery ink, no
   new colour is introduced.
   ============================================================ */

body.near-miss {
  --rec1: #d3e2d6;
  --rec2: #8fb8a6;
  --rec3: #17705f;
  --turn-rule: 6px solid var(--ink);
}

/* ---------- the recovery ramp, after the turn ---------- */
.rec-0 { background: var(--bg); }
.rec-1 { background: var(--rec1); }
.rec-2 { background: var(--rec2); }
.rec-3 { background: var(--rec3); color: var(--bg); }
.rec-2 .events li::before { background: #0f4f43; }
.rec-3 .events li::before { background: #bfe0d3; }
.rec-2 .events li.key::before { background: var(--ink); }
.rec-1 .events li.key::before,
.rec-0 .events li.key::before { background: var(--teal); }
.rec-3 .events li.key::before { background: var(--gold); }

/* ---------- the turn column ---------- */
body.near-miss thead th.turn {
  background: var(--teal);
  color: var(--bg);
  border-left: var(--turn-rule);
  border-right: 2px solid var(--ink);
  position: relative;
}
body.near-miss thead th.turn .since { color: #cfe6dc; }
body.near-miss tbody td.turn {
  border-left: var(--turn-rule);
  border-right: 2px solid var(--ink);
}
.turn-stamp {
  display: inline-block;
  margin-top: 8px;
  font-family: var(--caps);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  background: var(--bg);
  color: var(--teal);
  border: 2px solid var(--ink);
  padding: 3px 7px;
  transform: rotate(-2deg);
}

/* columns after the turn: a teal rule under the header instead of ink */
body.near-miss thead th.after { border-bottom-color: var(--teal); }

/* a header that carries a date the cell was last checked */
.asof {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--caps);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mic);
  border: 2px solid var(--mic);
  padding: 2px 6px;
}
td .events li.dated {
  border-left: 3px solid var(--mic);
  padding-left: 12px;
  margin-left: -2px;
}
td .events li.dated::before { display: none; }

/* shown by the script at the foot of the page when the check is old */
.stale-note {
  display: none;
  margin: 0 0 12px;
  padding: 10px 14px;
  border: 2px solid var(--mic);
  background: rgba(226, 59, 30, 0.07);
  font-size: 13px;
  line-height: 1.5;
}
html.is-stale .stale-note { display: block; }

/* ---------- case head: the outcome stamp ---------- */
.nm-verdict {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin: -6px 0 18px;
}
.nm-stamp {
  display: inline-block;
  font-family: var(--caps);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--teal);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 5px 12px;
  transform: rotate(-2deg);
}
.nm-verdict p {
  flex: 1 1 320px;
  font-size: 14px;
  line-height: 1.5;
}
.nm-verdict strong { color: var(--teal); }

/* ---------- the bar strip: total of the five rows per column ---------- */
.rise-fall {
  margin: 0 0 18px;
  border: 2px solid var(--ink);
  background: var(--bg);
  box-shadow: 5px 5px 0 var(--ink);
  padding: 14px 16px 10px;
}
.rise-fall .mag-label { display: block; margin-bottom: 10px; }
.rf-bars {
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), minmax(0, 1fr));
  gap: 6px;
  align-items: end;
  height: 120px;
  border-bottom: 2px solid var(--ink);
}
.rf-bar {
  position: relative;
  border: 2px solid var(--ink);
  border-bottom: none;
  min-height: 3px;
}
.rf-bar.turn { outline: 3px solid var(--ink); outline-offset: 2px; }
.rf-bar.turn span { top: -23px; }
.rf-bar span {
  position: absolute;
  top: -18px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--caps);
  font-size: 11px;
  color: var(--ink);
}
.rf-labels {
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}
.rf-labels span {
  font-family: var(--caps);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.25;
  text-align: center;
}
.rf-labels span.turn { color: var(--teal); }
.rf-note {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

/* the legend carries two ramps on a near-miss page */
.legend-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  margin-bottom: 8px;
}
.legend-row .ramp-name {
  font-family: var(--caps);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  min-width: 118px;
}
.legend-row .ramp-name.rec { color: var(--teal); }
.swatch.turn-swatch { border-left: 6px solid var(--ink); background: var(--teal); }

@media (max-width: 640px) {
  .rf-bars { height: 90px; gap: 3px; }
  .rf-labels { gap: 3px; }
  .rf-labels span { font-size: 8px; letter-spacing: 0.02em; }
  .legend-row .ramp-name { min-width: 0; width: 100%; }
}
