:root {
  --bg: #f6f2ec;
  --panel: #fffdf9;
  --ink: #26201b;
  --muted: #6d645c;
  --line: #e2d9ce;
  --wood: #8a4b32;
  --wood-hi: #b8673f;
  --accent: #a4532f;
  --hit: #e8a15f;
  --meter: #5b8a5a;
  --hot: #c0442b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171412;
    --panel: #211d1a;
    --ink: #eee6dc;
    --muted: #a79c91;
    --line: #3a332d;
    --wood: #9c5638;
    --wood-hi: #c67749;
    --accent: #e08a5a;
    --hit: #f0b470;
    --meter: #7fb07d;
    --hot: #e2614a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171412; --panel: #211d1a; --ink: #eee6dc; --muted: #a79c91; --line: #3a332d;
  --wood: #9c5638; --wood-hi: #c67749; --accent: #e08a5a; --hit: #f0b470; --meter: #7fb07d; --hot: #e2614a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.wrap { max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; }
header h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: 0.01em; }
.lede { margin: 0 0 16px; color: var(--muted); max-width: 60ch; }
h2 { font-size: 14px; margin: 0 0 6px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
h3 { font-size: 15px; margin: 0; }
.small { font-size: 12.5px; color: var(--muted); margin: 4px 0 8px; }

.instrument { position: relative; }
.gate {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 12px;
  padding-top: 110px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(2px);
  border-radius: 10px;
  text-align: center;
}
.gate[hidden] { display: none; }
.start {
  font: inherit; font-size: 17px; font-weight: 600;
  padding: 14px 26px; border-radius: 999px; border: 0;
  background: var(--accent); color: #fff; cursor: pointer;
}
.start:disabled { opacity: 0.6; cursor: progress; }
.progress { width: min(320px, 80%); height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.keys {
  display: grid; grid-template-columns: repeat(15, 1fr); gap: 5px;
  height: 210px; align-items: center;
  padding: 10px 8px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  touch-action: none;              /* a touch on the keys plays; scrolling and pinching happen elsewhere */
  -webkit-user-select: none; user-select: none;
}
.rotate { display: none; }
@media (pointer: coarse) and (orientation: portrait) { .rotate { display: block; margin: -6px 2px 10px; } }
@media (pointer: coarse) { select { font-size: 16px; } }
.gate a { color: var(--accent); margin-left: 6px; }
.key {
  position: relative; height: var(--h); min-height: 90px; width: 100%;
  border: 0; padding: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  color: #fff; font: inherit; touch-action: none; -webkit-tap-highlight-color: transparent;
}
.key .bar {
  position: absolute; inset: 0; border-radius: 6px;
  background: linear-gradient(180deg, var(--wood-hi), var(--wood) 70%);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.06s;
}
.key:hover .bar { filter: brightness(1.06); }
.key:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.key.hit .bar { animation: hit 0.35s ease-out; }
@keyframes hit { 0% { background: var(--hit); transform: scaleY(0.97); } 100% { transform: none; } }
.key span, .key kbd { position: relative; z-index: 1; line-height: 1.15; }
.key .name { font-weight: 650; font-size: 13px; }
.key .hz { font-size: 10px; opacity: 0.85; }
.key .mark { font-size: 10px; font-weight: 700; opacity: 0.9; min-height: 12px; }
.key kbd {
  font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; margin: 3px 0 6px;
  padding: 0 4px; border-radius: 3px; background: rgba(0, 0, 0, 0.22);
}
.legend { margin: 6px 2px 10px; }
.mark-b { font-weight: 700; color: var(--accent); }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.play { margin-bottom: 2px; }
.grow { flex: 1 1 220px; }
.btn, select {
  font: inherit; font-size: 14px; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer;
}
.btn:hover, select:hover { border-color: var(--accent); }
.status { min-height: 20px; }
#midi-status { margin-left: 8px; }

.field { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.field input[type="range"] { flex: 1; min-width: 80px; }
output { font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; font-size: 13px; color: var(--muted); }
input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; margin: 2px 0 6px; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin-top: 12px;
}
.big .big-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; }
.big .big-head output { color: var(--ink); text-align: center; }
.big input[type="range"] { width: 100%; height: 28px; margin: 6px 0 0; }

.layer-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.layer { border-left: 3px solid var(--line); padding-left: 10px; }
.layer .small { margin: 0 0 6px; }
.ms { display: flex; gap: 12px; font-size: 13.5px; margin-bottom: 4px; }
.ms label { display: inline-flex; align-items: center; gap: 4px; }

.extras { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 12px; }
.extras .panel .row { margin: 4px 0 8px; }
.extras select { margin-bottom: 8px; }
.meter { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 10px; }
.meter div { height: 100%; width: 0; background: var(--meter); }
.meter div.hot { background: var(--hot); }

.about { margin-top: 18px; color: var(--muted); font-size: 14px; }
.about summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.about p { max-width: 70ch; }

body:not(.ready) .instrument > :not(.gate) { filter: grayscale(0.4); opacity: 0.55; pointer-events: none; }

@media (max-width: 760px) {
  .keys { gap: 3px; height: 190px; padding: 8px 5px; }
  .key .hz, .key kbd { display: none; }
  .key .name { font-size: 11px; writing-mode: vertical-rl; transform: rotate(180deg); margin-bottom: 6px; }
  .layer-grid { grid-template-columns: repeat(2, 1fr); }
  .extras { grid-template-columns: 1fr; }
  .gate { padding-top: 80px; }
}
@media (max-width: 420px) {
  .keys { height: 170px; }
  .layer-grid { grid-template-columns: 1fr; }
}
