/* ============================================================
   PDF Workspace - Global Styles
   1) Tokens & theming   2) Reset/base   3) Layout
   4) Components   5) Feature UI   6) Utilities
   ============================================================ */

/* ---------- 1) Design tokens & theming ----------
   Light is the default. Dark applies automatically to users whose OS
   prefers dark AND who haven't chosen a theme, or explicitly via
   <html data-theme="dark"> (set by js/ui/theme.js).                   */
:root {
  /* Brand */
  --c-brand: #6366f1;
  --c-brand-strong: #4f46e5;
  --c-brand-2: #8b5cf6;
  --c-brand-soft: #eef1ff;
  --grad-brand: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --grad-text: linear-gradient(120deg, #4f46e5 0%, #7c3aed 60%, #9333ea 100%);

  /* Neutrals (light) */
  --c-bg: #f5f6fc;
  --c-surface: #ffffff;
  --c-surface-2: #f1f2f9;
  --c-border: #e5e7f0;
  --c-border-strong: #d5d8e6;
  --c-text: #1a1c26;
  --c-text-muted: #646a80;

  /* Status */
  --c-danger: #e11d48;
  --c-danger-soft: #fff1f3;
  --c-success: #12a150;

  /* Ambient page glows */
  --glow-1: rgba(99, 102, 241, .18);
  --glow-2: rgba(139, 92, 246, .14);

  /* Shape & motion */
  --radius-sm: 9px;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 44, .05), 0 2px 6px rgba(20, 22, 44, .05);
  --shadow: 0 6px 20px rgba(20, 22, 44, .08);
  --shadow-lg: 0 18px 48px rgba(20, 22, 44, .16);
  --ring: 0 0 0 3px rgba(99, 102, 241, .35);
  --ease: 200ms cubic-bezier(.2, .7, .3, 1);

  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --maxw: 1120px;
}

/* Dark palette, shared by auto-dark and explicit-dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --c-brand-soft: #20233d;
    --c-bg: #0b0d14;
    --c-surface: #161925;
    --c-surface-2: #1e2130;
    --c-border: #2a2e40;
    --c-border-strong: #3a3f57;
    --c-text: #eceef6;
    --c-text-muted: #9aa1ba;
    --c-danger-soft: #2a1620;
    --glow-1: rgba(99, 102, 241, .22);
    --glow-2: rgba(139, 92, 246, .16);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
    --shadow: 0 6px 20px rgba(0, 0, 0, .5);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  --c-brand-soft: #20233d;
  --c-bg: #0b0d14;
  --c-surface: #161925;
  --c-surface-2: #1e2130;
  --c-border: #2a2e40;
  --c-border-strong: #3a3f57;
  --c-text: #eceef6;
  --c-text-muted: #9aa1ba;
  --c-danger-soft: #2a1620;
  --glow-1: rgba(99, 102, 241, .22);
  --glow-2: rgba(139, 92, 246, .16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
  --shadow: 0 6px 20px rgba(0, 0, 0, .5);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
}

/* ---------- 2) Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--c-text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  background:
    radial-gradient(1100px 620px at 12% -8%, var(--glow-1), transparent 60%),
    radial-gradient(1000px 560px at 100% 0%, var(--glow-2), transparent 55%),
    var(--c-bg);
  background-attachment: fixed;
  transition: background-color var(--ease), color var(--ease);
}
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 750; letter-spacing: -.02em; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }
::selection { background: rgba(99, 102, 241, .25); }

/* ---------- 3) Layout ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--c-surface) 78%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--c-border);
}
.app-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); text-decoration: none; color: var(--c-text); }
.brand__mark {
  font-size: 20px; width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--grad-brand);
  color: #fff; /* white ¶ on the gradient chip, in both themes */
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.brand__name { font-weight: 750; font-size: 18px; letter-spacing: -.02em; }
.brand__tagline { margin: 0; color: var(--c-text-muted); font-size: 13px; }
.app-header__spacer { flex: 1; }
.header-link {
  color: var(--c-text-muted); text-decoration: none; font-size: 14px; font-weight: 650;
  padding: 8px 12px; border-radius: var(--radius-sm); transition: color var(--ease), background var(--ease);
}
.header-link:hover { color: var(--c-text); background: var(--c-surface-2); }

.theme-toggle {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 17px;
  cursor: pointer;
  transition: transform var(--ease), border-color var(--ease), background var(--ease);
}
.theme-toggle:hover { transform: translateY(-1px); border-color: var(--c-brand); }
.theme-toggle:active { transform: translateY(0); }
.theme-toggle:focus-visible { outline: none; box-shadow: var(--ring); }

.app-main { max-width: var(--maxw); margin: 0 auto; padding: var(--sp-7) var(--sp-5); }

.hero { text-align: center; margin-bottom: var(--sp-6); }
.hero__title {
  font-size: clamp(30px, 5vw, 46px);
  background: var(--grad-text);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.hero__subtitle { color: var(--c-text-muted); margin-top: var(--sp-3); font-size: 17px; }
.hero__badges {
  list-style: none; margin: var(--sp-5) 0 0; padding: 0;
  display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: center;
}
.hero__badges li {
  font-size: 13px; font-weight: 600; color: var(--c-text-muted);
  background: var(--c-surface); border: 1px solid var(--c-border);
  padding: 6px 12px; border-radius: 999px;
}

/* Homepage value strip */
.pitch {
  margin-top: var(--sp-7);
  display: grid; gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.pitch__item { padding: var(--sp-5); border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface); box-shadow: var(--shadow-sm); }
.pitch__item h3 { font-size: 16px; margin-bottom: var(--sp-2); }
.pitch__item p { font-size: 14px; margin: 0; }

/* Breadcrumb */
.breadcrumb { font-size: 13px; color: var(--c-text-muted); margin-bottom: var(--sp-4); }
.breadcrumb a { color: var(--c-text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--c-brand); text-decoration: underline; }
.breadcrumb span[aria-hidden] { margin: 0 6px; opacity: .6; }

/* Tool landing hero */
.tool-hero { text-align: center; max-width: 62ch; margin: 0 auto var(--sp-6); }
.tool-hero__title {
  font-size: clamp(28px, 4.5vw, 40px);
  background: var(--grad-text); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.tool-hero__lede { color: var(--c-text-muted); margin-top: var(--sp-3); font-size: 16px; }

/* Tool mount area (uploader + live tool) */
.tool-uploader { margin-bottom: var(--sp-5); }
#tool-live:not(:empty) {
  margin-top: var(--sp-5); padding-top: var(--sp-5);
  border-top: 1px solid var(--c-border);
}
.tool-hint { text-align: center; padding: var(--sp-4); font-size: 14px; }

/* SEO content section */
.seo { margin-top: var(--sp-7); max-width: 760px; }
.seo h2 { font-size: 20px; margin: var(--sp-6) 0 var(--sp-4); }
.seo h2:first-child { margin-top: 0; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: var(--sp-3); }
.steps li {
  position: relative; padding: var(--sp-3) var(--sp-4) var(--sp-3) 52px;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); font-size: 14.5px;
}
.steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; display: grid; place-items: center;
  border-radius: 50%; background: var(--grad-brand); color: #fff; font-weight: 700; font-size: 13px;
}
.faq { display: grid; gap: var(--sp-2); }
.faq__item {
  border: 1px solid var(--c-border); border-radius: var(--radius);
  background: var(--c-surface); box-shadow: var(--shadow-sm); overflow: hidden;
}
.faq__item summary {
  cursor: pointer; padding: var(--sp-3) var(--sp-4); font-weight: 650; font-size: 14.5px;
  list-style: none; display: flex; justify-content: space-between; align-items: center;
}
.faq__item summary::-webkit-details-marker { display: none; }
.faq__item summary::after { content: "+"; color: var(--c-text-muted); font-size: 18px; font-weight: 400; }
.faq__item[open] summary::after { content: "−"; }
.faq__item p { margin: 0; padding: 0 var(--sp-4) var(--sp-4); color: var(--c-text-muted); font-size: 14px; }

/* Footer */
.site-footer { margin-top: var(--sp-7); border-top: 1px solid var(--c-border); background: color-mix(in srgb, var(--c-surface) 60%, transparent); }
.site-footer__inner {
  max-width: var(--maxw); margin: 0 auto; padding: var(--sp-6) var(--sp-5);
  display: grid; gap: var(--sp-6); grid-template-columns: 1.2fr 1fr;
}
.site-footer__heading { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--c-text-muted); margin-bottom: var(--sp-3); }
.site-footer__links ul { list-style: none; margin: 0; padding: 0; columns: 2; gap: var(--sp-4); }
.site-footer__links a { color: var(--c-text-muted); text-decoration: none; font-size: 14px; line-height: 2; }
.site-footer__links a:hover { color: var(--c-brand); }
.site-footer__bar {
  border-top: 1px solid var(--c-border); padding: var(--sp-4) var(--sp-5);
  max-width: var(--maxw); margin: 0 auto; display: flex; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  font-size: 12.5px;
}

@media (max-width: 640px) {
  .site-footer__inner { grid-template-columns: 1fr; gap: var(--sp-5); }
  .app-main { padding: var(--sp-5) var(--sp-4) var(--sp-6); }
}

/* ---------- 4) Components ---------- */
.btn {
  --btn-bg: var(--c-surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  color: var(--c-text);
  background: var(--btn-bg);
  transition: background var(--ease), border-color var(--ease), transform var(--ease), box-shadow var(--ease), opacity var(--ease);
}
.btn:hover { transform: translateY(-1px); border-color: var(--c-border-strong); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn--primary {
  border-color: transparent;
  background: var(--grad-brand);
  color: #fff;
  box-shadow: 0 6px 18px rgba(99, 102, 241, .35);
}
.btn--primary:hover { box-shadow: 0 10px 26px rgba(99, 102, 241, .45); border-color: transparent; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--c-text-muted); }
.btn--ghost:hover { color: var(--c-text); background: var(--c-surface-2); border-color: transparent; }
.btn--danger { background: var(--c-danger); border-color: transparent; color: #fff; box-shadow: 0 6px 18px rgba(225, 29, 72, .3); }
.btn--danger:hover { border-color: transparent; box-shadow: 0 10px 26px rgba(225, 29, 72, .4); }
.btn--sm { padding: 7px 12px; font-size: 13px; }
.btn--block { width: 100%; }

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field__label { font-size: 13px; font-weight: 650; color: var(--c-text-muted); }
.input, .select {
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.input:focus, .select:focus { outline: none; border-color: var(--c-brand); box-shadow: var(--ring); }

/* ---------- 5) Feature UI ---------- */

/* Upload dropzone */
.dropzone {
  position: relative;
  border: 1.5px dashed var(--c-border-strong);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--c-brand-soft) 40%, var(--c-surface)) 0%, var(--c-surface) 100%);
  padding: var(--sp-7) var(--sp-5);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease), transform var(--ease), box-shadow var(--ease);
}
.dropzone:hover { border-color: var(--c-brand); transform: translateY(-2px); box-shadow: var(--shadow); }
.dropzone--over { border-color: var(--c-brand); border-style: solid; box-shadow: var(--ring), var(--shadow); }
.dropzone__icon {
  font-size: 26px; width: 62px; height: 62px; margin: 0 auto var(--sp-4);
  display: grid; place-items: center;
  border-radius: 18px;
  background: var(--grad-brand);
  color: #fff;
  box-shadow: 0 10px 24px rgba(99, 102, 241, .4), inset 0 1px 0 rgba(255, 255, 255, .3);
}
.dropzone__title { font-weight: 700; font-size: 17px; }
.dropzone__hint { color: var(--c-text-muted); font-size: 14px; margin-top: var(--sp-1); }
.dropzone__browse { color: var(--c-brand); font-weight: 650; text-decoration: underline; text-underline-offset: 2px; }

/* Selected-files summary bar */
.files-bar {
  margin-top: var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
}
.files-bar__count {
  font-weight: 700; font-size: 13px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--c-brand-soft); color: var(--c-brand-strong);
}
.files-bar__names { color: var(--c-text-muted); font-size: 13px; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tools grid */
.tools-section { margin-top: var(--sp-7); }
.tools-section__title { font-size: 19px; margin-bottom: var(--sp-4); }
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: var(--sp-4);
}
.tool-card {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-3);
  text-align: left;
  padding: var(--sp-5) var(--sp-4);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  overflow: hidden;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
}
.tool-card::before {
  content: ""; position: absolute; inset: 0;
  background: var(--grad-brand); opacity: 0;
  transition: opacity var(--ease);
  mix-blend-mode: normal;
}
.tool-card:hover { border-color: transparent; box-shadow: var(--shadow-lg); transform: translateY(-4px); }
.tool-card:hover::before { opacity: .06; }
.tool-card:focus-visible { outline: none; box-shadow: var(--ring); }
.tool-card:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: var(--shadow-sm); }
.tool-card:disabled:hover::before { opacity: 0; }
.tool-card > * { position: relative; }
.tool-card__icon {
  font-size: 22px; width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--c-brand-soft), color-mix(in srgb, var(--c-brand-soft) 30%, var(--c-surface-2)));
  border: 1px solid var(--c-border);
}
.tool-card__label { font-weight: 700; font-size: 15px; }
.tool-card__desc { font-size: 12.5px; color: var(--c-text-muted); }

/* Workspace */
.workspace__back { margin-bottom: var(--sp-4); }
.tool-head { margin-bottom: var(--sp-6); }
.tool-head__title { font-size: 24px; display: flex; align-items: center; gap: var(--sp-2); }
.tool-head__desc { color: var(--c-text-muted); margin-top: var(--sp-2); font-size: 15px; max-width: 62ch; }
.tool-body { display: grid; gap: var(--sp-5); }
.tool-actions { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: center; }

/* Reorderable file list (Merge) */
.file-list { display: flex; flex-direction: column; gap: var(--sp-2); list-style: none; margin: 0; padding: 0; }
.file-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: box-shadow var(--ease), border-color var(--ease), opacity var(--ease), transform var(--ease);
}
.file-row:hover { border-color: var(--c-border-strong); }
.file-row--dragging { opacity: .5; box-shadow: var(--shadow-lg); }
.file-row--over { border-color: var(--c-brand); box-shadow: var(--ring); }
.file-row__handle { color: var(--c-text-muted); cursor: grab; font-size: 16px; user-select: none; }
.file-row__index {
  width: 26px; height: 26px; flex: none;
  display: grid; place-items: center;
  background: var(--grad-brand); color: #fff;
  border-radius: 50%; font-size: 12px; font-weight: 700;
}
.file-row__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 550; }
.file-row__size { color: var(--c-text-muted); font-size: 12px; flex: none; }
.file-row__remove {
  border: none; background: transparent; color: var(--c-text-muted);
  cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 7px; border-radius: 7px;
}
.file-row__remove:hover { color: var(--c-danger); background: var(--c-danger-soft); }

/* Page thumbnail grid (Rotate / Delete / Rearrange) */
.grid-loading { display: flex; align-items: center; gap: var(--sp-2); color: var(--c-text-muted); padding: var(--sp-5); }
.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--sp-4);
}
.page-cell {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  box-shadow: var(--shadow-sm);
}
.thumb { width: 150px; height: 150px; display: grid; place-items: center; overflow: hidden; position: relative; }
.thumb__img {
  max-width: 140px; max-height: 140px; width: auto; height: auto;
  box-shadow: var(--shadow-sm);
  border-radius: 3px;
  transition: transform var(--ease), opacity var(--ease);
  transform-origin: center;
  background: #fff;
}
.page-cell__num { font-size: 12px; color: var(--c-text-muted); font-weight: 650; }
.page-cell__tools { display: flex; gap: var(--sp-2); }
.icon-btn {
  border: 1px solid var(--c-border);
  background: var(--c-surface-2);
  color: var(--c-text);
  border-radius: var(--radius-sm);
  width: 32px; height: 32px;
  font-size: 15px; line-height: 1;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
}
.icon-btn:hover { border-color: var(--c-brand); background: var(--c-brand-soft); transform: translateY(-1px); }

/* Selectable pages (Delete) */
.page-cell--selectable { cursor: pointer; transition: border-color var(--ease), background var(--ease), transform var(--ease); }
.page-cell--selectable:hover { border-color: var(--c-brand); transform: translateY(-2px); }
.page-cell--selectable:focus-visible { outline: none; box-shadow: var(--ring); }
.page-check {
  position: absolute; top: 6px; left: 6px;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  color: transparent;
  font-size: 13px; font-weight: 800;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}
.page-cell--selected { border-color: var(--c-danger); background: var(--c-danger-soft); }
.page-cell--selected .thumb__img { opacity: .4; }
.page-cell--selected .page-check { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.page-cell--selected .page-cell__num { color: var(--c-danger); }

/* Draggable pages (Rearrange) */
.page-cell--draggable { cursor: grab; }
.page-cell--draggable:hover { border-color: var(--c-brand); }
.page-cell--dragging { opacity: .45; box-shadow: var(--shadow-lg); }
.page-cell--drop-target { border-color: var(--c-brand); box-shadow: var(--ring); }
.page-remove {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface);
  color: var(--c-text-muted);
  font-size: 16px; line-height: 1; cursor: pointer;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}
.page-remove:hover { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.page-pos {
  position: absolute; top: 6px; left: 6px;
  min-width: 24px; height: 24px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--grad-brand); color: #fff;
  font-size: 12px; font-weight: 800;
  box-shadow: var(--shadow-sm);
}

/* Segmented control (Split mode, and reusable) */
.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.segmented__opt {
  border: none;
  background: transparent;
  color: var(--c-text-muted);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  transition: background var(--ease), color var(--ease), box-shadow var(--ease);
}
.segmented__opt:hover { color: var(--c-text); }
.segmented__opt[aria-pressed="true"] {
  background: var(--c-surface);
  color: var(--c-brand-strong);
  box-shadow: var(--shadow-sm);
}
.segmented__opt:focus-visible { outline: none; box-shadow: var(--ring); }

/* Image gallery (PDF → Images) */
.img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--sp-4);
}
.img-card {
  display: flex; flex-direction: column; gap: var(--sp-2);
  padding: var(--sp-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  box-shadow: var(--shadow-sm);
}
.img-card__preview {
  aspect-ratio: 3 / 4;
  display: grid; place-items: center;
  background: var(--c-surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.img-card__preview img { max-width: 100%; max-height: 100%; object-fit: contain; box-shadow: var(--shadow-sm); }
.img-card__meta { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; }

/* Range input */
input[type="range"] { accent-color: var(--c-brand); cursor: pointer; width: 220px; max-width: 100%; }

/* Colour picker */
.color-input {
  width: 52px; height: 36px; padding: 2px;
  border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  background: var(--c-surface); cursor: pointer;
}
input[type="checkbox"] { accent-color: var(--c-brand); width: 17px; height: 17px; cursor: pointer; }

/* 3×3 position picker (Watermark) */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 34px);
  grid-template-rows: repeat(3, 34px);
  gap: 5px;
  transition: opacity var(--ease);
}
.pos-cell {
  border: 1px solid var(--c-border);
  background: var(--c-surface-2);
  border-radius: 7px;
  cursor: pointer;
  position: relative;
  transition: background var(--ease), border-color var(--ease);
}
.pos-cell::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c-text-muted); opacity: .35;
  transition: background var(--ease), opacity var(--ease), transform var(--ease);
}
.pos-cell:hover { border-color: var(--c-brand); }
.pos-cell[aria-pressed="true"] { border-color: var(--c-brand); background: var(--c-brand-soft); }
.pos-cell[aria-pressed="true"]::after { background: var(--c-brand); opacity: 1; transform: scale(1.25); }
.pos-cell:focus-visible { outline: none; box-shadow: var(--ring); }

/* Inline notice (limitations / tips) */
.notice {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-brand);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text-muted);
  font-size: 13.5px;
  line-height: 1.5;
}
.notice strong { color: var(--c-text); }

/* Add Page Numbers */
.pgnum-layout { display: flex; gap: var(--sp-6); flex-wrap: wrap; align-items: flex-start; }
.pgnum-controls { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: var(--sp-4); }
.pgnum-previewwrap { display: flex; flex-direction: column; gap: var(--sp-2); }
.pgnum-page {
  position: relative;
  width: 190px; aspect-ratio: 210 / 297;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: var(--c-surface);
  box-shadow: var(--shadow-sm);
  background-image: repeating-linear-gradient(var(--c-surface-2) 0 1px, transparent 1px 14px);
}
.pgnum-zone {
  position: absolute;
  border: none; background: transparent; cursor: pointer;
  font-size: 10px; color: var(--c-text-muted);
  padding: 3px 6px; border-radius: 5px; line-height: 1.2;
  max-width: 80%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background var(--ease), color var(--ease);
}
.pgnum-zone:hover { background: var(--c-surface-2); }
.pgnum-zone[aria-pressed="true"] { background: var(--c-brand); color: #fff; font-weight: 700; }
.pgnum-zone.top-left { top: 6px; left: 6px; }
.pgnum-zone.top-center { top: 6px; left: 50%; transform: translateX(-50%); }
.pgnum-zone.top-right { top: 6px; right: 6px; }
.pgnum-zone.bottom-left { bottom: 6px; left: 6px; }
.pgnum-zone.bottom-center { bottom: 6px; left: 50%; transform: translateX(-50%); }
.pgnum-zone.bottom-right { bottom: 6px; right: 6px; }
.pgnum-zone.top-center[aria-pressed="true"], .pgnum-zone.bottom-center[aria-pressed="true"] { transform: translateX(-50%); }

/* Crop tool */
.crop-stage {
  position: relative;
  margin: 0 auto;
  overflow: hidden;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  touch-action: none;
  max-width: 100%;
}
.crop-canvas { display: block; width: 100%; height: 100%; }
.crop-box {
  position: absolute;
  border: 1.5px solid #fff;
  outline: 1px solid rgba(0, 0, 0, .4);
  cursor: move;
  box-sizing: border-box;
}
.crop-handle {
  position: absolute; width: 14px; height: 14px;
  background: #fff; border: 1.5px solid var(--c-brand);
  border-radius: 3px;
}
.crop-handle--nw { top: -7px; left: -7px; cursor: nwse-resize; }
.crop-handle--ne { top: -7px; right: -7px; cursor: nesw-resize; }
.crop-handle--sw { bottom: -7px; left: -7px; cursor: nesw-resize; }
.crop-handle--se { bottom: -7px; right: -7px; cursor: nwse-resize; }

/* Result zone */
.result {
  padding: var(--sp-5);
  text-align: center;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface-2);
}
.result__title { font-weight: 700; }
.result__meta { color: var(--c-text-muted); font-size: 13px; margin: var(--sp-1) 0 var(--sp-4); }

/* ---------- 6) Toasts & utilities ---------- */
.toast-stack { position: fixed; right: var(--sp-5); bottom: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); z-index: 50; }
.toast {
  min-width: 220px; max-width: 360px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 550;
  animation: toast-in var(--ease);
}
.toast--success { border-left: 4px solid var(--c-success); }
.toast--error { border-left: 4px solid var(--c-danger); }
.toast--info { border-left: 4px solid var(--c-brand); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; display: inline-block;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

[hidden] { display: none !important; }
.muted { color: var(--c-text-muted); }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
