:root {
  color-scheme: dark;
  --bg: #10131a;
  --panel: #191f2b;
  --ink: #edf2ff;
  --muted: #a9b4ca;
  --line: #30394d;
  --accent: #b8e07a;
  --accent2: #79c6e0;
  --warn: #ffd27a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #243044 0, var(--bg) 42rem);
  color: var(--ink);
}
main { max-width: 1120px; margin: 0 auto; padding: 2rem 1rem; }
.hero { padding: 2rem 0 1rem; }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .12em; font-size: .8rem; }
h1 { font-size: clamp(2.2rem, 6vw, 4.8rem); line-height: .95; margin: .2rem 0 1rem; }
h2 { margin-top: 0; }
p { color: var(--muted); max-width: 74ch; }
a { color: var(--accent2); }
.panel {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  padding: 1.25rem;
  margin: 1rem 0;
  box-shadow: 0 16px 50px rgba(0,0,0,.25);
}
.controls {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}
.controls h2 { margin-bottom: .2rem; }

/* Settings: predictable auto-fit cells that never collide. */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem 1.25rem;
  align-items: start;
}
.field { display: flex; flex-direction: column; gap: .4rem; color: var(--muted); font-weight: 700; }
label { color: var(--muted); font-weight: 700; }
.field-grid label { display: flex; flex-direction: column; gap: .4rem; }
select, input, button {
  font: inherit;
  border-radius: .7rem;
  border: 1px solid var(--line);
  background: #0f1420;
  color: var(--ink);
  padding: .6rem .7rem;
}
select, .field-grid input[type=number] { height: 2.7rem; }
select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 1px;
}

/* Seed: number + roll on one baseline, random toggle beneath. */
.field--seed .seed-row { display: flex; gap: .4rem; align-items: stretch; }
.field--seed .seed-row input { flex: 1 1 auto; min-width: 0; }
.dice {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 2.7rem; height: 2.7rem; font-size: 1.05rem; line-height: 1; padding: 0;
  cursor: pointer; background: #1a2333; border: 1px solid var(--line);
  border-radius: .7rem; color: var(--accent2);
}
.dice:hover { background: #243049; color: var(--ink); }
.checkline { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; font-size: .8rem; color: var(--muted); margin-top: .1rem; }
.checkline span { line-height: 1.1; }
.checkline input, .toggle-chip input, .mute-box input { accent-color: var(--accent2); width: 1rem; height: 1rem; }

/* Length with unit suffix inside the same control footprint. */
.with-suffix { display: flex; align-items: center; gap: .5rem; }
.with-suffix input { flex: 1 1 auto; min-width: 0; }
.with-suffix .suffix { color: var(--muted); font-weight: 600; font-size: .85rem; }

/* Tempo: readout pinned to the label, slider full-width below. */
.field--tempo label { flex-direction: row; align-items: baseline; justify-content: space-between; gap: .5rem; }
.tempo-readout { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.field--tempo input[type=range] { width: 100%; height: 2.7rem; padding: 0; accent-color: var(--accent); background: transparent; border: 0; }

/* Secondary option row: voicing + dynamics + mute, aligned. */
.option-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem 1.25rem; }
.field--voicing { min-width: 200px; }
.toggle-chip {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .6rem .85rem; height: 2.7rem;
  border: 1px solid var(--line); border-radius: .7rem; background: #0f1420;
  color: var(--ink); font-weight: 700; cursor: pointer; white-space: nowrap;
}
.toggle-chip:has(input:checked) { border-color: var(--accent2); background: color-mix(in srgb, var(--accent2) 14%, #0f1420); }
.mute-box {
  border: 1px solid var(--line); border-radius: .7rem; padding: .35rem .75rem .5rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; color: var(--muted);
}
.mute-box legend { color: var(--ink); font-weight: 800; padding: 0 .25rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.mute-box label { display: inline-flex; align-items: center; gap: .3rem; font-weight: 700; }

/* Action bar: tiered hierarchy. */
.action-bar {
  display: flex; flex-wrap: wrap; gap: .9rem 1.25rem; align-items: center;
  padding-top: 1.05rem; border-top: 1px solid var(--line);
}
.action-group { display: flex; flex-wrap: wrap; gap: .55rem; align-items: center; }
.action-group--export { margin-left: auto; }
.btn {
  cursor: pointer; font-weight: 800; border: 1px solid var(--line);
  background: #23304a; color: var(--ink); padding: .65rem 1rem; border-radius: .7rem;
  transition: background .12s ease, border-color .12s ease, transform .04s ease;
}
.btn:hover { background: #2f436a; }
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, #fff) 0, var(--accent) 100%);
  color: #16210a; border-color: color-mix(in srgb, var(--accent) 70%, #000);
  box-shadow: 0 6px 18px rgba(184,224,122,.18);
}
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 85%, #fff); }
.btn--play { background: color-mix(in srgb, var(--accent2) 22%, #23304a); border-color: color-mix(in srgb, var(--accent2) 45%, var(--line)); }
.btn--play:hover { background: color-mix(in srgb, var(--accent2) 32%, #2f436a); }
.btn--ghost { background: transparent; color: var(--muted); }
.btn--ghost:hover { background: #1a2333; color: var(--ink); }
.grid-wrap { overflow-x: auto; border-radius: .8rem; border: 1px solid var(--line); background: #0c1018; }
canvas { display: block; min-width: 760px; width: 100%; height: auto; }
.hint { color: var(--warn); }
#summary { color: var(--accent); margin: .4rem 0 1rem; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.5rem; }
.note-list, #corpusList { padding-left: 1.2rem; }
.note-list li, #corpusList li { margin: .3rem 0; color: var(--muted); }
.fold { border: 1px solid var(--line); border-radius: .8rem; background: #0e1320; padding: 0 1rem; align-self: start; }
.fold[open] { padding-bottom: .8rem; }
.fold > summary { cursor: pointer; list-style: none; display: flex; align-items: baseline; justify-content: space-between; gap: .8rem; padding: .85rem .2rem; color: var(--ink); font-weight: 700; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: "\25B8"; color: var(--accent); font-size: .8rem; margin-right: .15rem; transition: transform .15s ease; display: inline-block; }
.fold[open] > summary::before { transform: rotate(90deg); }
.fold > summary:hover { color: #fff; }
.fold > summary:focus-visible { outline: 2px solid var(--accent2); outline-offset: 3px; border-radius: .4rem; }
.fold .fold-title { flex: 1; }
.fold .fold-meta { color: var(--muted); font-weight: 500; font-size: .82rem; font-variant-numeric: tabular-nums; }
.fold > summary + *, .fold > * { margin-top: .2rem; }
.no-script-note { border: 2px solid var(--warn); border-radius: 1rem; padding: 1rem; background: #302415; }
.rhythm-box label { text-transform: none; }
.inst-box { display: flex; flex-wrap: wrap; gap: .5rem .9rem; align-items: center; }
.inst-box label { text-transform: none; display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; }
.inst-box select { font-size: .82rem; padding: .15rem .3rem; }
select:disabled, input:disabled { opacity: .5; cursor: not-allowed; }
.toggle-chip input:disabled + span { opacity: .5; }
footer { border-top: 1px solid var(--line); padding: 1.5rem; text-align: center; }
footer p { margin: 0 auto; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
.notation-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.view-pick { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .9rem; }
.view-pick select { font: inherit; }
.sub { margin: .6rem 0 .2rem; font-size: .95rem; color: var(--ink); }
.sheet-block, .roll-block { margin-top: .6rem; }
.sheet-wrap { overflow-x: auto; border-radius: .8rem; border: 1px solid var(--line); background: #0c1018; padding: .4rem; }
.sheet-wrap svg { display: block; min-width: 760px; height: auto; }

#printArea { display: none; }
@page { size: letter portrait; margin: 14mm; }
@media print {
  html, body { background: #fff; color: #111; }
  body > * { display: none !important; }
  main { display: block !important; max-width: none; padding: 0; margin: 0; }
  main > * { display: none !important; }
  #printArea { display: block !important; }
  #printArea svg.print-score { width: 100%; height: auto; display: block; }
}
