/* ── Design tokens ───────────────────────── */
:root {
  --bg:           #0e1417;
  --surface:      #161c20;
  --border:       #243038;
  --text:         #dee3e7;
  --muted:        rgba(222, 227, 231, 0.5);
  --primary:      #50dea9;
  --secondary:    #ffb347;
  --primary-bg:   rgba(80, 222, 169, 0.08);
  --primary-glow: 0 0 15px rgba(80, 222, 169, 0.4);
  --warn:         #e09040;
  --warn-bg:      #1c1408;
  --warn-border:  #4a3010;
  --font:         'Space Grotesk', sans-serif;

  --gap:    clamp(8px, 1.8vw, 14px);
  --radius: 8px;
  --max-w:  720px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

/* ── Fullscreen button (fixed top-right) ─── */
#btn-fullscreen {
  position: fixed;
  top: var(--gap);
  right: var(--gap);
  z-index: 200;
  background: var(--primary-bg);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  color: var(--primary);
  cursor: pointer;
  padding: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow .2s;
  -webkit-tap-highlight-color: transparent;
}
#btn-fullscreen:hover { box-shadow: var(--primary-glow); }
#btn-fullscreen svg   { width: 16px; height: 16px; display: block; }

/* ── Head (fixed top) ────────────────────── */
#head {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
  padding: var(--gap) var(--gap) calc(var(--gap) * 0.75);
  border-bottom: 1px solid var(--border);
}

/* ── Acordes (scrollable chord area) ─────── */
#acordes {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--gap) var(--gap) 0;
}

/* ── Header ────────────────────────────── */
header {
  width: 100%;
  max-width: var(--max-w);
  display: flex;
  gap: 12px;
  align-items: baseline;
  flex-wrap: wrap;
}
header .title {
  color: var(--primary);
  font-size: clamp(12px, 2vw, 14px);
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 5px 12px;
  background: var(--primary-bg);
  transition: box-shadow .2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
header .title:hover { box-shadow: var(--primary-glow); }
header .author { color: var(--muted); font-size: clamp(11px, 1.8vw, 12px); }

/* ── Transport ──────────────────────────── */
#transport {
  width: 100%;
  max-width: var(--max-w);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Play button */
#btn-play {
  background: var(--primary-bg);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-radius .35s ease, box-shadow .2s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
}
#btn-play:hover { box-shadow: var(--primary-glow); }
#btn-play.playing { border-radius: 50%; }
#btn-play svg {
  width: 44%;
  height: 44%;
  fill: currentColor;
  flex-shrink: 0;
}

#tempo-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
#tempo-wrap label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
}
#tempo-slider { flex: 1; accent-color: var(--primary); cursor: pointer; min-width: 0; }
#tempo-val    { color: var(--secondary); font-size: 12px; font-weight: 700; min-width: 32px; text-align: right; }

/* ── Keyboard ───────────────────────────── */
#keyboard-wrap {
  width: 100%;
  max-width: var(--max-w);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-x: auto;
  scroll-behavior: smooth;
  color-scheme: light;           /* evita que extensiones dark-mode inviertan colores */
  forced-color-adjust: none;     /* desactiva forzado de high-contrast / forced-colors */
}
#keyboard-wrap svg { display: block; width: 100%; height: auto; }
#keyboard rect { transition: fill 0.28s ease; }

/* ── Chord info ─────────────────────────── */
#chord-info {
  width: 100%;
  max-width: var(--max-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}
.chord-name-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
#chord-info .chord-name {
  color: var(--primary);
  font-size: clamp(16px, 3vw, 22px);
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.1;
}
#chord-info .notes {
  color: var(--muted);
  font-size: clamp(10px, 1.6vw, 11px);
  letter-spacing: .06em;
}
#ci-rhythm {
  color: var(--warn);
  font-size: clamp(9px, 1.5vw, 11px);
  padding: 3px 10px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 20px;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 500;
  letter-spacing: .04em;
  transition: box-shadow .2s, border-color .2s;
  -webkit-tap-highlight-color: transparent;
}
#ci-rhythm:hover {
  border-color: var(--warn);
  box-shadow: 0 0 10px rgba(224, 144, 64, 0.35);
}

/* ── Chord grid ─────────────────────────── */
#chord-grid {
  width: 100%;
  max-width: var(--max-w);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(90px, 22vw, 170px), 1fr));
  gap: 5px;
  padding-bottom: var(--gap);
}

/* ── Chord button ───────────────────────── */
.chord-btn {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px 8px 10px;
  cursor: pointer;
  text-align: center;
  font-family: var(--font);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 0;
}
.chord-btn:hover       { border-color: rgba(222,227,231,0.3); }
.chord-btn.active      {
  background: var(--primary-bg);
  border-color: var(--primary);
  box-shadow: var(--primary-glow);
}
.chord-btn.next        { border-color: rgba(255, 179, 71, 0.45); }
.chord-btn.next:hover  { border-color: rgba(255, 179, 71, 0.75); }
.chord-btn.next.active { border-color: var(--primary); box-shadow: var(--primary-glow); }

/* Number badge — top-left corner */
.btn-num {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: .08em;
  color: var(--muted);
  line-height: 1;
}

.chord-btn .btn-name {
  font-size: clamp(13px, 2.8vw, 20px);
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  padding-top: 10px;
}
.chord-btn.active .btn-name { color: var(--primary); }
.btn-alt-mark { color: var(--secondary); font-weight: 700; }

/* Progress bar */
.chord-btn .btn-progress {
  position: absolute;
  inset: 0;
  width: 0%;
  background: rgba(80, 222, 169, 0.13);
  pointer-events: none;
  transition: none;
}

/* ── Modal overlay ───────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(14, 20, 23, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  min-width: 280px;
  max-width: 480px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-heading {
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-bottom: 18px;
}

.lista-temas {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tema-item {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.tema-item:hover {
  border-color: rgba(222, 227, 231, 0.3);
  background: rgba(255, 255, 255, 0.03);
}
.tema-item.activo {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.tema-titulo {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.tema-item.activo .tema-titulo { color: var(--primary); }

.tema-autor {
  color: var(--muted);
  font-size: 12px;
}

/* ── Var popup ────────────────────────────── */
.var-popup-box {
  background: var(--surface);
  border: 1px solid var(--warn-border);
  border-radius: 12px;
  padding: 24px 28px;
  min-width: 260px;
  max-width: 460px;
  width: 88vw;
  max-height: 75vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#var-popup-chord {
  color: var(--warn);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .04em;
}

#var-popup-body {
  color: var(--text);
  font-size: clamp(12px, 1.8vw, 14px);
  line-height: 1.65;
}
