/* Paper: the standard sheet a book is printed on (A4, 2.5cm margins) */
:root {
  --paper-width: 210mm;
  --paper-height: 297mm;
  --paper-margin: 25mm;
  --paper-content-width: calc(var(--paper-width) - 2 * var(--paper-margin));
  --paper-content-height: calc(var(--paper-height) - 2 * var(--paper-margin));
}

.paper {
  font-family: var(--font-sans);
  font-size: 11pt;
  hyphens: auto;
  line-height: 1.4;
  orphans: 3;
  text-align: justify;
  widows: 2;

  :is(h1, h2, h3, h4, h5, h6) {
    break-after: avoid;
    text-align: start;
  }

  img {
    max-inline-size: 100%;
  }

  .heading__link {
    display: none;
  }

  /* Paged.js justifies the last line of a block cut across sheets. When the
     cut falls between blocks it marks their wrapper, and text-align-last is
     inherited: keep it to the block itself. */
  [data-align-last-split-element] * {
    text-align-last: auto;
  }
}

/* Print view: the whole book, one leaf per sheet. Paged.js lays it out on
   real sheets; until it does (or if it can't) the book shows as one column. */
body.print {
  background: var(--color-bg);
  display: block;
  padding-block: var(--block-space-double);

  @media print {
    padding: 0;
  }
}

.print__toolbar,
.print__book {
  margin-inline: auto;
  max-inline-size: var(--paper-content-width);

  @media print {
    max-inline-size: unset;
  }
}

.print__toolbar {
  display: flex;
  justify-content: flex-end;
  margin-block-end: var(--block-space);

  @media print {
    display: none;
  }
}

body.print--paginated {
  @media screen {
    background: #e5e5e5;

    .print__toolbar {
      max-inline-size: var(--paper-width);
    }

    .pagedjs_page {
      background: white;
      box-shadow: 0 0.2em 1em rgb(0 0 0 / 0.2);
      margin: 0 auto var(--block-space-double);
    }
  }
}

/* Slightly shorter than the sheet so rounding never spills it onto a second one */
.print__cover {
  block-size: calc(var(--paper-height) - 1mm);
  display: flex;
  justify-content: center;

  img {
    block-size: 100%;
    inline-size: 100%;
    object-fit: contain;
  }

  @media screen {
    body:not(.print--paginated) & {
      block-size: auto;
      margin-block-end: var(--block-space-double);
    }
  }
}

.print__title-page {
  padding-block-start: calc(var(--paper-content-height) * 0.35);
  text-align: center;

  h1 {
    font-size: 2.4em;
    margin: 0;
    text-align: center;
  }

  p {
    font-size: 1.3em;
    margin-block: 0.5em 0;
    text-align: center;
  }
}

.print__leaf {
  padding-block-start: var(--block-space-double);

  @media print {
    padding-block-start: 0;
  }
}

.print__section {
  padding-block-start: calc(var(--paper-content-height) * 0.35);
  text-align: center;

  h1 {
    font-size: 2em;
    text-align: center;
  }
}

.print__picture {
  margin: 0;
  text-align: center;

  figcaption {
    font-style: italic;
    margin-block-start: 0.5em;
    text-align: center;
  }
}

/* Editor A4 mode: the page as wide as a sheet, with a line where each sheet
   ends. A guide only: it lays out the markdown source, not the printed page. */
.paper-guide--enabled {
  inline-size: var(--paper-content-width);
  margin-inline: auto;
  max-inline-size: none;

  .house-md-content {
    background-image: repeating-linear-gradient(to bottom,
      transparent 0 calc(var(--paper-content-height) - 2px),
      var(--color-negative) calc(var(--paper-content-height) - 2px) var(--paper-content-height));
  }
}

/* A text toggle: the checkbox covers the label instead of taking room */
.paper-guide .btn {
  position: relative;

  input[type=checkbox] {
    block-size: 100%;
    inline-size: 100%;
    inset: 0;
    opacity: 0;
    position: absolute;
  }
}

.paper-guide__count--overflowing {
  color: var(--color-negative);
  font-weight: bold;
}
