:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1c1f23; --mute: #667085; --line: #e3e6ea; --accent: #1f5f8b; --chip: #eef3f8;
  --moving: #2e7d4f;
}
/* dark: the system's choice unless a theme is picked (data-theme on <html>, from the account menu) */
:root[data-theme="dark"] { --bg: #111418; --card: #1b2026; --ink: #e8eaed; --mute: #9aa3ad; --line: #2c333b; --accent: #7fb6e0; --chip: #232a32; --moving: #6cc795; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #111418; --card: #1b2026; --ink: #e8eaed; --mute: #9aa3ad; --line: #2c333b; --accent: #7fb6e0; --chip: #232a32; --moving: #6cc795; }
  /* the drawings are black on white, as printed: kept on a white card */
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
header#top { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
#q { flex: 1; min-width: 0; font-size: 16px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
.about { width: 32px; height: 32px; border-radius: 16px; display: grid; place-items: center; text-decoration: none; border: 1px solid var(--line); color: var(--mute); }
main { max-width: 760px; margin: 0 auto; padding: 12px 12px calc(40px + env(safe-area-inset-bottom)); }
.loading { color: var(--mute); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 12px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 5px 11px; font-size: 14px; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

details.chap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; overflow: hidden; }
details.chap > summary { list-style: none; padding: 12px 14px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; cursor: pointer; }
details.chap > summary::-webkit-details-marker { display: none; }
details.chap > summary .n { color: var(--mute); font-weight: 400; font-size: 14px; }
ul.pats { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
ul.pats li a { display: flex; align-items: baseline; gap: 8px; padding: 10px 14px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); }
ul.pats li:last-child a { border-bottom: 0; }
ul.pats .nm { flex: 1; }
ul.pats .meta { color: var(--mute); font-size: 13px; white-space: nowrap; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--chip); color: var(--mute); white-space: nowrap; }
.badge.mv { background: var(--moving); color: #fff; }
.results { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }

.pat h1 { font-size: 22px; margin: 4px 0 2px; }
.pat .sub { color: var(--mute); font-size: 14px; margin-bottom: 10px; }
.links { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 14px; }
.btn { display: inline-block; padding: 8px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: 14px; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 8px; color: var(--mute); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.notes dt { color: var(--mute); font-size: 13px; }
.notes dd { margin: 0 0 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; word-break: break-all; }
.paper { background: #fff; border-radius: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.paper svg { display: block; max-width: 100%; height: auto; }
.paper.wide svg { max-width: none; width: 100%; min-width: 520px; }
.drawbox { position: relative; width: 100%; }
.drawbox > svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.drawbox .kid { position: absolute; }
.drawbox .kid svg { display: block; width: 100%; height: 100%; }
.cap { color: var(--mute); font-size: 12px; margin-top: 6px; }
.mv-stage { width: 100%; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.mv-stage svg { width: 100%; height: 100%; display: block; }
.mv-ctl { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.mv-ctl .mv-slider { flex: 1; min-width: 0; }
.mv-ctl button { font-size: 18px; width: 48px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.mv-beat { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--mute); min-width: 88px; }
.mv-speed { font-size: 14px; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.pager { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; }
.pager a { flex: 1; text-align: center; }
.about-page p { margin: 0 0 10px; }
.empty { color: var(--mute); padding: 14px; }

/* nothing wider than the screen: a wide causal diagram scrolls sideways inside its own box */
html, body { overflow-x: hidden; }
main, .card, .pat { min-width: 0; max-width: 100%; }
.card { overflow: hidden; }
.card svg { max-width: 100%; }
.paper.wide { overflow-x: auto; }
.paper.wide svg { max-width: none; }
.mv-stage svg { max-width: 100%; }
.pager a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.links .btn, .card .btn { max-width: 100%; }

/* the book's words */
.source { font-size: 13px; color: var(--mute); margin: 2px 0 10px; }
article.text { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 10px; margin-bottom: 12px; }
article.text p { margin: 10px 0; }
article.text p.lab { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--line); }
article.text h3 { font-size: 16px; margin: 14px 0 6px; }
article.text ul { padding-left: 20px; margin: 8px 0; }
article.text hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
figure.draw { margin: 12px 0; }
figure.draw .tog { display: flex; gap: 6px; margin-bottom: 6px; }
figure.draw .tog .chip { font-size: 12px; padding: 3px 9px; }
figure.draw .v-orig { display: none; }
figure.draw.show-orig .v-orig { display: block; }
figure.draw.show-orig .v-ours { display: none; }
.paper.orig img { display: block; width: 100%; height: auto; }
.bookcard { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; text-decoration: none; color: var(--ink); }
.bookcard span { display: block; color: var(--mute); font-size: 13px; }

/* notes (hidden unless turned on at #/notes) */
#note-box { margin-top: 8px; width: 100%; }
#note-box textarea, #gh-token { width: 100%; font: inherit; font-size: 16px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.note-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.note-row #gh-token { flex: 1; min-width: 0; }
.note-msg, .note-when { color: var(--mute); font-size: 13px; }
.note-list { padding-left: 18px; }
.note-list li { margin-bottom: 8px; }
.notes-page h2 { margin-top: 14px; }

/* the pattern's siteswap at the top; the book's errata */
.topss { margin: 2px 0 10px; font-size: 14px; }
.topss .lab { color: var(--mute); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.topss code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; background: var(--chip); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.topss .how { color: var(--mute); font-size: 12px; }
sup.star { color: #c0392b; font-weight: 700; }
.errata { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 6px; font-size: 13px; color: var(--mute); }
.errata h3 { font-size: 13px; margin: 6px 0; text-transform: uppercase; letter-spacing: .03em; }
.errata p { margin: 6px 0; }

/* ---- wide screens: tablet (900px) and desktop (1200px) ---------------------------------------------------- */
#nav { display: none; }
.vlab { display: none; }
#pagepop { display: none; }
@media (min-width: 900px) {
  /* the chapters beside the page */
  #shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); align-items: start; }
  #nav { display: block; position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto; border-right: 1px solid var(--line);
         background: var(--card); padding: 8px 0 40px; font-size: 14px; }
  #nav .navhome { display: block; padding: 6px 14px 10px; font-weight: 600; text-decoration: none; }
  #nav details > summary { list-style: none; cursor: pointer; padding: 6px 14px; font-weight: 600; color: var(--ink); }
  #nav details > summary::-webkit-details-marker { display: none; }
  #nav details[open] > summary { color: var(--accent); }
  #nav ul { list-style: none; margin: 0 0 6px; padding: 0; }
  #nav li a { display: block; padding: 3px 14px 3px 24px; text-decoration: none; color: var(--mute); line-height: 1.3; }
  #nav li a:hover { color: var(--ink); background: var(--bg); }
  #nav li a.on { color: var(--ink); background: var(--chip); border-left: 3px solid var(--accent); padding-left: 21px; font-weight: 600; }
  main { max-width: 900px; padding: 16px 24px 60px; margin: 0; }
  .paper.wide svg { min-width: 0; }

  /* the book's page in a popover */
  #pagepop.open { display: flex; position: fixed; top: 4vh; left: 50%; transform: translateX(-50%); width: min(960px, 92vw); height: 92vh;
                  flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.35); z-index: 50; overflow: hidden; }
  #pagepop .bar { display: flex; gap: 12px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
  #pagepop .bar span { flex: 1; color: var(--mute); }
  #pagepop iframe { flex: 1; border: 0; width: 100%; background: #fff; }
}
@media (min-width: 1200px) {
  main { max-width: 1400px; }
  /* the panel -- siteswap, links, walking -- in view beside the book's words */
  .pat-cols { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; align-items: start; }
  .pat-side { order: 2; position: sticky; top: 73px; max-height: calc(100vh - 89px); overflow-y: auto; }
  .pat-main { order: 1; }
  .pat-side .mv-stage { aspect-ratio: 1; }
  .keys { display: block; }
}
.topss .parts { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-top: 4px; }
.only-wide { display: none; }
@media (min-width: 1200px) { .only-wide { display: block; } .only-narrow { display: none; } }
@media (min-width: 900px) { .paper.wide svg { width: auto; max-width: 100%; max-height: 280px; margin: 0 auto; } }

/* the pattern lines as a table */
.pt { margin: 10px 0; }
.pt .tog { display: flex; gap: 6px; margin-bottom: 6px; }
.pt .tog .chip { font-size: 12px; padding: 3px 9px; }
.pt .pt-words { display: none; }
.pt.show-words .pt-words { display: block; }
.pt.show-words .pt-table { display: none; }
.pt-table { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.pt-stage { font-size: 12px; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; margin: 10px 0 4px; }
.pt-grid { display: inline-flex; flex-direction: column; gap: 3px; min-width: 100%; --col: 3.6em; }
.pt-row { display: flex; align-items: center; white-space: nowrap; }
.pt-who { flex: 0 0 4.4em; font-weight: 700; font-size: 13px; }
.pt-cells { display: flex; padding-left: calc(var(--off) * var(--col)); }
.pt-c { flex: 0 0 var(--col); width: var(--col); box-sizing: border-box; text-align: center; font-size: 12.5px; padding: 3px 0; margin-right: 2px; border-radius: 5px; }
.pt-c.s { color: var(--mute); background: var(--bg); }
.pt-c.p { color: #fff; font-weight: 600; background: #888; }
.pt-c.h { text-decoration: underline; text-underline-offset: 3px; }
.pt-c.to-A, .pt-who.j-A { --c: #d9534f; } .pt-c.to-B, .pt-who.j-B { --c: #2a7ab9; }
.pt-c.to-C, .pt-who.j-C { --c: #3c9a3c; } .pt-c.to-D, .pt-who.j-D { --c: #c77c11; }
.pt-c.p[class*="to-"] { background: var(--c); }
.pt-who[class*="j-"] { color: var(--c); }

/* the book's ruled tables */
.booktable-wrap { overflow-x: auto; margin: 10px 0; }
.booktable { border-collapse: collapse; font-size: 14px; min-width: 60%; }
.booktable th, .booktable td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; vertical-align: top; }
.booktable th { background: var(--chip); }
.pt-c.b { display: inline-flex; flex-direction: column; gap: 2px; padding: 0; background: none; }
.pt-c.b .pt-c { margin: 0; width: 100%; }
.pt-c .hd { font-style: normal; font-size: 9px; opacity: .8; margin-right: 2px; vertical-align: 1px; }
.pt-start { margin-bottom: 6px; }
.ps-grid { display: flex; gap: 18px; flex-wrap: wrap; }
.ps-j { display: flex; flex-direction: column; align-items: center; }
.ps-hands { display: flex; gap: 6px; }
.ps-h { display: flex; flex-direction: column; align-items: center; min-width: 2.2em; padding: 2px 4px; border-radius: 6px; background: var(--bg); }
.ps-dots { letter-spacing: 1px; font-size: 13px; color: var(--ink); line-height: 1.2; }
.ps-lr { font-size: 10px; color: var(--mute); }
.ps-name { font-weight: 700; font-size: 13px; margin-top: 2px; }
.ps-name[class*="j-"] { color: var(--c); }
.ps-name.j-A { --c: #d9534f; } .ps-name.j-B { --c: #2a7ab9; } .ps-name.j-C { --c: #3c9a3c; } .ps-name.j-D { --c: #c77c11; }
.ps-off { font-size: 11px; color: var(--mute); }
.pt-c.none { background: none; min-height: 1.6em; }
/* synchronous tables: a line per hand */
.pt-c { align-self: center; line-height: 1.35; }
.pt-row.pt-sync { align-items: center; margin: 2px 0 6px; }
.pt-lr2 { display: flex; flex-direction: column; gap: 3px; margin-right: 4px; }
.pt-lr2 i { font-style: normal; font-size: 10px; color: var(--mute); line-height: 1.35; padding: 3px 0; }
.pt-lines { display: flex; flex-direction: column; gap: 3px; }
.pt-lines .pt-cells { padding-left: calc(var(--off) * var(--col)); }
.pt-c.none { background: none; min-height: 0; visibility: hidden; }
.pt-c.none::before { content: "·"; }
.pt-block { margin-bottom: 8px; }
.pt-range { font-size: 11px; color: var(--mute); margin: 4px 0 2px 4.4em; }
.club { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; margin: 0 1px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.35); }
.club.c-red { background: #e74c3c; } .club.c-green { background: #27ae60; } .club.c-blue { background: #2e86de; }
.club.c-yellow { background: #f1c40f; } .club.c-white { background: #fff; border-color: #999; }
.origurl { font-size: 12px; color: var(--mute); word-break: break-all; margin-top: 2px; }
.brand.home { color: var(--mute); font-weight: 600; margin-right: -2px; } .brand.home::after { content: " ›"; }
/* the animation at a sensible size on wider screens: not the column's full width */
@media (min-width: 900px) { .mv-stage { max-width: 380px; margin: 0 auto; } .mv-ctl { max-width: 380px; margin-left: auto; margin-right: auto; } }
@media (min-width: 1200px) { .pat-side .mv-stage, .pat-side .mv-ctl { max-width: 290px; } .pat-cols { grid-template-columns: minmax(0, 1fr) 340px; } }
/* tablets: a smaller animation, with a button to see it big */
@media (min-width: 600px) and (max-width: 1199px) { .mv-stage, .mv-ctl { max-width: 300px; margin-left: auto; margin-right: auto; } }
.mv-card h2 { display: flex; justify-content: space-between; align-items: center; }
.mv-big-btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; font-size: 16px; line-height: 1; padding: 4px 8px; cursor: pointer; }
.mv-card.mv-full { position: fixed; inset: 3vh 3vw; z-index: 40; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.45); display: flex; flex-direction: column; }
.mv-card.mv-full .mv-stage { max-width: min(82vh, 92vw) !important; width: min(82vh, 92vw); margin: 0 auto; }
.mv-card.mv-full .mv-ctl { max-width: min(82vh, 92vw) !important; margin: 8px auto 0; }
/* below 1200px one column in the book's order: siteswap line, the book's words, our animation and readings, the rest */
@media (max-width: 1199px) {
  .pat-cols { display: flex; flex-direction: column; }
  .pat-side, .pat-main { display: contents; }
  .pat-main > * { order: 3; }
  .pat-main > article { order: 1; }
  .pat-model { order: 2; }
}
.filters .fsep { width: 1px; background: var(--line); margin: 2px 2px; }
.filters .jrow { display: inline-flex; gap: 4px; flex-wrap: nowrap; } .filters .jrow .chip { padding: 5px 9px; }
/* segmented filter bars (as the other books) */
.filters { align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; color: var(--ink); font: inherit; font-size: 14px; padding: 5px 11px; border-left: 1px solid var(--line); cursor: pointer; }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--accent); color: #fff; }
.seg .seg-l { padding: 5px 4px 5px 11px; font-size: 12px; color: var(--mute); align-self: center; }
.seg .seg-l + button { border-left: 0; }
/* juggle-table cells (the Anthology's): manipulator moves, dots, marks, where each goes next */
.pt-c.m { color: var(--ink); background: none; border: 1.5px solid var(--mute); font-weight: 600; }
.pt-c sup, .pt-c sub { font-size: 9px; line-height: 0; }
.pt-dots { font-size: 7px; letter-spacing: 1px; vertical-align: 6px; margin-right: 1px; }
.pt-mark { font-weight: 700; }
.pt-next { margin-left: 4px; font-size: 11px; color: var(--mute); white-space: nowrap; font-weight: 400; }
.pt-next b { font-weight: 700; }
.pt-next b.j-A { color: #d9534f; } .pt-next b.j-B { color: #2a7ab9; } .pt-next b.j-C { color: #3c9a3c; } .pt-next b.j-D { color: #c77c11; }
.pt-who.j-M, .ps-name.j-M { --c: #7d5ba6; } .pt-c.to-M { --c: #7d5ba6; }
.pt-colgrid { --col: 2.5em; }
.pt-colgrid .pt-c { font-size: 11px; padding: 2px 0; }
.pt-colgrid .pt-who { flex-basis: 3.6em; }
/* each juggler's track: a band with the juggler's colour down its side, a line between tracks, the beats where
   nothing happens shown as faint dots (the rhythm, and where someone waits); "→ next" pinned at the right */
.pt-row.j-A { --c: #d9534f; } .pt-row.j-B { --c: #2a7ab9; } .pt-row.j-C { --c: #3c9a3c; } .pt-row.j-D { --c: #c77c11; }
.pt-row.j-E { --c: #8a6d3b; } .pt-row.j-M { --c: #7d5ba6; }
.pt-grid { gap: 0; }
.pt-row { border-left: 3px solid var(--c, var(--line)); border-bottom: 1px solid var(--line); padding: 4px 0 4px 6px; background: color-mix(in srgb, var(--c, transparent) 6%, transparent); }
.pt-row:first-child { border-top: 1px solid var(--line); }
.pt-row.pt-sync { margin: 0; }
.pt-c.none { visibility: visible; color: var(--mute); opacity: .45; background: none; }
.pt-c.none::before { content: "·"; }
.pt-next { position: sticky; right: 0; margin-left: auto; padding: 2px 6px 2px 6px; font-size: 12px; z-index: 1;
  background: var(--card); box-shadow: -10px 0 8px -2px var(--card); }
.pt-lr2.pt-lr-blank i { visibility: hidden; }
.pt-lr2.pt-lr-blank i::before { content: "R"; }

/* starting clubs at the head of each juggler's row; the hand that throws first outlined */
.pt-st { display: inline-flex; gap: 3px; margin-right: 8px; flex: 0 0 auto; }
.pt-st .ps-h { min-width: 1.9em; padding: 1px 3px; }
.pt-st .ps-dots { font-size: 11px; }
.pt-st .ps-lr { font-size: 9px; }
.pt-st .ps-h.first { box-shadow: inset 0 0 0 1.5px var(--ink); }
.pt-st .ps-late { align-self: center; font-size: 10px; color: var(--mute); margin-left: 1px; }
.pt-st .club { width: .8em; height: .8em; margin: 0 .5px; border: 0; vertical-align: -.05em; }
/* the book's club colours, lighter */
.club.c-red { background: #f4a09a; } .club.c-green { background: #8fd4a4; } .club.c-blue { background: #9cc2f5; }
.club.c-yellow { background: #f7dc7a; } .club.c-white { background: #fff; border: 1px solid #bbb; }
/* the start chit beside each row, outside the row's coloured band */
.pt-rowwrap { display: flex; align-items: center; }
.pt-rowwrap .pt-row { flex: 1 1 auto; min-width: 0; }
.pt-rowwrap:first-child .pt-row { border-top: 1px solid var(--line); }
.pt-rowwrap .pt-st { margin-right: 6px; }
.pt-c .pz { font-weight: 400; margin-right: 1px; opacity: .9; }

/* a table throw pointed at: its tooltip */
.pt-tip { position: fixed; z-index: 50; max-width: 280px; background: var(--card, #fff); color: var(--fg, #222); border: 1px solid var(--line, #ccc); border-radius: 8px; padding: 6px 9px; font-size: 12.5px; line-height: 1.35; box-shadow: 0 4px 14px rgba(0,0,0,.25); pointer-events: none; }
.pt-tip span { color: var(--mute, #666); }
.pt-table .pt-c:not(.none) { cursor: pointer; }
