/* A4 biodata page shared by every template (preview, thumbnails, export).
   Pages are real A4 at 96 dpi (794 x 1123 px), scaled by --sheet-scale.
   Templates (templates/<id>.css) restyle these parts through variables:
     --t-page --t-text --t-muted --t-accent --t-line          (from <id>.json colors)
     --t-header-bg --t-header-text --t-photo-border
     --t-frame-pad   space between page edge and the content box (border band)
     --t-pad-x / --t-pad-y   padding inside the content box
   --bio-scale (set by renderer.js) shrinks text for long biodatas (never below 0.8 ≈ 10 pt printed);
   --photo-scale, .is-tight and .lb-page__cols are the other one-page fitting steps (renderer.js). */

/* ---------- Sheet: scaled window onto one page ---------- */
/* contain: inline-size makes the width come only from the container, so the
   measured width (which sets --sheet-scale in preview.js) never depends on
   the sheets themselves — otherwise scale and width feed each other. */
.lb-app .lb-sheets {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  contain: inline-size;
  --sheet-scale: 0.3;
}
.lb-app .lb-sheet {
  position: relative;
  max-width: 100%;
  width: calc(794px * var(--sheet-scale));
  height: calc(1123px * var(--sheet-scale));
  overflow: hidden;
  border: 1px solid var(--lb-border);
  border-radius: 4px;
  background: #fff;
}

/* ---------- Page ---------- */
.lb-app .lb-page {
  --t-page: #FFFDF9;
  --t-text: #2A1A14;
  --t-muted: #6B5A50;
  --t-accent: #7B1E2E;
  --t-line: #B8862B;
  --t-header-bg: transparent;
  --t-header-text: var(--t-accent);
  --t-photo-border: var(--t-line);
  --t-frame-pad: 28px;
  --t-pad-x: 44px;
  --t-pad-y: 34px;
  --t-font-heading: var(--lb-font-bio);
  --t-font-body: var(--lb-font-bio);
  --bio-scale: 1;

  position: absolute;
  top: 0;
  left: 0;
  width: 794px;
  height: 1123px;
  margin: 0;
  padding: 0;
  border: 0;
  box-shadow: none;
  overflow: hidden;
  /* Themes must not leak into the biodata. */
  letter-spacing: normal;
  word-spacing: normal;
  text-transform: none;
  text-indent: 0;
  transform: scale(var(--sheet-scale, 1));
  transform-origin: 0 0;
  background: var(--t-page);
  color: var(--t-text);
  font-family: var(--t-font-body);
  font-size: 17px;
  line-height: 1.4;
  text-align: left;
}
.lb-app .lb-page[data-font-heading="mukta"] { --t-font-heading: var(--lb-font-ui); }
.lb-app .lb-page[data-font-body="mukta"] { --t-font-body: var(--lb-font-ui); }

.lb-app .lb-page__frame { position: absolute; inset: 0; padding: var(--t-frame-pad); }

/* Corner ornaments: templates set display + background-image (one image,
   used by all four corners) and may override size, inset or a single corner. */
.lb-app .lb-page__corner {
  display: none;
  position: absolute;
  z-index: 1;
  width: var(--t-corner-size, 40px);
  height: var(--t-corner-size, 40px);
  background: center / contain no-repeat;
  pointer-events: none;
}
.lb-app .lb-page__corner--tl { top: var(--t-corner-inset, 4px); left: var(--t-corner-inset, 4px); }
.lb-app .lb-page__corner--tr { top: var(--t-corner-inset, 4px); right: var(--t-corner-inset, 4px); }
.lb-app .lb-page__corner--bl { bottom: var(--t-corner-inset, 4px); left: var(--t-corner-inset, 4px); }
.lb-app .lb-page__corner--br { bottom: var(--t-corner-inset, 4px); right: var(--t-corner-inset, 4px); }
.lb-app .lb-page__inner {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: calc(var(--t-pad-y) * var(--fit-pad, 1)) var(--t-pad-x);
}

/* ---------- Header ---------- */
.lb-app .lb-page__header { flex: none; display: grid; justify-items: center; gap: 2px; text-align: center; color: var(--t-header-text); }
/* Header picture (renderer.js). Every kind has a fixed height; the width follows the file's own
   proportions (--deity-ratio), so nothing is stretched or cut. Explicit width + height (not
   aspect-ratio) – Safari sizes aspect-ratio boxes with padding wrongly in exports.
   art = painting / photo in a frame that matches the template's photo frame (--t-photo-border);
   figure = transparent cut-out, no frame. --deity-fit (renderer) evens out cut-outs and emblems
   of different shapes; very wide pictures (﷽) are capped at 300px wide. */
.lb-app .lb-page__deity {
  --deity-h: 70px;
  --deity-box: min(calc(var(--deity-h) * var(--deity-fit, 1)), calc(300px / var(--deity-ratio, 1)));
  display: block;
  box-sizing: content-box;
  width: calc(var(--deity-box) * var(--bio-scale) * var(--deity-ratio, 1));
  height: calc(var(--deity-box) * var(--bio-scale));
  max-width: none;
}
.lb-app .lb-page__deity--art {
  --deity-h: 96px;
  padding: 2px;
  border: 1.5px solid var(--t-photo-border);
  border-radius: 4px;
  background: var(--t-page);
  object-fit: contain;
}
.lb-app .lb-page__deity--symbol { --deity-h: 66px; object-fit: contain; }
.lb-app .lb-page__deity--figure { --deity-h: 100px; object-fit: contain; }
.lb-app .lb-page.is-tight .lb-page__deity--art { --deity-h: 84px; }
.lb-app .lb-page.is-tight .lb-page__deity--figure { --deity-h: 88px; }
/* Designs that put a light disc behind emblems: tall or wide emblems get a rounded box instead,
   so the disc never cuts their corners. */
.lb-app .lb-page[data-template] .lb-page__deity--symbol:not(.lb-page__deity--round) { border-radius: 10px; }
.lb-app .lb-page__invocation { margin: 4px 0 0; font-family: var(--t-font-heading); font-size: calc(18px * var(--bio-scale)); line-height: 1.35; }
.lb-app .lb-page__title {
  margin: 0;
  font-family: var(--t-font-heading);
  font-size: calc(36px * var(--bio-scale) * var(--bio-title-fit, 1));
  font-weight: 400;
  line-height: 1.25;
  overflow-wrap: anywhere;
  letter-spacing: normal;
  color: inherit;
}
.lb-app .lb-page[data-header="band"] .lb-page__header {
  margin: calc(var(--t-pad-y) * -1) calc(var(--t-pad-x) * -1) 0;
  padding: 22px var(--t-pad-x) 20px;
  background: var(--t-header-bg);
}

/* ---------- Body ---------- */
.lb-app .lb-page__body {
  position: relative; /* offsetParent for pagination */
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding-top: calc(8px * var(--bio-scale));
}
.lb-app .lb-page__name {
  margin: calc(4px * var(--bio-scale)) 0 calc(10px * var(--bio-scale));
  font-family: var(--t-font-heading);
  font-size: calc(27px * var(--bio-scale));
  line-height: 1.3;
  text-align: center;
  color: var(--t-text);
  overflow-wrap: anywhere; /* very long names never overflow the page */
}
.lb-app .lb-page__name.is-empty { opacity: 0.6; } /* still clearly a hint, but readable (3:1) */

.lb-app .lb-page { --t-photo-w: 160px; }
/* Photo: its own area at the top right, beside the first rows – never inside the table. The detail
   table keeps ONE label column from top to bottom (rows beside the photo only get a narrower value
   column). Fixed 3:4 passport frame: same size for every photo in a template (only the one-page
   "smaller photo" step changes it); the visitor's own crop fills it (object-fit: cover, never stretched).
   No photo: the details use the full width. Frame / border per template (--t-photo-border, templates/*.css). */
.lb-app .lb-page__photo {
  box-sizing: border-box;
  /* An explicit height (not aspect-ratio): Safari would size the photo to the outer box and cover the padding. */
  width: calc(var(--t-photo-w) * var(--photo-scale, 1));
  height: calc(var(--t-photo-w) * var(--photo-scale, 1) * 4 / 3);
  margin: 0 0 12px;
  padding: 4px;
  overflow: hidden;
  border: 2px solid var(--t-photo-border);
  background: var(--t-page);
}
.lb-app .lb-page__photo img { display: block; width: 100%; height: 100%; max-width: none; object-fit: cover; object-position: 50% 40%; }
/* "left" is drawn on the right as well: a left photo would push the label column of the rows beside it. */
.lb-app .lb-page[data-photo="right"] .lb-page__photo,
.lb-app .lb-page[data-photo="left"] .lb-page__photo { float: right; margin-left: 24px; }
.lb-app .lb-page[data-photo="top"] .lb-page__photo { margin: 0 auto 14px; }

/* Section titles and rows are "flow-root"/grid so they sit beside a floated photo. */
.lb-app .lb-page__section-title {
  display: flow-root;
  margin: calc(10px * var(--bio-scale)) 0 calc(5px * var(--bio-scale));
  padding-bottom: 3px;
  border-bottom: 1px solid var(--t-line);
  color: var(--t-accent);
  font-family: var(--t-font-heading);
  font-size: calc(21px * var(--bio-scale));
  font-weight: 400; /* Tiro has no bold; avoid faux bold (very visible in Safari) */
  line-height: 1.3;
}
.lb-app .lb-page__row {
  display: grid;
  grid-template-columns: calc(200px * var(--bio-scale)) 1fr; /* fixed, so values line up beside and below the photo */
  gap: 12px;
  padding: calc(1px * var(--bio-scale)) 0;
  font-size: calc(17px * var(--bio-scale));
  line-height: 1.4;
}
.lb-app .lb-page__label { color: var(--t-muted); overflow-wrap: anywhere; }
.lb-app .lb-page__label::after { content: ' :'; }
.lb-app .lb-page__value { white-space: pre-line; overflow-wrap: anywhere; }

/* ---------- One-page fitting (renderer.js) ---------- */
/* 1. Tighter spacing. */
.lb-app .lb-page.is-tight { --fit-pad: 0.6; }
.lb-app .lb-page.is-tight .lb-page__header { gap: 0; }
.lb-app .lb-page.is-tight .lb-page__body { padding-top: calc(4px * var(--bio-scale)); }
.lb-app .lb-page.is-tight .lb-page__name { margin: 0 0 calc(5px * var(--bio-scale)); }
.lb-app .lb-page.is-tight .lb-page__section-title { margin: calc(6px * var(--bio-scale)) 0 calc(3px * var(--bio-scale)); padding-bottom: 2px; }
.lb-app .lb-page.is-tight .lb-page__row { padding: 0; line-height: 1.3; }
.lb-app .lb-page.is-tight .lb-page__photo { margin-bottom: 8px; }
/* 2. Two columns below the photo: each column keeps its own label column. */
.lb-app .lb-page__cols { clear: both; column-count: 2; column-gap: 28px; }
.lb-app .lb-page__cols .lb-page__row { grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr); gap: 8px; break-inside: avoid; }
.lb-app .lb-page__cols .lb-page__section-title { break-after: avoid; break-inside: avoid; }
.lb-app .lb-page__cols > :first-child { margin-top: 0; }
.lb-app .lb-page__body.has-cols > .lb-page__row { grid-template-columns: var(--label-w) minmax(0, 1fr); gap: 8px; }

/* Longest entries while the biodata does not fit on one page (preview only, never exported). */
.lb-app #lb-preview .lb-page__row.is-long { background: #FFF1B8; box-shadow: 0 0 0 3px #FFF1B8; }

/* Empty biodata placeholder */
.lb-app .lb-page__ph-row { display: grid; grid-template-columns: 34% 1fr; gap: 18px; margin-top: 22px; }
.lb-app .lb-page__ph { display: block; height: 14px; border-radius: 7px; background: currentColor; opacity: 0.1; }

/* ---------- Footer and page number ---------- */
.lb-app .lb-page__brand-logo { display: inline-block; width: 16px; height: 16px; margin-right: 5px; vertical-align: -3px; }
.lb-app .lb-page__foot {
  flex: none;
  display: flex;
  justify-content: center;
  gap: 16px;
  padding-top: 6px;
  color: var(--t-muted);
  font-family: var(--lb-font-ui);
  font-size: 12px;
  line-height: 17px;
  height: 23px; /* fixed: page numbers are added after measuring */
}
