:root {
  --stage: #24101A;
  --stage-deep: #160910;
  --ebony: #120709;
  --ivory: #F3EBDC;
  --ivory-shade: #DCCFB8;
  --ink: #2A1812;
  --ink-soft: rgba(42, 24, 18, 0.55);
  --text: #F1E9DA;
  --text-dim: #CDBFAB;
  --text-faint: rgba(241, 233, 218, 0.6);
  --brass: #D4A24C;
  --brass-hi: #F2CB7E;
  --brass-deep: #9C6B26;
  --signal: #9EC2FF;
  --line: rgba(241, 233, 218, 0.13);
  --line-strong: rgba(241, 233, 218, 0.26);
  --danger: #F2907F;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --rule: 2.6rem;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 400 1rem/1.55 var(--sans);
  font-variant-numeric: tabular-nums;
  background-color: var(--stage-deep);
  background:
    radial-gradient(70% 55% at 50% 0%, rgba(242, 203, 126, 0.13), transparent 70%),
    radial-gradient(90% 60% at 50% 100%, rgba(0, 0, 0, 0.45), transparent 70%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.07) 0 2px, transparent 2px 7px),
    linear-gradient(180deg, var(--stage) 0%, var(--stage-deep) 100%);
}
a { color: var(--brass-hi); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- masthead ---------- */
.masthead {
  max-width: 1240px; margin: 0 auto; padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 0;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.wordmark {
  text-decoration: none;
  font: italic 400 clamp(2.6rem, 6vw, 3.6rem)/0.9 var(--serif); color: var(--brass-hi);
  text-shadow: 0 0 30px rgba(242, 203, 126, 0.25);
}
.console { display: flex; align-items: center; gap: 0.8rem; }
.sound {
  display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.5rem 0.85rem; border-radius: 999px;
  background: transparent; border: 1px solid var(--line-strong); color: var(--text-dim); cursor: pointer; font-size: 0.86rem;
}
.sound svg { width: 18px; height: 18px; fill: currentColor; }
.sound .wave { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; opacity: 0.25; }
.sound[aria-pressed="true"] { color: var(--brass-hi); border-color: var(--brass); }
.sound[aria-pressed="true"] .wave { opacity: 1; }
.metronome {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.9rem; border-radius: 12px;
  background: rgba(18, 7, 9, 0.6); border: 1px solid var(--line);
}
.tempo-figure { font: 400 2rem/1 var(--serif); color: var(--signal); min-width: 2.2ch; text-align: right; }
.tempo-unit { font-size: 0.74rem; line-height: 1.15; color: var(--text-faint); }
.tempo-unit small { font-size: 0.7rem; white-space: nowrap; }
.spark { width: 90px; height: 28px; }
.spark rect { fill: var(--signal); opacity: 0.45; }
.spark rect:last-child { opacity: 1; }

/* ---------- programme (tabs) ---------- */
.programme {
  max-width: 1240px; margin: 2rem auto 0; padding: 0 clamp(1rem, 4vw, 2.5rem);
  display: flex; gap: clamp(1rem, 4vw, 3rem); overflow-x: auto; scrollbar-width: none;
}
.programme a {
  padding: 0 0 0.6rem; text-align: left; color: var(--text-faint); text-decoration: none;
  border-bottom: 1px solid transparent; display: grid; gap: 0.1rem; white-space: nowrap;
}
.programme em { font: italic 400 clamp(1.7rem, 3.6vw, 2.4rem)/1 var(--serif); color: inherit; }
.programme span { font-size: 0.84rem; }
.programme a[aria-current="page"] { color: var(--text); border-bottom-color: var(--brass); }
.programme a[aria-current="page"] em { color: var(--brass-hi); }
.programme a:hover { color: var(--text); }

main { max-width: 1240px; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.5rem); }
.panel { padding: 1.6rem 0 3rem; }

/* ---------- the manuscript sheet ---------- */
.sheet {
  display: block; width: 100%; resize: vertical; border: 0; border-radius: 4px 4px 14px 14px;
  color: var(--ink); caret-color: var(--brass-deep);
  font: italic 400 clamp(1.45rem, 2.6vw, 1.95rem)/var(--rule) var(--serif);
  padding: calc(var(--rule) * 0.55) clamp(1.2rem, 4vw, 3rem) calc(var(--rule) * 0.6) clamp(2.6rem, 6vw, 4.6rem);
  min-height: calc(var(--rule) * 4.4);
  background-color: var(--ivory);
  background-image:
    linear-gradient(90deg, transparent calc(clamp(1.7rem, 4.4vw, 3.4rem)), var(--brass) calc(clamp(1.7rem, 4.4vw, 3.4rem)), var(--brass) calc(clamp(1.7rem, 4.4vw, 3.4rem) + 2px), transparent calc(clamp(1.7rem, 4.4vw, 3.4rem) + 2px), transparent calc(clamp(1.7rem, 4.4vw, 3.4rem) + 6px), var(--brass) calc(clamp(1.7rem, 4.4vw, 3.4rem) + 6px), var(--brass) calc(clamp(1.7rem, 4.4vw, 3.4rem) + 7px), transparent calc(clamp(1.7rem, 4.4vw, 3.4rem) + 7px)),
    repeating-linear-gradient(180deg, transparent 0 calc(var(--rule) - 1px), rgba(42, 24, 18, 0.2) calc(var(--rule) - 1px) var(--rule));
  background-position: 0 0, 0 calc(var(--rule) * 0.55);
  background-attachment: local;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 30px 60px -25px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(0, 0, 0, 0.3);
}
.sheet::placeholder { color: var(--ink-soft); }
.sheet:focus { outline: none; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 30px 60px -25px rgba(0, 0, 0, 0.75), 0 0 0 3px var(--brass); }
.sheet-small { --rule: 2rem; font-size: 1.2rem; min-height: calc(var(--rule) * 5.4); font-style: normal; }
.cues { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.5rem; margin-top: 0.85rem; color: var(--text-faint); font-size: 0.9rem; }
.cues > span { font: italic 1.1rem var(--serif); margin-right: 0.2rem; }
.cue {
  background: none; border: 0; padding: 0.15rem 0.35rem; cursor: pointer; color: var(--text-dim);
  font: italic 1.1rem var(--serif); border-bottom: 1px dotted var(--line-strong);
}
.cue:hover, .cue.on { color: var(--brass-hi); border-bottom-color: var(--brass); }

/* ---------- the instrument ---------- */
.instrument { margin-top: 2.2rem; display: grid; gap: 2rem; }
.register-name { margin: 0.7rem 0 0; font: italic 1.25rem/1.1 var(--serif); color: var(--text-dim); }
.manual {
  display: flex; align-items: stretch; gap: 0; padding: 14px 14px 18px; border-radius: 10px;
  background: linear-gradient(180deg, #1A0B10, var(--ebony));
  box-shadow: inset 0 10px 18px rgba(0, 0, 0, 0.7), 0 1px 0 rgba(255, 255, 255, 0.05);
}
.manual .register { flex: 5 1 0; min-width: 0; }
.manual .register[data-q="mood"] { flex: 4 1 0; }
.ebony-gap {
  flex: 0 0 26px; height: 120px; margin: 0 8px; border-radius: 0 0 5px 5px;
  background: linear-gradient(90deg, #070304, #2B1A1E 45%, #0A0506);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.6);
}
.keys { display: flex; gap: 4px; align-items: flex-start; }
.key { flex: 1 1 0; min-width: 0; display: grid; gap: 0.5rem; }
.key-body {
  position: relative; height: 200px; border-radius: 0 0 8px 8px; overflow: hidden;
  background: linear-gradient(180deg, #E9DFCD 0%, var(--ivory) 14%, var(--ivory) 82%, var(--ivory-shade) 100%);
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.13), 0 3px 0 #000, 0 6px 10px rgba(0, 0, 0, 0.5);
  transition: transform 260ms cubic-bezier(0.3, 0.7, 0.3, 1), box-shadow 260ms;
}
.key-swatch { position: absolute; left: 0; right: 0; top: 0; height: 10px; }
.key-fill {
  position: absolute; inset: auto 0 0 0; height: 100%; transform-origin: bottom; transform: scaleY(0);
  background: linear-gradient(180deg, var(--brass-hi), var(--brass) 50%, var(--brass-deep));
  transition: transform 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.key-pct {
  position: absolute; left: 0; right: 0; bottom: 0.7rem; text-align: center;
  font: 400 1.25rem/1 var(--serif); color: var(--ink);
}
.key-name { font-size: 0.84rem; color: var(--text-dim); text-align: center; overflow-wrap: anywhere; line-height: 1.2; }
.key.win .key-body {
  transform: translateY(5px);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15), 0 0 0 #000, 0 0 34px rgba(242, 203, 126, 0.42);
}
.key.win .key-name { color: var(--brass-hi); font-weight: 600; }

.console-row { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(0, 2fr); gap: clamp(1.5rem, 4vw, 3.5rem); align-items: start; }

/* tempo dial (score questions) */
.dial svg { width: 100%; max-width: 280px; height: auto; display: block; overflow: visible; }
.dial .needle { transition: transform 560ms cubic-bezier(0.25, 0.9, 0.25, 1.05); transform-origin: 100px 104px; }
.dial-caption { margin: 0.2rem 0 0; display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.dial-caption b { font: italic 400 1.9rem/1 var(--serif); color: var(--brass-hi); }
.dial-caption span { color: var(--text-dim); font-size: 0.9rem; }

/* organ stops (yes/no questions) */
.stops { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 1.2rem 0.9rem; }
.stop { display: grid; justify-items: center; gap: 0.45rem; text-align: center; }
.knob {
  position: relative; width: 70px; height: 70px; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #FFFBF2, var(--ivory) 45%, var(--ivory-shade) 100%);
  box-shadow: 0 0 0 5px #2A161C, 0 0 0 6px rgba(241, 233, 218, 0.15), inset 0 -4px 8px rgba(0, 0, 0, 0.18);
  display: grid; place-items: center; transition: transform 320ms cubic-bezier(0.3, 0.7, 0.3, 1), box-shadow 320ms;
}
.knob::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; border: 1px solid rgba(42, 24, 18, 0.22); }
.knob b { font: 400 1.15rem/1 var(--serif); color: var(--ink); position: relative; z-index: 1; }
.stop-label { font-size: 0.86rem; line-height: 1.25; color: var(--text-dim); max-width: 16ch; }
.stop.on .knob {
  transform: scale(1.1);
  box-shadow: 0 0 0 5px var(--brass), 0 0 0 6px var(--brass-hi), 0 10px 22px rgba(0, 0, 0, 0.55), 0 0 30px rgba(242, 203, 126, 0.4), inset 0 -4px 8px rgba(0, 0, 0, 0.18);
}
.stop.on .stop-label { color: var(--text); }

/* ---------- compose ---------- */
.field-label { display: block; color: var(--text-dim); font-size: 0.86rem; font-weight: 500; margin: 0 0 0.45rem; }
input, select, .q-item textarea {
  width: 100%; background: rgba(18, 7, 9, 0.7); border: 1px solid var(--line-strong); border-radius: 10px; padding: 0.7rem 0.9rem;
}
input:focus, select:focus, .q-item textarea:focus { border-color: var(--brass); outline: none; box-shadow: 0 0 0 3px rgba(212, 162, 76, 0.18); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 2.4rem; }
.compose { display: grid; grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); gap: clamp(1.5rem, 4vw, 3.5rem); align-items: start; }
.pack-row { margin-bottom: 1.1rem; max-width: 22rem; }
.q-head { display: flex; align-items: center; justify-content: space-between; margin-top: 1.5rem; }
.q-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }
.q-item { display: grid; grid-template-columns: 9.5rem 1fr auto; gap: 0.5rem; align-items: start; padding: 0.6rem; border-radius: 12px; background: rgba(18, 7, 9, 0.45); border: 1px solid var(--line); }
.q-item input, .q-item select, .q-item textarea { padding: 0.5rem 0.7rem; font-size: 0.92rem; resize: vertical; }
.q-item .q-opts { grid-column: 2 / 3; }
.q-item .remove { background: none; border: 0; color: var(--text-faint); cursor: pointer; padding: 0.45rem 0.5rem; font-size: 1.15rem; line-height: 1; }
.q-item .remove:hover { color: var(--danger); }
.compose-right { display: grid; gap: 1.8rem; }
.compose-right .key-body { height: 140px; }
.compose-right .register-name, .compose-right .q-title { font: italic 1.4rem/1.15 var(--serif); color: var(--text); margin: 0 0 0.8rem; }
.compose-right .stops { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.empty { color: var(--text-faint); margin: 0; font: italic 1.35rem/1.35 var(--serif); max-width: 26rem; }

/* ---------- sight-read ---------- */
.sight { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: clamp(1.5rem, 4vw, 3.5rem); align-items: start; }
.sight .instrument { margin-top: 0; }
.frame {
  position: relative; aspect-ratio: 4 / 3; border-radius: 6px; overflow: hidden; cursor: pointer; display: grid; place-items: center;
  background: repeating-linear-gradient(180deg, transparent 0 calc(2.2rem - 1px), rgba(42, 24, 18, 0.16) calc(2.2rem - 1px) 2.2rem), var(--ivory);
  box-shadow: 0 0 0 10px #1A0B10, 0 0 0 11px rgba(212, 162, 76, 0.45), 0 30px 60px -25px rgba(0, 0, 0, 0.8);
}
.frame.over { box-shadow: 0 0 0 10px #1A0B10, 0 0 0 12px var(--brass-hi); }
.frame video, .frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.frame video { transform: scaleX(-1); }
.frame-copy { display: grid; gap: 0.25rem; text-align: center; color: var(--ink-soft); }
.frame-copy strong { color: var(--ink); font: italic 400 2rem/1 var(--serif); }
.frame.has-media .frame-copy { display: none; }
.sight .register .key-body { height: 150px; }
.add-look-row { display: flex; gap: 0.6rem; }
.add-look-row input { flex: 1; }

/* ---------- controls ---------- */
.primary { background: var(--brass); color: var(--ebony); border: 0; border-radius: 999px; padding: 0.7rem 1.4rem; font-weight: 600; cursor: pointer; }
.primary:hover { background: var(--brass-hi); }
.primary:disabled { opacity: 0.55; cursor: progress; }
.ghost { background: transparent; border: 1px solid var(--line-strong); border-radius: 999px; padding: 0.5rem 1rem; cursor: pointer; color: var(--text-dim); }
.ghost:hover { border-color: var(--brass); color: var(--text); }
.run-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.1rem; }
.status { color: var(--text-faint); font-size: 0.88rem; }
.status.error { color: var(--danger); }
.hint { color: var(--text-faint); font-size: 0.88rem; margin: 0.9rem 0 0; max-width: 34rem; }

.foot { max-width: 1240px; margin: 0 auto; padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 3rem; color: var(--text-faint); font-size: 0.86rem; }
.foot p { max-width: 48rem; margin: 0; border-top: 1px solid var(--line); padding-top: 1.2rem; }

@media (max-width: 900px) {
  .compose, .sight, .console-row { grid-template-columns: 1fr; }
  .manual { flex-direction: column; gap: 1.4rem; }
  .ebony-gap { display: none; }
  .key-body { height: 150px; }
  .q-item { grid-template-columns: 1fr auto; }
  .q-item select { grid-column: 1 / 2; }
  .q-item .q-opts { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .key-body, .sight .register .key-body { height: 118px; }
  .keys { gap: 3px; }
  .key-name { font-size: 0.7rem; overflow-wrap: normal; word-break: normal; hyphens: auto; }
  .programme { gap: 1.1rem; margin-top: 1.4rem; }
  .programme em { font-size: 1.55rem; }
  .programme span { font-size: 0.74rem; }
  .manual { padding: 12px 10px 14px; }
  .key-pct { font-size: 1rem; }
  .sound span { display: none; }
  .stops { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .key-fill, .key-body, .dial .needle, .knob { transition: none; }
}


/* ---------- shared: page title, how-it-works drawer, Inside Clef inspector ---------- */
.page-head { margin: 0 0 1.2rem; display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-lede { margin: 0; color: var(--text-dim); max-width: 46rem; font-size: 1.02rem; }
.how-btn { float: right; margin: 0.2rem 0 0.8rem 1rem; }
dialog.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(560px, 100vw); padding: 0; border: 0;
  background: linear-gradient(180deg, #1B0A11, var(--ebony)); color: var(--text); box-shadow: -30px 0 60px rgba(0, 0, 0, 0.6);
}
dialog.drawer::backdrop { background: rgba(10, 4, 6, 0.6); backdrop-filter: blur(2px); }
.drawer-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.3rem; background: #1B0A11; border-bottom: 1px solid var(--line); z-index: 1; }
.drawer-title { margin: 0; font: italic 1.7rem/1 var(--serif); color: var(--brass-hi); }
.drawer-body { padding: 1rem 1.3rem 2rem; font-size: 0.95rem; line-height: 1.6; }
.drawer-body h3 { font: italic 400 1.35rem/1.2 var(--serif); color: var(--text); margin: 1.4rem 0 0.4rem; }
.drawer-body p, .drawer-body li { color: var(--text-dim); }
.drawer-body code, .drawer-body pre { font: 0.8rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.drawer-body pre { background: #0C0406; padding: 0.8rem; border-radius: 8px; overflow: auto; color: var(--text-dim); white-space: pre-wrap; word-break: break-word; }

.inspector, .mind {
  display: grid; gap: 0.9rem; padding: 1.1rem 1.1rem 1.2rem; border-radius: 14px;
  background: linear-gradient(180deg, #1B0A11, var(--ebony)); box-shadow: inset 0 0 0 1px var(--line);
}
.insp-head, .mind-head { display: flex; align-items: center; justify-content: space-between; }
.insp-title, .mind-title { margin: 0; font: italic 1.6rem/1 var(--serif); color: var(--brass-hi); }
.insp-mode, .mind-mode { font-size: 0.78rem; color: var(--signal); border: 1px solid rgba(158, 194, 255, 0.4); border-radius: 999px; padding: 0.1rem 0.6rem; }
.insp-mode.frozen, .mind-mode.frozen { color: var(--brass-hi); border-color: var(--brass); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; counter-reset: step; }
.step { counter-increment: step; position: relative; padding-left: 2.1rem; }
.step::before {
  content: counter(step); position: absolute; left: 0; top: -0.05rem; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  display: grid; place-items: center; font: italic 1rem/1 var(--serif); color: var(--ebony); background: var(--brass);
}
.step-title { margin: 0 0 0.5rem; font-weight: 600; font-size: 0.92rem; }
.facts { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.fact { display: inline-grid; padding: 0.3rem 0.55rem; border-radius: 8px; background: rgba(241, 233, 218, 0.06); border: 1px solid var(--line); font-size: 0.86rem; color: var(--text); line-height: 1.3; }
.fact small { font-size: 0.68rem; color: var(--text-faint); }
.fact.wide { flex-basis: 100%; }
.fact.muted, .muted { color: var(--text-faint); }
.verdict { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem; color: var(--text-dim); font-size: 0.9rem; }
.verdict b { font: italic 400 1.9rem/1 var(--serif); color: var(--ivory); }
.ok-text { color: var(--brass-hi); }
.bad-text { color: var(--danger); }
.beatbar { height: 8px; border-radius: 99px; background: rgba(241, 233, 218, 0.1); margin-top: 0.7rem; overflow: hidden; }
.beatbar i { display: block; height: 100%; width: 0; background: var(--signal); border-radius: 99px; transition: width 200ms; }
.beatbar i.over { background: var(--danger); }
.beatbar-caption { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--text-faint); }
.raw summary { cursor: pointer; color: var(--text-dim); font-size: 0.86rem; }
.raw pre { max-height: 260px; overflow: auto; margin: 0.6rem 0 0; padding: 0.7rem; border-radius: 8px; background: #0C0406; color: var(--text-dim); font-size: 0.72rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
@media (max-width: 520px) {
  .programme { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem 1.2rem; overflow: visible; }
  .programme a { white-space: normal; }
}
