/* Rhythm Racer - Retro Arcade UI */
:root {
  --bg: #07131a;
  --panel: #0f2430;
  --neon: #30e3ca;
  --accent: #ff3864;
  --gold: #ffcf33;
  --road: #0a1a23;
  --lane: #133040;
  --text: #d7f8ff;
  --scroll-road-h: 66px; /* height of the scrolling racetrack road inside #track */
}

* { box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -200px, #0b2a3a, var(--bg));
  color: var(--text);
  font-family: 'Press Start 2P', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

/* Start Screen */
.start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #0a1f2b, #0f2e40, #14455d);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.5s ease-out;
}

.start-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.start-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
}

.start-logo {
  height: clamp(400px, 50vh, 600px);
  width: auto;
  image-rendering: auto;
  image-rendering: -webkit-optimize-contrast;
  filter: drop-shadow(0 0 20px rgba(48, 227, 202, 0.3));
  animation: logoGlow 2s ease-in-out infinite alternate;
}

@keyframes logoGlow {
  from {
    filter: drop-shadow(0 0 20px rgba(48, 227, 202, 0.3));
  }
  to {
    filter: drop-shadow(0 0 30px rgba(48, 227, 202, 0.6));
  }
}

.start-game-btn {
  background: linear-gradient(145deg, #30e3ca, #26d0ce);
  color: #0a1f2b;
  border: none;
  padding: 15px 30px;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(14px, 2vw, 18px);
  border-radius: 8px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 2px;
  box-shadow: 
    0 4px 0 #1a9b8a,
    0 6px 0 #0f6b5f,
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: all 0.1s ease;
  position: relative;
  overflow: hidden;
}

.start-game-btn:hover {
  background: linear-gradient(145deg, #3af0d4, #2ce0de);
  transform: translateY(-2px);
  box-shadow: 
    0 6px 0 #1a9b8a,
    0 8px 0 #0f6b5f,
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.start-game-btn:active {
  transform: translateY(2px);
  box-shadow: 
    0 2px 0 #1a9b8a,
    0 4px 0 #0f6b5f,
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.start-game-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transition: left 0.5s;
}

.start-game-btn:hover::before {
  left: 100%;
}

/* Utility class for hiding elements */
.hidden {
  display: none !important;
}

/* HUD - Scale proportionally to maintain same relative sizes */
#hud {
  display: flex;
  align-items: center;
  justify-content: center; /* center the main content */
  gap: clamp(8px, 2vw, 16px);
  padding: 0 clamp(8px, 2vw, 18px) 8px;
  /* Reserve space on the right for the tempo/checkbox stack so center buttons never overlap */
  padding-right: clamp(180px, 28vw, 260px);
  /* Reserve space on the left for logo and mic UI in mic mode */
  padding-left: clamp(8px, 2vw, 18px);
  --hudH: clamp(100px, 15vh, 180px); /* more responsive height */
  height: var(--hudH);
  background: linear-gradient(180deg, #0f2e40, #0a1f2b);
  border-bottom: 3px solid #14455d;
  box-shadow: 0 4px 0 #07202b, inset 0 -3px 0 rgba(0,0,0,0.3);
  position: relative;
  z-index: 20; /* ensure HUD controls are always above the track */
  min-height: 100px; /* prevent too small on very narrow screens */
}

/* Mic Mode: keep controls in IDENTICAL position as regular mode */
#hud.mic-mode-active .controls {
  margin-left: 0; /* remove left offset, keep centered */
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0; /* remove margin-top since we're using absolute positioning */
  /* Use same positioning as base .controls rule - no overrides */
  left: 50%;
  transform: translateX(-50%);
  /* top is inherited from .controls base rule */
}

.logo {
  position: absolute;
  left: clamp(4px, 1vw, 10px); /* Reduced padding from left edge */
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 0 6px rgba(255, 207, 51, 0.8), 2px 2px 0 #000;
  flex-shrink: 0;
  z-index: 50;
}
.logo img {
  display: block;
  height: clamp(80px, 12vh, 160px); /* responsive height */
  width: auto;         /* Maintain aspect ratio */
  image-rendering: auto; /* Let browser choose best method */
  image-rendering: -webkit-optimize-contrast; /* Better scaling quality */
  max-width: 100%; /* prevent overflow on narrow screens */
}
.stats {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: clamp(10px, 2vw, 20px);
  font-size: clamp(11px, 2.25vw, 16px); /* responsive font size - 10% smaller */
  white-space: nowrap;
  text-align: center;
  z-index: 40;
  flex-shrink: 0; /* prevent shrinking */
}
.controls {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1vw, 10px);
  align-items: center;
  z-index: 60;
  flex-shrink: 0; /* prevent shrinking */
  /* Center directly below the score text */
  position: absolute;
  left: 50%;
  top: clamp(16px, 2.5vh, 22px); /* directly below score text */
  transform: translateX(-50%);
  /* Ensure controls don't overlap checkboxes - max width constraint */
  max-width: calc(50vw - 200px); /* Leave room for right stack */
}

/* Mic Mode: keep checkboxes in their default vertical stack position */
#hud.mic-mode-active .checkbox-group {
  flex-direction: column; /* keep vertical stack like default */
  align-items: flex-start;
  gap: 6px; /* same as default */
}
/* Mic Mode: JavaScript controls all positioning - no CSS positioning rules */
#hud.mic-mode-active #micLevelIndicator,
#hud.mic-mode-active .mic-level-indicator {
  /* Only set display and z-index - let JavaScript handle position/left/top/etc */
  display: flex !important;
  z-index: 999 !important;
  /* Remove any default positioning */
  right: auto !important;
  background: transparent !important;
  padding: 0 !important;
  border: none !important;
  /* Ensure mic UI doesn't exceed available space */
  max-width: calc(50vw - 300px); /* Prevent overflow, leave room for logo and controls */
}

/* Force remove ALL backgrounds from mic UI and ALL children elements */
#hud.mic-mode-active #micLevelIndicator *,
#hud.mic-mode-active .mic-level-indicator * {
  background-color: transparent !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

/* But keep backgrounds for buttons and functional elements */
#hud.mic-mode-active #micLevelIndicator button,
#hud.mic-mode-active #micLevelIndicator .mic-calibrate-btn,
#hud.mic-mode-active #micLevelIndicator input[type="checkbox"] {
  background: initial !important;
}

/* Ensure mic buttons (Calibrate, Block Game Audio) are BELOW the sensitivity slider */
#hud.mic-mode-active #micLevelIndicator .mic-buttons-row {
  align-items: flex-start;
  justify-content: flex-start;
  width: 100%;
  margin-top: 8px;
}

/* Keep right-stack in its original centered position - don't move checkboxes */
#hud.mic-mode-active .right-stack {
  top: 50% !important; /* restore original centered position */
  transform: translateY(-50%) !important; /* restore original transform */
}

/* Checkboxes stay in their default position within the right-stack */

.button-row {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vw, 10px);
  margin-top: 20px; /* Add space below score text */
}

.level-row {
  display: flex;
  justify-content: center;
}
.tempo-controls {
  display: flex;
  align-items: center;
  gap: 0; /* No gap - checkboxes and volume should be directly next to speedometer */
  font-size: clamp(10px, 1.5vw, 12px);
  position: relative;
  z-index: 50;
  flex-shrink: 0; /* prevent shrinking */
}
.tempo-controls .checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  margin-right: -4px; /* Negative margin to pull checkboxes closer to volume/speedometer */
  padding-right: 0; /* Remove any padding */
}
.tempo-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Prevent highlighting label text while interacting near the slider */
  -webkit-user-select: none;
  user-select: none;
}
.tempo-controls .tempo-meter {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  margin-left: -4px; /* Negative margin to pull speedometer closer to volume/checkboxes */
  padding-left: 0; /* Ensure no left padding */
}
.tempo-controls .tempo-meter-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.tempo-controls .tempo-readout { font-size: 12px; opacity: 0.95; }

/* Semicircle speedometer gauge */
.tempo-controls .tempo-gauge {
  --gsize: clamp(120px, 15vw, 200px); /* responsive gauge size */
  --r: calc(var(--gsize) / 2);
  --gscale: 0.8;            /* legacy scale var (not used for distances below) */
  --rim-color: #12384d;
  --rim: clamp(2px, 0.3vw, 4px); /* responsive rim thickness */
  --tick-gap: clamp(4px, 0.5vw, 6px); /* responsive tick gap */
  --minor-tick-len: clamp(5px, 0.8vw, 7px);
  --major-tick-len: clamp(8px, 1.2vw, 11px);
  --label-pad: clamp(8px, calc(var(--gsize) * 0.045), 16px);
  --label-gap: calc(var(--tick-gap) + var(--major-tick-len) + var(--label-pad)); /* labels align radially to major tick tips */
  --rim-inset: 1px;         /* small inward nudge to avoid subpixel bleed */
  position: relative;
  width: var(--gsize);
  height: calc(var(--gsize) / 2);
  /* clip to a perfect semicircle area via hidden overflow; the visible rim is drawn by ::before */
  border-radius: 0; /* rim handled by ::before */
  background: radial-gradient(120% 120% at 50% 120%, #0c2330, #07131a);
  border: none;
  box-shadow: inset 0 0 36px rgba(0,0,0,0.6), 0 4px 0 #07202b;
  overflow: hidden; /* ensures children don't overflow */
  /* Precise semicircle clip based on a circle of radius --r anchored at bottom center */
  clip-path: circle(var(--r) at 50% 100%);
  -webkit-clip-path: circle(var(--r) at 50% 100%);
  touch-action: none; /* allow pointer interactions without scrolling */
  flex-shrink: 0; /* prevent shrinking */
}

/* Circular rim to ensure a true semicircle outline */
.tempo-controls .tempo-gauge::before {
  content: "";
  position: absolute;
  inset: 0;
  /* Draw a ring from (r - rim) to r so it aligns exactly with clip-path */
  background:
    radial-gradient(circle at 50% 100%,
      transparent calc(var(--r) - var(--rim-inset) - var(--rim)),
      var(--rim-color) calc(var(--r) - var(--rim-inset) - var(--rim)),
      var(--rim-color) calc(var(--r) - var(--rim-inset)),
      transparent calc(var(--r) - var(--rim-inset))
    );
  box-shadow: 0 0 24px rgba(7, 32, 43, 0.6);
  pointer-events: none;
  z-index: 3; /* render above ticks/needle for crisp outline */
}
.tempo-controls .tempo-gauge .ticks {
  position: absolute;
  inset: 0; /* center of rotation exactly matches gauge center */
  pointer-events: none;
}
.tempo-controls .tempo-gauge .tick {
  --tick-len: var(--minor-tick-len);
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 2px;
  height: var(--tick-len); /* ~20% shorter */
  background: #ffffff;
  opacity: 0.95;
  border-radius: 2px;
  transform-origin: 50% 100%;
  /* pull ticks slightly inward so ends don't bleed past outline */
  transform: rotate(var(--angle, 0deg)) translateY(calc(-1 * (var(--r) - var(--rim-inset) - var(--rim) - var(--tick-gap) - var(--tick-len))));
  will-change: transform;
  box-shadow: 0 0 6px rgba(255,255,255,0.25);
}
.tempo-controls .tempo-gauge .tick.major {
  width: 3px;
  --tick-len: var(--major-tick-len); /* shared var so labels can align to tick tips */
  height: var(--tick-len);
  box-shadow: 0 0 8px rgba(255,255,255,0.35);
}

/* BPM number labels at major ticks */
.tempo-controls .tempo-gauge .tick-label {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform-origin: 50% 100%;
  /* Place slightly inside the arc and keep text upright */
  transform: rotate(var(--angle, 0deg))
             translateY(calc(-1 * (var(--r) - var(--rim-inset) - var(--rim) - var(--label-gap))))
             rotate(calc(var(--angle, 0deg) * -1))
             translateX(-50%);
  color: #d6ecff;
  font-size: clamp(6px, calc(var(--gsize) / 34), 10px); /* a little smaller for tighter visual centering */
  font-variant-numeric: tabular-nums; /* better alignment for numbers */
  font-weight: 600;
  letter-spacing: 0.1px;
  text-align: center;
  text-shadow: 0 1px 0 rgba(0,0,0,0.6), 0 0 6px rgba(128,192,255,0.25);
  user-select: none;
  pointer-events: none;
  will-change: transform;
}
.tempo-controls .tempo-gauge .needle {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 4px;
  height: calc(var(--r) - var(--rim-inset) - var(--rim) - var(--tick-gap) - 2px); /* align just inside tick tips */
  transform-origin: 50% 100%;
  transform: rotate(0deg);
  will-change: transform;
  background: linear-gradient(180deg, #ff6b6b, #d32020);
  border-radius: 3px;
  box-shadow: 0 0 12px rgba(255,56,100,0.55);
  z-index: 2; /* above ticks */
}
.tempo-controls .tempo-gauge .needle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  width: 12px;  /* slightly smaller knob */
  height: 12px;
  border-radius: 50%;
  background: #001017;
  border: 3px solid #d32020;
  box-shadow: 0 0 10px rgba(255,56,100,0.45), inset 0 0 6px rgba(0,0,0,0.4);
}

/* Hide original tempo slider but keep for accessibility/fallback */
.tempo-controls .tempo-meter #tempoSlider {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.tempo-controls input[type="range"] {
  width: 180px;
  position: relative;
  z-index: 1000;
  pointer-events: auto;
  /* Allow horizontal panning on touch screens, don't block dragging */
  touch-action: pan-x;
  cursor: pointer;
  /* Improve cross-browser dragging */
  appearance: none;
  -webkit-appearance: none;
  background: linear-gradient(180deg, #d1e6ee, #a9c3cf);
  height: 24px; /* slimmer but keeps a comfortable hit area */
  border-radius: 999px;
  outline: none;
}

/* WebKit (Chrome/Safari) */
.tempo-controls input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; /* thinner track */
  /* Top layer: dashed center line; Bottom layer: road gradient */
  background:
    repeating-linear-gradient(90deg, rgba(215,248,255,0.92) 0 22px, rgba(215,248,255,0.0) 22px 46px),
    linear-gradient(180deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  background-size: 100% 2px, 100% 100%;
  background-position: center, center;
  background-repeat: repeat, no-repeat;
  border-radius: 999px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}
.tempo-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -4px; /* center on 6px track within 24px input */
  background: var(--neon);
  border-radius: 50%;
  box-shadow: 0 0 0 2px #0b7263, 0 0 10px rgba(48, 227, 202, 0.6);
  pointer-events: auto;
  cursor: grab;
}
.tempo-controls input[type="range"]::-webkit-slider-thumb:active { cursor: grabbing; }

/* Firefox */
.tempo-controls input[type="range"]::-moz-range-track {
  height: 6px; /* thinner track */
  background:
    repeating-linear-gradient(90deg, rgba(215,248,255,0.92) 0 22px, rgba(215,248,255,0.0) 22px 46px),
    linear-gradient(180deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  background-size: 100% 2px, 100% 100%;
  background-position: center, center;
  background-repeat: repeat, no-repeat;
  border-radius: 999px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}
/* Firefox progress portion (left of thumb) */
.tempo-controls input[type="range"]::-moz-range-progress {
  height: 6px;
  background:
    repeating-linear-gradient(90deg, rgba(215,248,255,0.92) 0 22px, rgba(215,248,255,0.0) 22px 46px),
    linear-gradient(180deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  background-size: 100% 2px, 100% 100%;
  background-position: center, center;
  background-repeat: repeat, no-repeat;
  border-radius: 999px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}
.tempo-controls input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--neon);
  border: 2px solid #0b7263;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(48, 227, 202, 0.6);
  pointer-events: auto;
}

/* Fullscreen button positioned in top right corner */
.fullscreen-top-right {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 70;
  flex-shrink: 0;
}

/* Right-side stack for tempo controls only */
.right-stack {
  position: absolute;
  right: clamp(8px, 2vw, 18px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: row;
  align-items: flex-end; /* anchor gauge to the bottom of the HUD to maximize top clearance */
  gap: 0; /* No gap - everything is in tempo-controls which handles spacing */
  height: 100%;
  flex-shrink: 0; /* prevent shrinking */
  width: max-content; /* avoid stretching across the HUD which could collide with the logo */
  /* Ensure right stack doesn't overlap controls */
  min-width: 200px; /* Reserve minimum space for checkboxes and tempo gauge */
}

/* Text-styled button in HUD (override default neon button look) */
#hud .hud-link {
  padding: 0;
  background: none;
  border: 0;
  border-bottom: 0;
  color: var(--text);
  font-size: 12px;
  text-shadow: 0 0 6px rgba(215,248,255,0.35), 2px 2px 0 #000;
  cursor: pointer;
}
#hud .hud-link:hover { opacity: 0.85; text-decoration: underline; }

/* Layout and sizing when in the right-side stack */
.right-stack .tempo-controls { order: 1; height: 100%; margin-top: 0; }

/* Make the speedometer fill the header height (minus padding) */
.right-stack .tempo-controls .tempo-gauge {
  --gsize: calc((var(--hudH) - 8px - 10px) * 2); /* 0px top + 8px bottom padding; add 10px top headroom to avoid rim clip */
}
/* Stack meter so gauge sits on the bottom; header text is centered inside gauge */
.tempo-controls .tempo-meter {
  height: 100%;
  justify-content: flex-end;
  padding-top: 0; /* no extra spacing above the gauge */
}

/* Center the Tempo readout text inside the semicircle */
.tempo-controls .tempo-gauge .tempo-meter-header {
  position: absolute;
  left: 50%;
  bottom: 0; /* bottom is the circle center for the semicircle */
  transform: translate(-50%, calc(-1 * var(--r) * 0.38));
  display: inline-flex;
  flex-direction: column; /* stack Tempo on top and BPM below */
  align-items: center;
  gap: 2px;
  color: #d6ecff;
  text-shadow: 0 1px 0 rgba(0,0,0,0.6), 0 0 8px rgba(128,192,255,0.25);
  pointer-events: none;
  white-space: nowrap;
  z-index: 4; /* above needle, below doesn't matter since not near rim */
}
.tempo-controls .tempo-gauge .tempo-meter-header .tempo {
  font-size: clamp(8px, calc(var(--gsize) / 28), 12px);
  opacity: 0.95;
  line-height: 1;
}
.tempo-controls .tempo-gauge .tempo-meter-header .tempo-readout {
  font-size: clamp(10px, calc(var(--gsize) / 18), 16px);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

/* Metronome volume (small vertical slider) */
.tempo-controls .metro-vol {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: -8px; /* Increased negative margin to pull volume slider closer to speedometer */
  margin-left: 0; /* Reset left margin since checkboxes are already positioned correctly */
}
.tempo-controls .metro-vol .vol-text {
  font-size: 10px;
  opacity: 0.85;
}
.tempo-controls .slider-vertical {
  height: 120px;
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tempo-controls .slider-vertical input[type="range"] {
  width: 120px;  /* length of the vertical slider after rotation (doubled) */
  height: 22px;  /* keeps thumb hit area comfortable */
  transform: rotate(-90deg);
  transform-origin: center;
  touch-action: pan-y; /* allow vertical pan while dragging */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background: transparent; /* Match sensitivity slider */
}
/* Vertical track matching sensitivity slider aesthetic (WebKit) - with same pattern */
.tempo-controls .slider-vertical input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background:
    repeating-linear-gradient(0deg, rgba(215,248,255,0.92) 0 22px, rgba(215,248,255,0.0) 22px 46px),
    linear-gradient(180deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  background-size: 2px 100%, 100% 100%;
  background-position: center, center;
  background-repeat: repeat, no-repeat;
  border-radius: 999px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}
/* Vertical track matching sensitivity slider aesthetic (Firefox) - with same pattern */
.tempo-controls .slider-vertical input[type="range"]::-moz-range-track {
  height: 6px;
  background:
    repeating-linear-gradient(0deg, rgba(215,248,255,0.92) 0 22px, rgba(215,248,255,0.0) 22px 46px),
    linear-gradient(180deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  background-size: 2px 100%, 100% 100%;
  background-position: center, center;
  background-repeat: repeat, no-repeat;
  border-radius: 999px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}
/* Firefox progress portion (before thumb) - same pattern as sensitivity slider */
.tempo-controls .slider-vertical input[type="range"]::-moz-range-progress {
  height: 6px;
  background:
    repeating-linear-gradient(0deg, rgba(215,248,255,0.92) 0 22px, rgba(215,248,255,0.0) 22px 46px),
    linear-gradient(180deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  background-size: 2px 100%, 100% 100%;
  background-position: center, center;
  background-repeat: repeat, no-repeat;
  border-radius: 999px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}

/* Vertical slider thumb - matching sensitivity slider aesthetic (WebKit) */
.tempo-controls .slider-vertical input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--neon);
  border: 2px solid #0b7263;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  margin-top: -6px; /* Center the thumb on the track */
}

/* Vertical slider thumb - matching sensitivity slider aesthetic (Firefox) */
.tempo-controls .slider-vertical input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--neon);
  border: 2px solid #0b7263;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

button {
  font: inherit;
  font-size: clamp(10px, 1.5vw, 12px);
  padding: clamp(8px, 1.5vw, 10px) clamp(16px, 3vw, 20px); /* Increased horizontal padding */
  color: #001017;
  background: var(--neon);
  border: 0;
  border-bottom: clamp(3px, 0.5vw, 4px) solid #0b7263;
  border-radius: clamp(6px, 1vw, 8px);
  cursor: pointer;
  white-space: nowrap; /* prevent text wrapping */
  flex-shrink: 0; /* prevent shrinking */
}
button:disabled { opacity: 0.5; cursor: default; }

/* Level dropdown styled to match neon button look */
#levelSelect {
  font: inherit;
  font-size: clamp(10px, 1.5vw, 12px);
  padding: clamp(8px, 1.5vw, 10px) clamp(30px, 4vw, 36px) clamp(8px, 1.5vw, 10px) clamp(16px, 3vw, 20px); /* Increased left padding to match buttons */
  color: #001017;
  background: var(--neon);
  border: 0;
  border-bottom: clamp(3px, 0.5vw, 4px) solid #0b7263;
  border-radius: clamp(6px, 1vw, 8px);
  cursor: pointer;
  white-space: nowrap; /* prevent text wrapping */
  flex-shrink: 0; /* prevent shrinking */
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  /* Custom caret icon (dark arrow) */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23001017' d='M1.4 1.6L6 6.2l4.6-4.6L12 3 6 9 0 3z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
#levelSelect:focus {
  outline: none;
  box-shadow: 0 0 0 2px #0b7263;
}

/* Game viewport */
#game-viewport {
  width: 100%;
  max-width: none;
  margin: 12px 0 0; /* reduce vertical space below the HUD by ~50% */
  padding: 0 0 16px;
  position: relative;
  z-index: 1;
}

#playfield {
  display: flex;
  flex-direction: column; /* stack track over race */
  gap: 16px;
  align-items: stretch;
  position: relative;
}

#track { flex: 0 0 auto; }
#race { flex: 0 0 auto; width: 100%; min-width: 0; }

#track {
  position: relative;
  width: 100%;
  height: clamp(360px, 46vh, 680px); /* shorter so the race fits better below */
  border: 4px solid #12384d;
  border-radius: 14px;
  overflow: hidden; /* mask children so notation cannot extend outside the rectangle */
  /* Hard clip to rounded rectangle for all descendants (Safari + cross-browser) */
  -webkit-clip-path: inset(0 round 14px);
  clip-path: inset(0 round 14px);
  background: var(--road);
  box-shadow: inset 0 0 80px rgba(0,0,0,0.8), 0 16px 24px rgba(0,0,0,0.5);
  /* Safe-edge padding so notation never kisses the border */
  padding: 0 30px; /* increased to ensure more buffer space */
  /* Create a stacking context so ::after can layer above scroller but below playhead/car */
  z-index: 1;
  cursor: grab; /* Indicate scrollable when music is not playing */
}

#track:active {
  cursor: grabbing; /* Show grabbing cursor when actively scrolling */
}

/* Draw the border ring above children so notation appears contained under the edge */
#track::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit; /* match #track corners */
  pointer-events: none;
  /* Layering: above #measureScroller (z-index:4), below #car (9) and #playhead (10) */
  z-index: 8;
  /* Exact border overlay on top of content */
  border: 4px solid #12384d;
}

/* Inner edge masks to prevent the perception of lines coming from outside */
#track::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 7; /* above scroller, below the top border overlay */
  /* Cover the left/right safe-edge zones with the track background color */
  box-shadow: inset 30px 0 0 var(--road), inset -30px 0 0 var(--road); /* match increased padding */
}

/* Race panel */
#race {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.5vw, 12px);
  padding: clamp(8px, 1.5vw, 12px);
  width: 100%;
  background: linear-gradient(180deg, #0f2e40, #0a1f2b);
  border: clamp(2px, 0.5vw, 4px) solid #12384d;
  border-radius: clamp(10px, 2vw, 14px);
  box-shadow: inset 0 0 40px rgba(0,0,0,0.5), 0 12px 24px rgba(0,0,0,0.4);
  min-height: 200px;
  overflow: visible;
}

#raceTitle {
  font-size: clamp(10px, 2vw, 14px);
  letter-spacing: clamp(1px, 0.3vw, 2px);
  color: var(--gold);
  text-align: center;
  text-shadow: 0 0 6px rgba(255, 207, 51, 0.8), 2px 2px 0 #000;
}

#raceTrack {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  max-width: clamp(300px, 40vw, 405px); /* responsive max width */
  margin: 0 auto;           /* center below the notation */
  aspect-ratio: 2 / 1; /* wider oval */
  background: radial-gradient(120% 120% at 50% -10%, #0c2330, #07131a);
  border-radius: clamp(12px, 2.5vw, 16px);
  overflow: hidden;
  transform: translateZ(0); /* stabilize rendering */
}

/* Outer oval track ring */
#raceTrack::before {
  content: "";
  position: absolute;
  inset: 7%;
  border: 14px solid #1b4256; /* track asphalt, slightly thicker */
  border-radius: 50% / 45%;
  box-shadow: inset 0 0 0 8px #0a1a23, 0 0 48px rgba(0,0,0,0.75);
}

/* Subtle inner glow overlay (no lane drawing here; lanes are in .lane-dashes element) */
#raceTrack::after {
  content: "";
  position: absolute;
  inset: 9%;
  border: none;
  border-radius: 50% / 45%;
  box-shadow: inset 0 0 0 1px rgba(215,248,255,0.08);
  pointer-events: none;
}

/* Optional oval texture image layer (sits under lane dashes) */
#raceTrack .oval-texture {
  position: absolute;
  inset: 9%;
  border-radius: 50% / 45%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain; /* expects a pre-cropped oval PNG */
  image-rendering: pixelated; /* retro look if using pixel art */
  pointer-events: none;
  z-index: 0;
}

/* Lane overlay: two solid lane guide lines and a dashed separator between them */
#raceTrack .lane-dashes {
  position: absolute;
  inset: 12.5%;
  border: 5px dashed rgba(215,248,255,0.7);
  border-radius: 50% / 45%;
  filter: drop-shadow(0 0 6px rgba(48, 227, 202, 0.5));
  pointer-events: none;
  z-index: 0; /* below finish line (1) and cars (2) */
}
#raceTrack .lane-dashes::before,
#raceTrack .lane-dashes::after {
  content: "";
  position: absolute;
  border-radius: 50% / 45%;
  border: 2px solid rgba(215,248,255,0.45);
}
/* Outer lane line */
#raceTrack .lane-dashes::before {
  inset: 10.2%;
}
/* Inner lane line */
#raceTrack .lane-dashes::after {
  inset: 14.8%;
}

.race-car {
  position: absolute;
  width: clamp(20px, 3vw, 30px);
  height: clamp(12px, 2vw, 18px);
  transform: translate3d(-50%, -50%, 0); /* default; JS will rotate */
  will-change: transform, left, top;      /* hint to reduce jitter */
  backface-visibility: hidden;
  transform-style: preserve-3d;
  border-radius: clamp(3px, 0.8vw, 5px);
  border: clamp(1px, 0.3vw, 2px) solid rgba(0, 16, 23, 0.85); /* crisp arcade outline */
  box-shadow: 0 0 14px rgba(0,0,0,0.6);
  z-index: 2;
}
.race-car.user {
  background:
    radial-gradient(10px 8px at 25% 40%, #B40904 50%, transparent 52%),
    radial-gradient(10px 8px at 75% 40%, #B40904 50%, transparent 52%),
    linear-gradient(180deg, #B40904, #8A0603);
  box-shadow: 0 0 18px rgba(180, 9, 4, 0.7);
}
.race-car.cpu {
  background:
    radial-gradient(10px 8px at 25% 40%, #6cb6ff 50%, transparent 52%),
    radial-gradient(10px 8px at 75% 40%, #6cb6ff 50%, transparent 52%),
    linear-gradient(180deg, #1e88e5, #0a3f8a);
  box-shadow: 0 0 18px rgba(48, 227, 202, 0.55);
}

/* When a custom image is provided for a car */
.race-car.has-image {
  /* Allow inline background-image from JS to show above gradient */
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;         /* keep car proportions */
  image-rendering: pixelated;
}

/* Finish line marker (vertical bar positioned by JS at the TOP of the oval) */
#raceTrack .finish-line {
  position: absolute;
  left: 50%; /* will be overridden by JS */
  top: 50%;  /* will be overridden by JS */
  width: 10px;  /* default; JS adjusts */
  height: 80px; /* default; JS adjusts */
  transform: translate(-50%, -50%);
  border-radius: 4px;
  /* High-contrast checkered stripes */
  background: repeating-linear-gradient(
    0deg,
    #ffffff 0 8px,
    #0a1a23 8px 16px
  );
  box-shadow: 0 0 8px rgba(255,255,255,0.25), 0 0 12px rgba(48,227,202,0.35);
  z-index: 1;           /* below cars (z:2), above lane (::after default) */
  pointer-events: none; /* decorative */
}

/* Centered lap label inside race oval */
#raceTrack #raceLapLabel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(10px, 1.2vw, 12px);
  letter-spacing: 0.5px;
  white-space: nowrap; /* keep in one line */
  color: #B40904;
  text-shadow: 2px 2px 0 #000, 0 0 8px rgba(180, 9, 4, 0.5);
  z-index: 5; /* above cars (2) and finish line (1) */
  pointer-events: none;
}

/* Car labels that follow cars (no rotation) */
#raceTrack .car-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 10px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--text);
  text-shadow: 1px 1px 0 #000, 0 0 6px rgba(0,0,0,0.5);
  white-space: nowrap;
  pointer-events: none;
  z-index: 4; /* above cars (2), below raceLapLabel (5) */
}
#raceTrack .car-label.user { color: #B40904; }
#raceTrack .car-label.cpu { color: #6cb6ff; }

/* Rhythm Pattern Selection */
#rhythmSelection {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 0;
  z-index: 10;
  pointer-events: none;
  padding: 0;
  margin-top: 200px; /* Position below the track, over the race area */
}

.rhythm-patterns {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
  pointer-events: auto;
  justify-content: center;
  padding: 0;
  width: auto;
}

.rhythm-patterns.left-patterns {
  margin-left: 0;
  padding-right: 0;
  align-items: flex-start;
  margin-right: auto;
  padding-left: clamp(20px, 4vw, 40px);
}

.rhythm-patterns.right-patterns {
  margin-right: 0;
  padding-left: 0;
  align-items: flex-end;
  margin-left: auto;
  padding-right: clamp(20px, 4vw, 40px);
}

.rhythm-patterns h3 {
  font-size: clamp(10px, 1.5vw, 14px);
  color: var(--neon);
  margin: 0 0 clamp(6px, 1vw, 10px) 0;
  text-align: center;
  text-shadow: 0 0 4px rgba(48, 227, 202, 0.6);
  width: 100%;
}

.pattern-buttons {
  display: flex;
  flex-direction: row;
  gap: clamp(4px, 1.5vw, 12px);
  align-items: center;
  justify-content: center;
  width: 100%;
}

.pattern-btn {
  background: linear-gradient(145deg, #1a3a4a, #0f2e40);
  border: 2px solid #14455d;
  border-radius: clamp(4px, 0.8vw, 8px);
  padding: clamp(4px, 1vw, 8px);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(80px, 12vw, 160px);
  height: clamp(60px, 8vw, 100px);
  position: relative;
  overflow: hidden;
}

.pattern-btn:hover {
  background: linear-gradient(145deg, #2a4a5a, #1f3e50);
  border-color: var(--neon);
  box-shadow: 0 0 8px rgba(48, 227, 202, 0.4);
  transform: translateY(-2px);
}

.pattern-btn.selected {
  background: linear-gradient(145deg, #30e3ca, #26d0ce);
  border-color: #1a9b8a;
  box-shadow: 0 0 12px rgba(48, 227, 202, 0.6);
  transform: translateY(-2px);
}

.pattern-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(0.9);
  transition: filter 0.2s ease;
}

.pattern-btn:hover img,
.pattern-btn.selected img {
  filter: brightness(1.1);
}

.pattern-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
}

.pattern-btn:hover::before {
  left: 100%;
}

/* Scrolling background road lines */
#background-road,
#background-lines {
  position: absolute;
  inset: 0;
  z-index: 0;
}
#background-road {
  /* Remove decorative vertical lane lines */
  display: none;
}
#background-lines {
  /* Hide horizontal background lines so only VexFlow's staff is visible */
  display: none;
}

/* Fixed playhead */
#playhead {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%; /* moved from 38% to 50% for more space on left */
  width: 2px;
  transform: translateX(-1px);
  background: linear-gradient(var(--gold), #ff9f1a);
  box-shadow: 0 0 8px rgba(255, 207, 51, 0.9), 0 0 20px rgba(255, 207, 51, 0.4);
  z-index: 10; /* ensure playhead is above notes */
}

/* Car at playhead */
#car {
  position: absolute;
  bottom: 28px; /* lowered to sit visually on the scrolling racetrack road */
  left: 50%; /* moved from 38% to 50% for centering */
  transform: translate(-50%, 0);
  width: 144px;  /* 10% smaller than 160px */
  height: 72px;  /* 10% smaller than 80px */
  background-image: url('rrcar.png');
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  image-rendering: auto;
  z-index: 9; /* car above notes but below playhead */
}
/* Car wheels removed - now included in the car image */

/* Smoke animation for the car */
.smoke {
  position: absolute;
  bottom: 48px; /* positioned slightly higher at the exhaust level of the car */
  left: calc(50% - 130px); /* positioned even further to the left (behind) the car */
  transform: translateX(-50%);
  width: 12px; /* wider for horizontal effect */
  height: 12px; /* twice as thick for more visible smoke */
  background: radial-gradient(ellipse, rgba(150, 150, 150, 0.6) 0%, rgba(150, 150, 150, 0.3) 50%, transparent 100%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 5; /* below car but above track */
  animation: smokeTrail 2s ease-out forwards;
}

@keyframes smokeTrail {
  0% {
    opacity: 0.8;
    transform: translateX(-50%) translateX(0) translateY(0) scale(0.5);
  }
  25% {
    opacity: 0.7;
    transform: translateX(-50%) translateX(-20px) translateY(-2px) scale(0.8);
  }
  50% {
    opacity: 0.6;
    transform: translateX(-50%) translateX(-40px) translateY(1px) scale(1);
  }
  75% {
    opacity: 0.4;
    transform: translateX(-50%) translateX(-60px) translateY(-1px) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateX(-80px) translateY(0) scale(1.5);
  }
}

/* Multiple smoke particles with staggered timing */
.smoke:nth-child(1) { animation-delay: 0s; }
.smoke:nth-child(2) { animation-delay: 0.2s; }
.smoke:nth-child(3) { animation-delay: 0.4s; }
.smoke:nth-child(4) { animation-delay: 0.6s; }
.smoke:nth-child(5) { animation-delay: 0.8s; }

/* Microphone mode indicator */
.mic-mode-active {
  color: #ff6b35 !important;
  text-shadow: 0 0 8px rgba(255, 107, 53, 0.6) !important;
  font-weight: bold !important;
}

/* Keep text white when microphone mode is active - override orange color */
#hud.mic-mode-active .stats,
#hud.mic-mode-active .stats *,
#hud.mic-mode-active .checkbox-group label,
#hud.mic-mode-active .checkbox-group label span {
  color: var(--text) !important; /* Keep text white, not orange */
  text-shadow: none !important;
  font-weight: normal !important;
}

/* Microphone Mode checkbox label should still be orange when checked */
#hud.mic-mode-active .checkbox-group #micModeEnable:checked + span {
  color: #ff6b35 !important;
  text-shadow: 0 0 8px rgba(255, 107, 53, 0.6) !important;
  font-weight: bold !important;
}

/* Microphone mode checkbox styling */
#micModeEnable:checked + span {
  color: #ff6b35;
  text-shadow: 0 0 4px rgba(255, 107, 53, 0.4);
}

/* Remove hard left offsets on checkboxes to prevent collisions on narrow screens */

/* Microphone level indicator */
.mic-level-indicator {
  position: absolute;
  right: 20px; /* Position next to volume slider */
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 10px;
  color: #888;
  max-width: 100%;
  z-index: 70;
  background: transparent; /* Remove any white background */
  padding: 0; /* Remove any padding */
  border: none; /* Remove any border */
}

.mic-level-section {
  display: flex;
  flex-direction: row; /* Changed to horizontal layout */
  gap: 8px;
  align-items: center;
  width: 100%; /* Ensure full width for alignment */
  background: transparent;
  padding: 0;
  border: none;
}

.mic-level-label-wrapper,
.mic-sensitivity-label-wrapper {
  display: flex;
  flex-direction: column; /* Stack label and value vertically */
  gap: 2px;
  align-items: flex-start;
  min-width: 75px; /* Ensure consistent width so sliders align */
  background: transparent;
  padding: 0;
  border: none;
}

.mic-level-section .mic-level-bar {
  flex-shrink: 0; /* Prevent bar from shrinking */
}

.mic-level-bar {
  width: 120px; /* Horizontal width */
  height: 6px; /* Horizontal height */
  background: linear-gradient(90deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}

.mic-level-fill {
  width: 0%; /* Width changes based on volume */
  height: 100%; /* Full height of the horizontal bar */
  background: linear-gradient(90deg, #00ff00, #ffff00, #ff0000); /* Horizontal gradient */
  transition: width 0.1s ease;
  position: absolute;
  left: 0; /* Fill from left to right */
  top: 0;
}

.mic-level-text {
  font-size: 10px;
  color: var(--text);
  opacity: 0.85;
  text-align: left;
  white-space: nowrap; /* Prevent wrapping, like sensitivity label */
}

.mic-level-value {
  font-size: 10px;
  color: var(--text);
  opacity: 0.85;
}

.mic-controls-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: transparent;
  padding: 0;
  border: none;
}

.mic-sensitivity-row {
  display: flex;
  flex-direction: row; /* Horizontal layout */
  align-items: center;
  gap: 8px;
  font-size: 9px;
  justify-content: flex-start;
  width: 100%; /* Ensure full width to match mic-level-section */
  background: transparent;
  padding: 0;
  border: none;
}


.mic-sensitivity-row label {
  color: var(--text);
  font-size: 10px;
  opacity: 0.85;
  white-space: nowrap;
  margin: 0; /* Remove default margin */
}

.mic-sensitivity-value {
  font-size: 10px;
  color: var(--text);
  opacity: 0.85;
}

.mic-sensitivity-row input[type="range"],
#micSensitivity {
  width: 120px; /* Horizontal slider width - same as mic level bar */
  height: 22px; /* Keeps thumb hit area comfortable */
  outline: none !important;
  -webkit-appearance: none !important; /* Remove default WebKit styling */
  appearance: none !important;
  flex-shrink: 0; /* Prevent slider from shrinking */
  background: transparent !important; /* Remove any white background from input */
  background-color: transparent !important; /* Additional override */
  border: none !important; /* Remove any border */
  padding: 0 !important; /* Remove any padding */
  margin: 0 !important; /* Remove any margin */
  box-shadow: none !important; /* Remove any box shadow that might create white appearance */
}

/* Horizontal road style track (WebKit) */
.mic-sensitivity-row input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  background:
    repeating-linear-gradient(90deg, rgba(215,248,255,0.92) 0 22px, rgba(215,248,255,0.0) 22px 46px),
    linear-gradient(90deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  background-size: 100% 2px, 100% 100%;
  background-position: center, center;
  background-repeat: repeat, no-repeat;
  border-radius: 999px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}

/* Horizontal road style track (Firefox) */
.mic-sensitivity-row input[type="range"]::-moz-range-track {
  width: 100%;
  height: 6px;
  background:
    repeating-linear-gradient(90deg, rgba(215,248,255,0.92) 0 22px, rgba(215,248,255,0.0) 22px 46px),
    linear-gradient(90deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  background-size: 100% 2px, 100% 100%;
  background-position: center, center;
  background-repeat: repeat, no-repeat;
  border-radius: 999px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}

/* Firefox progress portion (before thumb) for horizontal slider */
.mic-sensitivity-row input[type="range"]::-moz-range-progress {
  height: 6px;
  background:
    repeating-linear-gradient(90deg, rgba(215,248,255,0.92) 0 22px, rgba(215,248,255,0.0) 22px 46px),
    linear-gradient(90deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  background-size: 100% 2px, 100% 100%;
  background-position: center, center;
  background-repeat: repeat, no-repeat;
  border-radius: 999px;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.25), inset 0 -2px 3px rgba(0,0,0,0.35);
}

.mic-sensitivity-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--neon);
  border: 2px solid #0b7263;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  margin-top: -6px; /* Center the thumb on the track */
}

.mic-sensitivity-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--neon);
  border: 2px solid #0b7263;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

#micSensitivityValue {
  font-size: 10px;
  color: var(--text);
  opacity: 0.85;
  font-weight: normal;
  min-width: 12px;
}

.mic-buttons-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: center;
  background: transparent;
  padding: 0;
  border: none;
}

.mic-silence-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.mic-calibrate-btn,
.mic-test-btn,
.mic-test-detection-btn,
.mic-disable-silence-btn {
  border: none;
  border-radius: 3px;
  padding: 3px 8px;
  font-size: 7px;
  cursor: pointer;
  font-weight: bold;
  min-width: 60px;
  text-align: center;
}

.mic-calibrate-btn {
  background: #ff6b35;
  color: white;
}

.mic-calibrate-btn:hover {
  background: #ff8c42;
}

.mic-calibrate-btn:active {
  background: #e55a2b;
}

.mic-test-btn {
  background: #30e3ca;
  color: white;
}

.mic-test-btn:hover {
  background: #4af0d8;
}

.mic-test-btn:active {
  background: #26d0b8;
}

.mic-test-detection-btn {
  background: #ff6b35;
  color: white;
}

.mic-test-detection-btn:hover {
  background: #ff8c42;
}

.mic-test-detection-btn:active {
  background: #e55a2b;
}

.mic-disable-silence-btn {
  background: #ff0000;
  color: white;
}

.mic-disable-silence-btn:hover {
  background: #ff3333;
}

.mic-disable-silence-btn:active {
  background: #cc0000;
}

.mic-silence-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 8px;
  color: #888;
}

.mic-silence-toggle input[type="checkbox"] {
  width: 12px;
  height: 12px;
  accent-color: #ff6b35;
}

.mic-debug-info {
  font-size: 8px;
  color: #888;
  text-align: center;
  background: transparent;
  padding: 0;
  border: none;
}

#micDebugStatus {
  color: #30e3ca;
  font-weight: bold;
}

/* Perfect lap text */
.perfect-text {
  position: absolute;
  bottom: 80px; /* above the car */
  left: 50%;
  transform: translateX(-50%);
  font-size: 24px;
  font-weight: bold;
  color: #ff6b35;
  text-shadow: 0 0 10px rgba(255, 107, 53, 0.8), 0 0 20px rgba(255, 107, 53, 0.4);
  z-index: 15; /* above everything */
  pointer-events: none;
  animation: perfectPulse 1.5s ease-out forwards;
}

@keyframes perfectPulse {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.5);
  }
  20% {
    opacity: 1;
    transform: translateX(-50%) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) scale(1);
  }
}


#countIn {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(28px, 5vw, 56px);
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 207, 51, 0.6), 2px 2px 0 #000;
  opacity: 0;
  transition: opacity 160ms ease;
  z-index: 15;
  pointer-events: none;
}
#countIn.visible { opacity: 1; }
#countIn.accent { color: #fff; text-shadow: 0 0 14px rgba(255,255,255,0.9), 0 0 40px rgba(255,255,255,0.4); }

@keyframes count-pop {
  0% { transform: translate(-50%, -50%) scale(0.86); }
  60% { transform: translate(-50%, -50%) scale(1.08); }
  100% { transform: translate(-50%, -50%) scale(1.0); }
}

/* Lap label at top of track, centered with the playhead */
#lapLabel {
  position: absolute;
  top: 7%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(14px, 2vw, 20px);
  letter-spacing: 1px;
  color: #B40904; /* red */
  text-shadow: 2px 2px 0 #000, 0 0 8px rgba(180, 9, 4, 0.5);
  z-index: 12; /* above notes and playhead line (10), below count-in (15) */
  pointer-events: none;
}

/* Retro confetti -----------------------------------------------------------*/
.confetti-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;         /* confine to host area */
  border-radius: inherit;   /* clip to host rounded corners */
}
.confetti-piece {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 10px;
  transform: translate(-50%, -50%) scale(0.85) rotate(0deg);
  opacity: 1;
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(255,255,255,0.25), 2px 2px 0 #000; /* retro glow + hard pixel drop */
  transition: transform 900ms cubic-bezier(0.16, 0.78, 0.28, 1.0), opacity 600ms ease;
  will-change: transform, opacity;
}
.confetti-piece.explode {
  transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(1);
  opacity: 0.9; /* visible during the burst */
}
.confetti-piece.fall {
  transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy) + var(--fallY))) rotate(var(--rot)) scale(1);
  opacity: 0; /* slowly fade while falling */
}

#instructions {
  margin-top: clamp(8px, 1.5vw, 10px);
  font-size: clamp(9px, 1.8vw, 11px);
  opacity: 0.9;
  text-align: center;
  padding: 0 clamp(10px, 2vw, 20px); /* responsive padding */
}

/* Media queries for very small screens */
@media (max-width: 768px) {
  #hud {
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    height: auto;
    min-height: 120px;
  }
  
  .stats {
    order: 1;
    font-size: clamp(10px, 3vw, 14px);
  }
  
  .controls {
    order: 2;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .right-stack {
    order: 3;
    margin-right: 0;
    justify-content: center;
  }
  
  .tempo-controls {
    flex-direction: column;
    gap: 6px;
  }
  
  .tempo-controls .checkbox-group {
    flex-direction: row;
    gap: 12px;
  }
  
  .fullscreen-top-right {
    position: static;
    order: 4;
    align-self: center;
  }
}

@media (max-width: 480px) {
  .logo img {
    height: clamp(60px, 15vh, 100px);
  }
  
  .controls {
    gap: 4px;
  }
  
  button, #levelSelect {
    font-size: 10px;
    padding: 6px 8px;
  }
  
  .tempo-controls .tempo-gauge {
    --gsize: clamp(100px, 20vw, 150px);
  }
}

/* Measure scroller */
#measureScroller {
  position: absolute;
  top: 0; /* fill entire track height */
  left: 0;
  height: 100%; /* take full height of the track */
  width: 3600px; /* increased canvas for larger render width */
  transform: translate3d(0,0,0);
  will-change: transform;
  z-index: 4; /* over the road */
  pointer-events: auto; /* enable manual scrolling */
  overflow: visible; /* ensure no clipping */
  cursor: grab; /* indicate scrollable area */
}
#measureScroller:active {
  cursor: grabbing; /* indicate dragging state */
}
#scrollRoad {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px; /* inset a bit from the border overlay */
  height: var(--scroll-road-h);
  border-radius: 10px;
  /* Asphalt look */
  background: linear-gradient(180deg, #1b4256 0%, #0f2e40 60%, #09202b 100%);
  box-shadow: inset 0 8px 12px rgba(0,0,0,0.45), inset 0 -8px 12px rgba(0,0,0,0.45), 0 0 20px rgba(0,0,0,0.5);
  z-index: 1; /* behind the notes */
}
#scrollRoad::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 3px;
  /* Horizontal dashed center line that scrolls with the measure */
  background: repeating-linear-gradient(90deg, rgba(215,248,255,0.9) 0 28px, rgba(215,248,255,0.0) 28px 56px);
  filter: drop-shadow(0 0 6px rgba(48, 227, 202, 0.5));
  opacity: 0.9;
  z-index: 0; /* keep center dash behind seams and finish bar */
}

/* Vertical seams aligned to double barlines under the notation */
#scrollRoad .road-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12px;
  transform: translateX(-50%);
  pointer-events: none;
  /* Subtle vertical seam with inner highlights */
  background:
    linear-gradient(180deg, rgba(215,248,255,0.18), rgba(215,248,255,0.06));
  box-shadow:
    inset 2px 0 0 rgba(0,0,0,0.35),
    inset -2px 0 0 rgba(0,0,0,0.35),
    0 0 10px rgba(0,0,0,0.25);
  border-radius: 2px;
  opacity: 0.9;
  z-index: 1; /* above the dashed road center line */
}

/* Checkered finish bar at the end of the phrase */
#scrollRoad .road-finish {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 16px;
  transform: translateX(-50%);
  border-radius: 2px;
  pointer-events: none;
  background-color: #0b0b0b;
  /* High-contrast checkered pattern */
  background-image:
    linear-gradient(45deg, #ffffff 25%, transparent 25%),
    linear-gradient(-45deg, #ffffff 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ffffff 75%),
    linear-gradient(-45deg, transparent 75%, #ffffff 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  box-shadow: 0 0 10px rgba(255,255,255,0.25), 0 0 14px rgba(48,227,202,0.35);
  z-index: 2; /* most prominent within the road layer */
}
#vf {
  width: 2400px; /* increased drawing width; adjusted in JS too */
  height: 100%; /* match track height */
  overflow: visible; /* ensure ledger lines and beams are visible */
  position: relative;
  z-index: 2; /* ensure notation renders above the road */
}

/* Music staff visual polish */
svg.vf svg, svg.vf {
  overflow: visible;
}
/* Ensure VexFlow container allows overflow (ledger lines, beams, etc.) */
#vf, #vf svg {
  overflow: visible;
}

/* Per-note hit/miss highlighting */
#vf .vf-stavenote.note-hit {
  filter: drop-shadow(0 0 6px rgba(76, 175, 80, 0.65));
}
#vf .vf-stavenote.note-miss {
  filter: drop-shadow(0 0 8px rgba(255, 56, 100, 0.7));
}
/* Recolor noteheads, stems, rests within the stavenote group */
#vf .vf-stavenote.note-hit path,
#vf .vf-stavenote.note-hit ellipse,
#vf .vf-stavenote.note-hit rect,
#vf .vf-stavenote.note-hit use {
  stroke: #58ff85 !important;
  fill: #58ff85 !important;
}
#vf .vf-stavenote.note-miss path,
#vf .vf-stavenote.note-miss ellipse,
#vf .vf-stavenote.note-miss rect,
#vf .vf-stavenote.note-miss use {
  stroke: #ff5b84 !important;
  fill: #ff5b84 !important;
}

/* Status badges (optional) */
.badge {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 12px;
  background: #113244;
  border: 2px solid #1d5973;
}

/* Responsive design for rhythm pattern buttons */
@media (max-width: 1200px) {
  .rhythm-patterns.left-patterns {
    padding-left: clamp(15px, 3vw, 30px);
  }
  
  .rhythm-patterns.right-patterns {
    padding-right: clamp(15px, 3vw, 30px);
  }
  
  .pattern-btn {
    width: clamp(70px, 10vw, 140px);
    height: clamp(50px, 7vw, 90px);
  }
  
  .pattern-buttons {
    gap: clamp(3px, 1vw, 8px);
  }
}

@media (max-width: 900px) {
  .rhythm-patterns.left-patterns {
    padding-left: clamp(12px, 2.5vw, 25px);
  }
  
  .rhythm-patterns.right-patterns {
    padding-right: clamp(12px, 2.5vw, 25px);
  }
  
  .pattern-btn {
    width: clamp(60px, 8vw, 120px);
    height: clamp(40px, 6vw, 80px);
  }
  
  .pattern-buttons {
    gap: clamp(2px, 0.8vw, 6px);
  }
  
  .rhythm-patterns h3 {
    font-size: clamp(8px, 1.2vw, 12px);
    margin: 0 0 clamp(4px, 0.8vw, 8px) 0;
  }
}

@media (max-width: 600px) {
  .rhythm-patterns.left-patterns {
    padding-left: clamp(10px, 2vw, 20px);
  }
  
  .rhythm-patterns.right-patterns {
    padding-right: clamp(10px, 2vw, 20px);
  }
  
  .pattern-btn {
    width: clamp(50px, 6vw, 100px);
    height: clamp(35px, 5vw, 70px);
  }
  
  .pattern-buttons {
    gap: clamp(1px, 0.5vw, 4px);
  }
  
  .rhythm-patterns h3 {
    font-size: clamp(6px, 1vw, 10px);
    margin: 0 0 clamp(2px, 0.5vw, 6px) 0;
  }
}

@media (max-width: 400px) {
  .rhythm-patterns.left-patterns {
    padding-left: clamp(8px, 1.5vw, 15px);
  }
  
  .rhythm-patterns.right-patterns {
    padding-right: clamp(8px, 1.5vw, 15px);
  }
  
  .pattern-btn {
    width: clamp(40px, 5vw, 80px);
    height: clamp(30px, 4vw, 60px);
  }
  
  .pattern-buttons {
    gap: clamp(1px, 0.3vw, 3px);
  }
  
  .rhythm-patterns h3 {
    font-size: clamp(5px, 0.8vw, 8px);
    margin: 0 0 clamp(1px, 0.3vw, 4px) 0;
  }
}
