/* ==========================================================================
   Entrenador auditivo musical y detector de solfeo con micrófono
   Estilos canónicos para fijate.com/tools/entrenador-oido-musical-solfeo/
   ========================================================================== */

:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-surface: #f1f5f9;
  --bg-surface-hover: #e2e8f0;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  --text-main: #0f172a;
  --text-muted: #64748b;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-text: #ffffff;

  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
  --bg-page: #0b0f17;
  --bg-card: #131b2a;
  --bg-surface: #1e293b;
  --bg-surface-hover: #334155;
  --border-color: #1e293b;
  --border-focus: #818cf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;

  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-text: #ffffff;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.mono {
  font-family: var(--font-mono);
}

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
}

.tool-with-sidebar {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

.card-main {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
}

/* ================= MODOS TABS ================= */
.mode-tabs-wrapper {
  display: flex;
  gap: 0.4rem;
  background: var(--bg-surface);
  padding: 0.35rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  border: 1px solid var(--border-color);
  overflow-x: auto;
}

.mode-tab {
  flex: 1 1 0%;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.mode-tab:hover {
  color: var(--text-main);
  background: var(--bg-surface-hover);
}

.mode-tab.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Barra de estadísticas */
.training-stats-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.stat-pill {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
}

.stat-lbl {
  color: var(--text-muted);
}

.stat-num {
  color: var(--text-main);
  font-weight: 700;
}

.stat-streak {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.3);
}

.stat-streak .stat-num {
  color: #d97706;
}
[data-theme="dark"] .stat-streak .stat-num {
  color: #fbbf24;
}

/* ================= PENTAGRAMA MUSICAL ================= */
.staff-stage-wrapper {
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1.25rem;
  position: relative;
  box-shadow: var(--shadow-md);
}

.staff-svg-container {
  width: 100%;
  display: flex;
  justify-content: center;
}

#music-staff-svg {
  max-width: 600px;
  display: block;
}

/* Feedback de entonación micrófono */
.mic-tuning-feedback {
  background: rgba(15, 23, 42, 0.9);
  border-top: 1px solid #334155;
  padding-top: 0.85rem;
  margin-top: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.feedback-main-note {
  display: flex;
  gap: 1.5rem;
  font-size: 0.9rem;
}

.target-badge {
  color: #38bdf8;
}

.detected-badge {
  color: #f8fafc;
}

.feedback-cents-bar {
  position: relative;
  width: 100%;
  max-width: 320px;
  height: 14px;
  background: #1e293b;
  border-radius: 9999px;
  overflow: hidden;
  border: 1px solid #475569;
}

.cents-center-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: #10b981;
}

.cents-indicator {
  position: absolute;
  top: 1px;
  bottom: 1px;
  left: 50%;
  width: 6px;
  background: #38bdf8;
  border-radius: 3px;
  transform: translateX(-50%);
  transition: left 0.08s linear;
}

.feedback-verdict {
  font-size: 0.82rem;
  color: #94a3b8;
}

/* ================= ACCIONES DEL RETO ================= */
.challenge-actions-bar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 1.25rem;
  height: 42px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
}

.playback-type-toggle {
  display: flex;
  gap: 0.85rem;
  background: var(--bg-surface);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-size: 0.82rem;
  align-items: center;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  color: var(--text-muted);
}

.radio-label input {
  cursor: pointer;
}

/* ================= BANCO DE RESPUESTAS ================= */
.answers-container {
  margin-bottom: 2rem;
}

.answers-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 0.85rem 0;
  color: var(--text-main);
}

.answers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.btn-answer {
  height: 44px;
  min-height: 44px;
  padding: 0 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.btn-answer:hover {
  background: var(--bg-surface-hover);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.btn-answer.correct {
  background: #059669;
  color: #ffffff;
  border-color: #059669;
}

.btn-answer.incorrect {
  background: #dc2626;
  color: #ffffff;
  border-color: #dc2626;
}

.hint-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 3px solid #f59e0b;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* ================= TECLADO DE PIANO VIRTUAL ================= */
.piano-keyboard-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.piano-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 1rem 0;
  color: var(--text-main);
}

.piano-keys-container {
  display: flex;
  position: relative;
  height: 140px;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  user-select: none;
}

.piano-key {
  cursor: pointer;
  transition: background-color 0.1s ease;
  position: relative;
}

.key-white {
  flex: 0 0 38px;
  height: 100%;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 0 0 4px 4px;
  z-index: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.key-white:active, .key-white.active {
  background: #e2e8f0;
}

.key-black {
  position: absolute;
  width: 24px;
  height: 60%;
  background: #0f172a;
  border-radius: 0 0 3px 3px;
  z-index: 2;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

.key-black:active, .key-black.active {
  background: #334155;
}

.key-label {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  color: #64748b;
  font-family: var(--font-mono);
  font-weight: 600;
  pointer-events: none;
}

/* ================= PREGUNTAS FRECUENTES ================= */
.tool-faq-section {
  margin-top: 2.5rem;
  margin-bottom: 2rem;
}

.faq-section-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--text-main);
}

.faq-accordion {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.faq-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.faq-item[open] {
  border-color: var(--border-focus);
}

.faq-question {
  padding: 1rem 1.25rem;
  font-family: var(--font-heading);
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  list-style: none;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-chevron {
  transition: transform 0.2s ease;
  flex-shrink: 0;
  color: var(--text-muted);
}

.faq-item[open] .faq-chevron {
  transform: rotate(180deg);
}

.faq-answer {
  padding: 0 1.25rem 1rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.faq-answer p {
  margin: 0;
}

/* ================= MODAL ================= */
.app-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.app-modal-backdrop.active {
  display: flex;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.app-modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.app-modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-modal-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-main);
}

.app-modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.app-modal-body {
  padding: 1.25rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.app-modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* ================= RESPONSIVO MOBILE ================= */
@media (max-width: 768px) {
  .tool-layout {
    margin: 1rem auto 2rem;
    padding: 0 0.75rem;
  }

  .card-main {
    padding: 0.85rem;
  }

  .mode-tabs-wrapper {
    flex-wrap: nowrap;
  }

  .challenge-actions-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-primary, .btn-secondary {
    width: 100%;
    min-height: 44px;
  }

  .playback-type-toggle {
    width: 100%;
    justify-content: space-around;
  }

  .answers-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
