/* Print / page-layout styles for the fairy-tale library.
 * Screen: a control bar + real-size sheet previews.
 * Print:  control chrome hidden, each .sheet = one physical page. */

.print-body {
  margin: 0;
  padding: 0 0 3rem;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ---------- Control bar (screen only) ---------- */
.print-controls {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--edge);
  box-shadow: var(--shadow);
}
.print-controls-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.85rem 1rem 1rem;
  display: flex;
  flex-direction: column;
}
.print-controls-inner > * { margin-bottom: 0.85rem; }
.print-controls-inner > *:last-child { margin-bottom: 0; }
.print-brand { display: flex; align-items: center; flex-wrap: wrap; }
.print-brand > * { margin-right: 0.8rem; }
.print-brand h1 { font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; margin: 0; color: var(--accent-deep); }
.back-link { padding: 0 var(--s-4); }

.print-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  grid-gap: 0.7rem 0.9rem; gap: 0.7rem 0.9rem;
  align-items: end;
}
.field { display: flex; flex-direction: column; font-size: 0.78rem; color: var(--ink-soft); font-weight: 700; }
.field > span { margin-bottom: 0.3rem; }
.field select {
  border: 1px solid var(--edge-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  padding: 0.55rem 0.6rem;
  min-height: var(--tap);
}
.field.check { flex-direction: row; align-items: center; color: var(--ink); }
.field.check > span { margin: 0 0 0 0.5rem; }
.field.check input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent-deep); }

.print-actions { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.print-summary { margin: 0 1rem 0 0; color: var(--ink-soft); font-weight: 700; font-size: 0.9rem; }
.print-go { font-size: 1rem; padding: 0 var(--s-6); }

.print-hint {
  max-width: 1100px;
  margin: 1rem auto 0;
  padding: 0 1rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* ---------- Preview stage ---------- */
.print-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem;
}
.print-stage > * { margin-bottom: 1.5rem; }
.print-stage > *:last-child { margin-bottom: 0; }

/* A sheet is sized in inches (set inline) so it maps 1:1 to the printed page. */
.sheet {
  position: relative;
  box-sizing: border-box;
  background: #fff;
  color: #1c130d;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 36px rgba(70, 37, 19, 0.22);
  overflow: hidden;
  font-family: Arial, "Helvetica Neue", "Noto Sans", sans-serif;
}
/* Flexbox `gap` chi co tu Safari 14.1 — dung margin cho iPad cu. */
.sheet > * { margin-bottom: 3mm; }
.sheet > *:last-child { margin-bottom: 0; }

.sheet-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), 1fr);
  grid-template-rows: repeat(var(--rows, 1), 1fr);
  grid-gap: 3mm; gap: 3mm;
}

.pslot {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.pslot > * { margin-bottom: 1.5mm; }
.pslot > *:last-child { margin-bottom: 0; }
.pslot-img {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 2mm;
  background: #faf3e6;
}
.pslot-img img { width: 100%; height: 100%; display: block; }
.sheet[data-fit="contain"] .pslot-img img { object-fit: contain; }
.sheet[data-fit="cover"] .pslot-img img { object-fit: cover; }
.sheet[data-fit="cover"] .pslot-img { background: transparent; }
.pslot-empty { color: #b59a82; font-size: 0.8rem; font-weight: 700; }

/* Caption under each image */
.pslot-caption {
  flex: 0 0 auto;
  font-size: 8.5pt;
  line-height: 1.32;
  color: #2a1710;
  max-height: 34%;
  overflow: hidden;
}
.pslot-caption strong { color: #B45309; }

/* Footer text block (all texts of the sheet, gathered) */
.sheet-footer {
  flex: 0 0 auto;
  border-top: 1px solid #e4cdae;
  padding-top: 2mm;
  font-size: 8.5pt;
  line-height: 1.34;
  color: #2a1710;
  max-height: 38%;
  overflow: hidden;
}
.sheet-footer p { margin: 0 0 1.2mm; }
.sheet-footer strong { color: #B45309; }

/* Single-image sheets can afford slightly larger text */
.sheet-grid[style*="--cols:1"][style*="--rows:1"] ~ .sheet-footer,
.sheet[data-fit] .sheet-grid { }

/* ---------- Print ---------- */
@media print {
  .print-controls,
  .print-hint,
  .status { display: none !important; }

  html, body { margin: 0; padding: 0; background: #fff; }
  .print-stage { display: block; padding: 0; }

  .sheet {
    box-shadow: none !important;
    margin: 0 !important;
    border-radius: 0;
    break-after: page;
    page-break-after: always;
  }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
  .pslot-img { background: transparent; }
}
