:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1a2230;
  --text-soft: #64748b;
  --border: #e2e8f0;
  --brand: #1f6feb;
  --brand-dark: #1858c4;
  --accent: #0e9f6e;
  --chord: #1f6feb;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232d;
  --text: #e6edf3;
  --text-soft: #8b98a9;
  --border: #2a323c;
  --brand: #4a8bff;
  --brand-dark: #3b78e7;
  --accent: #2bd4a0;
  --chord: #6ea8ff;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 34px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ---------- Cabeçalho ---------- */
.topo {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topo-inner {
  max-width: 900px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
}
.logo {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px;
  box-shadow: var(--shadow);
}
.titulo-app { display: flex; flex-direction: column; line-height: 1.15; }
.titulo-app b { font-size: 17px; letter-spacing: .2px; }
.titulo-app span { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 1.5px; }
.topo .espaco { flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); width: 40px; height: 40px; border-radius: 10px;
  font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .05s;
}
.icon-btn:hover { background: var(--border); }
.icon-btn:active { transform: scale(.94); }

/* ---------- Abas ---------- */
.tabs {
  max-width: 900px; margin: 0 auto; padding: 14px 16px 4px;
  display: flex; gap: 8px;
}
.tab {
  flex: 1; padding: 12px 8px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-soft); font-size: 15px; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.tab:hover { border-color: var(--brand); color: var(--text); }
.tab.ativa {
  background: var(--brand); color: #fff; border-color: var(--brand);
  box-shadow: var(--shadow);
}

/* ---------- Lista de músicas ---------- */
.lista {
  max-width: 900px; margin: 0 auto; padding: 10px 16px 40px;
  display: flex; flex-direction: column; gap: 10px;
}
.musica-card {
  display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; color: var(--text); box-shadow: var(--shadow);
  transition: transform .08s, border-color .15s, box-shadow .15s;
}
.musica-card:hover { border-color: var(--brand); box-shadow: var(--shadow-lg); }
.musica-card:active { transform: scale(.99); }
.musica-card .ordem {
  flex: none; width: 34px; height: 34px; border-radius: 9px;
  background: var(--surface-2); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.musica-card .info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.musica-card .titulo { font-size: 16px; font-weight: 600; }
.musica-card .meta { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }
.musica-card .seta { color: var(--text-soft); font-size: 26px; line-height: 1; }
.selo-editada {
  align-self: flex-start; margin-top: 4px; font-size: 10.5px; font-weight: 700;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding: 1px 7px; border-radius: 20px; text-transform: uppercase; letter-spacing: .4px;
}

/* ---------- Rodapé ---------- */
.rodape {
  max-width: 900px; margin: 0 auto; padding: 0 16px 40px;
  color: var(--text-soft); font-size: 12px; text-align: center;
}

/* ---------- Tela da música ---------- */
.musica-view {
  position: fixed; inset: 0; z-index: 40;
  background: var(--bg);
  display: none; flex-direction: column;
}
body.vendo-musica .musica-view { display: flex; }
body.vendo-musica .home { display: none; }

.mv-topo {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.mv-topo-inner {
  max-width: 900px; margin: 0 auto; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.mv-voltar {
  border: none; background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 9px 14px 9px 10px; cursor: pointer;
  font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 4px;
}
.mv-voltar:hover { background: var(--border); }
.mv-cabecalho { flex: 1; min-width: 0; }
.mv-cabecalho h1 {
  font-size: 18px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mv-cabecalho .subinfo {
  font-size: 12px; color: var(--text-soft); margin-top: 2px;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.mv-cabecalho .pill {
  background: var(--surface-2); padding: 1px 8px; border-radius: 20px;
}

/* botão de "cortina" (mostrar/ocultar controles) */
.mv-toggle {
  flex: none; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.mv-toggle:hover { border-color: var(--brand); color: var(--brand); }
.mv-toggle .chev { font-size: 15px; line-height: 1; transition: transform .22s ease; }
body.controles-ocultos .mv-toggle .chev { transform: rotate(-180deg); }

/* barra de controles — tudo em uma linha só */
.mv-controles {
  border-top: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  max-height: 64px;
  transition: max-height .24s ease, opacity .2s ease, border-color .24s;
}
body.controles-ocultos .mv-controles {
  max-height: 0; opacity: 0; border-top-color: transparent;
}
.mv-controles-inner {
  max-width: 900px; margin: 0 auto; padding: 10px 12px;
  display: flex; align-items: center; gap: 7px;
  flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.mv-controles-inner::-webkit-scrollbar { height: 0; }
.grupo-tom {
  display: flex; align-items: center; gap: 5px; flex: none;
  background: var(--surface-2); border-radius: 11px; padding: 4px 7px;
}
.grupo-tom .rotulo { font-size: 10px; color: var(--text-soft); letter-spacing: .5px; }
.ctrl {
  flex: none;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); width: 38px; height: 38px; border-radius: 10px;
  font-size: 19px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.ctrl:hover { border-color: var(--brand); color: var(--brand); }
.ctrl:active { transform: scale(.92); }
.tom-atual {
  font-size: 20px; font-weight: 800; color: var(--brand); line-height: 1;
  min-width: 40px; text-align: center;
}
#btn-reset { font-size: 17px; color: var(--text-soft); }
.sep { flex: none; width: 1px; height: 28px; background: var(--border); margin: 0 1px; }
.btn-fit {
  flex: none;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  border-radius: 10px; height: 38px; padding: 0 11px; cursor: pointer;
  font-size: 13px; font-weight: 700; white-space: nowrap;
  display: flex; align-items: center;
}
.btn-fit:hover { color: var(--brand); border-color: var(--brand); }
.btn-fit.ativo { background: var(--accent); color: #fff; border-color: var(--accent); }

/* corpo da cifra */
.cifra-wrap { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
.cifra {
  max-width: 900px; margin: 0 auto; padding: 14px 16px 40px;
  font-family: "SF Mono", "Roboto Mono", "Consolas", "Menlo", monospace;
  font-size: 15px;
}
.cifra.modo-fit { padding-bottom: 12px; }
body.editando .cifra { padding-bottom: 100px; }  /* espaço p/ a barra da nota */
.linha {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  margin: 0 0 1px;
}
.trecho { display: inline-flex; flex-direction: column; white-space: pre; }
.acorde {
  color: var(--chord); font-weight: 700; line-height: 1.05;
  height: 1.25em; white-space: pre;
}
.texto { line-height: 1.3; white-space: pre; }
.linha-vazia { height: .7em; }
.secao {
  color: var(--accent); font-weight: 800; letter-spacing: 1px;
  font-size: .8em; text-transform: uppercase;
  margin: .7em 0 .25em;
}
/* bloco do refrão com fundo destacado */
.bloco-refrao {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 3px 10px 6px;
  margin: 8px 0;
}
.bloco-refrao .secao-refrao { margin-top: 3px; }
:root[data-theme="dark"] .bloco-refrao,
:root:not([data-theme="light"]) .bloco-refrao {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

/* ---------- Editor de cifra ---------- */
.editor-bar { display: none; border-top: 1px solid var(--border); background: var(--surface); }
body.editando .editor-bar { display: block; }
body.editando .mv-controles { display: none; }
body.editando #btn-editar,
body.editando #btn-toggle { display: none; }
.editor-bar-inner {
  max-width: 900px; margin: 0 auto; padding: 9px 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.eb {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; height: 38px; padding: 0 14px; cursor: pointer;
  font-size: 14px; font-weight: 700; white-space: nowrap;
}
.eb-save { background: var(--accent); color: #fff; border-color: var(--accent); }
.eb-cancel:hover { border-color: var(--brand); color: var(--brand); }
.eb-restore { color: var(--text-soft); font-weight: 600; }
.eb-copy { color: var(--brand); border-color: var(--brand); }
.eb-copy:hover { background: var(--brand); color: #fff; }
.eb-hint { font-size: 11.5px; color: var(--text-soft); flex: 1; min-width: 140px; }
.eb-hint b { color: var(--text); }

/* botão do lápis destacado quando a música tem edição salva não é necessário aqui */
#btn-editar { font-size: 17px; }

/* linhas em modo edição: rolam na horizontal em vez de quebrar palavra */
.linha.edit { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
.linha.edit::-webkit-scrollbar { height: 0; }
.cel { display: inline-flex; flex-direction: column; white-space: pre; }
.cel .acorde.edit { min-height: 1.5em; display: flex; align-items: flex-end; gap: 2px; }
.pill-acorde {
  color: var(--chord); font-weight: 800; cursor: pointer;
  padding: 0 3px; border-radius: 5px; border: 1px dashed transparent;
  line-height: 1.25;
}
.pill-acorde:hover { border-color: var(--chord); }
.pill-acorde.sel {
  background: var(--accent); color: #fff; border-color: var(--accent); border-style: solid;
}
.pill-input {
  font-family: inherit; font-size: 1em; font-weight: 800; color: var(--chord);
  width: 4ch; min-width: 3ch; box-sizing: content-box;
  border: 2px solid var(--accent); border-radius: 5px;
  background: var(--surface); padding: 0 3px; text-align: center; line-height: 1.15;
  outline: none;
}
.linha.edit .texto {
  cursor: text; border-bottom: 1px dotted transparent;
}
.linha.edit .texto:hover { border-bottom-color: var(--text-soft); }

/* barra de navegação entre músicas */
.mv-nav {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--border);
}
body.editando .mv-nav { display: none; }
.navbtn {
  flex: 1; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 11px; height: 44px; cursor: pointer; font-size: 14px; font-weight: 700;
  white-space: nowrap;
}
.navbtn:hover { border-color: var(--brand); color: var(--brand); }
.navbtn:active { transform: scale(.97); }
.nav-atual {
  flex: none; min-width: 92px; text-align: center;
  font-size: 12px; color: var(--text-soft); font-weight: 600;
}

/* barra de ação da nota selecionada (fixa embaixo) */
.sel-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: none; align-items: center; gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -6px 20px rgba(0,0,0,.14);
}
body.sel-ativa .sel-bar { display: flex; }
.sel-bar .sel-label { font-size: 13px; color: var(--text-soft); font-weight: 700; }
.sel-bar button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  height: 44px; min-width: 48px; border-radius: 11px; cursor: pointer;
  font-size: 18px; font-weight: 700; flex: 1;
}
.sel-bar button:active { transform: scale(.94); }
.sel-bar button.perigo { color: #e5484d; }
.sel-bar button.ok { background: var(--brand); color: #fff; border-color: var(--brand); flex: 0 0 auto; padding: 0 18px; }

@media (max-width: 520px) {
  .titulo-app b { font-size: 15px; }
  .mv-topo-inner { padding: 9px 12px; }
  .mv-cabecalho h1 { font-size: 16px; }
  .mv-controles-inner { padding: 8px 10px; gap: 6px; }
  .grupo-tom { padding: 4px 6px; gap: 5px; }
  .ctrl { width: 36px; height: 36px; font-size: 18px; }
  .btn-fit { height: 36px; }
  .mv-controles { max-height: 60px; }
  .cifra { padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 400px) {
  .fit-txt { display: none; }        /* mostra só o ícone do "Encaixar" */
  .grupo-tom .rotulo { display: none; }
  .mv-voltar { padding: 9px 10px; }
}
