:root {
  --bg: #fbfaf6;
  --ink: #1b2233;
  --muted: #4a5163;
  --line: #d9d6cc;
  --panel: #ffffff;
  --accent: #1d4e89;
  --accent-ink: #ffffff;
  --warn-bg: #fff4dc;
  --warn-ink: #6b4200;
  --miss: #8a8a8a;
  --r: 10px;
  --r-small: 6px;
  --head: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d;
    --ink: #ecebe6;
    --muted: #b9bccb;
    --line: #353a48;
    --panel: #1d2029;
    --accent: #8db8f0;
    --accent-ink: #0e1420;
    --warn-bg: #3a2c10;
    --warn-ink: #ffdf9e;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 var(--body); }
a { color: var(--accent); }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--panel); color: var(--ink); padding: 8px 12px; z-index: 30; }
.skip:focus { left: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* header: the eight bell colors as a strip */
.top { border-bottom: 1px solid var(--line); padding: 18px 0 14px; position: relative; }
.top::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 6px;
  background: linear-gradient(90deg, #e0262b 0 12.5%, #f28a1a 0 25%, #f5cf1d 0 37.5%, #3aa845 0 50%, #5bb8e8 0 62.5%, #1f4fb5 0 75%, #7a3fb0 0 87.5%, #e0262b 0); }
.brand { margin: 0 0 2px; font: 700 16px/1.3 var(--head); color: var(--muted); }
h1 { font: 800 clamp(26px, 4.4vw, 38px)/1.15 var(--head); margin: 0 0 6px; letter-spacing: -0.01em; }
.lede { margin: 0; max-width: 62ch; color: var(--muted); }
h2 { font: 800 24px/1.25 var(--head); margin: 32px 0 10px; }
h3 { font: 700 19px/1.3 var(--head); margin: 22px 0 6px; }

.store-note { margin: 14px 0 0; padding: 10px 12px; background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--r-small); overflow-wrap: anywhere; }

/* tool layout */
.tool { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; margin-top: 18px; }
@media (min-width: 960px) {
  .tool { grid-template-columns: 340px minmax(0, 1fr); grid-template-rows: auto 1fr; grid-template-areas: "a out" "b out"; align-items: start; }
  #controls { grid-area: a; }
  .out { grid-area: out; }
  .controls-b { grid-area: b; }
}
.controls { display: grid; gap: 14px; align-content: start; }
.field { display: grid; gap: 4px; }
label, legend { font-weight: 650; }
select, input[type=text], input[type=number], textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--panel); border: 1.5px solid var(--line);
  border-radius: var(--r-small); padding: 10px 10px; min-height: 44px; width: 100%; }
textarea { line-height: 1.45; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
#m-words, #names { font-family: var(--body); }
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
.help { margin: 2px 0 0; color: var(--muted); font-size: 16px; }
.errors { margin: 4px 0 0; padding-left: 20px; color: #a1261d; }
@media (prefers-color-scheme: dark) { .errors { color: #ff9c92; } }
.errors:empty { display: none; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.custom { display: grid; gap: 8px; }
.range-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; }
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.nb { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 8px; border: 1.5px solid var(--line); border-radius: var(--r-small); font-weight: 500; }
.nb.sharp { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.nb input, .check input, .radio input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.mine { display: grid; gap: 12px; padding: 14px; border: 1.5px solid var(--line); border-radius: var(--r); background: var(--panel); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.more { border-top: 1px solid var(--line); padding-top: 10px; }
.more > summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.more[open] { display: grid; gap: 14px; }
.opts { display: grid; gap: 2px; }
.check, .radio { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; }
.colors { display: grid; gap: 8px; }
.color-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.col { display: flex; align-items: center; gap: 8px; font-weight: 500; min-height: 44px; }
.col input { width: 44px; height: 36px; padding: 0; border: 1.5px solid var(--line); border-radius: var(--r-small); background: none; flex: none; }
.bin { border-top: 1px solid var(--line); padding-top: 6px; }
.bin-h { font-size: 18px; margin: 8px 0; }
.bin ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.bin li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bin li > span { flex: 1 1 140px; overflow-wrap: anywhere; }

.btn { font: inherit; font-size: 16px; font-weight: 650; min-height: 44px; padding: 8px 16px; border-radius: var(--r-small);
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink); cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.quiet { border-color: var(--line); }
.btn:hover { border-color: var(--accent); }

/* output */
.out { min-width: 0; }
.fit { margin: 0 0 10px; }
.fit p { margin: 0; padding: 10px 12px; border-radius: var(--r-small); background: var(--panel); border: 1px solid var(--line); }
.fit.warn p { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.view-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.tabs { display: flex; border: 1.5px solid var(--ink); border-radius: var(--r-small); overflow: hidden; }
.tabs button { font: inherit; font-size: 16px; font-weight: 650; min-height: 44px; padding: 6px 14px; border: 0; background: transparent; color: var(--ink); cursor: pointer; white-space: nowrap; }
.tabs button + button { border-left: 1.5px solid var(--ink); }
.tabs button[aria-selected=true] { background: var(--ink); color: var(--bg); }
.acts { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 420px) { .tabs { width: 100%; } .tabs button { flex: 1; padding: 6px 6px; } }

/* the sheet is paper in both color modes */
.sheet-host { min-width: 0; }
.sheet { background: #fff; color: #111; border: 1px solid #ddd; border-radius: var(--r); padding: 18px 16px 20px;
  -webkit-print-color-adjust: exact; print-color-adjust: exact; --d: 40px; --u: 50px; --ly: 16px; }
.sheet.empty p { margin: 0; color: #333; }
.sheet-head { margin-bottom: 12px; }
.sheet-title { font: 800 26px/1.2 var(--head); margin: 0; }
.sheet-sub { font-weight: 600; font-size: 18px; color: #444; }
.sheet-meta, .sheet-by, .card-meta { margin: 2px 0 0; color: #3d3d3d; font-size: 16px; }
.sheet-foot { margin: 14px 0 0; color: #3d3d3d; font-size: 16px; }
.sheet-foot.wall-note { margin: 4px 0 12px; }
.sheet-by { margin: 0; }
.sheet-head + .sheet-by { margin-top: -10px; margin-bottom: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0 0 16px; padding-bottom: 12px; border-bottom: 1px solid #e3e3e3; --d: 30px; }
.leg { display: inline-flex; align-items: center; gap: 6px; }
.leg-t { font-size: 16px; }
.legend.big { --d: 44px; border: 0; }

.music { display: grid; gap: 14px; }
.line { display: flex; flex-wrap: wrap; row-gap: 12px; }
.bar { display: inline-flex; flex-wrap: wrap; align-items: flex-start; padding: 12px 8px 0; border-left: 2px solid #cfcfcf; max-width: 100%; }
.line > .bar:first-child { border-left-color: transparent; padding-left: 0; }
.tail { display: flex; flex-wrap: wrap; row-gap: inherit; max-width: 100%; }
.ev { position: relative; display: inline-flex; flex-direction: column; align-items: flex-start;
  min-width: max(calc(var(--d) + 6px), calc(var(--b) * var(--u))); }
.dot { position: relative; width: var(--d); height: var(--d); border-radius: 50%; border: calc(var(--d) * .2) solid #999;
  background: #fff; display: grid; place-items: center; flex: none; }
.dot.pale { box-shadow: 0 0 0 1.5px #6d6d6d, inset 0 0 0 1.5px #6d6d6d; }
.dot.missing { border: max(2px, calc(var(--d) * .09)) dashed var(--miss); }
.dot.missing .lt { color: #555; }
.lt { font: 800 calc(var(--d) * .42)/1 var(--head); color: #111; }
.dot.long .lt { font-size: calc(var(--d) * .32); letter-spacing: -0.02em; }
.oct { position: absolute; top: calc(var(--d) * -0.48); left: 0; right: 0; text-align: center; font-size: calc(var(--d) * .3); line-height: 1; color: #111; letter-spacing: 1px; }
.hold { position: absolute; left: calc(var(--d) + 2px); right: 6px; top: calc(var(--d) / 2 - 3px); border-top: 6px solid #999; border-radius: 3px; }
.ly { font-size: var(--ly); line-height: 1.2; margin-top: 5px; min-height: 1.2em; white-space: nowrap; padding-right: 4px; color: #111; }
.ly.ext::before { content: ""; display: block; width: calc(100% - 8px); margin-top: 0.9em; border-bottom: 1.5px solid #555; }
.ly.ext { align-self: stretch; }
.rest-mark { display: flex; align-items: center; height: var(--d); padding: 0 2px; font: italic 600 max(14px, calc(var(--d) * .36))/1 var(--body); color: #555; }
.mv { position: absolute; top: calc(var(--d) * -0.3); right: calc(var(--d) * -0.3); width: calc(var(--d) * .5); height: calc(var(--d) * .5);
  border-radius: 50%; background: #fff; border: 1px solid #222; display: grid; place-items: center;
  font: 800 calc(var(--d) * .36)/1 var(--body); color: #111; }
.cards-bar { margin: 0 0 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.ev.other .pip { display: block; width: 10px; height: 10px; border: 2px solid #b5b5b5; border-radius: 50%; margin: calc((var(--d) - 10px) / 2) 0 calc((var(--d) - 10px) / 2) calc((var(--d) - 10px) / 2); }
.sheet.wall { --d: 64px; --u: 76px; --ly: 22px; }
.sheet.wall .sheet-title { font-size: 36px; }
.cards { display: grid; gap: 16px; }
.sheet.card { --d: 30px; --u: 36px; --ly: 16px; border: 2px dashed #9a9a9a; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-bottom: 10px; }
.card-who { font: 800 24px/1.2 var(--head); margin: 0; }
.card-name { font-size: 16px; display: inline-flex; align-items: baseline; gap: 6px; }
.blank { display: inline-block; width: 160px; border-bottom: 1.5px solid #555; }
.card-meta { flex-basis: 100%; }
@media screen and (max-width: 600px) {
  .top { padding: 14px 0 10px; }
  .lede { font-size: 16px; }
  .tool { margin-top: 12px; gap: 14px; }
  .controls { gap: 10px; }
  .view-bar { gap: 8px; }
  .fit p { padding: 8px 10px; }
  h1 { font-size: 25px; }
  .acts .btn { padding: 8px 12px; }
  .sheet { padding: 14px 10px 16px; --d: 38px; --u: 44px; }
  .legend { --d: 38px; }
  .lt { font-size: max(16px, calc(var(--d) * .42)); }
  .dot.long .lt { font-size: 16px; letter-spacing: -0.05em; }
  /* on a phone the music comes straight after the title; the color key follows it */
  .sheet.score { display: flex; flex-direction: column; }
  .sheet.score .legend { order: 1; margin: 18px 0 0; padding: 12px 0 0; border-bottom: 0; border-top: 1px solid #e3e3e3; }
  .sheet.score .sheet-foot, .sheet.score .sheet-by { order: 2; }
  .sheet.wall { --d: 48px; --u: 56px; --ly: 18px; }
  .sheet.card { --d: 38px; --u: 42px; }
}

/* explain */
.explain { max-width: 72ch; margin-top: 28px; }
.explain p { margin: 0 0 12px; }
.sources { margin: 24px 0; border-top: 1px solid var(--line); padding-top: 8px; }
.sources summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.sources li { margin-bottom: 6px; }

/* footer */
.foot { margin-top: 36px; border-top: 1px solid var(--line); padding: 20px 0 28px; color: var(--muted); font-size: 16px; }
.sb-footer p { margin: 0 0 8px; }
.sb-more a { color: var(--muted); }
.sb-credit a { color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: var(--r-small); display: flex; align-items: center;
  gap: 12px; z-index: 20; box-shadow: 0 4px 18px rgba(0, 0, 0, .25); pointer-events: none; }
.toast .btn { background: var(--bg); color: var(--ink); border-color: var(--bg); pointer-events: auto; }
.toast[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* print: only the sheet on screen, at paper sizes */
@page { margin: 15mm 12mm 12mm; }
@page wall { size: landscape; margin: 14mm 10mm 10mm; }
@media print {
  body { background: #fff; color: #000; font-size: 11pt; }
  .top, .controls, .cards-bar, .fit, .view-bar, .explain, .foot, .toast, .skip, .store-note, #out-h { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  main.wrap, .tool { margin: 0; display: block; }
  .sheet { border: 0; border-radius: 0; padding: 0; --d: 9.5mm; --u: 9.6mm; --ly: 10.5pt; }
  .sheet.score .music { gap: 2.5mm; }
  .sheet.score .line { row-gap: 1.5mm; }
  .sheet.score .bar { padding: 2.5mm 1.2mm 0; }
  /* long notes get a short hold line on paper, so a line of four bars fits one row */
  .sheet.score .ev { min-width: max(calc(var(--d) + 0.6mm), min(calc(var(--b) * var(--u)), calc(var(--u) * 1.7))); }
  .sheet.score .ly { margin-top: 1mm; }
  .sheet-title { font-size: 20pt; }
  .sheet-sub { font-size: 13pt; }
  .sheet-meta, .sheet-by, .sheet-foot, .card-meta, .leg-t, .card-name { font-size: 11pt; }
  .legend { --d: 7mm; gap: 1.5mm 5mm; margin-bottom: 3mm; padding-bottom: 2.5mm; }
  .sheet-head { margin-bottom: 2mm; }
  /* a line of music that wraps may break between its rows, so pages fill; a bar is never split */
  .bar { break-inside: avoid; }
  .sheet.wall { page: wall; --d: 22mm; --u: 26mm; --ly: 20pt; }
  .sheet.wall .sheet-title { font-size: 28pt; }
  .sheet.wall .music { gap: 3mm; }
  .sheet.wall .bar { padding-top: 1.5mm; }
  .sheet.wall .line { row-gap: 2mm; }
  .tail { break-inside: avoid; }
  .sheet.wall .ly { margin-top: 1mm; }
  .cards { display: block; }
  .sheet.card { --d: 8.4mm; --u: 9.5mm; --ly: 10pt; border: 1.5px dashed #888; border-radius: 0; padding: 4mm 5mm; margin: 0 0 4mm; break-inside: avoid; }
  .sheet.card .legend.big { --d: 12mm; margin-bottom: 2mm; padding-bottom: 0; }
  .card-who { font-size: 16pt; }
  .sheet.card .lt { font-size: max(10pt, calc(var(--d) * .42)); }
  .sheet.card .dot.long .lt { font-size: 10pt; letter-spacing: -0.04em; }
  .sheet.card .dot { border-width: calc(var(--d) * .17); }
  .sheet.card .bar { padding-top: 1mm; }
  .sheet.card .line { row-gap: 0.5mm; }
  .sheet.card .ly { margin-top: 0.6mm; padding-right: 1.6mm; }
  .sheet.card .card-head { margin-bottom: 1mm; }
  .sheet.card .music { gap: 2mm; }
  .ev.other .pip { width: 2.4mm; height: 2.4mm; border-width: 0.5mm; margin: calc((var(--d) - 2.4mm) / 2) 0 calc((var(--d) - 2.4mm) / 2) calc((var(--d) - 2.4mm) / 2); }
  a { color: #000; text-decoration: none; }
}
