:root {
  --ink: #141413;
  --slate: #3d3d3a;
  --muted: #73726c;
  --ivory: #faf9f5;
  --paper: #f0eee6;
  --oat: #e3dacc;
  --line: #dedbd0;
  --clay: #d97757;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; scrollbar-width: none; }
*::-webkit-scrollbar { display: none; }
html, body { height: 100%; }
html, .presets, textarea, .stage-wrap { scroll-behavior: smooth; overscroll-behavior: contain; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  display: flex;
  flex-direction: column;
}

button { font: inherit; color: inherit; cursor: pointer; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--ivory);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 30px; height: 30px; flex: none; }
.word { font: 600 22px/1 var(--serif); letter-spacing: -0.01em; }
.tag { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exports { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1.5px solid var(--ink); background: var(--ink); color: var(--ivory);
  border-radius: 999px; padding: 7px 14px; font-weight: 550;
  transition: transform .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--oat); }
.btn.small { padding: 4px 11px; font-size: 13px; }
.btn:focus-visible, .round:focus-visible, input:focus-visible, textarea:focus-visible, .preset:focus-visible {
  outline: 2px solid var(--clay); outline-offset: 2px;
}

.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) minmax(320px, 420px);
}

h2 { font: 600 13px/1 var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; }

.brand { color: inherit; text-decoration: none; }
.i { display: inline-flex; width: 16px; height: 16px; flex: none; }
.i svg { width: 100%; height: 100%; }
.gh-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 10px;
  border: 1.5px solid var(--ink); border-radius: 999px; text-decoration: none; color: var(--ink);
  font: 600 13px var(--sans); transition: background .15s;
}
.gh-btn:hover { background: var(--oat); }
.gh-btn .count { display: none; align-items: center; gap: 3px; }
.gh-btn .count .i { width: 12px; height: 12px; color: var(--clay); }
.gh-btn.has-stats .count { display: inline-flex; }
.presets { padding: 16px 12px; border-right: 1px solid var(--line); overflow: auto; }
.filter {
  width: 100%; border: 1.5px solid var(--line); background: var(--ivory); border-radius: 999px;
  padding: 7px 12px; font: inherit; margin-bottom: 14px;
}
.cat { margin-bottom: 14px; }
.cat h2 { margin: 6px 6px 8px; }
.presets ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.knobs .check { flex: 0 0 auto; }
.knobs .check input { accent-color: var(--ink); }
.stage.checker { background: repeating-conic-gradient(#e9e6dc 0 25%, #f6f4ee 0 50%) 0 0 / 28px 28px; }
.share form { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 0; }
.share h3 { margin: 0; font: 600 20px var(--serif); }
.share-body { padding: 8px 22px 24px; display: grid; gap: 14px; }
.share label { display: grid; gap: 6px; font-weight: 600; }
.share small { font-weight: 400; color: var(--muted); }
.share .row { display: flex; gap: 8px; }
.share input { flex: 1; min-width: 0; border: 1.5px solid var(--line); border-radius: 10px; padding: 7px 10px; font: 12px var(--mono); background: var(--paper); }
.hint { margin: 0; color: var(--muted); }
.preset {
  width: 100%; display: flex; gap: 10px; align-items: center; text-align: left;
  border: 1.5px solid transparent; background: transparent; border-radius: 14px; padding: 6px;
}
.preset:hover { background: var(--ivory); }
.preset[aria-current="true"] { background: var(--ivory); border-color: var(--ink); }
.preset img { width: 54px; height: 54px; border-radius: 10px; flex: none; background: var(--ivory); }
.preset b { display: block; font-weight: 600; }
.preset small { display: block; color: var(--muted); font-size: 12px; line-height: 1.3; }

.stage-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 22px; min-width: 0; overflow: auto;
}
.stage {
  width: min(100%, 62vh); aspect-ratio: 1 / 1;
  border-radius: 22px; overflow: hidden; background: var(--ivory);
  box-shadow: 0 1px 0 var(--line), 0 18px 40px -24px rgba(20, 20, 19, .35);
}
.stage canvas { width: 100%; height: 100%; display: block; }

.transport { width: min(100%, 62vh); display: flex; align-items: center; gap: 12px; }
.round {
  width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--ink);
  display: grid; place-items: center; flex: none;
}
.round svg { width: 18px; height: 18px; fill: var(--ivory); }
.round .i-play { display: none; }
.round.paused .i-play { display: block; }
.round.paused .i-pause { display: none; }
.time { font: 13px var(--mono); color: var(--slate); min-width: 52px; text-align: right; }

input[type="range"] { flex: 1; accent-color: var(--ink); min-width: 0; }
.knobs {
  width: min(100%, 62vh); display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center;
  color: var(--slate); font-size: 13px;
}
.knobs label { display: flex; align-items: center; gap: 8px; flex: 1 1 140px; }
.stats { margin: 0; color: var(--muted); font: 12px var(--mono); }

.editor { display: flex; flex-direction: column; border-left: 1px solid var(--line); padding: 18px; min-height: 0; background: var(--ivory); }
.editor-head { display: flex; justify-content: space-between; align-items: center; }
.editor-head h2 { margin: 0; }
.editor-actions { display: flex; gap: 6px; }
textarea {
  flex: 1; min-height: 240px; margin-top: 12px; resize: none;
  border: 1.5px solid var(--line); border-radius: 14px; padding: 14px;
  background: var(--paper); color: var(--ink);
  font: 12.5px/1.55 var(--mono); tab-size: 2;
}
.error {
  margin: 10px 0 0; padding: 10px 12px; border-radius: 10px;
  background: #f6dcd2; color: #8a2f14; font-size: 13px;
}

dialog {
  border: none; border-radius: 18px; padding: 0; width: min(760px, 92vw); max-height: 86vh;
  background: var(--ivory); color: var(--ink); box-shadow: 0 30px 80px -30px rgba(20,20,19,.5);
}
dialog::backdrop { background: rgba(20, 20, 19, .35); }
dialog form { position: sticky; top: 0; display: flex; justify-content: flex-end; padding: 12px; background: var(--ivory); }
dialog pre { margin: 0; padding: 0 26px 26px; white-space: pre-wrap; font: 13px/1.55 var(--mono); }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .presets { border-right: none; border-bottom: 1px solid var(--line); }
  .presets { max-height: 280px; }
  .stage, .transport, .knobs { width: min(100%, 560px); }
  .editor { border-left: none; border-top: 1px solid var(--line); }
  textarea { min-height: 360px; }
  .tag { display: none; }
}
@media (max-width: 520px) {
  .top { flex-direction: column; align-items: flex-start; padding: 12px 16px; }
  .stage-wrap, .editor { padding: 16px; }
}
