/* components.css */
/* ======================================
   VMQ COMPONENTS CSS v3.0.4 (Drop-in replacement)
   Layout • Buttons • Cards • Charts • Toasts • Responsive
   Notes:
   - Fixes missing keyframes (toastSlideUp).
   - Avoids Safari-breaking color-mix() usage.
   - Keeps classnames you referenced intact.
   ====================================== */

/* -------------------- APP LAYOUT - Music Stand Optimized -------------------- */
.app-wrapper {
  max-width: min(1200px, 100vw);
  margin: 0 auto;
  padding: clamp(var(--space-md), 4vw, var(--space-2xl));
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  isolation: isolate; /* Stacking context for PWA overlays/toasts */
}

.module-container {
  max-width: 800px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: clamp(var(--space-lg), 4vh, var(--space-xl));
}

/* Optional: common grids used across modules (safe fallbacks) */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-lg); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-lg); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-lg); }

/* -------------------- KEYFRAMES (fallbacks if base.css loads late) -------------------- */
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.7; } }

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgb(var(--primary-rgb) / 0.40); }
  50%      { box-shadow: 0 0 0 12px rgb(var(--primary-rgb) / 0); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ✅ Missing in your original snippet: toast entrance animation */
@keyframes toastSlideUp {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* -------------------- BUTTON SYSTEM v3.0 - Haptic Ready -------------------- */
.btn {
  --ripple-origin: 50% 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: clamp(14px, 3vw, 18px) clamp(24px, 5vw, 32px);
  font-size: clamp(var(--font-size-sm), 3.5vw, var(--font-size-base));
  font-weight: 700;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition:
    transform var(--motion-duration-base) var(--motion-easing),
    box-shadow var(--motion-duration-base) var(--motion-easing),
    background var(--motion-duration-base) var(--motion-easing),
    filter var(--motion-duration-base) var(--motion-easing);
  text-decoration: none;
  min-height: 48px;
  min-width: 48px;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
  background: var(--surface);
  color: var(--ink);
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    45deg,
    transparent 30%,
    rgb(255 255 255 / 0.12) 50%,
    transparent 70%
  );
  transform: scale(0);
  transition: transform 0.6s;
  z-index: 1;
}

.btn > * { position: relative; z-index: 2; }

.btn:not(:disabled):active::before {
  transform: scale(2);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
  filter: none !important;
}

/* 🎯 ML-AWARE BUTTON STATES */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-color: rgba(var(--primary-rgb) / 0.75); /* avoid color-mix() */
  box-shadow: var(--shadow-sm);
}

.btn-primary[data-mastered="true"] {
  background: linear-gradient(135deg, var(--perfect), #059669);
  border-color: rgb(5 150 105 / 0.8);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-xl);
}

.btn-secondary { 
  background: var(--card);
  color: var(--ink);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* Outline button commonly referenced in JS */
.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--ink);
}
.btn-outline:hover:not(:disabled) {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Text button (used by onboarding "Skip setup →") */
.btn-text {
  background: transparent;
  border: none;
  padding: 0.5rem 0.75rem;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
}
.btn-text:hover { text-decoration: underline; }
.btn-text:disabled { opacity: 0.6; cursor: not-allowed; }

/* 🎯 BUTTON SIZING - Music Touch Targets */
.btn-xl { 
  padding: clamp(20px, 4vw, 28px) clamp(36px, 7vw, 48px);
  font-size: clamp(var(--font-size-lg), 5vw, var(--font-size-2xl));
  min-height: 64px;
}
.btn-lg { padding: clamp(16px, 3.5vw, 20px) clamp(28px, 6vw, 36px); min-height: 56px; }
.btn-sm { padding: clamp(10px, 2vw, 14px) clamp(20px, 4vw, 24px); min-height: 44px; }
.btn-xs { padding: clamp(8px, 1.5vw, 12px) clamp(16px, 3vw, 20px); min-height: 36px; }

/* 🎯 SPECIALIZED BUTTONS */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: rgba(0 0 0 / 0.03); /* safe fallback */
  color: var(--ink-light);
  border: 2px solid var(--border);
  font-size: var(--font-size-sm);
  min-height: auto;
  border-radius: var(--radius-md);

  position: sticky;
  top: max(env(safe-area-inset-top), 0px);
  z-index: 20;
  backdrop-filter: blur(20px);
}

@media (prefers-color-scheme: dark) {
  .btn-back { background: rgba(255 255 255 / 0.06); }
}

.btn-back:hover {
  border-color: var(--primary);
  background: rgba(var(--primary-rgb) / 0.12);
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

.btn-play {
  --play-glow: var(--perfect);
  position: relative;
  overflow: visible;
}

.btn-play::after {
  content: '';
  position: absolute;
  inset: -4px;
  background: radial-gradient(circle, var(--play-glow) 0%, transparent 70%);
  border-radius: inherit;
  opacity: 0;
  transition: opacity var(--motion-duration-base) var(--motion-easing);
  z-index: -1;
}

.btn-play:not(:disabled):hover::after {
  opacity: 1;
  animation: pulse-glow 2s infinite;
}

.btn-play.playing {
  background: var(--perfect);
  color: #fff;
  border-color: rgb(5 150 105 / 0.85);
  animation: pulse 1.5s infinite;
}

/* -------------------- FINGERBOARD v3.x -------------------- */
.btn-show-answer-v3, .btn-hide-answer-v3 {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.35);
  color: white;
  font-weight: 700;
}
.btn-show-answer-v3:hover { filter: brightness(1.1); }

/* -------------------- ML DASHBOARD CARDS v3.0 -------------------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: clamp(var(--space-lg), 5vw, var(--space-xl));
  box-shadow: var(--shadow-md);
  margin-bottom: clamp(var(--space-xl), 6vh, var(--space-2xl));
  border: 1px solid var(--border);
  transition:
    transform var(--motion-duration-base) var(--motion-easing),
    box-shadow var(--motion-duration-base) var(--motion-easing),
    border-color var(--motion-duration-base) var(--motion-easing);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(20px);
}

.card[data-live="true"] {
  box-shadow: var(--shadow-lg), 0 0 20px rgb(16 185 129 / 0.3);
  animation: pulse-live 3s infinite;
}

.card[data-mastered="true"] {
  border-color: var(--perfect);
  background: linear-gradient(135deg, rgb(16 185 129 / 0.04), transparent);
}

.card.elevated { 
  box-shadow: var(--shadow-xl);
  transform: translateY(-4px);
}

.card.compact { 
  padding: clamp(var(--space-md), 3vw, var(--space-lg)); 
}

.card-live { 
  border-left: 5px solid var(--primary);
  background: linear-gradient(90deg, rgb(59 130 246 / 0.05) 0%, transparent 100%);
}

/* 🎯 ML INSIGHT CARDS */
.insight {
  padding: clamp(var(--space-lg), 4vw, var(--space-xl));
  background: var(--surface);
  border-radius: var(--radius-lg);
  border-left: 5px solid var(--primary);
  transition: transform var(--motion-duration-base) var(--motion-easing),
              box-shadow var(--motion-duration-base) var(--motion-easing);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.insight[data-priority="urgent"] {
  border-left-color: var(--danger);
  background: linear-gradient(135deg, rgb(239 68 68 / 0.12), transparent);
  box-shadow: 0 4px 12px rgb(239 68 68 / 0.15);
}

.insight[data-priority="high"] {
  border-left-color: var(--warning);
  animation: pulse-warning 2s infinite;
}

.insight:hover {
  transform: translateX(8px) translateY(-2px);
  box-shadow: var(--shadow-xl);
}

.insight-header {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  margin-bottom: var(--space-md);
}

.insight-icon {
  font-size: clamp(var(--font-size-xl), 6vw, var(--font-size-2xl));
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.insight[data-priority="urgent"] .insight-icon {
  background: rgb(239 68 68 / 0.2);
  color: var(--danger);
}

/* -------------------- ML MODULE PERFORMANCE -------------------- */
.module-performance-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  max-height: 600px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.module-performance-item {
  display: grid;
  grid-template-columns: 1fr auto 100px;
  align-items: center;
  gap: var(--space-lg);
  padding: clamp(var(--space-lg), 4vw, var(--space-xl));
  background: var(--card);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition:
    transform var(--motion-duration-base) var(--motion-easing),
    box-shadow var(--motion-duration-base) var(--motion-easing),
    border-color var(--motion-duration-base) var(--motion-easing);
  border: 1px solid var(--border);
  position: relative;
}

.module-performance-item[data-mastered="true"] {
  border-color: var(--perfect);
  background: linear-gradient(135deg, rgb(16 185 129 / 0.08), transparent);
}

.module-performance-item[data-breakthrough="true"] {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.2);
  animation: breakthrough-glow 2s infinite;
}

.module-performance-item:hover {
  transform: translateX(8px);
  box-shadow: var(--shadow-xl);
  border-color: var(--primary);
}

.module-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.module-name {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin: 0;
}

.module-name h4 {
  font-size: clamp(var(--font-size-lg), 4vw, var(--font-size-xl));
  font-weight: 700;
  margin: 0;
  flex: 1;
}

.badge {
  padding: clamp(4px, 1vw, 6px) clamp(8px, 2vw, 12px);
  border-radius: var(--radius-full);
  font-size: clamp(var(--font-size-3xs), 2.5vw, var(--font-size-xs));
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-success { background: rgb(16 185 129 / 0.2); color: var(--perfect); }
.badge-primary { background: rgb(59 130 246 / 0.2); color: var(--primary); }
.badge-warning { background: rgb(245 158 11 / 0.2); color: var(--warning); }

.module-meta {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  font-size: var(--font-size-sm);
  color: var(--ink-light);
}

.difficulty-badge {
  padding: 4px 12px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-3xs);
  font-weight: 700;
  text-transform: uppercase;
}

/* supports either data-level="easy" OR class names */
.difficulty-badge[data-level="easy"],
.difficulty-easy   { background: rgb(16 185 129 / 0.15); color: var(--perfect); }

.difficulty-badge[data-level="medium"],
.difficulty-medium { background: rgb(245 158 11 / 0.15); color: var(--warning); }

.difficulty-badge[data-level="hard"],
.difficulty-hard   { background: rgb(239 68 68 / 0.15); color: var(--danger); }

.module-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-sm);
  text-align: right;
}

.accuracy-badge {
  font-size: clamp(var(--font-size-lg), 5vw, var(--font-size-xl));
  font-weight: 800;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  min-width: 60px;
}

.mastery-score {
  font-size: var(--font-size-sm);
  color: var(--perfect);
  font-weight: 700;
}

.progress-mini {
  width: 72px;
  height: 8px;
}

.progress-mini .progress-fill {
  border-radius: 4px;
}

.module-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  transition: transform var(--motion-duration-sm) var(--motion-easing);
}

.module-action:hover {
  transform: scale(1.1) rotate(90deg);
}

/* -------------------- ML BREAKTHROUGH STATES -------------------- */
@keyframes breakthrough-glow {
  0%, 100% { box-shadow: 0 0 20px rgb(59 130 246 / 0.4); }
  50%      { box-shadow: 0 0 40px rgb(59 130 246 / 0.6); }
}

@keyframes pulse-live {
  0%, 100% { box-shadow: var(--shadow-md), 0 0 20px rgb(16 185 129 / 0.3); }
  50%      { box-shadow: var(--shadow-lg), 0 0 40px rgb(16 185 129 / 0.5); }
}

@keyframes pulse-warning {
  0%, 100% { box-shadow: var(--shadow-md), 0 0 10px rgb(245 158 11 / 0.3); }
  50%      { box-shadow: var(--shadow-lg), 0 0 20px rgb(245 158 11 / 0.5); }
}

/* -------------------- WEEKLY ACTIVITY CHART -------------------- */
.weekly-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  height: clamp(120px, 25vh, 160px);
  padding: var(--space-lg) 0;
  gap: var(--space-sm);
  background: var(--surface);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.weekly-chart::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgb(59 130 246 / 0.03) 50%, transparent 100%);
  pointer-events: none;
}

.day-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2xs);
  position: relative;
}

.day-bar {
  width: 100%;
  min-height: 6px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: transform var(--motion-duration-base) var(--motion-easing),
              filter var(--motion-duration-base) var(--motion-easing);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.day-bar:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
}

.day-bar::after {
  content: attr(data-questions);
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--font-size-3xs);
  font-weight: 700;
  color: var(--ink-light);
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--motion-duration-sm) var(--motion-easing);
}

.day-column:hover .day-bar::after {
  opacity: 1;
}

.day-label {
  font-size: var(--font-size-xs);
  color: var(--ink-light);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.weekly-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md);
  border-top: 1px solid var(--border);
  font-size: var(--font-size-sm);
  font-weight: 600;
}

/* -------------------- RETENTION METRICS -------------------- */
.retention-metrics {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-lg);
  text-align: center;
}

.stat-large {
  font-size: clamp(var(--font-size-3xl), 12vw, var(--font-size-4xl));
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--primary), var(--success));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.retention-breakdown {
  display: flex;
  gap: var(--space-xl);
  font-size: var(--font-size-sm);
  color: var(--ink-light);
  flex-wrap: wrap;
  justify-content: center;
}

/* -------------------- SESSION LIST v3.0 -------------------- */
.session-list.compact {
  max-height: 240px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.session-item.compact {
  padding: var(--space-md);
  gap: var(--space-lg);
  min-height: 56px;
}

.session-info.compact {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.session-meta.compact {
  display: flex;
  gap: var(--space-md);
  font-size: var(--font-size-3xs);
  font-weight: 600;
}

/* -------------------- CIRCLE OF FIFTHS v3.0 -------------------- */
.circle-of-fifths {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--space-sm);
  padding: var(--space-xl);
  background: var(--surface);
  border-radius: var(--radius-xl);
  justify-items: center;
  position: relative;
}

.circle-key {
  width: clamp(48px, 8vw, 64px);
  height: clamp(48px, 8vw, 64px);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(var(--font-size-sm), 4vw, var(--font-size-base));
  cursor: pointer;
  transition:
    transform var(--motion-duration-base) var(--motion-easing),
    box-shadow var(--motion-duration-base) var(--motion-easing),
    background var(--motion-duration-base) var(--motion-easing),
    border-color var(--motion-duration-base) var(--motion-easing);
  position: relative;
  border: 3px solid var(--border);
  background: var(--card);
  color: var(--ink);
}

.circle-key:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: rgba(var(--primary-rgb) / 0.65); /* avoid color-mix() */
}

.circle-key.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
  transform: scale(1.2);
  box-shadow: var(--shadow-xl), 0 0 20px rgb(59 130 246 / 0.5);
  z-index: 10;
}

.circle-key.mastered {
  background: linear-gradient(135deg, var(--perfect), #059669);
  color: #fff;
  border-color: var(--perfect);
}

.circle-key.mastered::after {
  content: '⭐';
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: 12px;
}

/* -------------------- ML PROGRESS BARS -------------------- */
.progress-bar {
  height: clamp(10px, 2vh, 16px);
  background: var(--surface);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: clamp(var(--space-sm), 2vh, var(--space-md)) 0;
  position: relative;
  box-shadow: inset 0 2px 4px rgb(0 0 0 / 0.05);
}

.progress-fill {
  height: 100%;
  width: var(--width, 0%); /* allows base shell + JS to drive width */
  background: linear-gradient(90deg, var(--primary) 0%, var(--perfect) 70%, var(--success) 100%);
  transition: width var(--motion-duration-lg) var(--motion-easing);
  position: relative;
  overflow: hidden;
}

.progress-fill::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgb(255 255 255 / 0.4) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 2s infinite linear;
}

/* -------------------- TOAST SYSTEM v3.0 - ML Live -------------------- */
.toast-container {
  position: fixed;
  bottom: clamp(20px, 6vh, 32px);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  max-width: min(90vw, 420px);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: clamp(16px, 4vw, 24px);
  pointer-events: none;
}

.toast {
  padding: clamp(16px, 3vw, 20px) clamp(24px, 5vw, 32px);
  border-radius: var(--radius-xl);
  color: #fff;
  font-weight: 700;
  font-size: clamp(var(--font-size-sm), 3.5vw, var(--font-size-base));
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(32px);
  border: 1px solid rgb(255 255 255 / 0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  animation: toastSlideUp 0.4s var(--motion-easing);
  pointer-events: all;
  position: relative;
  overflow: hidden;
}

.toast::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 0%, rgb(255 255 255 / 0.1) 100%);
  pointer-events: none;
}

.toast > * { position: relative; z-index: 1; }

.toast-icon {
  font-size: clamp(var(--font-size-lg), 6vw, var(--font-size-xl));
  width: clamp(40px, 8vw, 56px);
  height: clamp(40px, 8vw, 56px);
  border-radius: var(--radius-full);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-weight: 900;
}

.toast.success {
  background: linear-gradient(135deg, rgb(16 185 129 / 0.95), rgb(5 150 105 / 0.95));
}

.toast.error {
  background: linear-gradient(135deg, rgb(239 68 68 / 0.95), rgb(220 38 38 / 0.95));
}

/* Optional warning/info variants (safe if used by JS later) */
.toast.warning {
  background: linear-gradient(135deg, rgb(245 158 11 / 0.95), rgb(217 119 6 / 0.95));
}
.toast.info {
  background: linear-gradient(135deg, rgb(59 130 246 / 0.95), rgb(29 78 216 / 0.95));
}

.toast-progress {
  height: 4px;
  margin-top: var(--space-sm);
  background: rgb(255 255 255 / 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.toast-progress-fill {
  height: 100%;
  background: rgb(255 255 255 / 0.9);
  border-radius: 2px;
  transition: width 100ms linear;
}

/* -------------------- RESPONSIVE BREAKPOINTS -------------------- */
@media (max-width: 1024px) {
  .module-performance-item {
    grid-template-columns: 1fr auto;
    gap: var(--space-md);
  }

  .module-stats {
    flex-direction: row;
    align-items: center;
    gap: var(--space-lg);
  }
}

@media (max-width: 768px) {
  .app-wrapper { padding: var(--space-lg); }

  .module-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-lg);
    text-align: center;
  }

  .stats-live {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--space-md);
  }

  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  .answer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: var(--space-md);
  }
}

@media (max-width: 480px) {
  .module-container { padding: 0 var(--space-md); }

  .card {
    margin-bottom: var(--space-lg);
    padding: var(--space-lg);
  }

  .weekly-chart {
    height: clamp(100px, 20vh, 120px);
  }
}

/* -------------------- PRINT - Sheet Music Export -------------------- */
@media print {
  .no-print,
  .toast-container,
  .btn:not(.btn-print) { display: none !important; }

  .card {
    box-shadow: none !important;
    border: 1px solid #ddd;
    page-break-inside: avoid;
    margin-bottom: 1.5cm;
    background: #fff !important;
  }

  .module-container {
    max-width: none;
    gap: 2cm;
  }

  h1, h2, h3 {
    color: #000 !important;
    page-break-after: avoid;
  }
}

/* ======================================================================
   KEY SIGNATURES MODULE (KeySignatures.js) — UI polish block
   Targets only classes used by the Key Signatures module
   Safe for iOS Safari + GH Pages (no color-mix dependency)
   ====================================================================== */

/* Container */
.mode-container.keysig-mode {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(var(--space-lg), 3vh, var(--space-xl));
}

.mode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  position: sticky;
  top: max(env(safe-area-inset-top), 0px);
  z-index: 30;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: rgb(255 255 255 / 0.75);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-sm);
}

@media (prefers-color-scheme: dark) {
  .mode-header { background: rgb(16 26 46 / 0.75); }
}

.mode-header h2 {
  margin: 0;
  font-size: clamp(var(--font-size-lg), 4vw, var(--font-size-2xl));
  color: var(--ink);
}

.difficulty-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 6px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-light);
  font-size: var(--font-size-3xs);
  letter-spacing: 0.06em;
}

.difficulty-badge .ml-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: rgb(var(--primary-rgb) / 0.12);
  border: 1px solid rgb(var(--primary-rgb) / 0.25);
}

/* Main content area */
.mode-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.keysig-area {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: clamp(var(--space-lg), 4vw, var(--space-xl));
}

/* Visual: staff + accidentals */
.keysig-visual {
  background: linear-gradient(180deg, rgb(var(--primary-rgb) / 0.05), transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.staff {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.staff::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 16%;
  height: 68%;
  background:
    linear-gradient(to bottom,
      transparent 0%,
      transparent 9%,
      rgb(0 0 0 / 0.07) 10%,
      transparent 11%,
      transparent 29%,
      rgb(0 0 0 / 0.07) 30%,
      transparent 31%,
      transparent 49%,
      rgb(0 0 0 / 0.07) 50%,
      transparent 51%,
      transparent 69%,
      rgb(0 0 0 / 0.07) 70%,
      transparent 71%,
      transparent 89%,
      rgb(0 0 0 / 0.07) 90%,
      transparent 91%,
      transparent 100%);
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .staff::before { background:
    linear-gradient(to bottom,
      transparent 0%,
      transparent 9%,
      rgb(255 255 255 / 0.10) 10%,
      transparent 11%,
      transparent 29%,
      rgb(255 255 255 / 0.10) 30%,
      transparent 31%,
      transparent 49%,
      rgb(255 255 255 / 0.10) 50%,
      transparent 51%,
      transparent 69%,
      rgb(255 255 255 / 0.10) 70%,
      transparent 71%,
      transparent 89%,
      rgb(255 255 255 / 0.10) 90%,
      transparent 91%,
      transparent 100%);
  }
}

.clef {
  font-family: var(--font-family-music);
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  line-height: 1;
  color: var(--ink);
  z-index: 1;
}

.accidentals-display {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  z-index: 1;
}

.no-accidentals {
  font-weight: 800;
  color: var(--ink-light);
  font-size: var(--font-size-sm);
}

.accidentals {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.accidental {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 1.25rem;
  font-weight: 900;
  box-shadow: var(--shadow-xs);
}

.accidentals.sharp .accidental {
  border-color: rgb(var(--primary-rgb) / 0.35);
  background: rgb(var(--primary-rgb) / 0.08);
}

.accidentals.flat .accidental {
  border-color: rgb(239 68 68 / 0.35);
  background: rgb(239 68 68 / 0.08);
}

/* Circle of fifths indicator (the small track/marker) */
.circle-indicator {
  display: grid;
  gap: var(--space-xs);
  margin: var(--space-lg) 0;
}

.circle-track {
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.circle-marker {
  position: absolute;
  top: 50%;
  left: calc((var(--position, 0) / 11) * 100%);
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  background: var(--primary);
  box-shadow: 0 0 0 4px rgb(var(--primary-rgb) / 0.18), var(--shadow-sm);
  border: 2px solid rgb(255 255 255 / 0.9);
}

@media (prefers-color-scheme: dark) {
  .circle-marker { border-color: rgb(16 26 46 / 0.9); }
}

.circle-label {
  font-size: var(--font-size-sm);
  color: var(--ink-light);
  font-weight: 700;
}

/* Instruction */
.instruction {
  margin: var(--space-md) 0 var(--space-lg) 0;
  color: var(--ink);
  font-weight: 800;
  font-size: clamp(var(--font-size-base), 3.6vw, var(--font-size-lg));
}

/* Answer form */
.answer-form {
  display: grid;
  gap: var(--space-md);
  margin-top: var(--space-md);
}

.input-key {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.input-key::placeholder {
  color: var(--ink-lighter);
  font-weight: 700;
}

.input-key:focus {
  border-color: rgb(var(--primary-rgb) / 0.85);
  box-shadow: 0 0 0 4px rgb(var(--primary-rgb) / 0.18);
  outline: none;
}

/* “Likely correct” ML hinting class */
.input-key.likely-correct {
  border-color: rgb(16 185 129 / 0.85);
  box-shadow: 0 0 0 4px rgb(16 185 129 / 0.18);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

/* Hint line under stats */
.hint-text {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px dashed var(--border);
  color: var(--ink-lighter);
  font-size: var(--font-size-xs);
  font-weight: 700;
}

/* Session stats */
.session-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-md);
  margin-top: var(--space-lg);
}

.stat-item {
  padding: var(--space-md);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
}

.stat-value {
  display: block;
  font-weight: 900;
  font-size: clamp(var(--font-size-lg), 5vw, var(--font-size-2xl));
  color: var(--ink);
  line-height: 1.05;
}

.stat-label {
  display: block;
  margin-top: 4px;
  font-size: var(--font-size-2xs);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-light);
}

/* Feedback */
.feedback {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: var(--space-md) var(--space-lg);
  box-shadow: var(--shadow-sm);
  font-weight: 800;
}

.feedback-success {
  background: rgb(16 185 129 / 0.10);
  border-color: rgb(16 185 129 / 0.35);
  color: var(--ink);
}

.feedback-error {
  background: rgb(239 68 68 / 0.10);
  border-color: rgb(239 68 68 / 0.35);
  color: var(--ink);
}

.feedback-hint {
  background: rgb(var(--primary-rgb) / 0.10);
  border-color: rgb(var(--primary-rgb) / 0.35);
  color: var(--ink);
}

/* Mastery overlay (modal) */
.mastery-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: rgb(0 0 0 / 0.55);
  display: grid;
  place-items: center;
  padding: max(var(--space-lg), env(safe-area-inset-top));
  backdrop-filter: blur(12px);
}

.mastery-panel {
  width: min(980px, 96vw);
  max-height: min(86vh, 86svh);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: clamp(var(--space-lg), 4vw, var(--space-xl));
}

.mastery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  position: sticky;
  top: 0;
  background: var(--card);
  padding: var(--space-sm) 0;
  z-index: 1;
}

.mastery-header h3 {
  margin: 0;
  color: var(--ink);
}

.btn-close {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

.btn-close:hover {
  border-color: rgb(var(--primary-rgb) / 0.65);
  box-shadow: var(--shadow-sm);
}

/* Mastery details list */
.mastery-details {
  margin-top: var(--space-xl);
}

.mastery-list {
  display: grid;
  gap: var(--space-md);
}

.mastery-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: var(--space-md);
}

.mastery-item-name {
  font-weight: 900;
  color: var(--ink);
  margin-bottom: 4px;
}

.mastery-item-stats {
  font-weight: 700;
  color: var(--ink-light);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-sm);
}

.mastery-item-bar {
  height: 10px;
  border-radius: var(--radius-full);
  background: rgb(0 0 0 / 0.06);
  overflow: hidden;
  border: 1px solid var(--border);
}

@media (prefers-color-scheme: dark) {
  .mastery-item-bar { background: rgb(255 255 255 / 0.08); }
}

.mastery-item-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--perfect));
  transition: width var(--motion-duration-lg) var(--motion-easing);
}

/* Fingerboard mini (for handMap) */
.fingerboard-mini {
  margin: var(--space-md) 0 var(--space-lg) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: var(--space-md);
}

.fingerboard-strings {
  display: grid;
  gap: var(--space-sm);
}

.fingerboard-mini .string {
  display: grid;
  grid-template-columns: 28px repeat(5, minmax(0, 1fr));
  align-items: center;
  gap: var(--space-xs);
  padding: 6px 8px;
  border-radius: var(--radius-md);
  border: 1px solid rgb(0 0 0 / 0.06);
  background: rgb(255 255 255 / 0.55);
}

@media (prefers-color-scheme: dark) {
  .fingerboard-mini .string {
    border-color: rgb(255 255 255 / 0.10);
    background: rgb(16 26 46 / 0.45);
  }
}

.fingerboard-mini .string.active {
  border-color: rgb(var(--primary-rgb) / 0.45);
  background: rgb(var(--primary-rgb) / 0.08);
}

.string-label {
  font-weight: 900;
  color: var(--ink);
}

.finger-position {
  height: 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  opacity: 0.85;
}

.finger-position.high { outline: 0; }
.finger-position.low  { outline: 0; }

.finger-position.correct {
  background: rgb(16 185 129 / 0.85);
  border-color: rgb(16 185 129 / 0.95);
  box-shadow: 0 0 0 3px rgb(16 185 129 / 0.18);
  opacity: 1;
}

.finger-hint {
  margin-top: var(--space-sm);
  font-size: var(--font-size-xs);
  font-weight: 800;
  color: var(--ink-light);
  text-align: center;
}

/* Mastery toggle button spacing */
.btn-mastery-toggle {
  margin-top: var(--space-md);
  width: 100%;
}

/* Small screens */
@media (max-width: 480px) {
  .form-actions { grid-template-columns: 1fr; }
  .session-stats { grid-template-columns: 1fr; }
  .accidental { width: 30px; height: 30px; }
}

/* ======================================================================
   KEY SIGNATURES — Mastery Status Colors (drop-in additive)
   Works with:
   - .circle-key ${stat.status}
   - .mastery-item ${stat.status} + [data-status="..."]
   Safe defaults if statuses differ (no breakage)
   ====================================================================== */

/* --- Shared status tokens (local) --- */
.keysig-mode {
  --ks-new-bg:        rgb(var(--primary-rgb) / 0.06);
  --ks-new-border:    rgb(var(--primary-rgb) / 0.28);

  --ks-learning-bg:   rgb(245 158 11 / 0.10);
  --ks-learning-border: rgb(245 158 11 / 0.40);

  --ks-review-bg:     rgb(59 130 246 / 0.10);
  --ks-review-border: rgb(59 130 246 / 0.45);

  --ks-mastered-bg:   rgb(16 185 129 / 0.12);
  --ks-mastered-border: rgb(16 185 129 / 0.55);

  --ks-struggle-bg:   rgb(239 68 68 / 0.10);
  --ks-struggle-border: rgb(239 68 68 / 0.45);
}

/* --- Circle of Fifths keys: status-driven look --- */
.circle-key.new,
.circle-key[data-status="new"] {
  background: var(--ks-new-bg);
  border-color: var(--ks-new-border);
}

.circle-key.learning,
.circle-key[data-status="learning"] {
  background: var(--ks-learning-bg);
  border-color: var(--ks-learning-border);
}

.circle-key.review,
.circle-key[data-status="review"] {
  background: var(--ks-review-bg);
  border-color: var(--ks-review-border);
}

/* Your CSS already has .circle-key.mastered — keep it, but make it richer */
.circle-key.mastered,
.circle-key[data-status="mastered"] {
  background: linear-gradient(135deg, rgb(16 185 129 / 0.95), rgb(5 150 105 / 0.95));
  border-color: var(--ks-mastered-border);
  color: #fff;
}

/* Safety net: if your engine uses “struggling / weak / lapse / incorrect” */
.circle-key.struggling,
.circle-key.weak,
.circle-key.lapse,
.circle-key.incorrect,
.circle-key[data-status="struggling"],
.circle-key[data-status="weak"],
.circle-key[data-status="lapse"],
.circle-key[data-status="incorrect"] {
  background: var(--ks-struggle-bg);
  border-color: var(--ks-struggle-border);
}

/* Add a subtle “state glow” on hover (keeps existing hover transform) */
.circle-key.new:hover       { box-shadow: 0 0 0 4px rgb(var(--primary-rgb) / 0.14), var(--shadow-sm); }
.circle-key.learning:hover  { box-shadow: 0 0 0 4px rgb(245 158 11 / 0.16), var(--shadow-sm); }
.circle-key.review:hover    { box-shadow: 0 0 0 4px rgb(59 130 246 / 0.16), var(--shadow-sm); }
.circle-key.mastered:hover  { box-shadow: 0 0 0 4px rgb(16 185 129 / 0.18), var(--shadow-sm); }
.circle-key.struggling:hover,
.circle-key.weak:hover,
.circle-key.lapse:hover,
.circle-key.incorrect:hover { box-shadow: 0 0 0 4px rgb(239 68 68 / 0.16), var(--shadow-sm); }

/* Keep your “active” state dominant even when also mastered/learning/etc */
.circle-key.active {
  outline: 3px solid rgb(var(--primary-rgb) / 0.35);
  outline-offset: 2px;
}

/* --- Mastery list items: left rail + background tint by status --- */
.mastery-item {
  position: relative;
  overflow: hidden;
}

.mastery-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: var(--border);
  opacity: 0.95;
}

/* NEW */
.mastery-item.new,
.mastery-item[data-status="new"] {
  background: linear-gradient(90deg, rgb(var(--primary-rgb) / 0.05), transparent 40%);
}
.mastery-item.new::before,
.mastery-item[data-status="new"]::before {
  background: rgb(var(--primary-rgb) / 0.75);
}

/* LEARNING */
.mastery-item.learning,
.mastery-item[data-status="learning"] {
  background: linear-gradient(90deg, rgb(245 158 11 / 0.08), transparent 40%);
}
.mastery-item.learning::before,
.mastery-item[data-status="learning"]::before {
  background: rgb(245 158 11 / 0.85);
}

/* REVIEW */
.mastery-item.review,
.mastery-item[data-status="review"] {
  background: linear-gradient(90deg, rgb(59 130 246 / 0.08), transparent 40%);
}
.mastery-item.review::before,
.mastery-item[data-status="review"]::before {
  background: rgb(59 130 246 / 0.85);
}

/* MASTERED */
.mastery-item.mastered,
.mastery-item[data-status="mastered"] {
  background: linear-gradient(90deg, rgb(16 185 129 / 0.10), transparent 40%);
  border-color: rgb(16 185 129 / 0.35);
}
.mastery-item.mastered::before,
.mastery-item[data-status="mastered"]::before {
  background: rgb(16 185 129 / 0.92);
}

/* STRUGGLING / WEAK / LAPSE */
.mastery-item.struggling,
.mastery-item.weak,
.mastery-item.lapse,
.mastery-item.incorrect,
.mastery-item[data-status="struggling"],
.mastery-item[data-status="weak"],
.mastery-item[data-status="lapse"],
.mastery-item[data-status="incorrect"] {
  background: linear-gradient(90deg, rgb(239 68 68 / 0.08), transparent 40%);
  border-color: rgb(239 68 68 / 0.35);
}
.mastery-item.struggling::before,
.mastery-item.weak::before,
.mastery-item.lapse::before,
.mastery-item.incorrect::before,
.mastery-item[data-status="struggling"]::before,
.mastery-item[data-status="weak"]::before,
.mastery-item[data-status="lapse"]::before,
.mastery-item[data-status="incorrect"]::before {
  background: rgb(239 68 68 / 0.92);
}

/* Reduce motion: keep it classy */
@media (prefers-reduced-motion: reduce) {
  .circle-key,
  .mastery-item {
    transition: none !important;
  }
}

/* ======================================================================
   KEY SIGNATURES — Circle of Fifths Status Mapping (matches module output)
   Statuses emitted by KeySignatures.js:
   new | good | mastered | needs-work
   ====================================================================== */

/* --- 1) Color + styling for circle keys --- */
.circle-key.new {
  background: color-mix(in srgb, var(--primary) 18%, var(--card) 82%);
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border) 45%);
}

.circle-key.good {
  background: color-mix(in srgb, var(--warning) 20%, var(--card) 80%);
  border-color: color-mix(in srgb, var(--warning) 55%, var(--border) 45%);
}

.circle-key.mastered {
  /* you already have a mastered style — this just ensures consistency */
  background: linear-gradient(135deg, var(--perfect), #059669);
  border-color: var(--perfect);
  color: #fff;
}

.circle-key.needs-work {
  background: color-mix(in srgb, var(--danger) 18%, var(--card) 82%);
  border-color: color-mix(in srgb, var(--danger) 55%, var(--border) 45%);
}

/* --- 2) Matching styling for mastery list items (optional but nice) --- */
.mastery-item.new        { border-left: 5px solid var(--primary); }
.mastery-item.good       { border-left: 5px solid var(--warning); }
.mastery-item.mastered   { border-left: 5px solid var(--perfect); }
.mastery-item.needs-work { border-left: 5px solid var(--danger); }

/* --- 3) CSS-only legend injected into the mastery header --- */
.mastery-panel .mastery-header::after {
  content: "🟦 New   🟨 Good (75%+)   🟩 Mastered (90%+)   🟥 Needs work";
  display: block;
  margin-top: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 85%, transparent 15%);
  color: var(--ink-light);
  font-size: var(--font-size-xs);
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.35;
  text-align: center;
}

/* Keep header layout stable + close button clickable */
.mastery-panel .mastery-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-sm);
  align-items: start;
}

@media (max-width: 520px) {
  .mastery-panel .mastery-header::after { text-align: left; }
}
