/* Pyrbit PDF for the web — styled after the iOS app (system colours, grouped
   backgrounds, rounded cards). Phone: iPhone layout with the floating tab bar.
   Tablet/desktop (≥ 768px): the iPad/Mac layout — sidebar, canvas, inspector. */

:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f2f2f7;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.62);
  --label-3: rgba(60, 60, 67, 0.32);
  --separator: rgba(60, 60, 67, 0.16);
  --fill: rgba(120, 120, 128, 0.12);
  --accent: #ff9500;
  --accent-2: #ff7a00;
  --accent-soft: rgba(255, 149, 0, 0.14);
  --blue: #007aff;
  --green: #34c759;
  --orange: #ff9500;
  --teal: #30b0c7;
  --red: #ff3b30;
  --purple: #af52de;
  --pink: #d65ad8;
  --gray: #8e8e93;
  --cyan: #32ade6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --tabbar-h: 64px;
  --sidebar-w: 280px;
  --inspector-w: 330px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --card: #1c1c1e; --card-2: #2c2c2e; --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.62); --label-3: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6); --fill: rgba(120, 120, 128, 0.24);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --card: #1c1c1e; --card-2: #2c2c2e; --label: #ffffff;
  --label-2: rgba(235, 235, 245, 0.62); --label-3: rgba(235, 235, 245, 0.3);
  --separator: rgba(84, 84, 88, 0.6); --fill: rgba(120, 120, 128, 0.24);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--label);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--blue); text-decoration: none; }
.icon { width: 22px; height: 22px; flex: none; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 28px; height: 28px; }
.icon.xl { width: 40px; height: 40px; }
.hidden { display: none !important; }
.muted { color: var(--label-2); }
.small { font-size: 13px; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* Category colours (iOS system colours) */
.c-edit { --c: var(--blue); } .c-convert { --c: var(--green); } .c-organize { --c: var(--orange); }
.c-create { --c: var(--teal); } .c-protect { --c: var(--red); } .c-annotate { --c: var(--pink); }
.c-advanced { --c: var(--gray); } .c-info { --c: var(--cyan); }
.tint-bg { background: color-mix(in srgb, var(--c) 15%, transparent); color: var(--c); }

/* ---------- App frame ---------- */
#app { min-height: 100%; }
.frame { display: flex; min-height: 100vh; min-height: 100dvh; }
.main { flex: 1; min-width: 0; padding: 0 16px calc(var(--tabbar-h) + 32px); }
.page { max-width: 640px; margin: 0 auto; }
.page.wide { max-width: 980px; }
.nav-title { text-align: center; font-weight: 600; font-size: 17px; padding: 14px 0 10px; }
.large-title { font-size: 34px; font-weight: 700; letter-spacing: 0.3px; margin: 12px 0 10px; }

/* Floating tab bar (iPhone) */
.tabbar {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(520px, calc(100% - 28px)); height: var(--tabbar-h); z-index: 30;
  display: flex; align-items: center; justify-content: space-around; padding: 0 8px;
  background: color-mix(in srgb, var(--card) 78%, transparent);
  backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: 999px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12), inset 0 0 0 0.5px var(--separator);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 500;
  color: var(--label); padding: 6px 12px; border-radius: 999px; min-width: 62px; }
.tabbar a.on { color: var(--accent); background: var(--fill); }

/* Sidebar (iPad / Mac) */
.sidebar { display: none; }

/* ---------- Cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.section-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; margin: 22px 4px 10px; }
.section-head .count { margin-left: auto; font-size: 12px; font-weight: 500; color: var(--label-2); }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; }
.list-row + .list-row { border-top: 0.5px solid var(--separator); }
.list-row .t { font-weight: 600; } .list-row .s { font-size: 13px; color: var(--label-2); }
.list-row .chev { color: var(--label-3); }
.icon-tile { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.badge-on-device { font-size: 9px; font-weight: 800; padding: 2px 6px; border-radius: 6px; background: var(--green); color: #fff; letter-spacing: 0.3px; }
.lock-badge { width: 18px; height: 18px; border-radius: 6px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.lock-badge .icon { width: 11px; height: 11px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 50px; padding: 0 20px;
  border-radius: 14px; font-weight: 600; font-size: 17px; width: 100%; transition: transform 0.06s, opacity 0.2s; }
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.btn-primary { background: linear-gradient(180deg, #ffa31a, var(--accent-2)); color: #fff; box-shadow: 0 4px 14px rgba(255, 122, 0, 0.3); }
.btn-soft { background: var(--accent-soft); color: var(--accent-2); }
.btn-plain { background: var(--fill); color: var(--label); }
.btn-outline { background: var(--card); color: var(--label); box-shadow: inset 0 0 0 1px var(--separator); }
.btn-sm { height: 36px; font-size: 15px; border-radius: 10px; padding: 0 14px; width: auto; white-space: nowrap; }
.btn-link { color: var(--accent-2); font-weight: 600; }
.capsule-btn { height: 36px; padding: 0 16px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-weight: 500; }
.icon-btn { width: 32px; height: 32px; border-radius: 999px; display: grid; place-items: center; color: var(--label-2); }
.icon-btn:hover { background: var(--fill); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; color: var(--label-2); }
.input, select.input, textarea.input { width: 100%; background: var(--card-2); border: 0; border-radius: 10px; padding: 11px 12px; outline: none; }
.input:focus { box-shadow: 0 0 0 2px var(--accent); }
textarea.input { min-height: 140px; resize: vertical; }
.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { flex: 1; padding: 7px 8px; border-radius: 7px; font-size: 13px; font-weight: 500; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.range { width: 100%; accent-color: var(--accent); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle input { width: 46px; height: 28px; appearance: none; background: var(--fill); border-radius: 999px; position: relative; transition: background 0.2s; flex: none; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: left 0.2s; }
.toggle input:checked { background: var(--green); }
.toggle input:checked::after { left: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 7px 14px; border-radius: 999px; background: var(--fill); font-size: 14px; font-weight: 500; }
.chip.on { background: var(--accent); color: #fff; }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 32px 20px;
  background: linear-gradient(180deg, #f7e3fb 0%, var(--bg) 45%); }
:root[data-theme="dark"] .login { background: linear-gradient(180deg, #3a1840 0%, var(--bg) 45%); }
.login-box { width: 100%; max-width: 440px; text-align: center; }
.login-orb { width: 132px; height: 132px; border-radius: 50%; margin: 0 auto 26px; display: grid; place-items: center; color: #fff;
  background: radial-gradient(circle at 30% 25%, #e46ee8, #c83ad6); box-shadow: 0 18px 50px rgba(200, 58, 214, 0.35); }
.login h1 { font-size: 30px; margin: 0 0 8px; }
.login .lead { color: var(--label-2); margin: 0 0 26px; }
.login-feats { text-align: left; display: flex; flex-direction: column; gap: 16px; margin: 0 6px 28px; }
.login-feats .row { gap: 14px; }
.login-feats .ok { margin-left: auto; color: var(--green); }
.btn-apple { background: #000; color: #fff; }
:root[data-theme="dark"] .btn-apple { background: #fff; color: #000; }
.login .fine { font-size: 13px; color: var(--label-2); margin-top: 22px; }
.demo-note { display: inline-block; margin-top: 14px; font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--fill); color: var(--label-2); }

/* ---------- Home ---------- */
.hero { padding: 16px; margin-top: 12px; }
.hero .brand { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.hero .brand img { width: 58px; height: 58px; border-radius: 14px; box-shadow: var(--shadow); }
.hero h2 { margin: 0; font-size: 22px; }
.private-pill { display: flex; align-items: center; gap: 8px; margin: 12px 0; padding: 8px 12px; border-radius: 12px; font-size: 13px;
  color: #248a3d; background: rgba(52, 199, 89, 0.14); }
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.quick { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 14px 6px 12px; display: flex; flex-direction: column;
  align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; text-align: center; }
.quick .icon-tile { border-radius: 50%; width: 46px; height: 46px; }
.quick, .tool-card, a.list-row, a.card { color: var(--label); }
.welcome { text-align: center; padding: 24px 0 8px; }
.welcome img { width: 68px; height: 68px; border-radius: 16px; box-shadow: var(--shadow); }
.welcome h1 { font-size: 28px; margin: 14px 0 6px; }
.drop-card { display: flex; align-items: center; gap: 16px; padding: 22px; border-radius: 18px; border: 1.5px dashed var(--separator); background: var(--card); }
.drop-card.drag { border-color: var(--accent); background: var(--accent-soft); }
.stats { display: flex; gap: 12px; justify-content: center; margin: 20px 0 6px; }
.stat { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px; text-align: center; min-width: 76px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--label-2); }

/* Tools grid (Tools tab) */
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.search input { border: 0; outline: none; background: transparent; flex: 1; }
.tool-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tool-card { position: relative; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 18px 12px 16px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px; }
.tool-card .icon-tile { border-radius: 50%; width: 48px; height: 48px; }
.tool-card .t { font-weight: 600; font-size: 15px; }
.tool-card .s { font-size: 12px; color: var(--label-2); }
.tool-card .lock-badge { position: absolute; top: 10px; right: 10px; }

/* ---------- Tool screen ---------- */
.tool-top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 10px 0;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.tool-top .title { flex: 1; text-align: center; font-weight: 600; font-size: 17px; }
.tool-top .side { width: 84px; }
.tool-body { display: flex; flex-direction: column; gap: 14px; }
.empty-card { padding: 26px 20px 20px; text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.empty-card .icon { color: var(--accent); }
.file-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.file-card .ftile { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.file-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .meta { font-size: 13px; color: var(--label-2); }
.panel { padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.panel-title { font-size: 12px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--label-2); }
.result-title { color: var(--green); }
.preview { padding: 12px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.preview canvas, .preview img.page-img { max-width: 100%; height: auto; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12); border-radius: 2px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; font-size: 14px; color: var(--label-2); }
.pager .capsule { background: var(--fill); padding: 5px 14px; border-radius: 999px; }
.pager button { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); }
.pager button[disabled] { opacity: 0.35; }
.thumbs { display: flex; gap: 10px; overflow-x: auto; padding: 6px 2px 10px; width: 100%; }
.thumb { flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--label-2); position: relative; }
.thumb canvas { width: 72px; height: auto; background: #fff; border-radius: 4px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15); outline: 2px solid transparent; }
.thumb.on canvas { outline-color: var(--accent); }
.thumb.sel canvas { outline-color: var(--accent); }
.thumb .check { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #fff; display: none; place-items: center; }
.thumb.sel .check { display: grid; }
.thumb.removed canvas { opacity: 0.3; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 14px; width: 100%; }
.page-grid .thumb canvas { width: 100%; }
.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.action-tile { background: var(--accent-soft); color: var(--accent-2); border-radius: 12px; padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.text-out { white-space: pre-wrap; font: 13px/1.5 ui-monospace, Menlo, monospace; max-height: 360px; overflow: auto; background: var(--card-2); border-radius: 10px; padding: 12px; width: 100%; }
.file-list { display: flex; flex-direction: column; }
.file-list .list-row { padding: 10px 12px; }

/* Bottom sheet / dialogs */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade 0.2s; }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 18px 28px; animation: up 0.25s ease-out; }
.sheet .grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--label-3); margin: 0 auto 10px; }
.dialog { margin: auto; max-width: 400px; width: calc(100% - 40px); background: var(--card); border-radius: 18px; padding: 22px; text-align: center; animation: pop 0.2s ease-out; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 34px); transform: translateX(-50%); z-index: 60; background: rgba(30, 30, 30, 0.92);
  color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; animation: fade 0.2s; max-width: calc(100% - 40px); }
.busy { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.25); display: grid; place-items: center; }
.busy .box { background: var(--card); padding: 22px 26px; border-radius: 18px; display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 200px; box-shadow: var(--shadow); }
.spin { animation: spin 0.9s linear infinite; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } }

/* Page editor (Edit PDF, Add Text, Sign, Highlight, Redact) */
.editor-wrap { position: relative; display: inline-block; touch-action: none; user-select: none; }
.editor-wrap canvas { display: block; }
.ov { position: absolute; border: 1.5px dashed transparent; }
.ov.sel { border-color: var(--accent); }
.ov.text { white-space: pre; line-height: 1.15; cursor: move; padding: 0 1px; }
.ov.img { cursor: move; }
.ov.img img { width: 100%; height: 100%; display: block; pointer-events: none; }
.ov.box { cursor: move; }
.ov.box.redact { background: #000; }
.ov.box.highlight { mix-blend-mode: multiply; }
.ov .handle { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; cursor: nwse-resize; display: none; }
.ov.sel .handle { display: block; }
.ov .del { position: absolute; top: -12px; right: -12px; width: 22px; height: 22px; border-radius: 50%; background: var(--red); color: #fff; display: none; place-items: center; }
.ov.sel .del { display: grid; }
.ov .del .icon { width: 13px; height: 13px; }
.ink { position: absolute; inset: 0; pointer-events: none; }
.sigpad { width: 100%; height: 180px; background: #fff; border-radius: 12px; touch-action: none; box-shadow: inset 0 0 0 1px var(--separator); }
video.cam { width: 100%; border-radius: 14px; background: #000; max-height: 60vh; object-fit: contain; }

/* ---------- Tablet & desktop: the iPad / Mac layout ---------- */
@media (min-width: 768px) {
  .tabbar { display: none; }
  .main { padding: 0 28px 40px; }
  .sidebar { display: flex; flex-direction: column; width: var(--sidebar-w); flex: none; height: 100vh; height: 100dvh; position: sticky; top: 0;
    background: color-mix(in srgb, var(--card) 55%, var(--bg)); border-right: 0.5px solid var(--separator); overflow: hidden; }
  .sidebar .sb-top { padding: 14px 12px 8px; display: flex; gap: 8px; align-items: center; }
  .sidebar .search { box-shadow: none; background: var(--fill); padding: 7px 10px; flex: 1; font-size: 14px; }
  .sidebar nav { overflow-y: auto; padding: 4px 10px 24px; }
  .sb-group { background: var(--card); border-radius: 12px; overflow: hidden; margin-bottom: 14px; box-shadow: var(--shadow); }
  .sb-link { display: flex; align-items: center; gap: 12px; padding: 9px 12px; color: var(--label); font-size: 14.5px; width: 100%; text-align: left; }
  .sb-link + .sb-link { border-top: 0.5px solid var(--separator); }
  .sb-link.on { background: var(--fill); }
  .sb-link .icon { width: 19px; height: 19px; color: var(--c, var(--accent)); }
  .sb-link .lock-badge .icon { width: 11px; height: 11px; color: #fff; }
  .sb-link .sub { display: block; font-size: 11.5px; color: var(--label-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sb-link .txt { flex: 1; min-width: 0; }
  .sb-cat { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 6px 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.5px;
    text-transform: uppercase; color: var(--label-2); }
  .sb-cat .icon { width: 15px; height: 15px; color: var(--c); }
  .sb-cat .chev { margin-left: auto; transition: transform 0.2s; }
  .sb-cat.closed .chev { transform: rotate(-90deg); }
  .frame.rail .sidebar { width: 64px; }
  .frame.rail .sidebar .search, .frame.rail .sidebar .txt, .frame.rail .sidebar .sb-cat span, .frame.rail .sb-cat .chev, .frame.rail .lock-badge { display: none; }
  .frame.rail .sb-link { justify-content: center; }

  .quick-grid { grid-template-columns: repeat(4, 1fr); gap: 14px; }
  .tool-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

  /* Tool screen: canvas in the middle, inspector on the right (Mac/iPad) */
  .tool-screen { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .tool-top { padding-top: 16px; }
}

/* Tool screen areas. Phone & tablet: file → preview → options, one column. */
.tool-screen { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "doc" "canvas" "opts"; gap: 14px; }
.area-doc { grid-area: doc; } .area-canvas { grid-area: canvas; } .area-opts { grid-area: opts; }
.area-doc:empty, .area-canvas:empty, .area-opts:empty { display: none; }
.tool-screen:not(.has-canvas) { max-width: 640px; margin: 0 auto; width: 100%; }

/* Desktop: the Mac layout — the document in the middle, an inspector on the right. */
@media (min-width: 1100px) {
  .tool-screen.has-canvas { grid-template-columns: minmax(0, 1fr) var(--inspector-w); grid-template-rows: auto 1fr; grid-template-areas: "canvas doc" "canvas opts"; align-items: start; }
  .tool-screen.has-canvas .area-opts { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; padding-bottom: 8px; }
  .tool-screen.has-canvas .area-canvas { min-height: 70vh; }
}
@media (max-width: 767px) { .viewer-rail { display: none !important; } }

@media (max-width: 380px) {
  .quick-grid { gap: 8px; } .quick { font-size: 11.5px; }
  .tabbar a { min-width: 0; padding: 6px 8px; }
}

/* ---------- Edit PDF (the app's EditPdfView) ---------- */
body.editing .tabbar { display: none; }
body.editing .main { padding: 0; }
.flip-x { transform: scaleX(-1); }
.ed { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--bg); }
.ed-top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.ed-round { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--card); color: var(--accent); box-shadow: var(--shadow); }
.ed-round[disabled] { color: var(--label-3); box-shadow: none; }
.ed-pair { display: flex; gap: 2px; background: var(--card); border-radius: 999px; box-shadow: var(--shadow); }
.ed-pair .ed-round { box-shadow: none; background: transparent; }
.ed-chip { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--card); font-size: 14px; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); }
.ed-chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.ed-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.ed-canvas { position: relative; min-height: 0; min-width: 0; }
.ed-scroll { position: absolute; inset: 0; overflow: auto; padding: 12px 16px 200px; display: flex; flex-direction: column; align-items: center; gap: 14px; background: color-mix(in srgb, var(--label) 6%, var(--bg)); }
.ed-page { position: relative; flex: none; background: #fff; box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18); }
.ed-img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.ed-layer { position: absolute; inset: 0; }
.ed-layer:not(.ed-overlay) { pointer-events: none; }
.ed-overlay { touch-action: pan-x pan-y; }
.ed-scroll { touch-action: pan-x pan-y; }
.ed-overlay[data-mode="view"] { pointer-events: none; }
.ed-overlay[data-mode="draw"], .ed-overlay[data-mode="markup"] { touch-action: none; cursor: crosshair; }
.ed-overlay[data-mode="add"] { cursor: text; }
.ed-block { position: absolute; background: rgba(0, 122, 255, 0.12); border-radius: 2px; cursor: text; outline: 1px solid rgba(0, 122, 255, 0.18); }
.ed-block:hover { background: rgba(0, 122, 255, 0.22); }
.ed-block.locked { background: transparent; outline: 1px dashed rgba(142, 142, 147, 0.5); cursor: not-allowed; }
.ed-obj { position: absolute; outline: 2px dashed rgba(255, 149, 0, 0.8); background: rgba(255, 149, 0, 0.08); cursor: pointer; }
.ed-obj.link { outline-color: rgba(0, 122, 255, 0.8); background: rgba(0, 122, 255, 0.08); }
.ed-obj.sel { outline: 2px solid var(--accent); cursor: move; }
.ed-handle { position: absolute; right: -8px; bottom: -8px; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; cursor: nwse-resize; }
.ed-live { position: absolute; outline: 1.5px solid var(--accent); border-radius: 2px; cursor: text; }
.ed-preview { position: absolute; }
.ed-sel { position: absolute; background: rgba(0, 122, 255, 0.28); }
.ed-caret { position: absolute; width: 2px; background: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.ed-input { position: absolute; opacity: 0.01; border: 0; padding: 0; margin: 0; background: transparent; color: transparent; caret-color: transparent; outline: none; pointer-events: none; }
.ed-ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.ed-placer { position: absolute; outline: 2px dashed var(--accent); cursor: move; touch-action: none; z-index: 3; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25); }
.ed-placer img { width: 100%; height: 100%; display: block; pointer-events: none; }
.ed-float { position: absolute; left: 0; right: 0; top: 8px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 5; }
.ed-float > * { pointer-events: auto; }
.ed-pills { display: flex; gap: 10px; }
.ed-pill { display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 16px; border-radius: 999px; background: rgba(120, 120, 128, 0.9); color: #fff; font-weight: 600; box-shadow: var(--shadow); }
.ed-pill.primary { background: var(--accent); }
.ed-pill[disabled] { opacity: 0.5; }
.ed-msg { display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 14px; background: color-mix(in srgb, var(--card) 94%, transparent); box-shadow: var(--shadow); font-size: 14px; }
.ed-msg.warn { color: var(--red); }
.ed-hint { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; }
.ed-hint .icon { color: var(--accent); }
.ed-badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.ed-subtools { display: flex; gap: 6px; overflow-x: auto; }
.ed-subtools button { flex: 1; min-width: 56px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 6px; border-radius: 9px; font-size: 11px; font-weight: 600; color: var(--label-2); }
.ed-subtools button.on { color: var(--accent); background: var(--accent-soft); }
.ed-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-swatch { width: 26px; height: 26px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.ed-swatch.on { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--purple); }
.ed-swatch.custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); position: relative; overflow: hidden; }
.ed-swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.ed-writing { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 12px; background: var(--card-2); }
.ed-fmt { min-width: 38px; height: 34px; border-radius: 8px; background: var(--card); font-weight: 700; box-shadow: var(--shadow); padding: 0 8px; }
.ed-strip { display: flex; gap: 10px; overflow-x: auto; padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 0.5px solid var(--separator); background: var(--bg); flex: none; }
.ed-thumb { flex: none; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--label-2); }
.ed-thumb img { height: 64px; width: auto; background: #fff; border-radius: 3px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); outline: 2px solid transparent; }
.ed-thumb.on img { outline-color: var(--accent); }
.ed-thumb.on span { color: var(--accent); font-weight: 700; }
.ed-thumb.add .plus { height: 64px; width: 48px; display: grid; place-items: center; border: 1.5px dashed var(--accent); border-radius: 6px; color: var(--accent); }
/* Phone: the floating dock and its option panel over the page */
.ed-phone-ui { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 8px; z-index: 6; pointer-events: none; }
.ed-phone-ui > * { pointer-events: auto; }
.ed-panel { background: color-mix(in srgb, var(--card) 94%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-radius: 20px; padding: 12px; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15); max-height: 46vh; overflow: auto; }
.ed-dock { display: flex; justify-content: space-between; gap: 2px; padding: 6px; border-radius: 22px; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18); }
.ed-dock button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 9.5px; font-weight: 500; color: var(--label-2); padding: 2px 0; }
.ed-dock .ic { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; }
.ed-dock button.on { color: var(--t); font-weight: 700; }
.ed-dock button.on .ic { background: color-mix(in srgb, var(--t) 16%, transparent); }
/* Tablet & desktop: the docked inspector on the right */
.ed-inspector { display: none; }
@media (min-width: 768px) {
  .ed-body { grid-template-columns: minmax(0, 1fr) 300px; }
  .ed-inspector { display: flex; flex-direction: column; gap: 12px; padding: 12px; overflow: auto; border-left: 0.5px solid var(--separator); background: var(--bg); }
  .ed-card { background: var(--card); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
  .ed-toolrow { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; font-weight: 500; text-align: left; }
  .ed-toolrow:hover, .ed-toolrow.on { background: var(--fill); }
  .ed-toolchip { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
  .ed-scroll { padding-bottom: 40px; }
}
.ed-round.on { color: #fff; background: var(--blue); }
.ed-scroll.grid .ed-page::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(0, 122, 255, 0.18) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 122, 255, 0.18) 1px, transparent 1px);
  background-size: var(--cell) var(--cell); }
.ed-typed { position: absolute; background: #fff; line-height: 1.25; white-space: pre-wrap; word-break: break-word; box-shadow: 0 0 0 2px #fff; }
.ed-fmtbar { display: flex; align-items: center; gap: 6px; overflow-x: auto; padding: 2px; }
.ed-fmtbar .ed-fmt { flex: none; }
body.in-tool .tabbar { display: none; }
body.in-tool .main { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.dialog, .sheet, .toast, .card, .ed-msg, .ed-card { overflow-wrap: anywhere; }
.dialog { max-height: 90vh; overflow: auto; }
/* Cut Out & Replace: the box */
.co-box { position: absolute; outline: 2px dashed var(--accent); background: rgba(255, 149, 0, 0.08); cursor: move; touch-action: none; }
.co-size { position: absolute; left: 0; top: -22px; font-size: 11px; font-weight: 600; background: var(--accent); color: #fff; padding: 2px 6px; border-radius: 6px; white-space: nowrap; }
.co-h { position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid var(--accent); border-radius: 3px; }
.co-h.nw { left: -8px; top: -8px; cursor: nwse-resize; } .co-h.ne { right: -8px; top: -8px; cursor: nesw-resize; }
.co-h.sw { left: -8px; bottom: -8px; cursor: nesw-resize; } .co-h.se { right: -8px; bottom: -8px; cursor: nwse-resize; }

/* Ads (free users only; see js/ads.js) */
.ad-box { margin: 18px 0; padding: 8px; border-radius: 14px; background: var(--card, rgba(127,127,127,.06)); min-height: 60px; overflow: hidden; }
.ad-box .ad-label { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; opacity: .55; margin: 0 0 4px 4px; }
