/* Lottery ticket explorable.
 *
 * Layout and typography follow the proportions of Google PAIR's AI Explorables:
 * an 850px page column with a narrower 750px measure for prose, 16px/1.55 body,
 * teal links, and figures allowed to use the full column width.
 *
 * Data colours are the Okabe-Ito assignments from src/figures/style.py, so a
 * method keeps the same colour here as in the static PNGs in the repository.
 */

:root {
  --page: 850px;
  --measure: 750px;

  --ink: #3c4043;
  --ink-strong: #202124;
  --muted: #6b6b6b;
  --rule: #e3e3e3;
  --surface: #ffffff;
  --surface-alt: #f8f9fa;

  --link: #00695c;
  --link-hover: #ff4081;

  /* Okabe & Ito, matched to src/figures/style.py */
  --blue: #0072b2;
  --aqua: #009e73;
  --amber: #e69f00;
  --violet: #7b4ea3;
  --red: #cc3311;
  --magenta: #cc79a7;
  --orange: #d55e00;
  --grey: #6b6b6b;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  /* Safari on iOS otherwise inflates body text when the phone turns landscape. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  padding: 0 16px 120px;
  max-width: var(--page);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}

/* ---- Prose measure -------------------------------------------------- */

p, ul, ol, blockquote, .note, h2, h3, h4, .byline, .toc, pre {
  max-width: var(--measure);
}

h1, h2, h3, h4 {
  color: var(--ink-strong);
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 34px;
  line-height: 1.25;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 26px;
  line-height: 1.3;
  margin: 72px 0 4px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}

h3 { font-size: 20px; margin: 40px 0 4px; }
h4 { font-size: 17px; margin: 28px 0 4px; }

p { margin: 0 0 18px; }
h2 + p, h3 + p, h4 + p { margin-top: 12px; }

a { color: var(--link); text-decoration: none; border-bottom: 1px solid rgba(0, 105, 92, 0.25); }
a:hover { color: var(--link-hover); border-bottom-color: rgba(255, 64, 129, 0.4); }

strong { font-weight: 600; color: var(--ink-strong); }
em { font-style: italic; }

ul, ol { padding-left: 22px; margin: 0 0 18px; }
li { margin-bottom: 8px; }

blockquote {
  margin: 24px 0;
  padding: 14px 20px;
  border-left: 3px solid var(--blue);
  background: var(--surface-alt);
  color: var(--ink);
}
blockquote p:last-child { margin-bottom: 0; }

code {
  font-family: var(--mono);
  font-size: 0.87em;
  background: var(--surface-alt);
  padding: 1px 4px;
  border-radius: 3px;
}

pre {
  background: var(--surface-alt);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 24px;
}
pre code { background: none; padding: 0; font-size: 13px; }

.tok-com { color: var(--muted); font-style: italic; }
.tok-str { color: var(--aqua); }
.tok-kw  { color: var(--violet); }
.tok-num { color: var(--blue); }
.tok-fn  { color: var(--orange); }

/* ---- Masthead ------------------------------------------------------- */

.masthead {
  padding: 56px 0 0;
  margin-bottom: 40px;
}

.eyebrow {
  font-size: 13px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

.byline {
  font-size: 19px;
  line-height: 1.5;
  color: var(--muted);
  margin: 14px 0 0;
}

.masthead-meta {
  margin-top: 24px;
  font-size: 14px;
  color: var(--muted);
}
.masthead-meta a { border-bottom-color: transparent; }

/* ---- Contents ------------------------------------------------------- */

.toc {
  margin: 40px 0 0;
  padding: 20px 24px;
  background: var(--surface-alt);
  border-radius: 8px;
  font-size: 15px;
}
.toc h4 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.toc ol { margin: 0; padding-left: 20px; }
.toc li { margin-bottom: 5px; }

/* ---- Figures -------------------------------------------------------- */

figure {
  margin: 32px 0 36px;
  max-width: var(--page);
}

figure img {
  display: block;
  width: 100%;
  height: auto;
}

.fig-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-strong);
  margin-bottom: 2px;
  line-height: 1.3;
}

.fig-sub {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.45;
  max-width: var(--measure);
}

figcaption {
  font-size: 13.5px;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.5;
  max-width: var(--measure);
}

.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

/* A chart is most of a phone screen, so up-and-down drags have to stay with the
   page. Sideways ones are the charts' own: see LT.MOVE in js/toolkit.js. */
.chart svg, .chart canvas { touch-action: pan-y; }

.axis-line { stroke: #333; stroke-width: 0.9; fill: none; }
.tick line { stroke: #333; stroke-width: 0.9; }
.tick text { fill: var(--ink); font-size: 11px; font-family: var(--sans); }
.axis-label { fill: var(--ink); font-size: 12.5px; font-family: var(--sans); }
.rule-dashed { stroke: var(--grey); stroke-dasharray: 5 3; stroke-width: 1; fill: none; }
.series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-dim { opacity: 0.14; }
.annot { fill: var(--muted); font-size: 12px; font-family: var(--sans); }

/* ---- Legend --------------------------------------------------------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 10px 0 0;
  font-size: 13px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 2px 7px 2px 4px;
  border-radius: 20px;
  border: 1px solid transparent;
  user-select: none;
  transition: background 120ms, opacity 120ms;
}
.legend-item:hover { background: var(--surface-alt); }
.legend-item.off { opacity: 0.35; }
.legend-swatch { width: 20px; height: 3px; border-radius: 2px; flex: none; }
/* Charts may add a small marker glyph to a legend entry. Override the
   full-width sizing that .chart svg applies to plot canvases, or the glyph
   inflates to the width of the figure. */
.legend-item svg { display: block; flex: none; width: auto; height: auto; }
.legend-item span { white-space: nowrap; }

/* ---- Controls ------------------------------------------------------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin: 14px 0 4px;
  padding: 12px 16px;
  background: var(--surface-alt);
  border-radius: 8px;
  font-size: 14px;
}
.control { display: flex; align-items: center; gap: 10px; }
.control label { color: var(--muted); white-space: nowrap; }
.control input[type="range"] { width: 190px; accent-color: var(--blue); }
.control output { font-variant-numeric: tabular-nums; font-weight: 600;
  color: var(--ink-strong); min-width: 62px; }

.btn-group { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.btn-group button {
  font: inherit; font-size: 13px; padding: 5px 12px; border: 0;
  background: var(--surface); color: var(--ink); cursor: pointer;
  border-right: 1px solid var(--rule);
}
.btn-group button:last-child { border-right: 0; }
.btn-group button:hover { background: var(--surface-alt); }
.btn-group button[aria-pressed="true"] { background: var(--blue); color: #fff; }

/* ---- Tooltip -------------------------------------------------------- */

.tip {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity 90ms;
  background: rgba(32, 33, 36, 0.94);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.45;
  padding: 7px 10px;
  border-radius: 5px;
  max-width: 260px;
}
.tip.on { opacity: 1; }
.tip b { color: #fff; font-weight: 600; }
.tip .tip-key { color: rgba(255, 255, 255, 0.62); }

/* ---- Scrollytelling ------------------------------------------------- */

.scrolly { position: relative; margin: 40px 0 56px; }

/* On a wide screen the block breaks out of the 850px column so the pinned
   graphic and the step cards can sit side by side instead of the cards
   covering the data. --stepw is reserved on the right for the cards. */
@media (min-width: 1080px) {
  .scrolly {
    --scrollyw: min(1200px, 94vw);
    --stepw: 400px;
    width: var(--scrollyw);
    margin-left: calc((100% - var(--scrollyw)) / 2);
  }
  .scrolly-graphic { padding-right: calc(var(--stepw) + 40px); }
  .scrolly .step { max-width: var(--stepw); }
}

.scrolly-graphic {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--surface);
  z-index: 1;
}

/* The step column is pulled back over the pinned graphic, so it must not
   swallow pointer events: without this, every chart inside a scrolly block is
   unclickable because a full-width transparent div covers it. The cards
   themselves take events back. */
.scrolly-steps {
  position: relative;
  z-index: 2;
  margin-top: -100vh;
  pointer-events: none;
}
.scrolly-steps .step { pointer-events: auto; }

.step {
  max-width: 420px;
  margin: 0 0 68vh auto;
  padding: 20px 22px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(3px);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  opacity: 0.35;
  transition: opacity 200ms;
}
.step.active { opacity: 1; }
.step:first-child { margin-top: 12vh; }
.step:last-child { margin-bottom: 24vh; }
.step p { max-width: none; margin-bottom: 10px; font-size: 15.5px; }
.step p:last-child { margin-bottom: 0; }
.step-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin-bottom: 6px; font-weight: 600;
}

/* ---- Tables --------------------------------------------------------- */

.table-wrap { overflow-x: auto; margin: 22px 0 8px; max-width: var(--page); }

table {
  border-collapse: collapse;
  font-size: 13.5px;
  width: 100%;
  min-width: 560px;
}
th, td {
  text-align: right;
  padding: 7px 12px;
  border-bottom: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; white-space: normal; }
thead th {
  font-weight: 600;
  color: var(--ink-strong);
  border-bottom: 1.5px solid #bdbdbd;
  vertical-align: bottom;
  font-size: 13px;
}
tbody tr:hover { background: var(--surface-alt); }
td.hi { font-weight: 600; color: var(--red); }
.table-note { font-size: 13px; color: var(--muted); margin-top: 8px; max-width: var(--measure); }

/* ---- Callouts ------------------------------------------------------- */

.note {
  margin: 26px 0;
  padding: 14px 18px;
  border-radius: 8px;
  background: #f1f7f6;
  border: 1px solid #cfe3e0;
  font-size: 15px;
}
.note p:last-child { margin-bottom: 0; }
.note-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; color: var(--link); margin-bottom: 6px;
}

/* ---- Branch navigation ---------------------------------------------- */

.branch-nav {
  margin: 34px 0;
  padding: 14px 18px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
}
.branch-nav-label { font-size: 13.5px; color: var(--muted); margin-bottom: 10px; }
.branch-nav-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.branch-nav-btns button {
  font: inherit;
  font-size: 13.5px;
  padding: 6px 13px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--ink);
  cursor: pointer;
}
.branch-nav-btns button:hover { color: var(--ink-strong); border-color: var(--muted); }
.branch-nav-btns button[aria-pressed="true"] {
  background: var(--link);
  border-color: var(--link);
  color: #fff;
  font-weight: 600;
}
.branch-nav-btns > a { font-size: 13.5px; margin-left: auto; white-space: nowrap; }
.branch-hidden { display: none; }

/* ---- Appendix ------------------------------------------------------- */

.appendix-item {
  margin: 26px 0;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0 18px;
  background: var(--surface);
}
.appendix-item > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  color: var(--ink-strong);
  padding: 14px 0;
}
.appendix-item > summary:hover { color: var(--link); }
.appendix-item[open] > summary { border-bottom: 1px solid var(--rule); margin-bottom: 14px; }
.appendix-item > :last-child { margin-bottom: 18px; }

/* ---- Section progress rail ------------------------------------------ */

.rail {
  position: fixed;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  font-size: 12px;
  display: none;
  /* Only the links are clickable, so the rail's empty column never blocks a
     chart that a wide scrolly block has extended underneath it. */
  pointer-events: none;
}
.rail a { pointer-events: auto; }
.rail a {
  display: block;
  padding: 3px 0 3px 14px;
  color: var(--muted);
  border: 0;
  border-left: 2px solid var(--rule);
  line-height: 1.3;
  max-width: 130px;
}
.rail a:hover { color: var(--ink-strong); }
.rail a.on { color: var(--link); border-left-color: var(--link); font-weight: 600; }
@media (min-width: 1240px) {
  .rail { display: block; }
  /* Once the rail is visible it owns the left ~170px, so keep wide scrolly
     blocks out of that column instead of drawing charts on top of it. */
  .scrolly { --scrollyw: min(1200px, calc(100vw - 380px)); }
}

/* ---- Footer --------------------------------------------------------- */

.colophon {
  margin-top: 90px;
  padding-top: 26px;
  border-top: 1px solid var(--rule);
  font-size: 14px;
  color: var(--muted);
}
.colophon h4 { font-size: 15px; margin: 22px 0 6px; color: var(--ink); }
.colophon ul { padding-left: 20px; }
.colophon li { margin-bottom: 6px; }

/* ---- Responsive ----------------------------------------------------- */

/* Below the width at which the graphic and the cards fit side by side, the
   graphic un-sticks and the cards become ordinary blocks underneath it. This
   breakpoint must match MOBILE in js/scroll.js, or there is a band of widths
   where a pinned chart sits under a card. */
@media (max-width: 1079px) {
  .branch-nav { display: none; }
  .scrolly-graphic { position: relative; height: auto; top: auto; margin-bottom: 20px; }
  .scrolly-steps { margin-top: 0; }
  .step {
    max-width: none; margin: 0 0 28px; opacity: 1;
    background: var(--surface-alt); backdrop-filter: none; box-shadow: none;
  }
  .step:first-child { margin-top: 0; }
  .step:last-child { margin-bottom: 0; }
}

@media (max-width: 640px) {
  body { font-size: 15.5px; }
  h1 { font-size: 27px; }
  h2 { font-size: 22px; margin-top: 52px; }
  .tick text { font-size: 10px; }

  /* A slider gets its own row, with its label on the line above: the label,
     track and readout together are wider than a phone, and sharing one line
     leaves a track too short to aim at. */
  .control { flex: 1 1 100%; flex-wrap: wrap; gap: 2px 10px; }
  .control label { flex: 1 1 100%; white-space: normal; }
  .control input[type="range"] { flex: 1 1 90px; width: auto; }
  .control output { text-align: right; }
}

/* Touch input has no hover state to aim with, so the things you press get big
   enough to hit. Apple's guidance is 44px; these sit just under it because the
   controls are inline with text. */
@media (pointer: coarse) {
  .legend-item { padding: 8px 10px 8px 6px; }
  .btn-group button { padding: 10px 16px; }
  .control input[type="range"] { height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
