/* LiveDoc PDF import - screen + print styles */

:root {
  --ink: #1f1d1a;
  --accent: #9a6a3c;
  --accent-hover: #b07d49;
  --paper: #ffffff;
  --bg: #efece6;
  --muted: #7d756a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- Intro / drop zone (hidden once a doc loads) ---- */
.intro {
  max-width: 640px;
  margin: 8vh auto 4vh;
  padding: 0 20px;
  text-align: center;
}
.intro h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: -0.02em; }
.intro .sub { color: var(--muted); font-size: 15px; margin: 0 0 28px; line-height: 1.5; }

.dropzone {
  display: block;   /* <label> is inline by default - collapses without this */
  border: 2px dashed #c9bfae;
  border-radius: 16px;
  background: #fbfaf7;
  padding: 48px 24px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--accent); background: #fff; }
.dropzone.dragover { border-color: var(--accent); background: #fff8f0; }
.dropzone .big { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.dropzone .small { color: var(--muted); font-size: 13px; }
.dropzone input { display: none; }

.note {
  margin-top: 22px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.55;
  text-align: left;
  background: #fbfaf7;
  border: 1px solid #e7e0d3;
  border-radius: 10px;
  padding: 14px 16px;
}
.note b { color: var(--ink); }

.status-msg {
  margin-top: 18px;
  font-size: 14px;
  min-height: 20px;
}
.status-msg.err { color: #a23b2d; font-weight: 600; }

/* ---- The editable document ---- */
.sheet {
  display: none;                 /* shown once content loads */
  max-width: 816px;              /* ~ US Letter at 96dpi */
  margin: 32px auto 80px;
  background: var(--paper);
  padding: 72px 84px;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0,0,0,.12);
  line-height: 1.6;
  font-size: 16px;
}
body.has-doc .intro { display: none; }
body.has-doc .sheet { display: block; }

.sheet h1 { font-size: 28px; margin: 0 0 12px; letter-spacing: -0.01em; }
.sheet h2 { font-size: 20px; margin: 26px 0 8px; }
.sheet p  { margin: 0 0 12px; }
.sheet ul, .sheet ol { margin: 0 0 12px; padding-left: 26px; }
.sheet li { margin: 0 0 4px; }

/* A small "start over" affordance, top-left so it clears the LiveDoc bar */
.reopen {
  position: fixed; top: 14px; left: 14px; z-index: 2147483646;
  display: none;
  font: inherit; font-size: 13px;
  background: var(--ink); color: #fff; border: 0;
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
}
body.has-doc .reopen { display: inline-block; }
.reopen:hover { background: #35312b; }

/* Hide LiveDoc's toolbar until a document is actually loaded. */
body:not(.has-doc) .livedoc-bar { display: none !important; }

/* "+ Add text" - visible only while Edit is armed */
.addtext {
  position: fixed; top: 14px; left: 112px; z-index: 2147483646;
  display: none;
  font: inherit; font-size: 12.5px; line-height: 1;
  background: var(--ink); color: #cfc6b4; border: 0;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
}
body.has-doc.mode-styled.styled-editing .addtext { display: inline-block; }
.addtext.on { background: var(--accent); color: #fff; }
body.placing-text .pdfpage { cursor: crosshair; }

/* ---- Style toolbar (floats above the run being edited) ---- */
.ld-styletool {
  position: fixed; z-index: 2147483647; display: none;
  align-items: center; gap: 1px;
  background: var(--ink); border-radius: 9px; padding: 4px;
  box-shadow: 0 6px 22px rgba(0,0,0,.30);
}
.ld-styletool.on { display: inline-flex; }
.ld-styletool button {
  font: inherit; font-size: 13px; line-height: 1; min-width: 32px;
  border: 0; background: transparent; color: #e8e0d2;
  padding: 7px 9px; border-radius: 6px; cursor: pointer;
}
.ld-styletool button:hover { background: rgba(255,255,255,.12); }
.ld-styletool button.on { background: var(--accent); color: #fff; }
.ld-styletool .match { font-weight: 600; color: #fff; white-space: nowrap; }
.ld-styletool .sep { width: 1px; align-self: stretch; margin: 4px 3px; background: rgba(255,255,255,.18); }
.ld-styletool input[type="color"] {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 30px; border: 0; border-radius: 6px;
  padding: 0; margin-left: 2px; cursor: pointer; background: transparent;
}
.ld-styletool input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.ld-styletool input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(255,255,255,.35); border-radius: 4px; }
.ld-styletool input[type="color"]::-moz-color-swatch { border: 1px solid rgba(255,255,255,.35); border-radius: 4px; }

/* "Match" (eyedropper) mode: highlight the line whose style will be copied. */
body.ld-matching .textLayer span { cursor: crosshair !important; }
body.ld-matching .textLayer span:hover {
  outline: 2px solid var(--accent); outline-offset: 2px;
  background: rgba(154, 106, 60, .14);
}

/* ---- Styled (overlay) mode: pixel-accurate pages + editable text layer ---- */
body.mode-styled .sheet {
  background: transparent; box-shadow: none;
  padding: 0; max-width: none; border-radius: 0;
  overflow-x: auto;
}
/* Top padding keeps the fixed toolbars clear of the first page (screen only). */
.pdfpages { display: flex; flex-direction: column; align-items: center; gap: 24px; padding-top: 56px; }
.pdfpage {
  position: relative; flex: none;
  background: #fff;
  box-shadow: 0 10px 40px rgba(0,0,0,.12);
}
.pagebg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; user-select: none;
}
.textLayer {
  position: absolute; inset: 0; overflow: hidden;
  line-height: 1; transform-origin: 0 0; text-align: initial;
}
.textLayer span {
  color: transparent;            /* original rendered glyphs show through */
  position: absolute; white-space: pre;
  cursor: default; transform-origin: 0 0;
  line-height: 1;
}
/* Edit armed: show which runs are clickable */
body.styled-editing .textLayer span { cursor: text; }
body.styled-editing .textLayer span:hover:not([contenteditable="plaintext-only"]):not([contenteditable="true"]):not([data-noedit]) {
  outline: 1.5px dashed rgba(154, 106, 60, .85);
  outline-offset: 2px;
}
/* Rotated/vertical runs can't be patch-edited - don't pretend otherwise. */
.textLayer span[data-noedit] { pointer-events: none; }
body.styled-editing .textLayer span[data-noedit] { cursor: not-allowed; }
.textLayer span[contenteditable="plaintext-only"],
.textLayer span[contenteditable="true"] {
  outline: 1.5px solid rgba(154, 106, 60, .9);
  outline-offset: 3px;
}
.textLayer span:focus { outline-style: solid; }

/* #debug - visualize the text layer alignment */
body.ld-debug .textLayer span {
  outline: 1px dotted rgba(220, 60, 60, .5);
  color: rgba(220, 60, 200, .35);
}

@media print {
  body.mode-styled .sheet { overflow: visible; margin: 0; }
  .pdfpages { display: block; padding-top: 0; }
  .pdfpage { box-shadow: none; margin: 0; page-break-after: always; }
  .pdfpage:last-child { page-break-after: auto; }
}

/* ---- Print / PDF export ---- */
@page { margin: 0.75in; }
@media print {
  html, body { background: #fff; }
  /* Only the document prints: hides our chrome (view toggle, + Add text,
     reopen, LiveDoc bar) AND anything a browser extension injected. */
  body > :not(.sheet) { display: none !important; }
  /* Patches carry sampled page colors - print them exactly as seen,
     independent of the browser's "Background graphics" setting. */
  .sheet, .sheet * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .sheet {
    display: block !important;
    box-shadow: none; margin: 0; padding: 0;
    max-width: none; border-radius: 0;
  }
}
