* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
}
body.is-dragging { overflow: hidden; touch-action: none; }
button, input, select, textarea { font-family: inherit; }
svg { display: block; }
h1, h2, h3 { margin: 0; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Estructura ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: var(--header-h);
  padding: 8px calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
  padding-top: calc(8px + var(--safe-t));
  background: color-mix(in srgb, var(--bg-alt) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.app-header h1 { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.header-sub { font-size: 12px; color: var(--text-dim); margin-top: 1px; }
.header-title-wrap { min-width: 0; flex: 1; }
.header-title-wrap h1, .header-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.screen { display: none; padding: 14px calc(14px + var(--safe-r)) 24px calc(14px + var(--safe-l)); }
.screen.active { display: block; }
.screen-reader, .screen-live { padding-left: 0; padding-right: 0; }

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 240px; }
  .app-header { padding-left: 28px; }
  .screen { max-width: 1100px; }
}

/* ---------- Navegación ---------- */
.tabbar {
  position: fixed; z-index: 30; inset: auto 0 0 0;
  display: flex; align-items: stretch;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg-alt) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; color: var(--text-faint); font-size: 11px; font-weight: 600; cursor: pointer;
}
.tab svg { width: 23px; height: 23px; }
.tab.active { color: var(--accent); }

@media (min-width: 900px) {
  .tabbar {
    inset: 0 auto 0 0; width: 240px; height: auto; flex-direction: column;
    justify-content: flex-start; gap: 4px; padding: calc(20px + var(--safe-t)) 12px 20px;
    border-top: none; border-right: 1px solid var(--border);
  }
  .tabbar::before {
    content: 'MySetlist'; display: block; font-size: 17px; font-weight: 800;
    letter-spacing: -.02em; color: var(--text); padding: 0 12px 18px;
  }
  .tab {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 13px 12px; border-radius: var(--r-md); font-size: 15px;
  }
  .tab.active { background: var(--accent-soft); }
}

/* ---------- Controles ---------- */
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--panel-2); color: var(--text); cursor: pointer;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:active { transform: scale(.95); }
.icon-btn.ghost { background: transparent; border-color: transparent; }
.icon-btn.sm { width: 38px; height: 38px; border-radius: var(--r-sm); }
.icon-btn.sm svg { width: 17px; height: 17px; }
.icon-btn.danger { color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--panel-2); color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #001427; }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.input, .textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--text); padding: 14px; font-size: 16px; outline: none;
  -webkit-user-select: text; user-select: text;
}
.input:focus, .textarea:focus { border-color: var(--accent); }
.textarea { font-family: var(--mono); font-size: 14px; line-height: 1.5; min-height: 260px; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.search-box { position: relative; display: flex; align-items: center; margin-bottom: 14px; }
.search-box svg { position: absolute; left: 14px; width: 18px; height: 18px; color: var(--text-faint); pointer-events: none; }
.search-box .input { padding-left: 44px; border-radius: var(--r-lg); }

/* ---------- Tarjetas / listas ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 16px; margin-bottom: 12px;
}
.list { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-md); margin-bottom: 8px; overflow: hidden;
}
.list-row.dragging {
  opacity: .92; box-shadow: var(--shadow); border-color: var(--accent);
  position: relative; z-index: 5;
}
.row-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  background: none; border: none; color: var(--text); text-align: left;
  padding: 13px 14px; cursor: pointer;
}
.row-main:active { background: var(--panel-2); }
.row-title { font-size: 16px; font-weight: 650; }
.row-sub { font-size: 13px; color: var(--text-dim); }
.row-meta { font-size: 11px; color: var(--text-faint); display: flex; gap: 8px; margin-top: 1px; }
.row-actions { display: flex; align-items: center; gap: 2px; padding-right: 6px; }
.drag-handle {
  display: flex; align-items: center; justify-content: center;
  width: 46px; align-self: stretch; flex-shrink: 0;
  color: var(--text-faint); background: none; border: none; cursor: grab;
  touch-action: none;
}
.drag-handle svg { width: 19px; height: 19px; }

.section-title {
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-faint); margin: 22px 0 10px;
}
.section-title:first-child { margin-top: 4px; }
.empty {
  text-align: center; color: var(--text-faint); font-size: 14px;
  padding: 40px 20px; line-height: 1.6;
}
.empty strong { display: block; color: var(--text-dim); font-size: 16px; margin-bottom: 6px; }
.badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-dim);
  font-size: 12px; font-weight: 650;
}
.badge.plain { background: var(--panel-2); color: var(--text-dim); }
.banner {
  border-radius: var(--r-md); padding: 12px 14px; margin-bottom: 14px;
  font-size: 14px; line-height: 1.5;
  background: var(--accent-soft); color: var(--accent-dim);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.banner.warn { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }

/* ---------- Lector de canción ---------- */
.reader-bar {
  position: sticky; top: calc(var(--header-h) + var(--safe-t)); z-index: 15;
  display: flex; align-items: center; gap: 8px;
  padding: 8px calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
  background: color-mix(in srgb, var(--bg-alt) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.reader-bar::-webkit-scrollbar { display: none; }
.stepper {
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 4px;
}
.stepper-label { min-width: 42px; text-align: center; font-size: 13px; font-weight: 650; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.scroll-btn {
  display: flex; align-items: center; gap: 7px; flex-shrink: 0;
  height: 46px; padding: 0 16px; border: none; border-radius: var(--r-md);
  background: var(--accent); color: #001427; font-size: 14px; font-weight: 700; cursor: pointer;
}
.scroll-btn svg { width: 18px; height: 18px; }
.scroll-btn.active { background: var(--danger); color: #fff; }
.scroll-btn:active { transform: scale(.97); }

.song-head { padding: 16px calc(16px + var(--safe-r)) 4px calc(16px + var(--safe-l)); }
.song-head h2 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.song-head p { margin: 2px 0 0; color: var(--text-dim); font-size: 15px; }
.song-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.chords-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: 14px calc(16px + var(--safe-r)) 40vh calc(16px + var(--safe-l));
}
.song-content {
  font-family: var(--mono); white-space: pre; line-height: 1.55;
  margin: 0; display: inline-block; min-width: 100%;
  -webkit-user-select: text; user-select: text;
}
.song-content .chord { color: var(--accent); font-weight: 700; }
.song-content .section-label {
  color: var(--accent-dim); font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; font-size: .82em;
}
.song-content .annotation { color: var(--text-faint); font-style: italic; white-space: pre-wrap; }

/* ---------- Modo en vivo ---------- */
.live-nav {
  position: fixed; z-index: 25; left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b));
  display: flex; align-items: center; gap: 10px;
  padding: 10px calc(14px + var(--safe-r)) 10px calc(14px + var(--safe-l));
  background: color-mix(in srgb, var(--bg-alt) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.live-progress { flex: 1; text-align: center; font-size: 13px; font-weight: 650; color: var(--text-dim); }
.live-progress span { display: block; font-size: 11px; color: var(--text-faint); font-weight: 500; }
@media (min-width: 900px) { .live-nav { left: 240px; bottom: 0; } }
.screen-live .chords-scroll { padding-bottom: 45vh; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: flex-end; justify-content: center; background: var(--overlay);
}
.modal.open { display: flex; }
.modal-card {
  width: min(560px, 100%); max-height: 92vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 20px calc(18px + var(--safe-r)) calc(20px + var(--safe-b)) calc(18px + var(--safe-l));
}
@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-card { border-radius: var(--r-lg); max-height: 86vh; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.modal-head h2 { font-size: 19px; font-weight: 700; }

.toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow);
  border-radius: var(--r-md); padding: 12px 18px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.toast.show { opacity: 1; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin .7s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
