:root {
  --game-bg: linear-gradient(180deg, #e8f5e9 0%, #e1f5fe 45%, #fce4ec 100%);
  --rail-wood: linear-gradient(180deg, #8d5524 0%, #b27a3c 40%, #704018 100%);
}

/* ========================================================
   Main Field & Background
   ======================================================== */
.xylo-field {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 100%;
  padding: 10px 14px 20px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.musical-backdrop {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.ambient-cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 50px;
  filter: blur(2px);
  animation: cloud-drift linear infinite alternate;
}

.cloud-1 {
  width: 140px;
  height: 48px;
  top: 15%;
  left: 5%;
  animation-duration: 22s;
}

.cloud-2 {
  width: 180px;
  height: 56px;
  top: 60%;
  right: 5%;
  animation-duration: 28s;
}

@keyframes cloud-drift {
  0% { transform: translateX(0); }
  100% { transform: translateX(35px); }
}

/* ========================================================
   Toolbar & Mascot
   ======================================================== */
.xylo-toolbar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 460px;
  margin-bottom: 12px;
}

.mascot-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.85);
  padding: 4px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border: 2px solid #fff;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  font-size: inherit;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.15s ease;
}

.mascot-badge:hover {
  transform: scale(1.05);
}

.mascot-badge:active {
  transform: scale(0.95);
}

.mascot-badge:focus-visible {
  outline: 3px solid #ffb300;
  outline-offset: 2px;
}

.mascot-avatar {
  font-size: 32px;
  line-height: 1;
  display: inline-block;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mascot-avatar.mascot-sing {
  animation: mascot-hop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes mascot-hop {
  0%, 100% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-10px) scale(1.2) rotate(-8deg); }
  70% { transform: translateY(0) scale(0.95) rotate(5deg); }
}

.mascot-note {
  font-size: 20px;
  animation: mascot-note-bob 1.8s ease-in-out infinite alternate;
}

@keyframes mascot-note-bob {
  0% { transform: translateY(0) rotate(-6deg); }
  100% { transform: translateY(-4px) rotate(8deg); }
}

.mode-toggles {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.7);
  padding: 4px;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.mode-tab {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: #555;
  transition: all 0.2s ease;
}

.mode-tab.active {
  background: linear-gradient(135deg, #ab47bc 0%, #8e24aa 100%);
  color: #fff;
  box-shadow: 0 3px 8px rgba(142, 36, 170, 0.35);
}

.song-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  background: #ffffff;
  border: 2px solid #ab47bc;
  color: #8e24aa;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s ease, background 0.15s ease;
}

.tool-btn:hover {
  transform: scale(1.04);
}

.tool-btn:active {
  transform: scale(0.95);
}

.tool-btn.play-btn {
  background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
  color: #fff;
  border-color: #ffe082;
}

/* ========================================================
   Xylophone Stage & Wooden Rails
   ======================================================== */
.xylo-stage {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 440px;
  flex: 1;
  min-height: 0;
  touch-action: none;
}

.wood-rail {
  position: absolute;
  top: 10px;
  bottom: 10px;
  width: 22px;
  background: var(--rail-wood);
  border-radius: 11px;
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.4),
    inset 0 -2px 4px rgba(0, 0, 0, 0.4),
    0 8px 18px rgba(0, 0, 0, 0.22);
  z-index: 5;
  pointer-events: none;
}

.rail-left {
  left: 22px;
  transform: rotate(-2.5deg);
}

.rail-right {
  right: 22px;
  transform: rotate(2.5deg);
}

.xylo-frame {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  gap: clamp(4px, 1.2vh, 8px);
  width: 100%;
  height: 100%;
  max-height: 520px;
  touch-action: none;
}

/* ========================================================
   Rainbow Bars
   ======================================================== */
.xylo-bar {
  position: relative;
  flex: 1 1 0;
  min-height: 32px;
  max-height: 52px;
  height: auto;
  border-radius: 26px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  box-shadow:
    inset 0 4px 6px rgba(255, 255, 255, 0.55),
    inset 0 -5px 8px rgba(0, 0, 0, 0.25),
    0 6px 14px rgba(0, 0, 0, 0.16);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  margin: 0 auto;
  outline: none;
  transition: transform 0.08s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.08s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.xylo-bar:focus-visible {
  outline: 4px solid #ffb300;
  outline-offset: 4px;
}

.xylo-hit {
  transform: scale(0.96) translateY(2px) !important;
  filter: brightness(1.3) contrast(1.15) !important;
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.7),
    0 2px 6px rgba(0, 0, 0, 0.2) !important;
}

/* Rubber grommet and silver screw pins */
.bar-pin {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 13px;
  height: 13px;
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #b0bec5 55%, #78909c 100%);
  border-radius: 50%;
  border: 2px solid #37474f;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

.pin-left { left: 10px; }
.pin-right { right: 10px; }

/* Note Name & Letter Labels */
.bar-solfege {
  font-size: 19px;
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.bar-center-cue {
  font-size: 20px;
  color: #ffffff;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bar-letter {
  font-size: 16px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.16);
  padding: 2px 8px;
  border-radius: 12px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

/* Song Mode Guide Star Indicator */
.guide-star {
  font-size: 26px;
  filter: drop-shadow(0 0 8px #ffe57f);
  animation: star-bounce 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) infinite alternate;
}

@keyframes star-bounce {
  0% { transform: scale(0.9) rotate(-8deg); }
  100% { transform: scale(1.3) rotate(12deg); }
}

.bar-target-glow {
  animation: target-bar-glow 0.8s ease-in-out infinite alternate !important;
}

@keyframes target-bar-glow {
  0% { filter: brightness(1); }
  100% { filter: brightness(1.28) drop-shadow(0 0 12px #ffe57f); }
}

/* ========================================================
   Floating Notes & Confetti Particles
   ======================================================== */
.notes-layer,
.sparkles-layer,
.confetti-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}

.floating-note {
  position: absolute;
  font-size: 32px;
  line-height: 1;
  pointer-events: none;
  animation: note-rise-sway 0.9s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes note-rise-sway {
  0% {
    transform: translate(0, 0) scale(0.5) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx, 0), -65px) scale(1.25) rotate(var(--rot, 25deg));
    opacity: 0;
  }
}

.sparkle-dot {
  position: absolute;
  width: 14px;
  height: 14px;
  background: radial-gradient(circle, #ffffff 0%, #ffeb3b 60%, transparent 100%);
  border-radius: 50%;
  animation: sparkle-burst 0.7s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes sparkle-burst {
  0% { transform: translate(0, 0) scale(0.2); opacity: 1; }
  100% { transform: translate(var(--sx, 0), var(--sy, 0)) scale(1.3); opacity: 0; }
}

.confetti-piece {
  position: absolute;
  width: 12px;
  height: 16px;
  border-radius: 3px;
  animation: confetti-drop linear forwards;
}

@keyframes confetti-drop {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--cx, 0), var(--cy, 450px)) rotate(var(--crot, 720deg));
    opacity: 0;
  }
}

/* ========================================================
   Compact / Landscape Viewport Optimization
   ======================================================== */
@media (max-height: 560px) {
  .xylo-field {
    padding: 4px 10px 10px;
  }
  .xylo-toolbar {
    margin-bottom: 6px;
    gap: 6px;
  }
  .bar-solfege {
    font-size: 16px;
  }
  .bar-letter {
    font-size: 13px;
    padding: 1px 6px;
  }
  .guide-star {
    font-size: 20px;
  }
}

/* ========================================================
   Reduced Motion
   ======================================================== */
@media (prefers-reduced-motion: reduce) {
  .ambient-cloud,
  .mascot-avatar.mascot-sing,
  .mascot-note,
  .guide-star,
  .bar-target-glow,
  .floating-note,
  .sparkle-dot,
  .confetti-piece {
    animation: none !important;
  }
  .xylo-bar,
  .tool-btn,
  .mode-tab,
  .mascot-badge {
    transition: none !important;
  }
}
