/*
  Print styles for ukulelechords / ChordPress
  - Separate file to avoid touching screen styles.
  - Printing respects the user's toggles (Show diagrams / Chords above).
*/

/* ------------------------------------------------------------------
   Chrome print-preview hardening
   ------------------------------------------------------------------
   In Chrome/Chromium, print preview can sometimes snapshot the page
   before text has been painted (especially when themes use modern
   performance CSS like content-visibility/contain, or when animations
   temporarily set opacity/transform).

   We only apply these overrides on dedicated print-view pages
   (body.cpress-print-view) so regular pages remain untouched.
*/

/* Ensure the print-view page actually renders all content on screen
   (prevents Chrome treating it as "skippable"/not-yet-rendered). */
body.cpress-print-view,
body.cpress-print-view .wp-site-blocks,
body.cpress-print-view main,
body.cpress-print-view article,
body.cpress-print-view .entry-content,
body.cpress-print-view .cpress,
body.cpress-print-view .cpress * {
  content-visibility: visible !important;
  contain: none !important;
}

/* Stop any fade/slide-in effects affecting the first print snapshot. */
body.cpress-print-view * {
  animation: none !important;
  transition: none !important;
}
/* ------------------------------------------------------------
   Print preview (on-screen): hide mobile top bar on desktop
   ------------------------------------------------------------ */
@media screen and (min-width: 769px){
  body.cpress-print-view .cpress-mobile-topbar,
  body.cpress-print-view .cpress-mobile-bar,
  body.cpress-print-view .cpress-mobile-backdrop{
    display:none !important;
  }
  body.cpress-print-view{
    padding-top: 0 !important;
  }
}


/* Single-song print preview: let the ChordPress block use the full paper width
   so its left edge aligns with the print title/meta block above. */
body.cpress-print-view.single-song .cpress-print-sheet > .cpress,
body.cpress-print-view.single-song .cpress-print-sheet .cpress{
  max-width: none !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}


@page { margin: 12mm; }

@media print {
  /* Respect Meta Info toggle in print */
  body.cpress-hide-meta .cpress-print-meta,
  body.cpress-hide-meta .cpress-meta,
  body.cpress-hide-meta .cpress-meta-line,
  body.cpress-hide-meta .cpress-meta-key,
  body.cpress-hide-meta .cpress-meta-difficulty,
  body.cpress-hide-meta .cpress-meta-cap,
  body.cpress-hide-meta .cpress-meta-bpm,
  body.cpress-hide-meta .cpress-meta-artist,
  body.cpress-hide-meta .cpress-meta-album,
  body.cpress-hide-meta .cpress-meta-year{
    display: none !important;
  }



  html, body { background: #fff !important; }

  /* Print must be robust in Chrome: use system fonts to avoid FOIT
     (invisible text while webfonts load) and force fully-opaque text. */
  body.cpress-print-view {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif !important;
    color: #000 !important;
    -webkit-text-size-adjust: 100%;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body.cpress-print-view * {
    color: #000 !important;
    -webkit-text-fill-color: #000 !important;
    text-shadow: none !important;
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    animation: none !important;
    transition: none !important;
    content-visibility: visible !important;
    contain: none !important;
  }

  /* -------------------------------------------
     Block theme: hide site header/footer + admin bar
  -------------------------------------------- */
  #wpadminbar,
  header.wp-block-template-part,
  footer.wp-block-template-part,
  .wp-site-blocks > header,
  .wp-site-blocks > footer {
    display: none !important;
  }

  /* Remove extra padding/margins on wrappers (helps prevent blank last pages) */
  body, .wp-site-blocks, main, article, .entry-content {
    margin-top: 0 !important;
    padding-top: 0 !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }

  .wp-site-blocks {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
  }

  /* -------------------------------------------
     Hide navigation / chips we don't want in print
  -------------------------------------------- */

  /* Back-to-library pill (your plugin) */
  .cpress-back-chip-wrap,
  .cpress-back-chip,
  .cpress-back-link {
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Catch-all: hide any link pointing back to the library index */
  .cpress a[href*="/ukulelechords"] {
    display: none !important;
  }

  /* If the dot is injected via ::before, kill it */
  .cpress-back-chip-wrap::before,
  .cpress-back-chip::before,
  .cpress-back-link::before {
    content: "" !important;
    display: none !important;
  }

  /* Theme next/prev navigation below the post */
  .wp-block-post-navigation,
  .post-navigation,
  .navigation.post-navigation,
  .nav-links,
  .wp-block-post-navigation-link {
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* -------------------------------------------
     Stop forced page breaks / phantom blank pages
  -------------------------------------------- */

  /* Remove any forced breaks that might be on blocks after content */
  .wp-site-blocks * {
    break-before: auto !important;
    break-after: auto !important;
    break-inside: auto !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
    page-break-inside: auto !important;
  }

  /* Make sure the last visible thing doesn't carry a big bottom margin */
  .wp-site-blocks > :last-child,
  main > :last-child,
  article > :last-child,
  .entry-content > :last-child,
  .cpress > :last-child {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }

  /* -------------------------------------------
     Links: print like plain text
  -------------------------------------------- */
  .cpress a,
  .taxonomy-artist a,
  .taxonomy-decade a {
    color: inherit !important;
    text-decoration: none !important;
  }

  /* -------------------------------------------
     Core typography for print
  -------------------------------------------- */
  .cpress {
    color: #000 !important;
    /* IMPORTANT:
       Do not hard-set a fixed print font-size here.
       The Print Preview sidebar controls set the overall scale on the
       print "sheet" container (via --cpress-print-scale), and we want
       the content (lyrics + chords) to follow that in the actual Print/PDF.
       Leaving font-size to inherit ensures it matches the user's setting.
    */
    font-size: inherit;
    line-height: 1.35;
    max-width: none !important;

    /* Diagrams: default to a compact size, but prefer the user's chosen
       Print Preview value when present. */
    --cpress-diagram: var(--cpress-print-diagram, 72px);
    --cpress-gap: var(--cpress-print-gap, 8px);
  }
  body .cpress-section{
    margin-top: 12pt;
    margin-bottom: 6pt;
    break-after: avoid;
    page-break-after: avoid;
  }

  /* When section labels are hidden, keep a section break but tighter */
  body.cpress-hide-sections .cpress-section{
    visibility:hidden !important;
    /* Keep a subtle section break without wasting vertical space */
    min-height: 7pt;
    margin-top: 7pt;
    margin-bottom: 3pt;
  }
  /* Avoid awkward page breaks in the song body */
  .cpress-section,
  .cpress-line,
  .cpress-diagrams,
  .cpress-diagram {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* -------------------------------------------
     Toolbar: hide controls, keep only key selector line
  -------------------------------------------- */
  .cpress-toolbar { margin: 0 0 10pt !important; }

  .cpress-toolbar .cpress-spell,
  .cpress-toolbar .cpress-btnrow,
  .cpress-toolbar .cpress-toggles {
    display: none !important;
  }
	
  /* Hide all on-screen print tools from the physical/PDF printout */
  .cpress-print-toolbar,
  .cpress-print-panel,
  /* Current Print Preview UI (sidebar + mobile bars) */
  .cpress-print-sidebar,
  #cpressPrintSidebar,
  .cpress-side-shell,
  .cpress-side-box,
  .cpress-side-actions,
  .cpress-mobile-topbar,
  .cpress-mobile-bar,
  .cpress-mobile-backdrop,
  .cpress-mobile-settings-btn,
  .cpress-mobile-actions,
  .cpress-mobile-action,
  .cpress-mobile-action-btn,
  #cpressMobileSettingsToggle,
  .cpress-print-gate,
  .cpress-membership-cta{
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* When printing, the content area should use the full page width */
  body.cpress-print-view .cpress-print-main{
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
  }
  body.cpress-print-view .cpress-print-sheet{
    box-shadow: none !important;
    border: 0 !important;
  }

  /* (Optional) make sure membership CTA never sneaks into print */
  .cpress-membership-cta{
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .cpress-toolbar .cpress-key-select {
    background: transparent !important;
    border: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    font-weight: 700;
  }

  /* -------------------------------------------
     Chords: remove chip styling for print
  -------------------------------------------- */
  .cpress-chord {
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    color: #000 !important;
    font-weight: 700 !important;
  }

  /* Inline view: show bracketed chords like [C] */
  .cpress-lyrics-inline .cpress-chord::before { content: "["; }
  .cpress-lyrics-inline .cpress-chord::after  { content: "]"; }

  /* Above view: keep chords compact and readable */
  .cpress-lyrics-above .cpress-chord {
    font-size: 10pt;
    line-height: 1.1;
    font-weight: 700;
  }

  /* -------------------------------------------
     Diagrams: compact and wrap nicely
     (Still respects the user's "Show diagrams" toggle)
  -------------------------------------------- */
  .cpress-diagrams { max-width: none !important; }

}

@media print {
  /* Keep Two Columns ON when printing/saving PDF */
  body.cpress-two-col .cpress-lyrics-inline,
  body.cpress-two-col .cpress-lyrics-above{
    column-count: 2 !important;
    column-gap: 2rem !important;
    column-fill: auto !important; /* fill left-to-right */
    -webkit-column-count: 2 !important;
    -webkit-column-gap: 2rem !important;
    -webkit-column-fill: auto !important;

    /* Prevent margin-collapsing on the first item in a column
       (can make column 2 look "higher" than column 1). */
    padding-top: 0.01px !important;
  }

  /* Column-top alignment: remove top margins that can push the first item
     in a column down. Spacing comes from the section-block bottom margin. */
  body.cpress-two-col .cpress-section{ margin-top: 0 !important; }
  body.cpress-two-col .cpress-section-block{ margin: 0 0 12pt 0 !important; }
  body.cpress-two-col .cpress-section-block:last-child{ margin-bottom: 0 !important; }

  /* Keep a whole section together (heading + its lines) */
  body.cpress-two-col .cpress-section-block{
    -webkit-column-break-inside: avoid;
    break-inside: avoid-column;
    page-break-inside: avoid;
  }

  /* Extra safety: avoid breaking individual elements too */
  body.cpress-two-col .cpress-section,
  body.cpress-two-col .cpress-line,
  body.cpress-two-col .cpress-diagrams{
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
