/* Interface. The preview area is a binder's cutting mat; the panel is the
   worksheet beside it. */

:root {
  --mat: #2b5a4d;
  --mat-line: #37695b;
  --mat-deep: #214a3f;
  --sheet: #f5f6f2;
  --rule: #d9dcd3;
  --ink: #171a1d;
  --soft: #5a625c;
  --navy: #1f2a44;
  --foil: #d0a94e;
  --warn: #9c2f25;
  --ui: "Heebo", system-ui, sans-serif;
  --serif: "Frank Ruhl Libre", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 var(--ui); color: var(--ink); background: var(--sheet); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { display: grid; grid-template-columns: 372px minmax(0, 1fr); height: 100vh; }

/* ---- panel ---- */
#panel { overflow-y: auto; background: var(--sheet); border-right: 1px solid var(--rule); padding: 0 20px 28px; }
.brand { padding: 22px 0 16px; border-bottom: 2px solid var(--ink); }
.brand-name { font-family: var(--serif); font-weight: 900; font-size: 42px; line-height: 1; letter-spacing: -0.02em; }
.brand p { margin: 8px 0 0; color: var(--soft); font-size: 13px; max-width: 30ch; }

.grp { padding: 16px 0 18px; border-bottom: 1px solid var(--rule); display: grid; gap: 10px; }
.grp h2 { font-family: var(--serif); font-weight: 700; font-size: 19px; margin: 0 0 2px; }
.lbl { display: block; font-size: 12px; color: var(--soft); margin-bottom: 3px; }
label { display: block; min-width: 0; }
.row { display: grid; gap: 10px; }
.row.two { grid-template-columns: 1fr 1fr; }
.row.font { grid-template-columns: 1fr 68px; }
select, input[type="text"], input[type="number"], input[type="search"] {
  width: 100%; height: 34px; padding: 0 9px; background: #fff; border: 1px solid #bfc4b9; border-radius: 3px; min-width: 0;
}
select { padding-right: 4px; text-overflow: ellipsis; }
input[type="range"] { width: 100%; accent-color: var(--mat); }
select:focus-visible, input:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--mat); outline-offset: 1px; }
.chk { display: flex; gap: 8px; align-items: baseline; font-size: 13.5px; cursor: pointer; }
.chk input { accent-color: var(--mat); flex: none; transform: translateY(1px); }
.hint { margin: 0; font-size: 12.5px; color: var(--soft); }
output { color: var(--ink); font-weight: 600; }

.combo { position: relative; }
#search { height: 40px; font-size: 15px; border-color: var(--ink); }
#results {
  position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin: 3px 0 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--ink); border-radius: 3px; max-height: 320px; overflow: auto;
  box-shadow: 0 10px 24px rgba(23, 26, 29, 0.18);
}
#results li { padding: 7px 9px; border-radius: 2px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
#results li small { color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#results li[aria-selected="true"], #results li:hover { background: #e6ece6; }
#results li.none { color: var(--soft); cursor: default; background: none; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.quick button { border: 1px solid #bfc4b9; background: #fff; border-radius: 3px; padding: 4px 8px; font-size: 12.5px; cursor: pointer; }
.quick button:hover { border-color: var(--ink); }
.quick [lang="he"] { font-family: var(--serif); font-size: 14px; font-weight: 500; }
.picked { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 9px 12px; background: var(--navy); color: var(--foil); border-radius: 3px; }
#picked-he { font-family: var(--serif); font-weight: 700; font-size: 22px; line-height: 1.1; }
#picked-en { font-family: var(--serif); font-size: 14px; text-align: right; }
#book-box { display: grid; gap: 10px; }

.comm-list { display: grid; gap: 5px; }
.comm { justify-content: flex-start; }
.comm span:first-of-type { flex: 1; }
.comm [lang="he"] { font-family: var(--serif); font-size: 15px; color: var(--soft); }
#comm-opts { display: grid; gap: 10px; }
.link { white-space: nowrap; background: none; border: 0; padding: 0; color: var(--mat-deep); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; justify-self: start; }

.specimen { background: #fff; border: 1px solid var(--rule); padding: 10px 12px; display: grid; gap: 4px; overflow: hidden; white-space: nowrap; }

.styles { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid #bfc4b9; border-radius: 3px; overflow: hidden; background: #fff; }
.styles button { border: 0; background: none; padding: 7px 2px; font-size: 12.5px; cursor: pointer; border-left: 1px solid #bfc4b9; }
.styles button:first-child { border-left: 0; }
.styles button[aria-checked="true"] { background: var(--navy); color: var(--foil); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.3); background: var(--sw); cursor: pointer; padding: 0; }
.swatches button[aria-checked="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }
.custom-color { width: 26px; height: 26px; border-radius: 50%; overflow: hidden; border: 1px dashed var(--soft); position: relative; background: conic-gradient(#c33, #cc3, #3a3, #3cc, #33c, #c3c, #c33); }
.custom-color input { position: absolute; inset: -6px; width: 40px; height: 40px; opacity: 0; cursor: pointer; }

.foot { padding-top: 14px; font-size: 12px; color: var(--soft); display: grid; gap: 8px; }
.foot p { margin: 0; }
.foot a { color: inherit; }

/* ---- stage ---- */
#stage { display: grid; grid-template-rows: auto auto minmax(0, 1fr); min-width: 0; position: relative; background: var(--mat); }
#summary { position: relative; display: flex; align-items: center; gap: 18px; padding: 16px 24px 15px; background: var(--sheet); border-bottom: 1px solid var(--rule); }
.sum-text { min-width: 0; flex: 1; }
.sum-main { font-family: var(--serif); font-weight: 700; font-size: 30px; line-height: 1.1; }
.sum-sub { color: var(--soft); margin-top: 3px; font-size: 13.5px; max-width: 78ch; }
.primary { background: var(--navy); color: var(--foil); border: 0; border-radius: 3px; padding: 10px 16px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.primary:hover { background: #172036; }
.ghost { background: #fff; color: var(--ink); border: 1px solid var(--ink); border-radius: 3px; padding: 9px 16px; font-weight: 600; cursor: pointer; }
#parts-box { display: grid; gap: 5px; }
.bar { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: transparent; }
.bar i { display: block; height: 100%; width: 0; background: var(--foil); transition: width 0.2s ease-out; }

.tabs { display: flex; align-items: center; gap: 2px; padding: 0 16px; background: var(--mat-deep); color: #e8efe9; min-height: 42px; flex-wrap: wrap; }
.tabs [role="tab"] { background: none; border: 0; color: inherit; padding: 11px 12px 9px; cursor: pointer; border-bottom: 3px solid transparent; opacity: 0.75; font-weight: 500; }
.tabs [role="tab"][aria-selected="true"] { border-bottom-color: var(--foil); opacity: 1; }
.tabs .spacer { flex: 1; }
.tabs label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; margin-left: 14px; }
.tabs select { height: 28px; width: auto; max-width: 210px; background: var(--mat); color: #fff; border-color: var(--mat-line); }
.tabs .volpick button { width: 26px; height: 28px; background: var(--mat); color: #fff; border: 1px solid var(--mat-line); border-radius: 3px; cursor: pointer; line-height: 1; }
.tabs input[type="range"] { width: 110px; accent-color: var(--foil); }

#mat {
  --zoom: 1.25; overflow: auto; position: relative;
  background-color: var(--mat);
  background-image:
    linear-gradient(var(--mat-line) 1px, transparent 1px), linear-gradient(90deg, var(--mat-line) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 96px 96px, 96px 96px, 19.2px 19.2px, 19.2px 19.2px;
}
.busy #mat .view { opacity: 0.6; transition: opacity 0.15s; }
.view { padding: 22px 26px 60px; }
.zoomed { zoom: var(--zoom); }
.mat-note { color: #dfe9e2; margin: 0 0 16px; font-size: 13px; max-width: 80ch; }

.spreads { display: flex; flex-wrap: wrap; gap: 9mm 8mm; align-items: flex-start; }
.spreads.rtl { flex-direction: row-reverse; justify-content: flex-end; }
.spread { display: flex; box-shadow: 0 1.2mm 3.5mm rgba(0, 0, 0, 0.35); background: transparent; content-visibility: auto; contain-intrinsic-size: calc(var(--pw) * 2) var(--ph); }
.leaf { width: var(--pw); height: var(--ph); position: relative; background: #fff; }
.leaf.none { background: transparent; visibility: hidden; }
.leaf + .leaf::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3mm; background: linear-gradient(90deg, rgba(0, 0, 0, 0.13), transparent); pointer-events: none; z-index: 1; }
.spread .leaf:first-child::after { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 3mm; background: linear-gradient(270deg, rgba(0, 0, 0, 0.1), transparent); pointer-events: none; z-index: 1; }

.shelf-box, .wrap-box { margin-bottom: 26px; }
.shelf-box h3, .wrap-box h3 { color: #eef4ef; font-family: var(--serif); font-size: 18px; margin: 0 0 12px; font-weight: 500; }
.shelf { display: flex; align-items: flex-end; gap: 0.25mm; padding: 0 0 2mm; border-bottom: 2.2mm solid #7b5a3a; width: max-content; max-width: none; }
.shelf.rtl { flex-direction: row-reverse; }
.shelf-spine { overflow: hidden; position: relative; flex: none; box-shadow: inset 0.35mm 0 0.5mm rgba(255, 255, 255, 0.16), inset -0.35mm 0 0.6mm rgba(0, 0, 0, 0.3), 0 0.6mm 1.5mm rgba(0, 0, 0, 0.3); border-radius: 0.4mm; }
.cover-grid { display: flex; flex-wrap: wrap; gap: 9mm 8mm; }
.cover-fig { margin: 0; }
.cover-fig .cover { box-shadow: 0 1.2mm 3.5mm rgba(0, 0, 0, 0.35); }
.cover-fig figcaption { color: #dfe9e2; font: 3.1mm/1.3 var(--ui); margin-top: 2mm; }

.print-card { background: var(--sheet); border-radius: 4px; padding: 20px 24px; max-width: 760px; margin-bottom: 18px; }
.print-card h3 { font-family: var(--serif); font-size: 21px; margin: 0 0 10px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 9px; }
.fine { color: var(--soft); font-size: 12.5px; margin: 14px 0 0; }
.print-card .all { margin: 0 0 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.print-card button:not(.link):not(.primary) { background: #fff; border: 1px solid var(--ink); border-radius: 3px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.print-card button:not(.link):not(.primary):hover { background: #e6ece6; }
.print-table { border-collapse: collapse; width: 100%; }
.print-table th, .print-table td { padding: 8px 10px 8px 0; border-top: 1px solid var(--rule); text-align: left; vertical-align: middle; }
.print-table th { font-weight: 600; width: 99%; }
.print-table th small { display: block; font-weight: 400; color: var(--soft); }

.empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 18px; color: #dfe9e2; text-align: center; padding: 24px; }
.empty-book { width: 134px; height: 210px; background: #fff; box-shadow: 0 5px 14px rgba(0, 0, 0, 0.35); display: grid; place-items: center; transform: rotate(-3deg); }
.empty-book span { font-family: var(--serif); font-weight: 900; font-size: 120px; line-height: 1; color: var(--navy); }
.empty p { margin: 0; max-width: 30ch; }

#error { position: absolute; left: 24px; right: 24px; bottom: 20px; background: #fff; border-left: 5px solid var(--warn); padding: 12px 16px; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3); max-width: 720px; z-index: 30; }

#measure { position: absolute; left: -100000px; top: 0; visibility: hidden; pointer-events: none; }

@media (max-width: 860px) {
  #app { display: block; height: auto; }
  #panel { border-right: 0; overflow: visible; padding: 0 16px 20px; }
  #stage { min-height: 100vh; }
  #summary { flex-wrap: wrap; padding: 14px 16px; position: sticky; top: 0; z-index: 10; }
  .sum-main { font-size: 24px; }
  .view { padding: 16px 16px 60px; }
  .tabs { padding: 0 8px; }
  .tabs .zoom span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .bar i, .busy #mat .view { transition: none; }
}
