/* ==========================================================
   ארץ המוזיקה.

   שפת העולם: במה. וילון קטיפה, רצפת פרקט מבריקה, זרקורים
   צבעוניים מלמעלה, וקווי חמשה עדינים באוויר. סגול-מג'נטה חם
   עם זהב, לא כחול קר.

   כל מה שמשמיע צליל גם *זז* - זה עולם שבו אפשר לראות מוזיקה.
   ========================================================== */

:root {
  --mu-back: #2a1436;
  --mu-mid: #46215a;
  --mu-near: #6b3080;
  --mu-gold: #f2c83c;
  --mu-rose: #e08ac0;
}

/* בסיס משותף לכל מסכי העולם */
.rh-stage, .ml-stage, .pt2-stage, .wh-stage, .cm-stage {
  position: absolute;
  overflow: hidden;
  border-radius: clamp(14px, 2.4vmin, 26px);
  background:
    /* זרקורים מלמעלה */
    radial-gradient(42% 74% at 22% -12%, rgba(255, 200, 120, .22), transparent 66%),
    radial-gradient(38% 70% at 50% -14%, rgba(200, 160, 255, .24), transparent 64%),
    radial-gradient(42% 74% at 78% -12%, rgba(255, 150, 200, .2), transparent 66%),
    linear-gradient(180deg, var(--mu-back) 0%, var(--mu-mid) 54%, var(--mu-near) 100%);
}
/* רצפת הבמה */
.rh-stage::after, .ml-stage::after, .pt2-stage::after,
.wh-stage::after, .cm-stage::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 15%;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(60, 30, 16, .3) 0 3px, transparent 3px 74px),
    linear-gradient(180deg, #a8763c, #6d4a24);
  box-shadow: inset 0 8px 16px rgba(30, 10, 20, .5);
}
/* וילון קטיפה בשני הצדדים */
.rh-stage::before, .ml-stage::before, .pt2-stage::before,
.wh-stage::before, .cm-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-repeat: no-repeat;
  background-size: 15% 100%, 15% 100%;
  background-position: left top, right top;
  background-image:
    repeating-linear-gradient(90deg, #7a1f4a 0 14px, #5a1236 14px 30px),
    repeating-linear-gradient(90deg, #5a1236 0 16px, #7a1f4a 16px 30px);
  -webkit-mask-image:
    linear-gradient(90deg, #000 0 92%, transparent),
    linear-gradient(270deg, #000 0 92%, transparent);
  mask-image:
    linear-gradient(90deg, #000 0 92%, transparent),
    linear-gradient(270deg, #000 0 92%, transparent);
  -webkit-mask-size: 15% 100%, 15% 100%;
  mask-size: 15% 100%, 15% 100%;
  -webkit-mask-position: left top, right top;
  mask-position: left top, right top;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

/* כפתור "להשמיע שוב" - זהה בכל חמשת המשחקים */
.rh-again, .ml-again, .pt2-again, .wh-again {
  position: absolute;
  inset-inline-start: clamp(10px, 2vmin, 22px);
  bottom: clamp(10px, 2vmin, 22px);
  width: clamp(52px, 9vmin, 100px);
  aspect-ratio: 1;
  border: none;
  border-radius: 50%;
  background: rgba(122, 31, 74, .9);
  box-shadow: 0 4px 0 rgba(62, 12, 38, .95);
  padding: clamp(9px, 1.8vmin, 20px);
  cursor: pointer;
  z-index: 5;
}
.rh-again svg, .ml-again svg, .pt2-again svg, .wh-again svg {
  width: 100%; height: 100%; display: block;
}
.rh-again:active, .ml-again:active, .pt2-again:active, .wh-again:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(62, 12, 38, .95);
}

/* ==========================================================
   1. חיקוי קצב
   ========================================================== */
.rh-stage {
  inset: clamp(56px, 9vmin, 92px) clamp(8px, 1.6vmin, 18px) clamp(8px, 1.6vmin, 18px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.4vmin, 30px);
}
/*
  התבנית מוצגת גם בעין: עיגול לכל הקשה, ורווח לכל שתיקה.
  רווח קצר וארוך נראים שונים - ולכן הילד יכול *לראות* את
  הקצב, לא רק לזכור אותו.
*/
.rh-pattern, .rh-mine {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(30px, 5.4vmin, 60px);
}
.rh-beat, .rh-slot {
  width: clamp(24px, 4.4vmin, 48px);
  aspect-ratio: 1;
  border-radius: 50%;
  flex: 0 0 auto;
}
.rh-beat {
  background: rgba(255, 244, 224, .22);
  border: clamp(2px, .5vmin, 4px) solid rgba(255, 244, 224, .5);
  transition: background .12s ease, transform .12s ease;
}
.rh-beat.hit {
  background: var(--mu-gold);
  transform: scale(1.28);
  box-shadow: 0 0 clamp(8px, 1.6vmin, 18px) rgba(242, 200, 60, .95);
}
.rh-gap { display: block; flex: 0 0 auto; height: 4px; border-radius: 2px; }
.rh-gap.s { width: clamp(14px, 2.6vmin, 30px); background: rgba(255, 244, 224, .2); }
.rh-gap.l { width: clamp(44px, 8vmin, 92px); background: rgba(255, 244, 224, .2); }
.rh-pattern.show .rh-gap { background: rgba(242, 200, 60, .75); height: 7px; }

.rh-slot {
  background: rgba(255, 244, 224, .1);
  border: clamp(2px, .5vmin, 4px) dashed rgba(255, 244, 224, .35);
  margin-inline: clamp(5px, 1vmin, 12px);
}
.rh-slot.on { background: rgba(255, 244, 224, .4); border-style: solid; }
.rh-slot.good { background: #7fe08a; border-color: #3f9e56; }
.rh-slot.off { background: #f0a86a; border-color: #c47a34; }

/* התוף - שטח נגיעה ענק, כי זה כל המשחק */
.rh-drum {
  position: relative;
  z-index: 2;
  width: min(58%, 380px);
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  filter: drop-shadow(0 10px 18px rgba(20, 6, 16, .6));
}
.rh-drum svg { width: 100%; height: auto; display: block; }
.rh-drum.live { animation: rhLive 1.8s ease-in-out infinite; }
@keyframes rhLive {
  0%, 100% { filter: drop-shadow(0 10px 18px rgba(20, 6, 16, .6)); }
  50%      { filter: drop-shadow(0 0 22px rgba(242, 200, 60, .7)); }
}
.rh-drum.boom { animation: rhBoom .16s ease; }
@keyframes rhBoom {
  0%   { transform: scale(1.05, .94); }
  100% { transform: scale(1, 1); }
}
.rh-drum.won { animation: rhWon .5s ease 3; }
@keyframes rhWon {
  0%, 100% { transform: rotate(0); }
  30%      { transform: rotate(-3deg); }
  70%      { transform: rotate(3deg); }
}

/* ==========================================================
   2. רצף מוזיקלי
   ========================================================== */
.ml-stage, .wh-stage {
  inset: clamp(56px, 9vmin, 92px) clamp(8px, 1.6vmin, 18px) clamp(8px, 1.6vmin, 18px);
  display: grid;
  place-items: center;
}
.ml-row, .wh-row {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(10px, 2.4vmin, 36px);
  width: min(80%, 900px);
}
/* כלי נגינה על הבמה: מסגרת זהב, וגוון משלו */
.ml-inst, .wh-inst {
  position: relative;
  flex: 0 1 clamp(84px, 15vmin, 188px);
  aspect-ratio: 1;
  border: clamp(3px, .6vmin, 6px) solid rgba(242, 200, 60, .55);
  border-radius: clamp(14px, 2.4vmin, 26px);
  background: radial-gradient(70% 70% at 50% 20%,
              color-mix(in srgb, var(--hue) 26%, transparent), rgba(255, 255, 255, .06));
  padding: clamp(6px, 1.2vmin, 14px);
  cursor: pointer;
  transition: transform .14s ease, box-shadow .2s ease;
  filter: drop-shadow(0 6px 12px rgba(20, 6, 16, .6));
}
.ml-inst svg, .wh-inst svg { width: 100%; height: 100%; display: block; }
.ml-inst:active, .wh-inst:active { transform: translateY(4px) scale(.96); }
/* מנגן עכשיו - קופץ ונדלק בגוון שלו */
.ml-inst.play {
  animation: mlPlay .42s cubic-bezier(.3, 1.5, .5, 1);
  box-shadow: 0 0 clamp(10px, 2vmin, 24px) var(--hue);
}
@keyframes mlPlay {
  0%   { transform: translateY(-14px) scale(1.1); }
  100% { transform: translateY(0) scale(1); }
}
.ml-inst.miss, .wh-inst.miss { animation: muShake .38s ease; }
.wh-inst.ok { box-shadow: 0 0 clamp(10px, 2vmin, 24px) #7fe08a; border-color: #7fe08a; }
@keyframes muShake {
  0%, 100% { transform: translateX(0); }
  30%      { transform: translateX(-9px); }
  70%      { transform: translateX(9px); }
}
/* תו שעולה מהכלי כשהוא מנגן */
.ml-note {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 34%;
  pointer-events: none;
  animation: mlNote 1.2s ease-out forwards;
}
.ml-note svg { width: 100%; height: 100%; display: block; }
@keyframes mlNote {
  0%   { transform: translate(-50%, 0) scale(.5); opacity: 0; }
  25%  { opacity: 1; }
  100% { transform: translate(calc(-50% + 30px), -90px) scale(1) rotate(16deg); opacity: 0; }
}

/* ==========================================================
   3. גבוה או נמוך
   ========================================================== */
.pt2-stage {
  inset: clamp(56px, 9vmin, 92px) clamp(8px, 1.6vmin, 18px) clamp(8px, 1.6vmin, 18px);
  display: grid;
  place-items: center;
}
.pt2-row {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 3.4vmin, 52px);
}
.pt2-tone {
  width: clamp(88px, 16vmin, 200px);
  aspect-ratio: 1;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  transition: transform .14s ease;
  filter: drop-shadow(0 6px 12px rgba(20, 6, 16, .6));
}
.pt2-tone svg { width: 100%; height: 100%; display: block; }
.pt2-tone:active { transform: translateY(4px) scale(.96); }
/* מצלצל עכשיו - טבעות שיוצאות ממנו */
.pt2-tone.ring { animation: ptRing .52s ease-out; }
@keyframes ptRing {
  0%   { filter: drop-shadow(0 6px 12px rgba(20, 6, 16, .6)); transform: scale(1); }
  40%  { filter: drop-shadow(0 0 26px rgba(255, 244, 200, 1)); transform: scale(1.1); }
  100% { filter: drop-shadow(0 6px 12px rgba(20, 6, 16, .6)); transform: scale(1); }
}
.pt2-tone.miss { animation: muShake .38s ease; }
.pt2-tone.right { animation: ptRight .55s ease; }
@keyframes ptRight {
  0%, 100% { transform: scale(1); }
  45%      { transform: scale(1.16); }
}

/* ==========================================================
   4. איזה כלי ניגן
   ========================================================== */
/*
  הרמקול במרכז ולא ליד הכלי: אם הוא היה מסמן את המקור, הוא
  היה מסגיר את התשובה - וזה משחק שכולו אוזניים.
*/
.wh-speaker {
  position: absolute;
  left: 50%;
  top: 22%;
  width: clamp(48px, 8.6vmin, 104px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  border: clamp(4px, .8vmin, 8px) solid var(--mu-gold);
  transition: opacity .2s ease;
  z-index: 2;
}
.wh-speaker.on { opacity: 1; animation: whWave 1.1s ease-out infinite; }
@keyframes whWave {
  0%   { transform: translate(-50%, -50%) scale(.4); opacity: .95; }
  100% { transform: translate(-50%, -50%) scale(2.2); opacity: 0; }
}

/* ==========================================================
   5. בנה מנגינה
   ========================================================== */
.cm-stage {
  inset: clamp(56px, 9vmin, 92px) clamp(8px, 1.6vmin, 18px) clamp(112px, 20vmin, 182px);
}
/* חמישה קווי חמשה - הרקע שעליו המנגינה נבנית */
.cm-staff {
  position: absolute;
  inset: 24% 12% 32%;
  z-index: 2;
  background: repeating-linear-gradient(180deg,
    rgba(255, 244, 224, .5) 0 3px, transparent 3px 25%);
  pointer-events: none;
}
.cm-bar {
  position: absolute;
  inset: 18% 12% 26%;
  z-index: 3;
  display: flex;
  align-items: stretch;
  gap: clamp(6px, 1.4vmin, 20px);
  /*
    שמאל לימין, בניגוד לשאר האפליקציה: זו חמשה, ומנגינה
    נקראת לפי כיוון התווים. ב-RTL השקע הראשון נחת בקצה הימני
    והמנגינה נבנתה אחורה.
  */
  direction: ltr;
}
/*
  שקע = עמודה שלמה בגובה החמשה. התו יושב בגובה שמייצג את
  הצליל שלו, ולכן המנגינה נראית עולה ויורדת.
*/
.cm-slot {
  position: relative;
  flex: 1 1 0;
  border-radius: clamp(8px, 1.6vmin, 16px);
  border: clamp(2px, .5vmin, 4px) dashed rgba(255, 244, 224, .3);
  background: rgba(255, 255, 255, .04);
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease;
}
.cm-slot.full {
  border-style: solid;
  border-color: color-mix(in srgb, var(--hue) 70%, transparent);
  background: color-mix(in srgb, var(--hue) 14%, transparent);
}
.cm-dot {
  position: absolute;
  left: 50%;
  top: var(--y, 50%);
  width: clamp(34px, 6vmin, 70px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: cmDrop .36s cubic-bezier(.3, 1.5, .5, 1);
}
.cm-dot svg { width: 100%; height: 100%; display: block; }
@keyframes cmDrop {
  0%   { transform: translate(-50%, -160%) scale(1.2); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.cm-slot.ring { background: color-mix(in srgb, var(--hue) 40%, transparent); }
.cm-slot.ring .cm-dot { animation: cmRing .4s ease; }
@keyframes cmRing {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  45%      { transform: translate(-50%, -50%) scale(1.3); }
}

/* כפתור נגן - נדלק רק כשיש מה לנגן */
.cm-play {
  position: absolute;
  inset-inline-end: clamp(10px, 2vmin, 22px);
  bottom: clamp(6px, 1.2vmin, 14px);
  width: clamp(58px, 10vmin, 112px);
  aspect-ratio: 1;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  z-index: 5;
  opacity: .4;
  filter: grayscale(.7) drop-shadow(0 5px 9px rgba(20, 6, 16, .6));
  transition: opacity .2s ease, filter .2s ease, transform .14s ease;
}
.cm-play svg { width: 100%; height: 100%; display: block; }
.cm-play.armed {
  opacity: 1;
  filter: grayscale(0) drop-shadow(0 6px 12px rgba(40, 140, 70, .7));
  animation: cmReady 1.5s ease-in-out infinite;
}
@keyframes cmReady {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.07); }
}
.cm-play:active { transform: scale(.93); }

.cm-tray {
  position: absolute;
  inset-inline: clamp(8px, 1.6vmin, 18px);
  bottom: clamp(8px, 1.6vmin, 18px);
  min-height: clamp(92px, 16vmin, 152px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(6px, 1.4vmin, 20px);
  padding: clamp(8px, 1.4vmin, 16px);
  border-radius: clamp(14px, 2.4vmin, 26px);
  background:
    radial-gradient(80% 120% at 50% 0%, rgba(242, 200, 60, .16), transparent 70%),
    linear-gradient(180deg, rgba(90, 18, 54, .95), rgba(50, 10, 34, .96));
  border: clamp(3px, .6vmin, 6px) solid rgba(242, 200, 60, .45);
}
/*
  גובה הכפתור במגש מציג את גובה הצליל: התו הנמוך נמוך, הגבוה
  גבוה. זה קישור שאפשר לראות בין סימן לצליל.
*/
.cm-tone {
  width: clamp(34px, 6vmin, 72px);
  height: var(--h, 60%);
  min-height: clamp(34px, 6vmin, 72px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  filter: drop-shadow(0 4px 8px rgba(20, 6, 16, .6));
}
.cm-tone svg { width: 100%; height: auto; display: block; pointer-events: none; }
.cm-tone:active { cursor: grabbing; }
.cm-tray.hint-pulse { box-shadow: 0 0 0 4px rgba(242, 200, 60, .7); }

@media (prefers-reduced-motion: reduce) {
  .rh-drum.live, .rh-drum.boom, .rh-drum.won, .ml-inst.play, .ml-note,
  .pt2-tone.ring, .pt2-tone.right, .wh-speaker.on, .cm-dot, .cm-play.armed,
  .cm-slot.ring .cm-dot, .ml-inst.miss, .wh-inst.miss, .pt2-tone.miss {
    animation: none;
  }
}

/* ==========================================================
   מפת ארץ המוזיקה וזהות היצורים - חיים ברקע
   ========================================================== */
.mm-spots { animation: mmSpots 7s ease-in-out infinite; transform-origin: 50% 0; }
@keyframes mmSpots {
  0%, 100% { opacity: .7; transform: skewX(-1.6deg); }
  50%      { opacity: 1;  transform: skewX(1.6deg); }
}
.mm-staff { animation: mmStaff 9s ease-in-out infinite; }
@keyframes mmStaff {
  0%, 100% { opacity: .7; } 50% { opacity: 1; }
}
.mm-note { animation: mmNote 5s ease-in-out infinite; }
.mm-note.n1 { animation-duration: 6.5s; animation-delay: -2s; }
.mm-note.n2 { animation-duration: 8s; animation-delay: -4s; }
@keyframes mmNote {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50%      { transform: translateY(-30px) rotate(5deg); }
}
.mm-glow { animation: mmGlow 4s ease-in-out infinite; }
@keyframes mmGlow {
  0%, 100% { opacity: .08; } 50% { opacity: .2; }
}

/* --- זהות היצורים: כל אחד זז כמו הכלי שהוא --- */
/* מקלות התוף של תופי */
.crt-stick { animation: crtStick 1.1s ease-in-out infinite; transform-origin: 20% 80%; }
.crt-stick.s2 { animation-delay: -.55s; transform-origin: 80% 80%; }
@keyframes crtStick {
  0%, 100% { transform: rotate(0deg); }
  50%      { transform: rotate(-14deg); }
}
/* לשון הפעמון של פעמוני */
.crt-clap { animation: crtClap 1.6s ease-in-out infinite; transform-origin: 100px 160px; }
@keyframes crtClap {
  0%, 100% { transform: rotate(-9deg); }
  50%      { transform: rotate(9deg); }
}
/* נשיפות החליל של חלילי */
.crt-puff { animation: crtPuff 2.2s ease-out infinite; }
.crt-puff.p2 { animation-delay: -1.1s; }
@keyframes crtPuff {
  0%   { opacity: 0; transform: translateX(-8px); }
  40%  { opacity: .9; }
  100% { opacity: 0; transform: translateX(22px); }
}
/*
  צ'יפור. שלוש תנועות בבת אחת, וכולן באותו קצב: הכנף מכה כמו
  מקל תוף, הרגליים מקפצות, והציצית מתנדנדת. זה מה שהופך אותו
  לדמות שמזוהה עם קצב ולא לעוד ציפור.
*/
.crt-wing { animation: crtWing .62s ease-in-out infinite; transform-origin: 100px 116px; }
@keyframes crtWing {
  0%, 100% { transform: rotate(0deg); }
  50%      { transform: rotate(-24deg); }
}
.crt-hop { animation: crtHop .62s ease-in-out infinite; }
@keyframes crtHop {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}
.crt-tuft { animation: crtTuft 1.24s ease-in-out infinite; transform-origin: 132px 44px; }
@keyframes crtTuft {
  0%, 100% { transform: rotate(-7deg); }
  50%      { transform: rotate(7deg); }
}
.crt-tone { animation: crtTone 2.4s ease-out infinite; }
.crt-tone.t1 { animation-delay: -.8s; }
.crt-tone.t2 { animation-delay: -1.6s; }
@keyframes crtTone {
  0%   { transform: translateY(14px) scale(.5); opacity: 0; }
  30%  { opacity: 1; }
  100% { transform: translateY(-26px) scale(1) rotate(14deg); opacity: 0; }
}
/* שרביט המנצח של נגיני */
.crt-baton { animation: crtBaton 1.9s ease-in-out infinite; transform-origin: 146px 142px; }
@keyframes crtBaton {
  0%, 100% { transform: rotate(-11deg); }
  50%      { transform: rotate(11deg); }
}

@media (prefers-reduced-motion: reduce) {
  .mm-spots, .mm-staff, .mm-note, .mm-glow, .crt-stick, .crt-clap, .crt-puff,
  .crt-wing, .crt-hop, .crt-tuft, .crt-tone, .crt-baton { animation: none; }
}
