:root {
  --bg: #0a0a0a;
  --bg-light: #1a1a1a;
  --text: #e0e0e0;
  --text-muted: #666;
  --major: #e84393;
  --minor: #00cec9;
  --dom7: #fdcb6e;
  --dim: #a29bfe;
  --aug: #55efc4;
  --tonic: #e84393;
  --subdominant: #fdcb6e;
  --dominant: #74b9ff;
  --edge: rgba(255, 255, 255, 0.15);
  --edge-hover: rgba(255, 255, 255, 0.6);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh; /* fallback */
  height: 100dvh; /* iOS Safari: evita que la barra de URL tape los controles */
  width: 100vw;
}

#app {
  display: flex; flex-direction: column;
  height: 100vh; /* fallback */
  height: 100dvh;
}

/* Header */
#header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 20px 10px;
  background: var(--bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 100;
  flex-shrink: 0;
  position: relative;
}
#header-top {
  display: flex; align-items: center; justify-content: space-between;
}
#header h1 {
  font-size: 15px; font-weight: 600; letter-spacing: 0.4px;
  color: var(--text);
}

/* Header right-side group (CTA + lang selector) */
.header-right-group {
  display: flex; align-items: center; gap: 8px;
}

/* Learn CTA */
.learn-cta {
  text-decoration: none;
  font-size: 11px;
  padding: 5px 12px;
  background: linear-gradient(135deg, rgba(232,67,147,0.18), rgba(0,206,201,0.12));
  border: 1px solid rgba(232,67,147,0.35);
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(232,67,147,0.12);
  transition: all 0.22s ease;
  position: relative;
  overflow: hidden;
}
.learn-cta:hover {
  background: linear-gradient(135deg, rgba(232,67,147,0.32), rgba(0,206,201,0.22));
  border-color: rgba(232,67,147,0.6);
  box-shadow: 0 4px 18px rgba(232,67,147,0.3);
  transform: translateY(-1px);
}
.learn-cta:active { transform: translateY(0); }
@keyframes learn-cta-pulse {
  0%, 100% { box-shadow: 0 2px 10px rgba(232,67,147,0.12); }
  50% { box-shadow: 0 2px 18px rgba(232,67,147,0.35); }
}
.learn-cta { animation: learn-cta-pulse 3.2s ease-in-out infinite; }

/* Language selector */
#lang-selector { position: relative; }
#lang-toggle { font-size: 11px; padding: 4px 10px; }
.lang-dropdown {
  position: absolute; top: 100%; right: 0; margin-top: 4px;
  background: rgba(20,20,20,0.95); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px; padding: 4px;
  backdrop-filter: blur(12px); z-index: 200;
  min-width: 130px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.lang-dropdown.hidden { display: none; }
.lang-option {
  display: block; width: 100%;
  background: none; border: none; color: var(--text-muted);
  padding: 6px 12px; font-size: 12px; font-family: inherit;
  cursor: pointer; border-radius: 6px; text-align: left;
  transition: background 0.15s, color 0.15s;
}
.lang-option:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.lang-option.active { background: rgba(255,255,255,0.12); color: #fff; font-weight: 600; }

/* Chip rows */
.chip-row {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 2px;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip-label {
  font-size: 10px; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.6px; min-width: 32px; flex-shrink: 0; white-space: nowrap;
}
.chip-divider {
  color: rgba(255,255,255,0.12); font-size: 14px; margin: 0 2px;
  flex-shrink: 0; user-select: none;
}
.chip-scroll {
  display: flex; align-items: center; gap: 4px;
  overflow-x: auto; scrollbar-width: none;
  -ms-overflow-style: none; padding: 2px 0;
}
.chip-scroll::-webkit-scrollbar { display: none; }
.chip {
  background: transparent; color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px; padding: 4px 10px;
  font-size: 11px; font-family: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: background 0.25s ease, border-color 0.25s ease,
              color 0.25s ease, transform 0.2s ease;
  transform: scale(1);
}
.chip:hover {
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text);
}
.chip:active { transform: scale(0.95); }
.chip.active {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
}
.chip.minor { font-style: italic; }

/* Main SVG area */
#main { flex: 1; position: relative; overflow: hidden; z-index: 1; touch-action: none; }
#graph {
  width: 100%; height: 100%; display: block;
  touch-action: none;
}

/* Top-right controls */
#top-right-controls {
  position: absolute; top: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 10;
}
.tr-toggle {
  background: rgba(20,20,20,0.85); color: var(--text-muted);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 10px;
  padding: 6px 12px; font-size: 11px; font-family: inherit; font-weight: 500;
  cursor: pointer; backdrop-filter: blur(10px);
  transition: all 0.2s; text-align: left; white-space: nowrap;
}
.tr-toggle:hover {
  background: rgba(30,30,30,0.95); border-color: rgba(255,255,255,0.25); color: var(--text);
}
.tr-toggle.active {
  background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.3); color: #fff;
}

/* Zoom controls */
#zoom-controls {
  position: absolute; bottom: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 10;
}
#zoom-controls button {
  width: 36px; height: 36px;
  background: rgba(20,20,20,0.85);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; color: var(--text);
  font-size: 18px; font-family: inherit;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  backdrop-filter: blur(10px);
  transition: background 0.2s, border-color 0.2s;
  line-height: 1; padding: 0;
}
#zoom-controls button:hover {
  background: rgba(30,30,30,0.95);
  border-color: rgba(255,255,255,0.25);
  color: #fff;
}
#zoom-controls button:active { transform: scale(0.92); }
#zoom-reset { font-size: 15px; }

/* Edges */
.edge {
  fill: none; stroke: var(--edge); stroke-width: 1;
  transition: stroke 0.3s, stroke-opacity 0.3s, stroke-width 0.3s;
}
.edge.highlighted { stroke: var(--edge-hover); stroke-width: 1.5; stroke-opacity: 1; }
.edge.edge-non-dia { stroke-opacity: 0.08; }
.edge.dimmed { stroke-opacity: 0.05; }
.edge.dotted { stroke-dasharray: 4 3; }
.edge.dim-family { stroke: rgba(162,155,254,0.3); stroke-width: 0.8; }
.edge.primary { stroke-width: 1.8; stroke: rgba(255,255,255,0.22); }

/* Nodes */
.node { cursor: pointer; transition: opacity 0.3s; }
.node.dimmed { opacity: 0.15; }
.node.non-diatonic .node-circle { stroke-opacity: 0.2; }
.node.non-diatonic .node-label { fill-opacity: 0.2; }

.node-circle {
  fill: var(--bg); stroke-width: 2;
  transition: fill 0.2s, stroke-width 0.2s, filter 0.2s;
}
.node:hover .node-circle { stroke-width: 2.5; }

.node-major .node-circle { stroke: var(--major); }
.node-minor .node-circle { stroke: var(--minor); }
.node-dom7 .node-circle { stroke: var(--dom7); }
.node-dim .node-circle { stroke: var(--dim); }
.node-aug .node-circle { stroke: var(--aug); }

.node-label {
  text-anchor: middle; dominant-baseline: central;
  font-size: 11px; font-weight: 500;
  pointer-events: none; transition: fill 0.2s;
}
.node-major .node-label { fill: var(--major); }
.node-minor .node-label { fill: var(--minor); }
.node-dom7 .node-label { fill: var(--dom7); }
.node-dim .node-label { fill: var(--dim); }
.node-aug .node-label { fill: var(--aug); }

/* Roman numeral secondary label */
.node-roman {
  text-anchor: middle; font-size: 9px;
  fill: var(--text-muted); pointer-events: none;
}

/* Selected glow */
.node.selected .node-circle { stroke-width: 3; }
.node-major.selected .node-circle { filter: drop-shadow(0 0 8px var(--major)); }
.node-minor.selected .node-circle { filter: drop-shadow(0 0 8px var(--minor)); }
.node-dom7.selected .node-circle { filter: drop-shadow(0 0 8px var(--dom7)); }
.node-dim.selected .node-circle { filter: drop-shadow(0 0 8px var(--dim)); }
.node-aug.selected .node-circle { filter: drop-shadow(0 0 8px var(--aug)); }

.node-major:hover .node-circle { filter: drop-shadow(0 0 4px var(--major)); }
.node-minor:hover .node-circle { filter: drop-shadow(0 0 4px var(--minor)); }
.node-dom7:hover .node-circle { filter: drop-shadow(0 0 4px var(--dom7)); }
.node-dim:hover .node-circle { filter: drop-shadow(0 0 4px var(--dim)); }
.node-aug:hover .node-circle { filter: drop-shadow(0 0 4px var(--aug)); }

/* Tree links */
.tree-link {
  fill: none; stroke: var(--edge); stroke-width: 1.2;
  transition: stroke 0.3s, stroke-opacity 0.3s;
}
.tree-link.highlighted { stroke: var(--edge-hover); stroke-width: 1.8; }
.tree-link.dimmed { stroke-opacity: 0.05; }

/* Tonnetz */
.tonnetz-edge { stroke: rgba(255,255,255,0.07); stroke-width: 0.8; fill: none; }
.tonnetz-edge.fifth { stroke: rgba(232,67,147,0.12); }
.tonnetz-edge.major-third { stroke: rgba(0,206,201,0.12); }
.tonnetz-edge.minor-third { stroke: rgba(253,203,110,0.12); }
.tonnetz-tri {
  opacity: 0.06; cursor: pointer;
  transition: opacity 0.2s, fill 0.2s;
}
.tonnetz-tri:hover { opacity: 0.3; }
.tonnetz-tri.highlighted { opacity: 0.22; }
.tonnetz-tri.active { opacity: 0.35; }

/* Center root badge */
.center-root-circle {
  fill: var(--bg-light); stroke-width: 2.5;
  filter: drop-shadow(0 0 12px rgba(255,255,255,0.08));
}
.center-root-label {
  text-anchor: middle; dominant-baseline: central;
  font-size: 16px; font-weight: 600; fill: #fff;
}
.center-root-sub {
  text-anchor: middle; font-size: 9px;
  fill: var(--text-muted); letter-spacing: 0.5px;
}

/* Diatonic guide shape */
.diatonic-guide { fill: none; stroke: rgba(255,255,255,0.04); stroke-width: 1; }

/* Tooltip */
#tooltip {
  position: fixed; display: none;
  background: rgba(26, 26, 26, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px; padding: 10px 14px;
  font-size: 12px; pointer-events: none;
  z-index: 100; backdrop-filter: blur(8px); max-width: 240px;
}
#tooltip .chord-name { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
#tooltip .chord-type { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
#tooltip .chord-notes { margin-top: 6px; color: var(--text-muted); }
#tooltip .chord-function { margin-top: 4px; font-size: 11px; color: var(--text-muted); }

/* Info panel (legend + guide, collapsible) */
#info-panel {
  position: fixed; bottom: 16px; left: 16px;
  z-index: 10; max-width: 280px;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
#info-panel.collapsed #info-body { display: none; }
#info-panel.collapsed { max-width: none; }

#info-toggle {
  display: flex; align-items: center; gap: 6px;
  background: rgba(20,20,20,0.85); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; padding: 6px 12px;
  color: var(--text-muted); font-size: 11px; font-family: inherit;
  cursor: pointer; backdrop-filter: blur(10px);
  transition: background 0.2s, border-color 0.2s;
  margin-bottom: 6px;
}
#info-toggle:hover { background: rgba(30,30,30,0.95); border-color: rgba(255,255,255,0.2); }
#info-toggle .arrow { transition: transform 0.3s; display: inline-block; }
#info-panel.collapsed #info-toggle .arrow { transform: rotate(180deg); }

#info-body {
  background: rgba(20, 20, 20, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 11px;
  line-height: 1.55;
  backdrop-filter: blur(12px);
  color: var(--text-muted);
}

#info-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid; background: var(--bg);
}
.legend-dot.major { border-color: var(--major); }
.legend-dot.minor { border-color: var(--minor); }
.legend-dot.dom7 { border-color: var(--dom7); }
.legend-dot.dim { border-color: var(--dim); }
.legend-dot.aug { border-color: var(--aug); }

#info-guide { border-top: 1px solid rgba(255,255,255,0.06); padding-top: 8px; }
.guide-title {
  font-size: 11px; font-weight: 600; color: var(--text);
  margin-bottom: 4px; letter-spacing: 0.3px;
}
.guide-body b { color: var(--text); font-weight: 500; }

/* Chord diagram modal */
.chord-modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}
.chord-modal.hidden { display: none; }
.chord-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
}
.chord-modal-card {
  position: relative;
  background: #181818;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 28px 32px 24px;
  min-width: 280px;
  max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.chord-modal-close {
  position: absolute; top: 10px; right: 14px;
  background: none; border: none; color: var(--text-muted);
  font-size: 22px; cursor: pointer; line-height: 1;
  transition: color 0.2s;
}
.chord-modal-close:hover { color: #fff; }
.chord-modal-title {
  font-size: 22px; font-weight: 700;
  margin-bottom: 2px;
}
.chord-modal-notes {
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 12px;
}
.chord-modal-instrument {
  display: flex; gap: 6px; margin-bottom: 14px;
}
.chord-instr-btn {
  background: transparent; color: var(--text-muted);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px; padding: 4px 14px;
  font-size: 11px; font-family: inherit; font-weight: 500;
  cursor: pointer; transition: all 0.2s;
}
.chord-instr-btn:hover {
  border-color: rgba(255,255,255,0.25); color: var(--text);
}
.chord-instr-btn.active {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.3); color: #fff;
}
.chord-modal-diagram svg { display: block; margin: 0 auto; }
.chord-modal-play {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; margin-top: 14px; padding: 10px 0;
  background: rgba(255,255,255,0.08); color: var(--text);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 12px;
  font-size: 13px; font-family: inherit; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.chord-modal-play:hover {
  background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.3);
}
.chord-modal-play:active { transform: scale(0.97); }
.chord-modal-play.playing {
  background: rgba(232,67,147,0.15); border-color: var(--major); color: var(--major);
}

/* Piano keys in modal */
.piano-white {
  stroke: #333; stroke-width: 0.5; rx: 2;
}
.piano-black {
  stroke: #111; stroke-width: 0.5; rx: 1.5;
}
.piano-hl { fill: #f0932b; }
.piano-label {
  font-size: 10px; font-weight: 600; fill: #fff;
  text-anchor: middle; dominant-baseline: auto;
}

/* Guitar diagram in modal */
.guitar-string { stroke: rgba(255,255,255,0.35); }
.guitar-fret { stroke: rgba(255,255,255,0.2); }
.guitar-nut { stroke: #fff; stroke-width: 3; }
.guitar-dot {
  fill: #f0932b; stroke: none;
}
.guitar-finger {
  font-size: 9px; font-weight: 700; fill: #fff;
  text-anchor: middle; dominant-baseline: central;
}
.guitar-open {
  font-size: 11px; fill: rgba(255,255,255,0.5);
  text-anchor: middle;
}
.guitar-mute {
  font-size: 11px; fill: rgba(255,255,255,0.3);
  text-anchor: middle;
}
.guitar-fret-label {
  font-size: 10px; fill: var(--text-muted);
}

/* Modulation panel */
.modulation-panel {
  position: fixed;
  top: 15vh;
  right: 16px;
  bottom: 15vh;
  width: 260px;
  min-width: 200px;
  min-height: 180px;
  background: rgba(20, 20, 20, 0.92);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 16px;
  z-index: 10;
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 12px;
  resize: horizontal;
  overflow: hidden;
  direction: rtl;
}
.modulation-panel > * { direction: ltr; }
.modulation-panel.hidden { display: none; }
.modulation-panel::-webkit-resizer {
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.15) 40%,
    rgba(255,255,255,0.15) 45%, transparent 45%, transparent 55%,
    rgba(255,255,255,0.15) 55%, rgba(255,255,255,0.15) 60%, transparent 60%);
}
.mod-toggle {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; color: #fff;
  font-size: 13px; font-weight: 600; font-family: inherit;
  letter-spacing: 0.3px; cursor: pointer; padding: 0;
  width: 100%;
}
.mod-toggle:hover { color: rgba(255,255,255,0.7); }
.mod-toggle-arrow {
  font-size: 10px; transition: transform 0.25s;
  display: inline-block;
}
.modulation-panel.collapsed .mod-toggle-arrow { transform: rotate(-90deg); }
.mod-body {
  display: flex; flex-direction: column; gap: 12px;
  flex: 1; min-height: 0; overflow: hidden;
}
.modulation-panel.collapsed .mod-body { display: none; }
.modulation-panel.collapsed {
  bottom: auto; min-height: 0; resize: none;
}
.mod-selectors {
  display: flex; align-items: flex-end; gap: 8px;
}
.mod-field {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
}
.mod-field label {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.mod-field select {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; color: #fff;
  padding: 6px 8px; font-family: inherit;
  font-size: 12px; cursor: pointer; outline: none;
}
.mod-field select:focus { border-color: rgba(255,255,255,0.3); }
.mod-field select option,
.mod-field select optgroup { background: #1a1a1a; color: #fff; }
.mod-swap-btn {
  background: none; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px; color: var(--text-muted);
  padding: 5px 8px; cursor: pointer; font-size: 14px;
  transition: all 0.2s; margin-bottom: 1px;
}
.mod-swap-btn:hover {
  border-color: rgba(255,255,255,0.3); color: #fff;
}
.mod-paths-header {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 8px;
}
.mod-paths {
  overflow-y: auto; flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 4px;
  scrollbar-width: thin;
}
.mod-path-item {
  display: flex; gap: 10px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; transition: all 0.2s;
}
.mod-path-item:hover { background: rgba(255,255,255,0.04); }
.mod-path-item.active {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.15);
}
.mod-path-num {
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: var(--text-muted);
  flex-shrink: 0;
}
.mod-path-item.active .mod-path-num {
  background: rgba(116,185,255,0.2); color: #74b9ff;
}
.mod-path-info { flex: 1; min-width: 0; }
.mod-path-keys {
  font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mod-path-techs {
  font-size: 9px; color: var(--text-muted); margin-top: 3px;
  display: flex; flex-wrap: wrap; gap: 2px 8px;
}
.mod-tech { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.mod-tech-dot {
  width: 6px; height: 6px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
  background: rgba(255,255,255,0.15);
}
/* Botón ▶ por ruta de modulación */
.mod-path-play {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  align-self: center; padding: 0;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7); font-size: 8px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.mod-path-play:hover {
  background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.35); color: #fff;
}
.mod-path-play.playing {
  background: rgba(232,67,147,0.12); border-color: var(--major); color: var(--major);
}
.mod-path-empty {
  color: var(--text-muted); font-style: italic;
  padding: 12px 0; text-align: center;
}

/* Botón ▶ de cada progresión (SVG) */
.prog-play { cursor: pointer; }
.prog-play-circle {
  fill: rgba(255,255,255,0.05);
  stroke: rgba(255,255,255,0.25); stroke-width: 1;
  transition: all 0.2s;
}
.prog-play:hover .prog-play-circle {
  fill: rgba(255,255,255,0.14); stroke: rgba(255,255,255,0.5);
}
.prog-play-icon {
  fill: rgba(255,255,255,0.8); font-size: 11px;
  pointer-events: none; user-select: none;
}
.prog-play.playing .prog-play-circle {
  fill: rgba(232,67,147,0.15); stroke: var(--major);
}
.prog-play.playing .prog-play-icon { fill: var(--major); }

/* Acorde resaltado mientras suena en una secuencia */
.node.seq-active { opacity: 1 !important; }
.node.seq-active .node-circle {
  stroke-width: 4;
  filter: drop-shadow(0 0 8px rgba(255,255,255,0.65));
}

/* ============================================================
   Progression Playground (vista 'playground' — capa HTML sobre #graph)
   ============================================================ */
#playground-panel {
  position: absolute; inset: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  touch-action: pan-y; /* #main tiene touch-action:none; aquí sí queremos scroll */
  z-index: 5;
  padding: 24px 20px 40px;
  display: flex; justify-content: center;
}
#playground-panel.hidden { display: none; }
.pg-inner {
  width: 100%; max-width: 860px;
  display: flex; flex-direction: column; gap: 20px;
  padding-right: 120px; /* deja sitio a los controles de la esquina superior derecha */
}
.pg-section {
  background: rgba(20,20,20,0.7);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 14px;
  padding: 16px 18px;
  backdrop-filter: blur(8px);
}
.pg-section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 4px;
}
.pg-section-title {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.8px;
  margin-bottom: 10px;
}
.pg-section-head .pg-section-title { margin-bottom: 0; }
.pg-count { font-weight: 400; text-transform: none; letter-spacing: 0; }
.pg-row-label {
  font-size: 9px; color: rgba(255,255,255,0.28);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin: 8px 0 5px;
}
.pg-row-label:first-of-type { margin-top: 0; }

/* Chips de acorde (paleta, sugerencias y pasos de la línea de tiempo) */
.pg-palette { display: flex; flex-wrap: wrap; gap: 6px; }
.pg-chip, .pg-step {
  display: inline-flex; flex-direction: column; align-items: center;
  gap: 1px; min-width: 48px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px; padding: 6px 10px;
  font-family: inherit; cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}
.pg-chip:hover, .pg-step:hover {
  background: rgba(255,255,255,0.08);
  transform: translateY(-1px);
}
.pg-chip:active, .pg-step:active { transform: scale(0.94); }
.pg-chip-name { font-size: 13px; font-weight: 600; line-height: 1.1; }
.pg-chip-roman { font-size: 9px; color: var(--text-muted); line-height: 1.1; }
/* Color por tipo de acorde (mismos colores que los nodos del grafo) */
.pg-major { border-color: rgba(232,67,147,0.45); }
.pg-major .pg-chip-name { color: var(--major); }
.pg-minor { border-color: rgba(0,206,201,0.45); }
.pg-minor .pg-chip-name { color: var(--minor); }
.pg-dom7 { border-color: rgba(253,203,110,0.45); }
.pg-dom7 .pg-chip-name { color: var(--dom7); }
.pg-dim { border-color: rgba(162,155,254,0.45); }
.pg-dim .pg-chip-name { color: var(--dim); }
/* Pulso del chip de la paleta mientras suena su acorde */
@keyframes pg-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.35); }
  100% { box-shadow: 0 0 0 9px rgba(255,255,255,0); }
}
.pg-chip.pg-pulse {
  background: rgba(255,255,255,0.12);
  animation: pg-pulse 0.5s ease-out;
}

/* Sugerencias de siguiente acorde */
.pg-suggest {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
  min-height: 20px;
}
.pg-suggest-label { font-size: 10px; color: var(--text-muted); margin-right: 4px; }
.pg-chip-suggest { border-style: dashed; background: transparent; }

/* Línea de tiempo (scroll horizontal en móvil) */
.pg-timeline {
  display: flex; gap: 6px; align-items: stretch;
  overflow-x: auto; scrollbar-width: thin; touch-action: pan-x pan-y;
  padding: 6px 2px; min-height: 56px;
}
.pg-step { flex-shrink: 0; position: relative; }
.pg-step:hover { border-color: rgba(255,100,100,0.6); }
.pg-step:hover::after {
  content: '✕'; position: absolute; top: -6px; right: -5px;
  width: 14px; height: 14px; border-radius: 50%;
  background: rgba(200,60,60,0.9); color: #fff;
  font-size: 8px; line-height: 14px; text-align: center;
}
.pg-step.pg-active {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.6);
  box-shadow: 0 0 10px rgba(255,255,255,0.25);
}
.pg-empty {
  color: var(--text-muted); font-size: 12px; font-style: italic;
  align-self: center; padding: 8px 4px;
}
.pg-roman {
  font-size: 12px; color: rgba(255,255,255,0.55);
  letter-spacing: 0.5px; min-height: 16px; margin-top: 6px;
  font-variant-numeric: lining-nums;
}

/* Transporte */
.pg-transport {
  display: flex; align-items: center; flex-wrap: wrap; gap: 14px;
}
.pg-btn {
  background: rgba(255,255,255,0.07); color: var(--text);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 12px;
  padding: 9px 18px; font-size: 12px; font-family: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s;
}
.pg-btn:hover { background: rgba(255,255,255,0.13); border-color: rgba(255,255,255,0.3); }
.pg-btn:active { transform: scale(0.96); }
.pg-btn-small { padding: 4px 10px; font-size: 10px; font-weight: 500; color: var(--text-muted); }
.pg-btn-play { min-width: 96px; }
.pg-btn-play.playing {
  background: rgba(232,67,147,0.15); border-color: var(--major); color: var(--major);
}
.pg-btn.copied { border-color: var(--minor); color: var(--minor); }
.pg-tempo { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 180px; }
.pg-tempo label {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.pg-tempo input[type="range"] {
  flex: 1; accent-color: var(--major); cursor: pointer; min-width: 80px;
}
.pg-bpm { font-size: 11px; color: var(--text); min-width: 58px; text-align: right; font-variant-numeric: tabular-nums; }

/* Responsive */
@media (max-width: 768px) {
  /* Deja libre la esquina superior derecha (auto-play / instrumento / notación) */
  #playground-panel { padding: 100px 10px 30px; align-items: flex-start; }
  .pg-inner { padding-right: 0; gap: 12px; }
  .pg-section { padding: 12px; }
  .pg-chip, .pg-step { min-width: 44px; padding: 7px 9px; } /* táctil */
  .pg-transport { gap: 10px; }
}

@media (max-width: 768px) {
  #header { padding: 8px 12px; gap: 4px; }
  #header h1 { font-size: 13px; }
  .chip-label { display: none; }
  .chip { padding: 3px 7px; font-size: 10px; }
  .learn-cta { font-size: 10px; padding: 4px 8px; }
  #info-panel { max-width: 200px; bottom: auto; left: 10px; }
  #info-body { font-size: 10px; padding: 10px 12px; }
  #info-toggle { padding: 5px 10px; font-size: 10px; }
  .modulation-panel {
    top: auto; bottom: 0; left: 0; right: 0;
    width: auto; min-width: 0;
    max-height: 50vh; min-height: 0;
    border-radius: 16px 16px 0 0;
    padding: 12px 16px;
    font-size: 11px;
    resize: none; direction: ltr;
  }
  .modulation-panel > * { direction: ltr; }
  .modulation-panel.collapsed {
    max-height: none; bottom: 0;
  }
  .mod-swap-btn { padding: 3px 6px; font-size: 12px; }
  #top-right-controls { top: 10px; right: 10px; }
  .tr-toggle { padding: 4px 8px; font-size: 10px; }
  #zoom-controls button { width: 32px; height: 32px; font-size: 16px; }
  #zoom-controls { bottom: 10px; right: 10px; }
}

/* ============================================================
   Live input (MIDI + micrófono) — vista círculo de quintas
   ============================================================ */
/* Punto rojo "LIVE" parpadeante en el botón mientras está activo */
#live-toggle.live-on { color: #fff; border-color: rgba(255, 80, 80, 0.55); }
#live-toggle.live-on::after {
  content: ''; display: inline-block; width: 7px; height: 7px; margin-left: 7px;
  border-radius: 50%; background: #ff3b30; vertical-align: middle;
  animation: liveBlink 1.1s ease-in-out infinite;
}
@keyframes liveBlink {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px rgba(255, 59, 48, 0.9); }
  50% { opacity: 0.35; box-shadow: 0 0 1px rgba(255, 59, 48, 0.4); }
}

/* HUD: tarjeta oscura arriba a la derecha, bajo los toggles */
#live-hud {
  position: absolute; top: 172px; right: 16px; z-index: 11;
  width: 200px; padding: 12px 14px;
  background: rgba(12, 12, 14, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px; backdrop-filter: blur(10px);
  color: var(--text); font-size: 11px;
}
#live-hud.hidden { display: none; }
.live-hud-head { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-weight: 600; letter-spacing: 0.04em; }
.live-hud-dot { width: 7px; height: 7px; border-radius: 50%; background: #ff3b30; animation: liveBlink 1.1s ease-in-out infinite; flex: none; }
.live-hud-switch {
  margin-left: auto; background: none; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px; color: var(--text-muted); cursor: pointer;
  font-size: 11px; font-family: inherit; padding: 1px 6px;
}
.live-hud-switch:hover { color: #fff; border-color: rgba(255,255,255,0.4); }
.live-hud-status { margin-top: 6px; color: var(--text-muted); min-height: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-hud-main { margin-top: 4px; font-size: 26px; font-weight: 600; color: #ffe066; min-height: 32px; line-height: 1.2; }
.live-hud-sub { color: var(--text-muted); min-height: 13px; }
.live-hud-level { margin-top: 8px; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.08); overflow: hidden; }
.live-hud-level.hidden { display: none; }
#live-hud-level-fill { height: 100%; width: 0; background: linear-gradient(90deg, #00cec9, #ffe066); transition: width 0.12s; }

/* Selector de fuente (MIDI / micrófono) */
#live-picker {
  position: absolute; top: 172px; right: 16px; z-index: 12;
  width: 220px; padding: 14px;
  background: rgba(12, 12, 14, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px; backdrop-filter: blur(10px);
  display: flex; flex-direction: column; gap: 8px;
}
#live-picker.hidden { display: none; }
.live-picker-title { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.live-picker-btn {
  background: rgba(255,255,255,0.06); color: var(--text);
  border: 1px solid rgba(255,255,255,0.14); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; font-family: inherit;
  cursor: pointer; text-align: left; transition: all 0.15s;
}
.live-picker-btn:hover:not(:disabled) { background: rgba(255,255,255,0.13); border-color: rgba(255,255,255,0.35); }
.live-picker-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Resplandor del acorde/nota detectados (SVG: stroke + drop-shadow animados) */
.node.live-active { opacity: 1 !important; }
.node.live-active .node-circle {
  stroke: #ffe066; fill: rgba(255, 224, 102, 0.16);
  animation: livePulse 0.9s ease-in-out infinite;
}
.node.live-active .node-label { fill: #fff; font-weight: 700; }
@keyframes livePulse {
  0%, 100% {
    stroke-width: 4;
    filter: drop-shadow(0 0 6px rgba(255,224,102,0.9)) drop-shadow(0 0 14px rgba(255,224,102,0.5));
  }
  50% {
    stroke-width: 6;
    filter: drop-shadow(0 0 12px rgba(255,224,102,1)) drop-shadow(0 0 26px rgba(255,224,102,0.7));
  }
}
/* Resoluciones clásicas del acorde detectado: brillo suave */
.node.live-next { opacity: 1 !important; }
.node.live-next .node-circle {
  stroke: rgba(255, 224, 102, 0.55); stroke-width: 2.5;
  filter: drop-shadow(0 0 6px rgba(255, 224, 102, 0.35));
}
/* 1-2 notas sueltas: posición de la clase de altura, iluminación tenue */
.node.live-dim { opacity: 1 !important; }
.node.live-dim .node-circle {
  stroke: rgba(255, 224, 102, 0.45);
  filter: drop-shadow(0 0 5px rgba(255, 224, 102, 0.3));
}

@media (max-width: 768px) {
  #live-hud, #live-picker { top: 150px; right: 10px; width: 170px; }
  .live-hud-main { font-size: 20px; }
}
