:root {
  --bg: #0f1420;
  --bg-soft: #161d2e;
  --card: #1b2438;
  --border: #2a3550;
  --text: #eaf0ff;
  --text-dim: #9aa7c2;
  --primary: #5b8cff;
  --primary-dark: #3f6fe0;
  --accent: #35d69a;
  --danger: #ff6b6b;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

a { text-decoration: none; }

body {
  margin: 0;
  font-family: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #1c2740 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

.site-header {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(15, 20, 32, .85);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.header-inner .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 800;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 0;
}

.logo-mark {
  width: 36px;
  height: 36px;
  display: inline-flex;
  flex-shrink: 0;
}

.logo-mark svg { width: 100%; height: 100%; }

.main-nav {
  display: flex;
  gap: 6px;
}

.nav-link {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s ease;
}

.nav-link:hover { color: var(--text); background: var(--bg-soft); }
.nav-link { display: inline-block; }

.auth-trigger {
  background: var(--primary) !important;
  color: #fff !important;
}

.lang-switch {
  display: flex;
  gap: 4px;
  margin-inline-start: 4px;
  padding-inline-start: 8px;
  border-inline-start: 1px solid var(--border);
}

.lang-switch a {
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  transition: all .15s ease;
}

.lang-switch a:hover { color: var(--text); background: var(--bg-soft); }

.lang-switch a.active {
  background: var(--primary);
  color: #fff;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.user-chip #user-email-label {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, .7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 360px;
  width: 100%;
  position: relative;
}

.modal-box h2 { margin: 0 0 18px; font-size: 20px; }

.modal-box input {
  width: 100%;
  margin-bottom: 12px;
}

.modal-box .btn { width: 100%; margin-bottom: 10px; }

.modal-close {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
}

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin: 8px 0 0;
}

.auth-switch a { color: var(--primary); font-weight: 600; }

.faq-section { margin-top: 36px; }

.faq-section h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

.faq-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

.faq-item summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.faq-item summary::-webkit-details-marker { display: none; }

.faq-item summary::after {
  content: "+";
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.faq-item[open] summary::after { content: "\2212"; }

.faq-item p {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.7;
  margin: 10px 0 0;
}

.related-tools {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.related-tools h2 {
  font-size: 16px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.footer-grid {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  text-align: start;
  padding: 30px 0 16px;
}

.footer-brand p {
  color: var(--text-dim);
  font-size: 13px;
  max-width: 320px;
  margin: 6px 0 0;
}

.footer-links {
  display: flex;
  gap: 16px;
}

.footer-links a {
  color: var(--text-dim);
  font-size: 13px;
}

.footer-links a:hover { color: var(--text); }

.footer-copy {
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin: 0;
}

.about-section {
  margin: 40px 0;
  padding-top: 8px;
}

.about-section h2 {
  font-size: 20px;
  margin-bottom: 14px;
}

.about-section p {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.8;
  margin: 0 0 14px;
}

.about-section p:last-child { margin-bottom: 0; }

.ad-slot {
  min-height: 120px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  margin: 28px 0;
}

.legal-page h1 { font-size: 26px; }
.legal-page h2 { font-size: 18px; margin-top: 28px; }
.legal-page p, .legal-page li { color: var(--text-dim); line-height: 1.8; font-size: 14px; }
.legal-page { padding: 40px 0 60px; }

.tagline {
  color: var(--text-dim);
  margin-top: 8px;
  font-size: 14px;
}

.hero {
  text-align: center;
  padding: 48px 10px 40px;
}

.hero-badge {
  display: inline-block;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 18px;
}

.hero h1 {
  font-size: 36px;
  margin: 0 0 16px;
  line-height: 1.35;
}

.grad-text {
  background: linear-gradient(90deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  color: var(--text-dim);
  font-size: 16px;
  max-width: 620px;
  margin: 0 auto;
  line-height: 1.7;
}

.tool-category { margin: 36px 0; }

.tool-category h2 {
  font-size: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.tool-icon, .dz-icon, .cat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 10px;
  background: rgba(91, 140, 255, .14);
  color: var(--primary);
}

.tool-icon svg, .dz-icon svg, .cat-icon svg { display: block; }

.cat-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: rgba(53, 214, 154, .15);
  color: var(--accent);
}

.cat-icon svg { width: 18px; height: 18px; }

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

.tool-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: start;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: inherit;
  color: var(--text);
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}

.tool-card:hover {
  border-color: var(--primary);
  background: #1e2a45;
  transform: translateY(-2px);
}

.tool-icon { width: 44px; height: 44px; }
.tool-icon svg { width: 24px; height: 24px; }

.tool-title { font-weight: 700; font-size: 15px; }

.tool-desc { color: var(--text-dim); font-size: 13px; line-height: 1.5; }

.back-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  margin-bottom: 20px;
}

.back-btn:hover { color: var(--text); border-color: var(--primary); }
.back-btn { display: inline-block; }

.view { display: none; animation: fadeIn .2s ease; padding-bottom: 20px; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-head {
  text-align: center;
  margin-bottom: 24px;
}

.panel-head h1 {
  font-size: 26px;
  margin: 0 0 8px;
}

.panel-head p {
  color: var(--text-dim);
  margin: 0;
  font-size: 15px;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: #1a2338;
}

.dz-icon { width: 64px; height: 64px; border-radius: 16px; margin: 0 auto 12px; }
.dz-icon svg { width: 32px; height: 32px; }

.dz-content p { margin: 4px 0; }

.dz-hint {
  color: var(--text-dim);
  font-size: 13px;
}

.controls-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 18px;
}

.control-row { margin-bottom: 16px; }
.control-row:last-child { margin-bottom: 0; }

.control-row label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 14px;
}

.control-row.inline {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-row.inline label { margin-bottom: 0; white-space: nowrap; }

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.quality-hints {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 4px;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-weight: 500 !important;
  cursor: pointer;
}

select, input[type="number"], input[type="text"] {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
}

.actions-row {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s ease, filter .15s ease;
}

.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--accent); color: #06281c; }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.result-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  background: #000;
}

.result-info {
  padding: 12px;
  font-size: 13px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.size-row {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
}

.size-row .new-size { color: var(--accent); font-weight: 700; }

.reduction-badge {
  display: inline-block;
  background: rgba(53, 214, 154, .15);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  align-self: flex-start;
}

.increase-badge {
  display: inline-block;
  background: rgba(255, 107, 107, .15);
  color: var(--danger);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  align-self: flex-start;
}

.result-card .btn {
  margin: 0 12px 12px;
  padding: 8px 14px;
  font-size: 13px;
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

.reorder-hint {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 12px;
}

.thumb-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.thumb-item {
  width: 110px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: grab;
  position: relative;
  user-select: none;
}

.thumb-item.dragging { opacity: .4; }

.thumb-item img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
}

.thumb-item .thumb-label {
  font-size: 11px;
  padding: 4px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-dim);
}

.thumb-item .order-badge {
  position: absolute;
  top: 4px;
  inset-inline-start: 4px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

.thumb-item .remove-btn {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  background: var(--danger);
  color: #fff;
  border: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.file-list .thumb-item {
  width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100px;
  text-align: center;
  padding: 8px;
}

.file-list .thumb-item .file-icon { font-size: 28px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.site-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 30px 20px 40px;
}

.hint-note {
  background: rgba(255, 200, 80, .1);
  border: 1px solid rgba(255, 200, 80, .3);
  color: #ffcf7a;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin: 0 0 16px;
}

input[type="color"] {
  padding: 2px;
  width: 44px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  cursor: pointer;
}

.crop-stage {
  position: relative;
  max-width: 100%;
  display: inline-block;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.crop-stage img, .crop-stage canvas {
  display: block;
  max-width: 100%;
  max-height: 480px;
}

.crop-box {
  position: absolute;
  border: 2px dashed var(--primary);
  background: rgba(91, 140, 255, .15);
  cursor: move;
}

.crop-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  background: var(--primary);
  border: 2px solid #fff;
  border-radius: 50%;
  bottom: -8px;
  inset-inline-end: -8px;
  cursor: nwse-resize;
}

.pdf-compress-result {
  margin-top: 18px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.thumb-item .rotate-btn {
  position: absolute;
  bottom: 4px;
  inset-inline-end: 4px;
  background: var(--bg);
  color: #fff;
  border: 1px solid var(--border);
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.thumb-item .thumb-img-wrap {
  overflow: hidden;
  height: 90px;
}

.thumb-item .thumb-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .15s ease;
}

.scan-stage {
  position: relative;
  max-width: 100%;
  display: inline-block;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  line-height: 0;
}

.scan-stage img {
  display: block;
  max-width: 100%;
  max-height: 520px;
}

.scan-quad-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.scan-quad-overlay polygon {
  fill: rgba(53, 214, 154, .18);
  stroke: var(--accent);
  stroke-width: 2;
}

.scan-handle {
  position: absolute;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 50%;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

.scan-handle:active { cursor: grabbing; }

.scan-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 14px;
  padding: 14px;
}

.scan-mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}

.scan-mode-option {
  background: var(--bg-soft);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.scan-mode-option.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(53, 214, 154, .1);
}

.scan-mode-option .scan-mode-icon { font-size: 22px; display: block; margin-bottom: 4px; }

.scan-input-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 14px 0;
  flex-wrap: wrap;
}

.scan-input-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.scan-input-actions .btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.ocr-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 18px;
}

.ocr-panel h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.ocr-panel textarea {
  width: 100%;
  min-height: 160px;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  line-height: 1.7;
  font-family: inherit;
  resize: vertical;
}

.ocr-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 14px;
  padding: 6px 0 14px;
}

.nav-toggle-checkbox { display: none; }

.nav-toggle-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle-btn:hover { background: var(--bg-soft); }

.nav-toggle-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform .2s ease, opacity .2s ease;
}

@media (max-width: 760px) {
  .header-inner {
    flex-wrap: nowrap;
    position: relative;
  }

  .nav-toggle-btn { display: flex; }

  .main-nav {
    display: none;
    position: absolute;
    inset-inline: 0;
    top: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px 20px;
    box-shadow: 0 16px 28px rgba(0, 0, 0, .35);
  }

  .nav-toggle-checkbox:checked ~ .main-nav { display: flex; }

  .nav-toggle-checkbox:checked ~ .nav-toggle-btn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-toggle-checkbox:checked ~ .nav-toggle-btn span:nth-child(2) { opacity: 0; }
  .nav-toggle-checkbox:checked ~ .nav-toggle-btn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .main-nav .nav-link,
  .main-nav .auth-trigger {
    width: 100%;
    text-align: start;
    padding: 10px 12px;
  }

  .main-nav .user-chip {
    width: 100%;
    justify-content: space-between;
    padding: 10px 12px;
  }

  .main-nav .lang-switch {
    width: 100%;
    margin-inline-start: 0;
    padding-inline-start: 0;
    border-inline-start: none;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 6px;
  }
}

@media (max-width: 560px) {
  .control-row.inline { flex-wrap: wrap; }
  .panel-head h1 { font-size: 21px; }
  .hero h1 { font-size: 27px; }
}
