/* ==========================================================================
   Judy Piano Studio — "Aurora" theme
   A dark, luminous practice room: glass panels over a slow-drifting aurora,
   with the falling notes as the brightest thing on screen.
   Built to live full-screen on an iPad in landscape.
   ========================================================================== */

:root {
  /* Surfaces */
  --void: #06060f;
  --deep: #0b0a18;
  --glass: rgba(255, 255, 255, 0.055);
  --glass-hi: rgba(255, 255, 255, 0.10);
  --glass-press: rgba(255, 255, 255, 0.16);
  --stroke: rgba(255, 255, 255, 0.11);
  --stroke-hi: rgba(255, 255, 255, 0.22);

  /* Type */
  --text: #f4f2ff;
  --text-dim: #a9a3cb;
  --text-faint: #6e688f;

  /* Accents */
  --violet: #a855f7;
  --pink: #ec4899;
  --cyan: #22d3ee;
  --amber: #fbbf24;
  --grad-hot: linear-gradient(135deg, #a855f7 0%, #ec4899 100%);

  /* Hands — left is the exact pink already used for the play button and
     mode switch (--pink below), right is a matching glowing blue. Reusing
     the brand's own pink here, rather than a similar-but-different shade,
     is what makes the falling notes read as part of one app instead of a
     separate color system laid on top. */
  --right: #3b82f6;
  --right-soft: #60a5fa;
  --left: #ec4899;
  --left-soft: #f9a8d4;

  --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;

  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 20px;
  --r-pill: 999px;

  --kb-h: clamp(118px, 21vh, 190px);
  --tap: 40px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--void);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button, select, input { font-family: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
svg { display: block; }

/* --------------------------------------------------------------------------
   Aurora backdrop
   -------------------------------------------------------------------------- */
.aurora {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% -20%, #17123a 0%, transparent 60%),
    linear-gradient(180deg, #0b0a18 0%, #06060f 100%);
}

.aurora-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  will-change: transform;
}

.blob-violet {
  width: 46vw; height: 46vw;
  background: #7c3aed;
  top: -16vw; left: 4vw;
  animation: drift-a 26s ease-in-out infinite alternate;
}
.blob-cyan {
  width: 38vw; height: 38vw;
  background: #0891b2;
  bottom: -14vw; right: 8vw;
  opacity: 0.38;
  animation: drift-b 32s ease-in-out infinite alternate;
}
.blob-pink {
  width: 30vw; height: 30vw;
  background: #db2777;
  top: 22vh; right: -8vw;
  opacity: 0.3;
  animation: drift-c 38s ease-in-out infinite alternate;
}

@keyframes drift-a { to { transform: translate3d(9vw, 5vh, 0) scale(1.15); } }
@keyframes drift-b { to { transform: translate3d(-8vw, -6vh, 0) scale(1.2); } }
@keyframes drift-c { to { transform: translate3d(-5vw, 8vh, 0) scale(0.88); } }

@media (prefers-reduced-motion: reduce) {
  .aurora-blob { animation: none; }
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */
.topbar {
  position: relative;
  z-index: 20;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 16px;
  padding-top: max(9px, env(safe-area-inset-top));
  background: rgba(10, 9, 22, 0.55);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-bottom: 1px solid var(--stroke);
}

.brand { position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: rgba(168, 85, 247, 0.16);
  border: 1px solid rgba(192, 132, 252, 0.34);
  box-shadow: 0 0 22px rgba(168, 85, 247, 0.3);
  flex: 0 0 auto;
}
.brand-mark svg { width: 21px; height: 21px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.brand-name {
  font-family: var(--font-display);
  font-size: 17px; font-weight: 800; letter-spacing: -0.3px;
  background: linear-gradient(100deg, #ffffff 20%, #f0abfc 90%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-sub {
  font-size: 9.5px; font-weight: 600; letter-spacing: 1.3px;
  text-transform: uppercase; color: var(--text-faint);
}

/* Sliding segmented mode switch — true center of the bar, not just the
   leftover space between the two flanks (which skews since the brand block
   and the io-chip cluster are different widths). */
.mode-pills {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  padding: 3px;
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--stroke);
  z-index: 1;
}

.pill-btn {
  position: relative;
  z-index: 2;
  padding: 7px 20px;
  min-height: 34px;
  font-size: 13px; font-weight: 600;
  color: var(--text-dim);
  border-radius: var(--r-pill);
  transition: color 0.25s ease;
  white-space: nowrap;
}
.pill-btn.is-active { color: #fff; }

.pill-glider {
  position: absolute;
  z-index: 1;
  top: 3px; left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  border-radius: var(--r-pill);
  background: var(--grad-hot);
  box-shadow: 0 3px 16px rgba(168, 85, 247, 0.5);
  transition: transform 0.32s cubic-bezier(0.34, 1.4, 0.5, 1);
}
.mode-pills.at-free .pill-glider { transform: translateX(100%); }

.topbar-right {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Live-input chips (electronic piano + microphone) */
.io-chip {
  display: flex; align-items: center; gap: 7px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--r-pill);
  background: var(--glass);
  border: 1px solid var(--stroke);
  font-size: 12px; font-weight: 600;
  color: var(--text-dim);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  white-space: nowrap;
}
.io-button:hover { background: var(--glass-hi); border-color: var(--stroke-hi); }
.io-button:active { transform: scale(0.96); }

.io-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
  flex: 0 0 auto;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.io-chip.is-live {
  color: #fff;
  border-color: rgba(52, 211, 153, 0.5);
  background: rgba(16, 185, 129, 0.14);
}
.io-chip.is-live .io-dot {
  background: #34d399;
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.75);
  animation: pulse-dot 2s infinite;
}
.io-chip.is-warn {
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.1);
}
.io-chip.is-warn .io-dot { background: var(--amber); }
.io-chip.is-dim { opacity: 0.62; }

@keyframes pulse-dot {
  70%  { box-shadow: 0 0 0 7px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.volume { display: flex; align-items: center; gap: 8px; color: var(--text-dim); }
.vol-icon { width: 17px; height: 17px; flex: 0 0 auto; }

/* Range inputs */
.range {
  -webkit-appearance: none; appearance: none;
  height: 4px;
  width: 82px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.16);
  outline: none;
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 10px rgba(236, 72, 153, 0.75);
  cursor: pointer;
}
.range::-moz-range-thumb {
  width: 15px; height: 15px; border: none; border-radius: 50%;
  background: #fff; box-shadow: 0 0 10px rgba(236, 72, 153, 0.75);
}

/* --------------------------------------------------------------------------
   Lesson bar
   -------------------------------------------------------------------------- */
.lessonbar {
  position: relative;
  z-index: 15;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 16px;
  background: rgba(10, 9, 22, 0.4);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--stroke);
  flex-wrap: wrap;
}

.lb-group { display: flex; align-items: center; gap: 9px; min-width: 0; }
.lb-song { flex: 1 1 240px; min-width: 0; overflow: hidden; }
.lb-practice { flex: 0 0 auto; }
.lb-transport { flex: 0 0 auto; margin-left: auto; }

.select {
  appearance: none; -webkit-appearance: none;
  height: var(--tap);
  padding: 0 32px 0 13px;
  border-radius: var(--r-md);
  background: var(--glass) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' stroke='%23a9a3cb' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 11px center / 12px;
  border: 1px solid var(--stroke);
  font-size: 13px; font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.select:hover { border-color: var(--stroke-hi); }
.select option { background: #16142a; color: #fff; }

.select-song {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 320px;
  font-family: var(--font-display);
  font-weight: 700;
}
.select-difficulty { flex: 0 0 auto; }
.select-mini { height: 32px; font-size: 12px; padding: 0 28px 0 11px; background-size: 11px; }

.song-details {
  display: flex; gap: 6px; align-items: center;
  min-width: 0; flex: 0 1 auto; overflow: hidden;
}

.meta-pill {
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px;
  padding: 0 9px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--stroke);
  font-size: 11px; font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}
.meta-pill.level-easy {
  color: #6ee7b7; background: rgba(16, 185, 129, 0.13);
  border-color: rgba(52, 211, 153, 0.34);
}
.meta-pill.level-intermediate {
  color: #fcd34d; background: rgba(251, 191, 36, 0.13);
  border-color: rgba(251, 191, 36, 0.34);
}
.meta-pill.level-advanced {
  color: #fda4af; background: rgba(244, 63, 94, 0.13);
  border-color: rgba(244, 63, 94, 0.34);
}

/* Segmented controls */
.seg {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--stroke);
}

.seg-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 12px; font-weight: 600;
  color: var(--text-dim);
  transition: background 0.2s ease, color 0.2s ease;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.13);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.35);
}
.seg-hands .seg-btn:nth-child(2).is-active { background: rgba(59, 130, 246, 0.26); }
.seg-hands .seg-btn:nth-child(3).is-active { background: rgba(236, 72, 153, 0.26); }

/* Transport */
.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--glass);
  border: 1px solid var(--stroke);
  color: var(--text-dim);
  transition: all 0.18s ease;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { color: #fff; border-color: var(--stroke-hi); background: var(--glass-hi); }
.icon-btn:active { transform: scale(0.93); }

.play-btn {
  width: 50px; height: 50px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--grad-hot);
  color: #fff;
  box-shadow: 0 5px 24px rgba(168, 85, 247, 0.55);
  transition: transform 0.18s cubic-bezier(0.34, 1.5, 0.6, 1), box-shadow 0.2s ease;
}
.play-btn svg { width: 24px; height: 24px; }
.play-btn:hover { box-shadow: 0 7px 30px rgba(236, 72, 153, 0.68); }
.play-btn:active { transform: scale(0.92); }
.play-btn .ico-pause { display: none; }
.play-btn.is-playing .ico-play { display: none; }
.play-btn.is-playing .ico-pause { display: block; }

.tempo { display: flex; align-items: center; gap: 8px; }
.tempo-cap { font-size: 11px; font-weight: 600; color: var(--text-faint); }
.tempo-val {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 700;
  color: var(--pink);
  width: 36px;
}

/* --------------------------------------------------------------------------
   Falling-note stage
   -------------------------------------------------------------------------- */
.stage {
  position: relative;
  z-index: 10;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(6, 6, 15, 0.4) 0%, rgba(6, 6, 15, 0.82) 100%);
  transition: flex-grow 0.35s ease, opacity 0.3s ease;
}

/* Free Play: keep the space (so the keys stay at the bottom where her hands
   already are) but let the aurora show through it. */
.stage.canvas-hidden {
  background: none;
  pointer-events: none;
}
/* the id selector on the canvas would otherwise out-rank a bare `> *` */
.stage.canvas-hidden > *,
.stage.canvas-hidden #waterfall-canvas { display: none; }

/* …and give her a bigger keyboard while there's no music falling on it. */
body.is-free-play { --kb-h: clamp(150px, 30vh, 250px); }

#waterfall-canvas { display: block; touch-action: none; }

.hud {
  position: absolute;
  top: 12px; left: 14px;
  display: flex;
  gap: 7px;
  pointer-events: none;
}

.hud-chip {
  display: flex; align-items: baseline; gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  background: rgba(12, 10, 26, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--stroke);
  font-size: 11px;
}
.hud-chip[hidden] { display: none; }

.hud-cap {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--text-faint);
}
.hud-chip strong {
  font-family: var(--font-mono);
  font-size: 13px; font-weight: 700; color: #fff;
}
.chip-timer strong { color: var(--cyan); }
.chip-score strong { color: var(--text); }
.chip-streak strong { color: var(--amber); }
.chip-streak .flame { font-size: 11px; }
.chip-streak.is-hot {
  border-color: rgba(251, 191, 36, 0.5);
  background: rgba(251, 191, 36, 0.14);
}
.chip-streak.is-hot .flame { animation: flicker 0.9s ease-in-out infinite alternate; }
@keyframes flicker { to { transform: scale(1.25) rotate(-6deg); } }

/* Big "play this note next" readout */
.hud-target {
  position: absolute;
  top: 12px; right: 14px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  background: rgba(12, 10, 26, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--stroke);
  font-size: 13px; font-weight: 600;
  color: var(--text-dim);
  transition: border-color 0.2s ease, background 0.2s ease;
  pointer-events: none;
  max-width: 46vw;
}
.hud-target strong {
  font-family: var(--font-display);
  font-size: 17px; font-weight: 800; color: #fff;
}
.clef { font-size: 20px; line-height: 1; color: var(--text-faint); }

.hud-target.for-right {
  border-color: rgba(59, 130, 246, 0.55);
  background: rgba(59, 130, 246, 0.15);
  box-shadow: 0 0 26px rgba(59, 130, 246, 0.28);
}
.hud-target.for-right .clef { color: var(--right-soft); }
.hud-target.for-left {
  border-color: rgba(236, 72, 153, 0.55);
  background: rgba(236, 72, 153, 0.15);
  box-shadow: 0 0 26px rgba(236, 72, 153, 0.28);
}
.hud-target.for-left .clef { color: var(--left-soft); }

.hand-tag { font-size: 11px; font-weight: 600; opacity: 0.85; }

/* Hint shown when nothing is listening to her real playing */
.track-hint[hidden] { display: none; }

.track-hint {
  position: absolute;
  left: 50%; top: 54px;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 9px;
  padding: 9px 16px;
  border-radius: var(--r-pill);
  background: rgba(20, 16, 40, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(251, 191, 36, 0.32);
  font-size: 12px; font-weight: 500;
  color: #fde68a;
  max-width: min(560px, 88vw);
  text-align: center;
}
.track-hint b { font-weight: 700; color: #fff; }
.track-hint-icon { font-size: 15px; }

/* --------------------------------------------------------------------------
   Practice loop — repeat a section, and speed it up automatically
   -------------------------------------------------------------------------- */
.loopbar {
  position: relative;
  z-index: 14;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  background: rgba(10, 9, 22, 0.34);
  border-bottom: 1px solid var(--stroke);
}

.loop-icon { width: 13px; height: 13px; }

.loop-track {
  position: relative;
  flex: 1 1 auto;
  height: 24px;
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--stroke);
  cursor: pointer;
  touch-action: none;
}

.loop-fill {
  position: absolute;
  top: 2px; bottom: 2px;
  left: 0; width: 100%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, rgba(168, 85, 247, 0.4), rgba(236, 72, 153, 0.4));
  border: 1px solid rgba(192, 132, 252, 0.45);
  pointer-events: none;
  opacity: 0.4;
  transition: opacity 0.2s ease;
}
.loopbar.is-active .loop-fill { opacity: 1; }

.loop-handle {
  position: absolute;
  top: 50%;
  width: 16px; height: 16px;
  margin-left: -8px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--violet);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  transform: translateY(-50%);
  cursor: ew-resize;
  touch-action: none;
  z-index: 3;
  transition: transform 0.12s ease;
}
.loop-handle:active { background: var(--violet); transform: translateY(-50%) scale(1.15); }

.loop-playhead {
  position: absolute;
  top: -3px; bottom: -3px;
  left: 0;
  width: 2px;
  border-radius: 1px;
  background: #fff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
  pointer-events: none;
  z-index: 2;
}

.icon-btn-mini { width: 30px; height: 30px; }
.icon-btn-mini svg { width: 14px; height: 14px; }

.tempo-val.is-ramping { animation: tempo-bump 0.4s ease; }
@keyframes tempo-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.3); color: #fff; }
  100% { transform: scale(1); }
}

.toggle-label-short { display: none; }
@media (max-width: 900px) {
  .toggle-ramp .toggle-label-full { display: none; }
  .toggle-ramp .toggle-label-short { display: inline; }
}

/* --------------------------------------------------------------------------
   Keyboard
   -------------------------------------------------------------------------- */
.keyboard-section {
  position: relative;
  z-index: 30;
  flex: 0 0 auto;
  padding: 0 14px 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(14, 12, 30, 0.86) 0%, rgba(6, 6, 15, 0.97) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--stroke);
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.6);
}

.keystrip {
  position: relative;
  z-index: 14;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 16px;
  background: rgba(10, 9, 22, 0.32);
  border-bottom: 1px solid var(--stroke);
  flex-wrap: wrap;
}
.ks-group { display: flex; align-items: center; gap: 8px; }

.octave {
  display: flex; align-items: center; gap: 2px;
  padding: 3px;
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--stroke);
}
.oct-btn {
  width: 26px; height: 26px;
  border-radius: 7px;
  font-size: 15px; font-weight: 700;
  color: var(--text-dim);
  display: grid; place-items: center;
  transition: all 0.15s ease;
}
.oct-btn:hover { background: var(--glass-hi); color: #fff; }
.oct-btn:active { transform: scale(0.9); }
.oct-read {
  display: flex; align-items: baseline; gap: 4px;
  padding: 0 7px;
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 700; color: #fff;
}
.oct-cap { font-size: 8.5px; letter-spacing: 0.8px; color: var(--text-faint); }

.toggle {
  display: flex; align-items: center; gap: 7px;
  height: 32px;
  padding: 0 13px;
  border-radius: var(--r-pill);
  background: var(--glass);
  border: 1px solid var(--stroke);
  font-size: 12px; font-weight: 600;
  color: var(--text-dim);
  transition: all 0.2s ease;
  white-space: nowrap;
}
.toggle:hover { color: #fff; border-color: var(--stroke-hi); }
.toggle-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  transition: all 0.2s ease;
}
.toggle.is-on {
  color: #fff;
  background: rgba(168, 85, 247, 0.2);
  border-color: rgba(192, 132, 252, 0.5);
}
.toggle.is-on .toggle-dot {
  background: #e879f9;
  box-shadow: 0 0 10px #e879f9;
}

/* Loop and auto-ramp get their own tint instead of Sustain/Metronome's
   default violet-pink "on" — placed after the base rule so they win the tie
   (same specificity, later wins). */
.toggle-loop.is-on {
  color: #fff;
  background: rgba(168, 85, 247, 0.22);
  border-color: rgba(192, 132, 252, 0.55);
}
.toggle-loop.is-on .toggle-dot {
  background: #e9d5ff;
  box-shadow: 0 0 10px #c084fc;
}
.toggle-ramp.is-on {
  color: #fff;
  background: rgba(34, 211, 238, 0.18);
  border-color: rgba(34, 211, 238, 0.5);
}
.toggle-ramp.is-on .toggle-dot {
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

/* The keys themselves */
#piano-container { width: 100%; }

.piano-bed {
  width: 100%;
  padding: 6px 8px 9px;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  background: linear-gradient(180deg, #17142c 0%, #0c0a1a 100%);
  border: 1px solid var(--stroke);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 10px 34px rgba(0, 0, 0, 0.55);
  /* the felt strip along the back of the keys */
  border-top: 3px solid;
  border-image: linear-gradient(90deg, #a855f7, #ec4899, #22d3ee) 1;
}

.piano-keys-track {
  position: relative;
  display: flex;
  width: 100%;
  height: var(--kb-h);
  touch-action: none;
}

.piano-key { position: relative; }

/* Now just a layout slot in the flex row and a positioning anchor for the
   black key nested inside it (see .black-key) — no background, no
   transform of its own, so pressing it can never visually move that child.
   All the actual key body lives in .key-surface, one level deeper. */
.white-key {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  /* Matches .key-surface's own radius — this one is invisible (no
     background here), but the wrong-key flash ring is still drawn on the
     outer element (box-shadow doesn't drag descendants around the way
     transform does, so it's safe to keep it there), and needs a radius of
     its own to clip to the key's rounded shape instead of a sharp box. */
  border-radius: 3px 3px 8px 8px;
}

.key-surface {
  position: absolute;
  inset: 0;
  border-radius: 3px 3px 8px 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f3f1fa 78%, #ddd9ec 100%);
  box-shadow:
    inset 0 -5px 7px -4px rgba(76, 62, 122, 0.5),
    inset -1px 0 0 rgba(120, 110, 160, 0.25),
    0 3px 5px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 9px;
  transition: background 0.06s ease, transform 0.06s ease, box-shadow 0.06s ease;
  transform-origin: top center;
}

.black-key {
  position: absolute;
  top: 0;
  right: -31%;
  width: 62%;
  height: 62%;
  z-index: 5;
  border-radius: 2px 2px 6px 6px;
  background: linear-gradient(180deg, #423a5e 0%, #1c1730 42%, #0a0814 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 -3px 5px rgba(0, 0, 0, 0.7),
    0 4px 7px rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
}

.key-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #8b83ad;
  pointer-events: none;
}
.black-key .key-label { color: rgba(255, 255, 255, 0.42); font-size: 8.5px; }

.white-key.is-pressed .key-surface {
  background: linear-gradient(180deg, #ede9fe 0%, #ddd3f7 100%);
  transform: translateY(2px) scaleY(0.985);
  box-shadow:
    inset 0 -3px 6px -3px rgba(76, 62, 122, 0.6),
    0 1px 2px rgba(0, 0, 0, 0.5);
}
.black-key.is-pressed {
  background: linear-gradient(180deg, #5b4f80 0%, #241d3d 100%);
  transform: translateY(2px) scaleY(0.98);
}

/* Tutorial target keys */
.white-key.tutorial-target.target-right .key-surface {
  background: linear-gradient(180deg, #dbeafe 0%, #60a5fa 100%);
  box-shadow: inset 0 0 0 2px var(--right), 0 0 24px rgba(59, 130, 246, 0.75);
}
.white-key.tutorial-target.target-left .key-surface {
  background: linear-gradient(180deg, #fce7f3 0%, #f9a8d4 100%);
  box-shadow: inset 0 0 0 2px var(--left), 0 0 24px rgba(236, 72, 153, 0.75);
}
.black-key.tutorial-target.target-right {
  background: linear-gradient(180deg, #3b82f6 0%, #1e3a8a 100%);
  box-shadow: inset 0 0 0 1.5px var(--right-soft), 0 0 20px rgba(59, 130, 246, 0.8);
}
.black-key.tutorial-target.target-left {
  background: linear-gradient(180deg, #ec4899 0%, #831843 100%);
  box-shadow: inset 0 0 0 1.5px var(--left-soft), 0 0 20px rgba(236, 72, 153, 0.8);
}
.tutorial-target .key-label { color: rgba(10, 8, 20, 0.6); }
.black-key.tutorial-target .key-label { color: rgba(255, 255, 255, 0.75); }

/* A key she pressed that the song wasn't expecting right now — a soft amber
   ring, not a red "wrong" buzzer. Layers as a box-shadow so it doesn't fight
   whatever background the key already has (pressed, target, plain). */
@keyframes key-miss-ring {
  0%   { box-shadow: inset 0 0 0 3px rgba(251, 191, 36, 0.95), 0 0 18px rgba(251, 191, 36, 0.85); }
  100% { box-shadow: inset 0 0 0 3px rgba(251, 191, 36, 0); }
}
.piano-key.key-miss-flash { animation: key-miss-ring 0.34s ease-out; }

/* A quick pulse on the correct key after a miss, to pull her eye back to it. */
@keyframes target-pulse {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}
.white-key.key-target-pulse .key-surface { animation: target-pulse 0.3s ease; transform-origin: top center; }
.black-key.key-target-pulse { animation: target-pulse 0.3s ease; transform-origin: top center; }

/* Which finger to use, printed on the key */
.key-finger-badge {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 19px; height: 19px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 800;
  font-family: var(--font-display);
  color: #fff;
  pointer-events: none;
  animation: badge-pop 0.28s cubic-bezier(0.34, 1.6, 0.5, 1);
}
.black-key .key-finger-badge { top: 5px; width: 16px; height: 16px; font-size: 10px; }
.badge-right { background: #2563eb; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.75); }
.badge-left  { background: #db2777; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.75); }
@keyframes badge-pop { from { transform: translateX(-50%) scale(0.3); opacity: 0; } }

.hit-indicator { display: none; }

/* --------------------------------------------------------------------------
   Well-done modal
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 3, 12, 0.74);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}
.modal-backdrop.is-open { opacity: 1; pointer-events: auto; }

.modal-card {
  width: min(430px, 92vw);
  padding: 30px 28px 24px;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(165deg, #221b45 0%, #120f26 100%);
  border: 1px solid rgba(192, 132, 252, 0.3);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.65), 0 0 90px rgba(168, 85, 247, 0.2);
  transform: scale(0.9) translateY(14px);
  transition: transform 0.36s cubic-bezier(0.34, 1.45, 0.5, 1);
}
.modal-backdrop.is-open .modal-card { transform: scale(1) translateY(0); }

.modal-burst { font-size: 46px; margin-bottom: 6px; animation: twinkle 2.4s ease-in-out infinite; }
@keyframes twinkle {
  0%, 100% { transform: scale(1) rotate(0); }
  50% { transform: scale(1.14) rotate(7deg); }
}

.modal-title {
  font-family: var(--font-display);
  font-size: 25px; font-weight: 800; letter-spacing: -0.4px;
  background: linear-gradient(100deg, #fff 25%, #f0abfc 95%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 7px;
}
.modal-sub { font-size: 13.5px; color: var(--text-dim); margin-bottom: 22px; line-height: 1.5; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.stat-box {
  padding: 13px 10px;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--stroke);
}
.stat-box[hidden] { display: none; }
.stat-wide { grid-column: span 2; }
.stat-cap {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.9px;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 5px;
}
.stat-val {
  font-family: var(--font-mono);
  font-size: 22px; font-weight: 700; color: #fff;
}

.modal-actions { display: flex; gap: 10px; }
.btn-primary, .btn-ghost {
  flex: 1;
  height: 46px;
  border-radius: var(--r-md);
  font-size: 14px; font-weight: 700;
  transition: all 0.2s ease;
}
.btn-primary {
  background: var(--grad-hot);
  color: #fff;
  box-shadow: 0 5px 20px rgba(168, 85, 247, 0.45);
}
.btn-primary:active { transform: scale(0.97); }
.btn-ghost {
  background: var(--glass);
  border: 1px solid var(--stroke);
  color: var(--text-dim);
}
.btn-ghost:hover { color: #fff; border-color: var(--stroke-hi); }

/* --------------------------------------------------------------------------
   Rotate nudge
   -------------------------------------------------------------------------- */
.rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--void);
  text-align: center;
}
.rotate-icon { font-size: 62px; animation: tip 2.6s ease-in-out infinite; }
@keyframes tip {
  0%, 45%, 100% { transform: rotate(0); }
  60%, 90% { transform: rotate(-90deg); }
}
.rotate-hint p {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 700; line-height: 1.6;
}
.rotate-hint span { font-size: 13px; font-weight: 500; color: var(--text-dim); }

@media (orientation: portrait) and (max-width: 900px) {
  .rotate-hint { display: flex; }
}

/* --------------------------------------------------------------------------
   Narrower screens
   -------------------------------------------------------------------------- */
@media (max-width: 1320px) {
  .meta-pill.pill-key { display: none; }
}

@media (max-width: 1180px) {
  .meta-pill.pill-bpm { display: none; }
  .select-song { max-width: 250px; }
}

@media (max-width: 1120px) {
  .song-details { display: none; }
  .select-song { max-width: 300px; }
}

@media (max-width: 1000px) {
  .brand-text { display: none; }
  .tempo-cap { display: none; }
  .range { width: 66px; }
  .seg-btn { padding: 0 9px; font-size: 11.5px; }
  .hud-target { font-size: 12px; }
}

@media (max-width: 820px) {
  .lessonbar { gap: 8px; padding: 8px 12px; }
  .topbar { gap: 10px; padding: 8px 12px; }
  .io-chip .io-label { display: none; }
  .io-chip { padding: 0 11px; }
  .mode-pills { max-width: 46vw; }
  .pill-btn { padding: 7px 14px; font-size: 12px; }
  .loopbar { gap: 8px; padding: 7px 12px; }
}

/* Fine-pointer polish that would misfire on touch */
@media (hover: none) {
  .seg-btn:hover, .toggle:hover, .icon-btn:hover, .select:hover { }
}

/* Middle C gets a quiet marker so she can always find home */
.white-key.is-middle-c::after {
  content: '';
  position: absolute;
  bottom: 3px; left: 50%;
  transform: translateX(-50%);
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #c084fc;
  box-shadow: 0 0 7px rgba(192, 132, 252, 0.9);
  pointer-events: none;
}
.white-key.is-middle-c.tutorial-target::after { opacity: 0.35; }

/* The mic dot breathes with what it can actually hear */
.io-chip.is-live .io-dot {
  transform: scale(calc(1 + var(--mic-level, 0) * 0.8));
  transition: transform 0.09s linear;
}
