/* The guide's pages. Dagr's own look: near-black ground, amber accent,
   bytes in monospace. Prose is set for reading, panels for playing. */
:root {
  --ground: #08090a; --ground-2: #141618; --amber: #f0c000;
  --bg: #faf9f4; --card: #ffffff; --text: #1b1916; --muted: #6f6b61;
  --line: #d4d0c3; --link: #8a6500; --shadow: #1b1916;
  /* What a byte is: one colour each, the same on every page. */
  --k-frame: #d9d6cc; --k-shape: #f6d77a; --k-pointer: #f3b3d2;
  --k-size: #a6dbe6; --k-number: #b5e0b0; --k-text: #c4c6f5;
  --ctl: #f0c000; --pay: #e9e6dc; --idle: transparent;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #08090a; --card: #0f1113; --text: #f6f4ee; --muted: #a9a59c;
    --line: #2a2d31; --link: #f0c000; --shadow: #f0c000;
    --k-frame: #3a3c40; --k-shape: #6b5500; --k-pointer: #6e2850;
    --k-size: #17505c; --k-number: #23552a; --k-text: #36398a;
    --ctl: #b08d00; --pay: #2a2d31;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 18px/1.65 Charter, "Iowan Old Style", "Palatino Linotype", Georgia, serif; }
main { max-width: 760px; margin: 0 auto; padding: 12px 18px 60px; }
.play, table, nav.chapters, .crumbs, .badge, button, select, input, label, .legend {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.mono, code, pre, .bytes, .hex, .sizes, .say {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }

/* The top of a chapter. */
header.top { background: var(--ground); color: #f6f4ee;
             border-bottom: 6px solid var(--amber); }
header.top .in { max-width: 760px; margin: 0 auto; padding: 22px 18px 44px; }
.crumbs { font-size: 0.82rem; color: #a9a59c; display: flex; gap: 10px;
          align-items: center; flex-wrap: wrap; }
.crumbs a { color: #a9a59c; }
.crumbs img { width: 28px; height: 28px; display: block; border-radius: 6px; }
.crumbs .draft { border: 1px solid #54565a; border-radius: 4px; padding: 0 6px; }
.badge { display: inline-flex; align-items: center; gap: 10px; margin: 40px 0 0;
         font-weight: 600; font-size: 0.8rem; letter-spacing: 0.14em;
         text-transform: uppercase; color: var(--amber); }
.badge b { display: grid; place-items: center; min-width: 40px; height: 40px;
           padding: 0 8px; border-radius: 8px; background: var(--amber);
           color: var(--ground); font: 700 1.3rem/1 "IBM Plex Mono", ui-monospace, Menlo, monospace;
           letter-spacing: 0; }
h1 { font: 700 clamp(2.1rem, 6.5vw, 3.3rem)/1.08 system-ui, -apple-system, "Segoe UI", sans-serif;
     margin: 14px 0 16px; letter-spacing: -0.02em; }
h1 em { font-style: normal; color: var(--amber); }
.lead { font-size: 1.18rem; line-height: 1.5; color: #d4d0c3; margin: 0; max-width: 34em; }

h2 { font: 700 1.6rem/1.2 system-ui, -apple-system, "Segoe UI", sans-serif;
     margin: 60px 0 12px; padding-top: 18px; letter-spacing: -0.01em;
     border-top: 3px solid var(--text); }
h3 { font: 700 1.1rem/1.3 system-ui, -apple-system, "Segoe UI", sans-serif; margin: 30px 0 8px; }
p { margin: 0 0 18px; }
a { color: var(--link); text-underline-offset: 3px; text-decoration-thickness: 2px; }
ul, ol { margin: 0 0 18px; padding-left: 24px; }
li { margin-bottom: 8px; }
code { font-size: 0.84em; background: color-mix(in srgb, var(--amber) 22%, transparent);
       border-radius: 4px; padding: 1px 5px; }
pre { margin: 0 0 20px; padding: 14px 16px; overflow-x: auto; background: var(--ground);
      color: #f6f4ee; border-radius: 10px; border-left: 6px solid var(--amber);
      font-size: 0.8rem; line-height: 1.55; }
pre code { background: none; padding: 0; font-size: inherit; }
.hl-c { color: #8a877f; } .hl-s { color: #9fd69a; } .hl-n { color: #8fd3e0; }
.hl-k { color: #f0c000; } .hl-t { color: #f3b3d2; }
table { border-collapse: collapse; width: 100%; margin: 0 0 20px; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
         vertical-align: top; }
th { font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase;
     color: var(--muted); border-bottom: 2px solid var(--text); }
.note { margin: 0 0 20px; padding: 14px 16px 2px; border: 2px solid var(--text);
        border-radius: 10px; background: var(--card); }

/* A panel to play with. */
.play { margin: 26px 0 34px; background: var(--card); border: 2px solid var(--text);
        border-radius: 12px; overflow: hidden; font-size: 0.9rem;
        box-shadow: 6px 6px 0 var(--shadow); }
.play::before { content: "play with this"; display: block; padding: 5px 14px;
                background: var(--amber); color: #08090a; font-weight: 700;
                font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; }
.play .bar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
             padding: 12px 14px; border-bottom: 1px solid var(--line); }
.play .stage { padding: 14px; overflow-x: auto; }
.play .say { padding: 10px 14px; border-top: 1px solid var(--line); font-size: 0.82rem;
             min-height: 3.6em; color: var(--text); }
.play .say b { font-weight: 700; }
.play label { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); }
input[type=text], select { font: inherit; font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
        color: var(--text); background: var(--bg); border: 1.5px solid var(--text);
        border-radius: 6px; padding: 5px 8px; max-width: 100%; }
input[type=text] { width: 15em; }
button { font-size: 0.82rem; font-weight: 600; color: var(--text); background: var(--bg);
         border: 1.5px solid var(--text); border-bottom-width: 3px; border-radius: 6px;
         padding: 4px 10px; cursor: pointer; }
button:hover { background: color-mix(in srgb, var(--amber) 30%, var(--bg)); }
button[aria-pressed=true] { background: var(--amber); color: #08090a; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

/* A row of bytes with their bits: the hex on top, eight bits under it. */
.row { display: grid; grid-template-columns: 7.5em 1fr; gap: 6px 12px;
       align-items: start; margin-bottom: 14px; }
.row > span { color: var(--muted); font-size: 0.8rem; padding-top: 4px; }
.row > span b { display: block; color: var(--text); font-size: 0.86rem; }
.bytes { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.74rem; }
.byte { border: 1.5px solid var(--text); border-radius: 5px; overflow: hidden;
        text-align: center; }
.byte .hx { display: block; padding: 1px 0; font-weight: 700; font-size: 0.82rem;
            border-bottom: 1px solid var(--line); }
.byte .bits { display: flex; }
.byte .bits i { font-style: normal; width: 1.05em; padding: 1px 0; background: var(--pay); }
.byte .bits i.ctl { background: var(--ctl); color: #08090a; font-weight: 700; }
.byte .bits i.idle { background: none; color: var(--muted); }
.byte.none { border-style: dashed; padding: 6px 10px; color: var(--muted); }
.glyph { display: inline-flex; flex-direction: column; align-items: center; gap: 4px;
         margin: 0 10px 10px 0; }
.glyph > b { font: 400 1.5rem/1.2 system-ui, sans-serif; min-height: 1.2em; }
.key { display: inline-block; padding: 0 5px; border-radius: 4px; font-weight: 600; }
.key.ctl { background: var(--ctl); color: #08090a; }
.key.pay { background: var(--pay); }

/* The buffer: one cell a byte, coloured by what it is. */
.hex { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 3px;
       font-size: 0.8rem; max-width: 620px; }
.hex button { border: 1.5px solid transparent; border-radius: 4px; padding: 5px 0;
              font: inherit; font-weight: 500; text-align: center; color: var(--text); }
.hex button.on { border-color: var(--text); font-weight: 700; }
.hex button.to { outline: 3px dashed var(--text); outline-offset: 1px; }
.k-frame { background: var(--k-frame); } .k-shape { background: var(--k-shape); }
.k-pointer { background: var(--k-pointer); } .k-size { background: var(--k-size); }
.k-number { background: var(--k-number); } .k-text { background: var(--k-text); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0 14px 12px; font-size: 0.8rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.sizes { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr); gap: 6px;
         padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: stretch; }
.sizes .ax { font-size: 0.72rem; color: var(--muted); align-self: center; line-height: 1.25; }
.sizes .ax.top { text-align: center; align-self: end; }
.sizes .ax b { display: block; color: var(--text); font-size: 0.78rem; }
.sizes button { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center;
                text-align: left; font: inherit; font-size: 0.8rem; border-bottom-width: 1.5px;
                padding: 6px 8px; }
.sizes button.wide { grid-column: 2 / 4; }
.sizes .track { grid-column: 1 / 3; display: flex; height: 12px; border-radius: 3px; overflow: hidden; }
.sizes .track i { display: block; height: 100%; }
.sizes .n { text-align: right; white-space: nowrap; }
/* The two switches as a square: what each side of it means. */
table.square th, table.square td { border: 1px solid var(--line); }
table.square td b { display: block; font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; }
table.square th[scope=row] { width: 24%; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 15em); gap: 14px; }
.split pre { margin: 0; font-size: 0.72rem; border-left-width: 4px; }
@media (max-width: 640px) {
  .hex { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  table { font-size: 0.76rem; } th, td { padding: 6px 4px; } th { letter-spacing: 0; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .row { grid-template-columns: minmax(0, 1fr); }
  .sizes { padding: 10px 8px; } .sizes button { font-size: 0.72rem; padding: 5px 6px; }
}
svg.plot { display: block; width: 100%; height: auto; }
svg.plot text { font: 12px system-ui, sans-serif; fill: var(--muted); }
svg.plot .axis { stroke: var(--line); }
svg.plot .leb { stroke: var(--text); fill: none; stroke-width: 2.5; }
svg.plot .v62 { stroke: #c79a00; fill: none; stroke-width: 2.5; stroke-dasharray: 7 4; }
svg.plot .now { stroke: var(--text); stroke-width: 1; stroke-dasharray: 2 3; }
svg.plot text.l { fill: var(--text); font-weight: 600; }

/* The chapters, at the foot of every page. */
nav.chapters { margin-top: 70px; padding: 18px; border: 2px solid var(--text);
               border-radius: 12px; background: var(--card); font-size: 0.92rem; }
nav.chapters p { margin: 0 0 10px; color: var(--muted); }
nav.chapters ol { list-style: none; margin: 0; padding: 0; }
nav.chapters li { display: flex; gap: 10px; align-items: baseline; margin: 0;
                  padding: 5px 0; color: var(--muted); }
nav.chapters li span { font: 700 0.8rem "IBM Plex Mono", ui-monospace, Menlo, monospace;
                       min-width: 2em; color: var(--muted); }
nav.chapters li.here { color: var(--text); font-weight: 700; }

/* Chapter 3: a list of formats to pick from, bytes a reader skips, and
   what an old reader makes of new bytes. */
.sizes.list { grid-template-columns: minmax(0, 1fr); }
.hex button.dim { opacity: 0.28; }
input[type=text].short { width: 7.5em; }
.cards { display: grid; gap: 12px; padding: 14px; }
.card { border: 1.5px solid var(--text); border-radius: 8px; padding: 10px 12px; }
.card h4 { margin: 0 0 8px; font: 700 0.86rem/1.3 system-ui, sans-serif; }
.card .hex { margin-bottom: 10px; font-size: 0.72rem; }
.card .hex span { border-radius: 3px; padding: 3px 0; text-align: center; }
.card p { margin: 0; font: 0.8rem/1.5 "IBM Plex Mono", ui-monospace, Menlo, monospace; }
.card .ok, .card .wrong { font-weight: 700; padding: 0 4px; border-radius: 3px; }
.card .ok { background: var(--k-number); }
.card .wrong { background: var(--k-pointer); text-decoration: underline wavy; }

/* Chapter 4: people and the arrows between them. */
svg.graph { color: var(--text); max-width: 380px; align-self: start; }
svg.graph circle { stroke: var(--text); stroke-width: 2; }
svg.graph circle.in { fill: var(--k-shape); }
svg.graph circle.out { fill: none; stroke-dasharray: 4 4; }
#people .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
#people pre.what { min-height: 20em; }
@media (max-width: 640px) { #people .split { grid-template-columns: minmax(0, 1fr); } #people pre.what { min-height: 0; } }

/* Chapter 6: two buffers one above the other, each under its name. */
.play h3.cap { margin: 0 0 8px; font: 700 0.86rem/1.3 system-ui, sans-serif; }
.play .hex + h3.cap { margin-top: 18px; }

/* Chapter 7: rows of sizes that are only read, not chosen. */
.sizes .line { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center;
               font-size: 0.8rem; padding: 6px 8px; border: 1.5px solid var(--line); border-radius: 6px; }
.play .stage.rows { padding: 0; }
.play .stage.rows .sizes { border-bottom: 0; }

/* Chapter 8: a value typed as JSON. */
.play textarea { font: inherit; font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; font-size: 0.82rem; line-height: 1.5;
                 width: 100%; box-sizing: border-box; resize: vertical; padding: 8px 10px; border-radius: 6px;
                 border: 1.5px solid var(--text); background: var(--bg); color: var(--text); }

/* Chapter 9: a token as text, and a verifier's steps. */
.play .jwt { margin: 0 0 6px; font: 0.8rem/1.9 "IBM Plex Mono", ui-monospace, Menlo, monospace; overflow-wrap: anywhere; }
.play .jwt span { padding: 3px 2px; border-radius: 3px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.play .decoded { margin: 0 0 18px; font-size: 0.78rem; line-height: 1.6; overflow-wrap: anywhere; }
.play .steps { margin: 14px 0 0; padding: 0; list-style: none; font-size: 0.84rem; line-height: 1.5; }
.play .steps li { margin: 0 0 6px; padding: 6px 10px 6px 34px; position: relative; border-radius: 6px; border: 1.5px solid var(--line); }
.play .steps li::before { position: absolute; left: 10px; font-weight: 700; }
.play .steps li.ok::before { content: "\2713"; }
.play .steps li.no::before { content: "\2717"; }
.play .steps li.no { border-color: var(--text); font-weight: 600; }
.play .steps li[tabindex] { cursor: default; }

/* Chapter 11: memory drawn 16 addresses to a row, so that boundaries line up. */
.mem { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 2px; max-width: 560px;
       font: 0.62rem/1 "IBM Plex Mono", ui-monospace, Menlo, monospace; }
.mem > * { box-sizing: border-box; min-width: 0; padding: 6px 0; text-align: center; border-radius: 3px; border: 1.5px solid transparent;
           font: inherit; color: var(--text); overflow: hidden; }
.mem .empty { background: transparent; border-color: var(--line); opacity: 0.7; }
.mem .other { background: repeating-linear-gradient(135deg, var(--k-frame) 0 3px, transparent 3px 6px); }
.mem .edge { box-shadow: inset 3px 0 0 var(--text); }
.mem .first { font-weight: 700; }
.mem button.on { border-color: var(--text); font-weight: 700; }
.mem button.to { outline: 2px dashed var(--text); outline-offset: 0; }
.play input[type=range] { vertical-align: middle; width: 9em; max-width: 100%; }

/* Chapter 12: a region's words, and the step each program is at. */
.play .words { margin: 0 0 14px; font: 0.9rem/1.6 "IBM Plex Mono", ui-monospace, Menlo, monospace; }
.play .steps li.now { border-color: var(--text); background: var(--k-shape); }
.play .steps li.now::before { content: "\25B6"; font-size: 0.7em; top: 9px; }
.play .split .steps { margin-top: 0; }
/* Two versions of a schema side by side, and tool output (the chapter on change). */
.play .versions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; margin: 0 0 14px; }
.play .versions h3.cap { margin-top: 0; }
.play pre.schema { margin: 0 0 14px; padding: 8px 10px; font: 0.72rem/1.55 "IBM Plex Mono", ui-monospace, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; border: 1.5px solid var(--line); border-radius: 6px; }
.play .versions pre.schema { margin: 0; }
.play pre.schema b { background: var(--k-shape); font-weight: 600; }
.play .words .swatch { display: inline-block; width: 1.1em; height: 1.1em; vertical-align: -0.2em; border: 1.5px solid var(--line); border-radius: 3px; }
#change .bar label { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; max-width: 100%; min-width: 0; }
#change .bar select { max-width: 100%; min-width: 0; text-overflow: ellipsis; }
#change .words { font-size: 0.76rem; overflow-wrap: anywhere; margin-bottom: 8px; }
@media (max-width: 640px) { .play .versions { grid-template-columns: minmax(0, 1fr); } }
/* A stream as a row of record cards (the signed log). */
.play .recs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.play .recs .rec { font: 0.78rem/1.3 "IBM Plex Mono", ui-monospace, Menlo, monospace; padding: 6px 9px; border-radius: 6px; border: 1.5px solid var(--line); background: transparent; color: var(--text); cursor: default; text-align: left; }
.play .recs button.rec { cursor: pointer; }
.play .recs .rec.check { background: var(--k-pointer); }
.play .recs .rec.seal { background: var(--k-shape); }
.play .recs .rec.in { border-color: var(--text); border-style: dashed; }
.play .recs .rec.on { border-color: var(--text); border-width: 2.5px; padding: 5px 8px; }
.play .recs .rec.is-signed { background: var(--k-number); }
.play .recs .rec.is-unsigned { background: var(--k-frame); }
.play .recs .rec.is-bad { background: var(--k-pointer); border-color: var(--text); border-width: 2.5px; padding: 5px 8px; font-weight: 700; }
.play .recs .rec.is-unread { background: transparent; opacity: 0.4; }
.play .split + h3.cap { margin-top: 16px; }

/* Chapter 2: the three fields of a floating-point number. */
.byte .bits i.sgn { background: var(--k-pointer); font-weight: 700; }
.byte .bits i.exp { background: var(--k-size); }
/* Chapters 17, 19 and 20: measured sizes as bars, text with its repeats marked, output of a tool. */
.play .meter { display: grid; grid-template-columns: minmax(0, 12.5em) minmax(0, 1fr) 5.2em; gap: 5px 10px; align-items: center;
               font: 0.76rem/1.3 "IBM Plex Mono", ui-monospace, Menlo, monospace; }
.play .meter .what { grid-column: 1 / 4; margin-top: 10px; font-weight: 700; }
.play .meter .what:first-child { margin-top: 0; }
.play .meter .who { color: var(--muted); padding-left: 10px; }
.play .meter .track { height: 14px; background: var(--pay); border-radius: 3px; overflow: hidden; }
.play .meter .track i { display: block; height: 100%; background: var(--k-text); border-right: 1.5px solid var(--text); }
.play .meter .track.d i { background: var(--k-number); }
.play .meter .track.x i { background: var(--k-shape); }
.play .meter .n { text-align: right; white-space: nowrap; }
.play .lz { margin: 0; font: 0.8rem/1.9 "IBM Plex Mono", ui-monospace, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.play .lz .copy { background: var(--k-size); border-radius: 3px; cursor: default; }
.play .lz .copy.on { outline: 2px solid var(--text); }
.play .lz .src { background: var(--k-shape); }
.play textarea { width: 100%; min-height: 5.5em; font: 0.8rem/1.5 "IBM Plex Mono", ui-monospace, Menlo, monospace; padding: 8px;
                 border: 1.5px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); resize: vertical; }
.play pre.out { margin: 0 0 12px; padding: 8px 10px; font: 0.72rem/1.55 "IBM Plex Mono", ui-monospace, Menlo, monospace; white-space: pre-wrap;
                overflow-wrap: anywhere; border: 1.5px solid var(--line); border-radius: 6px; max-height: 26em; overflow-y: auto; }
.play pre.out .add { background: var(--k-number); } .play pre.out .mod { background: var(--k-shape); } .play pre.out .bad { background: var(--k-pointer); }
.play pre.out .cmd { color: var(--muted); }
@media (max-width: 640px) { .play .meter { grid-template-columns: minmax(0, 6.5em) minmax(0, 1fr) 4.6em; font-size: 0.68rem; } .play .meter .who { padding-left: 0; } }
/* Chapter 18: how many times faster or slower, on a scale where each step is a factor. */
.play .meter.ratio .track { position: relative; overflow: visible; }
.play .meter.ratio .track::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; border-left: 1.5px solid var(--text); }
.play .meter.ratio .track i { position: absolute; top: 0; border-right: 0; border-radius: 3px; }
.play .meter.ratio .track i.ahead { left: 50%; background: var(--k-number); }
.play .meter.ratio .track i.behind { right: 50%; background: var(--k-pointer); }
.play .meter.ratio .track i.even { left: calc(50% - 4px); width: 8px !important; background: var(--k-shape); }
.play .meter.ratio .who small { display: block; font-size: 0.9em; opacity: 0.85; }
.play .meter.ratio { grid-template-columns: minmax(0, 14em) minmax(0, 1fr) 7.4em; }
@media (max-width: 640px) { .play .meter.ratio { grid-template-columns: minmax(0, 8.5em) minmax(0, 1fr) 5.6em; } }
