/* Atril: atril de ensayo. Papel frío, tinta azul noche, acento latón.
   Layout: en escritorio, barra lateral con la obra y el transporte + la partitura a lo ancho.
   En móvil, la misma secuencia en una columna. Espaciado en pasos de 4 px. */
:root {
  --paper: #f3f5f8;
  --surface: #ffffff;
  --ink: #172031;
  --muted: #5d6879;
  --line: #e1e6ee;
  --accent: #a87720;
  --accent-soft: #f5ebd6;
  --accent-ink: #3d2905;
  --good: #2f7d4f;
  --warn: #b4521f;
  --font-display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --r: 12px;
  --side: 340px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f131a; --surface: #161c26; --ink: #e7ebf2; --muted: #9aa5b6; --line: #252e3c;
    --accent: #e2b45c; --accent-soft: #312818; --accent-ink: #1b1306; --good: #6cc792; --warn: #f08d5a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f131a; --surface: #161c26; --ink: #e7ebf2; --muted: #9aa5b6; --line: #252e3c;
  --accent: #e2b45c; --accent-soft: #312818; --accent-ink: #1b1306; --good: #6cc792; --warn: #f08d5a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 16px/1.5 var(--font-body); }
h1, h2, h3, h4 { font-family: var(--font-display); text-wrap: balance; margin: 0; line-height: 1.2; font-weight: 600; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.05rem; margin-bottom: 12px; }
a { color: inherit; }
button, select, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Cabecera ---------- */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--paper) 90%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); padding: 0 24px; display: flex; align-items: center; gap: 24px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand .name { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; }
.tabs { display: flex; gap: 4px; overflow-x: auto; align-self: stretch; scrollbar-width: none; }
.tabs a { display: flex; align-items: center; text-decoration: none; padding: 0 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-color: var(--accent); }
.prefs { margin-left: auto; position: relative; }

/* menús desplegables (ajustes, descargar) */
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
.pop { position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 8px 24px rgb(0 0 0 / .12); padding: 12px; display: grid; gap: 12px; min-width: 260px; }
.pop.right { right: 0; }
.menu { position: relative; }
.menu .pop { gap: 2px; padding: 6px; min-width: 220px; }
#snd-menu .pop { gap: 12px; padding: 12px; min-width: 260px; }
.item { all: unset; cursor: pointer; padding: 8px 12px; border-radius: 8px; }
.item:hover, .item:focus-visible { background: var(--accent-soft); }

/* aviso de demo (solo sin servidor) */
.demo-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 16px; padding: 10px 24px; background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: .9rem; }
.demo-bar p { margin: 0; max-width: 90ch; }
@media (max-width: 600px) { .demo-bar { padding: 10px 12px; justify-content: flex-start; } }

/* ---------- Estructura ---------- */
main { max-width: 1320px; margin: 0 auto; padding: 24px; }
.view { display: grid; gap: 16px; }
.view.narrow { max-width: 880px; margin: 0 auto; }
.workspace { grid-template-columns: var(--side) minmax(0, 1fr); align-items: start; gap: 24px; }
.side { display: grid; gap: 16px; }
.main { display: grid; gap: 16px; min-width: 0; }
.theory { grid-template-columns: minmax(0, 1fr) 440px; align-items: start; gap: 24px; }
.theory .col { display: grid; gap: 16px; min-width: 0; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 16px; margin-top: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px 16px; align-items: end; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.field.check { grid-template-columns: auto 1fr; align-items: center; gap: 8px; }
.field.check label { font-weight: 400; font-size: .9rem; color: var(--ink); }
select, input[type="search"], input[type="password"], input.num, input.txt, textarea {
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-width: 0; width: 100%; }
select { text-overflow: ellipsis; }
.hint { color: var(--muted); font-size: .88rem; margin: 8px 0 0; max-width: 65ch; }

/* secciones plegables */
.fold > summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -4px 0; padding: 4px 0; border-radius: 8px; }
.fold > summary h3 { margin: 0; }
.fold > summary::after { content: ""; flex: none; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translate(-2px, -2px); transition: transform .15s ease-out; }
.fold:not([open]) > summary::after { transform: rotate(-45deg); }
.fold > summary:hover::after { border-color: var(--ink); }
.fold > .fold-body { margin-top: 16px; }
.fold:not([open]) { padding-top: 16px; padding-bottom: 16px; }
@media (prefers-reduced-motion: reduce) { .fold > summary::after { transition: none; } }

/* ---------- Botones ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px; cursor: pointer; font-weight: 600;
  display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; transition: border-color .15s ease-out, background-color .15s ease-out; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 4px 12px; font-size: .85rem; }
.linkbtn { all: unset; cursor: pointer; color: var(--muted); font-size: .85rem; text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:hover, .linkbtn:focus-visible { color: var(--ink); }

/* ---------- Barra lateral ---------- */
.open-bar.drag { border-color: var(--accent); background: var(--accent-soft); }
.open-bar .hint { margin-top: 8px; }
.status { margin-top: 8px; font-size: .9rem; }
.status:empty { display: none; }
.status .bar { height: 3px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.status .bar i { display: block; height: 100%; width: 30%; background: var(--accent); animation: slide 1.2s infinite ease-in-out; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .status .bar i { animation: none; width: 100%; opacity: .5; } }
.err { color: var(--warn); }

.ficha .meta { color: var(--muted); }
#ficha-title { font-size: 1.2rem; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 12px 0 0; font-size: .92rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.facts dd small { font-weight: 400; color: var(--muted); }
.ficha .note-warn { margin-top: 12px; font-size: .88rem; color: var(--warn); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: .85rem; background: var(--paper); }
button.chip { cursor: pointer; transition: border-color .15s ease-out; }
button.chip:hover, button.chip[aria-pressed="true"] { border-color: var(--accent); }
button.chip[aria-pressed="true"] { background: var(--accent-soft); }

.summary { margin-top: 16px; padding: 12px 16px; background: var(--accent-soft); border-radius: 10px; display: grid; gap: 8px; font-size: .92rem; }
.summary > div { display: grid; gap: 2px; }
.summary .big { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
.more { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.more > summary { color: var(--muted); font-weight: 600; font-size: .9rem; }
.more > summary::after { content: " +"; }
.more[open] > summary::after { content: " −"; }
.more[open] > summary { margin-bottom: 12px; }

/* ---------- Partitura ---------- */
.score-card { padding: 16px 20px 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.toolbar .sp { flex: 1; }
.toolbar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.tempo { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; }
input.num { width: 4.5rem; padding: 6px 8px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.toggle:hover { background: var(--paper); }
.paper { color: var(--ink); overflow-x: auto; min-height: 160px; }
.paper svg { max-width: 100%; }
.paper pre { font-family: var(--font-mono); font-size: .8rem; white-space: pre-wrap; }
.foot { display: flex; justify-content: flex-end; padding-top: 8px; }
.warnbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; margin-bottom: 12px; border-radius: 8px; border: 1px solid var(--warn); color: var(--warn); font-size: .9rem; }

/* pestañas bajo la partitura */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--paper); border-radius: 10px; margin-bottom: 20px; overflow-x: auto; }
.seg button { all: unset; cursor: pointer; padding: 8px 16px; border-radius: 8px; font-weight: 600; color: var(--muted); white-space: nowrap; flex: 1; text-align: center; }
.seg button:hover { color: var(--ink); }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .06); }
.seg button:focus-visible { outline: 2px solid var(--accent); }

.measures { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.measure { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: grid; gap: 2px; align-content: start; min-height: 72px; }
.measure .n { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.measure .chs { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.measure button { all: unset; cursor: pointer; display: grid; border-radius: 6px; padding: 2px 4px; margin: 0 -4px; }
.measure button:hover, .measure button:focus-visible { background: var(--accent-soft); }
.measure .sym { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; line-height: 1.2; }
.measure .sub { font-size: .75rem; color: var(--muted); }
.legend-line { color: var(--muted); font-size: .88rem; margin: 0 0 12px; }

.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 10px 24px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv + .kv { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }

.prose { max-width: 68ch; }
.prose:empty { display: none; }
.prose h4 { margin: 20px 0 6px; font-size: 1rem; }
.prose h4:first-child { margin-top: 0; }
.prose p { margin: 6px 0; }
.prose ul { margin: 4px 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.prose.cols { max-width: none; columns: 2 340px; column-gap: 40px; }
.prose.cols h4 { break-after: avoid; }
.prose.cols ul { break-inside: avoid-column; }

code { font-family: var(--font-mono); font-size: .85em; background: var(--paper); padding: 1px 4px; border-radius: 4px; }
.ed-measures { display: grid; gap: 6px; margin-top: 16px; }
.ed-row { display: grid; grid-template-columns: 3rem 1fr 10rem; gap: 8px; align-items: center; }
.ed-row .n { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ed-row input { font-family: var(--font-mono); font-size: .85rem; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; min-width: 0; }
.ed-row.bad input { border-color: var(--warn); }

/* ---------- Tablas, notas, teclado ---------- */
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
.tablewrap { overflow-x: auto; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; }
td.num { font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-soft); }
tr.me td { background: var(--accent-soft); font-weight: 600; }

.notes { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.note { border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; text-align: center; min-width: 56px; background: var(--paper); }
.note .nn { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; display: block; }
.note .dg { font-size: .72rem; color: var(--muted); display: block; }
.kb { margin: 12px 0; overflow-x: auto; }
.kb svg { display: block; max-width: 100%; height: auto; }
.callout { margin-top: 16px; padding: 12px 16px; border: 1px dashed var(--accent); border-radius: 10px; }
.th-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; margin-top: 20px; }
.th-head h2 { font-size: 1.4rem; }
.th-head .facts-inline { color: var(--muted); font-size: .9rem; }
.section-gap { margin-top: 24px; }

#circle svg { width: 100%; max-width: 360px; display: block; margin: 8px auto 0; }
#circle text { font-family: var(--font-display); font-weight: 600; }
#circle .cof-key { cursor: pointer; outline: none; }
#circle .cof-w, #circle .cof-t { transition: fill .15s ease-out; }
#circle .cof-key:focus-visible .cof-w { stroke: var(--accent); stroke-width: 2.5; }
@media (prefers-reduced-motion: reduce) { #circle .cof-w, #circle .cof-t { transition: none; } }
.cof-info { margin-top: 12px; }
.cof-info .notes { margin: 12px 0; gap: 6px; }
.cof-info .note { min-width: 44px; padding: 4px 8px; }
.cof-info .note .nn { font-size: 1rem; }
.cof-name { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }

/* ---------- Repertorio, reportes, diálogo ---------- */
.rep-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.rep-item .t { font-weight: 600; }
.rep-item .m { color: var(--muted); font-size: .88rem; }
.rep-children { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.badge { font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); margin-left: 8px; vertical-align: 2px; }
.report { border-bottom: 1px solid var(--line); padding: 12px 0; display: grid; gap: 4px; }
.report pre { font-family: var(--font-mono); font-size: .72rem; white-space: pre-wrap; max-height: 160px; overflow: auto; background: var(--paper); padding: 8px; border-radius: 6px; margin: 0; }
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 20px; width: min(520px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { display: grid; gap: 12px; }
textarea { resize: vertical; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 16px; border-radius: 999px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s ease-out; max-width: calc(100% - 32px); }
.toast.on { opacity: 1; }

/* ---------- Pantallas medianas y móvil ---------- */
@media (max-width: 1100px) {
  .theory { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .top { padding: 0 12px; gap: 12px; flex-wrap: wrap; }
  .tabs { order: 3; width: 100%; margin: 0 -12px; padding: 0 4px; border-top: 1px solid var(--line); min-height: 44px; }
  .tabs a { padding: 0 8px; font-size: .95rem; }
  main { padding: 12px; }
  .view, .side, .main { gap: 12px; }
  .panel { padding: 16px; }
  .score-card { padding: 12px 12px 8px; }
  h2 { font-size: 1.3rem; }
  .toolbar .sep { display: none; }
  .ed-row { grid-template-columns: 2.4rem 1fr; }
  .ed-row input.c { grid-column: 2; }
  .seg button { padding: 8px 6px; font-size: .9rem; }
  .prose.cols { columns: 1; }
}
