:root {
  --bg: #14161a;
  --surface: #1f2228;
  --surface-2: #2a2e36;
  --text: #f1f2f4;
  --muted: #9aa0aa;
  --accent: #e8b04a;
  --ok: #4cc38a;
  --danger: #e5604f;
  --sheet: #ffffff;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; }

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--bg);
}
.bar h1 { margin: 0; font-size: 1.35rem; flex: 1; }
.logo { color: var(--accent); }

.icon-btn {
  background: var(--surface);
  border: 0;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.25rem;
  cursor: pointer;
  flex: none;
}
.pill-btn {
  background: var(--surface-2);
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.pill-btn[aria-pressed="true"] { background: var(--accent); color: #1a1a1a; font-weight: 600; }

.primary-btn {
  display: block;
  text-align: center;
  background: var(--accent);
  color: #1a1a1a;
  font-weight: 600;
  padding: 14px;
  border-radius: var(--radius);
  cursor: pointer;
}

/* Biblioteca */
.lib-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(20, 22, 26, 0));
  position: relative;
  z-index: 2;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.brand p { margin: 0; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.7rem;
  color: #1a1a1a;
  background: linear-gradient(135deg, #f3c76a, var(--accent));
  flex: none;
}
.head-actions { display: flex; align-items: center; gap: 10px; }
.add-btn { padding: 10px 16px; border-radius: 999px; }

.lib-main {
  flex: 1;
  overflow-y: auto;
  padding: 4px 20px calc(32px + var(--safe-bottom));
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

.hint {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  padding: 10px 10px 10px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.hint span { flex: 1; }
.hint-close { background: none; border: 0; color: var(--muted); font-size: 1rem; padding: 6px; cursor: pointer; }

.continue-card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  text-align: left;
  padding: 12px 18px 12px 12px;
  margin-bottom: 20px;
  border: 1px solid rgba(232, 176, 74, 0.35);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(232, 176, 74, 0.16), var(--surface) 60%);
  cursor: pointer;
}
.continue-thumb {
  width: 64px;
  aspect-ratio: 0.72;
  border-radius: 8px;
  background: #fff center top / cover no-repeat;
  flex: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.continue-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.continue-text strong { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eyebrow { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.continue-go {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #1a1a1a;
  flex: none;
  padding-left: 3px;
}

.progress { display: block; height: 3px; border-radius: 2px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); }

.lib-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.lib-tools input[type="search"] {
  flex: 1 1 200px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 14px;
  outline: none;
}
.lib-tools input[type="search"]:focus { border-color: var(--accent); }
.segmented { display: inline-flex; background: var(--surface); border-radius: 12px; padding: 3px; }
.segmented button { background: none; border: 0; padding: 7px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }

.score-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 22px 16px;
}
.score-card { position: relative; min-width: 0; }
.score-open {
  display: grid;
  gap: 4px;
  width: 100%;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 0.72;
  border-radius: 10px;
  background: #fff center top / cover no-repeat;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  color: #c9ccd2;
  font-size: 2.4rem;
  margin-bottom: 6px;
  transition: transform 0.15s ease;
}
.score-open:active .thumb { transform: scale(0.97); }
.score-name {
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.score-menu-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: rgba(20, 22, 26, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.no-results { text-align: center; margin-top: 32px; }

.menu {
  position: fixed;
  z-index: 20;
  min-width: 170px;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  display: grid;
}
.menu button { background: none; border: 0; text-align: left; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: rgba(255, 255, 255, 0.06); }
.menu .danger { color: var(--danger); }

.empty { text-align: center; max-width: 420px; margin: 48px auto 0; display: grid; gap: 12px; justify-items: center; }
.empty h2 { margin: 8px 0 0; font-size: 1.4rem; }
.empty p { margin: 0 0 8px; }
.empty-mark {
  width: 96px;
  height: 96px;
  border-radius: 28px;
  display: grid;
  place-items: center;
  font-size: 3.6rem;
  color: var(--accent);
  background: var(--surface);
}

.guide { margin-top: 40px; background: var(--surface); border-radius: 18px; padding: 4px 16px; }
.guide[open] { padding-bottom: 16px; }
.guide summary {
  cursor: pointer;
  padding: 14px 0;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.guide summary::-webkit-details-marker { display: none; }
.guide summary::before { content: "›"; color: var(--accent); font-size: 1.3rem; transition: transform 0.2s; }
.guide[open] summary::before { transform: rotate(90deg); }
.guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.guide figure { margin: 0; }
.guide img { display: block; width: 100%; height: auto; border-radius: 12px; background: var(--bg); }
.guide figcaption { margin-top: 8px; font-size: 0.85rem; color: var(--muted); text-align: center; }
.guide figcaption b { color: var(--text); }
.guide-more { text-align: center; margin: 14px 0 0; }

.lib-footer { text-align: center; color: var(--muted); font-size: 0.75rem; opacity: 0.7; margin-top: 40px; }

.drop-overlay {
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: 20px;
  background: rgba(20, 22, 26, 0.85);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  font-weight: 600;
  z-index: 5;
  pointer-events: none;
}

@media (max-width: 480px) {
  .score-grid { grid-template-columns: repeat(2, 1fr); gap: 18px 12px; }
  .lib-head, .lib-main { padding-left: 16px; padding-right: 16px; }
  .brand-mark { width: 40px; height: 40px; font-size: 1.5rem; }
}

/* Visor */
#viewer { background: #000; }
.stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: var(--sheet);
  overflow: hidden;
  padding: var(--safe-top) 0 var(--safe-bottom);
}
.stage canvas { display: block; background: #fff; }
body.dark-sheets .stage { background: #000; }
body.dark-sheets .stage canvas { filter: invert(1) hue-rotate(180deg); }

.tap-zone { position: absolute; top: 0; bottom: 0; background: none; border: 0; padding: 0; cursor: pointer; }
.tap-zone.left { left: 0; width: 28%; }
.tap-zone.right { right: 0; width: 28%; }
.tap-zone.middle { left: 28%; right: 28%; }
body.no-taps .tap-zone.left, body.no-taps .tap-zone.right { pointer-events: none; }
body.no-taps .tap-zone.middle { left: 0; right: 0; }

/* Barra del visor: los botones quedan siempre visibles y semitransparentes
   sobre la partitura; el título y la página se ocultan solos. */
.overlay {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  background: none;
  pointer-events: none;
}
.overlay > * { pointer-events: auto; }
.overlay .icon-btn {
  background: rgba(20, 22, 26, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  width: 44px;
  height: 44px;
}
.overlay #cam-toggle[aria-pressed="true"] { background: rgba(232, 176, 74, 0.75); color: #1a1a1a; }
.title-block {
  flex: 1;
  min-width: 0;
  align-self: center;
  justify-self: start;
  margin-right: auto;
  max-width: max-content;
  background: rgba(20, 22, 26, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 12px;
  padding: 4px 12px;
  transition: opacity 0.2s ease;
}
.overlay.hidden .title-block { opacity: 0; pointer-events: none; }
.score-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.flash {
  position: absolute;
  top: 50%;
  width: 64px;
  height: 64px;
  margin-top: -32px;
  border-radius: 50%;
  background: rgba(232, 176, 74, 0.9);
  color: #1a1a1a;
  font-size: 2rem;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
}
.flash.show { animation: flash 0.5s ease-out; }
.flash.next { right: 16px; }
.flash.prev { left: 16px; }
@keyframes flash { 0% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.3); } }

.cam-dot {
  position: absolute;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.cam-dot[data-state="tracking"] { background: var(--ok); }
.cam-dot[data-state="searching"] { background: var(--accent); }
.cam-dot[data-state="idle"] { background: var(--muted); }
.cam-dot[data-state="loading"] { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* iOS deja de entregar imágenes de un <video> oculto, así que queda diminuto pero visible */
.video {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 2px;
  height: 2px;
  opacity: 0.01;
  pointer-events: none;
  transform: scaleX(-1);
}
body.show-preview .video {
  width: 96px;
  height: 72px;
  right: 30px;
  bottom: calc(12px + var(--safe-bottom));
  opacity: 0.85;
  border-radius: 8px;
  object-fit: cover;
}

/* Ajustes */
.sheet {
  border: 0;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border-radius: 18px;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
.sheet-inner { padding: 8px 20px 24px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); padding: 12px 0 4px; z-index: 1; }
.sheet h2 { margin: 0; font-size: 1.2rem; }
.sheet h3 { margin: 20px 0 8px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.row.col { flex-wrap: wrap; }
.row.col input[type="range"] { flex-basis: 100%; }
.row.check { justify-content: flex-start; }
.row select { background: var(--surface-2); border: 0; border-radius: 8px; padding: 8px; max-width: 60%; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="checkbox"] { accent-color: var(--accent); width: 20px; height: 20px; }

.defaults-actions { display: grid; gap: 8px; }
.defaults-actions .primary-btn { border: 0; width: 100%; font: inherit; font-weight: 600; }
.defaults-actions .pill-btn { width: 100%; padding: 12px; border-radius: var(--radius); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }

.meters { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-top: 8px; display: grid; gap: 6px; }
.meter { display: grid; grid-template-columns: 11em 1fr; align-items: center; gap: 8px; font-size: 0.85rem; }
.meter i { position: relative; height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.meter b { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--muted); transition: width 0.08s linear; }
.meter.on b { background: var(--ok); }
.meter.center i::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--muted); }
.meter.center b { background: var(--accent); transition: none; }
.meter em { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); }
.meters:not(.live) .meter { opacity: 0.4; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  padding: 10px 16px;
  border-radius: 10px;
  max-width: calc(100vw - 32px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 10;
}
.toast.show { opacity: 1; }
