/* Rhythm: a dark, stage-like look with amber (the beat), a cooler teal for subdivisions, and
   coral for beat one. Phones get the section tabs at the bottom. */
:root {
  --bg: #14121c;
  --panel: #1e1b2a;
  --raised: #2a2638;
  --ink: #f2eefb;
  --muted: #a39cb8;
  --line: #34304a;
  --beat: #ffb547;
  --one: #ff6b5b;
  --sub: #4fd1c5;
  --radius: 16px;
  --font: "Avenir Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- frame ---------- */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 800; font-size: 1.2rem; letter-spacing: 0.02em; }
.brand-mark { display: inline-flex; align-items: flex-end; gap: 3px; height: 22px; }
.brand-mark i { display: block; width: 5px; border-radius: 3px; background: var(--beat); }
.brand-mark i:nth-child(1) { height: 60%; }
.brand-mark i:nth-child(2) { height: 100%; background: var(--one); }
.brand-mark i:nth-child(3) { height: 75%; background: var(--sub); }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 600; }
.tabs a:hover { color: var(--ink); background: var(--raised); }
.tabs a.active { color: var(--beat); background: var(--raised); }
.tabs svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.view { max-width: 760px; margin: 0 auto; padding: 16px 16px 40px; outline: none; }
@media (max-width: 640px) {
  .top { justify-content: center; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; justify-content: space-around; gap: 0; padding: 6px 4px max(6px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
  .tabs a { flex-direction: column; gap: 2px; padding: 4px 10px; font-size: 0.7rem; }
  .tabs a.active { background: none; }
  .view { padding-bottom: 96px; }
}

/* ---------- shared ---------- */
.panel { margin-bottom: 14px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.label { margin: 16px 0 8px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.panel > .label:first-child { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 8px 14px; border: 1.5px solid var(--line); border-radius: 999px; background: var(--raised); font-weight: 600; font-size: 0.92rem; }
.chips button.is-on { border-color: var(--beat); color: var(--beat); }
.chips .danger { color: var(--one); }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; margin-top: 18px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--beat); }
.center-switch { display: flex; justify-content: center; margin-top: 14px; }
.volume { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 600; }
input[type="range"] { accent-color: var(--beat); }
.volume input { width: 140px; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 18px; border: 1.5px solid var(--line); border-radius: 999px; background: var(--raised); font-weight: 700; }
.button.primary { border-color: var(--beat); background: var(--beat); color: #1d1405; }
.button:disabled { opacity: 0.4; cursor: default; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

/* Tempo: − [number] +, with a slider underneath. */
.tempo { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px 14px; }
.tempo input[type="range"] { grid-column: 1 / -1; width: 100%; }
.round { width: 52px; height: 52px; border: 1.5px solid var(--line); border-radius: 50%; background: var(--raised); font-size: 1.6rem; line-height: 1; touch-action: manipulation; user-select: none; }
.round:active { border-color: var(--beat); }
.bpm { display: flex; flex-direction: column; align-items: center; }
.bpm input { width: 3.6ch; padding: 0; border: 0; background: none; color: var(--ink); font: 800 3.4rem/1 var(--font); text-align: center; -moz-appearance: textfield; }
.bpm input::-webkit-inner-spin-button { -webkit-appearance: none; }
.bpm input:focus { outline: none; color: var(--beat); }
.bpm span { color: var(--muted); font-size: 0.85rem; font-weight: 600; letter-spacing: 0.06em; }
.bpm em { font-style: normal; color: var(--beat); }

/* Play: a big round button; amber with a square while playing. */
.play { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; height: 64px; margin-top: 18px; border: 0; border-radius: 999px; background: var(--beat); color: #1d1405; font-size: 1.15rem; font-weight: 800; letter-spacing: 0.04em; }
.play.is-on { background: var(--one); color: #fff; }
.play-icon { width: 0; height: 0; border-left: 16px solid currentColor; border-top: 10px solid transparent; border-bottom: 10px solid transparent; }
.play.is-on .play-icon { width: 14px; height: 14px; border: 0; background: currentColor; border-radius: 2px; }
.play.small { width: auto; height: 52px; margin: 0; padding: 0 22px; }

/* ---------- metronome ---------- */
.pulse { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 170px; margin-bottom: 18px; border-radius: 14px; background: var(--raised); overflow: hidden; }
.pulse::before { content: ''; position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(circle at center, var(--flash, var(--beat)) 0%, transparent 70%); opacity: 0; }
.pulse.flash::before { --flash: var(--beat); animation: pulse 0.35s ease-out; }
.pulse.flash-one::before { --flash: var(--one); animation: pulse 0.45s ease-out; }
.pulse.flash-sub::before { --flash: var(--sub); animation: pulse-sub 0.2s ease-out; }
@keyframes pulse { from { opacity: 0.55; } to { opacity: 0; } }
@keyframes pulse-sub { from { opacity: 0.22; } to { opacity: 0; } }
.beats { position: relative; display: grid; grid-template-columns: repeat(var(--count), minmax(0, 1fr)); gap: 10px; width: min(100%, calc(var(--count) * 64px)); padding: 0 16px; }
.beat { aspect-ratio: 1; max-width: 48px; justify-self: center; width: 100%; border-radius: 50%; border: 2px solid var(--line); background: var(--panel); transition: transform 0.08s; }
.beat.is-one { border-color: color-mix(in srgb, var(--one) 60%, var(--line)); }
.beat.is-lit { background: var(--beat); border-color: var(--beat); box-shadow: 0 0 18px var(--beat); transform: scale(1.12); }
.beat.is-one.is-lit { background: var(--one); border-color: var(--one); box-shadow: 0 0 22px var(--one); }
.meter-big { position: relative; margin: 0; color: var(--muted); font-weight: 800; font-size: 1.1rem; letter-spacing: 0.1em; }
.custom-meter { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 12px; }
.stepper { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; }
.stepper button { width: 36px; height: 36px; border: 1.5px solid var(--line); border-radius: 50%; background: var(--raised); font-size: 1.2rem; line-height: 1; }
.stepper b { min-width: 1.6ch; color: var(--ink); font-size: 1.3rem; text-align: center; }
.stepper select { height: 36px; padding: 0 10px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--raised); color: var(--ink); font: 700 1.05rem var(--font); }
.over { color: var(--muted); font-size: 1.4rem; }

/* ---------- tap tempo ---------- */
.tap-pad { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; min-height: 300px; border: 2px dashed var(--line); border-radius: 20px; background: var(--raised); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.tap-pad.hit { animation: hit 0.25s ease-out; }
@keyframes hit { from { background: color-mix(in srgb, var(--beat) 35%, var(--raised)); border-color: var(--beat); transform: scale(0.985); } to { background: var(--raised); } }
.tap-bpm { font-size: 5.5rem; font-weight: 800; line-height: 1; }
.tap-unit { color: var(--muted); font-weight: 700; letter-spacing: 0.12em; }
.tap-mark { margin-top: 10px; color: var(--beat); font-weight: 600; }
.steady { height: 6px; margin: 14px 0 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.steady span { display: block; height: 100%; background: var(--sub); transition: width 0.2s; }

/* ---------- drum machine ---------- */
.drum-top { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 16px; }
.drum-top .tempo { grid-template-columns: auto auto auto 1fr; }
.drum-top .tempo input[type="range"] { grid-column: auto; }
.drum-top .bpm input { font-size: 2.2rem; }
@media (max-width: 640px) {
  .drum-top { grid-template-columns: 1fr; }
  .drum-top .tempo { grid-template-columns: auto 1fr auto; }
  .drum-top .tempo input[type="range"] { grid-column: 1 / -1; }
  .play.small { width: 100%; }
}
.grid-scroll { margin-top: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.grid { display: grid; grid-template-columns: 100px repeat(var(--steps), minmax(20px, 1fr)); gap: 5px 4px; min-width: calc(100px + var(--steps) * 24px); }
/* The sound names stay put while a long bar scrolls sideways. */
.track { position: sticky; left: 0; z-index: 1; display: flex; align-items: center; gap: 6px; padding-right: 4px; background: var(--panel); }
.track-name { flex: 1; min-width: 0; padding: 0; border: 0; background: none; text-align: left; font-weight: 700; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mute { flex: none; width: 14px; height: 14px; padding: 0; border: 2px solid var(--sub); border-radius: 50%; background: var(--sub); }
.mute[aria-pressed="true"] { background: none; border-color: var(--muted); }
.track.is-muted .track-name { color: var(--muted); text-decoration: line-through; }
.step { height: 36px; min-width: 0; padding: 0; border: 1.5px solid var(--line); border-radius: 6px; background: var(--raised); }
.step.on-beat { border-color: #4a4566; }
.step.is-on { background: var(--beat); border-color: var(--beat); }
.step.is-now { box-shadow: 0 0 0 2px var(--ink) inset; }
.step.is-on.is-now { background: #fff1d6; box-shadow: 0 0 14px var(--beat); }
.count { text-align: center; font-size: 0.7rem; color: var(--muted); }
.count.on-beat { color: var(--ink); font-weight: 700; }

/* Kit and layer choices: cards with a name and a line about them. */
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.choice { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--raised); text-align: left; }
.choice b { font-size: 0.95rem; }
.choice span { color: var(--muted); font-size: 0.78rem; }
.choice.is-on { border-color: var(--beat); }
.choice.is-on b { color: var(--beat); }
.chips button[aria-pressed="false"] { color: var(--muted); }

/* Bar tabs above the grid (loops of 2 bars or more). */
.bar-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 16px; }
.bar-tabs[hidden] { display: none; }
.bar-tabs .chips button { padding: 6px 12px; font-size: 0.85rem; }
.link { padding: 0; border: 0; background: none; color: var(--beat); font-weight: 700; font-size: 0.9rem; }
.field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; }
.field select { height: 36px; padding: 0 10px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--raised); color: var(--ink); font: 600 0.95rem var(--font); }
