:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1b2434;
  --muted: #5a6577;
  --accent: #dc2626;
  --accent-strong: #b91c1c;
  --accent-soft: #fdecec;
  --border: #e3e7ee;
  --ring: rgba(220, 38, 38, 0.35);
  --ok: #15803d;
  --ok-soft: #e9f9ef;
  --shadow: 0 10px 30px rgba(20, 28, 45, 0.08);
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

html[dir="rtl"] {
  --font: "Cairo", "Segoe UI", Tahoma, system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f1420;
  --surface: #171e2e;
  --text: #e8ecf4;
  --muted: #9aa4b8;
  --accent: #ef4444;
  --accent-strong: #dc2626;
  --accent-soft: #2a1a1d;
  --border: #273043;
  --ring: rgba(239, 68, 68, 0.4);
  --ok: #4ade80;
  --ok-soft: #14301f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

img, svg { display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  width: min(1100px, 100% - 2.5rem);
  margin-inline: auto;
}

:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  inset-inline-start: -999px;
  inset-block-start: 0.5rem;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  z-index: 200;
}
.skip-link:focus { inset-inline-start: 0.5rem; }

.site-header {
  position: sticky;
  inset-block-start: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-block-end: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.7rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .logo-badge { flex: none; }
.header-actions { display: flex; align-items: center; gap: 0.55rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.55rem 1.05rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  box-shadow: 0 6px 18px rgba(220, 38, 38, 0.35);
}
.btn-primary:hover { box-shadow: 0 8px 22px rgba(220, 38, 38, 0.45); }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.lang-switch {
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
}
.lang-switch:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.hero { padding-block: clamp(2.5rem, 7vw, 5rem) clamp(1.5rem, 4vw, 3rem); text-align: center; }
.hero h1 {
  font-size: clamp(1.7rem, 4.5vw, 2.9rem);
  line-height: 1.25;
  margin-inline: auto;
  max-width: 22ch;
  letter-spacing: -0.02em;
}
.hero .accent { color: var(--accent); }
.lede {
  color: var(--muted);
  max-width: 60ch;
  margin: 1rem auto 0;
  font-size: clamp(0.98rem, 2vw, 1.13rem);
}
.badges {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
  padding: 0;
  margin: 1.6rem 0 0;
}
.badges li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.badges svg { width: 15px; height: 15px; color: var(--ok); }

.section { padding-block: clamp(1.8rem, 5vw, 3.2rem); }
.section-head { text-align: center; max-width: 46ch; margin-inline: auto; margin-block-end: 2rem; }
.section-head h2 { font-size: clamp(1.35rem, 3vw, 1.8rem); margin: 0 0 0.4rem; letter-spacing: -0.01em; }
.section-head p { color: var(--muted); margin: 0; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 0.9rem;
}
.card {
  appearance: none;
  font: inherit;
  text-align: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  cursor: pointer;
  display: grid;
  gap: 0.45rem;
  align-content: start;
  color: var(--text);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  text-decoration: none;
}
.card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}
.card-icon svg { width: 22px; height: 22px; }
.card h3 { margin: 0.35rem 0 0; font-size: 1.02rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.86rem; line-height: 1.5; }

.steps {
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  padding: 0;
  margin: 0;
}
.steps li {
  counter-increment: step;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  position: relative;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  inset-block-start: -0.8rem;
  inset-inline-start: 1.1rem;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.35);
}
.steps h3 { margin: 0.6rem 0 0.25rem; font-size: 1rem; }
.steps p { margin: 0; color: var(--muted); font-size: 0.88rem; }

.faq-list { display: grid; gap: 0.6rem; max-width: 780px; margin-inline: auto; }
.faq-list details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.faq-list summary {
  cursor: pointer;
  font-weight: 700;
  padding: 0.95rem 1.1rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.faq-list summary::-webkit-details-marker { display: none; }
.faq-list summary::after {
  content: "+";
  font-size: 1.3rem;
  color: var(--accent);
  flex: none;
  transition: transform 0.2s ease;
}
.faq-list details[open] summary::after { transform: rotate(45deg); }
.faq-list details p {
  margin: 0;
  padding: 0 1.1rem 1rem;
  color: var(--muted);
  font-size: 0.93rem;
}

.site-footer {
  border-block-start: 1px solid var(--border);
  margin-block-start: 2rem;
  padding-block: 2rem 2.4rem;
  background: var(--surface);
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  justify-content: space-between;
  align-items: flex-start;
}
.footer-brand { display: grid; gap: 0.4rem; max-width: 42ch; }
.footer-brand strong { font-size: 1rem; }
.footer-brand span { color: var(--muted); font-size: 0.86rem; }
.footer-links { display: grid; gap: 0.35rem; font-size: 0.9rem; }
.footer-links a { color: var(--muted); }
.footer-links a:hover { color: var(--accent); }
.copyright { margin-block-start: 1.6rem; color: var(--muted); font-size: 0.82rem; text-align: center; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 14, 24, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: min(660px, 100%);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 30px 70px rgba(5, 10, 25, 0.4);
  animation: pop 0.22s ease;
}
@keyframes pop {
  from { transform: scale(0.96) translateY(8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.2rem;
  border-block-end: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.08rem; flex: 1; }
.modal-body { padding: 1.2rem; overflow-y: auto; display: grid; gap: 1.1rem; align-content: start; }
.tool-desc { margin: 0; color: var(--muted); font-size: 0.9rem; }

.dropzone {
  border: 2px dashed color-mix(in srgb, var(--accent) 40%, var(--border));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 4%, var(--surface));
  padding: 1.6rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone svg { width: 34px; height: 34px; margin-inline: auto; color: var(--accent); }
.dropzone strong { display: block; margin-block-start: 0.5rem; font-size: 0.98rem; }
.dropzone small { color: var(--muted); display: block; margin-block-start: 0.15rem; font-size: 0.8rem; }

.file-list { display: grid; gap: 0.45rem; }
.file-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  font-size: 0.87rem;
}
.file-item .fname {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.file-item .fsize { color: var(--muted); font-size: 0.78rem; flex: none; }
.file-item button {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
}
.file-item button:hover { color: var(--accent); border-color: var(--accent); }

.field-row { display: grid; gap: 0.3rem; }
.field-row label { font-weight: 700; font-size: 0.88rem; }
.field-row .hint { color: var(--muted); font-size: 0.78rem; margin: 0; }
.field-grid { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
input[type="text"], input[type="number"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  width: 100%;
}
input[type="color"] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 4px;
  cursor: pointer;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
.radio-set { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}
.radio-pill:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.radio-pill input { accent-color: var(--accent); margin: 0; }

.action-bar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.progress-wrap { display: grid; gap: 0.4rem; }
.progress-label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
progress {
  appearance: none;
  width: 100%;
  height: 8px;
  border: none;
  border-radius: 99px;
  overflow: hidden;
  background: var(--border);
}
progress::-webkit-progress-bar { background: var(--border); border-radius: 99px; }
progress::-webkit-progress-value { background: linear-gradient(90deg, var(--accent), var(--accent-strong)); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }
progress:indeterminate { background: var(--border); }
progress:indeterminate::-moz-progress-bar {
  background: var(--accent);
  width: 40%;
  animation: slide 1.1s infinite alternate ease-in-out;
}
@keyframes slide { from { margin-inline-start: 0; } to { margin-inline-start: 60%; } }

.result-box {
  border: 1px solid color-mix(in srgb, var(--ok) 45%, var(--border));
  background: var(--ok-soft);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: grid;
  gap: 0.6rem;
}
.result-box .result-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  color: var(--ok);
  font-size: 0.95rem;
}
.result-files { display: grid; gap: 0.45rem; }
.result-file {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  font-size: 0.87rem;
}
.result-file .rname {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.result-file .rsize { color: var(--muted); font-size: 0.78rem; flex: none; }
.result-file a {
  flex: none;
  font-weight: 700;
  font-size: 0.84rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
}
.result-file a:hover { text-decoration: none; filter: brightness(1.08); }

.error-box {
  border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--border));
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.thumbs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.6rem;
}
.thumb {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  aspect-ratio: 3 / 4;
  padding: 0;
}
.thumb canvas { width: 100%; height: 100%; object-fit: contain; }
.thumb .page-no {
  position: absolute;
  inset-block-end: 4px;
  inset-inline-end: 4px;
  background: rgba(15, 20, 32, 0.75);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 6px;
  padding: 0.05rem 0.4rem;
}
.thumb.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.thumb.selected::after {
  content: "✓";
  position: absolute;
  inset-block-start: 4px;
  inset-inline-start: 4px;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.toast-region {
  position: fixed;
  inset-block-end: 1.2rem;
  inset-inline: 0;
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  z-index: 150;
  pointer-events: none;
}
.toast {
  background: #101626;
  color: #f1f4fa;
  border-radius: 12px;
  padding: 0.65rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  max-width: min(92vw, 480px);
  text-align: center;
  animation: toast-in 0.25s ease;
}
.toast.error { background: var(--accent-strong); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes toast-in {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.offline-banner {
  display: none;
  background: var(--accent-soft);
  color: var(--accent-strong);
  text-align: center;
  font-size: 0.83rem;
  font-weight: 700;
  padding: 0.4rem 1rem;
}
body.is-offline .offline-banner { display: block; }

noscript .noscript-box {
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 0.9rem 1.2rem;
  border-radius: 12px;
  margin: 1rem auto;
  max-width: 720px;
  text-align: center;
  font-weight: 700;
}

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

@media (max-width: 640px) {
  .header-inner { flex-wrap: wrap; }
  .brand span { font-size: 0.95rem; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.7rem; }
  .card { padding: 0.95rem; }
  .modal-body { padding: 1rem; }
  .btn { padding: 0.5rem 0.9rem; font-size: 0.88rem; }
}

@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; }
}
