:root {
  color-scheme: dark;
  --body: #1a1b1e; --panel: #0c0d0f; --panel-edge: #2e3036;
  --key: #2a2c31; --key-hi: #3a3d44; --key-low: #0e0f11; --key-lit: #33302d;
  --text: #e8e6e1; --muted: #9a9da6; --tick: #6b6e76;
  --led: #ff8a3d; --led-soft: #ffb085; --led-dim: #3a2a1e; --led-off: #45372c; --unit: #b07a56;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-family: system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, button { touch-action: manipulation; }
html { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body { margin: 0; background: var(--body); color: var(--text); }
main { width: min(100%, 440px); min-height: 100dvh; margin: auto; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 18px; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, .knob:focus-visible { outline: 3px solid var(--led-soft); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.unit { font: 500 .75rem var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--unit); }

.display { background: var(--panel); border-radius: 14px; box-shadow: inset 0 2px 8px rgba(0,0,0,.6), 0 0 0 1px var(--panel-edge); padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.display-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
#beats { display: flex; flex-wrap: wrap; gap: 12px; min-height: 12px; }
.version { font: .65rem var(--mono); color: #8a8d96; letter-spacing: .04em; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--led-dim); }
.dot.active { background: var(--led); box-shadow: 0 0 0 3px rgba(255,138,61,.25); }
.readouts { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.readout { display: flex; align-items: baseline; gap: 8px; }
#tempo-value { font: 700 clamp(3.2rem, 17vw, 4.25rem)/.9 var(--mono); letter-spacing: -.04em; color: var(--led); font-variant-numeric: tabular-nums; }
.swing-readout { flex-direction: column; align-items: flex-end; gap: 2px; }
#swing-value { font: 700 1.4rem var(--mono); color: var(--led); white-space: nowrap; }

.key { border: 0; border-radius: 12px; background: var(--key); box-shadow: inset 0 1px 0 var(--key-hi), 0 2px 0 var(--key-low); }
.key:active { transform: translateY(1px); box-shadow: inset 0 1px 0 var(--key-hi), 0 1px 0 var(--key-low); }

.tempo { display: flex; align-items: center; justify-content: space-between; }
.tempo .key { width: 64px; height: 64px; font-size: 1.6rem; font-weight: 600; }
.knob-wrap { position: relative; width: 156px; height: 156px; }
.knob-ticks { position: absolute; inset: 0; color: #55585f; }
.knob { position: absolute; inset: 22px; border-radius: 50%; background: var(--key); border: 2px solid var(--key-low); touch-action: none; cursor: grab; }
.knob:active { cursor: grabbing; }
.knob-cap { position: absolute; inset: 8px; border-radius: 50%; background: #303238; }
.knob-mark { position: absolute; left: 50%; top: 4px; width: 4px; height: 18px; border-radius: 2px; background: var(--led); transform: translateX(-50%); }
.knob-label { position: absolute; left: 0; right: 0; bottom: -4px; text-align: center; font-size: .7rem; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }

.swing { display: flex; flex-direction: column; gap: 6px; }
#swing { --fill: 0%; appearance: none; -webkit-appearance: none; width: 100%; height: 52px; margin: 0; background: transparent; touch-action: none; cursor: pointer; }
#swing:focus-visible { outline-offset: 0; }
#swing::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: linear-gradient(var(--led), var(--led)) 0 50% / var(--fill) 2px no-repeat, var(--panel); box-shadow: inset 0 1px 3px rgba(0,0,0,.8); }
#swing::-moz-range-track { height: 8px; border-radius: 4px; background: linear-gradient(var(--led), var(--led)) 0 50% / var(--fill) 2px no-repeat, var(--panel); box-shadow: inset 0 1px 3px rgba(0,0,0,.8); }
#swing::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 40px; margin-top: -16px; border-radius: 6px; background: linear-gradient(var(--led), var(--led)) center / 16px 2px no-repeat, var(--key-hi); box-shadow: inset 0 1px 0 #4c5058, 0 3px 6px rgba(0,0,0,.5); }
#swing::-moz-range-thumb { width: 28px; height: 40px; border: 0; border-radius: 6px; background: linear-gradient(var(--led), var(--led)) center / 16px 2px no-repeat, var(--key-hi); box-shadow: inset 0 1px 0 #4c5058, 0 3px 6px rgba(0,0,0,.5); }
.detents { position: relative; height: 8px; margin: -10px 14px 4px; }
.detents span { position: absolute; top: 0; width: 2px; height: 8px; background: var(--tick); }
.detents span:nth-child(1) { left: 0; }
.detents span:nth-child(2) { left: 66.6667%; transform: translateX(-50%); }
.detents span:nth-child(3) { right: 0; }
.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.presets button { height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; font-size: .85rem; font-weight: 600; text-transform: capitalize; }

.bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stepper { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; height: 56px; border-radius: 10px; background: var(--panel); box-shadow: 0 0 0 1px var(--panel-edge); }
.stepper button { width: 56px; height: 56px; border: 0; background: transparent; font-size: 1.4rem; font-weight: 600; }
.stepper-value { display: flex; align-items: baseline; gap: 10px; }
#beats-value { font: 700 1.4rem var(--mono); color: var(--led); }
.toggle { height: 56px; display: flex; align-items: center; justify-content: center; gap: 8px; font-size: .85rem; font-weight: 600; }

.presets button::before, .toggle::before { content: ''; border-radius: 2px; background: var(--led-off); }
.presets button::before { width: 18px; height: 4px; }
.toggle::before { width: 7px; height: 7px; border-radius: 50%; }
.key[aria-pressed=true] { background: var(--key-lit); box-shadow: inset 0 2px 4px rgba(0,0,0,.5); color: var(--led-soft); }
.key[aria-pressed=true]::before { background: var(--led); box-shadow: 0 0 6px rgba(255,138,61,.7); }

#status { text-align: center; color: var(--led-soft); font-size: .85rem; }
#status:empty { display: none; }
.play { margin-top: auto; height: 76px; flex-shrink: 0; border: 0; border-radius: 14px; background: var(--led); color: var(--body); box-shadow: inset 0 1px 0 var(--led-soft), 0 3px 0 #9a4a1a; font-size: 1.25rem; font-weight: 700; letter-spacing: .04em; display: flex; align-items: center; justify-content: center; gap: 12px; }
.play::before { content: ''; width: 16px; height: 16px; background: currentColor; clip-path: polygon(10% 0, 100% 50%, 10% 100%); }
.play[aria-pressed=true]::before { clip-path: none; border-radius: 2px; }
.play:active { transform: translateY(2px); box-shadow: inset 0 1px 0 var(--led-soft), 0 1px 0 #9a4a1a; }

@media (max-width: 350px) { main { padding-inline: 12px; } .knob-wrap { width: 136px; height: 136px; } .tempo .key { width: 56px; height: 56px; } }
@media (prefers-reduced-motion: no-preference) { .dot { transition: background-color 200ms, box-shadow 200ms; } .dot.active { transition: none; } }
@media (max-height: 760px) {
  main { gap: 12px; padding-top: 14px; }
  .display { padding: 12px 16px; gap: 10px; }
  #tempo-value { font-size: 3rem; }
  .knob-wrap { width: 124px; height: 124px; }
  .knob { inset: 17px; }
  .knob-label { bottom: -8px; }
  .tempo .key { width: 56px; height: 56px; }
  #swing { height: 44px; }
  .presets button { height: 52px; gap: 6px; }
  .stepper, .stepper button, .toggle { height: 48px; }
  .play { height: 64px; }
}
