:root {
  --bone: 239 230 214;   /* gut string */
  --brass: 224 174 85;   /* cymbal */
  --ember: 240 80 60;    /* recording */
  --night: 9 12 22;      /* dark stage */
  --serif: 'Newsreader', 'Iowan Old Style', Georgia, serif;
}

* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 38%, #171d31, rgb(var(--night)) 70%);
  color: rgb(var(--bone));
  font: italic 400 17px/1.4 var(--serif);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- stage ---------- */

#cam {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  filter: saturate(.3) brightness(.5) contrast(1.15);
  opacity: 0;
  transition: opacity 1.2s;
}
body[data-mode="camera"] #cam { opacity: 1; }

/* darkens the floor so the loop stays readable over any room */
body::before {
  content: '';
  position: fixed; inset: 0;
  background: linear-gradient(to top, rgb(var(--night) / .78), transparent 26%);
  pointer-events: none;
}

#stage {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  cursor: none;
  touch-action: none;
}

.side {
  position: fixed; top: 22px;
  font-size: 1.1rem;
  pointer-events: none;
  text-shadow: 0 1px 12px rgb(var(--night) / .9);
  opacity: 0;
  transition: opacity 1.2s .4s;
}
.side-drums { left: 28px; color: rgb(var(--brass)); }
.side-strings { right: 28px; text-align: right; }
body.playing .side { opacity: .85; }

.hint {
  display: block;
  color: rgb(var(--bone));
  font-size: .95rem;
  opacity: .8;
  transition: opacity 1s;
}
body.made .hint { opacity: 0; }

#notice {
  position: fixed; top: 22px; left: 50%;
  transform: translateX(-50%);
  max-width: min(34rem, 60vw);
  padding: 10px 18px;
  font-style: normal;
  font-size: .95rem;
  text-align: center;
  background: rgb(var(--night) / .8);
  border: 1px solid rgb(var(--bone) / .25);
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .6s;
}
#notice.show { opacity: 1; }

/* ---------- deck: tempo, loop, transport ---------- */

.deck {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 24px;
  padding: 0 22px 16px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s .4s;
}
body.playing .deck { opacity: 1; }
body.playing .deck > * { pointer-events: auto; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
button:focus-visible {
  outline: 1px solid rgb(var(--bone) / .85);
  outline-offset: 2px;
}

.tempo, .transport { display: flex; align-items: center; height: 48px; }
.tempo { justify-self: start; }
.transport { justify-self: end; gap: 2px; }

.tempo button, .transport button {
  min-width: 44px; min-height: 44px;
  padding: 0 12px;
  border-radius: 22px;
  opacity: .72;
  transition: opacity .15s, background .15s;
}
.tempo button:hover, .transport button:hover { opacity: 1; }
.tempo button.pressed, .transport button.pressed { opacity: 1; background: rgb(var(--bone) / .14); }
.tempo output { min-width: 4.6em; text-align: center; font-variant-numeric: tabular-nums; }
.tempo button { font-style: normal; font-size: 1.5rem; line-height: 1; }

#rec::before {
  content: '';
  display: inline-block;
  width: 9px; height: 9px;
  margin-right: 8px;
  border: 1.5px solid rgb(var(--ember));
  border-radius: 50%;
}
#rec[aria-pressed="true"] { opacity: 1; color: rgb(var(--ember)); }
#rec[aria-pressed="true"]::before {
  background: rgb(var(--ember));
  box-shadow: 0 0 12px rgb(var(--ember) / .8);
}

.steps { display: flex; height: 88px; }

.step {
  width: 24px;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  justify-items: center;
  gap: 4px;
  padding: 0;
  border-radius: 4px;
}
.step:nth-child(4n+1):not(:first-child) { margin-left: 14px; }
.step.pressed { background: rgb(var(--bone) / .14); }

.step .up, .step .down { display: flex; gap: 3px; align-items: center; }
.step .up { flex-direction: column-reverse; align-self: end; }
.step .down { flex-direction: column; align-self: start; }

.step .tick {
  width: 1.5px; height: 8px;
  background: rgb(var(--bone) / .34);
  transition: height .09s, background .09s;
}
.step:nth-child(4n+1) .tick { height: 14px; background: rgb(var(--bone) / .6); }
.step.on .tick { height: 24px; background: rgb(var(--bone)); }
body.recording .step.on .tick { background: rgb(var(--ember)); }

.step .d {              /* a drum hit */
  width: 7px; height: 7px;
  border: 1.5px solid rgb(var(--brass));
  border-radius: 50%;
}
.step .s {              /* a plucked string */
  width: 11px; height: 1.5px;
  background: rgb(var(--bone));
}

/* ---------- intro ---------- */

#intro {
  position: fixed; inset: 0;
  display: grid;
  align-content: center;
  justify-items: start;
  padding: 8vh 9vw;
  background: rgb(var(--night) / .74);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  transition: opacity .9s, visibility .9s;
}
body.playing #intro { opacity: 0; visibility: hidden; }

#intro h1 {
  font-weight: 300;
  font-size: clamp(3.4rem, 10vw, 8.5rem);
  line-height: .95;
  letter-spacing: -.02em;
}
#intro p {
  max-width: 36ch;
  margin-top: 1.6rem;
  font-style: normal;
  font-size: 1.25rem;
  line-height: 1.45;
}
#intro .go { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 26px; margin-top: 2.2rem; }
#intro .primary {
  min-height: 52px;
  padding: 0 28px;
  font-size: 1.2rem;
  border: 1px solid rgb(var(--bone) / .8);
  border-radius: 26px;
  transition: background .2s, color .2s;
}
#intro .primary:hover:not(:disabled) { background: rgb(var(--bone)); color: rgb(var(--night)); }
#intro .primary:disabled { opacity: .6; cursor: progress; }
#intro .quiet {
  min-height: 44px;
  font-size: 1.1rem;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
  opacity: .8;
}
#intro .quiet:hover { opacity: 1; }
#intro .fine { font-size: .95rem; opacity: .6; max-width: 46ch; }

@media (max-width: 860px) {
  .deck { grid-template-columns: 1fr 1fr; gap: 0 12px; }
  .steps { grid-column: 1 / -1; justify-self: center; order: -1; height: 72px; }
  .step { width: 19px; }
  .step:nth-child(4n+1):not(:first-child) { margin-left: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01s !important; }
}
