@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url(fonts/newsreader-latin-standard-normal.woff2) format("woff2-variations");
}
@font-face {
  font-family: "Newsreader";
  font-style: italic;
  font-display: swap;
  font-weight: 200 800;
  src: url(fonts/newsreader-latin-standard-italic.woff2) format("woff2-variations");
}

:root {
  --paper: #f6f3ec;
  --card: #fbfaf6;
  --ink: #1f1d1a;
  --muted: #6d675d;
  --faint: #857f73;
  --rule: #dcd6c9;
  --track: #d3ccbe;
  --accent: #2f4a5c;
  --good: #4f7a5e;
  --mixed: #9a7630;
  --bad: #a54a3b;
  --serif: "Newsreader", "Iowan Old Style", Charter, Georgia, serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --indent: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151514;
    --card: #1c1c1a;
    --ink: #ebe6dc;
    --muted: #a19a8d;
    --faint: #6f6a61;
    --rule: #34322e;
    --track: #2c2a27;
    --accent: #9fb8c8;
    --good: #7fae8d;
    --mixed: #d4b067;
    --bad: #d07a68;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  padding: 0 20px env(safe-area-inset-bottom);
}

button, input { font: inherit; color: inherit; }

h1, h2, h3, p { margin: 0; }

.valence-good { --v-color: var(--good); }
.valence-mixed { --v-color: var(--mixed); }
.valence-bad { --v-color: var(--bad); }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--v-color, var(--faint));
  flex: none;
}

.label, .eyebrow, .section-head h2, .timeframe {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.text-btn {
  font-family: var(--sans);
  font-size: 13px;
  background: none;
  border: 0;
  padding: 6px 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

/* ---------- masthead ---------- */

.masthead {
  max-width: 680px;
  margin: 0 auto;
  padding: 56px 0 28px;
}

.masthead h1 {
  margin-top: 14px;
  font-size: clamp(36px, 10vw, 64px);
  line-height: 1.02;
  font-weight: 500;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.subtitle {
  margin-top: 16px;
  font-size: 21px;
  line-height: 1.35;
  font-style: italic;
  color: var(--muted);
  text-wrap: pretty;
}

.intro {
  margin-top: 20px;
  text-wrap: pretty;
}

.note {
  margin-top: 20px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
}

/* ---------- outlook ---------- */

.outlook {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 0 8px;
  border-top: 1px solid var(--rule);
}

.outlook-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  gap: 2px;
}

.outlook-bar .seg {
  flex-basis: 0;
  background: var(--v-color);
  transition: flex-grow 0.25s ease;
}

.outlook-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  margin: 12px 0 0;
  font-family: var(--sans);
  font-size: 13px;
}

.outlook-legend div { display: flex; align-items: baseline; gap: 8px; }
.outlook-legend dt { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.outlook-legend dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- layout ---------- */

.layout {
  max-width: 680px;
  margin: 0 auto;
  display: grid;
  gap: 40px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 28px 0 14px;
  border-bottom: 1px solid var(--ink);
  margin-bottom: 20px;
}

/* ---------- tree ---------- */

.root-card .root-title {
  margin-top: 6px;
  font-size: 28px;
  font-weight: 500;
  line-height: 1.15;
}

.root-card .summary { margin-top: 6px; }

.fork { margin-top: 18px; }

.fork-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  justify-content: space-between;
}

.fork-q {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: none;
  border: 0;
  padding: 4px 0;
  text-align: left;
  font-style: italic;
  font-size: 17px;
  color: var(--accent);
  cursor: pointer;
}

.fork-q::before {
  content: "";
  flex: none;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 6px solid currentColor;
  transform: translateY(-2px);
  transition: transform 0.15s ease;
}

.fork-q[aria-expanded="false"]::before { transform: translateY(-2px) rotate(-90deg); }

.children {
  list-style: none;
  margin: 8px 0 0;
  padding: 0 0 0 var(--indent);
  border-left: 1px solid var(--rule);
}

.node { padding: 14px 0 14px; }
.node + .node { border-top: 1px solid var(--rule); }
.children .children .node + .node { border-top-style: dotted; }

.head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.title {
  font-size: 20px;
  font-weight: 560;
  line-height: 1.2;
  letter-spacing: -0.005em;
  text-align: left;
}

.children .children .title { font-size: 18px; }

.title-btn {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.title-btn .chev {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 8px;
  border-right: 1.5px solid var(--faint);
  border-bottom: 1.5px solid var(--faint);
  transform: translateY(-3px) rotate(45deg);
  transition: transform 0.15s ease;
}

.title-btn[aria-expanded="true"] .chev { transform: translateY(0) rotate(-135deg); }

.nums {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: none;
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
}

.pct { font-size: 17px; font-weight: 600; }
.base { font-size: 12px; color: var(--muted); }
.changed .pct { color: var(--accent); }

.summary {
  margin-top: 4px;
  color: var(--ink);
  opacity: 0.86;
  text-wrap: pretty;
}

/* ---------- editing ---------- */

.edit {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.range {
  flex: 1;
  min-width: 0;
  height: 28px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  --v: 0%;
  --b: 0%;
}

.range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--ink) var(--v), var(--track) var(--v));
}

.changed .range::-webkit-slider-runnable-track {
  background:
    linear-gradient(to right, transparent calc(var(--b) - 1px), var(--muted) calc(var(--b) - 1px), var(--muted) calc(var(--b) + 1px), transparent calc(var(--b) + 1px)) 0 -3px / 100% 10px no-repeat,
    linear-gradient(to right, var(--accent) var(--v), var(--track) var(--v));
}

.range::-moz-range-track { height: 4px; border-radius: 2px; background: var(--track); }
.range::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--ink); }
.changed .range::-moz-range-progress { background: var(--accent); }

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--card);
  border: 1.5px solid var(--ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
}

.range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--card);
  border: 1.5px solid var(--ink);
}

.range:disabled { cursor: default; opacity: 0.45; }

.number-wrap {
  display: flex;
  align-items: baseline;
  flex: none;
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 16px;
}

.number {
  width: 3.4em;
  border: 0;
  background: transparent;
  padding: 3px 2px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.number::-webkit-inner-spin-button, .number::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.number:focus-visible { outline: none; }
.number-wrap:focus-within { border-bottom-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 2px; }
.number:disabled { opacity: 0.5; }
.unit { color: var(--muted); padding-right: 2px; }

.lock {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  position: relative;
  color: var(--faint);
}

/* A small padlock, drawn in CSS. */
.lock::before, .lock::after { content: ""; position: absolute; left: 50%; }
.lock::before {
  width: 8px;
  height: 7px;
  top: 8px;
  transform: translateX(-50%) translateX(3px);
  border: 1.5px solid currentColor;
  border-bottom: 0;
  border-radius: 5px 5px 0 0;
  transition: transform 0.15s ease;
}
.lock::after {
  width: 12px;
  height: 9px;
  top: 15px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: currentColor;
}
.lock[aria-pressed="true"] { color: var(--ink); background: var(--track); }
.lock[aria-pressed="true"]::before { transform: translateX(-50%); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* ---------- end worlds ---------- */

.abs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
}

.abs-label { flex: 1; }
.abs-val { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.abs-val::after { content: " of all worlds"; font-weight: 400; color: var(--muted); }

/* ---------- details ---------- */

.more {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  font-size: 16px;
}

.more > * + * { margin-top: 10px; }
.more .label { margin-top: 16px; }
.signposts { margin: 6px 0 0; padding-left: 18px; }
.signposts li + li { margin-top: 4px; }
.origin { font-family: var(--sans); font-size: 12px; color: var(--muted); }

.flash > .card { animation: flash 1.6s ease; }
@keyframes flash {
  0%, 30% { background: color-mix(in srgb, var(--accent) 12%, transparent); }
  100% { background: transparent; }
}

/* ---------- ranked ---------- */

.ranked ol { list-style: none; margin: 0; padding: 0; }

.rank a {
  display: block;
  padding: 10px 0 12px;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}

.rank-line { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.rank-title { font-size: 17px; font-weight: 520; }
.rank-val { font-family: var(--sans); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rank-path { display: block; font-family: var(--sans); font-size: 12px; color: var(--muted); margin-top: 1px; }

.bar {
  display: block;
  height: 5px;
  margin-top: 7px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
}

.bar .fill {
  display: block;
  height: 100%;
  background: var(--v-color);
  transition: width 0.25s ease;
}

.rank a:hover .rank-title { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* ---------- footer ---------- */

.colophon {
  max-width: 680px;
  margin: 56px auto 0;
  padding: 20px 0 48px;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
}

.noscript { text-align: center; padding: 40px; }

/* ---------- wide ---------- */

@media (min-width: 960px) {
  body { font-size: 18px; padding: 0 48px; }
  :root { --indent: 28px; }

  .masthead, .outlook { max-width: 1180px; }
  .masthead { padding-top: 72px; }
  .masthead > * { max-width: 720px; }
  .outlook > * { max-width: 720px; }

  .layout {
    max-width: 1180px;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 72px;
    align-items: start;
  }

  .ranked { position: sticky; top: 0; max-height: 100vh; overflow-y: auto; padding-bottom: 24px; }

  .colophon { max-width: 1180px; }
  .colophon p { max-width: 720px; }
  .edit { max-width: 440px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* On the phone, keep the outcome bar in view while the visitor edits the map. */
@media (max-width: 959px) {
  html { scroll-padding-top: 90px; }
  .outlook {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--paper);
    padding: 12px 0 10px;
    border-bottom: 1px solid var(--rule);
  }
  .outlook .label { margin-bottom: 8px; }
  .outlook-legend { flex-wrap: nowrap; gap: 18px; margin-top: 8px; }
}
.outlook .label { margin-bottom: 10px; }

.p-note { font-family: var(--sans); font-size: 13px; color: var(--muted); }
#map-heading:focus { outline: none; }
