@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;600;700&family=Playfair+Display:ital@0;1&display=swap');

:root {
  --color-bg: #0C0C0E;
  --color-bg-alt: #131311;
  --color-surface: #1A1917;
  --color-surface-2: #211F1C;
  --color-border: #322F2A;
  --color-border-input: #6B6559;
  --color-text: #F3EEE1;
  --color-text-muted: #C9C2B0;
  --color-gold: #D9C696;
  --color-gold-soft: #EEE4C9;
  --color-gold-deep: #4A3C1E;
  --color-focus: #F0D98A;
  --gradient-vivid: linear-gradient(135deg, #FBF6EA, var(--color-gold));
  --font-heading: 'Rubik', 'Segoe UI', Tahoma, Arial, sans-serif;
  --font-body: 'Rubik', 'Segoe UI', Tahoma, Arial, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  /* Physical sheet: the DNP media Memories4U already prints on ("4x6").
     The real roll is 104.9x156.1mm; 101.6x152.4mm is the nominal "4x6in"
     every OS print dialog and the installed driver already recognize for
     this printer, so content is designed against that and the driver
     absorbs the ~1.5mm difference exactly as it already does for every
     other Memories4U print. */
  --page-w: 101.6mm;
  --page-h: 152.4mm;
  --gutter: 6mm;   /* blank channel at the exact vertical middle — the guillotine's cut line */
  --trim: 3mm;     /* outer safe margin — trimmed away on all four sides after the center cut */
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--color-bg); color: var(--color-text);
  font-family: var(--font-body); font-size: 15px;
  direction: rtl;
}
button, input, select, textarea { font-family: inherit; }

#app {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------------- Left: controls ---------------- */
#controls {
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  padding: 20px;
  overflow-y: auto;
}
#controls h1 {
  font-family: var(--font-heading);
  font-size: 19px; margin: 0 0 2px;
  color: var(--color-gold-soft);
}
#controls .subtitle { color: var(--color-text-muted); font-size: 13px; margin-bottom: 18px; }

.panel {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 14px;
}
.panel h2 {
  font-size: 13px; margin: 0 0 10px; color: var(--color-gold);
  text-transform: uppercase; letter-spacing: .05em;
}
.row { display: flex; gap: 8px; margin-bottom: 8px; }
.row > * { flex: 1; }
label.field { display: block; font-size: 12px; color: var(--color-text-muted); margin-bottom: 4px; }
input[type=text], input[type=number] {
  width: 100%; background: var(--color-bg-alt); color: var(--color-text);
  border: 1px solid var(--color-border-input); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 14px;
}
input[type=checkbox] { width: 16px; height: 16px; vertical-align: middle; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--color-surface-2); color: var(--color-text);
  border: 1px solid var(--color-border-input); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13px; cursor: pointer; width: 100%;
}
.btn:hover { border-color: var(--color-gold); }
.btn.primary { background: var(--gradient-vivid); color: #211a08; border: none; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { width: auto; padding: 6px 10px; font-size: 12px; }

#frame-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.frame-opt {
  border: 2px solid var(--color-border); border-radius: var(--radius-sm);
  overflow: hidden; cursor: pointer; background: #fff; position: relative;
  aspect-ratio: 1388 / 1000;
}
.frame-opt svg { width: 100%; height: 100%; display: block; }
.frame-opt span {
  position: absolute; inset-inline: 0; bottom: 0; font-size: 10px; text-align: center;
  background: rgba(0,0,0,.55); color: #fff; padding: 2px 2px;
}
.frame-opt.active { border-color: var(--color-gold); box-shadow: 0 0 0 2px var(--color-gold) inset; }

.zoom-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.zoom-row input[type=range] { flex: 1; accent-color: var(--color-gold); }
.zoom-row .btn.small { width: 30px; padding: 6px 0; font-size: 16px; line-height: 1; }
#zoom-readout { font-size: 12px; color: var(--color-text-muted); min-width: 38px; text-align: center; }

.active-slot-label {
  background: var(--color-gold-deep); color: var(--color-gold-soft);
  border: 1px solid var(--color-gold); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 12px; font-weight: 600; margin-bottom: 10px;
}

.hint { font-size: 11px; color: var(--color-text-muted); line-height: 1.5; margin-top: 6px; }

/* ---------------- Right: gallery of every sheet at once ---------------- */
#stage {
  position: relative;
  padding: 18px; overflow-y: auto; background: var(--color-bg);
}
#gallery {
  display: flex; flex-wrap: wrap; gap: 18px; align-content: flex-start;
}

.sheet-card {
  /* direction:ltr is load-bearing, not cosmetic: the page is dir="rtl", and
     .sheet is wider (384px, pre-scale) than this card (260px) until its
     transform:scale(...) kicks in. Under rtl a too-wide static block child
     right-aligns to the container instead of left-aligning, so the
     scale(), anchored at transform-origin:"top left" of the (wrongly
     shifted) element, ends up clipping the sheet's left portion and
     leaving dead space on the right. ltr restores left-alignment so the
     post-scale box exactly fills the card. */
  direction: ltr;
  position: relative; background: #000; border-radius: 4px; overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,.55); flex-shrink: 0;
}
.sheet-label {
  position: absolute; top: 4px; left: 4px; z-index: 5;
  font-size: 10px; color: rgba(255,255,255,.7); background: rgba(0,0,0,.4);
  padding: 2px 6px; border-radius: 3px; pointer-events: none;
}

.sheet {
  width: var(--page-w); height: var(--page-h);
  position: relative; background: #fff;
}

.cell {
  position: absolute; left: 0; width: 100%;
  height: calc((100% - var(--gutter)) / 2);
  overflow: hidden; cursor: pointer;
}
.cell.top { top: 0; }
.cell.bottom { top: calc(50% + var(--gutter) / 2); }
/* A UI affordance, not part of the design: bright blue, drawn OUTSIDE the
   cell so it never visually merges with a frame's own (often gold) border. */
.cell.selected { outline: 4px solid #35B6FF; outline-offset: 2px; z-index: 2; box-shadow: 0 0 0 2px rgba(53,182,255,.35); }
.cell:not(.selected):hover { outline: 2px dashed rgba(255,255,255,.35); outline-offset: 2px; }

.cell .photo-layer {
  position: absolute; inset: 0; overflow: hidden; background: #e8e4da;
}
.cell .photo-layer img {
  position: absolute; left: 50%; top: 50%;
  max-width: none; max-height: none;
  transform-origin: center center;
  user-select: none; -webkit-user-drag: none;
}
.cell .empty-slot {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #9a9488; font-size: 2.6mm; text-align: center; padding: 4mm;
  background: repeating-linear-gradient(45deg,#f2efe8,#f2efe8 10px,#e9e4d8 10px,#e9e4d8 20px);
}

.cell .frame-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.cell .caption-band {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none; text-align: center;
}
.cell .caption-line1 { font-size: 4.6mm; line-height: 1.15; }
.cell .caption-line2 { font-size: 2.6mm; line-height: 1.2; opacity: .85; margin-top: .6mm; }
.font-script .caption-line1 { font-family: 'Playfair Display', Georgia, serif; font-style: italic; }
.font-serif .caption-line1 { font-family: Georgia, 'Times New Roman', serif; }
.font-editorial .caption-line1 { font-family: var(--font-heading); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.font-rounded .caption-line1 { font-family: var(--font-heading); font-weight: 700; }

.cell .brand-strip {
  position: absolute; top: 50%; writing-mode: vertical-rl; transform: translateY(-50%) rotate(180deg);
  display: flex; flex-wrap: nowrap; align-items: center; gap: 1.4mm; pointer-events: none;
  font-size: 2.3mm; font-weight: 700; color: #111;
  white-space: nowrap; width: max-content; height: max-content;
}
.cell .brand-strip span { white-space: nowrap; }
.cell .brand-strip img { width: 2.6mm; height: 2.6mm; flex: none; writing-mode: horizontal-tb; transform: rotate(180deg); }
.cell .brand-strip.side-left { left: 2.2mm; }

/* cut + trim guides — thin, printed on purpose so the guillotine has a line to follow */
.guide-center {
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
  border-top: 0.35mm dashed #bdbdbd;
  pointer-events: none;
}
.guide-center::before, .guide-center::after {
  content: ''; position: absolute; top: -2mm; width: 0; height: 4mm; border-left: 0.35mm solid #9a9a9a;
}
.guide-center::before { left: 0; }
.guide-center::after { right: 0; }
.guide-trim {
  position: absolute; pointer-events: none;
  border: 0.3mm dotted #c8c8c8;
  inset: var(--trim);
}

/* ---------------- screen-only chrome, never printed ---------------- */
.screen-only { }
@media print {
  html, body { background: #fff !important; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { position: static !important; left: auto !important; }
  #print-root .sheet { box-shadow: none; page-break-after: always; }
  #print-root .sheet:last-child { page-break-after: auto; }
  @page { size: 101.6mm 152.4mm; margin: 0; }
}
/* Off-screen, NOT display:none: buildPrintRoot() measures each cell's
   real pixel box (getBoundingClientRect) to size photos — display:none
   elements always measure 0x0, which silently shrank every printed photo
   to ~1px (invisible) while the on-screen gallery looked fine. Shifting
   it off-screen keeps it fully laid out and measurable at all times. */
#print-root { position: absolute; left: -99999px; top: 0; }

#dropzone {
  border: 2px dashed var(--color-border-input); border-radius: var(--radius-md);
  padding: 22px 12px; text-align: center; color: var(--color-text-muted); font-size: 13px;
  cursor: pointer; margin-bottom: 10px;
}
#dropzone.drag { border-color: var(--color-gold); color: var(--color-gold-soft); background: rgba(217,198,150,.06); }
#file-input { display: none; }

.empty-state {
  color: var(--color-text-muted); text-align: center; max-width: 360px; margin-top: 60px; line-height: 1.7;
}
