:root {
  --bg: #14121f;
  --bg-2: #221d36;
  --bar: rgba(255, 255, 255, 0.06);
  --text: #f4f1ff;
  --muted: #a8a1c7;
  --accent: #ffd23f;
  --bar-h: 64px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, select {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

/* ---------- Top bar ---------- */

.bar {
  flex: none;
  min-height: var(--bar-h);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bar);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 16px;
}

.follow-only {
  display: none;
}
body[data-mode="follow"] .follow-only {
  display: flex;
}
.bar .follow-only {
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}
body[data-timed="false"] .timed-only {
  display: none;
}

.seg {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 3px;
}
.seg button {
  border: 0;
  background: transparent;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 600;
}
.seg button.on {
  background: var(--text);
  color: var(--bg);
}

select {
  min-height: 46px;
  padding: 0 12px;
  border-radius: 12px;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 600;
  max-width: 260px;
}

.tempo {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 3px;
}
.tempo button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 22px;
}
.tempo span {
  min-width: 52px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.tempo span::after {
  content: " bpm";
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.toggle {
  min-height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-weight: 600;
}
.toggle[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
}

.play {
  margin-left: auto;
  min-height: 46px;
  min-width: 120px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  background: #6bd425;
  color: #10240a;
  font-weight: 800;
  font-size: 18px;
}
.play.stop {
  background: #ff4d6d;
  color: #2a0710;
}

/* ---------- Drum room ---------- */

.room {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  background: radial-gradient(ellipse at 50% 60%, var(--bg-2), var(--bg) 70%);
}

.stage {
  position: relative;
  aspect-ratio: 4 / 3;
  width: min(100%, (100vh - var(--bar-h) - 40px) * 4 / 3);
  width: min(100%, (100dvh - var(--bar-h) - 40px) * 4 / 3);
  touch-action: none;
}

/* The rug under the kit */
.stage::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: 6%;
  bottom: 2%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(120, 90, 200, 0.18), transparent 70%);
}

.piece {
  position: absolute;
  cursor: pointer;
  touch-action: none;
}

.face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

/* Drum seen from above: coloured shell, chrome rim, cream head */
.drum .face {
  background:
    radial-gradient(circle at 42% 38%, #fffdf6 0%, #f1ead8 55%, #ddd3bb 100%);
  box-shadow:
    inset 0 0 0 calc(0.5vmin + 2px) #d9dbe3,
    inset 0 0 0 calc(0.5vmin + 4px) #8e909c,
    0 0 0 calc(0.6vmin + 3px) var(--c),
    0 8px 18px rgba(0, 0, 0, 0.5);
}

/* Cymbal: gold with lathe grooves and a bell */
.cymbal .face {
  background:
    radial-gradient(circle, #8a6a1c 0 5%, #e9c45a 6% 14%, transparent 15%),
    repeating-radial-gradient(circle, #e2b649 0 1.5%, #c99a2e 1.5% 3%),
    #d4a73a;
  box-shadow:
    0 0 0 3px rgba(0, 0, 0, 0.25),
    0 8px 18px rgba(0, 0, 0, 0.5);
}

/* Kick: wide pedal bar */
.kick .face {
  border-radius: 22px;
  background: linear-gradient(180deg, #3a3150, #241e36);
  box-shadow:
    inset 0 0 0 4px var(--c),
    0 8px 18px rgba(0, 0, 0, 0.5);
}
.kick .face::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 22%;
  width: 18%;
  height: 56%;
  transform: translateX(-50%);
  border-radius: 10px;
  background: linear-gradient(180deg, #9a9cab, #5e606d);
}

.label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1.5em;
  text-align: center;
  font-size: clamp(11px, 1.4vmin, 15px);
  font-weight: 700;
  color: var(--c);
  opacity: 0.85;
  pointer-events: none;
}
.drum .label {
  bottom: calc(-1.5em - 0.6vmin - 3px);
}
.kick .label {
  bottom: auto;
  top: 50%;
  transform: translateY(-50%);
  text-align: left;
  padding-left: 6%;
  font-size: clamp(14px, 2.2vmin, 22px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---------- Follow Me effects ---------- */

.piece.lit {
  z-index: 2;
}
.piece.lit .face {
  animation: glow 0.35s ease-in-out infinite alternate;
}
.drum.lit .face {
  box-shadow:
    inset 0 0 0 calc(0.5vmin + 2px) #d9dbe3,
    inset 0 0 0 calc(0.5vmin + 4px) #8e909c,
    0 0 0 calc(0.6vmin + 5px) var(--c),
    0 0 40px 14px var(--c);
}
.cymbal.lit .face {
  box-shadow: 0 0 0 5px var(--c), 0 0 40px 14px var(--c);
}
.kick.lit .face {
  box-shadow: inset 0 0 0 5px var(--c), 0 0 40px 14px var(--c);
}
@keyframes glow {
  from { filter: brightness(1.1); }
  to { filter: brightness(1.45); }
}

.ring, .ripple, .burst {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}
.kick .ring, .kick .ripple, .kick .burst {
  border-radius: 22px;
}
.ring {
  border: calc(0.6vmin + 3px) solid var(--c);
  box-shadow: 0 0 12px var(--c);
  opacity: 0;
  will-change: transform, opacity;
}
.kick .ring {
  transform-origin: center;
}
.ring.waiting {
  opacity: 1;
  animation: beckon 0.8s ease-in-out infinite alternate;
}
@keyframes beckon {
  from { transform: scale(1.35); }
  to { transform: scale(1.08); }
}
.ripple {
  border: 3px solid rgba(255, 255, 255, 0.8);
}
.burst {
  background: radial-gradient(circle, #fff 0%, var(--c) 40%, transparent 70%);
  mix-blend-mode: screen;
}

/* Centre of the kit: count-in, Great!/Good!, stars */
.center {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  width: 28%;
  text-align: center;
  pointer-events: none;
}
.count {
  font-size: clamp(32px, 7vmin, 72px);
  font-weight: 900;
  color: var(--accent);
  min-height: 1.1em;
}
.feedback {
  font-size: clamp(26px, 5vmin, 54px);
  font-weight: 900;
  opacity: 0;
  min-height: 1.1em;
}
.feedback.great { color: #ffd23f; }
.feedback.good { color: #7fdcff; }
.score {
  justify-content: center;
  font-size: clamp(18px, 3vmin, 30px);
  font-weight: 800;
  min-height: 1.2em;
}

/* ---------- Start screen ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 8, 20, 0.92);
}
.start-card {
  text-align: center;
}
.start-drum {
  font-size: min(30vmin, 220px);
  line-height: 1;
}
.overlay.ready .start-drum {
  animation: bounce 1s ease-in-out infinite;
}
@keyframes bounce {
  50% { transform: translateY(-6%) scale(1.04); }
}
.start-card h1 {
  margin: 16px 0 4px;
  font-size: clamp(32px, 6vmin, 60px);
}
.start-card p {
  margin: 0;
  font-size: clamp(18px, 3vmin, 28px);
  color: var(--muted);
}
.overlay.ready p {
  color: var(--accent);
  font-weight: 800;
}

/* ---------- Portrait hint ---------- */

.rotate-hint {
  display: none;
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  text-align: center;
  font-size: 15px;
  pointer-events: none;
}
@media (orientation: portrait) {
  .rotate-hint { display: block; }
}
