/* Aratu: music paper. 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;
  --staff: rgba(120, 100, 70, 0.11);
  --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 2px rgba(60, 40, 20, 0.08), 0 4px 14px rgba(60, 40, 20, 0.06);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15100d;
  --paper: #1d1612;
  --panel: #221a15;
  --line: #3a2d24;
  --staff: rgba(255, 220, 180, 0.05);
  --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 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: var(--accent);
}

[hidden] {
  display: none !important;
}

.serif,
h1,
h2,
h3,
.brand .name {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

/* The header. */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 28px;
  padding: 10px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand img {
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand .name {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
}

.brand .tagline {
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tabs a {
  padding: 8px 18px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--soft);
  font-weight: 600;
  font-size: 16px;
}

.tabs a:hover {
  background: var(--panel);
}

.tabs a.here {
  background: var(--accent);
  color: var(--accent-ink);
}

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

button,
select {
  font: inherit;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}

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

.lang button {
  border-radius: 0;
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 600;
}

.lang button:first-child {
  border-radius: 8px 0 0 8px;
}

.lang button:last-child {
  border-radius: 0 8px 8px 0;
}

.lang button + button {
  border-left: 0;
}

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

.theme-switch button {
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.btn.big {
  font-size: 17px;
  padding: 9px 18px;
}

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

.btn-play.on {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.btn-check {
  background: var(--mangue);
  border-color: var(--mangue);
  color: #fff;
}

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

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

/* Views. */

.view {
  flex: 1;
  min-height: 0;
}

/* Play. */

.play-view {
  display: flex;
  flex-direction: column;
  padding: 14px 20px 8px;
  gap: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.examples {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 15px;
}

.status {
  display: flex;
  gap: 18px;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.status b {
  font-weight: 600;
  color: var(--text);
}

.beat {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--line);
  align-self: center;
  transition: background 60ms;
}

.beat.on {
  background: var(--accent);
}

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

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

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

.side {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  overflow: auto;
  box-shadow: var(--shadow);
}

.side h2,
.toc h2 {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
}

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

.messages li {
  padding: 9px 12px;
  border-left: 4px solid var(--warning);
  background: var(--panel);
  border-radius: 6px;
  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;
  color: var(--muted);
  font-size: 12px;
}

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

/* The rhythm map under the editor. */

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

.rhythm-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  margin-bottom: 8px;
}

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

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

.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;
}

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

/* The code editor, everywhere. */

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

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

.cm-scroller {
  font-family: "JetBrains Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  line-height: 1.7;
}

.cm-gutters {
  background: var(--panel) !important;
  color: var(--muted) !important;
  border-right: 1px solid var(--line) !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;
}

/* The book. */

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

.toc {
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 66px;
  align-self: start;
  max-height: calc(100vh - 66px);
  overflow: auto;
}

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

.toc li a {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--soft);
  font-size: 15px;
  line-height: 1.3;
}

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

.toc li a.here {
  background: var(--paper);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}

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

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

.page {
  padding: 28px clamp(18px, 5vw, 64px) 60px;
  max-width: 900px;
  width: 100%;
  font-size: 18px;
  line-height: 1.65;
}

.page h1 {
  font-size: 38px;
  line-height: 1.15;
  margin: 0 0 6px;
  padding-bottom: 22px;
  /* A staff under the title. */
  background: repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 5px,
      var(--staff) 5px,
      var(--staff) 6px
    )
    bottom / 100% 31px no-repeat;
}

.page h2 {
  font-size: 26px;
  margin: 36px 0 8px;
  color: var(--name);
}

.page h3 {
  font-size: 21px;
  margin: 26px 0 6px;
}

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

.page code {
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 0.88em;
  background: var(--panel);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--name);
}

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

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

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

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

.page th {
  color: var(--muted);
  font-weight: 600;
}

.page blockquote {
  margin: 18px 0;
  padding: 12px 18px 12px 64px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  position: relative;
  box-shadow: var(--shadow);
}

/* The crab gives tips. */
.page blockquote::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 12px;
  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: 48px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.page-nav a {
  text-decoration: none;
  font-weight: 600;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}

.page-nav a.next {
  margin-left: auto;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.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,
.lang a {
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  text-decoration: none;
}

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

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

.lang a {
  display: inline-block;
  border-radius: 0;
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 600;
}

.lang a:first-child {
  border-radius: 8px 0 0 8px;
}

.lang a:last-child {
  border-radius: 0 8px 8px 0;
}

.lang a + a {
  border-left: 0;
}

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

.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: 20px 0 26px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

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

.block-label {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
  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 {
  font-size: 14px;
  padding: 6px 12px;
}

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

.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;
}

.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: "JetBrains Mono", Consolas, monospace;
  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.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;
}

.grid {
  padding-top: 16px;
}

.quantum {
  display: flex;
  align-items: center;
  gap: 0;
}

.quantum-label {
  color: var(--muted);
  font-size: 13px;
  margin-right: 8px;
}

.quantum button {
  font-size: 13px;
  padding: 4px 9px;
}

.quantum button:nth-child(2) {
  border-radius: 8px 0 0 8px;
}


.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: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  white-space: nowrap;
}

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

/* 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 {
  transition: transform 80ms ease-out, background 80ms;
}

.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: 10px 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  background: var(--paper);
}

/* The side panel's tabs and the Sounds panel. */

.side-tabs {
  display: flex;
  gap: 4px;
  margin: -4px 0 12px;
  border-bottom: 1px solid var(--line);
}

.side-tabs button {
  padding: 6px 12px 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

.sound-search {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  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: 14px 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

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

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

.sound-code {
  flex: none;
  padding: 2px 6px;
  border: 0;
  border-radius: 5px;
  background: var(--code-bg);
  color: var(--text);
  font-family: "JetBrains Mono", Consolas, monospace;
  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);
}

/* Two columns on stage: the second view goes on where the first ends. */

body.stage.stage-split .work {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0;
}

body.stage #editor-mirror {
  height: 100%;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
}

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

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

body.stage.stage-split #editor .cm-content,
body.stage.stage-split #editor-mirror .cm-content {
  padding: 8vh 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;
}

body.stage.stage-split.downbeat #editor-mirror {
  box-shadow:
    inset 0 0 0 4px var(--accent),
    inset 0 0 60px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* Melody lists on the stage. */

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

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

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

.stage-list-label {
  margin-right: 4px;
  color: var(--muted);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
}

.stage-list-choice {
  min-width: 30px;
  padding: 4px 8px;
}

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

/* The twelve-tone matrix. */

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

.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: "JetBrains Mono", Consolas, monospace;
  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 stage: only the code, full screen, for playing live. */

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

body.stage {
  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);
}

body.stage .work {
  display: block;
  height: 100vh;
  min-height: 0;
}

body.stage #editor {
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transition: box-shadow 120ms ease-out;
}

body.stage.downbeat #editor {
  box-shadow:
    inset 0 0 0 4px var(--accent),
    inset 0 0 60px color-mix(in srgb, var(--accent) 25%, transparent);
}

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

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

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

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-map .work {
  height: 64vh;
}

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

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

body.stage .stage-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 30;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  backdrop-filter: blur(8px);
  transition: opacity 400ms;
}

.stage-count {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 56px;
  padding: 0 6px;
  color: var(--text);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

body.stage.idle {
  cursor: none;
}

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

body.stage .stage-msg:not([hidden]) {
  display: block;
  /* Top right, under the controls: code lines seldom reach there, and the
     line being written is never covered. */
  position: fixed;
  top: 76px;
  right: 16px;
  z-index: 30;
  max-width: min(38vw, 560px);
  margin: 0;
  padding: 10px 16px;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  color: var(--text);
  font-size: calc(var(--stage-font, 30px) * 0.5);
  line-height: 1.4;
}


@media (max-width: 900px) {
  /* minmax(0, ...) lets a column be narrower than its widest content, so
     the lesson list scrolls on its own instead of widening the page. */
  .work {
    grid-template-columns: minmax(0, 1fr);
  }
  .book-view {
    grid-template-columns: minmax(0, 1fr);
  }
  .toc {
    min-width: 0;
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .toc ol {
    grid-auto-flow: column;
    overflow-x: auto;
  }
  .page {
    font-size: 17px;
  }
  /* On a phone the tabs go on two lines rather than past the screen. */
  .tabs {
    flex-wrap: wrap;
  }
  .tabs a {
    padding: 8px 12px;
    white-space: nowrap;
  }
  .prefs {
    margin-left: 0;
  }
  .status {
    margin-left: 0;
  }
}

/* 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;
}

/* 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: 8px 12px;
  border-radius: 8px;
  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);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 2px;
}
