:root {
  --bg: #111113;
  --node-bg: #1b1c20;
  --node-border: #36373c;
  --text: #f2f2f3;
  --text-dim: #a1a2a8;
  --text-muted: #7c7d83;
  --edge: #e9e9eb;
  --edge-dim: #4a4b50;
  --green: #76b900;
  --red: #ff2a2a;
  --accent: var(--green);
  --radius: 12px;
  --border-w: 1.5px;
  --font: ui-sans-serif, system-ui, -apple-system, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Canvas */

.viewport {
  position: relative;
  overflow: hidden;
}

.world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.edges {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}

.edge {
  fill: none;
  stroke: var(--edge-dim);
  stroke-width: 1.5;
  stroke-linecap: round;
  transition: stroke 160ms ease, opacity 160ms ease;
}

.edge { marker-end: url(#arrow-dim); }

.edge.active { stroke: var(--edge); marker-end: url(#arrow); }
.edge.no-arrow { marker-end: none; }

.arrow path, .arrow-dim path {
  fill: none;
  stroke: var(--edge);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.arrow-dim path { stroke: var(--edge-dim); }

.edge.drawing {
  marker-end: none;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 900ms cubic-bezier(.65, 0, .35, 1) forwards;
}

@keyframes draw { to { stroke-dashoffset: 0; } }

.labels, .nodes {
  position: absolute;
  top: 0;
  left: 0;
}

/* Answer buttons: the edge labels, and select boxes that are not expanded */

.edge-label {
  position: absolute;
  transform: translate(-50%, -50%);
  margin: 0;
}

.edge-label, .node.select:not(.active) {
  padding: 6px 16px;
  border: var(--border-w) solid #2c2d31;
  border-radius: 999px;
  background: var(--bg);
  color: #5f6066;
  font: 600 14px/1.2 var(--font);
  letter-spacing: .01em;
  white-space: nowrap;
  box-shadow: none;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease,
              box-shadow 160ms ease, scale 120ms ease;
}

.edge-label { pointer-events: none; }

/* The answers of the current node. Only these can be clicked. */
.edge-label.open, .node.select.open {
  pointer-events: auto;
  cursor: pointer;
  border-color: var(--edge);
  background: var(--edge);
  color: var(--bg);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .08);
}

.edge-label.open:hover, .node.select.open:hover {
  border-color: #fff;
  background: #fff;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, .14);
}

.edge-label.open:active, .node.select.open:active { scale: .95; }
.edge-label:focus-visible { outline: 2px solid var(--text-dim); outline-offset: 3px; }

/* An answer that the reader chose. */
.edge-label.chosen, .node.select.chosen {
  border-color: var(--edge);
  color: var(--text);
}

/* Nodes */

.node {
  position: absolute;
  top: 0;
  left: 0;
  padding: 18px 24px;
  border: var(--border-w) solid var(--node-border);
  border-radius: var(--radius);
  background: var(--node-bg);
  color: var(--text-muted);
  font-size: 17px;
  line-height: 1.35;
  text-align: center;
  text-wrap: balance;
  transition: border-color 160ms ease, opacity 160ms ease, box-shadow 160ms ease;
  animation: appear 500ms ease backwards;
}

@keyframes appear {
  from { opacity: 0; translate: 0 6px; }
  to { opacity: 1; translate: 0 0; }
}

/* Nodes that the reader reached, and the node they are on now */

.node.active { color: var(--text); border-color: #4a4b51; }

.node.current {
  border-color: #8b8c92;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .05);
}

/* A question that the reader answered. A click goes back to it. */
.node.rewind { cursor: pointer; }
.node.rewind:hover { border-color: #8b8c92; background: #222328; }
.node.rewind:focus-visible { outline: 2px solid var(--text-dim); outline-offset: 3px; }

/* The same height as a question, so that the rows line up. */
.node.outcome { font-weight: 600; padding: 18px 16px; }

.node.accent-red { --accent: var(--red); }

.node.accent.active {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--node-border));
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 10%, transparent),
              0 0 40px color-mix(in srgb, var(--accent) 16%, transparent);
}

/* Note: the facts */

.node.note {
  text-align: left;
  padding: 18px 22px 20px;
  font-size: 15px;
}

.note-title {
  margin: 0 0 12px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.note ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: fact;
}

.note li {
  padding-left: 22px;
  counter-increment: fact;
}

/* The number is inline, so it sits on the same baseline as the text. */
.note li::before {
  content: counter(fact);
  display: inline-block;
  width: 22px;
  margin-left: -22px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Select: pick one or more reasons */

/* A select box is a pill until the reader clicks it. Then it expands. */
.node.select { --select-gap: 8px; }

/* The options are the same distance from the sides and the bottom of the box
   as from each other. */
.node.select.active { padding: 10px var(--select-gap) var(--select-gap); text-align: left; }

.select-head {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: center;
}

/* When the box can be clicked, the head covers the whole box. */
.node.select.open .select-head { cursor: pointer; }
.node.select.open .select-head::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.select-head:focus-visible { outline: none; }
.node.select:has(.select-head:focus-visible) { outline: 2px solid var(--text-dim); outline-offset: 3px; }

.select-body { display: none; }
.node.select.active .select-head { display: none; }
/* An expanded box covers the pill of the other box. */
.node.select.active { z-index: 1; }
.node.select.active .select-body { display: block; }

/* "Yes. Why?" on the left, "(Select all that apply)" on the right */
.select-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 0 4px 10px;
  font-size: 14px;
  font-weight: 600;
}

.select-hint {
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 400;
}

.select-items {
  display: flex;
  flex-direction: column;
  gap: var(--select-gap);
}

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 0;
  /* The left gap of the checkbox is the same as its top and bottom gaps. */
  padding: 9px 14px 9px 10px;
  border: var(--border-w) solid var(--node-border);
  /* Concentric with the box: its radius minus the gap */
  border-radius: calc(var(--radius) - var(--select-gap));
  background: var(--node-bg);
  /* Gray until it is checked */
  color: var(--text-muted);
  font: inherit;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.35;
  text-align: left;
  pointer-events: none;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

/* The checkbox */
.check {
  position: relative;
  flex: none;
  width: 18px;
  height: 18px;
  border: var(--border-w) solid #4a4b51;
  border-radius: 5px;
  transition: background 120ms ease, border-color 120ms ease;
}

.check::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1.5px;
  width: 4px;
  height: 9px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  rotate: 45deg;
  opacity: 0;
}

.choice[aria-pressed="true"] { color: var(--text); border-color: #6e6f75; }
.choice[aria-pressed="true"] .check { background: var(--edge); border-color: var(--edge); }
.choice[aria-pressed="true"] .check::after { opacity: 1; }

/* The items of the current select node can be clicked. */
.node.current .choice { pointer-events: auto; cursor: pointer; }
.node.current .choice .check { border-color: #8b8c92; }
.node.current .choice:hover { border-color: #8b8c92; background: #222328; color: var(--text-dim); }
.node.current .choice[aria-pressed="true"]:hover { color: var(--text); }
.node.current .choice[aria-pressed="true"] .check { border-color: var(--edge); }

/* A checked reason that does not count, because a selfish reason is checked
   too. It keeps the gray style, with a gray check. */
.choice[aria-pressed="true"].discounted { color: var(--text-muted); border-color: var(--node-border); }
.node.current .choice[aria-pressed="true"].discounted .check { background: var(--text-muted); border-color: var(--text-muted); }
.node.current .choice[aria-pressed="true"].discounted:hover { color: var(--text-dim); }
.choice:focus-visible { outline: 2px solid var(--text-dim); outline-offset: 2px; }

/* Portrait: the light shows the state of the flow */

.node.portrait {
  padding: 0;
  overflow: hidden;
  background: #000;
}

.portrait svg {
  display: block;
  width: 100%;
  height: 100%;
  isolation: isolate;
}

.portrait .light polygon { opacity: 0; transition: opacity 500ms ease; }
.portrait[data-light="split"] .split polygon,
.portrait[data-light="green"] .green polygon,
.portrait[data-light="red"] .red polygon { opacity: 1; }

/* Note text: one paragraph, in place of a list */
.note-text { margin: 0; line-height: 1.45; }
.note.pending .note-text { color: var(--text-muted); }

/* The rationale: headings and bullet lists of reasons */
.note-subhead { margin: 0 0 .15em; font-weight: 600; }
.note-subhead:not(:first-of-type), .note-aside { margin-top: .6em; }
.note-emoji { width: 1.15em; height: 1.15em; vertical-align: -.2em; }
.note-aside { color: var(--text-muted); }
.note .note-list { margin: 0; padding-left: 1.2em; list-style: disc; }
.note .note-list li { padding-left: 2px; line-height: 1.4; }
.note .note-list li::before { content: none; }
.note .note-list li + li { margin-top: .1em; }
.note-shrug { display: block; width: 64px; height: 64px; }

/* In the screenshot variant, the chosen answers are filled, so that the
   path stands out at a small size. */
[data-mode="og"] .edge-label.chosen,
[data-mode="og"] .node.select.chosen {
  border-color: var(--edge);
  background: var(--edge);
  color: var(--bg);
}

/* The screenshot variant has text twice as large, so that it is readable
   when a feed shows the image small. */
[data-mode="og"] .node { font-size: 34px; padding: 24px 32px; border-radius: 18px; }
[data-mode="og"] .node.outcome { padding: 24px 24px; }
[data-mode="og"] .node.note { font-size: 38px; padding: 30px 38px; }
[data-mode="og"] .note-title { font-size: 26px; margin-bottom: 18px; }
/* The fact is as tall as the portrait next to it. Center its text. */
[data-mode="og"] [data-id="facts"] { display: flex; flex-direction: column; justify-content: center; }
[data-mode="og"] .note-shrug { width: 150px; height: 150px; }
[data-mode="og"] .edge-label,
[data-mode="og"] .node.select:not(.active) { font-size: 28px; padding: 10px 28px; border-width: 2px; }
[data-mode="og"] .edge { stroke-width: 2.5; }
/* The arrowheads are larger in this variant, so a thinner stroke inside them
   gives the same line width as the edges. */
[data-mode="og"] .arrow path, [data-mode="og"] .arrow-dim path { stroke-width: 1.55; }
[data-mode="og"] .node.portrait { padding: 0; }

/* The screenshot variant has no animation, so that the image is final. */
[data-mode="og"] *, [data-mode="og"] *::before, [data-mode="og"] *::after {
  animation: none !important;
  transition: none !important;
}

/* The screenshot variant has no header. */
[data-mode="og"] .brand,
[data-mode="og"] .restart,
[data-mode="og"] body::before { display: none; }

/* Chrome */

/* Frosted glass behind the title bar. The chart blurs under it, so that its
   text does not mix with the title. The lower edge fades out. */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  z-index: 5;
  height: calc(76px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-mask-image: linear-gradient(#000 78%, transparent);
  mask-image: linear-gradient(#000 78%, transparent);
  pointer-events: none;
}

.brand {
  position: fixed;
  top: max(20px, env(safe-area-inset-top));
  left: max(var(--edge-left, 24px), env(safe-area-inset-left));
  z-index: 10;
  pointer-events: none;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -.01em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}

.restart {
  position: fixed;
  top: max(20px, env(safe-area-inset-top));
  right: max(var(--edge-right, 24px), env(safe-area-inset-right));
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 8px 14px;
  border: var(--border-w) solid var(--node-border);
  border-radius: 999px;
  background: var(--node-bg);
  color: var(--text-dim);
  font: 500 13px/1.2 var(--font);
  cursor: pointer;
  animation: appear 300ms ease backwards;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.restart[hidden] { display: none; }
.restart:hover, .restart.ended { color: var(--text); border-color: #7a7b81; }
.restart:hover { background: #24252a; }
.restart:focus-visible { outline: 2px solid var(--text-dim); outline-offset: 3px; }

.restart svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 760px) {
  .brand h1 { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .node, .edge.drawing { animation: none; }
  .edge.drawing { stroke-dasharray: none; marker-end: url(#arrow-dim); }
  .edge.drawing.no-arrow { marker-end: none; }
}
