@font-face {
  font-family: Leland;
  src: url('../fonts/leland.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --bg: #f4f4f0;
  --app-bg: #fff;
  --border: #e5e5e0;
  --text: #1a1a1a;
  --text-dim: #666;
  --text-faint: #888;
  --chip-bg: #fff;
  --chip-border: #ddd;
  --btn-bg: #fff;
  --btn-border: #ddd;
  --select-bg: #fff;
  --log-bg: #f8f8f5;
  --log-border: #eee;
  --staff-bg: #fff;
  --shadow: 0 1px 6px rgba(0,0,0,.08);
  --accent: #2563eb;
  --chip-active-bg: #dbeafe;
  --chip-active-color: #1d4ed8;
  --chip-active-border: #93c5fd;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181818;
    --app-bg: #222;
    --border: #333;
    --text: #e0e0d8;
    --text-dim: #aaa;
    --text-faint: #777;
    --chip-bg: #2a2a2a;
    --chip-border: #444;
    --btn-bg: #2a2a2a;
    --btn-border: #444;
    --select-bg: #2a2a2a;
    --log-bg: #1c1c1c;
    --log-border: #333;
    --staff-bg: #1c1c1c;
    --shadow: 0 1px 6px rgba(0,0,0,.4);
    --chip-active-bg: #1e3a8a;
    --chip-active-color: #93c5fd;
    --chip-active-border: #3b82f6;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 0.8rem;
  overscroll-behavior: none;
}

body.side-resizing {
  cursor: col-resize;
  user-select: none;
}

.app-shell {
  display: flex;
  align-items: flex-start;
  gap: 0;
  max-width: 100%;
  margin: 0 auto;
}

.app-main {
  flex: 1;
  min-width: 0;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  background: var(--app-bg);
  border-radius: 14px;
  padding: 1.2rem 1.4rem;
  box-shadow: var(--shadow);
}

@media (min-width: 901px) {
  .app-shell .app-main .app {
    max-width: none;
    margin: 0;
    width: 100%;
  }

  .app-shell {
    align-items: flex-start;
    min-height: calc(100vh - 1.6rem);
  }

  .app-main {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 1.6rem);
    flex: 1;
  }

  .app {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 1.6rem);
  }

  .staff-outer {
    flex: 1 1 auto;
    min-height: 140px;
    margin-bottom: 0.35rem;
  }

  .tool-dock:not(.is-floating) {
    flex-shrink: 0;
  }

  .correction-dock:not(.is-floating) {
    flex: 1 1 160px;
    min-height: 120px;
    max-height: none;
  }

  .correction-dock:not(.is-floating) .correction-dock-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .correction-dock:not(.is-floating) .correction-card {
    flex: 1;
    min-height: 0;
    align-items: stretch;
  }

  .correction-dock:not(.is-floating) .correction-log {
    max-height: none;
    flex: 1;
    min-height: 0;
  }

  /* Ambos modales flotando: el pentagrama se lleva casi todo el hueco */
  .app-shell[data-tool-float="1"][data-corr-float="1"] .staff-outer {
    flex: 1 1 0;
    min-height: 200px;
  }

  /* Solo corrección acoplada: crece hacia abajo */
  .app-shell[data-corr-float="0"] .correction-dock:not(.is-floating) {
    flex: 1 1 200px;
  }

  .side-panel:not(.is-collapsed) {
    align-self: flex-start;
    flex-shrink: 0;
    overflow: hidden;
  }
}

h1 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 0.9rem;
  letter-spacing: -0.01em;
}

/* ── Filas de controles ── */
.row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.lbl {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Chips (figura, escritura, alteración, voz) ── */
.chip {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  cursor: pointer;
  color: var(--text);
  transition: border-color .12s, background .12s;
  min-height: 30px;
  touch-action: manipulation;
}

.chip:hover { border-color: #999; }

/* ── Tresillo: botón principal + flecha + menú desplegable ── */
.tuplet-btn-wrap {
  position: relative;
  display: inline-flex;
  gap: 2px;
}
.tuplet-arrow {
  padding: 4px 7px;
  border-radius: 0 20px 20px 0;
  font-size: 11px;
}
.tuplet-btn-wrap > .chip:first-child {
  border-radius: 20px 0 0 20px;
}
.tuplet-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  background: var(--panel-bg, #fff);
  border: 1px solid var(--chip-border, #ccc);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  min-width: 210px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tuplet-menu.hidden { display: none; }
.tuplet-option {
  background: none;
  border: none;
  padding: 10px 16px;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
  color: var(--text, #111);
  touch-action: manipulation;
}
.tuplet-option:hover { background: var(--chip-active-bg, #e0f2fe); }
.chip.sn { background: var(--chip-active-bg); color: var(--chip-active-color); border-color: var(--chip-active-border); font-weight: 500; }
.chip.sd { background: #dcfce7; color: #15803d; border-color: #86efac; font-weight: 500; }
.chip.sv { background: #fef9c3; color: #854d0e; border-color: #fde047; font-weight: 500; }

@media (prefers-color-scheme: dark) {
  .chip.sd { background: #14532d; color: #86efac; border-color: #16a34a; }
  .chip.sv { background: #422006; color: #fde047; border-color: #ca8a04; }
}

/* ── Botones de modo (Monodía / 2 voces…) ── */
.mbtn {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text-dim);
  cursor: pointer;
  min-height: 30px;
  touch-action: manipulation;
  transition: background .12s, border-color .12s;
}

.mbtn.on { background: var(--chip-active-bg); color: var(--chip-active-color); border-color: var(--chip-active-border); font-weight: 500; }

/* ── Select ── */
select {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--btn-border);
  background: var(--select-bg);
  color: var(--text);
  cursor: pointer;
  min-height: 30px;
  touch-action: manipulation;
}

input[type="range"] { accent-color: var(--accent); width: 90px; }

.rigorous-toggle { touch-action: manipulation; }

/* ── Pentagrama ── */
.staff-outer {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--staff-bg);
  overflow-x: auto;
  margin-bottom: 0.35rem;
  padding: 4px 0 2px;
  touch-action: pan-x; /* scroll horizontal libre, vertial bloqueado */
  -webkit-overflow-scrolling: touch;
}

.staff-content {
  position: relative;
  display: block;
}

.insert-overlay {
  position: absolute;
  z-index: 2;
  touch-action: none;
  background: transparent;
}

.insert-column,
.insert-pitch-strip {
  position: absolute;
  top: 0;
  height: 100%;
  cursor: crosshair;
}

.insert-column {
  left: 0;
  touch-action: none;
}

.insert-pitch-strip {
  touch-action: none;
  display: none;
}

.insert-overlay[data-pitch-strip="1"] .insert-pitch-strip {
  display: block;
  background: linear-gradient(
    90deg,
    rgba(37, 99, 235, 0.05) 0%,
    rgba(37, 99, 235, 0.1) 100%
  );
}

.insert-overlay[data-pitch-strip="1"] {
  background: transparent;
}

canvas { display: block; cursor: crosshair; user-select: none; touch-action: none; }

/* ── Fila de nudge de semitono (esencial en móvil) ── */
.pitch-nudge-row {
  display: flex;
  gap: 6px;
  margin-bottom: 0.35rem;
}

.pitch-btn {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  min-height: 36px;
  flex: 1;
  max-width: 120px;
  justify-content: center;
}

/* ── Botones de acción ── */
.btnrow {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

button.ab {
  padding: 6px 13px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  touch-action: manipulation;
  transition: background .12s;
}

button.ab:hover { background: #f5f5f5; }
@media (prefers-color-scheme: dark) { button.ab:hover { background: #333; } }
button.ab.play { background: #dcfce7; color: #15803d; border-color: #86efac; }
button.ab.del { color: #dc2626; border-color: #fca5a5; }
button.ab:disabled { opacity: 0.4; cursor: default; }
@media (prefers-color-scheme: dark) {
  button.ab.play { background: #14532d; color: #86efac; border-color: #16a34a; }
}

/* ── Log de feedback ── */
.log {
  background: var(--log-bg);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  min-height: 44px;
  max-height: min(360px, 40vh);
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.7;
  border: 1px solid var(--log-border);
  white-space: pre-line;
  margin-bottom: 0.5rem;
}

.lok  { color: #15803d; }
.lerr { color: #dc2626; }
.linf { color: var(--text-dim); }
.lharm     { color: #6b4c9a; font-weight: 500; }
.lharm-err { color: #7c3aed; font-weight: 500; }
.feedback-block { font-size: 12px; line-height: 1.7; }
@media (prefers-color-scheme: dark) {
  .lok       { color: #86efac; }
  .lerr      { color: #f87171; }
  .lharm     { color: #a78bfa; }
  .lharm-err { color: #c4b5fd; }
}

/* ── Hint ── */
.hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 0.4rem;
  line-height: 1.5;
}

/* ── Modal (atajos) ── */
body.modal-open { overflow: hidden; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
@media (prefers-color-scheme: dark) {
  .modal-backdrop { background: rgba(0, 0, 0, 0.62); }
}

.modal-sheet {
  position: relative;
  z-index: 1;
  width: min(540px, 100%);
  max-height: min(88vh, 680px);
  display: flex;
  flex-direction: column;
  background: var(--app-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.22);
  overflow: hidden;
  animation: modal-in 0.22s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 1rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--log-bg) 0%, var(--app-bg) 100%);
}

.modal-header-text { min-width: 0; }

.modal-header h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  line-height: 1.3;
}

.modal-subtitle {
  margin: 0.25rem 0 0;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
}

.modal-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.modal-close:hover {
  background: var(--log-bg);
  color: var(--text);
}

.modal-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 1.1rem 1.15rem;
  flex: 1;
}

/* ── Contenido atajos (dentro del modal) ── */
.shortcuts-intro {
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.55;
  margin: 0 0 1rem;
  padding: 0.65rem 0.75rem;
  background: var(--log-bg);
  border-radius: 10px;
  border: 1px solid var(--log-border);
}

.shortcuts-group {
  margin-bottom: 0.75rem;
  padding: 0.75rem 0.85rem;
  background: var(--log-bg);
  border: 1px solid var(--log-border);
  border-radius: 10px;
}
.shortcuts-group:last-child { margin-bottom: 0; }

.shortcuts-group h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin: 0 0 0.5rem;
}
@media (prefers-color-scheme: dark) {
  .shortcuts-group h3 { color: #93c5fd; }
}

.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.45;
}
.shortcuts-table td {
  padding: 0.28rem 0;
  vertical-align: top;
  border-top: 1px solid transparent;
}
.shortcuts-table tr + tr td {
  border-top-color: var(--border);
}
.shortcuts-table td:first-child {
  color: var(--text);
  padding-right: 0.85rem;
}
.shortcuts-table td:last-child {
  text-align: right;
  white-space: nowrap;
  color: var(--text-dim);
}

.shortcuts-table kbd,
.shortcuts-intro kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
}

button.ab.shortcuts-btn { flex: 0 1 auto; }

@media (max-width: 640px) {
  .modal-sheet { max-height: 92vh; border-radius: 14px; }
  .shortcuts-table td:last-child { white-space: normal; max-width: 46%; }
}

/* ── Panel lateral (escritorio) ── */
.side-panel {
  --side-width: 300px;
  /* Escala continua con el ancho — sin saltos por JS */
  --rules-font-size: clamp(
    11px,
    calc(11px + (var(--side-width) - 240px) * 0.0076),
    16.5px
  );
  flex-shrink: 0;
  width: var(--side-width);
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  margin-left: 0.65rem;
  border-radius: 12px;
  overflow: hidden;
  position: sticky;
  top: 0.8rem;
  height: calc(100vh - 1.6rem);
  max-height: calc(100vh - 1.6rem);
  box-sizing: border-box;
  background-color: #f6f0e4;
  background-image:
    linear-gradient(90deg, rgba(80, 60, 40, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(80, 60, 40, 0.03) 1px, transparent 1px);
  background-size: 20px 20px;
  border: 1px solid #ddd4c4;
  box-shadow: -3px 0 18px rgba(60, 40, 20, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: width 0.2s ease;
}
@media (prefers-color-scheme: dark) {
  .side-panel {
    background-color: #2a2620;
    background-image:
      linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
      linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    border-color: #3d3830;
    box-shadow: -3px 0 18px rgba(0, 0, 0, 0.35);
  }
}

.side-panel.is-collapsed {
  width: 0 !important;
  min-width: 0;
  margin-left: 0;
  border: none;
  box-shadow: none;
  overflow: visible;
  background: transparent;
}

.side-panel.is-collapsed .side-inner,
.side-panel.is-collapsed .side-resizer,
.side-panel.is-collapsed .side-close {
  visibility: hidden;
  pointer-events: none;
}

.side-resizer {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 7px;
  cursor: col-resize;
  z-index: 3;
  touch-action: none;
}
.side-resizer:hover { background: rgba(37, 99, 235, 0.12); }

.side-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  width: 26px;
  height: 26px;
  border: 1px solid #ccc4b4;
  border-radius: 6px;
  background: rgba(255, 252, 245, 0.9);
  color: #666;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.side-close:hover { background: #fff; color: #333; }

.side-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}

.side-inner-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.55rem 0.65rem 0.65rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.side-block { display: flex; flex-direction: column; min-height: 0; }

.side-block + .side-block {
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px dashed #d0c8b8;
}

.side-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 0.45rem;
  flex-shrink: 0;
}

.side-block-head h3 {
  font-size: 12px;
  font-weight: 700;
  color: #4a3f30;
}
@media (prefers-color-scheme: dark) {
  .side-block-head h3 { color: #e8dcc8; }
}

.side-block-fold {
  width: 24px;
  height: 24px;
  border: 1px solid #ccc4b4;
  border-radius: 5px;
  background: rgba(255, 252, 245, 0.85);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  color: #666;
}
.side-block-fold:hover { background: #fff; }

.side-block-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.side-block-content[hidden] { display: none; }

.side-block-rules { flex: 1; min-height: 0; }

.side-rules-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.side-expand-tab {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5000;
  padding: 14px 10px;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 10px 0 0 10px;
  background: #f6f0e4;
  color: #4a3f30;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: -2px 0 12px rgba(0, 0, 0, 0.1);
  writing-mode: vertical-rl;
}
.side-expand-tab:hover { background: #fff8ee; }

/* ── Botón acoplar / flotar ── */
.float-panel-btn {
  width: 26px;
  height: 26px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.float-panel-btn:hover {
  background: #fff;
  color: #334155;
  border-color: #94a3b8;
}

.dock-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Paneles flotantes (corrección) ── */
.correction-dock.is-floating {
  position: fixed !important;
  z-index: 8400;
  margin: 0 !important;
  display: flex !important;
  flex-direction: column;
  min-height: 0;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.2);
  box-sizing: border-box;
}

.correction-dock.is-floating .correction-dock-head {
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

body.panel-dragging .correction-dock.is-floating .correction-dock-head { cursor: grabbing; }

.correction-dock.is-floating .correction-dock-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.correction-dock.is-floating .correction-card {
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

.correction-dock.is-floating .correction-log {
  max-height: none;
  flex: 1;
  min-height: 0;
}

.float-resize-handle {
  display: none;
}

.is-floating .float-resize-handle {
  display: block;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 5;
  background: linear-gradient(135deg, transparent 52%, rgba(100, 116, 139, 0.38) 52%);
  border-bottom-right-radius: 10px;
}

body.panel-resizing,
body.panel-resizing * {
  cursor: nwse-resize !important;
  user-select: none !important;
}

@media (prefers-color-scheme: dark) {
  .float-panel-btn {
    border-color: #475569;
    background: rgba(40, 44, 52, 0.92);
    color: #94a3b8;
  }
  .float-panel-btn:hover {
    background: #323843;
    color: #e2e8f0;
    border-color: #64748b;
  }
  .is-floating .float-resize-handle {
    background: linear-gradient(135deg, transparent 52%, rgba(148, 163, 184, 0.45) 52%);
  }
}

/* ── Corrección (zona inferior, escritorio) ── */
.correction-dock {
  display: none;
}

@media (min-width: 901px) {
  .correction-dock {
    display: flex;
    flex-direction: column;
    flex: none;
    position: relative;
    margin-top: 0.45rem;
    border: 1px solid #ddd4c4;
    border-radius: 12px;
    overflow: hidden;
    background-color: #f6f0e4;
    background-image:
      linear-gradient(90deg, rgba(80, 60, 40, 0.04) 1px, transparent 1px),
      linear-gradient(rgba(80, 60, 40, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
  }

  .correction-dock-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0.5rem 0.85rem;
    background: rgba(255, 252, 245, 0.65);
    border-bottom: 1px solid #ddd4c4;
    flex-shrink: 0;
  }

  .correction-dock-head h2 {
    font-size: 14px;
    font-weight: 700;
    color: #4a3f30;
  }

  .correction-dock-body {
    padding: 0.75rem 1rem 0.85rem;
  }
  .correction-dock-body[hidden] { display: none; }

  .correction-card {
    display: flex;
    align-items: flex-end;
    gap: 0.85rem;
  }

  .correction-mascot {
    flex-shrink: 0;
    width: 96px;
    max-height: 148px;
    height: auto;
    object-fit: contain;
    object-position: bottom left;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.12));
    pointer-events: none;
    user-select: none;
  }

  .correction-log {
    flex: 1;
    min-width: 0;
    max-height: min(240px, 32vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: rgba(255, 252, 245, 0.88);
    border: 1px solid rgba(120, 100, 70, 0.18);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font-size: 14px;
    line-height: 1.72;
    box-shadow: inset 0 1px 3px rgba(80, 60, 40, 0.06);
  }

  .correction-log .feedback-block { font-size: 14px; line-height: 1.72; }
}

@media (prefers-color-scheme: dark) {
  @media (min-width: 901px) {
    .correction-dock {
      background-color: #2a2620;
      background-image:
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px);
      border-color: #3d3830;
    }
    .correction-dock-head {
      background: rgba(40, 36, 30, 0.8);
      border-color: #3d3830;
    }
    .correction-dock-head h2 { color: #e8dcc8; }
    .correction-log {
      background: rgba(30, 28, 24, 0.82);
      border-color: rgba(255, 255, 255, 0.08);
    }
  }
}

/* ── Reglas (contenido del panel) ── */
.rules-block { margin-bottom: 1rem; }
.rules-block:first-child { margin-top: 0.15rem; }
.rules-block[hidden] { display: none; }

.rules-block.mode-active {
  padding: 0.55rem 0.65rem;
  margin-left: -0.65rem;
  margin-right: -0.65rem;
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.06);
  box-shadow: inset 3px 0 0 var(--accent);
}
@media (prefers-color-scheme: dark) {
  .rules-block.mode-active {
    background: rgba(147, 197, 253, 0.08);
    box-shadow: inset 3px 0 0 #93c5fd;
  }
}

.rules-block h3 {
  font-size: 12px;
  font-weight: 600;
  color: #1d4ed8;
  margin-bottom: 0.35rem;
}
@media (prefers-color-scheme: dark) { .rules-block h3 { color: #93c5fd; } }

.rules-block h4 {
  font-size: 11px;
  font-weight: 600;
  margin: 0.65rem 0 0.25rem;
  color: #334155;
}
@media (prefers-color-scheme: dark) { .rules-block h4 { color: #cbd5e1; } }

.rules-intro {
  font-size: 11px;
  color: #555;
  margin: 0 0 0.4rem;
  line-height: 1.45;
}
@media (prefers-color-scheme: dark) { .rules-intro { color: #aaa; } }

.rules-block li.rules-note { font-style: italic; color: var(--text-dim); }

.rules-block ul {
  list-style: disc;
  padding-left: 1.2rem;
  font-size: 11.5px;
  line-height: 1.55;
  color: #444;
}
@media (prefers-color-scheme: dark) { .rules-block ul { color: #bbb; } }

.rules-block li { margin-bottom: 0.25rem; }

.rules-detection h3 { color: #64748b; }
@media (prefers-color-scheme: dark) { .rules-detection h3 { color: #94a3b8; } }
.rules-detection ul { color: #666; font-style: italic; }
@media (prefers-color-scheme: dark) { .rules-detection ul { color: #999; } }

/* Tipografía de reglas escala con el ancho del panel (escritorio) */
@media (min-width: 901px) {
  .side-panel .side-block-head h3,
  .side-panel .rules-block h3,
  .side-panel .rules-block h4,
  .side-panel .rules-intro,
  .side-panel .rules-block ul {
    transition: font-size 0.18s ease-out;
  }

  body.side-resizing .side-panel .side-block-head h3,
  body.side-resizing .side-panel .rules-block h3,
  body.side-resizing .side-panel .rules-block h4,
  body.side-resizing .side-panel .rules-intro,
  body.side-resizing .side-panel .rules-block ul {
    transition: none;
  }

  .side-panel .side-block-head h3 {
    font-size: calc(var(--rules-font-size) * 1.1);
  }

  .side-panel .rules-block h3 {
    font-size: calc(var(--rules-font-size) * 1.08);
  }

  .side-panel .rules-block h4 {
    font-size: calc(var(--rules-font-size) * 1.02);
  }

  .side-panel .rules-intro,
  .side-panel .rules-block ul {
    font-size: var(--rules-font-size);
    line-height: 1.58;
  }
}

/* ════════════════════════════════
   ESCRITORIO / MÓVIL — panel lateral
   ════════════════════════════════ */

@media (min-width: 901px) {
  .log-mobile { display: none; }

  .side-inner {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
  .side-inner-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .side-block-rules {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .side-rules-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }
}

@media (max-width: 900px) {
  .correction-dock { display: none !important; }

  .app-shell { display: block; min-height: 0; }
  .app-main { display: block; }
  .app { display: block; flex: none; }

  .side-panel {
    position: static;
    width: auto !important;
    margin: 0.75rem 0 0;
    max-height: none;
    border-radius: 10px;
  }

  .side-panel.is-collapsed {
    width: auto !important;
    margin-left: 0;
    border: 1px solid #ddd4c4;
    background-color: #f6f0e4;
  }

  .side-panel.is-collapsed .side-inner {
    visibility: visible;
    pointer-events: auto;
  }

  .side-resizer,
  .side-close,
  .side-expand-tab,
  .float-panel-btn,
  .float-resize-handle { display: none !important; }

  .side-inner {
    max-height: none;
    padding: 0.5rem 0.65rem 0.65rem;
  }

  .side-block-rules { max-height: none; }

  .side-rules-scroll {
    max-height: none;
    overflow-y: visible;
    overscroll-behavior: auto;
  }
}

/* ════════════════════════════════
   RESPONSIVE — MÓVIL
   ════════════════════════════════ */

@media (max-width: 600px) {
  body { padding: 0; }

  .app {
    border-radius: 0;
    padding: 0.8rem 0.75rem;
    box-shadow: none;
    min-height: 100dvh;
  }

  h1 { font-size: 15px; margin-bottom: 0.65rem; }

  /* Chips y botones más grandes para dedo */
  .chip   { min-height: 36px; padding: 6px 11px; font-size: 13px; }
  .mbtn   { min-height: 36px; padding: 6px 12px; font-size: 13px; }
  select  { min-height: 36px; font-size: 13px; }

  /* Tempo range más ancho */
  input[type="range"] { width: 110px; }

  /* Etiqueta "Rigurosa" más corta ya con el HTML */

  /* Staff ocupa todo el ancho */
  .staff-outer {
    border-radius: 8px;
    margin-left: -0.75rem;
    margin-right: -0.75rem;
    border-left: none;
    border-right: none;
    border-radius: 0;
    scroll-behavior: auto;
  }

  /* Scroll horizontal nativo en el pentagrama; la franja de altura sigue capturando el dedo */
  canvas { touch-action: pan-x; }

  .insert-overlay { pointer-events: none; }

  .insert-column {
    touch-action: pan-x;
    pointer-events: auto;
  }

  .insert-pitch-strip {
    touch-action: none;
    pointer-events: auto;
  }

  /* Botones de nudge más grandes y llamativos */
  .pitch-nudge-row { gap: 8px; }
  .pitch-btn {
    flex: 1;
    max-width: none;
    min-height: 44px;
    font-size: 15px;
    border-radius: 10px;
  }

  /* Botones de acción en dos columnas */
  .btnrow { gap: 8px; }
  button.ab {
    flex: 1 1 calc(50% - 4px);
    min-height: 42px;
    font-size: 13px;
    justify-content: center;
  }

  /* Log más compacto */
  .log {
    font-size: 13px;
    max-height: min(280px, 35vh);
  }

  /* Reglas: texto ligeramente más grande */
  .rules-block ul { font-size: 12.5px; }
  .rules-panel h2 { font-size: 15px; }
}

/* Menú contextual del pentagrama */
.ctx-menu {
  position: fixed;
  z-index: 10000;
  min-width: 210px;
  padding: 6px 0;
  background: var(--panel, #fff);
  border: 1px solid var(--border, #d0d4dc);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
}
.ctx-menu.hidden { display: none; }
.ctx-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.ctx-item:hover:not(:disabled):not(.disabled) {
  background: rgba(59, 130, 246, 0.1);
}
.ctx-item:disabled,
.ctx-item.disabled {
  opacity: 0.38;
  cursor: default;
}
.ctx-keys {
  font-size: 11px;
  opacity: 0.55;
  white-space: nowrap;
}
.ctx-sep {
  height: 1px;
  margin: 5px 10px;
  background: var(--border, #d0d4dc);
}

/* Pantallas muy pequeñas (iPhone SE, etc.) */
@media (max-width: 380px) {
  .app { padding: 0.6rem 0.6rem; }
  button.ab { font-size: 12px; min-height: 40px; }
  .chip { padding: 5px 9px; }
}

/* Contenedor de impresión (generado al pulsar PDF) */
.print-score-pages {
  display: none;
}

.print-score-system {
  margin-bottom: 0.6rem;
}

.print-score-system canvas {
  display: block;
  width: 100%;
  height: auto;
}

.print-score-analysis {
  display: none;
}

.print-score-prof {
  display: none;
}

.print-score-analysis-title {
  font: 600 13pt system-ui, sans-serif;
  margin: 0 0 0.5rem;
  color: #222;
}

/* Impresión / PDF: bloques de 4 compases + informe Falk */
@media print {
  @page {
    margin: 12mm 10mm;
  }

  body.print-score {
    background: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body.print-score .app-brand,
  body.print-score .control-deck,
  body.print-score #toolDock,
  body.print-score #sidePanel,
  body.print-score .side-expand-tab,
  body.print-score .side-resizer,
  body.print-score .side-close,
  body.print-score .modal,
  body.print-score .correction-mascot,
  body.print-score .float-panel-btn,
  body.print-score .float-resize-handle,
  body.print-score .staff-outer,
  body.print-score .correction-dock,
  body.print-score .log-mobile {
    display: none !important;
  }

  body.print-score .print-score-pages {
    display: block !important;
  }

  body.print-score .print-score-system {
    page-break-inside: avoid;
    break-inside: avoid;
    margin-bottom: 0.5rem;
  }

  body.print-score .print-score-system canvas {
    max-width: 100% !important;
    height: auto !important;
  }

  body.print-score .print-score-analysis {
    display: block !important;
    page-break-before: auto;
    break-before: auto;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #ccc;
  }

  body.print-score .print-score-analysis .feedback-block {
    font-size: 10pt !important;
    line-height: 1.55 !important;
  }

  body.print-score .print-score-prof {
    display: flex !important;
    flex-direction: row;
    align-items: flex-start;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #ccc;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  body.print-score .print-score-prof-img {
    width: 90px;
    height: auto;
    flex: 0 0 auto;
  }

  body.print-score .print-score-prof-text {
    flex: 1 1 auto;
  }

  body.print-score .print-score-prof-list {
    list-style: none;
    margin: 0.4rem 0 0;
    padding: 0;
  }

  body.print-score .print-score-prof-list li {
    font-size: 10pt;
    line-height: 1.55;
    padding-left: 1em;
    position: relative;
    margin-bottom: 0.25em;
  }

  body.print-score .print-score-prof-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: #666;
  }

  body.print-score .app-shell {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  body.print-score .app-main,
  body.print-score .app {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    padding: 0 !important;
    max-width: none !important;
  }

  body.print-score::before {
    content: 'MusicScope Series — contrapunto dodecafónico (Krenek)';
    display: block;
    font: 600 13pt system-ui, sans-serif;
    color: #222;
    margin-bottom: 0.5rem;
  }
}

/* ── Analyze Modal ─────────────────────────────────────────────────────────── */
.analyze-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.analyze-modal-overlay.visible { opacity: 1; }

.analyze-modal-box {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 1.5rem;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.28);
  padding: 2rem;
  max-width: 760px;
  width: calc(100vw - 2rem);
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(12px);
  transition: transform 0.22s ease;
}
.analyze-modal-overlay.visible .analyze-modal-box {
  transform: translateY(0);
}

@media (prefers-color-scheme: dark) {
  .analyze-modal-box { background: #1e1e2e; color: #d0d0c8; }
}

.analyze-modal-prof {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
}
.analyze-modal-prof-img {
  width: 140px;
  height: auto;
  border-radius: 8px;
  object-fit: contain;
}

.analyze-modal-text {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.analyze-modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  color: #1a1a2e;
}
@media (prefers-color-scheme: dark) {
  .analyze-modal-title { color: #e0e0d8; }
}

.analyze-modal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.analyze-modal-list li {
  font-size: 0.9rem;
  line-height: 1.55;
  padding-left: 1.1em;
  position: relative;
}
.analyze-modal-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: #888;
}

.analyze-modal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.analyze-modal-legend-chip {
  display: inline-block;
  padding: 0.2em 0.7em;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.03em;
}

.analyze-modal-close {
  align-self: flex-end;
  margin-top: 0.5rem;
  padding: 0.45em 1.4em;
  border: none;
  border-radius: 8px;
  background: #1e88e5;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.analyze-modal-close:hover { background: #1565c0; }

@media (max-width: 540px) {
  .analyze-modal-box { flex-direction: column; align-items: center; }
  .analyze-modal-prof-img { width: 100px; }
}
