:root {
  color-scheme: light;
  --paper: #f3f0e9;
  --ink: #161816;
  --muted: #6e716b;
  --line: #cbc8bf;
  --soft-line: #e3e0d8;
  --surface: #fbfaf6;
  --surface-strong: #ffffff;
  --green: #1c4f46;
  --green-soft: #dce8e4;
  --gold: #d7a820;
  --gold-soft: #f6edc8;
  --orange: #e14f2c;
  --violet: #7447c8;
  --blue: #55a7cf;
  --rank-early: #e14f2c;
  --rank-late: #69acd1;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 4%, rgb(28 79 70 / 8%), transparent 27rem),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="range"],
input[type="checkbox"] {
  cursor: pointer;
}

.page-shell {
  width: min(1540px, calc(100% - 32px));
  margin-inline: auto;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: end;
  gap: 48px;
  min-height: 350px;
  padding: 72px 20px 52px;
}

.eyebrow,
.section-index,
.sample-source {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
.sample-masthead h3,
.score-heading h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

h1 {
  max-width: 980px;
  margin-bottom: 26px;
  font-size: clamp(3.2rem, 5.2vw, 5rem);
  line-height: 0.92;
  letter-spacing: -0.06em;
}

h1 em {
  color: var(--green);
  font-weight: inherit;
}

.lede {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.98rem, 1.6vw, 1.15rem);
  line-height: 1.75;
}

.hero-note {
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 18px 0;
}

.hero-note-index {
  display: block;
  margin-bottom: 20px;
  color: var(--green);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.3rem;
}

.hero-note p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.65;
}

.hero-note strong {
  color: var(--ink);
}

.explorer {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
}

.control-deck {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(340px, 1.4fr) minmax(240px, 1fr) auto;
  align-items: end;
  gap: 24px;
  padding: 28px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--green);
  color: #fff;
}

.control-deck .section-index {
  color: rgb(255 255 255 / 58%);
}

.control-intro h2 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.8rem);
  line-height: 0.95;
}

.sample-picker {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  gap: 8px;
  min-width: 0;
}

.sample-picker label {
  grid-column: 2;
  color: rgb(255 255 255 / 65%);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.sample-picker select {
  grid-column: 2;
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 1px solid rgb(255 255 255 / 34%);
  border-radius: 8px;
  padding: 0 36px 0 12px;
  color: #fff;
  background: rgb(255 255 255 / 10%);
}

.sample-picker select option {
  color: var(--ink);
}

.icon-button {
  grid-row: 2;
  height: 42px;
  border: 1px solid rgb(255 255 255 / 34%);
  border-radius: 8px;
  color: #fff;
  background: transparent;
}

.icon-button:first-child {
  grid-column: 1;
}

.icon-button:last-child {
  grid-column: 3;
}

.icon-button:hover,
.play-button:hover {
  background: rgb(255 255 255 / 12%);
}

.step-control-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 11px;
  color: rgb(255 255 255 / 68%);
  font-size: 0.75rem;
  font-weight: 700;
}

.step-control,
.control-actions {
  min-width: 0;
}

.step-control output {
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.step-control input {
  width: 100%;
  accent-color: #f4c34d;
}

.control-actions {
  display: grid;
  gap: 10px;
}

.play-button {
  min-height: 42px;
  border: 1px solid rgb(255 255 255 / 34%);
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: transparent;
  font-weight: 700;
}

.check-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgb(255 255 255 / 72%);
  font-size: 0.75rem;
}

.check-control input {
  accent-color: #f4c34d;
}

.sample-masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
  padding: 34px 36px 26px;
}

.sample-masthead h3 {
  margin: 0;
  font-size: clamp(2.1rem, 5vw, 4.6rem);
  line-height: 0.9;
  letter-spacing: -0.045em;
}

.sample-facts {
  display: flex;
  margin: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.sample-facts div {
  min-width: 110px;
  padding: 12px 18px;
}

.sample-facts div + div {
  border-left: 1px solid var(--line);
}

.sample-facts dt {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sample-facts dd {
  margin: 6px 0 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.graph-toolbar {
  display: flex;
  align-items: center;
  gap: 28px;
  min-height: 48px;
  margin: 0 36px;
  border-top: 1px solid var(--soft-line);
  border-bottom: 1px solid var(--soft-line);
  color: var(--muted);
  font-size: 0.72rem;
}

.legend-group {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.legend-group > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-title {
  color: var(--ink);
  font-weight: 700;
}

.continuous-legend {
  gap: 8px;
}

.continuous-key {
  display: inline-block;
  width: 116px;
  height: 8px;
  border: 1px solid rgb(22 24 22 / 18%);
}

.contribution-strength-key {
  display: inline-block;
  width: 116px;
  height: 12px;
  background: linear-gradient(90deg, rgb(22 24 22 / 22%), rgb(22 24 22 / 88%));
  clip-path: polygon(0 44%, 100% 0, 100% 100%, 0 56%);
}

.order-key {
  background: linear-gradient(90deg, var(--orange), var(--violet), var(--blue));
}

.legend-limit {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.graph-status {
  margin: 0 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.graph-scroll {
  overflow-x: auto;
  padding: 18px 24px 6px;
  scrollbar-color: var(--line) transparent;
}

#flow-graph {
  display: block;
  width: 100%;
  min-width: 980px;
  height: auto;
  min-height: 570px;
}

.flow-band {
  fill: #f0f2ef;
}

.flow-band.major {
  fill: #e9efec;
}

.flow-grid-line {
  stroke: #dfe1dc;
  stroke-width: 1;
}

.flow-axis-line {
  stroke: #9da29d;
  stroke-width: 1.2;
}

.flow-node {
  fill: #f9faf8;
  stroke: #aeb3ae;
  stroke-width: 1;
}

.flow-node.is-active {
  fill: var(--surface-strong);
  stroke: #4f5752;
  stroke-width: 1.5;
}

.flow-node.is-anchor {
  fill: var(--gold-soft);
  stroke: var(--gold);
  stroke-width: 2;
}

.self-flow {
  fill: none;
  stroke-linecap: round;
  stroke-width: 2;
  opacity: 0.58;
}

.principal-edge {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  cursor: pointer;
  transition: opacity 140ms ease, filter 140ms ease;
}

.principal-edge:hover,
.principal-edge.is-highlighted {
  filter: drop-shadow(0 0 3px rgb(30 34 31 / 25%));
  opacity: 1 !important;
}

.token-label,
.layer-label,
.axis-label,
.chord-label,
.note-label {
  fill: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

.layer-label,
.axis-label {
  fill: var(--muted);
  font-size: 12px;
}

.layer-ellipsis {
  fill: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
}

.axis-label {
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.token-label {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.token-label.note {
  fill: var(--green);
}

.token-label.harmony {
  fill: var(--violet);
}

.chord-label {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  font-weight: 700;
}

.chord-function {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.chord-target-box {
  fill: var(--gold-soft);
  stroke: var(--gold);
}

.target-column {
  fill: var(--gold-soft);
  opacity: 0.65;
}

.token-annotation {
  cursor: pointer;
}

.sequence-order-dot {
  stroke: var(--surface-strong);
  stroke-width: 2;
}

.sequence-order-value {
  fill: #fff;
  font-size: 9px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.score-section {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 28px;
  margin: 4px 36px 0;
  padding: 28px 0 30px;
  border-top: 1px solid var(--soft-line);
}

.score-heading h3 {
  margin: 0 0 14px;
  font-size: 2rem;
  line-height: 1;
}

.score-heading > p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.6;
}

.score-wrap {
  min-width: 0;
  overflow-x: auto;
  border-left: 1px solid var(--soft-line);
  padding-left: 24px;
}

#score-paper {
  min-width: 720px;
}

#score-paper > svg {
  display: block;
  width: 100%;
  height: auto;
}

#score-paper .abcjs-note,
#score-paper .abcjs-chord {
  cursor: pointer;
}

#score-paper .note-rank-overlay circle,
#score-paper .chord-rank-overlay circle {
  stroke: #fff;
  stroke-width: 2;
}

#score-paper .note-rank-overlay text,
#score-paper .chord-rank-overlay text {
  color: #fff;
  fill: #fff !important;
  stroke: none !important;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 9px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
}

#score-paper .chord-rank-overlay {
  cursor: pointer;
}

#score-paper .target-halo {
  fill: var(--gold-soft);
  fill-opacity: 0.48;
  stroke: var(--gold);
  stroke-width: 2;
  opacity: 1;
  pointer-events: none;
}

.detail-strip {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 28px;
  padding: 24px 36px;
  border-top: 1px solid var(--line);
  background: #efeee8;
}

.detail-copy > p:last-child,
.method-note p {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.6;
}

.method-note {
  display: flex;
  gap: 14px;
  padding-left: 24px;
  border-left: 1px solid var(--line);
}

.method-note span {
  flex: 0 0 auto;
  height: fit-content;
  border-radius: 99px;
  padding: 6px 9px;
  color: #fff;
  background: var(--green);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.method-note p {
  color: var(--muted);
}

.lede,
.score-heading p,
.detail-strip p,
footer span {
  overflow-wrap: anywhere;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 8px 42px;
  color: var(--muted);
  font-size: 0.68rem;
}

.tooltip {
  position: fixed;
  z-index: 20;
  max-width: 290px;
  border: 1px solid rgb(255 255 255 / 16%);
  border-radius: 9px;
  padding: 10px 12px;
  color: #fff;
  background: rgb(20 24 21 / 94%);
  box-shadow: 0 12px 34px rgb(0 0 0 / 22%);
  font-size: 0.72rem;
  line-height: 1.5;
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

html.figure-export,
body.figure-export {
  overflow-anchor: none;
}

body.figure-export {
  min-width: 1180px;
  background: var(--surface);
}

.figure-export .page-shell {
  width: 100%;
  margin: 0;
}

.figure-export .hero,
.figure-export .control-deck,
.figure-export .sample-masthead,
.figure-export .graph-status,
.figure-export .score-heading,
.figure-export .detail-strip,
.figure-export footer,
.figure-export .tooltip {
  display: none !important;
}

.figure-export .explorer {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(530px, 1fr);
  column-gap: 48px;
  margin: 0;
  padding: 0 42px;
  overflow: visible;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--surface);
}

.figure-export .graph-toolbar {
  grid-column: 2;
  grid-row: 2;
  align-self: stretch;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 18px;
  min-height: 0;
  margin: 0;
  padding: 6px 0 20px;
  border-top: 1px solid var(--soft-line);
  border-bottom: 0;
  font-size: 1rem;
}

.figure-export .graph-toolbar .legend-group {
  display: grid;
  grid-template-columns: 170px 78px 180px minmax(76px, 1fr);
  gap: 8px;
  width: 100%;
}

.figure-export .graph-toolbar .continuous-key {
  width: 180px;
  height: 13px;
}

.figure-export .graph-toolbar .contribution-strength-key {
  width: 180px;
  height: 20px;
}

.figure-export .graph-toolbar .legend-title {
  justify-self: start;
}

.figure-export .graph-toolbar .legend-limit:last-child {
  justify-self: start;
}

.figure-export .graph-scroll {
  grid-column: 1 / -1;
  grid-row: 1;
  overflow: visible;
  padding: 10px 0 2px;
}

.figure-export #flow-graph {
  min-height: 0;
}

.figure-export .score-section {
  grid-column: 1;
  grid-row: 2;
  display: block;
  margin: 0;
  padding: 6px 0 20px;
}

.figure-export .score-wrap {
  overflow: visible;
  border-left: 0;
  padding-left: 0;
}

.figure-export #score-paper {
  min-width: 0;
  display: block !important;
  width: 100% !important;
  margin-inline: 0;
}

.figure-export #score-paper > svg {
  width: 100% !important;
  height: 100% !important;
}

@media print {
  @page {
    size: 16.6667in 10.85in;
    margin: 0;
  }

  html.figure-export,
  body.figure-export {
    --surface: #fff;
    --surface-strong: #fff;
    width: 16.6667in;
    height: 10.85in;
    min-width: 0;
    background: #fff !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .figure-export .page-shell,
  .figure-export .explorer {
    background: #fff !important;
  }
}

@media (max-width: 1180px) {
  .control-deck {
    grid-template-columns: minmax(220px, 0.8fr) minmax(340px, 1.2fr) minmax(260px, 1fr);
  }

  .control-actions {
    grid-column: 2 / -1;
    grid-template-columns: auto 1fr;
    align-items: center;
  }
}

@media (max-width: 820px) {
  .page-shell {
    width: min(100% - 18px, 1540px);
  }

  .hero {
    grid-template-columns: 1fr;
    min-height: 0;
    padding: 54px 10px 34px;
  }

  .hero-note {
    max-width: 420px;
  }

  .control-deck {
    grid-template-columns: 1fr;
    gap: 22px;
    padding: 24px 20px;
  }

  .control-deck > * {
    min-width: 0;
  }

  .control-actions {
    grid-column: auto;
  }

  .sample-masthead {
    display: grid;
    padding-inline: 22px;
  }

  .sample-facts {
    width: 100%;
  }

  .sample-facts div {
    flex: 1;
    min-width: 0;
    padding-inline: 12px;
  }

  .graph-toolbar {
    flex-wrap: wrap;
    gap: 12px 20px;
    margin-inline: 22px;
    padding-block: 10px;
  }

  .graph-status {
    width: 100%;
    margin: 0;
  }

  .score-section,
  .detail-strip {
    grid-template-columns: 1fr;
  }

  .score-section {
    margin-inline: 22px;
  }

  .score-wrap {
    border-left: 0;
    padding-left: 0;
  }

  .detail-strip {
    padding-inline: 22px;
  }

  .method-note {
    padding: 18px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  footer {
    display: grid;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 2.6rem;
  }

  .sample-picker {
    grid-template-columns: 36px minmax(0, 1fr) 36px;
  }

  .sample-picker select {
    text-overflow: ellipsis;
  }

  .control-actions {
    grid-template-columns: 1fr;
  }

  .sample-facts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .legend-group {
    flex-wrap: wrap;
  }

  .order-legend {
    display: none;
  }

  .method-note {
    display: grid;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .principal-edge {
    transition: none;
  }
}
