/* Overprint — prepress paper & ink */

:root {
  --paper: #f3efe6;
  --paper-deep: #e9e3d4;
  --ink: #17150e;
  --ink-soft: #57523f;
  --rule: #c9c1ab;
  --mag: #e0007a;      /* registration magenta */
  --cyan: #0092c8;
  --card: #fbf9f3;
  --shadow: 0 1px 0 rgba(23,21,14,.08), 0 10px 24px -14px rgba(23,21,14,.35);
  --font-display: "Instrument Serif", Georgia, serif;
  --font-ui: "Archivo", "Helvetica Neue", sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(224,0,122,.05), transparent 60%),
    radial-gradient(900px 420px at -10% 110%, rgba(0,146,200,.05), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(23,21,14,.022) 23px 24px),
    var(--paper);
  display: flex;
  flex-direction: column;
}

.mono { font-family: var(--font-mono); font-size: .74rem; letter-spacing: .02em; }

/* ---------- masthead ---------- */
.masthead {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; padding: 1.1rem 1.6rem .9rem;
  border-bottom: 1.5px solid var(--ink);
}
.masthead-brand { display: flex; align-items: baseline; gap: .8rem; }
.regmark { width: 22px; height: 22px; color: var(--mag); align-self: center; }
.masthead h1 {
  font-family: var(--font-display); font-weight: 400;
  font-size: 1.9rem; line-height: 1; letter-spacing: -.01em;
}
.masthead-tag {
  font-family: var(--font-mono); font-size: .72rem; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .14em;
}
.masthead-doc { display: flex; align-items: center; gap: .9rem; min-width: 0; }
#docName { color: var(--ink-soft); max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-mono); font-size: .74rem; letter-spacing: .06em;
  text-transform: uppercase; cursor: pointer;
  border: 1.5px solid var(--ink); background: var(--card); color: var(--ink);
  padding: .5rem .95rem; border-radius: 2px;
  transition: transform .06s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { background: var(--paper-deep); box-shadow: 2px 2px 0 var(--ink); transform: translate(-1px,-1px); }
.btn:active { transform: translate(0,0); box-shadow: none; }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); width: 100%; padding: .8rem 1rem; font-size: .8rem; }
.btn-primary:hover { background: var(--mag); border-color: var(--mag); box-shadow: 3px 3px 0 var(--ink); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; transform: none; }
.btn-ghost { border-color: var(--rule); background: transparent; }
.btn-mini { padding: .25rem .55rem; font-size: .66rem; }

/* ---------- crop marks ---------- */
.crop { position: absolute; width: 14px; height: 14px; border: 0 solid var(--mag); pointer-events: none; }
.crop.tl { top: -1px; left: -1px; border-top-width: 1.5px; border-left-width: 1.5px; }
.crop.tr { top: -1px; right: -1px; border-top-width: 1.5px; border-right-width: 1.5px; }
.crop.bl { bottom: -1px; left: -1px; border-bottom-width: 1.5px; border-left-width: 1.5px; }
.crop.br { bottom: -1px; right: -1px; border-bottom-width: 1.5px; border-right-width: 1.5px; }

/* ---------- upload stage ---------- */
.stage-upload {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1.2rem; padding: 2rem;
}
.drop {
  position: relative; width: min(680px, 92vw); padding: 4.2rem 2.5rem 3.6rem;
  text-align: center; cursor: pointer; background: var(--card);
  border: 1.5px dashed var(--ink-soft); border-radius: 2px;
  box-shadow: var(--shadow);
  transition: border-color .15s ease, background .15s ease;
  animation: rise .45s ease both;
}
.drop:hover, .drop:focus-visible, .drop.dragover { border-color: var(--mag); background: #fffdf8; outline: none; }
.drop.dragover { border-style: solid; }
.drop-mark { width: 44px; height: 44px; color: var(--mag); margin-bottom: 1.2rem; opacity: .9; }
.drop.dragover .drop-mark { animation: spin 2.4s linear infinite; }
.drop-title { font-family: var(--font-display); font-size: 2.3rem; line-height: 1.05; }
.drop-sub { margin-top: .5rem; color: var(--ink-soft); font-size: .95rem; }
.linkish { color: var(--mag); text-decoration: underline; text-underline-offset: 3px; }
.drop-hint { margin-top: 1.6rem; color: var(--ink-soft); line-height: 1.7; }
.upload-status { color: var(--mag); min-height: 1.2em; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- workspace ---------- */
.stage-work {
  flex: 1; min-height: 0;
  display: grid; gap: 1.1rem; padding: 1.1rem 1.6rem 1.4rem;
  grid-template-columns: 240px minmax(0, 1fr) 300px;
}
.pane { display: flex; flex-direction: column; min-height: 0; animation: rise .4s ease both; }
.pane-pages { animation-delay: .03s; }
.pane-preview { animation-delay: .08s; }
.pane-layers { animation-delay: .13s; }

.pane-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; border-bottom: 1.5px solid var(--ink); padding-bottom: .45rem; margin-bottom: .7rem; }
.pane-head h2 { font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; }
.pane-head-actions { display: flex; gap: .4rem; }
.pane-note { color: var(--ink-soft); }
#pageCount { margin-bottom: .6rem; }
.preview-pageno { color: var(--mag); }

/* thumbnails */
.thumb-grid { overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; padding: 2px 6px 2px 2px; align-content: start; }
.thumb {
  position: relative; background: var(--card); border: 1.5px solid var(--rule);
  border-radius: 2px; cursor: pointer; padding: .35rem .35rem 1.5rem;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.thumb:hover { border-color: var(--ink-soft); }
.thumb.current { border-color: var(--mag); box-shadow: 2px 2px 0 var(--mag); }
.thumb canvas { width: 100%; display: block; background: #fff; }
.thumb.excluded canvas { opacity: .3; filter: grayscale(1); }
.thumb-no { position: absolute; left: .45rem; bottom: .22rem; font-family: var(--font-mono); font-size: .68rem; color: var(--ink-soft); }
.thumb.excluded .thumb-no { text-decoration: line-through; }
.thumb-custom { position: absolute; right: 1.6rem; bottom: .3rem; width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); display: none; }
.thumb.customized .thumb-custom { display: block; }
.thumb-check {
  position: absolute; right: .35rem; bottom: .18rem;
  width: 15px; height: 15px; accent-color: var(--mag); cursor: pointer;
}

/* preview */
.pane-preview { align-items: stretch; }
.preview-frame {
  position: relative; flex: 1; min-height: 0; margin: 4px;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper-deep);
  border: 1.5px solid var(--rule); border-radius: 2px; padding: 22px;
}
#previewCanvas { max-width: 100%; max-height: 100%; background: #fff; box-shadow: var(--shadow); }
.preview-excluded {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(243,239,230,.82); color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .22em; font-size: .8rem;
}

/* layers: collapsible per-page-range sections */
.individual-toggle {
  display: flex; align-items: center; gap: .4rem; color: var(--ink-soft);
  cursor: pointer; user-select: none; text-transform: uppercase; letter-spacing: .08em;
}
.individual-toggle input { width: 15px; height: 15px; accent-color: var(--mag); cursor: pointer; }

.layer-sections { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; min-height: 0; padding: 2px; }

.sec { background: var(--card); border: 1.5px solid var(--rule); border-radius: 2px; }
.sec[open] { border-color: var(--ink-soft); }
.sec summary {
  list-style: none; display: flex; align-items: baseline; justify-content: space-between;
  gap: .6rem; padding: .6rem .75rem; cursor: pointer; user-select: none;
}
.sec summary::-webkit-details-marker { display: none; }
.sec summary::before {
  content: "▸"; color: var(--mag); font-size: .7rem; margin-right: .15rem;
  display: inline-block; transition: transform .12s ease; align-self: center;
}
.sec[open] summary::before { transform: rotate(90deg); }
.sec-title { font-weight: 600; font-size: .9rem; flex: 1; }
.sec-count { color: var(--ink-soft); white-space: nowrap; }
.sec-body { padding: .1rem .6rem .6rem; display: flex; flex-direction: column; gap: .4rem; }
.sec-tools { display: flex; gap: .45rem; margin-bottom: .15rem; }
.sec-tools .btn { flex: 1; }

.btn-link {
  background: none; border: none; cursor: pointer; width: 100%;
  color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px;
  padding: .55rem 0 .1rem; letter-spacing: .04em;
}
.btn-link:hover { color: var(--mag); }
.btn-link:disabled { opacity: .45; cursor: not-allowed; }

.layer-row {
  display: flex; align-items: center; gap: .6rem;
  background: var(--paper); border: 1.5px solid var(--rule); border-radius: 2px;
  padding: .5rem .65rem; cursor: pointer; user-select: none;
  transition: border-color .12s ease;
}
.layer-row:hover { border-color: var(--ink-soft); }
.layer-row input { width: 16px; height: 16px; accent-color: var(--mag); flex: none; cursor: pointer; }
.layer-row .swatch { flex: none; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); }
.layer-row.off .swatch { background: transparent; opacity: .35; }
.layer-row.on .swatch { background: var(--mag); border-color: var(--mag); }
.layer-name { font-size: .88rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row.off .layer-name { color: var(--ink-soft); text-decoration: line-through; text-decoration-thickness: 1px; }
.layer-empty { color: var(--ink-soft); font-size: .85rem; line-height: 1.6; padding: .4rem .1rem; }

.generate-block { margin-top: 1rem; border-top: 1.5px solid var(--ink); padding-top: 1rem; }
.letter-toggle {
  display: flex; align-items: center; gap: .5rem; cursor: pointer; user-select: none;
  color: var(--ink-soft); padding: 0 0 .7rem; letter-spacing: .03em;
}
.letter-toggle input { width: 16px; height: 16px; accent-color: var(--mag); flex: none; cursor: pointer; }
.letter-toggle em { font-style: normal; opacity: .7; }
.generate-note { margin-top: .5rem; color: var(--ink-soft); min-height: 1.1em; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: .7rem 1.2rem;
  border-radius: 2px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw;
}
.toast.error { background: var(--mag); }

/* print: on iOS/Safari the app prints #printRoot page images instead of a
   PDF iframe — hide the whole UI and show only the rendered pages */
#printRoot { display: none; }
@media print {
  body > *:not(#printRoot) { display: none !important; }
  #printRoot { display: block; }
  #printRoot img { display: block; page-break-after: always; break-inside: avoid; }
  @page { margin: 0; }
}

/* responsive: single column, pages as a horizontal filmstrip,
   generate button sticky at the bottom */
@media (max-width: 980px) {
  body { height: auto; }
  .masthead { flex-wrap: wrap; padding: .8rem 1rem .7rem; row-gap: .3rem; }
  .masthead h1 { font-size: 1.5rem; }
  .masthead-tag { display: none; }
  #docName { max-width: 46vw; }

  .stage-work {
    grid-template-columns: 1fr; grid-template-rows: none;
    padding: .8rem .9rem 1rem; overflow: visible;
  }
  .pane { min-height: auto; }

  .thumb-grid {
    display: flex; overflow-x: auto; overflow-y: hidden;
    gap: .6rem; padding-bottom: .5rem; -webkit-overflow-scrolling: touch;
  }
  .thumb { flex: 0 0 96px; }

  .preview-frame { min-height: 48vh; padding: 14px; }

  .drop { padding: 3rem 1.2rem 2.6rem; }
  .drop-title { font-size: 1.7rem; }
  .drop-hint br { display: none; }

  /* comfortable touch targets */
  .btn { padding: .65rem 1rem; }
  .btn-mini { padding: .5rem .7rem; }
  .sec summary { padding: .8rem .75rem; }
  .layer-row { padding: .7rem .65rem; }
  .layer-row input, .thumb-check, .individual-toggle input { width: 20px; height: 20px; }

  .layer-sections { overflow-y: visible; }
  .generate-block {
    position: sticky; bottom: 0; z-index: 10;
    background: var(--paper); padding-bottom: .7rem;
    margin-left: -.2rem; margin-right: -.2rem; padding-left: .2rem; padding-right: .2rem;
  }
}
