:root {
  color-scheme: dark;
  --ground: #151514;
  --surface: #1d1d19;
  --inset: #191915;
  --border: #3d382e;
  --text: #f1e9d8;
  --muted: #b3a58f;
  --gold: #efc482;
  --gold-text: #24190d;
  --blue: #9ec7e8;
  --serif: Georgia, "Times New Roman", serif;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--ground);
  color: var(--text);
  font-size: 15px;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }

h1, h2, p { margin: 0; }
button, select, input { font: inherit; }
button, select {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #26241e;
  color: var(--text);
}
button { padding: 0 12px; cursor: pointer; }
button:hover:enabled { background: #363026; border-color: #726044; }
button:disabled { opacity: 0.45; cursor: default; }
select {
  width: 100%;
  padding: 0 23px 0 8px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 52%, calc(100% - 8px) 52%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
input[type="range"] {
  margin: 0;
  min-height: 26px;
  cursor: pointer;
  accent-color: var(--gold);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.shell {
  max-width: 1520px;
  margin: 0 auto;
  padding: 0 clamp(16px, 3.4vw, 54px);
}
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 23px 0 22px;
}
h1 {
  white-space: nowrap;
  font: 400 clamp(34px, 3.5vw, 52px)/1 var(--serif);
  letter-spacing: -0.055em;
}
h1 em { color: var(--gold); font-weight: 400; }
.modes {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #191915;
}
.modes button {
  min-height: 36px;
  padding-inline: 15px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
  font-weight: 550;
  font-size: 0.9rem;
}
.modes button[aria-pressed="true"] {
  border-color: #6e5637;
  background: #352a1b;
  color: var(--gold);
}
.volume {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
}
.volume input { width: 88px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(294px, 28vw, 346px);
  gap: 18px;
  align-items: start;
}
.stage, .controls {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
}
.stage {
  overflow: hidden;
  background: radial-gradient(ellipse at 49% 42%, #30261b 0%, #221e17 47%, #191814 79%);
}
.stage-top, .stage-bottom {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  column-gap: 12px;
  padding: 10px 17px;
}
.stage-top { border-bottom: 1px solid #3d382e; background: #1d1b17; }
.stage-bottom { border-top: 1px solid #3d382e; background: #1d1b17; color: var(--muted); font-size: 0.83rem; }
.ring-picker { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.87rem; }
.ring-picker > span { margin-right: 4px; }
.ring-picker button { padding: 0; min-width: 34px; min-height: 34px; font-size: 1.1rem; }
.ring-picker output { min-width: 18px; color: var(--text); text-align: center; font-variant-numeric: tabular-nums; }
.meta { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.8rem; }
.board-viewport { height: clamp(430px, 71vh, 740px); padding: 8px; }
.board { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.tile { cursor: pointer; outline: none; }
.tile polygon {
  fill: #4b3d2b;
  stroke: #7e6849;
  stroke-width: 0.9;
}
.tile .note-label {
  fill: #f3e3c9;
  font-size: 13px;
  font-weight: 630;
  letter-spacing: -0.045em;
  pointer-events: none;
}
.tile.is-dim polygon { fill: #2b251c; stroke: #4f4230; }
.tile.is-dim .note-label { fill: #a3937a; }
.tile.is-match polygon { fill: #684d2d; stroke: #d8a76d; stroke-width: 1.45; }
.tile.is-chord polygon { fill: #334452; stroke: var(--blue); stroke-width: 1.45; }
.tile.is-reflected polygon { fill: #69502e; stroke: var(--gold); stroke-width: 1.45; }
.tile.is-chord.is-reflected polygon { fill: #334452; stroke: var(--gold); stroke-dasharray: 3.5 2; }
.tile.ray-a polygon { fill: #69502e; stroke: var(--gold); stroke-width: 1.6; }
.tile.ray-b polygon { fill: #334e61; stroke: var(--blue); stroke-width: 1.6; }
.tile.is-dim.is-pending polygon { fill: #252118; stroke: #403526; }
.tile.is-dim.is-pending .note-label { fill: #867256; }
.tile.is-recent polygon { fill: #805b32; stroke: #d5a469; }
.tile:hover polygon, .tile:focus-visible polygon { stroke: #fff0ce; stroke-width: 2.3; }
.tile.is-selected polygon { fill: var(--gold); stroke: #ffe1a3; stroke-width: 1.7; }
.tile.is-selected.ray-b polygon { fill: var(--blue); stroke: #d8edff; }
.tile.is-selected .note-label { fill: var(--gold-text); }
.tile:focus-visible polygon { stroke: #fff7e8; stroke-width: 2.8; }
.board[data-dense="true"] .tile.is-dim .note-label,
.board[data-dense="true"] .tile:not(.is-selected, .ray-a, .ray-b, .is-match, .is-chord, .is-reflected, :hover, :focus-visible) .note-label {
  opacity: 0;
}
#board-guides, #board-paths { pointer-events: none; }
.mirror-line { stroke: #ac9674; stroke-width: 1; stroke-dasharray: 2.2 6; opacity: 0.6; }
.center-marker { fill: #211b14; stroke: #ad997b; stroke-width: 1; }
.center-marker.center-playing { fill: #6d5333; stroke: var(--gold); }
.center-note { fill: #e7d4b4; font-size: 13px; font-weight: 630; }
.trace-line { fill: none; stroke: #ffce8c; stroke-width: 1.65; stroke-linecap: round; opacity: 0.72; }
.interval-line { stroke: var(--gold); stroke-width: 2; }
.interval-line.path-b { stroke: var(--blue); }

.controls { background: var(--surface); }
.panel-section { padding: 17px 18px; }
.panel-section + .panel-section, #interval-lines, .cycle-section { border-top: 1px solid var(--border); }
.now-playing { display: flex; align-items: center; min-height: 120px; gap: 16px; }
.note-medallion {
  display: grid;
  place-items: center;
  flex: 0 0 77px;
  height: 67px;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  background: var(--gold);
  color: var(--gold-text);
  font: 400 34px/1 var(--serif);
}
.micro-heading {
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.note-frequency { margin: 5px 0 3px; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: 0.82rem; line-height: 1.5; }
.panel-copy { margin: 9px 0 15px; color: var(--muted); font-size: 0.9rem; line-height: 1.55; }
.section-top { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.panel-section h2:not(.micro-heading) { font: 400 24px/1.15 var(--serif); letter-spacing: -0.02em; }
.small-button { min-height: 34px; color: var(--gold); font-size: 0.83rem; }
.text-button { padding: 0 3px; border-color: transparent; background: transparent; color: var(--gold); font-size: 0.83rem; }
.text-button:hover:enabled { border-color: transparent; background: transparent; color: var(--text); text-decoration: underline; }
.scale-fields { display: grid; grid-template-columns: minmax(69px, 0.55fr) minmax(0, 1fr); gap: 9px; margin: 13px 0; }
.scale-fields label, .path-picker { display: grid; gap: 5px; color: var(--muted); font-size: 0.78rem; }
.note-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
.note-grid button, .note-grid span {
  display: grid;
  place-items: center;
  min-height: 35px;
  padding: 0 1px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.89rem;
}
.note-grid [aria-pressed="true"], .note-grid .is-playing {
  border-color: var(--gold);
  background: #594125;
  color: #fff0cf;
}
.chord-notes { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; min-height: 42px; margin: 5px 0 10px; }
.chord-notes button { min-height: 34px; background: #2c3942; border-color: #50697b; color: #cce6f8; }
.button-row { display: flex; gap: 8px; }
.button-row button { flex: 1; padding-inline: 5px; font-size: 0.86rem; }
.chord-mirror { margin-top: 10px; color: var(--gold); }
.primary { border-color: var(--gold); background: var(--gold); color: var(--gold-text); font-weight: 650; }
.primary:hover:enabled { border-color: #ffdfa7; background: #ffdfa7; color: var(--gold-text); }
.trace-notes span { background: var(--inset); color: var(--muted); }
.full-range { width: 100%; }
.trace-transport { display: grid; grid-template-columns: 44px 1fr 44px; gap: 8px; margin: 10px 0 13px; }
.speed-row { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.83rem; }
.speed-row select { flex: 1; }
.reference-actions { display: flex; justify-content: space-between; flex-wrap: wrap; }
.reference-actions button { min-height: 34px; }
.interval-path { --path-color: var(--gold); }
.interval-path.path-b { --path-color: var(--blue); }
.interval-path h3 { margin: 0; color: var(--path-color); font-size: 0.92rem; font-weight: 650; }
.interval-path .small-button { color: var(--path-color); }
.interval-path .note-grid { margin-top: 11px; }
.interval-path .note-grid button.is-playing { border-color: var(--path-color); color: var(--path-color); }
.cycle-section button { width: 100%; margin-top: 9px; }
#audio-status { padding: 12px 18px; border-top: 1px solid var(--border); color: var(--gold); font-size: 0.85rem; }
.credits { padding: 15px 0 20px; color: var(--muted); font-size: 0.78rem; }
.credits a { color: var(--text); text-decoration-color: #8b7452; text-underline-offset: 3px; }

@media (max-width: 920px) {
  .workspace { gap: 12px; grid-template-columns: minmax(0, 1fr) 282px; }
  .panel-section { padding-inline: 14px; }
  .masthead { gap: 10px; }
  .modes button { padding-inline: 11px; }
  .volume input { width: 65px; }
}
@media (max-width: 690px) {
  .shell { padding-inline: 12px; }
  .masthead { display: grid; grid-template-columns: minmax(0, 1fr) auto; padding: 16px 0 12px; gap: 12px; }
  .modes { grid-row: 2; grid-column: 1 / -1; width: 100%; }
  .modes button { flex: 1; min-height: 39px; padding-inline: 6px; }
  .workspace { display: flex; flex-direction: column; }
  .stage, .controls { width: 100%; }
  .stage-top, .stage-bottom { padding: 8px 10px; }
  .stage-bottom { min-height: 39px; }
  .board-viewport { height: auto; aspect-ratio: 1 / 0.91; padding: 3px; }
  .tile .note-label { font-size: 15px; }
  .now-playing { min-height: 92px; }
  .panel-section { padding: 13px 14px; }
  .note-medallion { flex-basis: 63px; height: 55px; font-size: 28px; }
  select { font-size: 1rem; }
}
@media (max-width: 690px) and (min-height: 680px) {
  .stage { position: sticky; top: 0; z-index: 1; }
  .board-viewport { max-height: 42svh; }
  .controls :is(button, input, select) { scroll-margin-top: 54svh; }
}
