/* Cifras — tema escuro de palco, alto contraste, alvos de toque grandes */
:root {
  --bg: #0e1116;
  --bg-raised: #171c24;
  --bg-sheet: #1c232e;
  --border: #2a3342;
  --text: #e9edf2;
  --text-dim: #9aa7b8;
  --accent: #ffb454;        /* acordes */
  --accent-strong: #ffc266;
  --blue: #6cb6ff;
  --green: #57d38c;
  --red: #ff6b6b;
  --tap: 52px;              /* alvo mínimo de toque */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, "SF Pro Text", system-ui, Segoe UI, Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}
#root { height: 100%; display: flex; flex-direction: column; }
.boot { padding: 40vh 0 0; text-align: center; color: var(--text-dim); }

button {
  font: inherit; color: inherit; background: none; border: none; cursor: pointer;
}
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg-raised);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  -webkit-user-select: text; user-select: text; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--blue); border-color: transparent; }
textarea { font-family: var(--mono); font-size: 14px; line-height: 1.45; white-space: pre; }
/* corrigir a cifra no meio do ensaio: campo alto, para ver o verso inteiro */
.editorcifra { min-height: clamp(150px, 38vh, 420px); font-size: 15px; }
/* botões colados no pé da folha: com o teclado aberto, Salvar não some */
.sheet .acoes {
  position: sticky; bottom: 0; z-index: 1; background: var(--bg-sheet);
  padding: 10px 0 2px; margin-top: 6px; box-shadow: 0 -10px 12px -8px rgba(0, 0, 0, 0.6);
}

/* ---------- estrutura de tela ---------- */
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { color: var(--text-dim); font-size: 13px; font-weight: 400; }
.content { flex: 1; overflow-y: auto; padding: 14px 14px calc(20px + var(--safe-bottom)); }

.tabbar {
  display: flex; border-top: 1px solid var(--border); background: var(--bg-raised);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1; min-height: var(--tap); padding: 8px 0 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-dim); font-size: 12px;
}
.tabbar button.active { color: var(--accent); }
.tabbar .ico { font-size: 22px; line-height: 1; }

/* ---------- botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px;
  background: var(--bg-raised); border: 1px solid var(--border); font-weight: 600;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: #17120a; border-color: transparent; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.small { min-height: 40px; padding: 0 12px; border-radius: 10px; font-size: 15px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; }
.iconbtn {
  min-width: var(--tap); min-height: var(--tap); display: inline-flex;
  align-items: center; justify-content: center; font-size: 22px; border-radius: 12px;
  color: var(--text);
}
.iconbtn:active { background: var(--bg-raised); }

/* ---------- listas ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; min-height: 64px; width: 100%; text-align: left;
}
.card:active { background: var(--bg-sheet); }
.card .grow { flex: 1; min-width: 0; }
.card .title { font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { color: var(--text-dim); font-size: 14px; margin-top: 2px; }
.badge {
  font-family: var(--mono); font-size: 14px; font-weight: 700; color: var(--accent);
  background: rgba(255, 180, 84, 0.12); border-radius: 8px; padding: 4px 8px; flex: none;
}
.empty { text-align: center; color: var(--text-dim); padding: 48px 24px; line-height: 1.5; }
.empty .big { font-size: 44px; margin-bottom: 12px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; }

/* ---------- cifra ---------- */
.cifra {
  font-family: var(--mono);
  line-height: 1.42;
  -webkit-user-select: text; user-select: text;
}
.cifra .sec {
  font-family: var(--sans); font-weight: 700; color: var(--blue);
  margin: 1.1em 0 0.25em; font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.04em;
}
.cifra pre { font: inherit; white-space: pre-wrap; word-break: break-word; }
.cifra .ln-chords { white-space: pre; overflow-x: auto; }
.cifra .ln-tab { white-space: pre; overflow-x: auto; color: var(--text-dim); }
.cifra .chord {
  color: var(--accent); font-weight: 700; cursor: pointer; border-radius: 4px;
}
.cifra .chord:active { background: rgba(255, 180, 84, 0.25); }
.cifra .obs {
  font-family: var(--sans); background: rgba(108, 182, 255, 0.1); border-left: 3px solid var(--blue);
  padding: 8px 10px; border-radius: 0 8px 8px 0; margin: 10px 0; color: var(--text); white-space: pre-wrap;
}

/* ---------- leitura / palco ---------- */
.reader { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.reader .content { padding-bottom: 42vh; }
.readerbar {
  display: flex; align-items: center; gap: 4px; min-width: 0;
  padding: calc(6px + var(--safe-top)) 8px 6px;
  border-bottom: 1px solid var(--border); background: var(--bg); z-index: 6;
}
/* nenhum botão da barra pode virar largura mínima do app: no iPhone a soma
   deles empurrava a tela inteira para o lado e comia a borda direita */
.readerbar > * { min-width: 0; flex-shrink: 1; }
.readerbar .iconbtn { padding: 0 2px; }
.readerbar .t { flex: 1; min-width: 0; text-align: center; }
.readerbar .t .title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* música tocando agora: é o texto que o olho tem de achar em 1 segundo no palco */
/* a música tocando agora é o texto mais importante da tela: cresce com a tela
   e é o único em laranja no alto */
.readerbar .t .title.nowplaying {
  font-size: clamp(22px, 3vw, 34px); font-weight: 800; color: var(--accent);
  letter-spacing: 0.2px; line-height: 1.15;
}
.readerbar .t .meta { color: var(--text-dim); font-size: 12px; }
.playerfoot {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px calc(6px + var(--safe-bottom));
  border-top: 1px solid var(--border); background: var(--bg); z-index: 6;
}
.navzone {
  position: absolute; top: 15%; bottom: 15%; width: 64px; z-index: 4;
  display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 34px;
}
.navzone:active { color: var(--text-dim); }
.navzone.left { left: 0; } .navzone.right { right: 0; }
.scrollctl {
  position: absolute; right: 12px; bottom: calc(72px + var(--safe-bottom)); z-index: 5;
  display: flex; align-items: center; gap: 8px;
}
.scrollflag {
  background: rgba(23, 28, 36, 0.9); border: 1px solid var(--border);
  border-radius: 999px; padding: 10px 14px; color: var(--text-dim); font-size: 13px; min-height: 44px;
}
.scrollflag.on { color: var(--green); border-color: var(--green); }
.scrollbtn {
  background: rgba(23, 28, 36, 0.9); border: 1px solid var(--border);
  border-radius: 999px; min-width: 46px; min-height: 44px; font-size: 20px; color: var(--text);
}
.scrollbtn:active { border-color: var(--accent); color: var(--accent); }

/* ---------- clipe ao lado da cifra (ensaio) ---------- */
.readerbar .iconbtn.on { color: var(--accent); }
/* min-width: 0 é o que impede o painel de empurrar a tela inteira para o lado
   (sem ele, os dois botões abaixo viravam a largura mínima do app no iPhone) */
.videopane { display: flex; flex-direction: column; gap: 8px; padding: 8px; min-height: 0; min-width: 0; background: var(--bg-raised); }
/* aspect-ratio em vez do truque do padding-top: com padding-top a altura era
   calculada sobre a largura do PAINEL, então limitar a largura do vídeo não
   diminuía a altura e os botões vazavam por cima da cifra */
.videoframe { position: relative; width: 100%; aspect-ratio: 16 / 9; flex: none; border-radius: 12px; overflow: hidden; background: #000; }
.videoframe iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.videoacts { display: flex; gap: 8px; min-width: 0; }
.videoacts .btn {
  flex: 1 1 0; min-width: 0; padding: 0 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; line-height: var(--tap);
}

/* deitado: vídeo à esquerda, cifra à direita; em pé: vídeo em cima */
.reader.withvideo {
  display: grid;
  grid-template-areas: "bar bar" "video cifra" "foot foot";
  grid-template-columns: clamp(240px, 32%, 420px) 1fr;
  grid-template-rows: auto 1fr auto;
}
.reader.withvideo .readerbar { grid-area: bar; }
.reader.withvideo .videopane { grid-area: video; overflow-y: auto; border-right: 1px solid var(--border); }
.reader.withvideo .content { grid-area: cifra; min-width: 0; }
.reader.withvideo .playerfoot { grid-area: foot; }
/*
 * Com o vídeo aberto a cifra não ocupa mais a tela inteira, então a margem
 * que centraliza o texto em telas grandes não pode continuar valendo: ela
 * era calculada em cima da largura da JANELA e comia a coluna da cifra,
 * cortando o fim das linhas. Aqui ela volta ao mínimo.
 */
.reader.withvideo .content { padding-left: 14px; padding-right: 14px; }
/* se ainda assim sobrar linha comprida, a cifra INTEIRA desliza junto,
   preservando os acordes em cima das sílabas certas */
.reader.withvideo .content { overflow-x: auto; }
.reader.withvideo .cifra .ln-chords,
.reader.withvideo .cifra .ln-tab { overflow-x: visible; }
.reader.withvideo .cifra { width: max-content; min-width: 100%; }
.reader.withvideo .cifra pre { white-space: pre; word-break: normal; }
@media (orientation: portrait) {
  .reader.withvideo {
    grid-template-areas: "bar" "video" "cifra" "foot";
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
  }
  .reader.withvideo .videopane { border-right: none; border-bottom: 1px solid var(--border); overflow: hidden; }
  /* em pé, vídeo largo demais rouba altura da cifra: limita e centraliza */
  .reader.withvideo .videoframe { max-width: 520px; margin: 0 auto; }
  .reader.withvideo .videoacts { max-width: 520px; margin: 0 auto; width: 100%; }
}

/* botão de próxima música no rodapé do palco: só o destino, sem o nome dela */
.playerfoot .nextbtn { flex: 1; min-width: 0; min-height: 48px; justify-content: center; gap: 10px; padding: 0 12px; }
.playerfoot .nextbtn .nextlabel {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-transform: uppercase; letter-spacing: 1px; font-size: 13px; font-weight: 600; color: var(--text-dim);
}
.playerfoot .nextbtn .nextarrow { flex: none; color: var(--text-dim); font-size: 20px; line-height: 1; }
.playerfoot .nextbtn:disabled { opacity: 0.4; }

/* ---------- folha inferior (acordes etc.) ---------- */
.sheetwrap { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; justify-content: flex-end; }
.sheetwrap .backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.sheet {
  position: relative; background: var(--bg-sheet); border-radius: 18px 18px 0 0;
  border: 1px solid var(--border); border-bottom: none;
  padding: 10px 16px calc(18px + var(--safe-bottom)); max-height: 82vh; overflow-y: auto;
}
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--border); margin: 2px auto 12px; }
.sheet h2 { font-size: 19px; margin-bottom: 10px; }

.diagrams { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; justify-content: center; }
.diagram { text-align: center; }
.diagram .lbl { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
.notesline { text-align: center; color: var(--text-dim); margin-top: 10px; font-size: 15px; }
.notesline b { color: var(--accent); font-family: var(--mono); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--mono); font-weight: 700; color: var(--accent);
  background: rgba(255, 180, 84, 0.12); border: 1px solid transparent;
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
.chip:active, .chip.sel { border-color: var(--accent); }

/* ---------- setlist ---------- */
.setitem { touch-action: pan-y; -webkit-touch-callout: none; transition: transform 0.12s ease, box-shadow 0.12s ease; }
.setitem .handle { color: var(--text-dim); font-size: 20px; padding: 8px; cursor: grab; touch-action: none; }
/* música "no colo": levantada da lista enquanto o dedo a carrega */
.setitem.dragging {
  border-color: var(--accent); transform: scale(1.02);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45); cursor: grabbing; position: relative; z-index: 2;
}
/* enquanto carrega, nada de seleção de texto nem lupa do iPad */
.list.arrastando, .list.arrastando * { user-select: none; -webkit-user-select: none; }
.setitem .pos { color: var(--text-dim); font-family: var(--mono); width: 26px; text-align: right; flex: none; }
.setitem .ordbtn { min-width: 40px; font-size: 19px; color: var(--text-dim); }
.setitem .ordbtn:active { color: var(--accent); }

.banner {
  border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 15px; line-height: 1.45;
  background: rgba(255, 107, 107, 0.12); border: 1px solid var(--red); color: var(--text);
}
.banner.ok { background: rgba(87, 211, 140, 0.1); border-color: var(--green); }
.hint { color: var(--text-dim); font-size: 14px; line-height: 1.5; }

/* código de pareamento entre aparelhos */
.paircode {
  font-family: var(--mono); font-size: 42px; font-weight: 700; letter-spacing: 6px;
  text-align: center; color: var(--accent); background: var(--bg); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px 10px; margin: 6px 0 12px; user-select: all; -webkit-user-select: all;
}

/* ---------- diálogo de confirmação ---------- */
.confirmbox { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; }
.confirmbox .backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.confirmbox .box {
  position: relative; background: var(--bg-sheet); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px; max-width: 420px; width: 100%;
}
.confirmbox p { line-height: 1.5; margin-bottom: 18px; }
.confirmbox .row { justify-content: flex-end; }

@media (min-width: 768px) {
  .content { padding-left: max(14px, calc(50vw - 420px)); padding-right: max(14px, calc(50vw - 420px)); }
  .reader .content { padding-left: max(14px, calc(50vw - 460px)); padding-right: max(14px, calc(50vw - 460px)); }
  /* vem depois de propósito: com o vídeo aberto a conta acima não vale mais */
  .reader.withvideo .content { padding-left: 14px; padding-right: 14px; }
}
