/* Print styles for A4 sheet music */
@media print {
  @page {
    size: A4 portrait;
    margin: 1.5cm;
  }
  
  body {
    margin: 0;
    padding: 0;
    font-family: "Times New Roman", serif;
    line-height: 1.2;
    color: black;
    background: white;
  }
  
  #sheet-music {
    page-break-inside: avoid;
    margin: 0;
    padding: 0;
    orphans: 3;
    widows: 3;
  }
  
  /* Force better page break control */
  .abcjs-container {
    page-break-inside: avoid;
    orphans: 3;
    widows: 3;
  }
  
  /* Ensure ABCJS wrapper elements don't break */
  .abcjs-wrapper,
  .abcjs-wrapper * {
    page-break-inside: avoid !important;
  }
  
  /* Ensure ABCJS renders properly for print */
  #sheet-music svg {
    max-width: 100% !important;
    height: auto !important;
    page-break-inside: avoid;
    page-break-before: auto;
    page-break-after: auto;
  }
  
  /* Hide any non-essential elements during printing */
  .no-print {
    display: none !important;
  }
  
  /* Ensure clean typography for print */
  * {
    -webkit-print-color-adjust: exact;
    color-adjust: exact;
  }
  
  /* Prevent orphaned elements */
  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
  }
  
  /* Ensure proper spacing for sheet music */
  .abcjs-staff {
    page-break-inside: avoid;
    page-break-before: auto;
    page-break-after: auto;
    margin-bottom: 1em;
  }
  
  /* Prevent staff splitting - more specific selectors */
  .abcjs-staff svg,
  .abcjs-staff g,
  .abcjs-staff path,
  .abcjs-staff line,
  .abcjs-staff text {
    page-break-inside: avoid !important;
  }
  
  /* Group related musical elements together */
  .abcjs-voice {
    page-break-inside: avoid;
    page-break-before: auto;
    page-break-after: auto;
  }
  
  /* Ensure measure groups don't split */
  .abcjs-measure {
    page-break-inside: avoid !important;
  }
  
  /* Add some spacing to help with page breaks */
  .abcjs-staff + .abcjs-staff {
    margin-top: 2em;
  }
  
  /* Force better spacing between major sections */
  .abcjs-staff:not(:last-child) {
    margin-bottom: 3em;
  }
  
  /* Ensure proper page margins for staff content */
  .abcjs-staff {
    margin-left: 0;
    margin-right: 0;
    padding-left: 0;
    padding-right: 0;
  }
  
  /* Comprehensive staff protection - prevent ANY staff element from breaking */
  .abcjs-staff,
  .abcjs-staff *,
  .abcjs-staff svg,
  .abcjs-staff g,
  .abcjs-staff path,
  .abcjs-staff line,
  .abcjs-staff text,
  .abcjs-staff rect,
  .abcjs-staff circle,
  .abcjs-staff polygon,
  .abcjs-staff polyline,
  .abcjs-staff ellipse {
    page-break-inside: avoid !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
    break-inside: avoid !important;
    break-before: auto !important;
    break-after: auto !important;
  }
  
  /* Force ALL SVG elements to avoid page breaks */
  svg,
  svg *,
  svg g,
  svg path,
  svg line,
  svg text,
  svg rect,
  svg circle,
  svg polygon,
  svg polyline,
  svg ellipse {
    page-break-inside: avoid !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
    break-inside: avoid !important;
    break-before: auto !important;
    break-after: auto !important;
  }
  
  /* Target ABCJS specific classes more aggressively */
  [class*="abcjs"],
  [class*="abcjs"] *,
  [class*="staff"],
  [class*="staff"] *,
  [class*="measure"],
  [class*="measure"] *,
  [class*="voice"],
  [class*="voice"] * {
    page-break-inside: avoid !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
  }
  
  /* Force staff groups to stay together */
  .abcjs-staff-group {
    page-break-inside: avoid !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
  }
  
  /* Ensure the entire sheet music container doesn't break */
  #sheet-music,
  #sheet-music * {
    page-break-inside: avoid !important;
  }
  
  /* Force minimum height to prevent breaking */
  .abcjs-staff {
    min-height: 100px !important;
    display: block !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  
  /* Ensure staff containers don't break */
  .abcjs-staff svg {
    display: block !important;
    min-height: 80px !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  
  /* Force the entire ABCJS output to be treated as one unit */
  #sheet-music {
    display: flex !important;
    flex-direction: column !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    orphans: 10 !important;
    widows: 10 !important;
  }
  
  /* Ensure each staff section is treated as a block */
  .abcjs-staff {
    flex-shrink: 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    orphans: 5 !important;
    widows: 5 !important;
  }
  
  /* Force staff elements to be treated as atomic units */
  .abcjs-staff svg {
    display: inline-block !important;
    vertical-align: top !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  
  /* Prevent any staff element from being orphaned */
  .abcjs-staff:first-child {
    page-break-before: avoid !important;
    break-before: avoid !important;
  }
  
  .abcjs-staff:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }
  
  /* Protect ABCJS internal structure */
  .abcjs-staff svg,
  .abcjs-staff svg *,
  .abcjs-staff g,
  .abcjs-staff g * {
    page-break-inside: avoid !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
  }
  
  /* Specific protection for staff lines */
  .abcjs-staff svg g[data-name*="staff"],
  .abcjs-staff svg g[data-name*="measure"],
  .abcjs-staff svg g[data-name*="voice"] {
    page-break-inside: avoid !important;
  }
  
  /* Prevent orphaned staff elements */
  .abcjs-staff:first-of-type {
    page-break-before: avoid !important;
  }
  
  .abcjs-staff:last-of-type {
    page-break-after: avoid !important;
  }
  
  /* Print-friendly staff class */
  .print-friendly-staff,
  .print-friendly-staff * {
    page-break-inside: avoid !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
  }
  
  /* Force inline styles to override any conflicting styles */
  [style*="page-break-inside: avoid"] {
    page-break-inside: avoid !important;
  }
}

/* Screen styles */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  margin: 0;
  padding: 20px;
  background-color: #f5f5f5;
  line-height: 1.6;
  color: #333;
  min-height: 100vh;
}

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #000;
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 1000;
}

.skip-link:focus {
  top: 6px;
}

/* Main container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2rem;
}

h1 {
  color: #333;
  margin: 0 0 1rem 0;
  font-size: 2.5rem;
  font-weight: 700;
}

/* Description for screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Main content area */
main {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  overflow: hidden;
}

#sheet-music {
  padding: 2rem;
  margin: 0;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Loading state */
.loading {
  text-align: center;
  padding: 2rem;
  color: #666;
}

/* Error state */
.error {
  background: #fee;
  border: 1px solid #fcc;
  border-radius: 8px;
  padding: 1rem;
  margin: 1rem 0;
  color: #c33;
}

/* Responsive design */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }
  
  .container {
    padding: 0 10px;
  }
  
  h1 {
    font-size: 2rem;
  }
  
  #sheet-music {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.5rem;
  }
  
  #sheet-music {
    padding: 0.5rem;
  }
}

/* Focus styles for accessibility */
*:focus {
  outline: 2px solid #007acc;
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  body {
    background-color: #000;
    color: #fff;
  }
  
  main {
    background: #fff;
    color: #000;
    border: 2px solid #000;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
} 