/* Loopkins — Mix screen (drag rebuild). All classes prefixed mx- so nothing here collides
   with the shared styles.css. Consumes the shared paper/ink tokens from :root (styles.css)
   with safe fallbacks so this still holds up if ever loaded alone. */

/* ---------- transport ---------- */
.mx-transport { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-bottom: 10px; }
.mx-beatbar { display: flex; gap: 5px; margin-right: auto; }
.mx-pip { width: 12px; height: 12px; border-radius: 50%; background: var(--line-soft, #a89678);
  transition: transform .05s, background .05s; }
.mx-pip.mx-on { background: var(--accent, #ffd23f); transform: scale(1.5); box-shadow: 0 0 0 2px var(--line, #2c2622); }
.mx-pip.mx-downbeat.mx-on { background: var(--cat-beat, #d1495b); box-shadow: 0 0 0 2px var(--line, #2c2622); }

.mx-tbtn { font-family: var(--font-hand, cursive); font-size: 17px; font-weight: 700; color: var(--ink, #2c2622);
  background: var(--card, #fffaf2); border: 2px solid var(--line, #2c2622); border-radius: var(--radius-tab, 16px);
  padding: 12px 18px; cursor: pointer; min-height: 48px; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; box-shadow: 2px 2px 0 var(--line, #2c2622); transition: transform .08s, box-shadow .08s; }
.mx-tbtn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line, #2c2622); }
.mx-tbtn.mx-rec { border-color: var(--danger, #d1495b); color: var(--danger, #d1495b); }
.mx-tbtn.mx-rec.mx-recording { background: var(--danger, #d1495b); color: #fff; border-color: var(--danger, #d1495b);
  animation: mx-pulse 1s infinite; }

.mx-hint { font-family: var(--font-body, sans-serif); color: var(--ink-soft, #5b534a); font-size: 15px; text-align: center; margin: 0 0 10px;
  animation: mx-hint-nudge 1.8s ease-in-out infinite; } /* only ever visible while the stage is empty (display:none otherwise), so this costs nothing once filled */

/* ---------- tactile press feedback — every button/slot/tray-item gets this on pointerdown
   (mixer.js pressFx()), not just :active, because setPointerCapture makes :active unreliable
   on iPad for the drag-tracked elements. ---------- */
.mx-press { animation: mx-press-fx .28s cubic-bezier(.34, 1.56, .64, 1) 1; }

/* ---------- slots (top row of drop targets — "draw your band here") ---------- */
.mx-slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px;
  padding: 18px; margin-bottom: 18px; border: 3px dashed var(--line-soft, #a89678);
  border-radius: var(--radius-card, 22px); background: var(--paper-soft, #efe4cd);
  --mx-energy: 1; /* reward escalation multiplier, updated in renderSlots() as slots fill */ }

.mx-slot { touch-action: none; -webkit-user-select: none; user-select: none;
  position: relative; /* anchors the ::after ring-pulse */
  width: clamp(64px, 12vw, 100px); height: clamp(64px, 12vw, 100px); border-radius: 50%;
  border: 3px dashed var(--line-soft, #a89678); background: var(--card, #fffaf2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 4px; cursor: grab; color: var(--ink, #2c2622); font: inherit;
  transition: border-color .12s, background .12s, transform .08s, box-shadow .12s; }
.mx-slot .mx-slot-plus { font-size: 26px; color: var(--line-soft, #a89678); line-height: 1; }
.mx-slot.mx-filled { cursor: grab; border-style: solid; border-color: var(--line, #2c2622);
  background: color-mix(in srgb, var(--c, var(--cat-fallback, #8a8172)) 32%, var(--card, #fffaf2));
  box-shadow: 2px 2px 0 var(--c, var(--cat-fallback, #8a8172)); }
.mx-slot.mx-filled:active { transform: scale(.94); cursor: grabbing; }
.mx-slot-avatar { width: 64%; height: 64%; pointer-events: none; }
.mx-slot-name { font-family: var(--font-hand, cursive); font-size: 11px; font-weight: 700; max-width: 92%; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.mx-slot.mx-slot-hover { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent, #ffd23f) 65%, transparent); }
.mx-slot.mx-slot-hover-invalid { box-shadow: 0 0 0 5px color-mix(in srgb, var(--danger, #d1495b) 65%, transparent); }
.mx-slot.mx-dragsource-active { opacity: .35; }

/* ring pulse (drop + cheer) — a pseudo-element ring that scales+fades; transform/opacity only */
.mx-slot::after { content: ''; position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid var(--c, var(--accent, #ffd23f)); opacity: 0; transform: scale(1); pointer-events: none; }
.mx-slot.mx-ring-pulse::after { animation: mx-ring .5s ease-out 1; }
.mx-slot.mx-cheer-ring::after { animation: mx-cheer-ring-anim .9s ease-out 1; }

/* beat-synced squash-and-stretch hop — driven from mixer.js's rAF tick, once per NEW beat
   (engine.progress * manifest.bars*4), not a generic infinite loop. --mx-energy (set on
   .mx-slots as slots fill) scales the amplitude so a fuller stage bounces livelier. */
.mx-slot-avatar.mx-beat-hit { animation: mx-hop .32s cubic-bezier(.34, 1.56, .64, 1) 1; }
.mx-slot-avatar.mx-beat-hit.mx-beat-down { animation: mx-hop-down .36s cubic-bezier(.34, 1.56, .64, 1) 1; }

/* drop-in "plop" when a character lands on a slot */
.mx-slot-avatar.mx-drop-in { animation: mx-plop .45s cubic-bezier(.34, 1.56, .64, 1) 1; }

/* the all-8-full reward cheer — qualified with .mx-slot.mx-filled so its specificity (4
   classes) beats .mx-slot-avatar.mx-beat-hit.mx-beat-down (3 classes): a downbeat landing
   mid-celebration must not visibly interrupt the cheer bounce. */
.mx-slot.mx-filled .mx-slot-avatar.mx-cheer { animation: mx-cheer-bounce .9s cubic-bezier(.34, 1.56, .64, 1) 1; }

/* ---------- tray (bottom scrollable strip of draggable characters) ----------
   Characters keep their JS-set category-colored strokes (--c set inline via
   mixer.js) — they sit on a light "sticker" card here so those strokes (yellow
   ones especially) stay legible against the surrounding paper. */
.mx-tray { display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden; touch-action: pan-x;
  padding: 10px 6px 14px; margin-bottom: 4px; -webkit-overflow-scrolling: touch; }
.mx-tray-empty { font-family: var(--font-body, sans-serif); color: var(--ink-soft, #5b534a); font-size: 15px; padding: 20px; text-align: center; width: 100%; }

.mx-trayitem { touch-action: none; -webkit-user-select: none; user-select: none;
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-width: 76px; min-height: 92px; padding: 10px 8px; border-radius: var(--radius-tab, 16px); cursor: grab;
  background: var(--card, #fffaf2); border: 2px solid var(--c, var(--line-soft, #a89678)); color: var(--ink, #2c2622); font: inherit;
  box-shadow: 2px 2px 0 var(--line, #2c2622); transition: transform .08s, background .1s, opacity .15s, box-shadow .08s; }
.mx-trayitem:active { transform: translate(2px, 2px) scale(.97); cursor: grabbing; box-shadow: 0 0 0 var(--line, #2c2622); }
.mx-trayitem:not(:disabled):not(.mx-inuse) { background: color-mix(in srgb, var(--c, var(--cat-fallback, #8a8172)) 12%, var(--card, #fffaf2)); }
.mx-trayitem-avatar { width: 56px; height: 56px; display: grid; place-items: center; pointer-events: none; }
.mx-trayitem-name { font-family: var(--font-hand, cursive); font-size: 12px; font-weight: 700; max-width: 84px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.mx-trayitem.mx-inuse { opacity: .4; cursor: default; box-shadow: none; }
.mx-trayitem.mx-unavailable { opacity: .32; cursor: not-allowed; box-shadow: none; }

/* idle "breathing" — only while the stage is totally empty (mx-idle set in renderSlots()),
   so the tray never looks dead, and it steps aside the moment the mix is doing the talking. */
.mx-tray.mx-idle .mx-trayitem:not(.mx-unavailable) .mx-trayitem-avatar { animation: mx-idle-breathe 2.6s ease-in-out infinite; }
.mx-tray.mx-idle .mx-trayitem:nth-child(3n+2):not(.mx-unavailable) .mx-trayitem-avatar { animation-delay: .35s; }
.mx-tray.mx-idle .mx-trayitem:nth-child(3n+3):not(.mx-unavailable) .mx-trayitem-avatar { animation-delay: .7s; }

/* ---------- drag ghost ---------- */
.mx-ghostlayer { position: fixed; inset: 0; pointer-events: none; z-index: 999; }
.mx-ghost { position: fixed; left: 0; top: 0; transform: translate(-50%, -50%) scale(1.12);
  width: 84px; height: 84px; border-radius: var(--radius-tab, 26px); display: grid; place-items: center;
  background: color-mix(in srgb, var(--c, var(--cat-fallback, #8a8172)) 30%, var(--card, #fffaf2));
  box-shadow: 3px 4px 0 var(--line, #2c2622), 0 10px 18px rgba(44,38,34,.22);
  pointer-events: none; }

/* ---------- removal "poof" + reward confetti — both spawned into the shared ghostLayer
   (position: fixed; inset: 0), same overlay the drag ghost uses. ---------- */
.mx-poof { position: fixed; left: 0; top: 0; width: 54px; height: 54px;
  transform: translate(-50%, -50%) scale(.6); opacity: .85; border-radius: 50%;
  background: color-mix(in srgb, var(--c, var(--cat-fallback, #8a8172)) 55%, transparent);
  pointer-events: none; animation: mx-poof-anim .4s ease-out forwards; }

.mx-confetti-canvas { position: fixed; inset: 0; pointer-events: none; }

/* ---------- fallback avatar (used only if ctx.renderCharacter isn't wired up yet) ---------- */
.mx-fallback-avatar { display: grid; place-items: center; }

/* ---------- save area ---------- */
.mx-save { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 16px;
  padding: 14px 18px; background: var(--card, #fffaf2);
  border: 2px solid var(--line, #2c2622); border-radius: var(--radius-card, 20px); box-shadow: 3px 3px 0 var(--line, #2c2622); }
.mx-save audio { height: 40px; }

/* ---------- animations ---------- */
@keyframes mx-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* Beat hop — a musical squash-and-stretch, not a generic bob loop. --mx-energy (1 -> ~1.56 as
   the stage fills, see .mx-slots) scales the amplitude so a fuller band bounces livelier. */
@keyframes mx-hop {
  0%   { transform: scale(1, 1) translateY(0); }
  30%  { transform: scale(calc(1 + .12 * var(--mx-energy, 1)), calc(1 - .12 * var(--mx-energy, 1))) translateY(calc(2px * var(--mx-energy, 1))); }
  58%  { transform: scale(calc(1 - .08 * var(--mx-energy, 1)), calc(1 + .16 * var(--mx-energy, 1))) translateY(calc(-9px * var(--mx-energy, 1))); }
  100% { transform: scale(1, 1) translateY(0); }
}
/* Downbeats hit harder. */
@keyframes mx-hop-down {
  0%   { transform: scale(1, 1) translateY(0); }
  28%  { transform: scale(calc(1 + .2 * var(--mx-energy, 1)), calc(1 - .2 * var(--mx-energy, 1))) translateY(calc(3px * var(--mx-energy, 1))); }
  56%  { transform: scale(calc(1 - .12 * var(--mx-energy, 1)), calc(1 + .26 * var(--mx-energy, 1))) translateY(calc(-13px * var(--mx-energy, 1))); }
  100% { transform: scale(1, 1) translateY(0); }
}

/* Drop "plop": pops in, overshoots into a squash, springs to rest. */
@keyframes mx-plop {
  0%   { transform: scale(.25, .25); opacity: 0; }
  50%  { transform: scale(1.25, .78); opacity: 1; }
  72%  { transform: scale(.9, 1.12); }
  100% { transform: scale(1, 1); opacity: 1; }
}

/* Ring pulse around a slot on drop. */
@keyframes mx-ring {
  0%   { opacity: .9; transform: scale(.7); }
  100% { opacity: 0; transform: scale(1.55); }
}
/* Bigger/longer variant for the full-stage cheer. */
@keyframes mx-cheer-ring-anim {
  0%   { opacity: .95; transform: scale(.7); }
  60%  { opacity: .5; transform: scale(1.5); }
  100% { opacity: 0; transform: scale(1.9); }
}

/* Removal poof — a soft circle that blooms and fades where the character used to be. */
@keyframes mx-poof-anim {
  0%   { transform: translate(-50%, -50%) scale(.6); opacity: .85; }
  100% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
}

/* Tactile press: quick squash + spring-back. */
@keyframes mx-press-fx {
  0%   { transform: scale(1); }
  40%  { transform: scale(.86); }
  100% { transform: scale(1); }
}

/* Idle breathing so the tray never looks dead while the stage is empty. */
@keyframes mx-idle-breathe {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50%      { transform: scale(1.06) rotate(-2deg); }
}

/* Gentle nudge to draw the eye to the empty-stage hint. */
@keyframes mx-hint-nudge {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

/* All-8-full reward cheer — a bigger, happier bounce+wiggle. Kid-joyful only. */
@keyframes mx-cheer-bounce {
  0%   { transform: scale(1, 1) rotate(0deg); }
  20%  { transform: scale(1.22, .82) rotate(-6deg); }
  40%  { transform: scale(.88, 1.24) rotate(5deg); }
  60%  { transform: scale(1.14, .9) rotate(-3deg); }
  80%  { transform: scale(.95, 1.08) rotate(2deg); }
  100% { transform: scale(1, 1) rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .mx-hint, .mx-tbtn.mx-rec.mx-recording,
  .mx-slot-avatar, .mx-press, .mx-poof,
  .mx-slot.mx-ring-pulse::after, .mx-slot.mx-cheer-ring::after,
  .mx-tray.mx-idle .mx-trayitem-avatar { animation: none !important; }
}

@media (max-width: 720px) {
  .mx-slots { gap: 10px; padding: 12px; }
  .mx-trayitem { min-width: 68px; }
}

:focus-visible { outline: 3px solid var(--focus, #1d6fe0); outline-offset: 2px; }
.mx-slot:focus-visible, .mx-trayitem:focus-visible, .mx-tbtn:focus-visible { outline-offset: 3px; }
