:root {
  --bg: #14110f;
  --surface: #1f1b18;
  --surface-2: #2a2521;
  --line: #3a332d;
  --text: #f3ece4;
  --muted: #a89d91;
  --accent: #ff9f1c;
  --accent-ink: #1b1206;
  --accent-soft: rgba(255, 159, 28, 0.18);
  --hit: #e8dccf;
  --ghost: #7a6d61;
  --rec: #ff4d4d;
  --playhead: rgba(255, 159, 28, 0.22);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f1ea;
    --surface: #ffffff;
    --surface-2: #f0e9e0;
    --line: #e0d6ca;
    --text: #1d1915;
    --muted: #6f655b;
    --accent: #d97500;
    --accent-ink: #ffffff;
    --accent-soft: rgba(217, 117, 0, 0.14);
    --hit: #3b332c;
    --ghost: #b6a99b;
    --playhead: rgba(217, 117, 0, 0.16);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }

.topbar, main, .footer {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  padding-bottom: 8px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 34px; height: 34px; color: var(--accent); }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: 0.2px; }
.byline { margin: 0; color: var(--muted); font-size: 12px; }

main { display: grid; gap: 14px; padding-bottom: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

h2 { margin: 0; font-size: 17px; }
h3 { margin: 18px 0 6px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; }

.hint { margin: 4px 0 12px; color: var(--muted); font-size: 13px; }

.two-col { display: grid; gap: 14px; }
@media (min-width: 760px) { .two-col { grid-template-columns: 1fr 1fr; } }

/* ---------- Transport ---------- */
.transport { display: grid; gap: 14px; justify-items: center; text-align: center; }

.beats { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; min-height: 34px; }
.beat {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.06s, background 0.06s;
}
.beat[data-level="2"] { border-color: var(--accent); }
.beat[data-level="2"]::after {
  content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--accent);
}
.beat[data-level="0"] { opacity: 0.35; border-style: dashed; }
.beat.on { background: var(--accent-soft); transform: scale(1.18); }
.beat.on[data-level="2"] { background: var(--accent); }
.beats.counting .beat.on { background: var(--rec); border-color: var(--rec); }

.tempo-row { display: flex; align-items: center; gap: 16px; }
.round-btn {
  width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 24px; cursor: pointer; line-height: 1;
}
.round-btn:active { transform: scale(0.94); }

.bpm-display { display: grid; justify-items: center; }
.bpm-display input[type="number"] {
  width: 3.7ch;
  padding: 0;
  min-height: 0;
  font-size: 64px; font-weight: 700; line-height: 1;
  text-align: center;
  background: transparent; border: none; outline: none;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.bpm-display input::-webkit-outer-spin-button,
.bpm-display input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.bpm-label { color: var(--muted); font-size: 13px; letter-spacing: 1px; }
.tempo-name { color: var(--accent); margin-left: 4px; letter-spacing: 0; }

.transport .slider { width: min(520px, 100%); }

.transport-row { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; }

.play-btn {
  width: 76px; height: 76px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  box-shadow: 0 6px 24px var(--accent-soft);
}
.play-btn svg { width: 34px; height: 34px; }
.play-btn .i-stop { display: none; }
.play-btn.playing .i-play { display: none; }
.play-btn.playing .i-stop { display: block; }
.play-btn:active { transform: scale(0.96); }

.now-playing { color: var(--muted); font-size: 13px; min-height: 1.4em; }
.now-playing strong { color: var(--text); }

/* ---------- Controls ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  min-height: 40px;
}
.btn:hover { border-color: var(--muted); }
.btn.ghost { background: transparent; }
.btn.flash { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 700;
}

select, input[type="number"] {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 40px;
  max-width: 100%;
}
input[type="number"] { width: 100%; }

.select-wrap select { min-width: 92px; }
.select-wrap.compact select { min-width: 0; }

.field { display: grid; gap: 4px; margin-bottom: 10px; min-width: 0; }
.field > span { color: var(--muted); font-size: 13px; }
.field > select { width: 100%; min-width: 0; }
.field.grow { flex: 1 1 160px; }
.field.check { display: flex; align-items: center; gap: 8px; }
.field.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.field.check > span { color: var(--text); font-size: 14px; }
.field-row { display: flex; flex-wrap: wrap; gap: 0 14px; align-items: end; }
.field-row > .field { flex: 1 1 120px; }
.field-row.trainer > .field { flex: 1 1 80px; }

.slider { accent-color: var(--accent); width: 100%; height: 28px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span {
  width: 40px; height: 24px; border-radius: 12px;
  background: var(--line); position: relative; transition: background 0.15s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: var(--text);
  transition: transform 0.15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--accent-ink); }
.switch.rec input:checked + span { background: var(--rec); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch em { font-style: normal; font-size: 13px; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.toolbar .spacer { flex: 1; }

/* ---------- Step grid ---------- */
.grid-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; -webkit-overflow-scrolling: touch; }
.grid { display: grid; gap: 6px; width: max-content; min-width: 100%; }

.track {
  display: grid;
  grid-template-columns: 210px auto;
  gap: 8px;
  align-items: center;
}
.track-head { display: flex; gap: 4px; align-items: center; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.track-head select { flex: 1; min-width: 0; padding: 4px 6px; min-height: 34px; font-size: 13px; }
.mini {
  width: 28px; height: 34px; padding: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); cursor: pointer; font-size: 12px; font-weight: 700;
  color: var(--muted);
}
.mini.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.mini.mute.active { background: var(--muted); color: var(--surface); border-color: var(--muted); }

.steps { display: flex; gap: 10px; }
.beat-group { display: flex; gap: 3px; }
.cell {
  width: 30px; height: 34px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  padding: 0;
  position: relative;
}
.beat-group .cell:first-child { border-color: var(--muted); }
.cell[data-v="1"] { background: var(--ghost); border-color: var(--ghost); }
.cell[data-v="2"] { background: var(--hit); border-color: var(--hit); }
.cell[data-v="3"] { background: var(--accent); border-color: var(--accent); }
.cell[data-v="3"]::after {
  content: ""; position: absolute; left: 50%; top: 4px; width: 6px; height: 6px;
  margin-left: -3px; border-radius: 50%; background: var(--accent-ink);
}
.cell.now { box-shadow: 0 0 0 2px var(--accent) inset; }
.cell.now[data-v="2"], .cell.now[data-v="3"] { filter: brightness(1.25); }
.track.muted .cell { opacity: 0.4; }

/* ---------- Pads ---------- */
.pads { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.pad {
  aspect-ratio: 1.3;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  display: grid; place-items: center; align-content: center; gap: 2px;
  touch-action: manipulation;
  user-select: none;
  transition: transform 0.05s, background 0.08s;
}
.pad b { font-size: 14px; }
.pad small { color: var(--muted); font-size: 12px; }
.pad.hit { background: var(--accent); color: var(--accent-ink); transform: scale(0.96); }
.pad.hit small { color: var(--accent-ink); }

/* ---------- Samples ---------- */
.dropzone {
  display: grid; gap: 4px; justify-items: center; text-align: center;
  border: 2px dashed var(--line); border-radius: 12px;
  padding: 18px 12px; cursor: pointer; margin-bottom: 12px;
}
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone span { color: var(--muted); font-size: 13px; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

.recorder { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.rec-btn { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--rec); flex: none; }
.rec-btn.recording { background: var(--rec); border-color: var(--rec); color: #fff; }
.rec-btn.recording .rec-dot { background: #fff; border-radius: 2px; animation: rec-pulse 1s infinite; }
@keyframes rec-pulse { 50% { opacity: 0.35; } }
.meter { flex: 1 1 80px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.05s linear; }
.meter span.hot { background: var(--rec); }
.rec-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; min-width: 6ch; }
.hint.small { font-size: 12px; margin: 8px 0 12px; }

.sample-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.sample-list li {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: 10px; padding: 6px 8px;
}
.sample-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sample-list .empty { color: var(--muted); background: none; padding: 0; font-size: 13px; }

/* ---------- Misc ---------- */
.footer { color: var(--muted); font-size: 12px; padding-bottom: 24px; }

dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; max-width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
dialog dt { font-weight: 700; }
dialog dd { margin: 0; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 520px) {
  .bpm-display input[type="number"] { font-size: 54px; }
  .track { grid-template-columns: 158px auto; }
  .mini { width: 24px; }
  .track-head { gap: 3px; }
  .cell { width: 26px; height: 32px; }
  .steps { gap: 7px; }
  .beat-group { gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.recorder[hidden] { display: none; }
.kit-status { color: var(--accent); font-size: 12px; margin-left: 4px; }
.footer a { color: var(--muted); }

/* ---------- Footer links and info pages (privacy, support) ---------- */
.footer-links { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.footer-links a { display: inline-block; padding: 6px 0; }

a.brand { color: inherit; text-decoration: none; }
.brand-name { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: 0.2px; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; color: inherit; white-space: nowrap; }

.doc-page .topbar, .doc-page main, .doc-page .footer { max-width: 760px; }
.doc-page main { padding-bottom: 20px; }
.doc-page .footer a { text-decoration: underline; text-underline-offset: 2px; }

.doc-title { margin: 12px 0 0; font-size: 28px; line-height: 1.2; }
.doc-meta { margin: 0; color: var(--muted); font-size: 13px; }

.prose h2 { margin: 0 0 10px; }
.prose h3 { margin-top: 16px; }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0 0 12px; padding-left: 20px; }
.prose li { margin-bottom: 6px; }
.prose > :last-child, .prose li > :last-child { margin-bottom: 0; }
.prose a, .callout a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.prose a:hover { color: var(--accent); }
.prose a:focus-visible, .footer a:focus-visible, a.btn:focus-visible, a.brand:focus-visible, .jump a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
.prose dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 12px; }
.prose dt { font-weight: 700; }
.prose dd { margin: 0; color: var(--muted); }
.prose kbd {
  font: inherit; font-size: 13px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 6px;
}
.prose [id] { scroll-margin-top: 16px; }

.callout {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 12px 14px;
}
.callout p { margin: 0; }

.jump { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.jump a {
  display: inline-flex; align-items: center; min-height: 40px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--text); text-decoration: none; font-size: 14px;
}
.jump a:hover { border-color: var(--muted); }

@media (max-width: 520px) {
  .doc-title { font-size: 24px; }
  .doc-page .topbar { gap: 12px; }
}
