/*
 * Cloudflare, in pieces: the guide's shared layer, loaded by all five pages
 * after the site's files and before each page's own styles.css. It holds the
 * top bar and chapter menu, the evidence tags and panels, chapter prose,
 * the instruments (stage, packets, compartments, controls, readouts), the
 * drawers and the pager.
 *
 * The colors below are data and scene colors. Group colors mark a block's
 * service group on the map and on every stage, and each block also carries
 * its name. Packets differ by shape as well as color: a ring for the DNS
 * lookup, a dot for a request or response, a square for a binding call, a
 * diamond for background work. A stale copy is hatched and badged in words.
 * Contrast against --bg and --surface is recorded in docs/cloudflare/.
 */
:root {
  --data-delivery: #f6ae77; /* route and protect */
  --data-compute: #8bbff8; /* run your code */
  --data-storage: #a8cfa2; /* keep your data */
  --data-jobs: #c3adf0; /* do more work */
  --data-grid: #262622; /* the map's dot grid */
  --data-lookup: #e8cf72; /* the DNS lookup, before HTTP */
  --data-binding: #7fd6cf; /* a call through a binding */
  --data-background: #c3adf0; /* work after the response */
  --data-stale: #e0a458; /* hatching on a stale copy */
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

[hidden] {
  display: none !important;
}

/* Top bar: the mark home, the way back, and the chapters. */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-5);
  align-items: center;
  min-height: 78px;
  padding: var(--space-3) var(--gutter);
  border-bottom: 1px solid var(--line);
}

.topbar .lockup {
  min-height: 44px;
}

.topbar .back-link {
  margin: 0;
}

.chapter-menu {
  flex-basis: 100%;
}

.chapter-menu > summary {
  display: none;
}

.chapter-menu ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-5);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

.chapter-menu a {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  min-height: 44px;
  color: var(--ink-2);
  text-decoration: none;
}

.chapter-menu a:hover {
  color: var(--ink);
  text-decoration-line: underline;
}

.chapter-menu a[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline 2px var(--current);
  text-underline-offset: 0.4em;
}

.chapter-menu .section-label {
  font-variant-numeric: tabular-nums;
}

main {
  width: min(100% - 2 * var(--gutter), var(--content));
  margin-inline: auto;
  padding-block: var(--space-7) var(--space-9);
}

/* Intro. */
.intro .eyebrow {
  margin-bottom: var(--space-4);
}

h1 {
  margin: 0;
  font-weight: var(--weight-bold);
}

h1 span {
  color: var(--ink-2);
  font-weight: 400;
}

.lede {
  max-width: var(--prose);
  margin: var(--space-5) 0 var(--space-3);
  color: var(--ink-2);
  font-size: var(--text-lg);
  line-height: var(--leading-prose);
}

.meta {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-xs);
}

.toc {
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--line);
  background: var(--surface);
}

.toc ol {
  display: grid;
  gap: var(--space-1);
  margin: var(--space-3) 0 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

.toc a {
  display: inline-flex;
  gap: var(--space-3);
  align-items: baseline;
  min-height: 24px;
  padding-block: 2px;
  text-decoration: none;
}

.toc a:hover {
  text-decoration-line: underline;
}

.toc .section-label {
  min-width: 2ch;
}

/* The two kinds of evidence. */
.tag {
  display: inline-block;
  padding: 1px var(--space-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-label);
  line-height: 1.5;
  text-transform: var(--label-case);
  white-space: nowrap;
}

.tag--illustration {
  border-style: dashed;
}

.panel {
  margin: var(--space-6) 0;
  padding: var(--space-5);
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

.panel > :last-child {
  margin-bottom: 0;
}

/* Chapters. */
.chapter {
  padding-top: var(--section);
}

.chapter > .section-label {
  margin-bottom: var(--space-3);
}

.chapter h2 {
  margin: 0 0 var(--space-5);
}

/* Zero-specificity elements, so a page's own classes size their text. */
.chapter :where(p, li) {
  font-size: var(--text-prose);
  line-height: var(--leading-prose);
}

.chapter :where(.panel, .instrument, .drawer) :where(p, li),
.chapter .table-wrap {
  font-size: var(--text-base);
  line-height: var(--leading-ui);
}

code,
.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.figure-caption {
  max-width: var(--prose);
  margin: var(--space-4) 0 0;
  color: var(--ink-2);
  font-size: var(--text-sm);
}

/* Instrument buttons, shared by every interaction in the guide. */
button {
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:hover {
  background: var(--tint);
}

button[aria-pressed="true"],
button.primary {
  border-color: var(--action-bg);
  background: var(--action-bg);
  color: var(--action-ink);
}

button:disabled {
  border-color: var(--line);
  color: var(--muted);
  cursor: default;
}

button:disabled:hover {
  background: var(--surface);
}

input[type="checkbox"] {
  accent-color: var(--ink);
}

/* Service faces: the map's blocks. */
.group-delivery {
  --node-color: var(--data-delivery);
}

.group-compute {
  --node-color: var(--data-compute);
}

.group-data {
  --node-color: var(--data-storage);
}

.group-jobs {
  --node-color: var(--data-jobs);
}

.node-top {
  display: flex;
  gap: var(--space-1);
  align-items: center;
  justify-content: space-between;
}

.node-symbol {
  color: var(--node-color);
  font-family: var(--font-mono);
  line-height: 1;
}

.node-status {
  color: var(--ink-2);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: var(--label-case);
}

.node strong {
  font-weight: 500;
  line-height: 1.3;
}

.node-caption {
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.3;
}

/* Recap and sources. */
.closing {
  margin-top: var(--section);
}

.closing h2 {
  margin: 0 0 var(--space-4);
  font-size: var(--text-xl);
}

.closing h3 {
  margin: var(--space-5) 0 var(--space-2);
  font-size: var(--text-base);
}

.closing ul {
  max-width: var(--prose);
  margin: 0;
  padding-left: 1.2em;
}

.closing li + li {
  margin-top: var(--space-2);
}

/* Previous and next, named after where they go. */
.pager {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 1px;
  margin-top: var(--space-8);
  border: 1px solid var(--line);
  background: var(--line);
}

.pager a {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-5);
  background: var(--surface);
  text-decoration: none;
}

.pager a:hover {
  background: var(--tint);
}

.pager a:hover .pager-title {
  text-decoration-line: underline;
}

.pager .pager-next {
  text-align: right;
}

.pager-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}

.piece-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-5);
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--text-xs);
}

.piece-footer p {
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 620px) {
  .chapter-menu {
    flex-basis: auto;
    margin-left: auto;
  }

  .chapter-menu[open] {
    flex-basis: 100%;
  }

  .chapter-menu > summary {
    display: flex;
    align-items: center;
    width: max-content;
    min-height: 44px;
    margin-left: auto;
    padding: 0 var(--space-4);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    list-style: none;
    cursor: pointer;
  }

  .chapter-menu > summary::-webkit-details-marker {
    display: none;
  }

  .chapter-menu ol {
    flex-direction: column;
    padding-top: var(--space-2);
  }

  .panel {
    padding: var(--space-4);
  }

  .pager {
    grid-auto-flow: row;
  }
}

/* Code shown as text, never run by the page. */
.code-static {
  margin: 0;
  padding: var(--space-4);
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-2);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.code-static code {
  font-size: inherit;
}

/* ---------------------------------------------------------- instruments */

/* An instrument: the stage, then everything the reader operates below it,
   never over it. */
.instrument {
  margin: var(--space-6) 0;
  padding: var(--space-5);
  border: 1px dashed var(--line-strong);
  background: var(--surface);
}

.instrument-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  align-items: center;
  margin: 0 0 var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
}

.instrument-static {
  margin: 0;
  color: var(--ink-2);
}

.instrument.is-live .instrument-static {
  display: none;
}

.instrument-live:empty {
  display: none;
}

.stage {
  margin-inline: calc(-1 * var(--space-2));
  border: 1px solid var(--line);
  background: var(--bg);
}

.stage-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.stage text {
  fill: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
}

.stage .compartment rect {
  fill: none;
  stroke: var(--line-strong);
  stroke-dasharray: 2 6;
}

.stage .compartment--external rect {
  stroke-dasharray: 8 5;
}

.stage .compartment-label {
  fill: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stage .stage-note {
  fill: var(--muted);
  font-size: 12px;
}

.stage .path {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.stage .path.is-hidden {
  visibility: hidden;
}

.stage .path--lookup {
  stroke-dasharray: 5 4;
}

.stage .path--binding {
  stroke-dasharray: 1 4;
  stroke-linecap: round;
}

.stage .path--background {
  stroke-dasharray: 8 3 2 3;
}

.stage .path.is-active {
  stroke: var(--ink);
  stroke-width: 2;
}

/* Blocks are buttons; the ring replaces the outline because it scales with
   the drawing. */
.stage .block {
  --node-color: var(--line-strong);
  cursor: default;
}

.stage .block[tabindex] {
  cursor: pointer;
}

.stage .block:focus {
  outline: none;
}

.stage .block-face {
  fill: var(--surface);
  stroke: var(--node-color);
  stroke-width: 1.5;
}

.stage .block-hatch {
  visibility: hidden;
  stroke: none;
}

.stage .hatch-line {
  stroke: var(--data-stale);
  stroke-width: 1.4;
  opacity: 0.55;
}

.stage .block.is-hatched .block-hatch {
  visibility: visible;
}

.stage .block-ring {
  fill: none;
  stroke: none;
  stroke-width: 2;
}

.stage .block:focus-visible .block-ring {
  stroke: var(--focus);
}

.stage .block:hover .block-face {
  fill: var(--tint);
}

.stage .block-label {
  font-weight: var(--weight-bold);
}

.stage .block-sub {
  fill: var(--muted);
  font-size: 12px;
}

.stage .block-content {
  fill: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 12px;
}

.stage .block-badge {
  fill: var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
}

.stage .block.is-hatched .block-badge {
  fill: var(--data-stale);
}

.stage .block.is-lit .block-face {
  stroke: var(--ink);
  stroke-width: 2.5;
}

.stage .block.is-lit .block-label {
  text-decoration: underline;
}

/* Dark: not involved in this event. Dim keeps its outline and its words. */
.stage .block.is-dim .block-face {
  fill: var(--bg);
  stroke: var(--line-strong);
  stroke-dasharray: 4 3;
}

.stage .block.is-dim text {
  fill: var(--muted);
}

.stage .block.is-hidden {
  display: none;
}

.stage .block--client .block-face {
  rx: 10px;
}

.stage .block--lookup .block-face {
  stroke: var(--data-lookup);
  stroke-dasharray: 5 4;
}

.stage .block--external .block-face {
  stroke-dasharray: 8 4;
}

/* The illustrated photographs: two versions, told apart by shape and by
   their letter. */
.stage .photo-frame {
  fill: var(--bg);
  stroke: var(--line-strong);
}

.stage .photo-hill {
  fill: var(--data-storage);
}

.stage .photo-sun {
  fill: var(--data-lookup);
}

.stage .photo .photo-a,
.stage .photo .photo-b {
  visibility: hidden;
}

.stage .photo[data-version="A"] .photo-a,
.stage .photo[data-version="B"] .photo-b {
  visibility: visible;
}

.stage .photo[data-version="B"] .photo-hill {
  fill: var(--data-compute);
}

.stage .photo-letter {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-bold);
}

.stage .photo[data-version="none"] .photo-frame {
  stroke-dasharray: 3 3;
}

/* Packets: a dot with a trail; shape tells the kind apart. */
.stage .packet-trail {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0.6;
}

.stage .packet--request,
.stage .packet--response {
  fill: var(--ink);
  stroke: var(--ink);
}

.stage .packet--lookup {
  fill: var(--bg);
  stroke: var(--data-lookup);
  stroke-width: 2.5;
}

.stage .packet--binding {
  fill: var(--data-binding);
  stroke: var(--data-binding);
}

.stage .packet--background {
  fill: var(--data-background);
  stroke: var(--data-background);
}

.stage .packet-trail {
  fill: none;
}

/* What is happening now, the readouts and the observation. */
.now {
  min-height: 1.6em;
  margin: var(--space-3) 0 0;
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
}

.readouts {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  margin: var(--space-3) 0 0;
  border: 1px solid var(--line);
  background: var(--line);
}

.readout {
  flex: 1 1 7.5em;
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
}

.readout dt {
  color: var(--muted);
  font-size: var(--text-xs);
}

.readout dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
}

.observation {
  min-height: 3em;
  margin: var(--space-3) 0 0;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--ink);
  background: var(--tint);
  font-size: var(--text-base);
}

/* Controls: grouped, wrapping, 44 px targets. */
.controls {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.control-group {
  display: grid;
  gap: var(--space-1);
}

.control-label {
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-label);
  text-transform: var(--label-case);
}

.control-row,
.segmented,
.try-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.instrument button {
  font-family: var(--font-mono);
  font-size: 12px;
}

.instrument button[aria-disabled="true"] {
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: default;
}

.instrument button[aria-pressed="true"] {
  border-color: var(--action-bg);
  background: var(--action-bg);
  color: var(--action-ink);
}

.instrument button.primary-action:not([aria-disabled="true"]) {
  border-color: var(--ink);
  border-width: 2px;
}

.preset-bar {
  display: grid;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.transport {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  align-items: center;
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
}

.transport .reset {
  margin-left: auto;
}

.review {
  flex: 1 1 auto;
}

.review > summary,
.trace-box > summary,
.drawer > summary {
  min-height: 44px;
  align-content: center;
  cursor: pointer;
  font-size: var(--text-sm);
}

.review-body {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  align-items: center;
}

.scrub {
  display: flex;
  flex: 1 1 10em;
  align-items: center;
  min-height: 44px;
}

.scrub input {
  width: 100%;
  accent-color: var(--ink);
}

.event-count {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.try {
  display: grid;
  gap: var(--space-1);
  margin-top: var(--space-4);
}

.try-button::before {
  content: "→ ";
}

.trace-box {
  margin-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.trace-lines {
  margin: 0;
  padding: 0 0 0 2.4em;
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  line-height: 1.7;
}

.trace-lines:empty::before {
  content: "No events yet.";
  margin-left: -2.4em;
  color: var(--muted);
}

/* A block's card: below the stage, closed with Escape. */
.service-card {
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--line-strong);
  background: var(--bg);
}

.service-card h3 {
  margin: var(--space-1) 0 var(--space-2);
  font-size: var(--text-lg);
}

.service-card p {
  margin: 0 0 var(--space-3);
  color: var(--ink-2);
}

.service-card a {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-right: var(--space-4);
  font-size: var(--text-sm);
}

.card-close {
  display: block;
  margin-top: var(--space-3);
}

/* A/B readouts side by side beneath one stage. */
.ab-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  margin-top: var(--space-3);
  border: 1px solid var(--line);
  background: var(--line);
}

.ab-card {
  padding: var(--space-3);
  background: var(--bg);
}

.ab-card h4 {
  margin: 0 0 var(--space-1);
  font-size: var(--text-sm);
}

.ab-card p {
  margin: 0;
  font-size: var(--text-sm);
}

.ab-value {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-variant-numeric: tabular-nums;
}

.ab-tag {
  display: inline-block;
  margin-top: var(--space-1);
  padding: 0 var(--space-2);
  border: 1px dashed var(--data-stale);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.status-word {
  font-weight: var(--weight-bold);
}

.status-word--critical {
  color: var(--critical);
}

.status-word--positive {
  color: var(--positive);
}

.status-word--caution {
  color: var(--caution);
}

/* The legend under a stage: words and shapes, never hue alone. */
.stage-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: var(--space-3) 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: var(--text-xs);
}

.stage-legend li {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

/* Drawers: the mechanism in prose, the code, the comparisons. */
.drawer {
  margin: var(--space-5) 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.drawer > summary {
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
}

.drawer[open] > summary {
  margin-bottom: var(--space-3);
}

.drawer-body {
  max-width: var(--prose);
  padding-bottom: var(--space-4);
}

.drawer-body > :first-child {
  margin-top: 0;
}

@media (max-width: 620px) {
  .instrument {
    margin-inline: calc(-1 * var(--space-2));
    padding: var(--space-3);
  }

  .stage {
    margin-inline: calc(-1 * var(--space-1));
  }

  .transport .reset {
    margin-left: 0;
  }
}

.still .stage .packet-trail {
  display: none;
}

.choice-list {
  display: grid;
  gap: var(--space-3);
}

.choice-list dt {
  font-weight: var(--weight-bold);
}

.choice-list dd {
  margin: var(--space-1) 0 0;
  color: var(--ink-2);
}

/* Compartments inside a block: an object's working memory and its saved
   state. A hibernated object keeps only its storage outline. */
.stage .cell-face {
  fill: var(--bg);
  stroke: var(--line-strong);
}

.stage .cell--disk .cell-face {
  stroke: var(--data-storage);
}

.stage .cell-label {
  fill: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stage .cell-content {
  font-family: var(--font-mono);
  font-size: 13px;
}

.stage .cell.is-empty .cell-face {
  stroke: var(--line-strong);
  stroke-dasharray: 3 3;
}

.stage .cell.is-empty .cell-content {
  fill: var(--muted);
}

.stage .block.is-dim .cell--memory .cell-face {
  stroke: var(--line-strong);
  stroke-dasharray: 3 3;
}

.stage .block-fine {
  fill: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 7px;
}

.stage .path.is-socket {
  stroke: var(--ink-2);
  stroke-width: 2;
}

.stage .path.is-held {
  stroke: var(--ink-2);
  stroke-dasharray: 2 4;
}

.stage .path.is-lost {
  stroke: var(--critical);
  stroke-dasharray: 6 4;
}

/* Handler source on a stage: the current line is marked by a filled bar and
   an arrow, not by hue alone. */
.stage .code-line {
  fill: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre;
}

.stage .code-mark {
  fill: none;
}

.stage .code-row.is-current .code-mark {
  fill: var(--tint);
  stroke: var(--ink);
}

.stage .code-row.is-current .code-line {
  fill: var(--ink);
  font-weight: var(--weight-bold);
}
.ab-panel:empty {
  display: none;
}
