/* Print layout for a whole build log.
 *
 * Loaded only by /builds/{slug}/print. app.css supplies the type and colour;
 * this file does the paper.
 *
 * Two rules drive the whole thing:
 *
 *   1. Every entry starts a new sheet. A day's work is never split across a
 *      fold, and a single page can be pulled out and taken to the bench.
 *
 *   2. Photos pack as tightly as they can while staying whole. A build log is
 *      read for its pictures; one per page would turn two years of work into a
 *      three-hundred-page book nobody would print. Cells are a fixed 4:3 and
 *      images are contained rather than cropped, so rows align exactly -- which
 *      is what removes the ragged gaps that waste a third of a page.
 */

@page {
  size: auto;
  margin: 14mm 12mm;
}

body.printable {
  background: #fff;
  color: #000;
  max-width: 190mm;
  margin: 0 auto;
  padding: 1rem;
}

/* --- screen-only chrome --------------------------------------------------- */

.print-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 1rem;
  padding: 0.75rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.print-note { max-width: 60ch; margin-bottom: 2rem; }

/* --- sheets --------------------------------------------------------------- */

.sheet { margin-bottom: 3rem; }

.cover { border-bottom: 2px solid #000; padding-bottom: 1.5rem; }
.cover-kicker {
  font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: #555; margin: 0 0 0.4rem;
}
.cover-title { font-size: 2.1rem; line-height: 1.1; margin: 0 0 0.3rem; }
.cover-boat { font-family: var(--font-data); font-size: 1.05rem; margin: 0 0 0.2rem; }
.cover-by { color: #555; margin: 0 0 1.2rem; }
.cover-summary { max-width: 62ch; margin: 0 0 1.5rem; }

.cover-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.9rem 1.2rem;
  margin: 0 0 1.5rem;
  padding: 0.9rem 0;
  border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;
}
.cover-facts div { margin: 0; }
.cover-facts dt {
  font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: #555;
}
.cover-facts dd {
  font-family: var(--font-data); font-size: 1.15rem; margin: 0.15rem 0 0;
}
.cover-warning {
  border-left: 3px solid #000; padding-left: 0.8rem;
  font-size: 0.9rem; max-width: 62ch;
}
.cover-source { font-family: var(--font-data); font-size: 0.78rem; color: #555; }

/* --- entries -------------------------------------------------------------- */

.entry-head {
  display: flex; align-items: baseline; gap: 0.8rem; flex-wrap: wrap;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #ccc;
  margin-bottom: 0.7rem;
}
.entry-date { font-family: var(--font-data); font-weight: 700; }
.entry-phase {
  font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase;
  border: 1px solid #999; border-radius: 2px; padding: 0.1rem 0.4rem;
}
.entry-hours { font-family: var(--font-data); font-size: 0.85rem; color: #555; }
.entry-index {
  margin-left: auto;
  font-family: var(--font-data); font-size: 0.75rem; color: #777;
}
.entry-title { font-size: 1.25rem; margin: 0 0 0.5rem; }
.entry-body { max-width: none; }
.entry-body p { margin-bottom: 0.6rem; }
.entry-embeds { font-size: 0.8rem; color: #555; margin-top: 0.6rem; }

/* --- photo packing -------------------------------------------------------- */

.print-photos {
  display: grid;
  gap: 4mm;
  margin-top: 0.8rem;
}
.print-photos.cols-2 { grid-template-columns: repeat(2, 1fr); }
.print-photos.cols-3 { grid-template-columns: repeat(3, 1fr); }
.print-photos.cols-4 { grid-template-columns: repeat(4, 1fr); }

.print-photos figure {
  margin: 0;
  /* Never let a photo straddle a page break -- half an image is worse than
     the same image overleaf. */
  break-inside: avoid;
  page-break-inside: avoid;
}

.print-photos img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  /* Contain, not cover: a cropped photo of a scarf joint may be missing the
     joint. Uniform cells still align into clean rows either way. */
  object-fit: contain;
  background: #f4f4f2;
  border: 1px solid #ddd;
}
.print-photos figcaption {
  font-size: 0.68rem; line-height: 1.3; color: #444;
  margin-top: 0.15rem;
}

/* --- tables --------------------------------------------------------------- */

.section-title { font-size: 1.3rem; margin: 0 0 0.8rem; }
.print-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.print-table th, .print-table td {
  text-align: left; padding: 0.3rem 0.4rem; border-bottom: 1px solid #ddd;
  vertical-align: top;
}
.print-table .num { text-align: right; font-family: var(--font-data); }
.print-table tfoot th { border-top: 2px solid #000; border-bottom: 0; }

.sheet-footer {
  margin-top: 3rem; padding-top: 1rem;
  border-top: 1px solid #ccc;
  font-size: 0.8rem; color: #555;
}

/* --- what actually happens on paper --------------------------------------- */

@media print {
  body.printable {
    max-width: none;
    padding: 0;
    font-size: 10.5pt;
  }

  .print-bar, .print-note { display: none !important; }

  /* Rule 1: an entry always begins a fresh sheet. Not the first one, which
     would otherwise leave a blank page after the cover. */
  .entry-sheet {
    break-before: page;
    page-break-before: always;
    margin-bottom: 0;
  }

  .sheet { margin-bottom: 0; }

  /* Keep a heading with the text under it. */
  .entry-head, .entry-title { break-after: avoid; page-break-after: avoid; }

  /* Materials can flow; a long table across pages is fine and expected. */
  .print-table thead { display: table-header-group; }
  .print-table tr { break-inside: avoid; page-break-inside: avoid; }

  .sheet-footer { break-before: page; page-break-before: always; }

  /* Slightly denser on paper than on screen -- the gaps are for the eye, and
     paper has less of it to spare. */
  .print-photos { gap: 3mm; }

  a { text-decoration: none; color: #000; }

  /* The phase pill and photo backgrounds read as deliberate, not as artefacts,
     so ask for them -- browsers still let the reader override. */
  .entry-phase, .print-photos img { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
