/* ==========================================================================
   Fijate Tools - Explorador de escalas y modos musicales
   Hoja de estilos canónica (css/style.css)
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Colores base - Modo claro */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #475569;
  --border-color: #e2e8f0;
  --border-light: #edf2f7;

  /* Acentos de marca */
  --accent-primary: #0284c7;
  --accent-hover: #0369a1;
  --accent-glow: rgba(2, 132, 199, 0.15);

  /* Colores de intervalos musicales */
  --interval-root: #d97706;       /* Oro / Ámbar tónico */
  --interval-root-bg: #fef3c7;
  --interval-third: #0891b2;      /* Cian */
  --interval-third-bg: #cffafe;
  --interval-fifth: #2563eb;      /* Azul */
  --interval-fifth-bg: #dbeafe;
  --interval-seventh: #9333ea;    /* Púrpura */
  --interval-seventh-bg: #f3e8ff;
  --interval-other: #059669;      /* Esmeralda */
  --interval-other-bg: #d1fae5;

  /* Mástil y maderas */
  --fretboard-wood: #261c14;
  --fret-wire: #94a3b8;
  --guitar-string: #cbd5e1;
  --fret-nut: #f8fafc;
  --fret-inlay: #e2e8f0;

  /* Teclas de piano */
  --piano-white: #ffffff;
  --piano-white-border: #cbd5e1;
  --piano-black: #1e293b;

  --card-radius: 14px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-tertiary: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --border-light: #1e293b;

  --accent-primary: #38bdf8;
  --accent-hover: #0284c7;
  --accent-glow: rgba(56, 189, 248, 0.2);

  --interval-root: #fbbf24;
  --interval-root-bg: rgba(251, 191, 36, 0.2);
  --interval-third: #22d3ee;
  --interval-third-bg: rgba(34, 211, 238, 0.2);
  --interval-fifth: #60a5fa;
  --interval-fifth-bg: rgba(96, 165, 250, 0.2);
  --interval-seventh: #c084fc;
  --interval-seventh-bg: rgba(192, 132, 252, 0.2);
  --interval-other: #34d399;
  --interval-other-bg: rgba(52, 211, 153, 0.2);

  --fretboard-wood: #18120d;
  --fret-wire: #475569;
  --guitar-string: #64748b;
  --fret-nut: #e2e8f0;
  --fret-inlay: #64748b;

  --piano-white: #e2e8f0;
  --piano-white-border: #334155;
  --piano-black: #090d16;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.5);
}

/* Base global */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.6;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--text-main);
  line-height: 1.25;
}

/* Layout general */
.tool-layout {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto 3rem;
  padding: 0 1.25rem;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

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

/* Paneles y tarjetas */
.card-main {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
}

.card-section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.card-section-title svg {
  color: var(--accent-primary);
}

/* Panel de controles superiores */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.control-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Desplegables accesibles y anti-desborde */
.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 40px 0 12px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-main);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  transition: var(--transition);
  cursor: pointer;
}

.form-select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-select option, .form-select optgroup {
  background-color: var(--bg-secondary);
  color: var(--text-main);
  font-size: 0.95rem;
}

/* Fila secundaria de controles: Tabs de visualización y notación */
.options-subbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-tertiary);
  border-radius: 10px;
  margin-bottom: 1.5rem;
}

.segmented-group {
  display: inline-flex;
  background: var(--bg-secondary);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.segmented-option {
  position: relative;
  display: flex;
  align-items: center;
}

.segmented-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-option label {
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition);
}

.segmented-option input[type="radio"]:checked + label {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

/* Botones de acción sonora */
.audio-actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.btn-audio-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 42px;
  padding: 0 1.25rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary-play {
  background: var(--accent-primary);
  color: #ffffff;
}

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

.btn-secondary-drone {
  background: var(--bg-secondary);
  color: var(--text-main);
  border-color: var(--border-color);
}

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

.btn-secondary-drone.drone-active {
  background: #dc2626;
  color: #ffffff;
  border-color: #b91c1c;
  animation: pulse-drone 1.8s infinite;
}

@keyframes pulse-drone {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

.tempo-control-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.tempo-control-box input[type="range"] {
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.tempo-val-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-main);
  min-width: 65px;
}

/* Banner informativo de la escala activa */
.scale-hero-banner {
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.08) 0%, rgba(147, 51, 234, 0.08) 100%);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.75rem;
}

.scale-hero-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.scale-hero-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
}

.scale-formula-tag {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--bg-secondary);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  font-weight: 600;
}

.scale-notes-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.scale-note-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  user-select: none;
}

.scale-note-pill:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.scale-note-pill.active-play-step {
  box-shadow: 0 0 0 3px #ffffff, 0 0 12px var(--accent-primary);
  transform: scale(1.08);
}

.scale-note-pill.interval-root {
  background: var(--interval-root-bg);
  color: var(--interval-root);
  border-color: var(--interval-root);
  font-weight: 700;
}

.scale-note-pill.interval-third {
  background: var(--interval-third-bg);
  color: var(--interval-third);
  border-color: var(--interval-third);
}

.scale-note-pill.interval-fifth {
  background: var(--interval-fifth-bg);
  color: var(--interval-fifth);
  border-color: var(--interval-fifth);
}

.scale-note-pill.interval-seventh {
  background: var(--interval-seventh-bg);
  color: var(--interval-seventh);
  border-color: var(--interval-seventh);
}

.scale-note-pill.interval-other {
  background: var(--interval-other-bg);
  color: var(--interval-other);
  border-color: var(--interval-other);
}

.degree-tag {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  opacity: 0.85;
}

.scale-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
}

.scale-meta-item strong {
  color: var(--text-main);
}

/* Contenedor del Mástil y scroll responsivo */
.fretboard-scroll-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.75rem;
  margin: 1rem 0;
  border-radius: 8px;
  scrollbar-width: thin;
}

.fretboard-svg {
  min-width: 820px;
  width: 100%;
  height: auto;
  display: block;
}

.fretboard-wood {
  fill: var(--fretboard-wood);
}

.fret-wire {
  stroke: var(--fret-wire);
  stroke-width: 2.2;
}

.guitar-string {
  stroke: var(--guitar-string);
}

.fret-nut {
  fill: var(--fret-nut);
}

.fretboard-inlay {
  fill: var(--fret-inlay);
  opacity: 0.45;
}

.fret-number {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--text-muted);
  font-weight: 600;
}

/* Nodos interactivos de notas en el mástil */
.fret-note-group {
  cursor: pointer;
  transition: transform 0.15s ease;
  outline: none;
}

.fret-note-group:hover circle {
  filter: brightness(1.2);
}

.fret-note-group.note-pulse circle {
  animation: note-bounce 0.35s ease-out;
}

@keyframes note-bounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.note-text {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  fill: #ffffff;
}

/* Colores de los círculos de notas */
.interval-root .note-circle {
  fill: var(--interval-root);
}
.interval-third .note-circle {
  fill: var(--interval-third);
}
.interval-fifth .note-circle {
  fill: var(--interval-fifth);
}
.interval-seventh .note-circle {
  fill: var(--interval-seventh);
}
.interval-other .note-circle {
  fill: var(--interval-other);
}

.is-root-node circle {
  stroke: #ffffff;
  stroke-width: 2.2;
}

/* Leyenda cromática de intervalos */
.intervals-legend-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 0.85rem;
  margin-top: 1rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.legend-color-dot.root { background: var(--interval-root); }
.legend-color-dot.third { background: var(--interval-third); }
.legend-color-dot.fifth { background: var(--interval-fifth); }
.legend-color-dot.seventh { background: var(--interval-seventh); }
.legend-color-dot.other { background: var(--interval-other); }

/* Teclado de Piano SVG */
.piano-scroll-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.75rem;
  margin: 1rem 0;
  scrollbar-width: thin;
}

.piano-svg {
  min-width: 448px;
  max-width: 680px;
  width: 100%;
  height: auto;
  margin: 0 auto;
  display: block;
}

.piano-key-group {
  cursor: pointer;
  outline: none;
  user-select: none;
}

.white-rect {
  fill: var(--piano-white);
  stroke: var(--piano-white-border);
  stroke-width: 1;
}

.black-rect {
  fill: var(--piano-black);
  stroke: #000000;
  stroke-width: 1;
}

.piano-key-group:hover .white-rect {
  fill: #e0f2fe;
}

.piano-key-group:hover .black-rect {
  fill: #334155;
}

.piano-key-group.key-active .white-rect {
  fill: var(--accent-primary);
}

.piano-key-group.key-active .black-rect {
  fill: var(--accent-hover);
}

.key-badge-circle {
  fill: currentColor;
}

.white-key.in-scale .key-badge-circle {
  fill: var(--accent-primary);
}

.white-key.interval-root .key-badge-circle { fill: var(--interval-root); }
.white-key.interval-third .key-badge-circle { fill: var(--interval-third); }
.white-key.interval-fifth .key-badge-circle { fill: var(--interval-fifth); }
.white-key.interval-seventh .key-badge-circle { fill: var(--interval-seventh); }
.white-key.interval-other .key-badge-circle { fill: var(--interval-other); }

.black-key.interval-root .key-badge-circle { fill: var(--interval-root); }
.black-key.interval-third .key-badge-circle { fill: var(--interval-third); }
.black-key.interval-fifth .key-badge-circle { fill: var(--interval-fifth); }
.black-key.interval-seventh .key-badge-circle { fill: var(--interval-seventh); }
.black-key.interval-other .key-badge-circle { fill: var(--interval-other); }

.key-badge-text {
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  fill: #ffffff;
}

/* Tabla de acordes derivados y armonía modal */
.table-responsive {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.chords-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.92rem;
}

.chords-table th, .chords-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.chords-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chords-table tr:last-child td {
  border-bottom: none;
}

.chords-table tr:hover td {
  background: var(--bg-tertiary);
}

.degree-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  background: var(--bg-tertiary);
  padding: 3px 8px;
  border-radius: 4px;
}

.chord-highlight {
  font-weight: 600;
  color: var(--accent-primary);
}

.chords-table code {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
}

.table-function-text {
  color: var(--text-muted);
}

/* Sección de contenido educativo / FAQ */
.faq-section {
  margin-top: 3rem;
}

.faq-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
}

.faq-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.faq-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 1.5rem;
}

.faq-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
  color: var(--accent-primary);
}

.faq-card p {
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Vista exclusiva de impresión A4 (Lección 238) */
#print-sheet {
  display: none;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .app-header,
  .fijate-footer,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .controls-grid,
  .options-subbar,
  .audio-actions-row,
  .faq-section,
  #btn-theme-toggle {
    display: none !important;
  }

  #print-sheet {
    display: block !important;
    padding: 1.5cm;
  }

  .print-header {
    border-bottom: 2px solid #000000;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
  }

  .print-title {
    font-size: 24pt;
    font-weight: 800;
    margin-bottom: 0.4rem;
  }

  .print-meta {
    font-size: 11pt;
    color: #333333;
    line-height: 1.5;
  }

  .print-diagrams {
    margin: 2rem 0;
  }

  .fretboard-scroll-wrapper {
    overflow: visible !important;
  }

  .fretboard-svg {
    width: 100% !important;
    min-width: unset !important;
  }

  .fretboard-wood {
    fill: #f1f5f9 !important;
  }

  .fret-wire {
    stroke: #475569 !important;
  }

  .guitar-string {
    stroke: #0f172a !important;
  }

  .note-circle {
    stroke: #000000 !important;
    stroke-width: 1.5 !important;
  }

  .note-text {
    fill: #000000 !important;
    font-weight: 900 !important;
  }

  .chords-table th, .chords-table td {
    border-bottom: 1px solid #cccccc !important;
    color: #000000 !important;
  }
}

/* Responsividad móvil */
@media (max-width: 768px) {
  .tool-layout {
    margin: 1rem auto 2rem;
    padding: 0 0.85rem;
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

  .options-subbar {
    flex-direction: column;
    align-items: stretch;
  }

  .segmented-group {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented-option label {
    text-align: center;
    justify-content: center;
  }

  .audio-actions-row {
    flex-direction: column;
    width: 100%;
  }

  .btn-audio-action {
    width: 100%;
  }

  .tempo-control-box {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }

  .scale-hero-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
