:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --line: #dcd8cd;
  --text: #1f2328;
  --muted: #646b73;
  --accent: #1d4e89;
  --accent-soft: #e3ecf7;
  --es: #b4530a;
  --es-soft: #fbebd9;
  --mx: #0f7a66;
  --mx-soft: #d9f2ec;
  --cons: #3d4852;
  --cons-soft: #e6e9ec;
  --var: #b0256b;
  --var-soft: #fbe1ee;
  --gap: #ebe8e0;
  --ok: #1a7f37;
  --warn: #9a6700;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1e2126;
    --surface-2: #272b31;
    --line: #363b43;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --accent: #7fb2ee;
    --accent-soft: #1f3048;
    --es: #f0a35e;
    --es-soft: #3d2a17;
    --mx: #5fd0b8;
    --mx-soft: #15342e;
    --cons: #c3cad1;
    --cons-soft: #2f353c;
    --var: #f07fb4;
    --var-soft: #45182e;
    --gap: #24272c;
    --ok: #56d364;
    --warn: #e3b341;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
}
/* Everything one fifth larger on a desktop screen: text, staves, graphs and
   diagrams together, so their proportions stay as designed. Below 1200px the
   page keeps its base size, which leaves the 980px layout break untouched. */
@media (min-width: 1200px) { body { zoom: 1.2; } }
@media (min-width: 1500px) { body { zoom: 1.4; } }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; line-height: 1.25; margin: 0 0 .3rem; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 0 0 .4rem; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.site-header .inner {
  max-width: 1280px; margin: 0 auto; padding: .55rem 16px;
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.3rem; color: var(--text); letter-spacing: .01em; }
.brand span { color: var(--var); }
.site-header nav { display: flex; gap: .2rem; flex-wrap: wrap; }
.site-header nav a {
  padding: .3rem .65rem; border-radius: 6px; color: var(--muted); font-weight: 500;
}
.site-header nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.site-header nav a.active { background: var(--accent-soft); color: var(--accent); }
.site-header .clustering { margin-left: auto; color: var(--muted); display: flex; align-items: center; gap: .4rem; }
.site-header .clustering select { font: inherit; padding: .2rem .4rem; }
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 64px; }
.page-head { margin-bottom: 1rem; }
.page-head .crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 16px;
}
.card > h2:first-child { margin-top: 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.top { align-items: flex-start; }
.spacer { flex: 1; }
.grid { display: grid; gap: 12px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 980px) { .split { grid-template-columns: minmax(0, 1fr); } }

/* ---------- small components ---------- */
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }

.badge {
  display: inline-block; padding: 0 .45em; border-radius: 4px; font-size: .75rem; font-weight: 600;
  line-height: 1.6; vertical-align: middle; background: var(--surface-2); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.badge.es { background: var(--es-soft); color: var(--es); }
.badge.mx { background: var(--mx-soft); color: var(--mx); }
.badge.var { background: var(--var-soft); color: var(--var); }
.badge.cons { background: var(--cons-soft); color: var(--cons); }

button, .btn, select, input[type=text], input[type=search], input[type=number], textarea {
  font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: .35rem .65rem;
}
button, .btn { cursor: pointer; font-weight: 500; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { button.primary { color: #0d1117; } }
button.icon { padding: .2rem .5rem; min-width: 2rem; }
button.playing { background: var(--var-soft); border-color: var(--var); color: var(--var); }
textarea { width: 100%; min-height: 5rem; resize: vertical; }
input[type=text], input[type=search] { min-width: 12rem; }
label { font-size: .85rem; color: var(--muted); }
label.field { display: flex; flex-direction: column; gap: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); background: transparent; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed=true] { background: var(--accent-soft); color: var(--accent); }

.toolbar { display: flex; gap: 10px 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.notice {
  border-left: 3px solid var(--accent); background: var(--accent-soft); padding: .5rem .75rem;
  border-radius: 0 6px 6px 0; margin-bottom: 12px; font-size: .9rem;
}
.notice.error { border-color: var(--var); background: var(--var-soft); }
.empty { color: var(--muted); padding: 2rem 0; text-align: center; }
.loading { color: var(--muted); padding: 1.5rem 0; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; }
table.data th { vertical-align: bottom; line-height: 1.3; }
table.data td .simbar { width: 48px; }
.nowrap, table.data td a.btn { white-space: nowrap; }
table.data tr.clickable { cursor: pointer; }
.simbar { display: inline-block; width: 64px; height: 6px; border-radius: 3px; background: var(--gap); vertical-align: middle; margin-right: 6px; overflow: hidden; }
.simbar i { display: block; height: 100%; background: var(--accent); }

/* ---------- cluster cards ---------- */
.cluster-card { display: block; color: inherit; padding: 12px 14px; }
.cluster-card:hover { text-decoration: none; border-color: var(--accent); }
.cluster-card .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cluster-card .id { font-weight: 700; }
.cluster-card svg { display: block; width: 100%; height: 56px; margin: 6px 0; }
.cluster-card .meta { font-size: .82rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.share { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--gap); margin-top: 8px; }
.share .es { background: var(--es); }
.share .mx { background: var(--mx); }

/* ---------- variation graph ---------- */
.graph-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.graph-scroll svg { display: block; }
.vg-edge { fill: none; stroke: var(--cons); stroke-opacity: .55; }
.vg-edge.variation { stroke: var(--var); }
.vg-node rect, .vg-node circle { fill: var(--cons-soft); stroke: var(--cons); stroke-width: 1.5; }
.vg-node.variation rect { fill: var(--var-soft); stroke: var(--var); }
.vg-node.start rect { fill: var(--surface); stroke-dasharray: 3 2; }
.vg-node text { font: 600 12px var(--sans); fill: var(--text); text-anchor: middle; pointer-events: none; }
.vg-node text.sub { font: 500 10.5px var(--sans); fill: var(--muted); }
.vg-node text.count { font: 500 10px var(--sans); fill: var(--muted); }
.vg-node { cursor: pointer; }
.vg.has-selection .vg-node:not(.on-path) { opacity: .22; }
.vg.has-selection .vg-edge:not(.on-path) { stroke-opacity: .1; }
.vg .vg-edge.on-path { stroke: var(--accent); stroke-opacity: 1; }
.vg .vg-node.on-path rect { stroke: var(--accent); stroke-width: 2.5; }
.vg .vg-node.sounding rect { fill: var(--accent); }
.vg .vg-node.sounding text { fill: #fff; }
.vg-col-label { font: 500 10px var(--sans); fill: var(--muted); text-anchor: middle; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1.5px solid; }
.legend .l-cons { background: var(--cons-soft); border-color: var(--cons); }
.legend .l-var { background: var(--var-soft); border-color: var(--var); }
.legend .l-gap { background: var(--gap); border-color: var(--line); }
.legend .l-path { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- aligned phrases ---------- */
.aligned { border-collapse: separate; border-spacing: 0; }
.aligned th, .aligned td { padding: 0; border-bottom: 1px solid var(--line); }
.aligned thead th { font-size: .72rem; color: var(--muted); font-weight: 500; padding: 2px 4px; text-align: center; white-space: nowrap; }
.aligned td.who {
  position: sticky; left: 0; background: var(--surface); z-index: 2;
  padding: 6px 10px; white-space: normal; border-right: 1px solid var(--line);
  width: 216px; min-width: 216px; max-width: 216px; overflow-wrap: anywhere; vertical-align: top;
}
.aligned { min-width: 100%; }
.aligned tr.clickable { cursor: pointer; }
.aligned tr.clickable:hover td { background: var(--surface-2); }
.aligned tr.clickable:hover td.who { box-shadow: inset 3px 0 0 var(--accent); }
.aligned tr.selected td, .aligned tr.selected:hover td { background: var(--accent-soft); }
.aligned tr.selected .as-written { background: var(--accent); border-color: var(--accent); color: #fff; }
.who > .flag { margin-top: 6px; }
.aligned tr.outlier td.who { box-shadow: inset 3px 0 0 var(--var); }
.aligned td.staff { vertical-align: middle; }
.aligned svg { display: block; }
.staff-line { stroke: var(--muted); stroke-width: .8; opacity: .7; }
.staff-ledger { stroke: var(--text); stroke-width: 1; }
.note-head { fill: var(--text); }
.note-head.variation { fill: var(--var); }
.note-head.sounding { fill: var(--accent); }
.note-acc { font: 13px serif; fill: var(--text); text-anchor: end; }
.note-acc.variation { fill: var(--var); }
.col-band.variation { fill: var(--var-soft); }
.col-band.gap { fill: var(--gap); }
.col-band.minor { fill: var(--surface-2); }
.interval-label { font: 500 10px var(--sans); fill: var(--muted); text-anchor: middle; }
.interval-label.variation { fill: var(--var); font-weight: 700; }
.who .title { font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.who .sub .mono { font-size: .72rem; }
.who .acts { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.who .acts button { padding: .15rem .55rem; white-space: nowrap; }
.who .flag { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; white-space: nowrap; cursor: pointer; }
.who .flag input { margin: 0; }
.aligned tr.outlier .flag { color: var(--var); font-weight: 600; }
.who button.more { display: block; margin-top: 6px; padding: 0; border: 0; background: none; color: var(--accent); font-size: .78rem; font-weight: 500; text-align: left; }
.who button.more:hover { text-decoration: underline; background: none; }
.who .sub { font-size: .78rem; color: var(--muted); }

.vexflow-wrap { overflow-x: auto; background: #fff; border-radius: 6px; padding: 4px; border: 1px solid var(--line); }
.phrase-detail { padding: 10px 12px; background: var(--surface-2); }

/* ---------- alignment of two scores ---------- */
.align-block { font-family: var(--mono); font-size: .8rem; overflow-x: auto; padding-bottom: 4px; }
.align-row { display: flex; }
.align-row .lab { flex: 0 0 5.5rem; color: var(--muted); font-family: var(--sans); font-size: .78rem; padding-top: 4px; position: sticky; left: 0; background: var(--surface); }
.cell { flex: 0 0 2.6rem; text-align: center; padding: 3px 0; margin: 1px; border-radius: 4px; background: var(--cons-soft); }
.cell.x { background: var(--var-soft); color: var(--var); font-weight: 700; }
.cell.g { background: var(--gap); color: var(--muted); }
.cell.mark { background: transparent; color: var(--muted); padding: 0; }
.cell.boundary { box-shadow: inset 2px 0 0 var(--accent); }
.chip {
  display: inline-block; min-width: 2.4rem; text-align: center; padding: 2px 6px; margin: 2px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: .82rem; font-variant-numeric: tabular-nums; color: inherit;
}
.chip.match { background: var(--mx-soft); border-color: var(--mx); }
.chip.shared { border-color: var(--accent); background: var(--accent-soft); }
.chip.gap { opacity: .4; }
a.chip:hover { text-decoration: none; border-color: var(--accent); }

.hist { display: flex; align-items: flex-end; gap: 1px; height: 80px; }
.hist div { flex: 1; background: var(--accent); opacity: .75; min-height: 1px; border-radius: 1px 1px 0 0; }
.hist div.off { background: var(--line); }
.hist-axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }

/* ---------- how it works ---------- */
.card.method { max-width: 60rem; scroll-margin-top: 70px; }
.card.method > h2 { display: flex; align-items: center; gap: .5rem; font-size: 1.2rem; }
.card.method ul { padding-left: 1.2rem; margin: 0 0 .8rem; }
.card.method li { margin-bottom: .35rem; }
.step-no {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--accent); color: var(--surface);
  font-size: .85rem; font-weight: 700;
}
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); counter-reset: none; }
.steps a {
  display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 10px 12px; color: inherit;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); position: relative;
}
.steps a:hover { border-color: var(--accent); text-decoration: none; }
.steps li:not(:last-child) a::after {
  content: '→'; position: absolute; right: 8px; top: 8px; color: var(--muted);
}
.method-fig { margin: 12px 0 16px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.method-fig figcaption { font-size: .85rem; color: var(--muted); margin-top: 10px; }
.method-fig .fig-body { min-width: 0; }
.fig-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px 20px; }
.fig-panel + .fig-panel { margin-top: 12px; }
.fig-panel.example { display: flex; flex-wrap: wrap; gap: 14px 40px; align-items: center; }
.fig-title { font-weight: 600; font-size: .85rem; margin-bottom: 8px; }
.fig-result { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; font-size: .85rem; color: var(--muted); }
.fig-result .formula { color: var(--text); padding: .3rem .6rem; }
.fig-panel .align-row .lab { flex-basis: 5rem; color: var(--text); font-weight: 600; }
table.counts { border-collapse: collapse; font-size: .85rem; }
table.counts th, table.counts td { padding: 4px 14px; text-align: center; border-bottom: 1px solid var(--line); }
table.counts th:first-child { text-align: left; padding-left: 0; padding-right: 20px; }
table.counts thead th { color: var(--muted); font-weight: 500; }
table.counts td { font-family: var(--mono); }
table.counts td.zero { color: var(--muted); }
.method-fig .aligned td.who { padding-left: 18px; width: 150px; min-width: 150px; }
.method li.sub { list-style: circle; margin-left: 1.2rem; }
.arrow-down { text-align: center; color: var(--muted); font-size: 1.3rem; line-height: 1; margin: 6px 0; }
.formula { font-family: var(--mono); background: var(--surface-2); padding: .5rem .75rem; border-radius: 6px; display: inline-block; }
table.data.compact { width: auto; }
table.data.compact td, table.data.compact th { padding: .25rem .8rem .25rem 0; }

svg.diagram { display: block; max-width: none; font-family: var(--sans); }
.diagram text { fill: var(--text); font-size: 12px; }
.diagram .row-label { font-weight: 600; font-size: 13px; }
.diagram .measure rect { fill: var(--surface); stroke: var(--cons); stroke-width: 1.2; }
.diagram .measure.second rect { fill: var(--accent-soft); }
.diagram .m-label { text-anchor: middle; fill: var(--muted); }
.diagram .rep rect, .diagram .rep circle { fill: var(--text); }
.diagram .ending { fill: none; stroke: var(--text); stroke-width: 1.2; }
.diagram .ending-label, .diagram .pass-label { font-size: 11px; fill: var(--muted); }
.diagram .pass-label { text-anchor: middle; }
.diagram .phrase-bar rect { stroke-width: 1.5; }
.diagram .phrase-bar.annotated rect { fill: var(--cons-soft); stroke: var(--cons); }
.diagram .phrase-bar.repeat rect { fill: var(--surface); stroke: var(--muted); stroke-dasharray: 4 3; }
.diagram .phrase-bar.inferred rect { fill: var(--var-soft); stroke: var(--var); }
.diagram .bar-label { text-anchor: middle; font-size: 11.5px; }
.diagram .note { text-anchor: middle; font-size: 11px; fill: var(--muted); }
.diagram .sim-edge { stroke: var(--cons); stroke-width: 2; }
.diagram .phrase-dot circle { fill: var(--surface); stroke: var(--cons); stroke-width: 1.5; }
.diagram .phrase-dot text { text-anchor: middle; font-weight: 700; font-size: 13px; }
.diagram .hull { stroke-width: 1.5; }
.diagram .hull.g1 { fill: var(--accent-soft); stroke: var(--accent); }
.diagram .hull.g2 { fill: var(--mx-soft); stroke: var(--mx); }
.diagram .hull.alone { fill: none; stroke: var(--muted); stroke-dasharray: 4 3; }
.cluster-panels { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.cluster-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px; }
.cluster-panel svg { max-width: 100%; height: auto; }

.eval-list li { margin-bottom: .5rem; }
.verdicts { display: grid; gap: 4px; margin: 6px 0 10px; }
.verdicts label { color: var(--text); font-size: .9rem; display: flex; gap: 6px; align-items: baseline; }
footer.site { max-width: 1280px; margin: 0 auto; padding: 0 16px 32px; color: var(--muted); font-size: .82rem; }

/* ---------- full score, measures of a comparison ---------- */
.full-score { background: #fff; color: #000; border: 1px solid var(--line); border-radius: 6px; padding: 4px; margin-top: 8px; overflow-x: auto; }
.full-score svg { display: block; width: 100%; height: auto; }
.full-score .loading, .full-score p { padding: .8rem; margin: 0; color: #555; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.two { grid-template-columns: minmax(0, 1fr); } }
.grid.measures { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.measure { display: block; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.measure:hover { text-decoration: none; border-color: var(--accent); }
.measure .name { font-weight: 700; font-size: 1.05rem; }
.measure .value { display: flex; align-items: center; gap: 6px; margin: 6px 0; font-variant-numeric: tabular-nums; }
.measure .value .simbar { width: 72px; margin: 0; }
.measure .value b { font-size: 1.1rem; }
.measure .unit, .measure .text { font-size: .82rem; color: var(--muted); }
.letter { display: inline-grid; place-items: center; flex: 0 0 auto; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; font-size: .9rem; }
.shared-cluster { border-top: 1px solid var(--line); padding: 12px 0; }
.shared-phrase { margin-top: 8px; }
.measure .unit { white-space: nowrap; }
.card .row > button { white-space: nowrap; flex: 0 0 auto; }
.full-score .stanzas { padding: .4rem .8rem .6rem; font-size: .9rem; }
.full-score .stanzas summary { cursor: pointer; color: #333; font-weight: 600; }
.full-score .stanzas pre { font: inherit; white-space: pre-wrap; margin: .5rem 0 0; }

.swatch { display: inline-block; width: .75rem; height: .75rem; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
details.computation { margin-top: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; background: var(--surface-2); font-size: .9rem; }
details.computation summary { cursor: pointer; font-weight: 600; color: var(--accent); }
details.computation p { margin: .5rem 0; }
details.computation .formula { font-variant-numeric: tabular-nums; }
details.computation table.data { background: var(--surface); width: auto; min-width: 60%; }
table.data tfoot td { border-bottom: 0; }
