@media print {
  /* Hide elements not meant for printing */
  .calculator,
  .disclaimer,
  .logo-container,
  #card-info-container,
  #calculate-btn,
  .print-button,
  .print-instructions,
  #card-info-display,
  .card-info-display,
  .card-info-item,
  .card-info,
  h3,
  .card-info h3,
  [class*="card-info"],
  [id*="card-info"],
  /* Additional merchant information selectors */
  [class*="merchant"],
  [id*="merchant"],
  .merchant-info,
  #merchant-info,
  [class*="phone"],
  [id*="phone"],
  [class*="tel"],
  [id*="tel"] {
    display: none !important;
  }
  
  /* Optimize page settings for A4 paper */
  @page {
    margin: 1cm;
    size: A4 portrait;
  }
  
  /* Adjust font size for print */
  body {
    color: #000;
    background: #fff;
    font-size: 14pt;
    line-height: 1.6;
  }
  
  /* Container adjustments */
  .container {
    width: 100%;
    max-width: 100%;
    padding: 0;
    margin: 0;
  }
  
  /* Main title */
  h1 {
    font-size: 18pt;
    margin: 0 0 8px 0;
    padding: 0;
  }
  
  /* Show simulation conditions section for printing even if it's hidden on screen */
  .simulation-conditions {
    display: block !important;
    width: 100%;
    margin: 0;
    padding: 3px;
    margin-bottom: 5px;
  }
  
  /* Compact the simulation conditions heading */
  .simulation-conditions h2 {
    font-size: 12pt;
    margin: 0 0 3px 0;
    padding: 0;
  }
  
  /* Style condition items to match result items */
  .condition-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
    border-bottom: 1px solid #eee;
    padding-bottom: 2px;
  }
  
  /* Show results section for printing even if it's hidden on screen */
  .results {
    display: block !important;
    width: 100%;
    margin: 0;
    padding: 3px;
  }
  
  /* Optimize table for A4 paper */
  .payment-schedule {
    width: 100%;
    page-break-inside: avoid;
    margin-top: 5px;
  }
  
  /* Add page title at the top */
  .results::before {
    content: "クレジットカード分割払いシュミレーション結果";
    display: block;
    font-size: 16pt;
    font-weight: bold;
    text-align: center;
    margin-bottom: 8px;
  }
  
  /* Compact headings */
  h2 {
    font-size: 12pt;
    margin: 5px 0 3px 0;
    page-break-after: avoid;
  }
  
  /* Result items styling with increased spacing */
  .result-item {
    margin-bottom: 5px;
    padding-bottom: 5px;
  }
  
  /* Format table for better print layout */
  .payment-schedule table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13pt;
    margin-bottom: 0;
  }
  
  .payment-schedule th,
  .payment-schedule td {
    border: 1px solid #ddd;
    padding: 5px 8px;
    text-align: center;
  }
  
  /* For 12 or fewer payments, keep table on one page */
  .payment-schedule.few-payments table {
    page-break-inside: avoid;
  }
  
  /* For 13+ payments, allow page breaks between rows */
  .payment-schedule.many-payments table {
    page-break-inside: auto;
  }
  
  /* Force page breaks after specific rows */
  .payment-schedule tr.page-break-after {
    page-break-after: always;
  }
  
  /* Ensure rows don't break across pages */
  .payment-schedule table tr {
    page-break-inside: avoid;
  }
  
  /* Add disclaimer text at the bottom - more compact */
  .payment-schedule::after {
    content: "※支払回数、金額はあくまでも参考数値です。実際とは異なる場合があります。";
    display: block;
    font-size: 7pt;
    text-align: left;
    margin-top: 5px;
  }
  
  /* Add simulation date at the bottom - more compact */
  .results::after {
    content: "印刷日: " attr(data-print-date);
    display: block;
    font-size: 7pt;
    text-align: right;
    margin-top: 5px;
  }
}
