:root {
  --bg: #fffaf0;
  --card: #ffffff;
  --fg: #2b2622;
  --muted: #6b6159;
  --accent: #6741d9;
  --accent-ink: #ffffff;
  --rule: #efdcbc;
  --white-key: #fffdf8;
  --white-key-down: #e5dbff;
  --black-key: #2b2622;
  --black-key-down: #6741d9;
  --lit: #ffd43b;
  --rec: #e03131;
  --kick: #d9480f;
  --snare: #1971c2;
  --hat: #2b8a3e;
  --clap: #c2255c;
  --kofi: #ff5e5b;
  --max: 52rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --card: #2c2722;
    --fg: #f3ede4;
    --muted: #bdb2a6;
    --accent: #b197fc;
    --accent-ink: #1b1916;
    --rule: #3d362e;
    --white-key: #ece6dc;
    --white-key-down: #b197fc;
    --black-key: #0f0d0b;
    --black-key-down: #845ef7;
  }
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

a { color: var(--accent); }
.wrap { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 16px; }
.gc-pixel { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
button { font: inherit; color: inherit; }
.noscript { background: var(--card); border: 2px solid var(--rule); border-radius: 1rem; padding: 1rem; }

/* Header */
.site-header { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--rule); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding-top: 0.55rem; padding-bottom: 0.55rem; }
.brand { margin: 0; display: flex; align-items: center; gap: 0.55rem; font-weight: 800; font-size: 1.2rem; line-height: 1.1; }
.brand small { display: block; font-weight: 500; font-size: 0.78rem; color: var(--muted); }
/* A tiny CSS piano for a logo */
.logo {
  display: inline-flex; justify-content: space-around; align-items: flex-start;
  width: 2em; height: 1.4em; padding: 0 0.3em; border-radius: 0.35em;
  background: var(--white-key); border: 0.13em solid var(--accent); flex: none;
}
.logo span { width: 0.25em; height: 0.7em; background: var(--black-key); border-radius: 0 0 0.08em 0.08em; }

.kofi {
  display: inline-flex; align-items: center; gap: 0.35em; background: var(--kofi); color: #fff;
  font-weight: 700; text-decoration: none; padding: 0.45em 1em; border-radius: 999px; min-height: 40px;
}
.kofi-small { font-size: 0.9rem; padding: 0.3em 0.85em; min-height: 36px; }

/* Panels */
.studio { flex: 1; padding-top: 0.75rem; padding-bottom: 1rem; display: flex; flex-direction: column; gap: 0.85rem; }
.panel { background: var(--card); border: 2px solid var(--rule); border-radius: 1.1rem; padding: 0.7rem 0.8rem 0.8rem; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin-bottom: 0.6rem; }
.panel h2 { margin: 0; font-size: 1.05rem; font-weight: 800; }
.panel h2 small { font-weight: 500; color: var(--muted); font-size: 0.8rem; }
.hint { margin: 0; color: var(--muted); font-size: 0.82rem; }

/* Piano / synth switch and octave buttons */
.seg { display: inline-flex; border: 2px solid var(--accent); border-radius: 999px; overflow: hidden; }
.seg-btn { border: 0; background: transparent; padding: 0.25em 0.9em; min-height: 36px; font-weight: 700; cursor: pointer; }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.octave { display: inline-flex; align-items: center; gap: 0.35rem; margin-left: auto; }
.octave-label { min-width: 4.2em; text-align: center; font-size: 0.85rem; color: var(--muted); }
.round {
  width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--accent); background: transparent;
  font-weight: 800; font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.round:disabled { opacity: 0.35; cursor: default; }

/* The keyboard: 4 grid columns per white key, black keys sit across the line between two whites. */
.keyboard {
  display: grid; grid-auto-columns: minmax(0, 1fr); grid-template-rows: 60% 40%;
  height: 11.5rem; position: relative;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.key {
  grid-row: 1 / 3; border: 0; margin: 0; padding: 0 0 0.45rem; cursor: pointer;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 0.1rem;
  -webkit-tap-highlight-color: transparent; transition: background-color 0.08s, transform 0.08s;
}
.key.white {
  background: var(--white-key); color: #2b2622; border: 1.5px solid #c9bfb2; border-radius: 0 0 0.55rem 0.55rem;
  box-shadow: inset 0 -0.35rem 0 rgba(0, 0, 0, 0.08);
}
.key.black {
  grid-row: 1 / 2; z-index: 2; background: var(--black-key); color: #f3ede4;
  border-radius: 0 0 0.4rem 0.4rem; box-shadow: inset 0 -0.25rem 0 rgba(255, 255, 255, 0.12);
}
.key-note { font-weight: 800; font-size: 1rem; }
.key-code { font-size: 0.7rem; opacity: 0.6; font-family: ui-monospace, Menlo, monospace; text-transform: uppercase; }
.key.white.down { background: var(--white-key-down); transform: translateY(2px); box-shadow: none; }
.key.black.down { background: var(--black-key-down); transform: translateY(2px); }
.key.loop-lit:not(.down) { background: var(--lit); color: #2b2622; }
.now-playing { margin: 0.5rem 0 0; min-height: 1.5em; color: var(--muted); font-size: 0.9rem; text-align: center; }

/* Drums */
.drums { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.6rem; }
.drum { display: flex; flex-direction: column; gap: 0.55rem; }
.pad {
  aspect-ratio: 1 / 0.85; border: 0; border-radius: 1rem; color: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; box-shadow: inset 0 -0.35rem 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.06s, filter 0.06s;
}
.pad-kick { background: var(--kick); }
.pad-snare { background: var(--snare); }
.pad-hat { background: var(--hat); }
.pad-clap { background: var(--clap); }
.pad-says { font-weight: 800; font-size: 1.15rem; line-height: 1.1; }
.pad-name { font-size: 0.8rem; font-weight: 700; opacity: 0.92; }
.pad .key-code { opacity: 0.75; }
.pad.hit { transform: scale(0.94); filter: brightness(1.25); box-shadow: none; }

/* Faders: a track with a fill; the value comes in as --v (0..1) */
.fader {
  --v: 0.8; position: relative; height: 30px; cursor: pointer; touch-action: none; border-radius: 999px;
}
.fader::before {
  content: ""; position: absolute; left: 0; right: 0; top: 11px; height: 8px; border-radius: 999px; background: var(--rule);
}
.fader-fill {
  position: absolute; left: 0; top: 11px; height: 8px; width: calc(13px + var(--v) * (100% - 26px)); border-radius: 999px;
  background: var(--accent);
}
.fader-fill::after {
  content: ""; position: absolute; right: -13px; top: 50%; width: 26px; height: 26px; margin-top: -13px;
  border-radius: 50%; background: var(--white-key); border: 3px solid var(--accent);
}

/* Knobs: a dial whose dot turns from -135deg to +135deg */
.knobs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.6rem; }
.knob-wrap { display: flex; flex-direction: column; align-items: center; text-align: center; }
.knob {
  --v: 0.5; position: relative; width: 64px; height: 64px; border-radius: 50%; cursor: grab; touch-action: none;
  background: conic-gradient(from -135deg, var(--accent) calc(var(--v) * 270deg), var(--rule) 0 270deg, transparent 0);
}
.knob::before {
  content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--white-key);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.knob-dot {
  position: absolute; inset: 7px; border-radius: 50%; transform: rotate(calc(-135deg + var(--v) * 270deg));
}
.knob-dot::after {
  content: ""; position: absolute; left: 50%; top: 5px; width: 8px; height: 14px; margin-left: -4px;
  border-radius: 4px; background: var(--accent);
}
.knob-name { margin-top: 0.3rem; font-weight: 800; font-size: 0.88rem; line-height: 1.2; }
.knob-word { color: var(--muted); font-size: 0.8rem; }

/* Tips */
.tips h2 { margin-bottom: 0.4rem; }
.tips details { border-top: 1px solid var(--rule); padding: 0.35rem 0; }
.tips summary { cursor: pointer; font-weight: 700; padding: 0.25rem 0; }
.tips p { margin: 0.25rem 0 0.4rem; color: var(--fg); font-size: 0.95rem; }

.site-footer { text-align: center; color: var(--muted); font-size: 0.85rem; padding-bottom: 0.5rem; }
.site-footer p { margin: 0.4rem 0; }
.site-footer .kofi { margin-left: 0.25rem; font-size: 0.85rem; }

/* Loop recorder: always at the bottom, so Record is one thumb away */
.loop-bar {
  position: sticky; bottom: 0; z-index: 5; background: var(--bg); border-top: 1px solid var(--rule);
  padding: 0.45rem 0 calc(0.55rem + env(safe-area-inset-bottom));
}
.loop-top { display: flex; align-items: center; gap: 0.6rem; }
.beats { display: flex; gap: 0.3rem; flex: 1; }
.beat { flex: 1; height: 10px; border-radius: 999px; background: var(--rule); transition: background-color 0.05s; }
.beat.bar { box-shadow: inset 0 0 0 2px var(--muted); }
.beat.on { background: var(--accent); }
.tidy {
  border: 2px solid var(--rule); background: transparent; border-radius: 999px; padding: 0.1em 0.75em;
  font-size: 0.8rem; min-height: 32px; cursor: pointer; color: var(--muted);
}
.tidy[aria-pressed="true"] { border-color: var(--accent); color: var(--fg); }
.tidy[aria-pressed="true"]::before { content: "✓ "; color: var(--accent); }
.loop-status { margin: 0.25rem 0 0.35rem; font-size: 0.85rem; color: var(--muted); min-height: 1.3em; }
.loop-buttons { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.45rem; }
.loop-btn {
  min-height: 46px; border-radius: 0.9rem; border: 2px solid var(--accent); background: var(--card);
  font-weight: 800; cursor: pointer; padding: 0 0.2rem; white-space: nowrap;
}
.loop-btn:disabled { opacity: 0.4; cursor: default; }
.loop-btn.rec span { color: var(--rec); }
.loop-btn.rec.live { background: var(--rec); border-color: var(--rec); color: #fff; }
.loop-btn.rec.live span { color: #fff; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

/* Phones: one octave (C to C) so keys stay finger-sized. */
@media (max-width: 34rem) {
  .key.extra { display: none; }
  .keyboard { height: 10.5rem; }
  .knob { width: 56px; height: 56px; }
  .pad-says { font-size: 1rem; }
  .drums, .knobs { gap: 0.45rem; }
  .octave { margin-left: 0; }
  .panel-head .hint { width: 100%; }
  .loop-btn { font-size: 0.92rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .key.down, .pad.hit { transform: none; }
}
