:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #dfe2ec;
  --text: #171a26;
  --muted: #646b82;
  --accent: #4f46e5;       /* links, icons, outlines */
  --accent-fill: #4f46e5;  /* filled buttons with white text (>= 4.5:1 contrast) */
  --accent-fill-2: #4338ca;
  --accent-soft: #eceafd;
  --danger: #dc2626;
  --viewer-bg: #e6e8ef;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .08);
  --radius: 10px;
  --topbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1b1e29;
    --surface-2: #252937;
    --border: #2f3445;
    --text: #e8eaf2;
    --muted: #9aa1b7;
    --accent: #7c74ff;       /* bright enough to read on the dark background */
    --accent-fill: #635bf0;  /* dark enough for white text: 4.9:1 */
    --accent-fill-2: #5a50e8;
    --accent-soft: #2a2752;
    --viewer-bg: #0d0f15;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
button { font: inherit; color: inherit; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .4; cursor: default; }
.btn:focus-visible, .tool:focus-visible, .dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-fill-2); border-color: var(--accent-fill-2); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.icon { width: 36px; padding: 0; justify-content: center; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); text-decoration: none; font-weight: 700; font-size: 17px; }
.brand span { color: var(--text); }
.brand svg { fill: currentColor; stroke: none; }
.topbar-actions { display: flex; align-items: center; gap: 4px; min-width: 0; }
.file-name { color: var(--muted); font-size: 14px; margin-right: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28vw; }
body:not(.editing) .editor-only { display: none; }

/* ---------- Landing ---------- */
.landing { padding: 56px 16px 0; }
.hero { width: 100%; max-width: 720px; margin: 0 auto; text-align: center; }
.hero h1 { font-size: clamp(30px, 5vw, 46px); line-height: 1.15; margin: 0 0 16px; letter-spacing: -.02em; }
.hero h1 span { color: var(--accent); }
.lead { color: var(--muted); font-size: 17px; margin: 0 auto 32px; max-width: 580px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 240px; padding: 32px;
  border: 2px dashed var(--border); border-radius: 18px;
  background: var(--surface); box-shadow: var(--shadow);
  cursor: pointer; transition: border-color .15s, background .15s, transform .15s;
}
.dropzone svg { color: var(--accent); margin-bottom: 8px; }
.dropzone strong {
  background: var(--accent-fill); color: #fff; padding: 10px 24px; border-radius: 10px; font-size: 16px;
}
.dropzone span { color: var(--muted); font-size: 14px; }
.dropzone:hover, body.dragging .dropzone { border-color: var(--accent); background: var(--accent-soft); }
body.dragging .dropzone { transform: scale(1.01); }
.trust { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 28px; padding: 0; margin: 28px 0 0; color: var(--muted); font-size: 14px; }
.trust b { color: var(--text); }

/* ---------- Landing: help sections ---------- */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body.editing .landing-only { display: none; }
.landing-nav { display: flex; gap: 4px; margin-left: auto; }
.landing-nav a { color: var(--muted); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 8px; }
.landing-nav a:hover { color: var(--text); background: var(--surface-2); }

.info { max-width: 1040px; margin: 0 auto; padding: 72px 0 0; scroll-margin-top: calc(var(--topbar-h) + 8px); }
.info h2, .cta h2 { font-size: clamp(24px, 3.4vw, 32px); letter-spacing: -.015em; line-height: 1.2; margin: 0 0 24px; text-align: center; }
.info h3 { font-size: 16px; margin: 0 0 6px; }
.info p { margin: 0; color: var(--muted); }
.info p b, .limits b { color: var(--text); }
.section-lead { text-align: center; margin: -12px 0 24px !important; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.steps li, .features li {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; margin-bottom: 12px;
  border-radius: 50%; background: var(--accent-fill); color: #fff; font-weight: 700;
}

.features { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.features svg {
  width: 40px; height: 40px; padding: 9px; margin-bottom: 12px; border-radius: 10px;
  color: var(--accent); background: var(--accent-soft);
}
.features p { font-size: 14px; }
@media (min-width: 1000px) { .features { grid-template-columns: repeat(4, 1fr); } }

.notice {
  display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; margin-bottom: 16px;
  border-radius: var(--radius); border: 1px solid #f5c26b; background: #fff8e8;
}
.notice svg { flex-shrink: 0; width: 22px; height: 22px; color: #b45309; margin-top: 1px; }
.notice p { color: #713f12; }
.notice p b { color: #713f12; }
@media (prefers-color-scheme: dark) {
  .notice { border-color: #7c5a1d; background: #2a2010; }
  .notice svg { color: #fbbf24; }
  .notice p, .notice p b { color: #fde7b0; }
}
.limits {
  list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 32px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 24px;
}
.limits li { position: relative; padding: 12px 0 12px 28px; color: var(--muted); font-size: 14px; border-bottom: 1px solid var(--border); }
.limits li:nth-last-child(-n+2) { border-bottom: 0; }
.limits li::before {
  content: ""; position: absolute; left: 2px; top: 16px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--muted);
}
.limits li::after { content: ""; position: absolute; left: 6px; top: 22.25px; width: 6px; height: 1.5px; background: var(--muted); }

.keys {
  margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 24px;
}
.keys div { display: flex; align-items: center; gap: 12px; }
.keys dt { min-width: 92px; white-space: nowrap; color: var(--muted); font-size: 13px; }
.keys dd { margin: 0; font-size: 14px; }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; margin: 0 1px; text-align: center;
  font: 12px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
}

.faq { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.faq summary {
  list-style: none; cursor: pointer; padding: 16px 48px 16px 20px; position: relative; font-weight: 600;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+"; position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  font-size: 22px; font-weight: 400; color: var(--muted); transition: transform .2s;
}
.faq details[open] summary::after { transform: translateY(-50%) rotate(45deg); }
.faq summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius); }
.faq details p { padding: 0 20px 18px; }

.cta { text-align: center; padding: 80px 0 24px; }
.cta h2 { margin-bottom: 20px; }
.btn.big { height: 48px; padding: 0 28px; font-size: 16px; border-radius: 10px; }
.site-footer { margin: 56px -16px 0; padding: 24px 16px; text-align: center; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); }
.site-footer p { margin: 0; }
.footer-links { display: flex; justify-content: center; gap: 20px; margin-top: 8px; }
.footer-links a { color: var(--muted); }
.footer-links a:hover, .footer-links a[aria-current] { color: var(--text); }

/* ---------- Privacy & Terms pages ---------- */
.legal { padding: 48px 16px 0; overflow-wrap: anywhere; }
.legal > * { max-width: 760px; margin-inline: auto; }
.legal > .site-footer { max-width: none; margin-inline: -16px; }
.legal h1 { font-size: clamp(28px, 4.4vw, 38px); line-height: 1.2; letter-spacing: -.02em; margin-block: 0 4px; }
.legal h2 { font-size: 19px; margin-block: 32px 8px; }
.legal p, .legal li { color: var(--muted); }
.legal p { margin-block: 0 12px; }
.legal li + li { margin-top: 6px; }
.legal b { color: var(--text); }
.legal a { color: var(--accent); }
.legal .updated { font-size: 14px; margin-bottom: 24px; }
.legal .summary { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; color: var(--text); }

@media (max-width: 760px) {
  .landing-nav { display: none; }
  .info { padding-top: 56px; }
  .steps, .limits { grid-template-columns: 1fr; }
  .features { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .features li { padding: 14px; }
  .features p { font-size: 13px; }
  #shortcuts { display: none; } /* phones have no keyboard */
  .limits li:nth-last-child(2) { border-bottom: 1px solid var(--border); }
}

/* ---------- Editor layout ---------- */
.editor { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); }
.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool-group { display: flex; align-items: center; gap: 2px; padding-right: 8px; border-right: 1px solid var(--border); }
.tool-group:last-child { border-right: 0; margin-left: auto; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 58px; padding: 5px 6px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; font-size: 11.5px; color: var(--muted); white-space: nowrap;
}
.tool svg { width: 20px; height: 20px; color: var(--text); }
.tool:hover { background: var(--surface-2); }
.tool.active { background: var(--accent-soft); color: var(--accent); }
.tool.active svg { color: var(--accent); }
.props { gap: 8px; }
.prop { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.prop select, .prop input[type=range] { accent-color: var(--accent); }
.prop select { height: 30px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); padding: 0 6px; }
.prop input[type=range] { width: 90px; }
.fmt { width: 32px; height: 32px; font-size: 16px; font-family: Helvetica, Arial, sans-serif; }
.fmt[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.fmt[aria-pressed="true"]:hover:not(:disabled) { background: var(--accent-soft); }
.auto-match {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 11px; white-space: nowrap;
  border: 1px solid var(--border); border-radius: 999px; background: transparent; color: var(--muted);
  font-size: 12.5px; cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.auto-match svg { width: 15px; height: 15px; }
.auto-match:hover { color: var(--text); }
.auto-match[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.auto-match:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { gap: 2px; padding: 2px; border-radius: 8px; background: var(--surface-2); }
.seg button {
  display: flex; align-items: center; justify-content: center; width: 30px; height: 28px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text); cursor: pointer;
}
.seg button svg { width: 16px; height: 16px; stroke-width: 2.6; }
.seg button:hover { color: var(--accent); }
.seg button.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(16, 24, 40, .15); }
.color-pick { display: flex; width: 30px; height: 30px; border-radius: 50%; overflow: hidden; border: 2px solid var(--border); cursor: pointer; }
.color-pick input { width: 44px; height: 44px; margin: -7px; border: 0; padding: 0; cursor: pointer; background: none; }
.zoom-label { min-width: 62px; justify-content: center; font-variant-numeric: tabular-nums; font-size: 13px; padding: 0 6px; }
.sidebar-toggle, .sidebar-close, .sidebar-backdrop { display: none; }
.sidebar-head-actions { display: flex; align-items: center; gap: 4px; }

.workspace { flex: 1; display: flex; min-height: 0; }
.sidebar {
  position: relative; width: var(--sidebar-w, 196px); flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar-resizer {
  position: absolute; top: 0; bottom: 0; right: -5px; width: 10px; z-index: 5;
  cursor: col-resize; touch-action: none; outline: none;
}
.sidebar-resizer::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 4px; width: 2px;
  background: var(--accent); opacity: 0; transition: opacity .15s;
}
.sidebar-resizer:hover::after, .sidebar-resizer:focus-visible::after, body.resizing-sidebar .sidebar-resizer::after { opacity: 1; }
body.resizing-sidebar { cursor: col-resize; user-select: none; }
body.resizing-sidebar .viewer { pointer-events: none; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); }
.thumbs { list-style: none; margin: 0; padding: 12px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.thumb { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; border-radius: 8px; padding: 6px; }
.thumb:hover { background: var(--surface-2); }
.thumb.current .thumb-img { outline: 2px solid var(--accent); outline-offset: 2px; }
.thumb.drag-over-before::before, .thumb.drag-over-after::after {
  content: ""; position: absolute; left: 6px; right: 6px; height: 3px; border-radius: 2px; background: var(--accent);
}
.thumb.drag-over-before::before { top: -9px; }
.thumb.drag-over-after::after { bottom: -9px; }
.thumb.dragging { opacity: .4; }
.thumb-img { background: #fff; box-shadow: var(--shadow); border-radius: 2px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.thumb-img canvas { display: block; }
.thumb-num { font-size: 12px; color: var(--muted); }
.thumb-actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.thumb:hover .thumb-actions, .thumb:focus-within .thumb-actions { opacity: 1; }
.thumb-actions button {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 6px; background: rgba(23, 26, 38, .82); color: #fff; cursor: pointer;
}
.thumb-actions button:hover { background: var(--accent-fill); }
.thumb-actions button.del:hover { background: var(--danger); }
.thumb-actions svg { width: 15px; height: 15px; }
.hint { margin: 0; padding: 8px 12px; font-size: 12px; color: var(--muted); text-align: center; border-top: 1px solid var(--border); }

.viewer { flex: 1; overflow: auto; background: var(--viewer-bg); outline: none; position: relative; touch-action: pan-x pan-y; /* pinch is handled by the app */ }
/* Centre pages in the visible area; a page wider than the screen starts at the left edge and scrolls sideways
   ("safe"), instead of widening the column and pushing narrower pages off-centre. */
.pages { display: flex; flex-direction: column; align-items: center; align-items: safe center; gap: 20px; padding: 24px; width: 100%; }

/* ---------- Pages & annotations ---------- */
.page { position: relative; background: #fff; box-shadow: var(--shadow); flex-shrink: 0; }
.page > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.page-label { position: absolute; top: -18px; left: 0; font-size: 11px; color: var(--muted); }
.layer { position: absolute; inset: 0; overflow: hidden; touch-action: pan-x pan-y; }
.page.moving { z-index: 1; } /* an item dragged off its page shows over the other pages */
.page.moving > .layer { overflow: visible; }
.viewer[data-tool="text"] .layer { cursor: text; }
.viewer[data-tool="mark"] .layer { cursor: crosshair; }
.viewer[data-tool="mark"] .annot.mark { cursor: pointer; }
.viewer[data-tool="draw"] .layer,
.viewer[data-tool="shape"] .layer,
.viewer[data-tool="measure"] .layer,
.viewer[data-tool="highlight"] .layer,
.viewer[data-tool="whiteout"] .layer { cursor: crosshair; touch-action: none; }

.annot { position: absolute; touch-action: none; }
.viewer[data-tool="select"] .annot { cursor: move; }
.annot.selected { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.annot.text {
  white-space: pre; line-height: 1.2; padding: 0; margin: 0;
  font-family: Helvetica, Arial, sans-serif; min-width: 4px;
}
.annot.text[contenteditable] { outline: 1.5px solid var(--accent); outline-offset: 2px; cursor: text; background: rgba(79, 70, 229, .04); }
.annot.text:empty::before { content: "Type here"; color: #9aa1b7; }
.annot.highlight { mix-blend-mode: multiply; }
.annot img, .annot svg { display: block; width: 100%; height: 100%; pointer-events: none; user-select: none; }
.annot svg { overflow: visible; }
.handle {
  position: absolute; right: -7px; bottom: -7px; width: 13px; height: 13px;
  background: #fff; border: 2px solid var(--accent); border-radius: 50%; cursor: nwse-resize;
}
.draft { position: absolute; pointer-events: none; }
.handle.end { right: auto; bottom: auto; transform: translate(-50%, -50%); cursor: move; }
.measure-label {
  position: absolute; white-space: nowrap; line-height: 1.3; padding: 0 .3em; border-radius: 3px;
  font-family: Helvetica, Arial, sans-serif; background: rgba(255, 255, 255, .85); pointer-events: none;
}
#btnScale.calibrating { border-color: var(--accent); color: var(--accent); }

/* ---------- Scale dialogs ---------- */
.dialog.small { width: min(520px, calc(100vw - 32px)); }
.dialog-sub { margin: -4px 0 16px; color: var(--muted); font-size: 14px; }
.scale-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.scale-row input, .scale-row select {
  height: 36px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
  padding: 0 10px; font: inherit;
}
.scale-row input { width: 96px; }
.scale-row input:focus, .scale-row select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.scale-row .eq { color: var(--muted); font-size: 14px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }

/* ---------- Dialog ---------- */
.dialog {
  border: 0; border-radius: 16px; padding: 20px; width: min(640px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.dialog::backdrop { background: rgba(10, 12, 20, .5); }
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
#signPad { width: 100%; height: auto; aspect-ratio: 600 / 220; background: #fff; border: 1px dashed var(--border); border-radius: 10px; touch-action: none; cursor: crosshair; display: block; }
.dialog-actions { display: flex; gap: 8px; margin-top: 14px; }
.spacer { flex: 1; }

/* ---------- Busy & toast ---------- */
.busy { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(10, 12, 20, .45); color: #fff; font-weight: 600; }
.spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 110; transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 10px;
  background: #171a26; color: #fff; font-size: 14px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .topbar { padding: 0 10px; }
  .brand span, .file-name, #btnClose { display: none; }
  #btnDownload span { display: none; }
  .sidebar-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; z-index: 40; top: var(--topbar-h); bottom: 0; left: 0;
    width: min(var(--sidebar-w, 196px), 85vw);
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  .sidebar-resizer { display: none; }
  body.sidebar-open .sidebar { transform: none; }
  .sidebar-close { display: inline-flex; width: 32px; height: 32px; }
  /* Dim the page behind the open panel; tapping it closes the panel. */
  .sidebar-backdrop {
    display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 39;
    background: rgba(10, 12, 20, .45); opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .thumb-actions { opacity: 1; }
  .tool { min-width: 48px; padding: 4px; }

  /* Two-row toolbar: tools on top (swipe sideways for more), and the active
     tool's options + zoom below, always in view while you work. */
  .toolbar { flex-wrap: wrap; overflow: visible; gap: 2px 6px; padding: 4px 8px; }
  .toolbar .tools, .toolbar .props {
    min-width: 0; overflow-x: auto; scrollbar-width: none; border-right: 0; padding-right: 0;
  }
  .toolbar .tools::-webkit-scrollbar, .toolbar .props::-webkit-scrollbar { display: none; }
  .toolbar .tools { flex: 1 1 calc(100% - 50px); }
  /* A real basis (not 0) so the options can't squeeze onto row 1; they wrap to row 2 beside zoom. */
  .toolbar .props { order: 2; flex: 1 1 calc(100% - 150px); min-height: 36px; }
  .toolbar .zoom { order: 3; }
  .prop > span { display: none; } /* "Size"/"Width" labels: the controls speak for themselves */
  .prop input[type=range] { width: 72px; }
  .auto-match span { display: none; } /* icon-only; the highlight shows on/off */
  .auto-match { padding: 0 8px; }
  .zoom-label { min-width: 48px; }
  .pages { padding: 16px 12px; }
}
