:root {
  --bg: #0a0b10;
  --bg-elevated: #15171f;
  --bg-input: #1c1f29;
  --text: #f3f4f8;
  --text-dim: #8d93a8;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --accent-contrast: #ffffff;
  --border: #272b37;
  --danger: #fb7185;
  --warn: #f5a524;
  --chords-zone-bg: color-mix(in srgb, var(--accent) 14%, var(--bg-input));
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --gradient: linear-gradient(135deg, var(--accent), var(--accent-2));
  --font-main: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', Consolas, Menlo, monospace;
}

[data-theme='light'] {
  --bg: #f4f5fa;
  --bg-elevated: #ffffff;
  --bg-input: #eef0f7;
  --text: #15161d;
  --text-dim: #666c82;
  --accent: #7c3aed;
  --accent-2: #0891b2;
  --accent-contrast: #ffffff;
  --border: #e3e5f0;
  --warn: #b5700a;
  --shadow: 0 10px 30px -12px rgba(30, 20, 60, 0.15);
  --shadow-sm: 0 2px 10px rgba(30, 20, 60, 0.06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  height: 100%;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font-family: inherit;
  font-size: 1rem;
}

.btn {
  background: var(--gradient);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.65em 1.2em;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: filter 0.15s, transform 0.15s;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn--secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
.btn--danger { background: var(--danger); color: white; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"] {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6em 0.85em;
}
input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5em 0.6em;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.2rem;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header__brand {
  font-weight: 800; font-size: 1.25rem; letter-spacing: -0.02em;
  background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.app-header__nav { display: flex; gap: 0.3rem; flex: 1; }
.app-header__link {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-weight: 600; padding: 0.45em 0.8em; border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.app-header__link:hover { color: var(--text); background: var(--bg-input); }
.app-header__link.is-active { color: var(--accent); background: var(--bg-input); }
.app-header__actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; min-width: 0; }
.app-header__menu-btn {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: var(--radius-sm); cursor: pointer; padding: 0.5em 0.7em;
  display: flex; align-items: center; transition: color 0.15s, border-color 0.15s;
}
.app-header__menu-btn svg { width: 20px; height: 20px; fill: currentColor; }
.app-header__menu-btn:hover { color: var(--accent); border-color: var(--accent); }

/* Chips reutilizables (notación, tema, escuchar...) */
.chip-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.chip {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 0.4em 0.9em; cursor: pointer; font-weight: 600; font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--accent); }
.chip.is-active { background: var(--gradient); color: var(--accent-contrast); border-color: transparent; }
.chip--listen { color: var(--accent); }

.settings-group { margin-bottom: 1.1rem; }
.settings-group__label { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 0.4rem; font-weight: 600; }
.settings-signout { width: 100%; margin-top: 0.4rem; }

.app-main { max-width: 1000px; margin: 0 auto; padding: 1rem; }

.view-header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.view-header h2 { margin: 0; flex: 1; }
.view-header__spacer { flex: 1; }

/* Auth */
.auth-box { max-width: 380px; margin: 10vh auto; text-align: center; }
.auth-box__subtitle { color: var(--text-dim); margin-bottom: 1.5rem; }
.auth-form { display: flex; flex-direction: column; gap: 0.7rem; }
.auth-form__actions { display: flex; gap: 0.6rem; }
.auth-form__actions .btn { flex: 1; }
.auth-error { color: var(--danger); }
.auth-info { color: var(--accent); }

/* Songs list */
.songs-search { width: 100%; margin-bottom: 1rem; }
.songs-list { display: flex; flex-direction: column; gap: 0.6rem; }
.song-card {
  display: flex; align-items: center; gap: 0.8rem;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.9rem 1.1rem; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: border-color 0.15s, transform 0.15s;
}
.song-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.song-card__title { font-weight: 600; }
.song-card__artist { color: var(--text-dim); font-size: 0.9rem; }
.song-card__meta { color: var(--text-dim); font-size: 0.85rem; margin-left: auto; text-align: right; }
.song-card__delete { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 1.2rem; }
.song-card__delete:hover { color: var(--danger); }
.song-card__prompter {
  background: var(--gradient); color: var(--accent-contrast); border: none;
  border-radius: 999px; width: 34px; height: 34px; min-width: 34px; cursor: pointer;
  font-size: 0.9rem; box-shadow: var(--shadow-sm);
}
.song-card__prompter:hover { filter: brightness(1.08); }

/* Editor */
.editor-meta { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.editor-meta__title { flex: 2; min-width: 160px; }
.editor-meta__artist { flex: 1; min-width: 140px; }
.editor-meta__bpm { width: 80px; }
.editor-meta label { display: flex; align-items: center; gap: 0.4em; color: var(--text-dim); }

.editor-header-chords { margin-bottom: 1.2rem; padding: 0.8rem; background: var(--bg-elevated); border-radius: var(--radius); border: 1px solid var(--border); }
.editor-header-chords h3 { margin: 0 0 0.6rem; font-size: 1rem; }
.editor-header-chords__chips { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.6rem; }

.chord-chip {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 999px;
  padding: 0.3em 0.8em; font-weight: 600; cursor: pointer; color: var(--text);
}
.chord-chip--removable { cursor: default; display: inline-flex; align-items: center; gap: 0.4em; }
.chord-chip__remove { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 1rem; }

.editor-paste { display: flex; gap: 0.6rem; margin-bottom: 1.2rem; flex-wrap: wrap; }

.editor-section {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.8rem; margin-bottom: 0.9rem;
}
.editor-section__head { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; flex-wrap: wrap; align-items: center; }
.editor-section__label { flex: 1; min-width: 140px; }
.editor-section__move { display: flex; gap: 0.3rem; margin-left: auto; }
.editor-section__up, .editor-section__down, .editor-section__delete {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); cursor: pointer; padding: 0.3em 0.6em; font-size: 0.85rem;
}
.editor-section__merge-up {
  background: color-mix(in srgb, var(--warn) 18%, var(--bg-input)); color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--border));
  border-radius: var(--radius-sm); cursor: pointer; padding: 0.3em 0.6em; font-size: 0.85rem; font-weight: 600;
}
.editor-section__merge-up:hover { filter: brightness(1.1); }

.editor-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 1.8rem; }
.editor-line__words {
  flex: 1; font-family: var(--font-mono); padding: 0.35em 0.5em; border-radius: var(--radius-sm);
  background: var(--chords-zone-bg); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  min-height: 1.6em; line-height: 1.6;
}
.editor-word { cursor: pointer; padding: 0 2px; border-radius: 4px; position: relative; }
.editor-word:hover { background: var(--border); }
.editor-word.has-chord { color: var(--accent); }
.editor-word__chord {
  display: block; font-size: 0.7em; color: var(--accent); font-weight: 700; line-height: 1;
  position: relative; top: -0.1em;
}
.editor-line__text { flex: 1; display: none; }
.editor-line__split {
  flex: 1 0 100%; order: -1;
  background: color-mix(in srgb, var(--warn) 18%, var(--bg-input)); color: var(--warn);
  border: 1px dashed color-mix(in srgb, var(--warn) 55%, var(--border));
  border-radius: var(--radius-sm); cursor: pointer; padding: 0.4em 0.8em; font-size: 0.75rem; font-weight: 600;
  text-align: left;
}
.editor-line__split:hover { filter: brightness(1.1); }
.editor-line__delete { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 1.2rem; }
.editor-line__delete:hover { color: var(--danger); }

/* mostrar el input de texto real debajo en pantallas pequeñas para edición táctil fácil */
@media (max-width: 640px) {
  .editor-line__text { display: block; flex: 1 0 100%; }
}
@media (min-width: 641px) {
  .editor-line__text { display: block; width: 45%; }
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5, 6, 10, 0.65); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal-box {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.3rem; max-width: 480px; width: 100%; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
}

/* Chord picker / drawer */
.chord-picker__custom { display: flex; gap: 0.5rem; margin: 0.6rem 0; }
.chord-picker__custom input { flex: 1; }
.chord-picker__library { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; max-height: 160px; overflow-y: auto; }
.chord-picker__draw, .chord-picker__remove { width: 100%; margin-top: 0.5rem; }

.chord-drawer__detected { color: var(--accent); margin-bottom: 0.6rem; }
.chord-drawer__editor { margin: 0.8rem 0; }
.chord-drawer__label-input { display: block; margin-bottom: 0.6rem; }
.chord-drawer__label-input input { width: 100%; margin-top: 0.3rem; }
.chord-drawer__save { width: 100%; }

/* Chord diagram (display + editor) */
.chord-diagram {
  --gutter: 20px; --col: 26px; --row: 22px;
  display: inline-block; text-align: center; font-family: var(--font-mono);
}
.chord-diagram--small { --gutter: 12px; --col: 15px; --row: 13px; }
.chord-diagram__label { font-weight: 700; margin-bottom: 0.2rem; color: var(--accent); }
.chord-diagram__topmarks, .chord-editor__topmarks {
  display: grid;
  grid-template-columns: var(--gutter) repeat(6, var(--col));
  width: calc(var(--gutter) + 6 * var(--col)); margin: 0 auto;
}
.chord-diagram__topmark, .chord-editor__topmark { text-align: center; font-size: 0.8rem; color: var(--text-dim); }
.chord-diagram__topmarks .chord-diagram__topmark:first-child { grid-column: 2; }
.chord-editor__topmark { background: none; border: none; cursor: pointer; padding: 0.2em; }
.chord-editor__topmark:hover { color: var(--accent); }
.chord-diagram__body {
  display: grid;
  grid-template-columns: var(--gutter) auto;
  width: calc(var(--gutter) + 6 * var(--col)); margin: 0 auto;
}
.chord-diagram__fretnums { display: flex; flex-direction: column; }
.chord-diagram__fretnum {
  height: var(--row); line-height: var(--row); font-size: 0.7rem; color: var(--text-dim);
  text-align: right; padding-right: 4px;
}
.chord-diagram--small .chord-diagram__fretnum { font-size: 0.55rem; padding-right: 2px; }
.chord-diagram__grid, .chord-editor__grid {
  display: grid;
  grid-template-columns: repeat(var(--strings), var(--col));
  grid-template-rows: repeat(var(--frets), var(--row));
  border-left: 2px solid var(--text-dim);
  border-top: 2px solid var(--text-dim);
}
.chord-diagram__cell, .chord-editor__cell {
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  position: relative; background: none; padding: 0; cursor: default;
}
.chord-editor__cell { cursor: pointer; }
.chord-editor__cell:hover { background: var(--border); }
.chord-diagram__dot {
  position: absolute; width: 65%; height: 65%; top: 50%; left: 50%;
  transform: translate(-50%, -50%); background: var(--accent); border-radius: 50%;
}
.chord-editor__basefret-row { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.chord-editor__basefret-row label { display: flex; align-items: center; gap: 0.4em; color: var(--text-dim); }
.chord-editor__basefret-input { width: 60px; }

.chords-grid { display: flex; flex-wrap: wrap; gap: 1rem; }
.chord-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.9rem; text-align: center; position: relative; box-shadow: var(--shadow-sm);
}
.chord-card__delete, .chord-card__edit {
  position: absolute; top: 4px; background: none; border: none;
  color: var(--text-dim); cursor: pointer; font-size: 1rem;
}
.chord-card__delete { right: 6px; }
.chord-card__edit { right: 26px; }
.chord-card__delete:hover { color: var(--danger); }
.chord-card__edit:hover { color: var(--accent); }
.chord-card__listen { display: block; margin: 0.6rem auto 0; }

/* Prompter: vista de pantalla completa, independiente del header/bottom-nav. */
.view--prompter {
  position: fixed; inset: 0; z-index: 25;
  max-width: none; padding: 0; margin: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.prompter-bar {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; flex: 0 0 auto;
  padding: 0.4rem 0.6rem; background: var(--bg-elevated); border-bottom: 1px solid var(--border);
}
.prompter-bar__group { display: flex; align-items: center; gap: 0.35rem; }
.prompter-bar .btn, .prompter-bar .chip {
  padding: 0.35em 0.6em; font-size: 0.8rem;
}
.prompter-bar__bpm-input { width: 56px; padding: 0.35em 0.4em; }

.prompter-host-wrap { position: relative; flex: 1; min-height: 0; }
.prompter-host {
  height: 100%;
  overflow-y: auto;
}
/* Guía central fija: marca dónde "se ilumina" el texto, independiente del scroll. */
.prompter-centerline {
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
  height: 3.6em; pointer-events: none; z-index: 1;
  background: linear-gradient(
    to bottom,
    transparent,
    color-mix(in srgb, var(--accent-2) 10%, transparent) 35%,
    color-mix(in srgb, var(--accent-2) 10%, transparent) 65%,
    transparent
  );
  border-top: 1px solid color-mix(in srgb, var(--accent-2) 35%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--accent-2) 35%, transparent);
}
.prompter__scroll { padding: 0 1rem; position: relative; z-index: 2; }
.prompter__spacer { height: 42vh; }
.prompter__section-label {
  color: var(--accent); font-weight: 700; letter-spacing: 0.08em; text-align: center;
  margin: 1.2rem 0 0.4rem; font-size: 0.9rem;
}
.prompter__line {
  text-align: center; margin: 1.1rem 0; font-family: var(--font-mono);
  opacity: 0.32; transition: opacity 0.2s, transform 0.2s; transform: scale(0.92);
}
.prompter__line.is-active { opacity: 1; transform: scale(1.1); }
.prompter__line.is-active .prompter__lyrics-row {
  color: var(--accent-2);
  text-shadow: 0 0 22px color-mix(in srgb, var(--accent-2) 55%, transparent);
}
.prompter__chords-row {
  color: var(--accent); white-space: pre-wrap; word-break: break-word; font-weight: 700;
  font-size: clamp(0.9rem, 2.2vw, 1.3rem); min-height: 1.4em;
}
.prompter__lyrics-row {
  font-size: clamp(1.1rem, 3vw, 2rem); white-space: pre-wrap; word-break: break-word; transition: color 0.2s, text-shadow 0.2s;
}
.prompter-host.hide-chords .prompter__chords-row { display: none; }

/* Menú inferior (móvil) */
.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 0.3rem 0.4rem calc(0.3rem + env(safe-area-inset-bottom));
  justify-content: space-around;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}
.bottom-nav__item {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 0.4rem 0.8rem; border-radius: var(--radius-sm); flex: 1; max-width: 110px;
  font-size: 0.7rem; font-weight: 600;
}
.bottom-nav__item svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.bottom-nav__item.is-active { color: var(--accent); }

@media (max-width: 768px) {
  .bottom-nav { display: flex; }
  .app-header__nav { display: none; }
  body { padding-bottom: 0; }
  .app-main { padding-bottom: 5.2rem; }
  .prompter-host { height: calc(100vh - 64px - 64px); }
  body[data-hide-bottom-nav] .bottom-nav { display: none; }
  body[data-hide-bottom-nav] .app-main { padding-bottom: 1rem; }
}

@media (max-width: 480px) {
  .app-header { gap: 0.5rem; }
  .app-header__brand { font-size: 1rem; }
  .prompter-bar { gap: 0.4rem; }
}
