:root {
  --night: #120d2b;
  --card: #18122f;
  --line: #33295a;
  --cell: #241c44;
  --cell-hover: #31275c;
  --saffron: #f4a62a;
  --ember: #e2663c;
  --cream: #fbeed2;
  --ink: #17112e;
  --muted: #a99fc9;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--night); color: var(--cream); font: 13px/1.4 "JetBrains Mono", ui-monospace, Menlo, monospace; }
button, select, input { font: inherit; color: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--cream); outline-offset: 2px; }
a { color: var(--saffron); }

.wrap { max-width: 1040px; margin: 0 auto; padding: 20px 16px 32px; }
.top { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.title { display: flex; align-items: center; gap: 12px; }
.mini { width: 58px; height: 76px; flex: none; }
.mini svg { width: 100%; height: 100%; display: block; overflow: visible; }
h1 { margin: 0; font: 700 30px/1 Fraunces, Georgia, serif; }
.title p { margin: 6px 0 0; color: var(--muted); min-height: 1.4em; }
h2 { margin: 0; font: 700 16px/1 Fraunces, Georgia, serif; color: var(--saffron); }

.transport { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.transport > button, .seg button { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; cursor: pointer; }
.transport > button:hover, .seg button:hover { border-color: var(--muted); }
.transport .primary { background: var(--saffron); border-color: var(--saffron); color: var(--ink); font-weight: 500; min-width: 84px; }
.transport .primary:hover { background: #ffbd4d; }
.seg { display: inline-flex; }
.seg button:first-child { border-radius: 999px 0 0 999px; }
.seg button:last-child { border-radius: 0 999px 999px 0; border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--cream); color: var(--ink); border-color: var(--cream); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.row + .row { margin-top: 10px; }
.label { color: var(--muted); width: 84px; flex: none; }
.label + .chips { flex: 1; min-width: 0; }
#templates { flex: 0 1 auto; }
.label.tempo { width: auto; margin-left: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; cursor: pointer; }
.chip:hover { border-color: var(--muted); }
.chip.dice { border-style: dashed; border-color: var(--saffron); color: var(--saffron); }
.chip.dice:hover { background: #f4a62a1a; }
.chip[aria-pressed="true"] { background: var(--saffron); border-color: var(--saffron); color: var(--ink); font-weight: 500; }
select { background: var(--cell); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 140px; height: 18px; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; background: var(--line); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: var(--saffron); }
input[type=range]::-moz-range-track { height: 3px; background: var(--line); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--saffron); }
output { min-width: 64px; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 18px 0 10px; }
.head:first-child { margin-top: 0; }
.sub { color: var(--muted); margin-right: auto; margin-left: 4px; }

.chords { display: grid; grid-template-columns: 48px repeat(4, 1fr); gap: 4px; }
.chords::before { content: ""; }
.chords select { width: 100%; text-align: center; font-weight: 500; }

.grid { display: grid; gap: 3px; user-select: none; -webkit-user-select: none; touch-action: none; }
.melody { grid-template-columns: 48px repeat(32, minmax(0, 1fr)); }
.beat { grid-template-columns: 48px repeat(16, minmax(0, 1fr)); }
.rowname { color: var(--muted); font-size: 11.5px; display: flex; align-items: center; }
.rowname.root { color: var(--cream); font-weight: 500; }
.cell { height: 24px; border: 0; padding: 0; border-radius: 5px; background: var(--cell); cursor: pointer; }
.beat .cell { height: 30px; }
.cell:hover { background: var(--cell-hover); }
.cell.bar { margin-left: 6px; }
.cell.beatline { margin-left: 4px; }
.cell[aria-pressed="true"] { background: var(--saffron); }
.beat .cell[aria-pressed="true"] { background: var(--ember); }
.melody .cell.joined { border-top-left-radius: 0; border-bottom-left-radius: 0; box-shadow: -3px 0 0 var(--saffron); }
.melody .cell.joined.bar { box-shadow: -9px 0 0 var(--saffron); }
.melody .cell.continues { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.melody .cell.joined.now { box-shadow: -3px 0 0 var(--saffron), inset 0 0 0 2px var(--cream); }
.cell.now { box-shadow: inset 0 0 0 2px var(--cream); }

.extras { margin-top: 18px; gap: 10px 22px; }
.knob { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.foot { color: var(--muted); text-align: center; margin: 18px 0 0; }

@media (max-width: 640px) {
  .grid { gap: 2px; }
  .melody, .beat, .chords { grid-template-columns: 38px repeat(var(--cols), minmax(0, 1fr)); }
  .melody { --cols: 32; } .beat { --cols: 16; } .chords { --cols: 4; }
  .cell { border-radius: 3px; height: 22px; }
  .cell.bar { margin-left: 3px; } .cell.beatline { margin-left: 2px; }
  .melody .cell.joined { box-shadow: -2px 0 0 var(--saffron); } .melody .cell.joined.bar { box-shadow: -5px 0 0 var(--saffron); }
  .label { width: 100%; }
  .label.tempo { margin-left: 0; }
  .transport { width: 100%; }
}
