@font-face {
  font-family: "Geist";
  src: url("fonts/geist.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("fonts/geist-mono.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

/* Crisp white and black, thin rules, and a few flat blocks of colour.
   Each person keeps one colour everywhere (line, legend, column, melody). */
:root {
  --paper: #ffffff;
  --ink: #000000;
  --muted: #6b6b6b;
  --rule: #000000;
  --hairline: #d9d9d9;
  --field: #ffffff;
  --person-1: #00978d;   /* Benzol green */
  --person-2: #b5b1d8;   /* greyish lavender */
  --action: #ffdd00;     /* Apricot yellow */
  /* Score colours (from the same palette) */
  --harmony-1: #bb7125;  /* Raw sienna: chords */
  --harmony-2: #f37f94;  /* Eosine pink: high harmony */
  --bass: #1c4286;       /* Deep Lyons blue */
  --symbol: #704357;     /* Dark slate purple: activity symbols */
  --diverge: #ffdd00;    /* Apricot yellow tint behind diverging moments */
  --action-ink: #000000;
  --chip: #f2f2f2;
  --focus: #00978d;
  --error: #d11a2a;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.375rem;
  --step-2: 2rem;
  --step-3: clamp(2.75rem, 7vw, 5.5rem);
  --gutter: clamp(1rem, 4vw, 4.5rem);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #000000;
    --ink: #ffffff;
    --muted: #a3a3a3;
    --rule: #ffffff;
    --hairline: #333333;
    --field: #111111;
    --person-1: #12b3a7;
    --person-2: #b5b1d8;
    --harmony-1: #d98b3a;
    --bass: #6f8fd6;
    --symbol: #c995ad;
    --chip: #1c1c1c;
    --focus: #12b3a7;
    --error: #ff6b74;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #000000;
  --ink: #ffffff;
  --muted: #a3a3a3;
  --rule: #ffffff;
  --hairline: #333333;
  --field: #111111;
  --person-1: #12b3a7;
  --person-2: #b5b1d8;
  --harmony-1: #d98b3a;
  --bass: #6f8fd6;
  --symbol: #c995ad;
  --chip: #1c1c1c;
  --focus: #12b3a7;
  --error: #ff6b74;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
/* Hidden for the moment it takes app.js to fill in the words from copy.js. */
html.loading main { visibility: hidden; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Geist", system-ui, sans-serif;
  font-size: var(--step-0);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 80rem;
  margin: 0 auto;
  padding: 2.5rem var(--gutter) 3rem;
}

h1, h2 { font-weight: 400; margin: 0; letter-spacing: -0.02em; }
h1 { font-size: var(--step-3); line-height: 0.95; letter-spacing: -0.04em; }
h2 { font-size: var(--step-2); line-height: 1.1; }
h3 { font-size: var(--step-0); font-weight: 500; margin: 0; }
p { margin: 0 0 0.75rem; max-width: 38em; }
a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }

.hint { color: var(--muted); font-size: var(--step--1); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Masthead */
.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 1.5rem var(--gutter);
  align-items: end;
  padding-bottom: 2rem;
}
.lede { font-size: var(--step-1); line-height: 1.35; margin-bottom: 0.5rem; }
.privacy { color: var(--muted); margin: 0; }

/* The two lines, drawn from the people's own recordings */
.traces { margin: 0 0 3rem; }
.traces svg { display: block; width: 100%; height: clamp(10rem, 22vw, 17rem); overflow: visible; }
.trace {
  fill: none;
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.trace-1 { stroke: var(--person-1); }
.trace-2 { stroke: var(--person-2); }
/* A person whose recording isn't chosen yet: a faint thin dashed line */
.trace.waiting { stroke: var(--hairline); stroke-width: 1; stroke-dasharray: 3 5; }
.trace-2 { stroke-width: 3; }   /* the lavender needs a little more weight on white */

/* Before any recording is chosen, the line area collapses to a single note. */
.traces.is-empty svg { display: none; }
.traces.is-empty figcaption { border-top: 1px solid var(--hairline); padding-top: 0.75rem; margin-top: 0; }
.traces:not(.is-empty) svg { animation: open 0.5s ease-out; }
@keyframes open { from { height: 0; opacity: 0; } }
/* backwards, not both: once drawn, the dash pattern is dropped so the whole line shows */
.trace.drawn { animation: draw 1.6s ease-out backwards; }
@keyframes draw {
  from { stroke-dashoffset: var(--length); stroke-dasharray: var(--length); }
  to { stroke-dashoffset: 0; stroke-dasharray: var(--length); }
}
.traces figcaption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 2rem;
  margin-top: 1rem;
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: var(--step--1);
  color: var(--muted);
}
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.15rem; }
.legend li { display: flex; align-items: center; gap: 0.6rem; }
.legend .dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; flex: none; }
.legend .who { color: var(--ink); }
.dot-1 { background: var(--person-1); }
.dot-2 { background: var(--person-2); }

/* Bands: sections divided by a black rule, heading on the left */
.band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 3fr);
  gap: 0.25rem var(--gutter);
  border-top: 1px solid var(--rule);
  padding: 1.5rem 0 3rem;
}
.band > h2 { grid-column: 1; grid-row: 1 / span 3; }
.band > * { grid-column: 2; }

/* People: two columns, each topped with its person's colour */
.people {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 1.25rem;
}
.person {
  display: grid;
  gap: 0.9rem;
  align-content: start;
  padding: 0 1.5rem 0.5rem;
  border-left: 1px solid var(--rule);
}
.person:first-child { border-left: 0; padding-left: 0; }
.person::before {
  content: "";
  display: block;
  height: 3.5rem;
  background: var(--person-color);
  border-radius: 0 0 1.75rem 0;
}
.person-1 { --person-color: var(--person-1); }
.person-2 { --person-color: var(--person-2); }
.person-2::before { border-radius: 0 0 0 1.75rem; }

.name { display: grid; gap: 0.3rem; font-size: var(--step--1); color: var(--muted); }
.name input {
  font: inherit;
  font-size: var(--step-1);
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  padding: 0.25rem 0;
  width: 100%;
}
.name input::placeholder { color: var(--muted); opacity: 0.6; }
.name input:focus-visible { outline: 0; border-bottom: 2px solid var(--person-color); }

.file-button { position: relative; justify-self: start; }
.file-button input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.file-button span {
  display: inline-block;
  padding: 0.55rem 1.2rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-weight: 500;
  background: var(--paper);
}
.file-button:hover span { background: var(--person-color); color: #000; border-color: var(--person-color); }
.file-button:focus-within span { outline: 2px solid var(--focus); outline-offset: 3px; }
.file-status { margin: 0; font-family: "Geist Mono", ui-monospace, monospace; font-size: var(--step--1); color: var(--muted); overflow-wrap: anywhere; }
.file-status.ok { color: var(--ink); }
.file-status.problem { color: var(--error); }

/* Toggles: groups in columns divided by thin rules */
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 1.25rem;
}
.toggle-column { padding: 0 1.5rem 1rem; border-left: 1px solid var(--rule); }
.toggle-column:first-child { border-left: 0; padding-left: 0; }
.group + .group { margin-top: 1.25rem; }
.group h3 { margin-bottom: 1rem; }
.toggle { border: 0; margin: 0 0 1.4rem; padding: 0; min-width: 0; }
.toggle legend { padding: 0; font-size: var(--step--1); color: var(--muted); margin-bottom: 0.45rem; }
.choices { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.choices label { position: relative; }
.choices input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choices span {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--paper);
  font-size: 0.9375rem;
}
.choices label:hover span { border-color: var(--ink); }
.choices input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.choices input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.toggle .hint { margin: 0.45rem 0 0; }
.toggle.inactive .choices { opacity: 0.35; }

.instruments { margin-top: 0.5rem; border-top: 1px solid var(--hairline); padding-top: 1rem; }
.instruments summary { cursor: pointer; font-weight: 500; }
#instrument-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1rem 1.5rem;
  margin-top: 1rem;
}
#instrument-list label { display: grid; gap: 0.3rem; font-size: var(--step--1); color: var(--muted); }
#instrument-list select {
  font: inherit;
  font-size: var(--step-0);
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  max-width: 100%;
}

/* The one big colour block: make the music */
#make-button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: var(--step-2);
  letter-spacing: -0.02em;
  padding: 2rem 1.75rem;
  border: 0;
  border-radius: 0;
  background: var(--action);
  color: var(--action-ink);
  cursor: pointer;
}
#make-button:hover:not(:disabled) { filter: brightness(0.97); }
/* Stays yellow while waiting for the engine or the files; only the text fades. */
#make-button:disabled { color: rgba(0, 0, 0, 0.38); cursor: not-allowed; }
.engine-status {
  margin: 0.75rem 0 0;
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: var(--step--1);
  color: var(--muted);
}
.engine-status.problem { color: var(--error); }

/* Result and player */
.result { padding: 2.5rem 0 1rem; }
#result-summary { font-size: var(--step-2); line-height: 1.15; letter-spacing: -0.02em; max-width: 24em; margin-bottom: 1.5rem; }
/* Scrolling score */
.score { margin: 0 0 1.5rem; }
.score canvas { display: block; width: 100%; height: clamp(15rem, 30vw, 24rem); }
.score-legend {
  display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; margin-top: 0.75rem;
  font-family: "Geist Mono", ui-monospace, monospace; font-size: var(--step--1); color: var(--muted);
}
.score-legend > span { display: inline-flex; align-items: center; gap: 0.5rem; }
.score-legend .dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; }
.key-bar { width: 1.1rem; height: 0.3rem; border-radius: 0.15rem; }
.key-chords { background: var(--harmony-1); }
.key-high { background: var(--harmony-2); }
.key-bass { background: var(--bass); }
.key-symbol { width: 1.1rem; height: 1.1rem; stroke: var(--symbol); fill: none; stroke-width: 1.5; }
.key-symbol .solid { fill: var(--symbol); stroke: none; }
.key-band { width: 1.1rem; height: 0.3rem; background: linear-gradient(90deg, var(--person-1) 50%, var(--person-2) 50%); }

.player { display: flex; align-items: center; gap: 1.25rem; }
#play-button {
  width: 4.5rem; height: 4.5rem;
  flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
#play-button svg { width: 1.6rem; height: 1.6rem; fill: currentColor; }
#play-button .icon-pause { display: none; }
#play-button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
#play-button[aria-pressed="true"] .icon-play { display: none; }
#play-button[aria-pressed="true"] .icon-pause { display: block; }
#play-button:disabled { opacity: 0.35; cursor: not-allowed; }
#seek { flex: 1; min-width: 0; accent-color: var(--ink); }
.time { font-family: "Geist Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; font-size: var(--step--1); color: var(--muted); white-space: nowrap; }
#player-status { margin-top: 0.5rem; min-height: 1.2em; }
.downloads { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1.25rem 0 0.75rem; }
.download {
  display: inline-block;
  padding: 0.55rem 1.2rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  text-decoration: none;
  font-weight: 500;
}
.download:hover { background: var(--ink); color: var(--paper); }

/* Footer */
.about {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 1.5rem var(--gutter);
  border-top: 1px solid var(--rule);
  margin-top: 3rem;
  padding-top: 1.5rem;
}
.about h2 { font-size: var(--step-1); margin-bottom: 0.75rem; }
.about p { color: var(--muted); }
.credits { font-family: "Geist Mono", ui-monospace, monospace; font-size: var(--step--1); color: var(--muted); }
.credits p { margin-bottom: 0.4rem; }

/* Narrower screens */
@media (max-width: 62rem) {
  .toggle-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toggle-column:nth-child(3) { grid-column: 1 / -1; border-left: 0; padding-left: 0; border-top: 1px solid var(--hairline); padding-top: 1.25rem; }
}
@media (max-width: 48rem) {
  .masthead, .band, .about { grid-template-columns: 1fr; }
  .band > h2, .band > * { grid-column: 1; grid-row: auto; }
  .people, .toggle-grid { grid-template-columns: 1fr; }
  .person, .toggle-column, .toggle-column:nth-child(3) {
    border-left: 0; padding-left: 0; padding-right: 0;
  }
  .person + .person { margin-top: 2rem; }
  .toggle-column + .toggle-column { border-top: 1px solid var(--hairline); padding-top: 1.25rem; }
  #make-button { padding: 1.5rem 1.25rem; font-size: var(--step-1); }
  .player { gap: 0.9rem; }
  #play-button { width: 3.75rem; height: 3.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .trace.drawn, .traces:not(.is-empty) svg { animation: none; }
}

/* Sound check panel (only with ?check in the address) */
.soundcheck {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 10;
  width: min(36rem, calc(100vw - 2rem)); max-height: 70vh; overflow: auto;
  background: var(--paper); color: var(--ink); border: 1px solid var(--rule);
  padding: 1rem; font-size: var(--step--1);
}
.soundcheck pre { white-space: pre-wrap; font-family: "Geist Mono", ui-monospace, monospace; margin: 0.5rem 0; }
.soundcheck-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.soundcheck button { font: inherit; padding: 0.35rem 0.8rem; border: 1px solid var(--rule); border-radius: 999px; background: var(--paper); color: var(--ink); cursor: pointer; }
