/* Aratu: music paper. The scenes are boxed like a score's rehearsal marks,
   the bar count is set in an engraver's face.
   A light theme for the classroom and the projector, a dark one for
   playing live. */

:root,
:root[data-theme="light"] {
  --bg: #f6f1e6;
  --paper: #fffdf8;
  --panel: #f1ead9;
  --line: #e2d8c3;
  --rule: #cfc2a8;
  --text: #2a2420;
  --soft: #5b5047;
  --muted: #8a7d70;
  --accent: #d9541e;
  --accent-ink: #ffffff;
  --accent-2: #b8860b;
  --mangue: #2f7d6d;
  --keyword: #b4431a;
  --dynamic: #a0640a;
  --number: #1f7a68;
  --barline: #7a6650;
  --marker: #b03a5b;
  --name: #6b3f1d;
  --chord: #2d5f9e;
  --hold: #a69684;
  --operator: #9a5a22;
  --error: #c4302b;
  --warning: #b07a00;
  --good: #2e8b57;
  --playing: rgba(217, 84, 30, 0.28);
  --code-bg: #fffdf8;
  --beatline: rgba(122, 102, 80, 0.45);
  --stepline: rgba(122, 102, 80, 0.16);
  --shadow: 0 1px 0 rgba(60, 40, 20, 0.05), 0 6px 18px -8px rgba(60, 40, 20, 0.16);
  /* The display in the transport: dark ink on the paper. */
  --display-bg: #2a2420;
  --display-text: #f6ecdc;
  --display-muted: #b3a28c;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.42 0 0 0 0 0.3 0 0 0 0 0.16 0 0 0 0.16 0'/></filter><rect width='100%25' height='100%25' filter='url(%23g)'/></svg>");
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15100d;
  --paper: #1d1612;
  --panel: #221a15;
  --line: #3a2d24;
  --rule: #4c3b2f;
  --text: #f3e6dc;
  --soft: #d6c4b5;
  --muted: #a38e7d;
  --accent: #ff6a1a;
  --accent-ink: #1a0e07;
  --accent-2: #ffb547;
  --mangue: #6cc5ae;
  --keyword: #ff8a3d;
  --dynamic: #ffcf5c;
  --number: #7fd6c2;
  --barline: #c9a48a;
  --marker: #ff9db0;
  --name: #ffd9b8;
  --chord: #9fc7ff;
  --hold: #8c7464;
  --operator: #e0a070;
  --error: #ff6b6b;
  --warning: #ffc04d;
  --good: #59d18a;
  --playing: rgba(255, 106, 26, 0.4);
  --code-bg: #120d0b;
  --beatline: rgba(201, 164, 138, 0.4);
  --stepline: rgba(201, 164, 138, 0.13);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 20px -10px rgba(0, 0, 0, 0.6);
  --display-bg: #0b0806;
  --display-text: #f3e6dc;
  --display-muted: #9b8574;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.95 0 0 0 0 0.85 0 0 0 0 0.7 0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23g)'/></svg>");
  color-scheme: dark;
}

:root {
  --font-display: "Gloock", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Atkinson Hyperlegible Mono", "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --radius: 6px;
  --top-h: 66px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  /* What a phone's camera, round corners and home bar cover: nothing is
     put there. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  background-image: var(--grain);
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

[hidden] {
  display: none !important;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg.i {
  width: 18px;
  height: 18px;
  flex: none;
}

.serif,
h1,
h2,
h3,
.brand .name {
  font-family: var(--font-display);
  font-weight: 400;
}

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

::selection {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

/* The header. The tab you are on is underlined in orange. */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px 30px;
  height: calc(var(--top-h) + var(--safe-top));
  padding: var(--safe-top) clamp(14px, 3vw, 30px) 0;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
}

.brand img {
  display: block;
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  min-width: 0;
}

.brand .name {
  font-size: 31px;
  letter-spacing: 0.005em;
  color: var(--accent);
}

.brand .tagline {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  white-space: nowrap;
}

.tabs {
  display: flex;
  align-self: stretch;
  gap: 2px;
}

.tabs a {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 15px;
  color: var(--soft);
  text-decoration: none;
  font-weight: 600;
  font-size: 15.5px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: color 150ms;
}

.tabs a:hover {
  color: var(--text);
}

.tabs a::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 220ms var(--ease);
}

.tabs a.here {
  color: var(--text);
}

.tabs a.here::after {
  transform: scaleX(1);
}

.prefs {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Buttons. */

button,
select {
  font: inherit;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  transition:
    border-color 150ms,
    background-color 150ms,
    color 150ms,
    transform 80ms;
}

button:hover,
select:hover {
  border-color: var(--accent);
}

button:active {
  transform: translateY(1px);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  white-space: nowrap;
}

.btn.big {
  height: 46px;
  padding: 0 18px;
  font-size: 16px;
}

.btn-play {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--accent) 55%, #000);
}

.btn-play:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 88%, #fff);
}

/* Playing: green, the mangrove's colour, with a slow breath. */
.btn-play.on {
  background: var(--mangue);
  border-color: var(--mangue);
  color: var(--accent-ink);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--mangue) 55%, #000);
}

.btn-check {
  background: var(--mangue);
  border-color: var(--mangue);
  color: var(--accent-ink);
}

.btn-goal {
  color: var(--mangue);
  border-color: var(--mangue);
}

.btn-quiet {
  color: var(--soft);
  font-weight: 500;
}

/* Segmented choices: the languages, the grid. */

.lang,
.seg {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  overflow: hidden;
}

.lang button,
.lang a,
.seg button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 5px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--soft);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-decoration: none;
}

.lang button + button,
.lang a + a,
.seg button + button {
  border-left: 1px solid var(--line);
}

.lang button:hover,
.lang a:hover,
.seg button:hover {
  color: var(--text);
  background: var(--panel);
}

.lang button.on,
.lang a.on,
.seg button.on {
  background: var(--accent);
  color: var(--accent-ink);
}

.theme-switch {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
}

.theme-switch button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}

.theme-switch button .i {
  width: 17px;
  height: 17px;
}

.theme-switch button.on {
  background: var(--panel);
  color: var(--accent);
}

/* Views, and how they come in. */

.view {
  flex: 1;
  min-height: 0;
  /* Nothing coming in from the side may widen a phone's page. */
  overflow-x: clip;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@keyframes turn {
  from {
    opacity: 0.15;
    transform: translateY(6px);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .toolbar > *,
  .tools > *,
  .play-view > .work,
  .play-view > .rhythm,
  .book-view > .toc,
  .book-view > .page {
    animation: rise 520ms var(--ease) both;
  }
  .toolbar > :nth-child(2) {
    animation-delay: 50ms;
  }
  .tools > * {
    animation-delay: 100ms;
  }
  .play-view > .work,
  .book-view > .page {
    animation-delay: 140ms;
  }
  .play-view > .rhythm {
    animation-delay: 220ms;
  }
  .page.turn {
    animation: turn 380ms var(--ease) both;
  }
}

/* Play. */

.play-view {
  display: flex;
  flex-direction: column;
  padding: 16px clamp(12px, 2vw, 24px) 10px;
  gap: 14px;
}

/* The transport: the buttons, the display, the stage and sharing; under
   them, over the score, its rehearsal marks and the examples. */

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto auto;
  grid-template-areas:
    "transport status follow daw stage share"
    "scenes scenes scenes scenes examples examples";
  align-items: center;
  gap: 12px;
}

/* While the page scrolls (following the music, say), the transport stays
   in reach under the header. */
@media (min-width: 721px) and (min-height: 501px) {
  .toolbar {
    position: sticky;
    top: calc(var(--top-h) + var(--safe-top));
    z-index: 6;
    margin: -16px calc(-1 * clamp(12px, 2vw, 24px)) 0;
    padding: 16px clamp(12px, 2vw, 24px) 10px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(8px);
  }
}

.transport {
  grid-area: transport;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tools {
  display: contents;
}

#follow {
  grid-area: follow;
}

#stage {
  grid-area: stage;
}

#daw {
  grid-area: daw;
}

/* The account: the button at the top and its panel. */
.account-open {
  height: 34px;
  max-width: 160px;
  padding: 0 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}

.account-open.on {
  border-color: var(--mangue);
  color: var(--mangue);
}

.acct-panel {
  position: absolute;
  z-index: 80;
  width: min(380px, calc(100vw - 16px));
  max-height: min(78vh, 680px);
  overflow-y: auto;
  padding: 14px 16px 16px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow), 0 18px 40px -18px rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
}

.acct-panel h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.acct-panel h4 {
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.acct-about,
.acct-note {
  margin: 0 0 10px;
  color: var(--soft);
  font-size: 13px;
  line-height: 1.45;
}

.acct-tabs {
  display: flex;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.acct-tabs button {
  flex: 1;
  justify-content: center;
}

.acct-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.acct-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--soft);
  font-size: 13px;
}

.acct-field input,
.acct-title {
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.acct-guardian {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 8px 10px 10px;
  border: 1px dashed var(--rule);
  border-radius: 8px;
}

.acct-guardian legend {
  padding: 0 4px;
  color: var(--soft);
  font-size: 12px;
}

.acct-terms {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--soft);
  font-size: 13px;
  line-height: 1.4;
}

.acct-terms a,
.acct-link {
  color: var(--accent);
}

.acct-link {
  align-self: center;
  font-size: 13px;
}

.acct-go {
  height: 38px;
}

.acct-error {
  margin: 0;
  color: var(--error);
  font-size: 13px;
}

.acct-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.acct-who {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.acct-who span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
}

.acct-out {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.acct-title {
  width: 100%;
  margin-bottom: 8px;
  box-sizing: border-box;
  font-weight: 600;
}

.acct-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.acct-row .btn {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.acct-status {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: var(--soft);
  font-size: 12px;
}

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

.acct-list li {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--line);
}

.acct-list li.on .acct-name {
  color: var(--accent);
}

.acct-open {
  display: flex;
  flex: 1;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.acct-open:hover .acct-name {
  text-decoration: underline;
}

.acct-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.acct-when {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.acct-del {
  width: 28px;
  height: 28px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

.acct-del:hover {
  color: var(--error);
}

.acct-versions {
  margin: 8px 0 0;
}

/* Playing in a DAW: the port, the button and how it stands. */
.daw-panel {
  position: absolute;
  z-index: 70;
  width: min(340px, calc(100vw - 16px));
  padding: 12px 14px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow), 0 18px 40px -18px rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-family: var(--font-ui);
}

.daw-panel h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.daw-panel p {
  margin: 0 0 10px;
  color: var(--soft);
  font-size: 13px;
  line-height: 1.45;
}

.daw-port {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
}

.daw-port input {
  width: 96px;
  padding: 6px 8px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--text);
  font: inherit;
}

.daw-connect {
  width: 100%;
  height: 36px;
  margin-bottom: 10px;
}

.daw-panel .daw-state {
  margin: 0;
  color: var(--text);
}

.tools .btn.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--paper));
  color: var(--accent);
}

/* The sound on the display: its wave, or its frequencies. */
.scope {
  flex: 1 1 auto;
  align-self: stretch;
  min-width: 0;
  height: auto;
  margin: 8px 0;
  color: var(--accent);
  cursor: pointer;
}

/* Drawings under a line of the code (`bass.wave`, `arp.roll`), as wide as
   a line of music and as tall as two of text. */
.cm-visual {
  padding: 2px 0 8px;
}

.cm-visual canvas {
  display: block;
  width: min(100%, 46em);
  height: 2.6em;
  border-radius: 4px;
  background:
    linear-gradient(color-mix(in srgb, var(--accent) 22%, transparent), color-mix(in srgb, var(--accent) 22%, transparent))
      0 50% / 100% 1px no-repeat,
    color-mix(in srgb, var(--panel) 55%, transparent);
  color: var(--accent);
}

/* An effect's curve beside its name in a chain; the tube glows as hard as
   it is driven. */
.cm-fx {
  display: inline-block;
  margin: 0 3px 0 4px;
  padding: 0 2px;
  vertical-align: middle;
  border-radius: 3px;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  color: var(--accent);
  line-height: 0;
}

.cm-fx svg {
  display: block;
  width: 2.9em;
  height: 1em;
}

.cm-fx-curve {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.cm-fx-zero {
  stroke: color-mix(in srgb, var(--muted) 50%, transparent);
  stroke-width: 0.8;
}

.cm-fx-eq {
  cursor: pointer;
}

.cm-fx-eq:hover {
  outline: 1px solid var(--accent);
}

.cm-fx-tube {
  box-shadow: 0 0 calc(var(--heat, 0) * 12px) color-mix(in srgb, var(--accent) calc(var(--heat, 0) * 90%), transparent);
}

/* The equalizer, opened from its curve. */
.eq-panel {
  position: absolute;
  z-index: 70;
  width: 344px;
  padding: 10px 12px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow), 0 18px 40px -18px rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-family: var(--font-ui);
}

.eq-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.eq-head b {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
}

.eq-close {
  padding: 2px 8px;
  border: 0;
  background: none;
  color: var(--muted);
}

.eq-graph {
  display: block;
  width: 320px;
  height: 150px;
  border-radius: 4px;
  background: var(--code-bg);
  touch-action: none;
}

.eq-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.eq-zero {
  stroke: var(--rule);
}

.eq-curve {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
}

.eq-band {
  fill: var(--accent);
  stroke: var(--paper);
  stroke-width: 2;
  cursor: grab;
}

.eq-mid {
  fill: var(--accent-2);
}

.eq-high {
  fill: var(--mangue);
}

.eq-legend,
.eq-hint {
  margin: 8px 0 0;
  color: var(--soft);
  font-size: 12px;
  line-height: 1.4;
}

.eq-hint {
  color: var(--muted);
}

.eq-legend {
  white-space: pre-line;
  font-variant-numeric: tabular-nums;
}

.cm-visual-roll canvas {
  height: 3.4em;
  background: color-mix(in srgb, var(--panel) 55%, transparent);
}

#share {
  grid-area: share;
}

#scenes {
  grid-area: scenes;
}

.examples {
  grid-area: examples;
  justify-self: end;
}

.btn-stop .i {
  width: 16px;
  height: 16px;
}

.btn.record .i {
  color: var(--error);
}

.status {
  grid-area: status;
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 46px;
  padding: 0 18px;
  border-radius: var(--radius);
  background: var(--display-bg);
  color: var(--display-text);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

:root[data-theme="dark"] .status {
  box-shadow: inset 0 0 0 1px var(--line);
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.stat b {
  color: var(--display-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1;
  text-transform: uppercase;
}

#bar,
#bpm,
.sig,
.btn.scene,
#stage-bar-n,
.stage-tempo,
.toc-n {
  font-variant-numeric: lining-nums tabular-nums;
}

#bar {
  min-width: 2ch;
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1;
}

#bpm {
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1;
}

/* The meter, stacked as a score writes it. */
.sig {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 0.86;
}

#meter:not(:has(.sig)) {
  font-family: var(--font-display);
  font-size: 18px;
}

/* The beats of the bar: the first bigger, the one now lit. */
.beat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.beat i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: color-mix(in srgb, currentColor 22%, transparent);
  transition:
    background 70ms,
    transform 70ms;
}

.beat i:first-child {
  width: 11px;
  height: 11px;
}

.beat i.now {
  background: color-mix(in srgb, currentColor 70%, transparent);
}

.beat i.hit {
  background: var(--accent);
  transform: scale(1.35);
}

/* How far the bar has gone, along the display's foot. */
.bar-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  pointer-events: none;
}

.bar-progress.run {
  animation: bar-run var(--bar-len, 2s) linear both;
}

@keyframes bar-run {
  to {
    transform: scaleX(1);
  }
}

.tools .btn {
  height: 40px;
  padding: 0 14px;
}

.examples {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.examples select {
  max-width: 240px;
  height: 40px;
  padding: 0 34px 0 12px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a7d70' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

/* Scenes: eight places for the piece, boxed like a score's rehearsal
   marks; in the toolbar and on stage. */
.scenes {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.scenes-label {
  margin-right: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.btn.scene {
  width: 30px;
  height: 32px;
  padding: 0;
  border: 1.5px dashed var(--rule);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.btn.scene.filled {
  border-style: solid;
  border-color: var(--text);
  background: var(--paper);
  color: var(--text);
}

.btn.scene.on {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

/* Recording: the button glows while it records. */
.btn.record.on {
  color: var(--error);
  border-color: var(--error);
  animation: record-pulse 1.2s ease-in-out infinite;
}

@keyframes record-pulse {
  50% {
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--error) 25%, transparent);
  }
}

.work {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  min-height: 440px;
}

.sheet {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.editor .cm-editor {
  height: 100%;
}

.side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow);
}

.side > div:not(.side-tabs) {
  padding: 14px 16px;
}

.side h2,
.toc h2 {
  margin: 0 0 10px;
  font-size: 22px;
  color: var(--text);
}

.side-tabs {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 2px;
  padding: 0 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.side-tabs button {
  padding: 12px 10px 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.side-tabs button:hover {
  color: var(--text);
}

.side-tabs button.on {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.messages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.messages li {
  padding: 9px 12px;
  border-left: 3px solid var(--warning);
  background: var(--panel);
  border-radius: 0 4px 4px 0;
  font-size: 15px;
  line-height: 1.45;
  cursor: pointer;
}

.messages li.error {
  border-left-color: var(--error);
}

.messages li.good {
  border-left-color: var(--good);
  cursor: default;
}

.messages li small {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.note {
  color: var(--soft);
  font-size: 14px;
}

/* The Sounds panel. */

.sound-search {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--text);
  font: inherit;
}

.sound-help {
  margin: 8px 0 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.sound-family {
  margin: 16px 0 4px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sound-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.sound-play {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--paper);
  color: var(--accent);
  font-size: 11px;
}

.sound-play.on {
  background: var(--accent);
  color: var(--accent-ink);
}

.sound-code {
  flex: none;
  padding: 2px 6px;
  border: 0;
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  cursor: copy;
}

.sound-code:hover {
  outline: 1px solid var(--accent);
}

.sound-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sound-state {
  flex: none;
  padding: 1px 6px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent-2) 22%, transparent);
  color: var(--text);
  font-size: 11px;
}

.sound-state[data-state="ready"] {
  background: color-mix(in srgb, var(--mangue) 30%, transparent);
}

.sound-state[data-state="failed"] {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}

/* Which engine plays a voice. */

.sound-engine {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 10px;
  font-size: 13px;
  cursor: pointer;
}

.sound-mb {
  flex: none;
  padding: 1px 6px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--mangue) 22%, transparent);
  color: var(--text);
  font-size: 11px;
}

/* The twelve-tone matrix. */

.matrix-toggle {
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.matrix {
  margin-top: 10px;
  overflow-x: auto;
}

.matrix-grid {
  display: grid;
  grid-template-columns: repeat(calc(var(--n) + 2), minmax(26px, auto));
  gap: 1px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.matrix-cell,
.matrix-form,
.matrix-corner {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 2px;
}

.matrix-cell {
  background: var(--code-bg);
  color: var(--text);
}

.matrix-cell.prime {
  background: color-mix(in srgb, var(--accent) 18%, var(--code-bg));
}

.matrix-form {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: copy;
}

.matrix-form:hover {
  text-decoration: underline;
}

/* The rhythm map under the editor. */

.rhythm {
  padding: 14px 16px 16px;
}

.rhythm-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  margin-bottom: 10px;
}

.rhythm-head h2 {
  margin: 0;
  font-size: 22px;
  color: var(--text);
}

.rhythm-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  flex: 1;
  min-width: 260px;
}

.quantum-label {
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.quantum-label + button {
  border-left: 0 !important;
}

.rhythm-grid {
  overflow-x: auto;
}

.rhythm-grid .grid-row {
  grid-template-columns: 120px repeat(var(--bars), minmax(max(240px, var(--bar-min, 0px)), 1fr));
}

.rhythm-grid .grid-bar {
  height: 34px;
}

.rhythm-grid .grid-hit {
  top: 6px;
  height: 22px;
  line-height: 22px;
  font-size: 13px;
}

.rhythm-grid .grid-label {
  font-size: 13px;
}

/* The timeline: bar numbers and sections on top, the names kept in sight
   while it scrolls, a playhead across every row. */
.grid.timeline {
  position: relative;
}

.timeline .grid-label {
  position: sticky;
  left: 0;
  z-index: 3;
  align-self: stretch;
  display: flex;
  align-items: center;
  padding-right: 6px;
  background: var(--paper);
}

.grid-head .grid-label {
  background: var(--paper);
}

.grid-mark {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 8px;
  height: 22px;
  padding-left: 3px;
  border-left: 2px solid var(--barline);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.grid-mark b {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
}

.grid-section {
  padding: 0 6px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.timeline .grid-num {
  display: none;
}

.timeline .grid-bar.playing::after {
  display: none;
}

.grid-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  width: 2px;
  margin-left: -1px;
  background: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms;
}

.grid-playhead.on {
  opacity: 1;
}

.grid-playhead::before {
  content: "";
  position: absolute;
  top: 0;
  left: -5px;
  border: 6px solid transparent;
  border-top: 8px solid var(--accent);
  border-bottom: 0;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* The code editor, everywhere. */

.cm-editor {
  font-size: 15.5px;
  background: var(--code-bg);
}

.cm-editor.cm-focused {
  outline: none;
}

/* CodeMirror's own theme names a plain monospace, after this sheet. */
.cm-scroller {
  font-family: var(--font-mono) !important;
  line-height: 1.7;
}

/* The gutter ends in a double rule, like a system's first bar line. */
.cm-gutters {
  background: color-mix(in srgb, var(--panel) 65%, var(--code-bg)) !important;
  color: var(--muted) !important;
  border-right: 3px double var(--rule) !important;
}

.cm-activeLine,
.cm-activeLineGutter {
  background: rgba(217, 84, 30, 0.05) !important;
}

.cm-cursor {
  border-left-color: var(--accent) !important;
  border-left-width: 2px !important;
}

.cm-selectionBackground,
.cm-focused .cm-selectionBackground {
  background: rgba(217, 84, 30, 0.2) !important;
}

.cm-playing {
  background: var(--playing);
  border-radius: 3px;
  box-shadow: 0 0 6px var(--playing);
}

.cm-tooltip {
  background: var(--paper) !important;
  color: var(--text);
  border: 1px solid var(--line) !important;
  border-radius: var(--radius);
  font-family: var(--font-ui);
}

/* The book. */

.book-view {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 0;
}

.toc {
  position: sticky;
  top: calc(var(--top-h) + var(--safe-top));
  align-self: start;
  max-height: calc(100vh - var(--top-h) - var(--safe-top));
  overflow: auto;
  padding: 26px 16px 32px 20px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 70%, transparent);
}

.toc-toggle {
  display: none;
}

.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 1px;
}

.toc li a {
  display: grid;
  grid-template-columns: 2em minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 2px 6px;
  padding: 7px 10px 7px 8px;
  border-radius: 4px;
  text-decoration: none;
  color: var(--soft);
  font-size: 15px;
  line-height: 1.3;
  transition:
    background 120ms,
    color 120ms;
}

.toc-n {
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.toc li a:hover {
  background: var(--paper);
  color: var(--text);
}

.toc li a.here {
  background: var(--paper);
  color: var(--text);
  font-weight: 600;
  box-shadow:
    inset 3px 0 0 var(--accent),
    var(--shadow);
}

.toc li a.here .toc-n {
  color: var(--accent);
}

.toc li.done a::after {
  content: "✓";
  color: var(--good);
  font-weight: 700;
}

.progress {
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.page {
  padding: 40px clamp(18px, 5vw, 72px) 72px;
  max-width: 900px;
  width: 100%;
  font-size: 18px;
  line-height: 1.7;
}

.page h1 {
  font-size: 46px;
  line-height: 1.08;
  letter-spacing: -0.005em;
  margin: 0 0 8px;
  padding-bottom: 20px;
  /* A short orange rule under the title. */
  background: linear-gradient(var(--accent), var(--accent)) left bottom / 56px 3px no-repeat;
}

.page h2 {
  font-size: 29px;
  line-height: 1.2;
  margin: 46px 0 10px;
  color: var(--name);
}

.page h3 {
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 700;
  margin: 28px 0 6px;
}

.page p,
.page li {
  color: var(--text);
}

.page code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--panel);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--name);
}

.page pre {
  background: var(--panel);
  padding: 12px 14px;
  border-radius: var(--radius);
  overflow: auto;
  font-size: 15px;
}

.page pre code {
  background: none;
  padding: 0;
}

.page table {
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 16px;
  width: 100%;
}

.page th,
.page td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.page th {
  border-bottom: 2px solid var(--rule);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.page blockquote {
  position: relative;
  margin: 22px 0;
  padding: 14px 18px 14px 66px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-2);
  border-radius: 0 var(--radius) var(--radius) 0;
  box-shadow: var(--shadow);
}

/* The crab gives tips. */
.page blockquote::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 14px;
  width: 38px;
  height: 38px;
  background: url("mascot.png") center / cover;
  border-radius: 8px;
}

.page blockquote p {
  margin: 6px 0;
}

.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.page-nav a {
  padding: 12px 18px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  font-weight: 600;
  text-decoration: none;
  transition:
    border-color 150ms,
    transform 150ms var(--ease);
}

.page-nav a:hover {
  border-color: var(--accent);
}

.page-nav a.next {
  margin-left: auto;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--accent) 55%, #000);
}

.page-nav a.next:hover {
  transform: translateX(3px);
}

.page-link {
  margin: 18px 0 0;
  font-size: 14px;
}

.page-link a {
  color: var(--muted);
}

/* The pages to read (scripts/site.mjs): the book without the editor, which
   need no script, for search engines and for sharing a link. */

a.btn {
  padding: 8px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--text);
  text-decoration: none;
}

a.btn:hover {
  border-color: var(--accent);
}

a.btn-play {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.read-view {
  display: flex;
  justify-content: center;
}

.open-in {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin: 16px 0 24px;
  color: var(--soft);
  font-size: 16px;
}

.read-list {
  padding-left: 1.4em;
}

.read-list li {
  margin: 12px 0;
}

.read-list a {
  font-weight: 600;
}

.read-list p {
  margin: 2px 0 0;
  color: var(--soft);
  font-size: 16px;
  line-height: 1.5;
}

.page .read-block pre {
  margin: 0;
  border-radius: 0;
  background: var(--code-bg);
}

.read-block .block-answer {
  border-top: 1px solid var(--line);
  padding: 8px 14px;
}

.read-block .block-answer summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--mangue);
}

.page .read-block .block-answer pre {
  margin: 8px -14px -8px;
  border-top: 1px solid var(--line);
}

/* A live block. */

.aratu-block {
  margin: 22px 0 28px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.aratu-block[data-kind="exercise"] {
  border-color: var(--mangue);
  border-width: 1.5px;
}

.block-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 9px 12px 9px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.block-label {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.aratu-block[data-kind="exercise"] .block-label {
  color: var(--mangue);
}

.block-label.done::after {
  content: " ✓";
  color: var(--good);
}

.block-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.block-buttons .btn {
  height: 34px;
  padding: 0 12px;
  font-size: 14px;
}

.block-editor .cm-editor {
  font-size: 16.5px;
}

.block-editor .cm-content {
  padding: 10px 6px;
}

.block-result:empty {
  display: none;
}

.block-result {
  padding: 10px 16px;
  font-size: 16px;
  border-top: 1px solid var(--line);
}

.block-result p {
  margin: 4px 0;
}

.block-result ul {
  margin: 6px 0 4px;
  padding-left: 20px;
}

.block-result.good {
  background: color-mix(in srgb, var(--good) 12%, var(--paper));
  color: var(--text);
  font-weight: 600;
}

.block-result.almost {
  background: color-mix(in srgb, var(--warning) 12%, var(--paper));
}

.block-result.bad {
  background: color-mix(in srgb, var(--error) 10%, var(--paper));
}

.block-result li.more {
  color: var(--muted);
  list-style: none;
}

.block-goal {
  border-top: 1px dashed var(--mangue);
}

/* The rhythm grid: beats of each bar, with the written symbols on them. */

.block-grid:empty {
  display: none;
}

.block-grid {
  padding: 8px 14px 12px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
}

.grid {
  display: grid;
  gap: 4px;
  min-width: min-content;
  padding-top: 16px;
}

.grid-row {
  display: grid;
  /* A bar with many steps is wider, so each step keeps room for its letter. */
  grid-template-columns: 92px repeat(var(--bars), minmax(max(150px, var(--bar-min, 0px)), 1fr));
  gap: 6px;
  align-items: center;
}

.grid-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid-bar {
  position: relative;
  height: 30px;
  border-left: 2px solid var(--barline);
  border-right: 2px solid var(--barline);
  border-radius: 3px;
  background-color: var(--panel);
  background-image:
    linear-gradient(to right, var(--beatline) 0 2px, transparent 2px),
    linear-gradient(to right, var(--stepline) 0 1px, transparent 1px);
  background-size:
    calc(100% / var(--beats)) 100%,
    calc(100% / var(--steps)) 100%;
  cursor: copy;
  touch-action: none;
}

.grid-bar.repeat .grid-hit:not(.on) {
  opacity: 0.45;
}

.grid-empty {
  height: 30px;
}

.grid-bar.locked {
  cursor: default;
  background-color: transparent;
  opacity: 0.75;
}

.grid-num {
  position: absolute;
  top: -17px;
  font-size: 11px;
  color: var(--muted);
  padding-left: 3px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.grid-hit {
  position: absolute;
  top: 5px;
  transform: translateX(1px);
  min-width: 18px;
  height: 20px;
  padding: 0 4px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  white-space: nowrap;
  transition:
    transform 80ms ease-out,
    background 80ms;
}

.grid-hit.short {
  min-width: 0;
  max-width: 18px;
  padding: 0;
}

.grid-hit.long {
  text-align: left;
  border-radius: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-tie {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
  min-width: 0;
  border-radius: 0 6px 6px 0;
}

.grid-hit:not(.grid-tie) {
  cursor: grab;
}

.grid-bar.locked .grid-hit {
  cursor: default;
}

.grid-hit.dragging {
  cursor: grabbing;
  opacity: 0.85;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  z-index: 2;
}

/* An accent: bigger, bolder, ringed, with the score's accent sign above. */

.grid-hit.accented {
  font-weight: 800;
  box-shadow: 0 0 0 2px var(--text);
  z-index: 1;
}

.grid-hit.accented::after {
  /* The accent wedge, wide and flat as a score draws it. */
  content: "";
  position: absolute;
  left: 50%;
  top: -11px;
  width: 14px;
  height: 8px;
  transform: translateX(-50%);
  background: var(--text);
  clip-path: polygon(0 0, 100% 50%, 0 100%, 0 78%, 66% 50%, 0 22%);
  pointer-events: none;
}

.grid-hit:not(.accented):not(.long):not(.grid-tie) {
  transform: translateX(1px) scale(0.85);
}

/* The needle, and the symbols it passes. */

.grid-bar.playing::after {
  content: "";
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: calc(var(--pos) * 100%);
  width: 2px;
  background: var(--mangue);
  border-radius: 1px;
  pointer-events: none;
}

.grid-hit.on,
.grid-hit.on:not(.accented):not(.long):not(.grid-tie) {
  transform: translateX(1px) scale(1.3);
  background: var(--mangue);
  z-index: 1;
}

/* Knobs beside numbers. */

.cm-knob {
  display: inline-block;
  vertical-align: middle;
  margin: 0 2px 0 4px;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}

.cm-knob svg {
  display: block;
}

.cm-knob .track {
  fill: var(--panel);
  stroke: var(--line);
  stroke-width: 2;
}

.cm-knob .value {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.cm-knob line {
  stroke: var(--accent-2);
  stroke-width: 2;
  stroke-linecap: round;
}

.cm-knob:hover .track,
.cm-knob.turning .track {
  stroke: var(--accent);
}

/* A parameter that moves: a second needle shows where it is now. */
.cm-knob line.now {
  display: none;
  stroke: var(--accent);
  stroke-width: 2.5;
}

.cm-knob.moving line.now {
  display: inline;
}

.cm-knob.moving .track {
  stroke: var(--accent);
}

/* The footer. */

.bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  padding: 12px clamp(14px, 3vw, 30px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  background: var(--paper);
}

/* What is downloading, and the sounds that could not be: over every view,
   the stage included. */

.sound-status {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 60;
  width: min(640px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sound-status[hidden] {
  display: none;
}

.sound-status p {
  margin: 0;
  padding: 9px 12px;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  line-height: 1.35;
}

.sound-status .sound-loading::before {
  content: "";
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-right: 8px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-right-color: transparent;
  vertical-align: -1px;
  animation: sound-spin 0.8s linear infinite;
}

@keyframes sound-spin {
  to {
    transform: rotate(360deg);
  }
}

.sound-status .sound-problem {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-color: var(--error);
  border-left-width: 4px;
}

.sound-status .sound-problem span {
  flex: 1;
}

.sound-status .sound-problem span::before {
  content: "⚠ ";
  color: var(--error);
}

.sound-status .sound-problem button {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  padding: 0 2px;
}

/* The stage: the code, full screen, under a rail that always shows where
   the piece is. The controls on the rail fade while the mouse rests. */

.stage-bar,
.stage-msg {
  display: none;
}

body.stage {
  --rail: 64px;
  overflow: hidden;
  background: var(--code-bg);
}

body.stage .top,
body.stage .bottom,
body.stage .toolbar,
body.stage .side,
body.stage .hint,
body.stage #view-play > .rhythm {
  display: none !important;
}

body.stage .play-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  margin: 0;
  padding: 0;
  max-width: none;
  background: var(--code-bg);
  animation: none;
}

body.stage .play-view > * {
  animation: none;
}

body.stage .work {
  position: absolute;
  inset: calc(var(--rail) + var(--safe-top)) var(--safe-right) 0 var(--safe-left);
  display: block;
  height: auto;
  min-height: 0;
}

/* The first beat of each bar breathes along the edges of the code. */
body.stage .work::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 0 transparent;
  transition: box-shadow 160ms ease-out;
}

body.stage.downbeat .work::after {
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--accent) 75%, transparent),
    inset 0 0 90px color-mix(in srgb, var(--accent) 16%, transparent);
  transition-duration: 30ms;
}

body.stage #editor,
body.stage #editor-mirror {
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--code-bg);
}

body.stage #editor .cm-editor,
body.stage #editor-mirror .cm-editor {
  font-size: var(--stage-font, 30px);
}

body.stage #editor .cm-gutters,
body.stage #editor-mirror .cm-gutters {
  display: none;
}

body.stage #editor .cm-content {
  padding: 5vh 6vw 30vh;
}

body.stage .cm-scroller {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

body.stage .cm-activeLine {
  background: transparent !important;
}

body.stage .cm-playing {
  box-shadow:
    0 0 18px var(--playing),
    0 0 4px var(--playing);
}

body.stage .stage-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 18px;
  height: calc(var(--rail) + var(--safe-top));
  padding: var(--safe-top) max(14px, var(--safe-right)) 0 max(22px, var(--safe-left));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  transition: box-shadow 160ms ease-out;
}

body.stage.downbeat .stage-bar {
  box-shadow: 0 10px 34px -16px color-mix(in srgb, var(--accent) 70%, transparent);
  transition-duration: 30ms;
}

.stage-hud {
  display: flex;
  align-items: center;
  gap: 18px;
  flex: none;
}

.stage-count {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  color: var(--text);
}

#stage-bar-n {
  min-width: 2ch;
  font-family: var(--font-display);
  font-size: 42px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color 160ms;
}

body.stage.downbeat #stage-bar-n {
  color: var(--accent);
  transition-duration: 30ms;
}

.stage-count .beat i {
  width: 10px;
  height: 10px;
}

.stage-count .beat i:first-child {
  width: 14px;
  height: 14px;
}

.stage-tempo {
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 18px;
  white-space: nowrap;
}

.stage-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
  transition: opacity 400ms;
}

body.stage .stage-bar .stage-exit {
  flex: none;
  transition:
    opacity 400ms,
    border-color 150ms,
    color 150ms;
}

.stage-controls::-webkit-scrollbar {
  display: none;
}

.stage-controls > * {
  flex: none;
}

.stage-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

body.stage .stage-bar .btn {
  height: 40px;
  padding: 0 12px;
  border-color: var(--line);
  background: transparent;
  color: var(--soft);
  font-size: 14px;
}

body.stage .stage-bar .btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

body.stage .stage-bar .btn.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

body.stage .stage-bar .btn-play,
body.stage .stage-bar #stage-stop {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
}

body.stage .stage-bar .btn-play {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

body.stage .stage-bar .btn-play.on {
  background: var(--mangue);
  border-color: var(--mangue);
  color: var(--accent-ink);
}

.font-step {
  font-family: var(--font-display);
  font-size: 18px !important;
  font-weight: 400 !important;
}

.font-step small {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
}

body.stage .stage-exit:hover {
  border-color: var(--error) !important;
  color: var(--error) !important;
}

/* The labels show where there is room; the icons always. */
@media (max-width: 1360px) {
  .stage-tools .btn span {
    display: none;
  }
}

body.stage .stage-bar .scenes-label {
  display: none;
}

body.stage .stage-bar .btn.scene {
  width: 32px;
  height: 36px;
  padding: 0;
  border-color: var(--line);
  font-size: 16px;
}

body.stage .stage-bar .btn.scene.filled {
  border-color: var(--soft);
  color: var(--text);
  background: transparent;
}

body.stage .stage-bar .btn.scene.on {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

body.stage .stage-bar .bar-progress {
  bottom: -1px;
}

body.stage.idle {
  cursor: none;
}

body.stage.idle .stage-controls,
body.stage.idle .stage-bar .stage-exit {
  opacity: 0;
  pointer-events: none;
}

/* A problem in the piece shows at the foot, never over the line being
   written. */
body.stage .stage-msg:not([hidden]) {
  display: block;
  position: fixed;
  left: max(20px, var(--safe-left));
  bottom: calc(18px + var(--safe-bottom));
  z-index: 30;
  max-width: min(64vw, 760px);
  margin: 0;
  padding: 10px 16px;
  border-left: 3px solid var(--error);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  color: var(--text);
  font-size: clamp(14px, calc(var(--stage-font, 30px) * 0.5), 22px);
  line-height: 1.4;
  box-shadow: var(--shadow);
}

body.stage.stage-map .work {
  bottom: 36vh;
}

body.stage.stage-map #view-play > .rhythm {
  display: block !important;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 36vh;
  overflow: auto;
  margin: 0;
  padding-bottom: calc(16px + var(--safe-bottom));
  border-radius: 0;
  border-width: 1px 0 0;
}

body.stage.stage-map #view-play > .rhythm .rhythm-head p {
  display: none;
}

/* Two columns on stage: the second view goes on where the first ends,
   past a double bar line. */

body.stage.stage-split .work {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  /* One row, the height of the screen: each column scrolls inside it, so
     the second can start where the first ends. */
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
}

body.stage #editor-mirror {
  border-left: 5px double color-mix(in srgb, var(--barline) 45%, transparent);
}

body.stage.stage-split #editor .cm-content,
body.stage.stage-split #editor-mirror .cm-content {
  padding: 5vh 3vw 30vh;
}

/* Room below, so the second column can always start after the first. */
body.stage.stage-split #editor-mirror .cm-content {
  padding-bottom: 100vh;
}

/* Melody lists on the stage. */

.stage-lists {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 6px;
}

.stage-lists:empty {
  display: none;
}

.stage-list {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding-right: 8px;
  border-right: 1px solid var(--line);
}

.stage-list-label {
  margin-right: 4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
}

body.stage .stage-bar .stage-list-choice {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
}

body.stage .stage-bar .stage-list-choice.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* Narrower screens. */

@media (max-width: 1180px) {
  .brand .tagline {
    display: none;
  }
  .stat b {
    display: none;
  }
}

/* The transport keeps its icons, so the display keeps its room. */
@media (max-width: 1000px) {
  .transport .btn span {
    display: none;
  }
  .transport .btn {
    width: 48px;
    padding: 0;
  }
  .transport .btn-play {
    width: 60px;
  }
}

/* Beside the display, the tools keep only their icons too, where the row
   is short of room and not yet a row of its own. */
@media (min-width: 721px) and (max-width: 1360px) {
  .tools > .btn span {
    display: none;
  }
  .tools > .btn {
    width: 46px;
    padding: 0;
  }
  /* The examples go under the icons, as wide as they are together. */
  .toolbar {
    grid-template-areas:
      "transport status follow daw stage share"
      "scenes scenes examples examples examples examples";
  }
  .examples {
    min-width: 0;
  }
  .examples > span {
    display: none;
  }
  .examples select {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 900px) {
  /* minmax(0, ...) lets a column be narrower than its widest content. */
  .work {
    grid-template-columns: minmax(0, 1fr);
  }
  #editor {
    height: 64vh;
    min-height: 340px;
  }
  .side {
    max-height: 420px;
  }

  /* The book's contents fold into a bar under the header. */
  .book-view {
    grid-template-columns: minmax(0, 1fr);
  }
  .toc {
    z-index: 5;
    max-height: none;
    padding: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--paper) 96%, transparent);
    backdrop-filter: blur(8px);
    overflow: visible;
  }
  .toc h2 {
    display: none;
  }
  .toc-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px clamp(14px, 3vw, 30px);
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    text-align: left;
  }
  .toc-toggle:active {
    transform: none;
  }
  .toc-kind {
    flex: none;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }
  .toc-here {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .toc-toggle .i {
    color: var(--accent);
    transition: transform 220ms var(--ease);
  }
  .toc.open .toc-toggle .i {
    transform: rotate(180deg);
  }
  .toc ol,
  .toc .progress {
    display: none;
  }
  .toc.open .progress {
    display: block;
    margin: 0;
    padding: 0 clamp(14px, 3vw, 30px) 6px;
  }
  .toc.open ol {
    display: grid;
    max-height: 60vh;
    overflow: auto;
    padding: 0 clamp(8px, 2vw, 22px) 14px;
  }
  .page {
    padding: 28px clamp(16px, 4vw, 40px) 56px;
    font-size: 17px;
  }
  .page h1 {
    font-size: 38px;
  }
}

/* Phones: the tabs go to the foot of the screen, under the thumb. */

@media (max-width: 720px) {
  :root {
    --top-h: 54px;
  }
  body {
    padding-bottom: calc(64px + var(--safe-bottom));
  }
  .top {
    gap: 8px;
    padding: var(--safe-top) 12px 0;
  }
  .brand {
    gap: 8px;
  }
  .brand img {
    width: 34px;
    height: 34px;
  }
  .brand .name {
    font-size: 25px;
  }
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    padding: 4px max(4px, var(--safe-right)) calc(4px + var(--safe-bottom)) max(4px, var(--safe-left));
    background: color-mix(in srgb, var(--paper) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 20px -14px rgba(0, 0, 0, 0.35);
  }
  .tabs a {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    height: 56px;
    padding: 0 2px;
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tabs a::before {
    content: "";
    position: static;
    width: 24px;
    height: 24px;
    background: currentColor;
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
  }
  .tabs a::after {
    left: 50%;
    right: auto;
    top: 0;
    bottom: auto;
    width: 26px;
    height: 3px;
    margin-left: -13px;
    border-radius: 0 0 3px 3px;
  }
  .tabs a.here {
    color: var(--accent);
  }
  .tabs a[data-icon="play"] {
    --icon: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'><circle cx='12' cy='12' r='9'/><path d='M10 8.3v7.4l6-3.7z' fill='black'/></svg>");
  }
  .tabs a[data-icon="learn"] {
    --icon: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'><path d='M3 5.5c3-1 6-1 9 1 3-2 6-2 9-1v13c-3-1-6-1-9 1-3-2-6-2-9-1z'/><path d='M12 6.5v13'/></svg>");
  }
  .tabs a[data-icon="manual"] {
    --icon: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><rect x='5' y='3' width='14' height='18' rx='1.5'/><path d='M9 8h6M9 12h6M9 16h4'/></svg>");
  }
  .tabs a[data-icon="inside"] {
    --icon: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M9 4C7 4 6 5 6 7v2c0 1.5-1 3-2.5 3C5 12 6 13.5 6 15v2c0 2 1 3 3 3M15 4c2 0 3 1 3 3v2c0 1.5 1 3 2.5 3-1.5 0-2.5 1.5-2.5 3v2c0 2-1 3-3 3'/></svg>");
  }
  .prefs {
    gap: 6px;
  }
  .lang button,
  .lang a {
    padding: 5px 7px;
    font-size: 12px;
  }
  .theme-switch button {
    width: 28px;
    height: 28px;
  }

  /* Play: the transport and the display on one line, the tools on a line
     that scrolls sideways. */
  .play-view {
    padding: 10px 10px 8px;
    gap: 10px;
  }
  .toolbar {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "transport status"
      "tools tools";
    gap: 8px;
  }
  .transport {
    gap: 6px;
  }
  .transport .btn span {
    display: none;
  }
  .transport .btn {
    width: 44px;
    padding: 0;
  }
  .transport .btn-play {
    width: 54px;
  }
  .status {
    justify-content: space-between;
    gap: 10px;
    padding: 0 12px;
  }
  .stat b {
    display: none;
  }
  #bar {
    font-size: 26px;
  }
  .beat {
    gap: 4px;
  }
  .tools {
    grid-area: tools;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    margin: 0 -10px;
    padding: 2px 10px 4px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tools::-webkit-scrollbar {
    display: none;
  }
  .tools > * {
    flex: none;
  }
  .examples > span {
    display: none;
  }
  .examples select {
    max-width: 62vw;
  }
  #editor {
    height: 58vh;
    min-height: 300px;
  }
  .cm-editor {
    font-size: 14px;
  }
  .side {
    max-height: none;
  }
  .rhythm {
    padding: 12px 10px;
  }
  .rhythm-head p {
    min-width: 0;
    flex-basis: 100%;
    font-size: 13px;
  }
  .rhythm-grid .grid-row {
    grid-template-columns: 76px repeat(var(--bars), minmax(max(190px, var(--bar-min, 0px)), 1fr));
  }
  .hint {
    display: none;
  }

  /* The book. */
  .toc-toggle {
    padding: 11px 16px;
  }
  .page {
    padding: 22px 16px 44px;
    font-size: 17px;
    line-height: 1.65;
  }
  .page h1 {
    font-size: 32px;
    padding-bottom: 16px;
  }
  .page h2 {
    font-size: 25px;
    margin-top: 36px;
  }
  .page table {
    display: block;
    overflow-x: auto;
    font-size: 15px;
  }
  .page pre {
    font-size: 13.5px;
  }
  .page blockquote {
    padding: 12px 14px 12px 58px;
  }
  .page blockquote::before {
    left: 12px;
    width: 34px;
    height: 34px;
  }
  .page-nav {
    flex-direction: column;
  }
  .page-nav a {
    text-align: center;
  }
  .page-nav a.next {
    order: -1;
    margin-left: 0;
  }
  .aratu-block {
    margin-left: -6px;
    margin-right: -6px;
  }
  .block-buttons {
    margin-left: 0;
    width: 100%;
  }
  .block-buttons .btn {
    flex: 1 1 auto;
  }
  .block-editor .cm-editor {
    font-size: 15px;
  }
  .grid-row {
    grid-template-columns: 70px repeat(var(--bars), minmax(max(140px, var(--bar-min, 0px)), 1fr));
  }

  .bottom {
    padding: 12px 16px 16px;
  }
  .sound-status {
    bottom: calc(76px + var(--safe-bottom));
  }
}

/* The stage on a phone, upright or lying down: one column, a slimmer rail,
   the tools in a row that scrolls. */
@media (max-width: 720px), (max-height: 500px) {
  body.stage {
    --rail: 54px;
    padding-bottom: 0;
  }
  body.stage .sound-status {
    bottom: calc(12px + var(--safe-bottom));
  }
  body.stage .stage-bar {
    gap: 10px;
    padding: var(--safe-top) max(8px, var(--safe-right)) 0 max(12px, var(--safe-left));
  }
  .stage-hud {
    gap: 10px;
  }
  .stage-count {
    gap: 10px;
  }
  #stage-bar-n {
    font-size: 30px;
  }
  .stage-tempo {
    display: none;
  }
  .stage-count .beat i {
    width: 7px;
    height: 7px;
  }
  .stage-count .beat i:first-child {
    width: 10px;
    height: 10px;
  }
  body.stage .stage-bar .btn {
    height: 36px;
    padding: 0 9px;
  }
  body.stage .stage-bar .btn-play,
  body.stage .stage-bar #stage-stop {
    width: 38px;
    height: 38px;
  }
  body.stage .stage-bar .btn.scene {
    width: 28px;
    height: 32px;
  }
  #stage-split {
    display: none !important;
  }
  .stage-tools .btn span,
  .stage-exit span {
    display: none;
  }
  body.stage #editor .cm-content {
    padding: 3vh 4vw 30vh;
  }
  body.stage .stage-msg:not([hidden]) {
    left: max(8px, var(--safe-left));
    right: max(8px, var(--safe-right));
    bottom: calc(10px + var(--safe-bottom));
    max-width: none;
    font-size: 14px;
  }
}

/* A touch screen has no resting mouse: the controls stay. */
@media (pointer: coarse) {
  body.stage.idle .stage-controls,
  body.stage.idle .stage-bar .stage-exit {
    opacity: 1;
    pointer-events: auto;
  }
  body.stage.idle {
    cursor: auto;
  }
}
