:root {
  --bg: #121212; --panel: #1c1c1e; --text: #ffffff; --chord: #4cd964; --section: #ffffff; --accent: #ff9f0a;
  --muted: color-mix(in srgb, var(--text) 55%, transparent);
  --border: color-mix(in srgb, var(--text) 14%, transparent);
  --panel2: color-mix(in srgb, var(--text) 8%, var(--panel));
  --hover: color-mix(in srgb, var(--text) 6%, transparent);
  --danger: #ff453a;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--ui); overflow: hidden; }
body { -webkit-user-select: none; user-select: none; -webkit-text-size-adjust: 100%; }
input, textarea, select { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; }
#app { height: 100%; display: flex; flex-direction: column; padding: var(--safe-t) var(--safe-r) 0 var(--safe-l); }

/* ---------- barra superior ---------- */
#topbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--border); flex: none; }
#tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 12px; padding: 3px; }
#tabs button { display: flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 9px 16px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--muted); min-height: 42px; }
#tabs button .ico { font-size: 17px; }
#tabs button.on { background: var(--panel2); color: var(--accent); }
#brand { flex: 1; text-align: center; font-weight: 800; letter-spacing: .5px; font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#savestate { font-size: 12px; color: var(--muted); min-width: 86px; text-align: right; white-space: nowrap; }
#savestate.err { color: var(--danger); font-weight: 700; }
.iconbtn { border: 1px solid var(--border); background: var(--panel2); width: 44px; height: 42px; border-radius: 10px; font-size: 20px; display: grid; place-items: center; flex: none; }

main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: none; }
.view.on { display: flex; }

/* ---------- botones y formularios ---------- */
.btn { border: 1px solid var(--border); background: var(--panel2); border-radius: 10px; padding: 10px 16px; font-size: 15px; font-weight: 600; min-height: 44px; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #000; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.btn:disabled { opacity: .4; }
input[type=text], input[type=search], input:not([type]), textarea, select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%; }
select { min-height: 44px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; line-height: 1.6; font-size: 16px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }

/* ---------- listas de canciones ---------- */
.list { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); min-height: 58px; cursor: pointer; }
.row:active { background: var(--hover); }
.row .info { flex: 1; min-width: 0; }
.row .t { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .a { font-size: 13px; color: var(--muted); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row .meta { font-size: 13px; color: var(--muted); white-space: nowrap; text-align: right; }
.row .dur { font-weight: 700; font-size: 16px; color: var(--text); }
.row .num { width: 26px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 1px solid var(--border); }
.rbtn { border: 1px solid var(--border); background: var(--panel2); border-radius: 9px; width: 42px; height: 40px; font-size: 18px; flex: none; display: grid; place-items: center; }
.rbtn.danger { color: var(--danger); }
.rbtn:disabled { opacity: .3; }

/* ---------- Biblioteca ---------- */
#view-lib, #view-sets { flex-direction: column; }
.toolbar { display: flex; gap: 8px; padding: 10px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--border); background: var(--panel); }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.lib-count { padding: 8px 14px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); }

/* ---------- Repertorios ---------- */
.sets { display: flex; flex: 1; min-height: 0; }
.sets-side { width: 300px; flex: none; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--panel); }
.sets-side .row.on { background: var(--panel2); box-shadow: inset 4px 0 0 var(--accent); }
.sets-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.sets-head { display: flex; gap: 8px; padding: 10px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.sets-head input { flex: 1; min-width: 160px; font-size: 18px; font-weight: 700; }

/* ---------- Performance ---------- */
#view-perf { flex-direction: column; }
.ph { display: flex; align-items: stretch; gap: 6px; padding: 6px; background: var(--bg); flex: none; }
.ph .box { background: var(--panel); border-radius: 10px; padding: 4px 12px; display: flex; flex-direction: column; justify-content: center; min-width: 92px; }
.ph .box .l { font-size: 11px; color: var(--accent); }
.ph .box .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ph .title { flex: 1; min-width: 0; text-align: center; align-items: center; }
.ph .title .v { font-size: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ph .title .l { color: var(--muted); font-style: italic; font-size: 13px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ph .nav { width: 56px; min-width: 56px; padding: 0; font-size: 22px; border: 0; color: var(--text); align-items: center; }
.progress { height: 10px; margin: 0 6px 4px; background: var(--panel); border-radius: 5px; overflow: hidden; flex: none; cursor: pointer; }
.progress .bar { height: 100%; width: 0; background: var(--accent); }
.progress.hidden { visibility: hidden; height: 4px; }
.pb { flex: 1; display: flex; min-height: 0; position: relative; }
.pside { width: 330px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--border); }
.pb.noside .pside { display: none; }
.pside .sel { padding: 8px; border-bottom: 1px solid var(--border); }
.pside .sum { padding: 6px 12px; font-size: 13px; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--border); }
.prow { position: relative; padding-left: 26px; }
.prow .tag { position: absolute; left: 0; top: 0; bottom: 0; width: 20px; writing-mode: vertical-rl; transform: rotate(180deg); font-size: 9px; font-weight: 800; letter-spacing: 1px; display: flex; align-items: center; justify-content: center; color: #000; }
.prow.cur { background: color-mix(in srgb, var(--accent) 22%, var(--panel)); }
.prow.cur .tag { background: var(--accent); }
.prow.done { opacity: .5; }
.prow.done .tag { background: #8e8e93; }
.prow.next .tag { background: #ffd60a; }
.sidetoggle { position: absolute; left: 330px; top: 50%; transform: translateY(-50%); z-index: 3; width: 30px; height: 60px; border: 1px solid var(--border); border-left: 0; border-radius: 0 10px 10px 0; background: var(--panel2); font-size: 18px; }
.pb.noside .sidetoggle { left: 0; }
.lw { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: 24px 36px 40vh; position: relative; }
.lw.fitted { padding-bottom: 24px; }
.lyrics { font-family: var(--mono); line-height: 1.3; color: var(--text); margin: 0 auto; }
.lyrics.c { text-align: center; }
.lyrics.left { text-align: left; }
.lyrics .line { white-space: pre-wrap; min-height: 1.3em; }
.lyrics.fit .line { white-space: pre; }
.lyrics.fit { width: fit-content; }
.lyrics .sec { font-style: italic; font-weight: 800; color: var(--section); font-size: 1.1em; margin-top: .3em; }
.lyrics .chords { color: var(--chord); font-weight: 700; }
.lyrics .seg { display: inline-flex; flex-direction: column; vertical-align: bottom; text-align: left; }
.lyrics .seg .ch { color: var(--chord); font-weight: 700; font-size: .9em; padding-right: .4em; line-height: 1.15; }
.lyrics .seg .ly { white-space: pre; }
.lyrics b { font-weight: 800; }
.nolyrics { color: var(--muted); font-family: var(--ui); font-size: 20px; text-align: center; margin-top: 15vh; line-height: 1.6; }
.pf { display: flex; align-items: center; gap: 8px; padding: 8px 10px calc(8px + var(--safe-b)); background: var(--panel); border-top: 1px solid var(--border); flex: none; flex-wrap: wrap; }
.grp { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.grp .cap { font-size: 11px; color: var(--muted); }
.grp .val { font-size: 12px; font-weight: 700; min-height: 15px; }
.pm { display: flex; }
.pm button { width: 52px; height: 44px; border: 1px solid var(--border); background: var(--panel2); font-size: 22px; }
.pm button:first-child { border-radius: 10px 0 0 10px; }
.pm button:last-child { border-radius: 0 10px 10px 0; border-left: 0; }
.fitbtn { height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel2); font-weight: 700; font-size: 15px; }
.fitbtn.on { background: var(--accent); border-color: var(--accent); color: #000; }
.playbtn { width: 110px; height: 56px; border-radius: 12px; border: 0; background: #34c759; color: #fff; font-size: 26px; }
.playbtn.on { background: #ff9f0a; }
.vol { flex: 1; min-width: 160px; }
.vol input { width: 100%; accent-color: var(--accent); height: 30px; }

/* ---------- modales ---------- */
#modal-root .back { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: calc(12px + var(--safe-t)) 12px calc(12px + var(--safe-b)); }
.modal { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 16px; width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal.wide { width: min(980px, 100%); height: 100%; }
.mh { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.mh h2 { flex: 1; margin: 0; font-size: 19px; }
.mb { padding: 14px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.mb label { font-size: 13px; font-weight: 700; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.fields { display: flex; gap: 10px; flex-wrap: wrap; }
.fields > label { flex: 1; min-width: 160px; }
.fields > label.k { flex: 0 0 110px; min-width: 0; }
.mb textarea.lyr { flex: 1; min-height: 260px; font-family: var(--mono); font-size: 16px; line-height: 1.4; resize: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions .sp { flex: 1; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sw { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--border); padding: 0; position: relative; }
.sw.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.sw.def { background: conic-gradient(var(--text) 0 50%, var(--bg) 0); }
.sw input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.sw.custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.sw.mini { width: 30px; height: 30px; }
.set-sec { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.set-sec h3 { margin: 0; font-size: 16px; }
.seg-ctl { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; width: fit-content; }
.seg-ctl button { border: 0; background: transparent; padding: 10px 18px; font-weight: 600; min-height: 42px; }
.seg-ctl button.on { background: var(--accent); color: #000; }
.crow { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.crow .n { flex: 1; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crow input[type=color] { width: 54px; height: 38px; border: 1px solid var(--border); border-radius: 8px; background: transparent; padding: 2px; }
.crow input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--accent); }
.crow input[type=range] { flex: 1; accent-color: var(--accent); }
.pick { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--border); min-height: 52px; }
.pick input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.pick .t { font-weight: 700; } .pick .a { color: var(--muted); font-size: 13px; font-style: italic; }
.preview { border: 1px solid var(--border); border-radius: 10px; padding: 10px; max-height: 160px; overflow: auto; font-family: var(--mono); font-size: 13px; white-space: pre-wrap; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 100; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; transform: translateX(-50%); }
#dropzone { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: color-mix(in srgb, var(--accent) 25%, rgba(0,0,0,.7)); z-index: 200; font-size: 28px; font-weight: 800; color: #fff; pointer-events: none; }
#dropzone.on { display: flex; }

@media (max-width: 820px) {
  #tabs button span:not(.ico) { display: none; }
  #brand { display: none; }
  .sets-side { width: 220px; }
  .pside { width: 260px; } .sidetoggle { left: 260px; }
  .lw { padding: 16px 16px 40vh; }
}
@media (max-width: 560px) {
  .sets { flex-direction: column; } .sets-side { width: auto; max-height: 34%; border-right: 0; border-bottom: 1px solid var(--border); }
  .pside { position: absolute; inset: 0 auto 0 0; z-index: 4; width: 85%; } .sidetoggle { left: 85%; }
  .ph .box:not(.title):not(.nav) { display: none; }
}

.pair { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.pair .pt { flex: 1; min-width: 0; }
.pair .pt .t { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pair .pt .a { font-size: 13px; color: var(--muted); font-style: italic; }
.pair .arrow { color: var(--accent); font-size: 20px; font-weight: 800; }
.pair select { flex: 1.2; min-width: 0; }
.pair.none .pt .t { opacity: .55; }
.pair.none select { color: var(--muted); }

.libfilter { display: flex; gap: 6px; padding: 8px 10px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.libfilter button { border: 1px solid var(--border); background: var(--panel2); border-radius: 20px; padding: 7px 14px; font-weight: 600; font-size: 14px; min-height: 38px; }
.libfilter button::after { content: ' ' attr(data-n); color: var(--muted); font-weight: 400; }
.libfilter button.on { background: var(--accent); border-color: var(--accent); color: #000; }
.libfilter button.on::after { color: #000; }
.libfilter .lib-count { border: 0; padding: 0 0 0 6px; margin-left: auto; }
.libsec { padding: 14px 12px 8px; font-weight: 800; font-size: 15px; color: var(--accent); background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1; }
