/**
 * PAPERWEAVE KIDS - Multi-Size Print & PDF Stylesheet
 * Supports A4 (Big Book), A5 (Classic Diary), B5 (Comics), and Square (Scrapbook)
 * Completely eliminates overflow splitting, cutoffs, and margin gaps.
 */

@page {
  margin: 0 !important;
}

@media print {
  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
    box-sizing: border-box !important;
  }

  html, body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    font-size: 10pt;
    -webkit-font-smoothing: antialiased;
  }

  /* Hide UI elements */
  .no-print,
  .preview-toolbar,
  .print-tip-bar,
  .pw-navbar,
  .creation-stepper,
  .kids-stepper,
  .btn,
  .modal,
  .toast-container,
  footer,
  .builder-toolbox,
  .pages-filmstrip {
    display: none !important;
  }

  .book-scroll-stage {
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    gap: 0 !important;
    display: block !important;
    width: 100% !important;
  }

  /* Single-Sheet Page Budgeting (Strict 1 page per sheet) */
  .print-page {
    page-break-before: auto !important;
    page-break-after: always !important;
    page-break-inside: avoid !important;
    break-after: page !important;
    break-inside: avoid !important;
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 auto !important;
    width: 100% !important;
    height: calc(100vh - 1.5mm) !important;
    max-height: calc(100vh - 1.5mm) !important;
  }

  .print-page:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  /* --- SIZE: A4 (210mm x 297mm) --- */
  .book-size-A4 .print-page {
    max-width: 210mm !important;
    padding: 12mm 14mm !important;
  }

  /* --- SIZE: A5 (148mm x 210mm) --- */
  .book-size-A5 .print-page {
    max-width: 148mm !important;
    padding: 10mm 12mm !important;
  }

  /* --- SIZE: B5 (176mm x 250mm) --- */
  .book-size-B5 .print-page {
    max-width: 176mm !important;
    padding: 11mm 13mm !important;
  }

  /* --- SIZE: SQUARE (200mm x 200mm) --- */
  .book-size-Square .print-page {
    max-width: 200mm !important;
    padding: 12mm 12mm !important;
  }

  /* Cover Pages Full-Bleed Fitting */
  .book-cover {
    box-sizing: border-box !important;
    padding: 10mm 12mm !important;
  }

  .cover-inner-frame {
    height: 100% !important;
    max-height: 100% !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    align-items: center !important;
    border: 3px solid rgba(0, 0, 0, 0.25) !important;
    border-radius: 12px !important;
    padding: 8mm 6mm !important;
    background: rgba(255, 255, 255, 0.18) !important;
    overflow: hidden !important;
  }

  .cover-center-content {
    max-height: 70% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
  }

  /* Prevent uploaded cover photo from pushing bottom author out */
  .book-cover img {
    max-height: 110px !important;
    max-width: 85% !important;
    object-fit: contain !important;
    margin: 0 auto !important;
  }

  .cover-title {
    font-size: 24pt !important;
    line-height: 1.2 !important;
    margin: 6px 0 !important;
  }

  .cover-subtitle {
    font-size: 12pt !important;
    margin: 3px 0 !important;
  }

  .cover-author {
    font-size: 11pt !important;
    padding: 4px 16px !important;
    display: inline-block !important;
    margin: 0 auto !important;
    border: 2px solid #2b2b2b !important;
    background: #ffffff !important;
    color: #2b2b2b !important;
  }

  /* Cartoon Color Themes Exact Print Reproduction */
  .theme-candy-pink { background-color: #ff758f !important; color: #ffffff !important; }
  .theme-sunny-yellow { background-color: #ffca3a !important; color: #2b2b2b !important; }
  .theme-sky-blue { background-color: #4cc9f0 !important; color: #ffffff !important; }
  .theme-mint-magic { background-color: #06d6a0 !important; color: #ffffff !important; }
  .theme-violet-galaxy { background-color: #7209b7 !important; color: #ffffff !important; }
  .theme-comic-white { background-color: #ffffff !important; color: #2b2b2b !important; }

  /* Inner Pages Content */
  .page-header-row {
    margin-bottom: 6mm !important;
    padding-bottom: 3mm !important;
    border-bottom: 2px solid #333333 !important;
  }

  .page-body-content {
    flex-grow: 1 !important;
    overflow: hidden !important;
  }

  /* Photos & Polaroids in Print */
  .polaroid-frame {
    background-color: #ffffff !important;
    border: 2px solid #2b2b2b !important;
    padding: 6px 6px 14px 6px !important;
    transform: none !important;
    page-break-inside: avoid !important;
  }

  .polaroid-img-placeholder {
    border: 1.5px dashed #888888 !important;
    background-color: #f7f3e8 !important;
  }

  /* Comic Panels in Print */
  .comic-panel-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  .comic-box {
    border: 2px solid #2b2b2b !important;
    background-color: #ffffff !important;
    min-height: 80px !important;
  }

  .speech-bubble {
    border: 1.5px solid #2b2b2b !important;
    background-color: #ffffff !important;
  }

  /* Ruled lines in print */
  .ruled-lines-container {
    gap: 8mm !important;
  }

  .ruled-line {
    background-color: #b5ac9e !important;
    height: 1px !important;
  }
}
