/* Load after checkout.css and book-sample.css. Mobile presentation only. */
@media (max-width: 760px) {
  .checkout-modal,
  .book-sample-modal {
    --mrc-height: calc(100vh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    width: calc(100% - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    max-width: none;
    max-height: var(--mrc-height);
    inset: calc(8px + env(safe-area-inset-top, 0px)) env(safe-area-inset-right, 0px) calc(8px + env(safe-area-inset-bottom, 0px)) env(safe-area-inset-left, 0px);
    margin: auto;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-block: 64px 24px;
  }

  @supports (height: 100dvh) {
    .checkout-modal,
    .book-sample-modal {
      --mrc-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }
  }

  /* Shared grid cell keeps the close control visible without taking page width. */
  .checkout-modal[open],
  .book-sample-modal[open] {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
  }

  .checkout-modal #modal-content,
  .book-sample-modal #modal-content {
    grid-area: 1 / 1;
    min-width: 0;
  }

  .checkout-modal > .close,
  .book-sample-modal > .close {
    grid-area: 1 / 1;
    position: sticky;
    top: 8px;
    right: auto;
    align-self: start;
    justify-self: end;
    z-index: 10;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    margin: 8px 8px 0 0;
    padding: 0;
    border: 1px solid #d8d1bd;
    border-radius: 50%;
    background: #fffdf6;
    font-size: 30px;
    line-height: 1;
  }

  .checkout-modal button,
  .checkout-modal summary,
  .book-sample-modal button {
    touch-action: manipulation;
  }

  /* The checkout retains its state, input names and native validation. */
  .checkout-modal .co-preview {
    min-height: 60px;
    padding: 16px 64px 16px 16px;
    font-size: 10px;
    line-height: 1.6;
    letter-spacing: .05em;
  }

  .checkout-modal .co-layout {
    display: flex;
    flex-direction: column;
  }

  .checkout-modal .co-summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0 12px;
    padding: 18px 16px;
    border: 0;
    border-bottom: 1px solid #dedaca;
  }

  .checkout-modal .co-summary > .co-kicker,
  .checkout-modal .co-side-note,
  .checkout-modal .co-summary-note,
  .checkout-modal .co-receipt > div:not(.co-total) {
    display: none !important;
  }

  .checkout-modal .co-book { gap: 12px; min-width: 0; }
  .checkout-modal .co-book img { width: 48px; flex-shrink: 0; }
  .checkout-modal .co-book h3 { font-size: 14px; line-height: 1.35; margin-bottom: 4px; }
  .checkout-modal .co-book h3 br { display: none; }
  .checkout-modal .co-book span { font-size: 12px; }
  .checkout-modal .co-book b { display: none; }
  .checkout-modal .co-receipt { border: 0; padding: 0; align-self: center; }
  .checkout-modal .co-receipt .co-total { display: block; border: 0; padding: 0; margin: 0; text-align: right; font-size: 12px; }
  .checkout-modal .co-total strong { display: block; margin-top: 4px; font-size: 22px; white-space: nowrap; }
  .checkout-modal .co-delivery { grid-column: 1 / -1; grid-row: 2; display: flex; flex-wrap: wrap; gap: 10px 16px; margin: 16px 0 0; }
  .checkout-modal .co-delivery li { align-items: center; gap: 7px; }
  .checkout-modal .co-delivery li > span { width: 22px; height: 22px; font-size: 15px; }
  .checkout-modal .co-delivery b { font-size: 12px; }
  .checkout-modal .co-delivery small { display: none; }
  .checkout-modal .co-main { padding: 22px 16px 26px; }

  .checkout-modal .co-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 24px; }
  .checkout-modal .co-steps button { min-width: 0; min-height: 60px; padding: 5px 2px; flex-direction: column; justify-content: center; gap: 6px; font-size: 12px; line-height: 1.3; }
  .checkout-modal .co-steps span { width: 25px; height: 25px; flex-shrink: 0; }
  .checkout-modal .co-heading { font-size: clamp(29px, 7.8vw, 36px); line-height: 1.12; overflow-wrap: anywhere; }
  .checkout-modal .co-intro { font-size: 15px; line-height: 1.65; margin-bottom: 22px; }
  .checkout-modal .co-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
  .checkout-modal .co-field { font-size: 13px; line-height: 1.45; gap: 7px; }
  .checkout-modal .co-field input,
  .checkout-modal .co-field select { width: 100%; max-width: 100%; min-height: 48px; height: 48px; padding: 11px 12px; font-size: 16px; line-height: 1.4; scroll-margin-block: 72px 24px; }
  .checkout-modal .co-field small,
  .checkout-modal .co-address-hint,
  .checkout-modal .co-address-help,
  .checkout-modal .co-small { font-size: 12px; line-height: 1.65; color: #686452; }
  .checkout-modal .co-phone-prompt { font-size: 10px; line-height: 1.6; }
  .checkout-modal .co-check { min-height: 44px; padding-block: 4px; gap: 10px; font-size: 13px; line-height: 1.6; }
  .checkout-modal .co-check small { font-size: 12px; line-height: 1.6; }
  .checkout-modal .co-check input,
  .checkout-modal .co-bump > input { width: 20px; height: 20px; margin-top: 3px; }
  .checkout-modal .co-check > span { min-width: 0; overflow-wrap: anywhere; }
  .checkout-modal .co-error { font-size: 13px !important; line-height: 1.6; }

  .checkout-modal .co-next,
  .checkout-modal .co-actions .co-next { min-width: 0; min-height: 52px; padding: 14px; font-size: 14px; line-height: 1.4; text-align: left; gap: 10px; }
  .checkout-modal .co-next > span { flex-shrink: 0; }
  .checkout-modal .co-back,
  .checkout-modal .co-actions .co-back { min-height: 44px; padding: 10px 3px; font-size: 13px; line-height: 1.5; }
  .checkout-modal .co-actions { gap: 12px; }
  .checkout-modal .co-test-data,
  .checkout-modal .co-manual { min-height: 44px; padding: 12px 4px; font-size: 12px; line-height: 1.5; }
  .checkout-modal .co-suggestions button { min-height: 60px; gap: 10px; padding: 12px; }
  .checkout-modal .co-suggestions button > span:nth-child(2) { min-width: 0; flex: 1; overflow-wrap: anywhere; }
  .checkout-modal .co-suggestions b { font-size: 14px; }
  .checkout-modal .co-suggestions small { font-size: 12px; line-height: 1.5; }

  .checkout-modal .co-bump { padding: 16px 12px; gap: 10px; }
  .checkout-modal .co-bump-kicker { font-size: 10px; line-height: 1.6; }
  .checkout-modal .co-bump-title { font-size: 19px; }
  .checkout-modal .co-bump-description { font-size: 14px; line-height: 1.6; }
  .checkout-modal .co-bump-grid { grid-template-columns: 60px minmax(0, 1fr); gap: 10px; }
  .checkout-modal .co-bump-grid img { width: 60px; }
  .checkout-modal .co-bump-grid > span > span { font-size: 12px; line-height: 1.65; }
  .checkout-modal .co-bump-grid strong { font-size: 14px; }
  .checkout-modal .co-review { font-size: 13px; line-height: 1.65; padding: 12px; }
  .checkout-modal .co-review > span { min-width: 0; overflow-wrap: anywhere; }
  .checkout-modal .co-review button { flex-shrink: 0; min-width: 44px; min-height: 44px; font-size: 12px; }
  .checkout-modal .co-payment legend { font-size: 14px; }
  .checkout-modal .co-pay-options { gap: 6px; }
  .checkout-modal .co-pay-options label { min-width: 0; }
  .checkout-modal .co-pay-options span { display: flex; justify-content: center; align-items: center; min-height: 48px; padding: 10px 5px; font-size: 13px; line-height: 1.3; }
  .checkout-modal .co-card-demo > span,
  .checkout-modal .co-card-demo > div,
  .checkout-modal .co-card-demo small,
  .checkout-modal .co-wallet-demo small { font-size: 12px; line-height: 1.6; }
  .checkout-modal .co-card-demo b { font-size: 15px; overflow-wrap: anywhere; }
  .checkout-modal .co-card-bottom { justify-content: space-between; gap: 16px; }
  .checkout-modal .co-wallet-demo p { font-size: 14px; }
  .checkout-modal .co-legal,
  .checkout-modal .co-legal p { font-size: 12px; line-height: 1.65; }
  .checkout-modal .co-legal summary { min-height: 44px; padding-block: 10px; }
  .checkout-modal .co-final-total { gap: 12px; font-size: 15px; }
  .checkout-modal .co-final-total strong { white-space: nowrap; }
  .checkout-modal .co-pay-button { min-height: 56px; max-width: 100%; padding: 14px; flex-wrap: wrap; gap: 8px 12px; font-size: 15px; line-height: 1.45; text-align: left; }
  .checkout-modal .co-pay-button span { font-size: 16px; }
  .checkout-modal .co-test-note { font-size: 12px; line-height: 1.6; }
  .checkout-modal .co-complete { padding: 30px 18px; }
  .checkout-modal .co-complete-note { font-size: 14px; overflow-wrap: anywhere; }

  /* The full-width page remains the original image and opens the existing zoom. */
  .book-sample-modal .bs-reader { padding: 22px 14px 18px; }
  .book-sample-modal .bs-header { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding-right: 0; }
  .book-sample-modal .bs-header > div { padding-right: 48px; min-width: 0; }
  .book-sample-modal .bs-heading { font-size: clamp(28px, 7.5vw, 35px); }
  .book-sample-modal .bs-eyebrow { font-size: 10px; }
  .book-sample-modal .bs-header p { max-width: 100%; font-size: 13px !important; line-height: 1.6; }
  .book-sample-modal .bs-sound { justify-self: start; min-height: 44px; margin-top: 0; padding: 10px 13px; gap: 8px; }
  .book-sample-modal .bs-sound span { font-size: 12px; }
  .book-sample-modal .bs-stage { padding: 0; }
  .book-sample-modal .bs-edge { display: none; }
  .book-sample-modal .bs-book.bs-is-single { width: min(100%, 420px); height: auto; aspect-ratio: 2 / 3; }
  .book-sample-modal .bs-is-single .bs-page { height: auto; aspect-ratio: 2 / 3; }
  .book-sample-modal .bs-book.bs-is-single.bs-is-overview { width: 100%; max-width: 520px; aspect-ratio: auto; }
  .book-sample-modal .bs-is-overview .bs-overview-toc { padding: 20px 16px; overflow: visible; }
  .book-sample-modal .bs-is-overview .bs-toc-intro { font-size: 12px !important; line-height: 1.5; }
  .book-sample-modal .bs-is-overview .bs-overview-toc li { gap: 8px; padding-block: 8px; font-size: 14px; line-height: 1.5; }
  .book-sample-modal .bs-is-overview .bs-overview-toc li > span { min-width: 0; overflow-wrap: anywhere; }
  .book-sample-modal .bs-is-overview .bs-overview-toc li > b { flex-shrink: 0; font-size: 12px; }
  .book-sample-modal .bs-is-overview .bs-overview-note { font-size: 12px !important; line-height: 1.6; margin-block: 14px !important; }
  .book-sample-modal .bs-is-overview .bs-start,
  .book-sample-modal .bs-full-toc-button { min-height: 48px; padding: 12px; font-size: 13px; line-height: 1.5; }
  .book-sample-modal .bs-controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-top: 20px; }
  .book-sample-modal .bs-status { grid-column: 1 / -1; grid-row: 1; }
  .book-sample-modal .bs-status strong { font-size: 13px; }
  .book-sample-modal .bs-status > span { max-width: none; font-size: 12px; }
  .book-sample-modal .bs-nav { grid-row: 2; justify-self: stretch; width: 100%; min-width: 0; min-height: 48px; padding: 11px 12px; font-size: 14px; }
  .book-sample-modal .bs-bottom { gap: 8px 12px; }
  .book-sample-modal .bs-overview-button { min-height: 44px; padding: 10px 4px; font-size: 13px; }
  .book-sample-modal .bs-bottom > span { max-width: 100%; font-size: 12px; line-height: 1.6; }
  .book-sample-modal .bs-zoom-cue { font-size: 10px; padding: 7px 9px; }

  .book-sample-modal.bs-zoom-active { height: var(--mrc-height); min-height: 0; }
  .book-sample-modal.bs-zoom-active #modal-content { height: calc(var(--mrc-height) - 2px); min-height: 0; }
  .book-sample-modal .bs-zoom { height: 100%; min-height: 0; }
  .book-sample-modal .bs-zoom-top { flex-shrink: 0; gap: 12px; padding: 12px; }
  .book-sample-modal .bs-zoom-top strong { font-size: 15px; line-height: 1.4; overflow-wrap: anywhere; }
  .book-sample-modal .bs-zoom-top span { font-size: 12px; line-height: 1.5; white-space: normal; overflow-wrap: anywhere; }
  .book-sample-modal .bs-zoom-close { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  .book-sample-modal .bs-zoom-tools { flex-shrink: 0; flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .book-sample-modal .bs-zoom-tools button { width: 44px; min-width: 44px; height: 44px; }
  .book-sample-modal .bs-zoom-tools output { min-width: 54px; font-size: 14px; }
  .book-sample-modal .bs-zoom-tools > span { flex: 1 1 140px; max-width: none; margin-left: 0; font-size: 12px; line-height: 1.4; }
  .book-sample-modal .bs-zoom-canvas { padding: 12px; scroll-padding: 12px; }
  .book-sample-modal .bs-all-contents-body { padding: 20px 16px; }
  .book-sample-modal .bs-all-contents-body h3 { gap: 12px; font-size: 25px; overflow-wrap: anywhere; }
  .book-sample-modal .bs-all-contents-body h3 > span { flex-shrink: 0; }
  .book-sample-modal .bs-all-contents-body li { gap: 12px; font-size: 15px; }
  .book-sample-modal .bs-all-contents-body li > span { min-width: 0; overflow-wrap: anywhere; }
  .book-sample-modal .bs-all-contents-body li > b { flex-shrink: 0; }
  .book-sample-modal .bs-all-contents-body .bs-toc-level-3,
  .book-sample-modal .bs-all-contents-body .bs-toc-level-4 { font-size: 14px; }
}

@media (max-width: 360px) {
  .checkout-modal .co-fields { grid-template-columns: minmax(0, 1fr); }
  .checkout-modal .co-full { grid-column: 1; }
  .checkout-modal .co-actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .checkout-modal .co-actions .co-back { align-self: flex-start; }
  .checkout-modal .co-bump-grid { grid-template-columns: 52px minmax(0, 1fr); gap: 8px; }
  .checkout-modal .co-bump-grid img { width: 52px; }
}
