/* Plots for "The Road to Doomsday". Tokens first; everything below is written against roles. */

/* Math labels use MathJax's own TeX fonts (same CDN the page already loads MathJax from),
   so x, t, k in the figures match the inline math in the text. */
/* The MathJax font files carry (near-)zero vertical metrics in the table Safari reads, so Safari gives
   the text a 2px line box and clips the glyphs. The overrides force normal Computer Modern metrics. */
@font-face {
  font-family: 'DD Math'; font-style: normal; font-weight: 400; font-display: swap;
  ascent-override: 95%; descent-override: 25%; line-gap-override: 0%;
  src: url('https://cdn.jsdelivr.net/npm/mathjax@3/es5/output/chtml/fonts/woff-v2/MathJax_Main-Regular.woff') format('woff');
}
@font-face {
  font-family: 'DD Math'; font-style: italic; font-weight: 400; font-display: swap;
  ascent-override: 95%; descent-override: 25%; line-gap-override: 0%;
  src: url('https://cdn.jsdelivr.net/npm/mathjax@3/es5/output/chtml/fonts/woff-v2/MathJax_Math-Italic.woff') format('woff');
}
/* MathJax renders its Computer Modern at ~1.2x the surrounding font size; match it. */
/* line-height is set explicitly: the MathJax font files declare (near-)zero ascent/descent, and Safari
   would otherwise give these spans a 2px inline box and may clip the glyphs to it */
.dd-f { display: inline-block; font-family: 'DD Math', 'Latin Modern Math', 'Times New Roman', serif; font-style: normal; font-weight: 400; font-size: 1.2em; line-height: 1.25; }
.dd-f .dd-f { display: inline; }
.dd-f i { font-style: italic; }
.dd-f .dd-f { font-size: 1em; }
/* Sub/superscripts as plain inline-block spans: immune to the theme's sub/sup rules in every browser. */
.dd-sub, .dd-sup { display: inline-block; font-size: .72em; line-height: 1.25; }
.dd-sub { vertical-align: -.2em; }
.dd-sup { vertical-align: .55em; }

.dd {
  --dd-card: #ffffff;
  --dd-ink: #1d2126;
  --dd-muted: #6b7178;
  --dd-faint: #9aa0a6;
  --dd-grid: #ecebe6;
  --dd-axis: #c9c7bf;
  --dd-data: #d68a1e;          /* historical points: amber */
  --dd-doom: #c81e1e;          /* the doomsday line and its year: red, reserved for this */
  --dd-model: #2f6fdb;
  --dd-model-soft: rgba(47, 111, 219, .12);
  --dd-track: #e6e4dd;
  --dd-border: #e8e6df;
  --dd-shadow: 0 1px 2px rgba(20, 20, 10, .04), 0 8px 28px rgba(20, 20, 10, .06);
  --dd-thumb-shadow: 0 1px 4px rgba(0, 0, 0, .18);
  margin: 2rem 0 2.25rem; padding: 20px 20px 16px;
  background: var(--dd-card); border: 1px solid var(--dd-border); border-radius: 16px; box-shadow: var(--dd-shadow);
  color: var(--dd-ink);
  -webkit-font-smoothing: antialiased;
}
body.dark .dd {
  --dd-card: #2a2d38;          /* one step above the theme's dark page (#23252f) */
  --dd-ink: #e8e9eb;
  --dd-muted: #a3aab3;
  --dd-faint: #7c848e;
  --dd-grid: #343845;
  --dd-axis: #4d5260;
  --dd-data: #f0b454;
  --dd-doom: #ff5a4e;
  --dd-model: #6aa1ff;
  --dd-model-soft: rgba(106, 161, 255, .16);
  --dd-track: #3c404d;
  --dd-border: #363a47;
  --dd-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .3);
  --dd-thumb-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.dd.dd-compact { padding: 16px 12px 12px; border-radius: 12px; }

/* header: title + legend */
.dd-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 20px; margin-bottom: 6px; }
.dd-title { font-weight: 600; font-size: 1em; line-height: 1.35; }
.dd-title .dd-f { font-weight: 400; }
.dd-legend { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: .82em; color: var(--dd-muted); }
/* Swatches hang off the text baseline and are lifted to the centre of the x-height, so they align with
   the letters even when the item is set in the (tall) math font. */
.dd-legend > span { display: inline-flex; align-items: baseline; gap: 7px; white-space: nowrap; }
.dd-sw { flex: none; display: inline-block; position: relative; }
.dd-sw-point { width: 9px; height: 9px; border-radius: 50%; background: var(--dd-data); top: 0; }
.dd-sw-line { width: 18px; height: 3px; border-radius: 2px; background: var(--dd-model); top: -.17em; }
.dd-sw-asym { width: 0; height: 14px; border-left: 1.5px dashed var(--dd-doom); margin: 0 3px; top: .15em; }
.dd-sw-handle { width: 12px; height: 12px; border-radius: 50%; box-sizing: border-box; border: 2px solid var(--dd-model); background: var(--dd-card); top: .09em; }

/* plot */
.dd-fig { position: relative; touch-action: pan-y; }
.dd-fig svg { display: block; width: 100%; height: auto; overflow: visible; font-family: inherit; }
.dd-grid line { stroke: var(--dd-grid); stroke-width: 1; shape-rendering: crispEdges; }
.dd-axes .dd-baseline, .dd-axes .dd-tick { stroke: var(--dd-axis); stroke-width: 1; shape-rendering: crispEdges; }
.dd-axes .dd-zero { stroke: var(--dd-axis); stroke-width: 1; stroke-dasharray: 2 4; }
.dd-mathaxes .dd-axes .dd-zero { stroke-dasharray: none; shape-rendering: crispEdges; }
.dd-ticks text { fill: var(--dd-muted); font-size: 15px; font-variant-numeric: tabular-nums; }
/* On the textbook plot the tick numbers sit inside the grid; a card-coloured halo keeps gridlines from crossing them. */
.dd-mathaxes .dd-ticks text:not(.dd-axis-label) { paint-order: stroke; stroke: var(--dd-card); stroke-width: 5px; stroke-linejoin: round; }
.dd-ticks .dd-axis-title { fill: var(--dd-faint); font-size: 14px; letter-spacing: .02em; }
.dd-ticks .dd-zero-label { fill: var(--dd-faint); font-size: 18px; }
.dd-ticks .dd-axis-label.dd-f { fill: var(--dd-muted); font-style: italic; font-size: 25px; letter-spacing: 0; } /* = inline MathJax size at the article's 21px body */
.dd-curve { fill: none; stroke: var(--dd-model); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.dd-point { fill: var(--dd-data); stroke: var(--dd-card); stroke-width: 1.5; transition: r .1s ease; }
.dd-x0 { fill: var(--dd-card); stroke: var(--dd-model); stroke-width: 2; pointer-events: none; }
.dd-x0-ring { fill: var(--dd-model-soft); pointer-events: none; opacity: 0; transition: opacity .12s ease; }
.dd-x0-hit { fill: transparent; cursor: ns-resize; outline: none; touch-action: none; }
.dd:has(.dd-x0-hit:hover) .dd-x0-ring, .dd:has(.dd-x0-hit:focus-visible) .dd-x0-ring, .dd-dragging .dd-x0-ring { opacity: 1; }
.dd-dragging .dd-x0 { fill: var(--dd-model); }
.dd-dragging .dd-overlay { pointer-events: none; }
.dd-asym { stroke: var(--dd-doom); stroke-width: 1.5; stroke-dasharray: 5 4; }
.dd-asym-label { fill: var(--dd-data); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.dd-hover line { stroke: var(--dd-faint); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.dd-hdot { fill: var(--dd-model); stroke: var(--dd-card); stroke-width: 2; pointer-events: none; }
.dd-overlay { cursor: crosshair; touch-action: pan-y; }

/* tooltip: inverted ink chip */
.dd-tip {
  position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none;
  padding: 7px 10px; border-radius: 8px; background: var(--dd-ink); color: var(--dd-card);
  font-size: 14px; line-height: 1.4; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.dd-tip[hidden] { display: none; }
.dd-tip-head { font-weight: 600; }
.dd-tip-head .dd-f { font-size: 1.1em; }
.dd-tip-rows { display: grid; grid-template-columns: auto auto; gap: 0 12px; align-items: baseline; }
.dd-tip-k { opacity: .65; }
.dd-tip-k.dd-f { font-size: 1.1em; opacity: .8; }
.dd-tip-v { text-align: right; }

/* formula / readout */
.dd-readout { text-align: center; margin: 8px 0 14px; font-size: 1em; line-height: 1.5; color: var(--dd-ink); font-variant-numeric: tabular-nums; }
.dd-readout .dd-f { white-space: nowrap; }
.dd-v { color: var(--dd-model); }
.dd-vd { color: var(--dd-doom); }

/* controls */
.dd-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 32px; padding-top: 14px; border-top: 1px solid var(--dd-border); }
.dd-narrow .dd-controls { grid-template-columns: 1fr; }
.dd-control { min-width: 0; }
.dd-label {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 12px;
  margin: 0; font-size: .85em; font-weight: 400; color: var(--dd-muted);
}
.dd-name { display: inline-flex; align-items: baseline; gap: .55em; }
/* Safari clips the low-metric MathJax webfont in control labels even with
   explicit line heights. Use a text font with full ascent/descent metrics here. */
.dd-label .dd-f { font-family: 'Times New Roman', serif; }
.dd-name .dd-f { color: var(--dd-ink); }
.dd-desc .dd-f { color: inherit; }
.dd-out { color: var(--dd-ink); white-space: nowrap; }
.dd-out output { font-weight: 600; font-variant-numeric: tabular-nums; }
.dd-num {
  width: 5.4em; padding: 2px 6px; margin: -3px 0; border: 1px solid var(--dd-axis); border-radius: 6px;
  background: var(--dd-card); color: inherit; font: inherit; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right;
}
.dd-num:hover { border-color: var(--dd-muted); }
.dd-num:focus { outline: none; border-color: var(--dd-model); box-shadow: 0 0 0 3px var(--dd-model-soft); }
.dd-out small { font-size: .85em; color: var(--dd-muted); }
.dd-out small .dd-sup { font-size: .8em; vertical-align: .45em; }
.dd-hint { display: flex; justify-content: space-between; margin-top: -2px; font-size: .75em; color: var(--dd-faint); font-variant-numeric: tabular-nums; }
.dd-hint-drag { display: block; margin-top: 6px; line-height: 1.4; }

.dd-label input[type=range] {
  --p: 0%;
  flex: 1 0 100%; -webkit-appearance: none; appearance: none; width: 100%; min-width: 0; height: 28px; margin: 2px 0 0;
  background: transparent; cursor: pointer;
}
.dd-label input[type=range]:focus { outline: none; }
.dd-label input[type=range]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--dd-model) 0 var(--p), var(--dd-track) var(--p) 100%);
}
.dd-label input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; box-sizing: border-box; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%;
  background: var(--dd-card); border: 2px solid var(--dd-model); box-shadow: var(--dd-thumb-shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.dd-label input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.1); }
.dd-label input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 5px var(--dd-model-soft), var(--dd-thumb-shadow); }
.dd-label input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--dd-track); }
.dd-label input[type=range]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--dd-model); }
.dd-label input[type=range]::-moz-range-thumb {
  box-sizing: border-box; width: 20px; height: 20px; border-radius: 50%; background: var(--dd-card);
  border: 2px solid var(--dd-model); box-shadow: var(--dd-thumb-shadow);
}
.dd-label input[type=range]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 5px var(--dd-model-soft), var(--dd-thumb-shadow); }

/* footer: data table (left) and reset (right) */
.dd-footer { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px 16px; margin-top: 12px; }
.dd-reset {
  margin-left: auto; flex: none; font: inherit; font-size: .78em; line-height: 1.5; color: var(--dd-muted);
  background: none; border: 1px solid var(--dd-border); border-radius: 999px; padding: 3px 12px; cursor: pointer;
}
.dd-reset:hover { color: var(--dd-ink); border-color: var(--dd-axis); }
.dd-reset:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--dd-model-soft); border-color: var(--dd-model); }

/* table view (collapsed) */
.dd-data { min-width: 0; font-size: .78em; line-height: 1.5; color: var(--dd-muted); }
.dd-data summary { cursor: pointer; list-style: none; display: inline-block; padding: 4px 0; }
.dd-data summary::-webkit-details-marker { display: none; }
.dd-data summary::before { content: '\25B8'; display: inline-block; width: 1em; transition: transform .15s; }
.dd-data[open] summary::before { transform: rotate(90deg); }
.dd-data summary:hover { color: var(--dd-ink); }
.dd-data table { margin: 6px 0 0; border-collapse: collapse; font-size: 1em; color: var(--dd-ink); font-variant-numeric: tabular-nums; background: none; }
.dd-data th { text-align: left; font-weight: 600; padding: 2px 18px 4px 0; color: var(--dd-muted); border: 0; border-bottom: 1px solid var(--dd-border); background: none; }
.dd-data td { padding: 1px 18px 1px 0; border: 0; background: none; }
.dd-data tr { background: none; }
