:root {
  --bg: #fafaf7;
  --fg: #1b1b1b;
  --muted: #777;
  --line: #e2e2dc;
  --chord: #d9601a;
  --section: #2a6fb0;
  --accent: #7c1adf;
  --accent-fg: #fff;
  --accent-text: #7c1adf;
  --danger: #c62828;
  --panel: rgba(250, 250, 247, 0.97);
  --flash: rgba(124, 26, 223, 0.16);
  --bar-h: 40px;
  --mono: 'Roboto Mono', ui-monospace, 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
}
:root[data-theme='dark'] {
  --bg: #111;
  --fg: #ececec;
  --muted: #8a8a8a;
  --line: #2a2a2a;
  --chord: #ff9a4d;
  --section: #6fb0ff;
  --accent: #7c1adf;
  --accent-text: #b388ff;
  --danger: #ff6b6b;
  --panel: rgba(22, 22, 22, 0.97);
  --flash: rgba(124, 26, 223, 0.28);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font: 16px/1.4 system-ui, -apple-system, Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button {
  font: inherit; color: inherit; background: transparent;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.danger { color: var(--danger); }
input, textarea {
  font: inherit; color: inherit; background: transparent;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Thin fixed header */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  height: calc(var(--bar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; gap: 4px;
  padding-left: max(4px, env(safe-area-inset-left)); padding-right: max(4px, env(safe-area-inset-right));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.bar-btn { border: 0; font-size: 24px; line-height: 1; padding: 0 12px; height: 100%; border-radius: 0; }
.bar-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; padding-left: 8px; }
.bar-title strong, .bar-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title strong { font-size: 16px; flex-shrink: 1; }
.bar-title span { color: var(--muted); font-size: 13px; flex-shrink: 2; }
.bar-extra { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; padding: 0 4px; }
body[data-view='viewer'] { --bar-h: 32px; }
body[data-view='viewer'] .bar-title strong { font-size: 14px; }
body[data-view='viewer'] .bar-btn { font-size: 20px; }

.bar-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; display: block; }
.bar-icon svg circle { fill: currentColor; stroke: none; }

/* Install banner (fixed under the header) */
:root { --banner-h: 0px; }
body.has-banner { --banner-h: 64px; }
.install-banner {
  position: fixed; left: 0; right: 0; z-index: 9; height: var(--banner-h);
  top: calc(var(--bar-h) + env(safe-area-inset-top));
  display: flex; align-items: center; gap: 2px;
  padding: 0 max(4px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  background: linear-gradient(135deg, #7c1adf 0%, #9356cf 100%); color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.install-open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; border: 0; padding: 8px 0; text-align: left; color: inherit; }
.install-open img { width: 44px; height: 44px; border-radius: 11px; flex: none; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); }
.install-text { flex: 1; min-width: 0; }
.install-text b, .install-text small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.install-text b { font-size: 15px; }
.install-text small { font-size: 12px; opacity: 0.85; }
.install-cta {
  flex: none; background: #fff; color: #7c1adf; font-weight: 700; font-size: 14px;
  border-radius: 999px; padding: 7px 14px;
}
.install-x { border: 0; color: inherit; font-size: 15px; padding: 12px 10px; opacity: 0.85; }
/* Install guide (full screen) */
.install-guide {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 50; overflow-y: auto;
  background: var(--bg); color: var(--fg);
  padding: max(16px, env(safe-area-inset-top)) 20px max(110px, calc(env(safe-area-inset-bottom) + 110px));
  animation: guide-in 0.18s ease-out;
}
@keyframes guide-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.install-close {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 10px; z-index: 2;
  border: 0; font-size: 20px; padding: 10px 14px; color: var(--muted);
}
.install-body { max-width: 440px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; }
.phone {
  --mock: var(--line);
  width: min(64vw, 300px); margin-top: 40px; padding: 22px 18px 0;
  border: 10px solid var(--mock); border-bottom: 0; border-radius: 56px 56px 0 0;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
.phone-notch { width: 34%; height: 26px; border-radius: 13px; background: var(--mock); }
.phone-grid { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.phone-grid i { display: block; padding-bottom: 100%; border-radius: 26%; background: var(--mock); }
.phone-grid img {
  grid-column: 2 / span 2; grid-row: 2 / span 2; width: 100%; border-radius: 22%;
  box-shadow: 0 10px 30px rgba(124, 26, 223, 0.35); animation: icon-pop 0.5s 0.15s ease-out both;
}
@keyframes icon-pop { from { transform: scale(0.6); opacity: 0; } 70% { transform: scale(1.06); } to { transform: none; opacity: 1; } }
.install-guide h2 { font-size: 26px; line-height: 1.2; text-align: center; margin: 28px 0 20px; }
.install-steps { align-self: stretch; margin: 0; padding-left: 28px; display: flex; flex-direction: column; gap: 12px; font-size: 18px; line-height: 1.6; }
.install-steps .hl { color: var(--accent-text); }
.ic {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: -6px;
  width: 26px; height: 26px; color: var(--accent-text); margin: 0 2px;
}
.ic svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic.fill { background: var(--accent); color: #fff; border-radius: 50%; width: 30px; height: 30px; }
.ic.fill svg { width: 20px; height: 20px; }
.ic svg .dot { fill: currentColor; stroke: none; }
.install-note { align-self: stretch; font-size: 14px; background: var(--line); border-radius: 10px; padding: 10px 12px; margin: 18px 0 0; }
.install-note .ic { width: 20px; height: 20px; vertical-align: -5px; }
.install-note .ic svg { width: 18px; height: 18px; }
.install-now { margin-top: 20px; padding: 12px 28px; font-size: 17px; border-radius: 999px; }
.install-browser { color: var(--muted); font-size: 13px; margin-top: 18px; }

/* "Toque em …" bubble pointing at the browser button */
.install-tip {
  position: fixed; z-index: 3; display: flex; align-items: center; gap: 8px;
  background: var(--accent); color: #fff; font-size: 19px; font-weight: 500;
  padding: 10px 12px 10px 20px; border-radius: 999px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  animation: tip-bob 1.4s ease-in-out infinite;
}
.install-tip .ic { color: var(--accent); background: #fff; border-radius: 50%; width: 32px; height: 32px; margin: 0; }
.install-tip .ic svg { width: 20px; height: 20px; }
.install-tip::after {
  content: ''; position: absolute; width: 16px; height: 16px; background: var(--accent); transform: rotate(45deg); border-radius: 3px;
}
.install-tip.bottom { bottom: max(18px, calc(env(safe-area-inset-bottom) + 14px)); }
.install-tip.bottom::after { bottom: -6px; }
.install-tip.top { top: max(14px, calc(env(safe-area-inset-top) + 10px)); --bob: -6px; }
.install-tip.top::after { top: -6px; }
.install-tip.center { left: 50%; transform: translateX(-50%); }
.install-tip.center::after { left: calc(50% - 8px); }
.install-tip.right { right: 12px; }
.install-tip.right::after { right: 26px; }
@keyframes tip-bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 var(--bob, 6px); } }

/* Share */
.share-link { font: 13px/1.3 var(--mono); word-break: break-all; color: var(--muted); }
.share-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.share-actions .row { justify-content: stretch; }
.share-actions .row button { flex: 1; }
a.btn.wa { background: #25D366; border-color: #25D366; color: #08260f; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; }
a.btn.wa svg { width: 22px; height: 22px; }

body.readonly #import-form, body.readonly #btn-paste,
body.readonly .rows .handle, body.readonly .rows .del, body.readonly .rows .chip { display: none; }
body.readonly .rows .open { padding-left: 10px; }

/* Lists */
.list-view {
  max-width: 720px; margin: 0 auto;
  padding: calc(var(--bar-h) + var(--banner-h) + env(safe-area-inset-top) + 8px) 12px calc(32px + env(safe-area-inset-bottom));
}
.rows { list-style: none; padding: 0; margin: 0; }
.rows li {
  display: flex; align-items: center; border-bottom: 1px solid var(--line);
  background: var(--bg); position: relative;
}
.rows .open { flex: 1; min-width: 0; text-align: left; border: 0; padding: 14px 6px; border-radius: 0; }
.rows .open small { display: block; color: var(--muted); font-size: 13px; }
.rows .num { color: var(--muted); font-size: 13px; margin-right: 8px; font-variant-numeric: tabular-nums; }
.rows .chev { color: var(--muted); font-size: 22px; padding: 0 8px; }
.rows .del { border: 0; color: var(--muted); font-size: 16px; padding: 14px 12px; }
.rows .handle {
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  color: var(--muted); font-size: 22px; padding: 14px 10px 14px 4px;
}
.rows.sorting li { transition: transform 0.15s ease; }
.rows.sorting li.dragging {
  transition: none; z-index: 2; background: var(--panel);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); border-radius: 8px;
}
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.import { display: flex; gap: 8px; margin: 4px 0 8px; }
.import button { white-space: nowrap; }
.paste-btn { width: 100%; margin-bottom: 4px; }
.stack p { margin: 0; }
.status { font-size: 14px; color: var(--muted); margin: 4px 0 8px; }
.status.err { color: var(--danger); }
.empty { color: var(--muted); text-align: center; margin-top: 40px; }

/* Dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--fg);
  padding: 16px; width: min(92vw, 480px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h2 { margin: 0; font-size: 18px; }
.menu { display: flex; flex-direction: column; gap: 8px; }
.menu button { text-align: left; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.center { align-items: center; text-align: center; }
.stack textarea { height: 40vh; font-family: var(--mono); font-size: 13px; white-space: pre; }
.row { display: flex; gap: 8px; justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; justify-content: center; }
.qr { width: min(64vw, 260px); }
.qr svg { display: block; width: 100%; height: auto; border-radius: 8px; }
.code { font: 700 28px/1.2 var(--mono); letter-spacing: 0.08em; color: var(--accent-text); }
.scan { width: 100%; max-height: 50vh; border-radius: 10px; background: #000; object-fit: cover; }

/* New playlist / Spotify */
.big-choice { display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px; }
.big-choice small { display: block; color: var(--muted); font-size: 13px; }
.spotify-logo { width: 32px; height: 32px; flex: none; }
h2 .spotify-logo { width: 22px; height: 22px; vertical-align: -4px; margin-right: 4px; }
.manual-icon { width: 32px; height: 32px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 22px; border: 1px solid var(--line); border-radius: 50%; }
.sp-preview { display: flex; flex-direction: column; gap: 8px; }
.sp-head { display: flex; gap: 12px; align-items: center; }
.sp-head img { width: 72px; height: 72px; border-radius: 6px; object-fit: cover; background: var(--line); }
.sp-head strong, .sp-head span { display: block; }
.sp-tracks { margin: 0; padding-left: 28px; max-height: 32vh; overflow-y: auto; font-size: 14px; }
.sp-tracks li { padding: 2px 0; }
.sp-tracks small { color: var(--muted); }
.cover-sm { width: 44px; height: 44px; border-radius: 4px; object-fit: cover; flex: none; margin-left: 4px; }
.pl-head { display: flex; gap: 14px; align-items: center; margin: 4px 0 12px; }
.pl-head img { width: 96px; height: 96px; border-radius: 8px; object-fit: cover; }
.pl-head strong { display: block; font-size: 18px; }
.pl-head a { color: #1DB954; font-size: 13px; text-decoration: none; }
.progress { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); }
.rows li.pending .open { color: var(--muted); }
.chip { font-size: 12px; border: 1px solid var(--accent-text); color: var(--accent-text); border-radius: 999px; padding: 3px 9px; white-space: nowrap; margin-right: 2px; }
.paste-target { display: flex; gap: 8px; }
a.btn {
  flex: 1; text-align: center; text-decoration: none; color: inherit; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 10px;
}
a.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }

/* Reader */
#viewer {
  position: fixed; left: 0; right: 0; bottom: 0; overflow: hidden; background: var(--bg);
  top: calc(var(--bar-h) + env(safe-area-inset-top));
}
.stage { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; touch-action: none; }
.track { display: flex; height: 100%; will-change: transform; }
.track.anim { transition: transform 0.22s ease-out; }
.page {
  flex: 0 0 100%; height: 100%; display: flex; gap: var(--col-gap, 24px); overflow: hidden;
  padding: 8px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.col { flex: 1 1 0; min-width: 0; overflow: hidden; }
.col + .col { border-left: 1px solid var(--line); padding-left: var(--col-gap, 24px); }

.sheet { font-family: var(--mono); line-height: 1.3; }
.sheet .ln { white-space: pre; height: 1.3em; overflow: hidden; }
.sheet .chord { color: var(--chord); font-weight: 700; }
.sheet .section { color: var(--section); font-weight: 700; }
.measure { position: absolute; visibility: hidden; left: -9999px; top: 0; font-size: 100px; white-space: pre; }

.controls {
  /* dropdown anchored under the header's ⋮ */
  position: absolute; top: 6px; right: max(6px, env(safe-area-inset-right)); z-index: 5;
  display: flex; flex-direction: column; gap: 2px; min-width: 200px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  transform-origin: top right; animation: drop-in 0.12s ease-out;
}
.controls::before {
  content: ''; position: absolute; top: -7px; right: 14px; width: 12px; height: 12px;
  background: var(--panel); border-left: 1px solid var(--line); border-top: 1px solid var(--line);
  transform: rotate(45deg);
}
.controls button { border: 0; text-align: left; padding: 11px 12px; border-radius: 8px; }
.controls button:active { background: var(--line); }
.controls .ctl-row { display: flex; gap: 2px; }
.controls .ctl-row button { flex: 1; text-align: center; font-weight: 600; }
@keyframes drop-in { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: none; } }
.toast {
  position: absolute; left: 50%; top: 40%; transform: translateX(-50%); max-width: 86vw; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px; font-size: 15px; pointer-events: none;
}

/* Page-turn feedback: blink the touched half + arrow showing direction */
.flash {
  position: absolute; left: 0; right: 0; height: 50%; pointer-events: none; opacity: 0;
  display: flex; align-items: center; justify-content: center;
}
.flash.top { top: 0; }
.flash.bottom { bottom: 0; }
.flash .flip { display: block; }
.flash.back .flip { transform: scaleX(-1); }
.flash svg {
  display: block; width: 88px; height: 88px; fill: none; stroke: var(--accent-text);
  stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
}
.flash.go { animation: flash-blink 0.5s ease-out; }
.flash.go svg { animation: flash-arrow 0.5s ease-out; }
@keyframes flash-blink {
  0% { opacity: 1; background: var(--flash); }
  25% { opacity: 1; background: transparent; }
  45% { opacity: 1; background: var(--flash); }
  100% { opacity: 0; background: transparent; }
}
@keyframes flash-arrow {
  0% { transform: translateX(-24px); }
  60% { transform: translateX(8px); }
  100% { transform: translateX(16px); }
}
