/* ==========================================================================
   Algo Resize — Core Stylesheet
   All design tokens live in the Theme block below. Nothing outside this
   block should ever hardcode a color, font, spacing, or radius value —
   rebrand by editing the variables here only.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&family=Noto+Sans+Bengali:wght@400;500;600&display=swap');

:root {
  /* Color — Ink Navy base with Violet / Signal Teal accents */
  --c-bg: #0A0E1A;
  --c-bg-alt: #0F1526;
  --c-surface: #151C30;
  --c-surface-2: #1B233C;
  --c-border: #262F4A;
  --c-text: #F4F6FB;
  --c-text-muted: #9AA3BD;
  --c-text-faint: #6B7590;
  --c-accent: #33e496;
  --c-accent-soft: rgba(51, 228, 150, 0.14);
  --c-accent-2: #24b8fd;
  --c-accent-2-soft: rgba(36, 184, 253, 0.14);
  --c-warn: #F5A623;
  --c-danger: #EF4560;
  --c-success: #2ED573;

  --shadow-sm: 0 2px 8px rgba(4, 6, 16, 0.35);
  --shadow-md: 0 12px 32px rgba(4, 6, 16, 0.45);
  --shadow-glow: 0 0 0 1px rgba(51, 228, 150, 0.25), 0 8px 30px rgba(51, 228, 150, 0.20);

  /* Typography */
  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --font-bn: 'Noto Sans Bengali', 'Inter', sans-serif;

  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-md: 1.125rem;
  --fs-lg: 1.375rem;
  --fs-xl: 1.75rem;
  --fs-2xl: 2.25rem;
  --fs-3xl: 3rem;
  --fs-4xl: 4rem;

  /* Spacing scale */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-8: 3rem;
  --sp-10: 4rem;
  --sp-12: 6rem;
  --sp-16: 8rem;

  /* Radius */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-full: 999px;

  /* Layout */
  --container-max: 1240px;
  --header-h: 76px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 160ms;
  --dur-base: 320ms;
  --dur-slow: 640ms;
}

/* Light theme overrides, applied via [data-theme="light"] on <html> */
[data-theme="light"] {
  --c-bg: #F6F7FB;
  --c-bg-alt: #FFFFFF;
  --c-surface: #FFFFFF;
  --c-surface-2: #EEF1F8;
  --c-border: #DDE1EC;
  --c-text: #10131F;
  --c-text-muted: #545C74;
  --c-text-faint: #8A91A8;
  --c-accent-soft: rgba(24, 174, 116, 0.12);
  --c-accent-2-soft: rgba(15, 143, 204, 0.12);
  --shadow-sm: 0 2px 8px rgba(16, 19, 31, 0.06);
  --shadow-md: 0 12px 32px rgba(16, 19, 31, 0.10);
  --shadow-glow: 0 0 0 1px rgba(24, 174, 116, 0.25), 0 8px 30px rgba(24, 174, 116, 0.14);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out);
}
html[lang="bn"] body { font-family: var(--font-bn); }

img { max-width: 100%; display: block; }
button { font-family: inherit; }
a { color: inherit; }

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--sp-5);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* -------------------------------------------------------------------- */
/* Top navigation                                                       */
/* -------------------------------------------------------------------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: flex;
  align-items: center;
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  background: color-mix(in srgb, var(--c-bg) 78%, transparent);
  border-bottom: 1px solid var(--c-border);
}
.topnav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-md);
  letter-spacing: -0.02em;
}
.brand__mark { color: var(--c-accent); }
.brand__tagline {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
  padding-left: var(--sp-3);
  border-left: 1px solid var(--c-border);
  margin-left: var(--sp-1);
  display: none;
}
@media (min-width: 640px) { .brand__tagline { display: inline; } }

.nav-controls { display: flex; align-items: center; gap: var(--sp-2); }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  min-width: 40px;
  height: 40px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  font-size: var(--fs-xs);
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--c-surface-2); border-color: var(--c-accent); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* -------------------------------------------------------------------- */
/* Hero                                                                  */
/* -------------------------------------------------------------------- */
.hero { padding: var(--sp-10) 0 var(--sp-6); text-align: center; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-accent);
  background: var(--c-accent-soft);
  border: 1px solid color-mix(in srgb, var(--c-accent) 35%, transparent);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-full);
  margin-bottom: var(--sp-4);
}
.eyebrow::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--c-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-accent) 25%, transparent);
}
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(var(--fs-2xl), 5vw, var(--fs-3xl));
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin: 0 auto var(--sp-4);
  max-width: 760px;
}
.hero p {
  color: var(--c-text-muted);
  font-size: clamp(var(--fs-base), 1.6vw, var(--fs-md));
  max-width: 560px;
  margin: 0 auto;
}

/* -------------------------------------------------------------------- */
/* Upload zone                                                          */
/* -------------------------------------------------------------------- */
.uploader {
  margin: var(--sp-8) auto 0;
  max-width: 780px;
  padding: var(--sp-8) var(--sp-5);
  border-radius: var(--r-lg);
  border: 1.5px dashed var(--c-border);
  background: var(--c-surface);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur-base) var(--ease-out), background var(--dur-base) var(--ease-out);
}
.uploader:hover, .uploader.is-dragover {
  border-color: var(--c-accent);
  background: color-mix(in srgb, var(--c-accent) 6%, var(--c-surface));
}
.uploader__icon { width: 48px; height: 48px; margin: 0 auto var(--sp-4); color: var(--c-accent); }
.uploader__title { font-family: var(--font-display); font-weight: 600; font-size: var(--fs-lg); margin: 0 0 var(--sp-2); }
.uploader__or { color: var(--c-text-faint); font-size: var(--fs-sm); margin: var(--sp-3) 0; }
.uploader__formats { color: var(--c-text-faint); font-size: var(--fs-xs); margin-top: var(--sp-4); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  border: none;
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: var(--fs-sm);
  padding: var(--sp-3) var(--sp-5);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-base) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--c-accent-2), var(--c-accent));
  color: #05130E;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-glow); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn-ghost { background: var(--c-surface); border: 1px solid var(--c-border); color: var(--c-text); }
.btn-ghost:hover { background: var(--c-surface-2); }
.btn-sm { padding: var(--sp-2) var(--sp-4); font-size: var(--fs-xs); }
.btn-danger-text { color: var(--c-danger); background: transparent; border: none; cursor: pointer; font-size: var(--fs-xs); font-weight: 600; }

/* -------------------------------------------------------------------- */
/* Section shell                                                        */
/* -------------------------------------------------------------------- */
.section { padding: var(--sp-8) 0; }
.section__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-5); gap: var(--sp-3); flex-wrap: wrap;
}
.section__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-lg);
  letter-spacing: -0.01em;
  margin: 0;
}
.section__title .count {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--c-accent);
  background: var(--c-accent-soft);
  padding: 2px 8px;
  border-radius: var(--r-full);
  margin-left: var(--sp-2);
  vertical-align: middle;
}

/* -------------------------------------------------------------------- */
/* Card grid — selected images / output / history                       */
/* -------------------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-4);
}
.card {
  background: var(--c-bg-alt);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.card__thumb { position: relative; aspect-ratio: 4 / 3; background: var(--c-surface); overflow: hidden; }
.card__thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform var(--dur-slow) var(--ease-out); }
.card:hover .card__thumb img { transform: scale(1.04); }
.card__remove {
  position: absolute; top: var(--sp-2); right: var(--sp-2);
  width: 28px; height: 28px; border-radius: 50%; border: none;
  background: rgba(10, 14, 26, 0.65); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; backdrop-filter: blur(4px);
  transition: background var(--dur-fast) var(--ease-out);
}
.card__remove:hover { background: var(--c-danger); }
.card__body { padding: var(--sp-3) var(--sp-4) var(--sp-4); }
.card__name {
  font-weight: 600; font-size: var(--fs-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: var(--sp-1);
}
.card__meta {
  font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--c-text-muted);
  display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2);
}
.card__meta .arrow { color: var(--c-accent); }
.card__badge {
  display: inline-block; font-size: 0.65rem; font-family: var(--font-mono);
  text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 6px;
  border-radius: 4px; background: var(--c-accent-2-soft); color: var(--c-accent-2);
}
.card__actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-3); }

.empty-state {
  text-align: center; padding: var(--sp-8) var(--sp-4);
  border: 1px dashed var(--c-border); border-radius: var(--r-md);
  color: var(--c-text-faint); font-size: var(--fs-sm);
}

/* -------------------------------------------------------------------- */
/* Settings panel                                                       */
/* -------------------------------------------------------------------- */
.panel {
  background: var(--c-bg-alt);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-sm);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.field { margin-bottom: var(--sp-5); }
.field label {
  display: block; font-size: var(--fs-xs); font-weight: 600; color: var(--c-text-muted);
  margin-bottom: var(--sp-2); text-transform: uppercase; letter-spacing: 0.03em;
}
.field input[type="number"], .field select {
  width: 100%; padding: var(--sp-3); border-radius: var(--r-sm);
  border: 1px solid var(--c-border); background: var(--c-surface); color: var(--c-text);
  font-family: var(--font-mono); font-size: var(--fs-md);
  transition: border-color var(--dur-fast) var(--ease-out);
}
.field input[type="number"]:focus, .field select:focus { border-color: var(--c-accent); outline: none; }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-3) 0; border-top: 1px solid var(--c-border);
}
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__track {
  position: absolute; inset: 0; border-radius: var(--r-full);
  background: var(--c-border); cursor: pointer; transition: background var(--dur-fast) var(--ease-out);
}
.switch__track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: transform var(--dur-fast) var(--ease-out);
}
.switch input:checked + .switch__track { background: var(--c-accent); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }

.preset-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.preset-btn {
  flex: 1; min-width: 64px; padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm); border: 1px solid var(--c-border);
  background: var(--c-surface); color: var(--c-text-muted);
  font-family: var(--font-mono); font-weight: 600; font-size: var(--fs-sm);
  cursor: pointer; transition: all var(--dur-fast) var(--ease-out);
}
.preset-btn:hover { border-color: var(--c-accent); color: var(--c-text); }
.preset-btn.is-active { background: var(--c-accent-soft); border-color: var(--c-accent); color: var(--c-accent); }

input[type="range"] {
  -webkit-appearance: none; width: 100%; height: 4px;
  border-radius: var(--r-full); background: var(--c-border); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--c-accent); border: 3px solid var(--c-bg-alt);
  box-shadow: 0 0 0 1px var(--c-accent); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--c-accent); border: 3px solid var(--c-bg-alt); cursor: pointer;
}
.quality-value { font-family: var(--font-mono); color: var(--c-accent); font-weight: 600; }

.progress-wrap { margin-top: var(--sp-5); }
.progress-bar { height: 8px; border-radius: var(--r-full); background: var(--c-border); overflow: hidden; }
.progress-bar__fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--c-accent-2), var(--c-accent));
  transition: width var(--dur-base) var(--ease-out);
}
.progress-label { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--c-text-muted); margin-top: var(--sp-2); }

/* -------------------------------------------------------------------- */
/* Toasts                                                                */
/* -------------------------------------------------------------------- */
.toast-stack {
  position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: 100;
  display: flex; flex-direction: column; gap: var(--sp-2);
  max-width: calc(100vw - 2 * var(--sp-5));
}
.toast {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-sm);
  background: var(--c-bg-alt); border: 1px solid var(--c-border);
  box-shadow: var(--shadow-md); font-size: var(--fs-sm); max-width: 340px;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.toast--success::before { background: var(--c-success); }
.toast--error::before { background: var(--c-danger); }
.toast--info::before { background: var(--c-accent-2); }

.skeleton {
  background: linear-gradient(90deg, var(--c-surface) 25%, var(--c-surface-2) 50%, var(--c-surface) 75%);
  background-size: 200% 100%; border-radius: var(--r-sm);
}

/* -------------------------------------------------------------------- */
/* Footer                                                                */
/* -------------------------------------------------------------------- */
.footer {
  border-top: 1px solid var(--c-border); padding: var(--sp-6) 0;
  text-align: center; color: var(--c-text-faint); font-size: var(--fs-sm);
}
.footer p { margin: var(--sp-1) 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* -------------------------------------------------------------------- */
/* Page-reorder grid (PDF Merge tool specific)                          */
/* -------------------------------------------------------------------- */
.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--sp-4);
}
.page-card {
  position: relative;
  background: var(--c-bg-alt);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
}
.page-card:active { cursor: grabbing; }
.page-card.is-dragging { opacity: 0.4; }
.page-card.is-dragover { border-color: var(--c-accent); box-shadow: var(--shadow-glow); }
.page-card__thumb {
  aspect-ratio: 3 / 4;
  background: var(--c-surface);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.page-card__thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.page-card__number {
  position: absolute; top: var(--sp-2); left: var(--sp-2);
  min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--c-accent); color: #05130E;
  font-family: var(--font-mono); font-weight: 700; font-size: var(--fs-xs);
  display: flex; align-items: center; justify-content: center;
}
.page-card__source {
  position: absolute; top: var(--sp-2); right: var(--sp-2);
  font-family: var(--font-mono); font-size: 0.62rem; text-transform: uppercase;
  padding: 2px 6px; border-radius: 4px;
  background: rgba(10, 14, 26, 0.65); color: #fff;
}
.page-card__footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-2) var(--sp-2);
  border-top: 1px solid var(--c-border);
}
.page-card__move { display: flex; gap: 2px; }
.page-card__move button, .page-card__remove-btn {
  width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--c-border);
  background: var(--c-surface); color: var(--c-text-muted);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.page-card__move button:hover { background: var(--c-surface-2); color: var(--c-text); }
.page-card__move button:disabled { opacity: 0.35; cursor: not-allowed; }
.page-card__remove-btn:hover { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.page-card__move svg, .page-card__remove-btn svg { width: 13px; height: 13px; }

.drop-indicator {
  height: 3px; border-radius: var(--r-full); background: var(--c-accent);
  margin: -1px 0; opacity: 0; transition: opacity var(--dur-fast) var(--ease-out);
}
.drop-indicator.is-active { opacity: 1; }
