/* ============================================================
   PDFMerger — Premium Design System
   Tokens · Light/Dark/System theme · Glass · Motion
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --primary: #4f46e5;          /* indigo */
  --primary-2: #7c3aed;        /* purple */
  --electric: #2563eb;         /* electric blue */
  --accent: #06b6d4;           /* cyan */
  --accent-2: #10b981;         /* emerald */

  --grad-brand: linear-gradient(135deg, #2563eb 0%, #4f46e5 45%, #7c3aed 100%);
  --grad-cta: linear-gradient(135deg, #4f46e5, #06b6d4);

  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f2f4fd;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.55);

  --text-1: #0f172a;
  --text-2: #3b4356;
  --text-3: #69718a;
  --border: #e4e8f5;

  --ok-bg: #e7f8f0;   --ok-fg: #0f7b52;
  --err-bg: #fdecee;  --err-fg: #b42334;

  --shadow-1: 0 2px 10px rgba(15, 23, 42, 0.06);
  --shadow-2: 0 14px 40px rgba(30, 41, 99, 0.12);
  --glow: 0 8px 26px rgba(79, 70, 229, 0.35);

  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-full: 999px;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;

  --aurora-1: rgba(79, 70, 229, 0.16);
  --aurora-2: rgba(6, 182, 212, 0.14);
  --aurora-3: rgba(124, 58, 237, 0.12);
}

html[data-theme="dark"] {
  --bg: #0a0f1f;
  --surface: #111830;
  --surface-2: #182144;
  --glass: rgba(15, 22, 44, 0.68);
  --glass-border: rgba(255, 255, 255, 0.09);

  --text-1: #eef1fb;
  --text-2: #c4cadf;
  --text-3: #8d95b2;
  --border: #26304f;

  --ok-bg: rgba(16, 185, 129, 0.14); --ok-fg: #4ade9d;
  --err-bg: rgba(244, 63, 94, 0.14); --err-fg: #fb8a9b;

  --shadow-1: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 16px 44px rgba(0, 0, 0, 0.5);
  --glow: 0 8px 30px rgba(99, 102, 241, 0.4);

  --aurora-1: rgba(99, 102, 241, 0.22);
  --aurora-2: rgba(6, 182, 212, 0.14);
  --aurora-3: rgba(168, 85, 247, 0.16);
}

/* ---------- Base ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  line-height: 1.7;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  position: relative;
}
html.theme-anim body, html.theme-anim body * {
  transition: background-color 0.45s ease, color 0.45s ease, border-color 0.45s ease, box-shadow 0.45s ease;
}

/* Aurora background */
body::before, body::after {
  content: ""; position: fixed; z-index: -1; border-radius: 50%;
  filter: blur(90px); pointer-events: none;
}
body::before {
  width: 55vw; height: 55vw; top: -18vw; right: -12vw;
  background: radial-gradient(circle at 30% 30%, var(--aurora-1), transparent 65%),
              radial-gradient(circle at 70% 60%, var(--aurora-3), transparent 60%);
  animation: drift1 26s ease-in-out infinite alternate;
}
body::after {
  width: 48vw; height: 48vw; bottom: -20vw; left: -14vw;
  background: radial-gradient(circle at 60% 40%, var(--aurora-2), transparent 65%);
  animation: drift2 32s ease-in-out infinite alternate;
}
@keyframes drift1 { from { transform: translate(0,0) scale(1); } to { transform: translate(-6vw, 5vh) scale(1.12); } }
@keyframes drift2 { from { transform: translate(0,0) scale(1); } to { transform: translate(5vw, -4vh) scale(1.08); } }

a { color: var(--primary); }
::selection { background: rgba(79, 70, 229, 0.22); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* subtle scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

.skip-link { position: absolute; left: -9999px; top: 0; background: var(--primary); color: #fff; padding: 8px 16px; z-index: 100; border-radius: 0 0 var(--r-sm) 0; }
.skip-link:focus { left: 0; }

/* ---------- Topbar (glass) ---------- */
.topbar {
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  backdrop-filter: blur(16px) saturate(1.5);
  border-bottom: 1px solid var(--glass-border);
  padding: 12px 20px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner { max-width: 1200px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.logo {
  font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 9px; text-decoration: none;
  background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo i { background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nav-links { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.nav-links a {
  color: var(--text-2); text-decoration: none; font-weight: 550; font-size: 0.93rem;
  padding: 7px 13px; border-radius: var(--r-full); transition: background 0.25s, color 0.25s;
}
.nav-links a:hover { color: var(--primary); background: var(--surface-2); }

/* Theme toggle (injected by theme.js) */
.theme-toggle {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  width: 38px; height: 38px; border-radius: var(--r-full); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-size: 0.95rem;
  transition: transform 0.25s, color 0.25s, box-shadow 0.25s;
}
.theme-toggle:hover { color: var(--primary); transform: rotate(15deg) scale(1.06); box-shadow: var(--shadow-1); }

/* ---------- Layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 20px; }

header.hero, .hero { text-align: center; padding: 44px 16px 20px; color: var(--text-1); }
.hero h1 {
  font-size: clamp(1.9rem, 4.5vw, 3rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.15;
  background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 14px;
}
.hero .subtitle { font-size: 1.1rem; color: var(--text-2); max-width: 700px; margin: 0 auto; line-height: 1.6; }

/* ---------- Cards ---------- */
.tool-card, .preview-section, .upload-section, .content-card, .page {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.tool-card, .preview-section, .upload-section { padding: 28px; margin-top: 16px; }
.content-card { padding: 32px; margin-top: 26px; line-height: 1.75; }
.page { max-width: 900px; margin: 34px auto; padding: 44px 40px; }
.app-container { display: flex; flex-wrap: wrap; gap: 25px; margin-top: 10px; }
.upload-section { flex: 1.2; min-width: 320px; }
.preview-section { flex: 1; min-width: 300px; }

.section-title { font-size: 1.35rem; margin-bottom: 18px; color: var(--text-1); font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.section-title i { background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; }

.content-card h2, .page h1 { color: var(--text-1); font-weight: 800; letter-spacing: -0.02em; }
.page h1 { font-size: 2rem; margin-bottom: 16px; }
.content-card h2 { margin-bottom: 14px; font-size: 1.45rem; }
.content-card h3, .page h2 { color: var(--primary); margin-top: 24px; margin-bottom: 10px; font-size: 1.18rem; font-weight: 700; }
.page h2 { font-size: 1.3rem; margin-top: 28px; margin-bottom: 12px; }
.page h3 { color: var(--primary); margin-top: 20px; margin-bottom: 8px; font-size: 1.08rem; }
.content-card p, .page p { margin-bottom: 14px; color: var(--text-2); }
.content-card ul, .content-card ol, .page ul, .page ol { margin: 8px 0 14px 22px; color: var(--text-2); }
.content-card li, .page li { margin-bottom: 7px; }
.meta, .updated { color: var(--text-3); font-size: 0.9rem; margin-bottom: 22px; }

/* article extras */
.tip { background: var(--surface-2); border-left: 4px solid var(--accent); padding: 14px 18px; border-radius: var(--r-sm); margin: 18px 0; font-size: 0.96rem; color: var(--text-2); }
.tip strong { color: var(--primary); }
table { width: 100%; border-collapse: collapse; margin: 14px 0 18px; font-size: 0.95rem; }
th, td { border: 1px solid var(--border); padding: 10px 12px; text-align: left; vertical-align: top; color: var(--text-2); }
th { background: var(--surface-2); color: var(--primary); font-weight: 650; }
.cta { background: var(--grad-cta); color: #fff; border-radius: var(--r-md); padding: 22px 24px; margin-top: 30px; text-align: center; box-shadow: var(--glow); }
.cta a { color: #fff; font-weight: 700; text-decoration: underline; }
.cta p { color: #fff; margin-bottom: 0; }

/* values / contact grids */
.values, .contact-grid { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 20px; }
.value, .contact-card { flex: 1; min-width: 220px; background: var(--surface-2); padding: 20px; border-radius: var(--r-md); border: 1px solid var(--border); transition: transform 0.3s, box-shadow 0.3s; }
.value:hover, .contact-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-2); }
.value i, .contact-card i { font-size: 1.8rem; background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; margin-bottom: 10px; }
.value h3, .contact-card h3 { color: var(--text-1); margin: 6px 0; font-size: 1.05rem; }
.value p, .contact-card p { font-size: 0.94rem; margin-bottom: 0; color: var(--text-2); }

/* forms */
label { display: block; margin-bottom: 6px; font-weight: 600; color: var(--text-1); }
input, textarea, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r-sm);
  font-family: inherit; font-size: 1rem; margin-bottom: 14px;
  background: var(--surface); color: var(--text-1);
  transition: border-color 0.25s, box-shadow 0.25s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.14); }
textarea { resize: vertical; min-height: 130px; }
.form-note { font-size: 0.85rem; color: var(--text-3); margin-top: 6px; }
#form-success { display: none; background: var(--ok-bg); color: var(--ok-fg); padding: 14px; border-radius: var(--r-sm); margin-bottom: 20px; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--grad-cta); color: #fff; border: none;
  padding: 12px 24px; font-size: 0.98rem; border-radius: var(--r-full); cursor: pointer;
  font-weight: 650; display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.28);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s;
  position: relative; overflow: hidden;
}
.btn:hover { transform: translateY(-2px) scale(1.015); box-shadow: var(--glow); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); box-shadow: none; }
.btn-secondary:hover { color: var(--primary); box-shadow: var(--shadow-1); }
.btn-small { padding: 7px 15px; font-size: 0.88rem; }
.action-buttons { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- Drop area (glass) ---------- */
.drop-area {
  border: 2px dashed color-mix(in srgb, var(--primary) 45%, transparent);
  border-radius: var(--r-md); padding: 34px 20px; text-align: center; cursor: pointer;
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  margin-bottom: 18px;
  transition: border-color 0.3s, box-shadow 0.3s, transform 0.3s;
}
.drop-area:hover, .drop-area.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 5px rgba(6, 182, 212, 0.12), var(--shadow-1);
  transform: translateY(-2px);
}
.drop-area i { font-size: 2.7rem; background: var(--grad-cta); -webkit-background-clip: text; background-clip: text; color: transparent; margin-bottom: 10px; }
.drop-area h3 { margin-bottom: 6px; color: var(--text-1); font-weight: 700; }
.drop-area p { color: var(--text-3); margin-bottom: 14px; }
.file-input { display: none; }

/* ---------- Options / info ---------- */
.options { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 16px 18px; margin: 14px 0; }
.options label { font-weight: 600; color: var(--text-1); margin: 10px 0 5px; }
.options input[type=text], .options select { max-width: 340px; margin-bottom: 0; }
.options input.invalid { border-color: var(--err-fg); background: var(--err-bg); }
.options .radio-row { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0; }
.options .radio-row label { font-weight: 500; color: var(--text-2); margin: 0; display: flex; align-items: center; gap: 7px; cursor: pointer; }
.options input[type=radio] { width: auto; margin: 0; accent-color: var(--primary); }
.fileinfo { font-size: 0.95rem; color: var(--text-2); margin: 10px 0; }
.fileinfo strong { color: var(--primary); }

/* ---------- File list ---------- */
.file-list { margin: 12px 0; }
.file-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 14px; background: var(--surface-2); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: var(--r-sm); margin-bottom: 9px;
  transition: transform 0.25s, box-shadow 0.25s;
  animation: itemIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes itemIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.file-item:hover { transform: translateX(3px); box-shadow: var(--shadow-1); }
.file-item.dragging { opacity: 0.55; }
.file-info { display: flex; align-items: center; gap: 10px; }
.file-icon { color: var(--primary-2); }
.file-name { font-weight: 550; color: var(--text-1); word-break: break-all; }
.file-size { color: var(--text-3); font-size: 0.85rem; }
.file-actions button, .action-btn { background: none; border: none; color: var(--text-3); cursor: pointer; font-size: 1rem; padding: 5px 8px; border-radius: 7px; transition: color 0.2s, background 0.2s; }
.file-actions button:hover, .action-btn:hover { color: var(--primary); background: var(--surface); }

/* ---------- Preview grid ---------- */
.preview-container {
  flex: 1; border: 1px solid var(--border); border-radius: var(--r-md); padding: 20px;
  background: var(--surface-2); min-height: 280px;
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
}
.preview-container.has-preview { justify-content: flex-start; }
.preview-placeholder i { font-size: 3rem; color: var(--text-3); opacity: 0.6; }
.preview-placeholder h3 { color: var(--text-2); font-weight: 600; margin-top: 12px; }
.preview-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin: 16px 0 6px; }
.preview-head h3 { color: var(--text-1); font-size: 1.05rem; font-weight: 700; }
.pages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 12px; margin: 10px 0; width: 100%; }
.page-thumb {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--r-md);
  padding: 8px 8px 6px; text-align: center; position: relative;
  transition: border-color 0.25s, background 0.25s, transform 0.25s, box-shadow 0.25s;
  animation: itemIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.page-thumb .canvas-wrap { height: 140px; display: flex; align-items: center; justify-content: center; }
.page-thumb canvas, .page-thumb img { max-width: 120px; max-height: 124px; box-shadow: 0 3px 10px rgba(0,0,0,0.22); background: #fff; transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1); border-radius: 3px; }
.page-thumb .pnum { font-size: 0.76rem; color: var(--text-3); margin-top: 5px; word-break: break-all; }
.page-thumb.selectable { cursor: pointer; }
.page-thumb.selectable:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: var(--shadow-1); }
.page-thumb.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.page-thumb .badge { position: absolute; top: 6px; right: 6px; background: var(--accent); color: #fff; border-radius: 50%; width: 22px; height: 22px; line-height: 22px; font-size: 0.72rem; display: none; box-shadow: var(--shadow-1); }
.page-thumb.selected .badge { display: block; animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
.thumb-btns { display: flex; justify-content: center; gap: 6px; margin-top: 6px; }
.thumb-btns button { background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 4px 10px; cursor: pointer; color: var(--primary); font-size: 0.85rem; transition: background 0.2s, transform 0.2s; }
.thumb-btns button:hover { background: var(--surface-2); transform: scale(1.1); }
.preview-note { font-size: 0.85rem; color: var(--text-3); margin: 6px 0 8px; }

/* compare */
.compare-grid { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; }
.compare-cell { flex: 1; min-width: 240px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px; text-align: center; }
.compare-cell img { max-width: 100%; box-shadow: 0 3px 12px rgba(0,0,0,0.25); background: #fff; border-radius: 4px; }
.compare-cell h4 { color: var(--primary); margin-bottom: 8px; font-size: 0.95rem; }

/* ---------- Progress & status ---------- */
.progress-container { margin-top: 16px; display: none; }
.progress-bar { height: 9px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-full); overflow: hidden; }
.progress {
  height: 100%; width: 0%; border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--electric), var(--primary-2), var(--accent), var(--electric));
  background-size: 250% 100%;
  animation: shimmer 1.6s linear infinite;
  transition: width 0.3s ease;
}
@keyframes shimmer { from { background-position: 0% 0; } to { background-position: 250% 0; } }
#progressText { color: var(--text-3); font-size: 0.9rem; margin-top: 6px; }
.status { margin-top: 16px; padding: 13px 16px; border-radius: var(--r-sm); text-align: center; display: none; font-weight: 550; animation: itemIn 0.35s ease; }
.status.success { background: var(--ok-bg); color: var(--ok-fg); display: block; }
.status.error { background: var(--err-bg); color: var(--err-fg); display: block; }

/* ---------- Index page sections ---------- */
.steps, .features { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 20px; }
.step, .feature {
  flex: 1; min-width: 210px; text-align: center; padding: 24px 20px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  color: var(--text-2); transition: transform 0.3s, box-shadow 0.3s;
}
.step:hover, .feature:hover { transform: translateY(-5px); box-shadow: var(--shadow-2); }
.feature i { font-size: 1.9rem; background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; margin-bottom: 10px; }
.feature h3, .step h3 { color: var(--text-1); margin: 8px 0 6px; font-size: 1.05rem; }
.step-number {
  width: 42px; height: 42px; border-radius: var(--r-full); background: var(--grad-cta); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 750; margin-bottom: 10px;
  box-shadow: var(--glow);
}
.faq-item { border-bottom: 1px solid var(--border); padding: 14px 0; }
.faq-q { font-weight: 650; color: var(--text-1); cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 12px; transition: color 0.2s; }
.faq-q:hover { color: var(--primary); }
.faq-q i { transition: transform 0.3s; color: var(--text-3); }
.faq-item.open .faq-q i { transform: rotate(180deg); color: var(--primary); }
.faq-a { display: none; padding-top: 8px; color: var(--text-2); }
.faq-item.open .faq-a { display: block; animation: itemIn 0.3s ease; }

.ad-slot { background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--r-sm); padding: 12px; margin: 25px 0; text-align: center; color: var(--text-3); font-size: 0.85rem; min-height: 90px; display: flex; align-items: center; justify-content: center; }
.ad-slot-inner { width: 100%; }

/* ---------- Footer ---------- */
footer { background: var(--surface); border-top: 1px solid var(--border); color: var(--text-2); padding: 34px 20px 26px; margin-top: 52px; font-size: 0.92rem; }
footer a { color: var(--primary); text-decoration: none; }
footer a:hover { text-decoration: underline; }
footer p { color: var(--text-2); }
.footer-inner { max-width: 1200px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 30px; }
.footer-col { flex: 1; min-width: 200px; }
.footer-col h4 { color: var(--text-1); margin-bottom: 10px; font-size: 1rem; }
.footer-col a { display: block; margin-bottom: 7px; color: var(--text-3); }
.footer-col a:hover { color: var(--primary); }
.footer-bottom { max-width: 1200px; margin: 25px auto 0; padding-top: 18px; border-top: 1px solid var(--border); text-align: center; font-size: 0.88rem; color: var(--text-3); }

/* simple centered footer variant (article/tool pages) */
footer.simple, footer:not(:has(.footer-inner)) { text-align: center; }

/* ---------- Scroll reveal (applied by theme.js) ---------- */
.reveal { opacity: 0; transform: translateY(20px); transition: opacity 0.65s ease, transform 0.65s cubic-bezier(0.22, 1, 0.36, 1); }
.reveal.in { opacity: 1; transform: none; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .hero h1 { font-size: 1.65rem; }
  .page { padding: 26px 20px; margin: 15px; }
  .tool-card, .content-card, .upload-section, .preview-section { padding: 20px; }
  .btn { width: 100%; justify-content: center; }
  .btn-small { width: auto; }
  .pages-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  body::before, body::after { filter: blur(60px); }
}

/* ============================================================
   Motion & Interface Polish (v2)
   ============================================================ */

/* ---------- Page entrance ---------- */
@keyframes pageIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.container, .page { animation: pageIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) both; }

/* ---------- Animated gradient headlines & logo ---------- */
.hero h1, .logo, .logo i {
  background-size: 220% 100%;
  animation: gradPan 7s ease-in-out infinite alternate;
}
@keyframes gradPan { from { background-position: 0% 50%; } to { background-position: 100% 50%; } }

/* ---------- Floating hero decorations (injected by theme.js) ---------- */
header.hero, .hero { position: relative; }
.hero h1, .hero .subtitle { position: relative; z-index: 1; }
.float-deco {
  position: absolute; z-index: 0; pointer-events: none; user-select: none;
  background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent;
  opacity: 0.16; filter: drop-shadow(0 6px 14px rgba(79,70,229,0.25));
  animation: floaty var(--fd-dur, 10s) ease-in-out var(--fd-delay, 0s) infinite alternate;
}
html[data-theme="dark"] .float-deco { opacity: 0.22; }
@keyframes floaty {
  from { transform: translateY(0) rotate(var(--fd-rot, -8deg)) scale(1); }
  to   { transform: translateY(-22px) rotate(calc(var(--fd-rot, -8deg) * -1)) scale(1.08); }
}

/* ---------- Drop area icon bob ---------- */
.drop-area > i { display: inline-block; animation: bob 3.2s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
.drop-area.drag-over > i { animation: bob 0.5s ease-in-out infinite; }

/* ---------- Button ripple (injected by theme.js) ---------- */
.ripple {
  position: absolute; border-radius: 50%; pointer-events: none;
  background: rgba(255, 255, 255, 0.5);
  transform: scale(0); animation: rippleGo 0.55s ease-out forwards;
}
.btn-secondary .ripple { background: rgba(79, 70, 229, 0.22); }
@keyframes rippleGo { to { transform: scale(3.2); opacity: 0; } }

/* ---------- Cursor glow on cards (vars set by theme.js) ---------- */
.glow-track { position: relative; }
.glow-track::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  opacity: 0; transition: opacity 0.35s;
  background: radial-gradient(340px circle at var(--mx, 50%) var(--my, 50%), rgba(79, 70, 229, 0.10), transparent 65%);
}
html[data-theme="dark"] .glow-track::after {
  background: radial-gradient(340px circle at var(--mx, 50%) var(--my, 50%), rgba(129, 140, 248, 0.14), transparent 65%);
}
.glow-track:hover::after { opacity: 1; }

/* ---------- Status icons (pure CSS, animated) ---------- */
.status.success::before, .status.error::before {
  font-family: "Font Awesome 6 Free"; font-weight: 900;
  display: inline-block; margin-right: 9px;
  animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.status.success::before { content: "\f058"; color: var(--ok-fg); }
.status.error::before { content: "\f06a"; color: var(--err-fg); }

/* ---------- Scroll progress bar ---------- */
.scroll-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: var(--grad-cta); z-index: 200; border-radius: 0 var(--r-full) var(--r-full) 0;
  box-shadow: 0 0 8px rgba(79, 70, 229, 0.5);
}

/* ---------- Back to top ---------- */
.back-top {
  position: fixed; right: 22px; bottom: 22px; z-index: 90;
  width: 46px; height: 46px; border-radius: var(--r-full); border: 1px solid var(--border);
  background: var(--glass); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  color: var(--primary); font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(14px); pointer-events: none;
  transition: opacity 0.35s, transform 0.35s, box-shadow 0.25s;
  box-shadow: var(--shadow-1);
}
.back-top.show { opacity: 1; transform: none; pointer-events: auto; }
.back-top:hover { box-shadow: var(--glow); transform: translateY(-3px); }

/* ---------- Active nav link ---------- */
.nav-links a.active { color: var(--primary); background: var(--surface-2); font-weight: 650; }

/* ---------- Progress text loading dots ---------- */
#progressText::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* decorative motion honours reduced-motion via the global rule above */
@media (max-width: 600px) { .float-deco { display: none; } .back-top { right: 14px; bottom: 14px; } }

/* ============================================================
   Fill & Sign tool + Excel preview
   ============================================================ */
.sig-gallery { display: flex; gap: 12px; flex-wrap: wrap; }
.sig-card {
  position: relative; background: #fff; border: 2px solid var(--border); border-radius: var(--r-sm);
  padding: 8px 12px; cursor: pointer; transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.sig-card img { max-width: 170px; max-height: 60px; display: block; }
.sig-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-1); }
.sig-card.armed { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(6,182,212,0.15); }
.sig-del {
  position: absolute; top: -8px; right: -8px; width: 22px; height: 22px; border-radius: 50%;
  border: none; background: var(--err-fg); color: #fff; font-size: 0.7rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.sig-tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.sig-tab {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
  padding: 8px 16px; border-radius: var(--r-full); cursor: pointer; font-weight: 600; font-size: 0.9rem;
  display: inline-flex; align-items: center; gap: 7px; transition: all 0.2s;
}
.sig-tab.active { background: var(--grad-cta); color: #fff; border-color: transparent; }
.sig-styles { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.sig-style {
  background: #fff; color: #141b52; border: 2px solid var(--border); border-radius: var(--r-sm);
  padding: 6px 16px; font-size: 1.5rem; cursor: pointer; transition: border-color 0.2s;
}
.sig-style.active { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(6,182,212,0.15); }
.sig-pad { background: #fff; border: 2px dashed var(--border); border-radius: var(--r-sm); max-width: 100%; touch-action: none; cursor: crosshair; }
.sig-viewer { overflow: auto; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); padding: 14px; display: flex; justify-content: center; }
.sig-pagewrap { position: relative; box-shadow: 0 4px 18px rgba(0,0,0,0.25); background: #fff; }
.sig-pagewrap canvas { display: block; }
.sig-place { position: absolute; cursor: grab; touch-action: none; border: 2px dashed transparent; border-radius: 4px; }
.sig-place:active { cursor: grabbing; }
.sig-place img { width: 100%; display: block; pointer-events: none; }
.sig-place .sig-text { color: #141b52; font-family: 'Inter', sans-serif; font-weight: 600; white-space: nowrap; pointer-events: none; display: block; }
.sig-place:hover, .sig-place.selected { border-color: var(--accent); background: rgba(6,182,212,0.06); }
.sig-handle {
  position: absolute; right: -8px; bottom: -8px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; cursor: nwse-resize; touch-action: none;
  opacity: 0; transition: opacity 0.2s; box-shadow: var(--shadow-1);
}
.sig-place:hover .sig-handle, .sig-place.selected .sig-handle { opacity: 1; }

/* Excel preview table */
.xl-wrap { overflow: auto; max-height: 380px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.xl-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; margin: 0; }
.xl-table td { border: 1px solid var(--border); padding: 5px 9px; white-space: nowrap; color: var(--text-2); }
.xl-table tr:first-child td { background: var(--surface-2); font-weight: 650; color: var(--primary); }
.xl-table tr:hover td { background: var(--surface-2); }

/* ---------- Fill & Sign: text formatting toolbar ---------- */
.text-toolbar { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; margin: 12px 0; display: none; }
.text-toolbar.open { display: block; animation: itemIn 0.3s ease; }
.text-toolbar textarea { min-height: 64px; margin-bottom: 10px; font-size: 1rem; }
.tt-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.tt-row label { margin: 0 4px 0 0; font-size: 0.85rem; color: var(--text-3); font-weight: 600; }
.tt-row select { width: auto; max-width: 160px; margin: 0; padding: 7px 10px; font-size: 0.9rem; }
.tt-row input[type=number] { width: 74px; margin: 0; padding: 7px 8px; text-align: center; font-size: 0.9rem; }
.tt-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
  min-width: 36px; height: 36px; border-radius: 8px; cursor: pointer; font-size: 0.9rem;
  display: inline-flex; align-items: center; justify-content: center; transition: all 0.18s;
}
.tt-btn:hover { color: var(--primary); border-color: var(--primary); }
.tt-btn.active { background: var(--grad-cta); color: #fff; border-color: transparent; }
.tt-sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; }
.tt-swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; padding: 0; transition: transform 0.15s, box-shadow 0.15s; }
.tt-swatch:hover { transform: scale(1.15); }
.tt-swatch.active { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--accent); }
.sig-place .sig-text { white-space: pre; line-height: 1.25; }

/* ---------- Fill & Sign: photo version chooser + camera ---------- */
.sig-versions { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.sig-version { text-align: center; cursor: pointer; border: 2px solid var(--border); border-radius: var(--r-md); padding: 10px; background: var(--surface); transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s; }
.sig-version:hover { transform: translateY(-3px); box-shadow: var(--shadow-1); }
.sig-version.chosen { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.15); }
.sig-version .checker {
  width: 200px; height: 130px; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; overflow: hidden; background-color: #fff;
  background-image: linear-gradient(45deg, #d9dbe6 25%, transparent 25%), linear-gradient(-45deg, #d9dbe6 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #d9dbe6 75%), linear-gradient(-45deg, transparent 75%, #d9dbe6 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.sig-version .checker img { max-width: 190px; max-height: 120px; }
.sig-version h4 { color: var(--text-2); font-size: 0.9rem; margin-top: 8px; font-weight: 600; }
.sig-version.chosen h4 { color: var(--primary); }
.sig-savechk { display: flex; align-items: center; gap: 8px; margin-left: auto; font-size: 0.9rem; color: var(--text-2); font-weight: 550; cursor: pointer; }
.sig-savechk input { width: auto; margin: 0; accent-color: var(--primary); }
