:root {
  --bg: #0b0c0f;
  --panel: #13151a;
  --panel-2: #1a1d24;
  --line: #2a2e38;
  --text: #ebe6da;
  --muted: #8b8e99;
  --accent: #d63a2f;
  --accent-soft: rgba(214, 58, 47, .16);
  --gold: #e3a54a;
  --radius: 8px;
  --font-ui: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-display: "Cinzel", "Palatino Linotype", Georgia, serif;

  --sheet-bg: #101216;
  --sheet-line: #4b505d;
  --sheet-ink: #f2ede1;
  --sheet-dim: #7d818d;
  --sheet-num: #e0655b;
  --font-tab: Arial, "Helvetica Neue", Helvetica, sans-serif;
}
.paper {
  --sheet-bg: #f6f2e8;
  --sheet-line: #a5a5a5;
  --sheet-ink: #1a1a1a;
  --sheet-dim: #6f6a5f;
  --sheet-num: #c22a1f;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-columns: minmax(0, 1fr);
}
.fretboard, .sheet { overflow: hidden; }

/* ---------- barra superior ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px;
  background: linear-gradient(180deg, #16181e, #111318);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark { color: var(--accent); font-size: 14px; }
.brand-name { font-family: var(--font-display); font-weight: 700; letter-spacing: .08em; font-size: 15px; text-transform: uppercase; }
.mainnav { display: flex; align-items: center; gap: 2px; margin-right: 6px; }
.mainnav a {
  padding: 7px 11px; border-radius: 7px; color: var(--muted); text-decoration: none;
  font-weight: 600; font-size: 13px; white-space: nowrap; transition: background .12s, color .12s;
}
.mainnav a:hover { color: var(--text); background: var(--panel-2); }
.mainnav a.on { color: var(--text); background: var(--accent-soft); box-shadow: inset 0 -2px 0 var(--accent); }
.title-input {
  flex: 1 1 120px; min-width: 90px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  padding: 7px 10px; font-size: 16px; font-weight: 600;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; border-color: var(--accent); background: var(--panel-2); }

.transport, .file { display: flex; align-items: center; gap: 8px; position: relative; }
.tempo { display: flex; align-items: center; gap: 6px; color: var(--muted); padding: 0 2px; white-space: nowrap; }
.tempo input[type=number] {
  width: 58px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 6px; text-align: center; color: var(--text); font-weight: 600;
}
.tempo input[type=range] { width: 90px; accent-color: var(--accent); }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: var(--radius);
  padding: 7px 12px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { border-color: #444a58; background: #222630; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.play { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; min-width: 128px; }
.btn.play:hover { background: #e4483c; }
.btn.play.on { background: #2a2e38; border-color: var(--gold); color: var(--gold); }
.btn.toggle { color: var(--muted); }
.btn.toggle.on { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 230px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px; box-shadow: 0 14px 40px rgba(0,0,0,.5);
}
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--accent-soft); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* ---------- barra de herramientas ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end;
  padding: 10px 18px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.group { display: flex; flex-direction: column; gap: 5px; }
.group.end { margin-left: auto; }
.group-label { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.group .row { display: inline-flex; gap: 4px; align-items: center; }
.group:first-child { display: grid; grid-template-columns: auto auto; grid-template-areas: "l l" "a b"; column-gap: 8px; }
.group:first-child .group-label { grid-area: l; }

.tool {
  height: 38px; min-width: 38px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
  cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text);
  transition: background .12s, border-color .12s;
}
.tool.wide { padding: 0 11px; font-weight: 500; }
.tool:hover { border-color: #4a5060; background: #232732; }
.tool.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tool svg { display: block; }
.tool svg * { stroke: currentColor; }
.tool svg .fill { fill: currentColor; }
.tool svg .hollow { fill: none; }

select {
  height: 38px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 0 8px; cursor: pointer;
}
select:focus, .tool:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.slash { color: var(--muted); }

/* ---------- hoja ---------- */
.sheet-wrap { overflow: auto; padding: 22px 26px; background: var(--bg); outline: none; }
.sheet {
  background: var(--sheet-bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 8px 8px; min-height: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.sheet svg { display: block; cursor: text; user-select: none; }
.s-line { stroke: var(--sheet-line); stroke-width: 1; }
.s-bar { stroke: var(--sheet-ink); stroke-width: 1; }
.s-bar.end { stroke-width: 3; opacity: 1; }
.s-ink { fill: var(--sheet-ink); }
.s-stroke { stroke: var(--sheet-ink); fill: none; stroke-linecap: round; }
.s-bg { fill: var(--sheet-bg); }
.s-fret { fill: var(--sheet-ink); font: 400 14px var(--font-tab); text-anchor: middle; dominant-baseline: central; font-variant-numeric: tabular-nums; }
.s-fret.tied { fill: var(--sheet-dim); font-size: 12px; }
.s-clef { fill: var(--sheet-ink); font: 700 19px var(--font-tab); text-anchor: middle; dominant-baseline: central; }
.s-ts { fill: var(--sheet-ink); font: 700 25px "Times New Roman", Georgia, serif; text-anchor: middle; dominant-baseline: central; }
.s-num { fill: var(--sheet-num); font: 400 11px var(--font-tab); }
.s-num.under { fill: var(--gold); }
.s-num.over { fill: var(--accent); font-weight: 700; }
.s-ann { fill: var(--sheet-ink); font: italic 400 11.5px Georgia, "Times New Roman", serif; text-anchor: middle; }
.s-text { text-anchor: start; font-style: normal; font-weight: 500; }
a.btn { text-decoration: none; display: inline-block; color: var(--text); }
.modal-body ul { margin: 8px 0; padding-left: 20px; line-height: 1.7; }
.s-trip { fill: var(--sheet-ink); font: italic 400 11px Georgia, "Times New Roman", serif; text-anchor: middle; }
.s-col { fill: var(--accent); opacity: .08; }
.s-cursor { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.6; }
.s-sel { fill: var(--gold); opacity: .2; }
.s-slot { fill: none; stroke: var(--sheet-dim); stroke-width: 1; stroke-dasharray: 3 3; opacity: .55; }
.playhead { fill: var(--gold); opacity: .22; }

/* ---------- diapasón ---------- */
.fb-panel { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 18px 10px; }
.fb-head { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.fb-title { font-family: var(--font-display); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; font-size: 12px; }
.fb-hint { color: var(--muted); font-size: 12px; flex: 1; }
.fb-panel.closed .fb-hint, .fb-panel.closed #tgAdvance { display: none; }
.fb-panel.closed .fb-head { margin-bottom: 0; }
.fb-panel.closed .fb-title { flex: 1; }
.fretboard svg { display: block; cursor: pointer; user-select: none; }
.f-wood { fill: #1d1712; }
.f-fret { stroke: #8f8a80; stroke-width: 2; }
.f-nut { stroke: #e6dfcf; stroke-width: 5; }
.f-string { stroke: #b9b3a6; }
.f-inlay { fill: #3b342c; }
.f-fnum { fill: var(--muted); font: 500 10px var(--font-ui); text-anchor: middle; }
.f-open { fill: var(--muted); font: 600 11px var(--font-ui); text-anchor: middle; dominant-baseline: central; }
.f-dot { fill: var(--accent); stroke: #fff; stroke-width: 1; }
.f-dot.play { fill: var(--gold); stroke: #1a1a1a; }
.f-dot.ghost { fill: #fff; opacity: .16; stroke: none; }
.f-lab { fill: #fff; font: 700 9.5px var(--font-ui); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.f-lab.play { fill: #1a1a1a; }
.f-lab.ghost { fill: #fff; opacity: .9; }

/* ---------- estado ---------- */
.status {
  display: flex; gap: 22px; align-items: center; padding: 6px 18px; font-size: 12px;
  color: var(--muted); background: #0e0f13; border-top: 1px solid var(--line);
}
.status .msg { margin-left: auto; color: var(--gold); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { width: min(640px, 92vw); max-height: 84vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-family: var(--font-display); font-size: 17px; letter-spacing: .06em; }
.modal-body { padding: 14px 18px 18px; overflow: auto; }
.lib-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.lib-item.current { border-color: var(--accent); }
.lib-item .name { flex: 1; font-weight: 600; }
.lib-item .meta { color: var(--muted); font-size: 12px; }
.keys { width: 100%; border-collapse: collapse; }
.keys td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.keys td:first-child { white-space: nowrap; width: 42%; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; font: 600 12px var(--font-ui); }

@media (max-width: 1500px) { .tempo input[type=range] { display: none; } }
@media (max-width: 1100px) {
  .tempo input[type=range] { display: none; }
  .fb-hint { display: none; }
}
@media print {
  .topbar, .toolbar, .fb-panel, .status, .modal { display: none !important; }
  .app { display: block; height: auto; }
  .sheet-wrap { overflow: visible; padding: 0; background: #fff; }
  .sheet { border: 0; box-shadow: none; --sheet-bg: #fff; --sheet-line: #999; --sheet-ink: #000; --sheet-dim: #666; }
  .s-cursor, .s-col, .s-slot, .playhead { display: none; }
}
