:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #1d2230;
  --muted: #6b7180;
  --line: #e3ddd2;
  --accent: #2547d0;
  --accent-ink: #ffffff;
  --accent-soft: rgba(37, 71, 208, .1);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 10px 30px rgba(0, 0, 0, .07);
  --on: #1fae5b;
  --off: #c9cdd6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1c1f26;
    --surface-2: #23262e;
    --ink: #e7e8eb;
    --muted: #9aa0ab;
    --line: #2f333c;
    --accent: #7c93ff;
    --accent-ink: #0e1120;
    --accent-soft: rgba(124, 147, 255, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
    --on: #2fc56f;
    --off: #4a4f5b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- header ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.logo { font-size: 22px; }
.name { font-size: 20px; letter-spacing: -.01em; }
.name b { color: var(--accent); }
.badge {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}
.tagline { margin: 0; color: var(--muted); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 24px;
  padding: 20px 24px;
  max-width: 1500px;
  margin: 0 auto;
}
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  position: sticky;
  top: 20px;
  align-self: start;
  padding-right: 4px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 16px;
  box-shadow: var(--shadow);
}
.card[open] { padding-bottom: 14px; }
.card > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 650;
  padding: 13px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
.card:not([open]) > summary::after { transform: rotate(-90deg); }

/* ---------- form controls ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.lbl {
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.lbl output { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--ink); }

textarea, select, input[type="number"], input[type="text"] {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}
textarea { resize: vertical; min-height: 200px; line-height: 1.45; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
:is(textarea, select, input, button):focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.help { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.help code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 11.5px; }
.meta { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }

.toolbar, .presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

button {
  font: inherit;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .6; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip { padding: 5px 10px; font-size: 12.5px; font-weight: 550; border-radius: 999px; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* font picker */
.fonts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  max-height: 248px;
  overflow-y: auto;
  margin-bottom: 12px;
  padding: 2px;
}
.font-opt {
  text-align: left;
  padding: 6px 10px;
  font-weight: 400;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 58px;
}
.font-opt .sample { font-size: 22px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-opt .fname { font: 11px/1.3 system-ui, sans-serif; color: var(--muted); }
.font-opt[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }

/* ink swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 2px; }
.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  padding: 0;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--accent); }
.swatch.custom { background: conic-gradient(#e33, #ec3, #3c5, #3ae, #63e, #e3a, #e33); }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.margins {
  border: 0;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.margins legend { margin-bottom: 6px; }
.margins label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.margins input { padding: 6px 8px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.status { min-height: 1.5em; margin: 10px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- preview ---------- */
.preview { min-width: 0; }
.preview-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 0 12px;
  margin-bottom: 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.preview-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.preview-bar .meta { margin: 0; font-weight: 600; color: var(--ink); }
.status { font-size: 13px; color: var(--muted); min-height: 1.3em; }
.status.error { color: #c0392b; }
.status button.link { margin-left: 6px; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 30px; padding: 12px 0 28px; }
.page { width: 100%; max-width: 900px; position: relative; background: #fff; border-radius: 3px; box-shadow: var(--shadow); }
.page canvas { display: block; width: 100%; height: 100%; border-radius: 3px; }
.page .pno { position: absolute; right: 0; bottom: -21px; font-size: 12px; color: var(--muted); }
.page.loading::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.035), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- upload ---------- */
.upload-card { padding: 14px 16px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 112px; padding: 14px;
  border: 2px dashed var(--accent);
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 10px;
  background: var(--accent-soft);
  text-align: center;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone.busy { cursor: progress; opacity: .75; }
.drop-icon { font-size: 26px; line-height: 1.2; }
.drop-title { font-weight: 700; font-size: 15.5px; color: var(--accent); }
.drop-hint { font-size: 12.5px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13.5px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.check-inline { margin-top: 22px; }
.pen-toggle { margin: 0 0 12px; align-items: flex-start; line-height: 1.4; }
.pen-toggle input { margin-top: 2px; }
.muted { color: var(--muted); font-size: 12px; }
button.link {
  border: 0; background: none; padding: 0; color: var(--accent);
  font: inherit; font-size: 12px; font-weight: 600; text-transform: none; letter-spacing: 0; text-decoration: underline; cursor: pointer;
}

.drag-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(20, 30, 80, .45);
  background: color-mix(in srgb, var(--accent) 22%, rgba(0,0,0,.35));
  backdrop-filter: blur(2px);
}
.drag-overlay[hidden] { display: none; }
.drag-overlay div {
  padding: 28px 36px; border-radius: 16px; background: var(--surface); color: var(--ink);
  font-size: 18px; font-weight: 700; border: 3px dashed var(--accent); box-shadow: var(--shadow);
}

/* ---------- on/off switches (green = on) ---------- */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 10px 12px; margin: 0 0 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.switch-row:hover { border-color: color-mix(in srgb, var(--on) 50%, var(--line)); }
.switch-row:has(.switch:checked) { border-color: color-mix(in srgb, var(--on) 55%, var(--line)); background: color-mix(in srgb, var(--on) 7%, var(--surface-2)); }
.switch-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch-text b { font-size: 14px; font-weight: 650; }
.switch-text small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; position: relative; margin: 0;
  width: 46px; height: 27px; border-radius: 999px;
  background: var(--off); cursor: pointer;
  transition: background .2s ease;
}
.switch::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .2s ease;
}
.switch:checked { background: var(--on); }
.switch:checked::before { transform: translateX(19px); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .switch, .switch::before { transition: none; } }

/* ---------- section summaries ---------- */
.card > summary { gap: 10px; }
.sum-title { white-space: nowrap; }
.sum-val {
  margin-left: auto; min-width: 0;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip-undo { border-color: var(--accent); color: var(--accent); }

/* ---------- step guide ---------- */
.steps {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.steps li {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.steps span {
  flex: none; display: grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 11px;
}

/* nicer range sliders */
input[type="range"] { height: 22px; cursor: pointer; }

/* ---------- preview mode switch ---------- */
.segmented {
  display: inline-grid; grid-auto-flow: column; gap: 4px; padding: 4px; margin: 4px 0 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.segmented button { border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; font-size: 13.5px; }
.segmented button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
body[data-mode="sim"] #pages { display: none; }

/* ---------- print check ---------- */
.sim { padding: 6px 0 30px; }
.sim[hidden] { display: none; }
.sim-intro { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; }
.sim-controls {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 14px 2px; box-shadow: var(--shadow);
}
.sim-controls .field { margin-bottom: 12px; }
.field[hidden] { display: none; }
.sim-controls input[type="number"] { padding: 8px 10px; }
.sim-switch { margin: 12px 0; background: var(--surface); }
.hint {
  display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%;
  background: var(--line); color: var(--ink); font-size: 10px; cursor: help; text-transform: none;
}
.sim-advice {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 10px 14px; margin: 0 0 12px; border-radius: 10px;
  background: #fff7e0; border: 1px solid #f0d27a; color: #5c4400; font-size: 13.5px;
}
@media (prefers-color-scheme: dark) { .sim-advice { background: #3a3218; border-color: #7a6526; color: #f3e2a8; } }
.sim-advice[hidden] { display: none; }
.sim-advice button { padding: 6px 12px; font-size: 13px; }
.sim-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.sim-nav .meta { margin: 0; min-width: 90px; text-align: center; }
.sim-nav button { padding: 7px 12px; }
.sim-spacer { flex: 1; }
.sim-summary { margin: 0 0 12px; font-size: 13.5px; }
.sim-stage {
  background: #7d8086; /* neutral grey desk so the white of the paper is visible */
  background: repeating-linear-gradient(45deg, #7b7e84 0 10px, #777a80 10px 20px);
  border-radius: 12px; padding: 28px; overflow: auto; max-height: 85vh;
  display: flex; justify-content: center; align-items: flex-start;
}
.sim-sheet { position: relative; flex: none; box-shadow: 0 2px 6px rgba(0,0,0,.35), 0 18px 40px rgba(0,0,0,.35); background: #fff; }
.sim-sheet canvas { display: block; width: 100%; height: 100%; }
.sim-sheet.busy::after {
  content: "Printing…"; position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(255,255,255,.6); color: #333; font-weight: 700;
}
.sim-area { position: absolute; border: 1.5px dashed rgba(220, 40, 40, .85); pointer-events: none; }
.sim-area[hidden] { display: none; }
@media (max-width: 420px) {
  .sim-stage { padding: 12px; }
  .sim-controls { grid-template-columns: 1fr 1fr; }
}

/* ---------- picker buttons (show the current choice; open a window) ---------- */
.pickers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.picker-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  text-align: left; padding: 10px 12px; min-height: 66px; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; position: relative;
}
.picker-btn::after { content: "\25BE"; position: absolute; right: 10px; top: 10px; color: var(--muted); font-size: 12px; }
.picker-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.pb-label { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.pb-value { display: flex; align-items: center; gap: 8px; font-size: 14px; min-width: 0; max-width: 100%; }
.pb-value > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-font { font-size: 22px; line-height: 1.1; }
.pb-swatch { width: 18px; height: 18px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--line); }
.pb-thumb { width: 22px; height: 30px; border-radius: 2px; box-shadow: 0 0 0 1px var(--line); flex: none; }

/* ---------- marks toolbar ---------- */
.formatbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0 0 8px; }
.fb-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.fb { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; font-size: 14px; font-weight: 600; border-radius: 7px; }
.fb .sw { width: 16px; height: 12px; border-radius: 3px; }

/* ---------- floating windows ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px;
  background: rgba(15, 18, 30, .5); backdrop-filter: blur(3px);
  animation: fadeIn .15s ease;
}
.modal-backdrop[hidden] { display: none; }
body.modal-open { overflow: hidden; }
.modal {
  width: min(920px, 100%); max-height: min(88vh, 900px); display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink); border-radius: 16px; border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0,0,0,.35); overflow: hidden; animation: popIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@media (prefers-reduced-motion: reduce) { .modal, .modal-backdrop { animation: none; } }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 8px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-head p { margin: 4px 0 0; font-size: 13px; }
.modal-x { border: 0; background: transparent; font-size: 18px; padding: 4px 8px; color: var(--muted); }
.modal-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 4px 20px 10px; border-bottom: 1px solid var(--line); }
.modal-tools[hidden] { display: none; }
.modal-search { flex: 1 1 220px; font: inherit; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.modal-body { padding: 14px 20px; overflow-y: auto; flex: 1; }
.modal-body .segmented { margin: 0 0 12px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
.modal-choice { flex: 1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-foot .primary { min-width: 110px; }

.pick-section h3 { margin: 4px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.pick-section + .pick-section { margin-top: 16px; }
.pick-grid { display: grid; gap: 10px; }
.grid-fonts { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid-swatches { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid-thumbs { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.grid-scenes { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid-sizes { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); align-items: end; }
.pick {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 12px; text-align: left; font-weight: 400; border-radius: 12px;
  background: var(--surface-2); border: 1.5px solid var(--line);
}
.pick:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.pick[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent) inset; }
.pick[aria-checked="true"]::before {
  content: "\2713"; position: absolute; right: 8px; bottom: 8px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; display: grid; place-items: center;
}
.pick-sample { font-size: 26px; line-height: 1.25; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 22px; }
.pick-sample.small { font-size: 22px; }
.pick-name { font-size: 12.5px; color: var(--muted); }
.star { position: absolute; top: 6px; right: 8px; font-size: 18px; color: var(--muted); cursor: pointer; line-height: 1; padding: 2px; }
.star.on { color: #f2b01e; }
.pick-dot { width: 34px; height: 34px; border-radius: 50%; box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--line); }
.pick-color { width: 100%; height: 30px; border: 0; padding: 0; background: none; cursor: pointer; }
.pick-thumb { width: 100%; height: auto; border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.18); background: #fff; }
.pick-scene { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 6px; background: #ccc; }
.pick-page { display: block; background: #fff; border: 1px solid var(--line); border-radius: 2px; box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.pick-empty { padding: 30px; text-align: center; }
.shortcuts { border-collapse: collapse; width: 100%; }
.shortcuts td { padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
kbd { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 2px 7px; }

@media (max-width: 600px) {
  .modal-backdrop { padding: 0; place-items: end stretch; }
  .modal { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .grid-fonts { grid-template-columns: 1fr; }
  .grid-thumbs { grid-template-columns: repeat(3, 1fr); }
  .grid-scenes { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- laptop & desktop: app layout with separately scrolling panes ---------- */
:root { --side-w: clamp(330px, 27vw, 460px); --header-h: 52px; }
.segmented.zoom button { padding: 7px 11px; font-size: 13px; }
.segmented.zoom button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
@media screen and (min-width: 901px) {
  html, body { height: 100%; }
  body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
  .topbar { flex: none; padding: 9px 20px; min-height: var(--header-h); align-items: center; }
  .layout {
    flex: 1; min-height: 0; max-width: none; margin: 0; padding: 0; gap: 0;
    grid-template-columns: var(--side-w) minmax(0, 1fr);
  }
  .sidebar {
    position: static; top: auto; max-height: none; height: 100%; overflow-y: auto; overscroll-behavior: contain;
    padding: 14px 14px 24px 16px; border-right: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 70%, var(--surface));
  }
  .preview { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 0 22px 20px; scroll-padding-top: 70px; }
  .preview-bar { top: 0; padding: 10px 0; margin-bottom: 4px; gap: 8px 12px; flex-wrap: wrap; justify-content: flex-start; }
  .preview-bar .segmented { margin: 0; }
  .preview-bar .preview-info { flex: 1 1 160px; }
  .preview-bar > .actions { margin-left: auto; }
  .foot { display: none; }
  .upload-card { padding: 12px 14px; }
  .dropzone { min-height: 86px; padding: 10px; }
  .drop-icon { font-size: 22px; }
  /* Fit page: whole pages, side by side when there is room */
  .pages[data-zoom="page"] { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 34px 26px; }
  .pages[data-zoom="page"] .page { width: auto; height: var(--fit-h, 78vh); max-width: none; flex: none; }
  .pages[data-zoom="width"] .page { max-width: min(100%, 1000px); }
  .sim-stage { max-height: none; }
}
@media screen and (min-width: 901px) and (max-width: 1180px) {
  :root { --side-w: 320px; }
  .tagline { display: none; }
}
@media screen and (min-width: 901px) and (max-width: 1439px) { .steps { display: none; } }
@media screen and (min-width: 901px) and (max-height: 760px) {
  .steps { display: none; }
  .card > summary { padding: 10px 0; }
}
@media screen and (min-width: 1181px) and (max-width: 1400px) { .tagline { font-size: 13px; } }
@media screen and (min-width: 2000px) { body { font-size: 15.5px; } :root { --side-w: 480px; } }
@media (max-width: 900px) {
  .preview-bar .segmented.zoom { display: none; }
}

/* mobile tabs (hidden on wide screens) */
.tabs { display: none; }

.print-area { display: none; }

.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 6px 24px 28px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px 16px; }
  .sidebar { min-width: 0; }
  .steps li { font-size: 11px; padding: 4px 6px; gap: 4px; }
  .sidebar { position: static; max-height: none; overflow: visible; padding-right: 0; }
  .topbar { padding: 12px 16px; }
  .tagline { display: none; }
  .tabs {
    display: grid; grid-template-columns: 1fr 1fr;
    position: sticky; top: 0; z-index: 10;
    background: var(--bg); border-bottom: 1px solid var(--line);
    padding: 8px 16px; gap: 8px;
  }
  .tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  body[data-view="edit"] .preview { display: none; }
  body[data-view="preview"] .sidebar { display: none; }
  .preview-bar { top: 53px; }
  .layout { padding-top: 12px; }
}
@media (max-width: 420px) {
  .margins { grid-template-columns: repeat(2, 1fr); }
  .font-opt .sample { font-size: 19px; }
  .preview-bar .actions { width: 100%; }
  .preview-bar .actions button { flex: 1; }
}

/* ---------- print: only the rendered pages ---------- */
@media print {
  body { background: #fff; margin: 0; }
  /* Our Print button: high-resolution page images. */
  body.print-images > *:not(.print-area) { display: none !important; }
  body.print-images .print-area { display: block !important; }
  .print-area img {
    display: block; width: var(--print-w); height: var(--print-h);
    break-after: page; page-break-after: always;
  }
  .print-area img:last-child { break-after: auto; page-break-after: auto; }
  /* Fallback (browser menu → Print): the preview pages. */
  body:not(.print-images) .topbar, body:not(.print-images) .tabs, body:not(.print-images) .sidebar,
  body:not(.print-images) .preview-bar, body:not(.print-images) .foot, body:not(.print-images) .pno,
  body:not(.print-images) .drag-overlay { display: none !important; }
  body:not(.print-images) .preview { display: block !important; }
  body:not(.print-images) .layout { display: block; padding: 0; max-width: none; }
  body:not(.print-images) .pages { display: block; padding: 0; }
  body:not(.print-images) .page {
    width: var(--print-w); height: var(--print-h); max-width: none; box-shadow: none; border-radius: 0;
    break-after: page; page-break-after: always;
  }
  body:not(.print-images) .page:last-child { break-after: auto; page-break-after: auto; }
}
body[data-mode="sim"] .segmented.zoom { display: none; }

/* Print check on laptops: settings column on the left, the printed sheet on the right */
@media screen and (min-width: 1100px) {
  .sim-cols { display: grid; grid-template-columns: minmax(250px, 300px) minmax(0, 1fr); gap: 18px; align-items: start; }
  .sim-left .sim-controls { grid-template-columns: 1fr; }
  .sim-left .sim-switch { margin: 12px 0; }
  .sim-stage { padding: 20px; }
}
@media screen and (min-width: 1700px) {
  .sim-cols { grid-template-columns: 420px minmax(0, 1fr); }
  .sim-left .sim-controls { grid-template-columns: 1fr 1fr; }
}
