/* ---------- Reset & variables ---------- */
*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --text: #1a1d29;
  --text-muted: #616678;
  --border: #e2e5ee;
  --primary: #1e5eff;
  --primary-hover: #1748c9;
  --danger: #e0364a;
  --success: #1e9e5a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(20, 25, 45, 0.06);
  --shadow-lg: 0 8px 28px rgba(20, 25, 45, 0.10);
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, "Helvetica Neue", Arial, sans-serif;
}
html.dark {
  --bg: #0f1218;
  --surface: #171b24;
  --surface-2: #1e2330;
  --text: #e9ecf3;
  --text-muted: #9aa2b5;
  --border: #2a3040;
  --primary: #4f82ff;
  --primary-hover: #6a96ff;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.5);
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
button, select, input { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px;
}
.brand {
  font-weight: 700; font-size: 1.05rem; color: var(--text);
  text-decoration: none; display: flex; align-items: center; gap: 10px;
}
.brand:hover { text-decoration: none; }
.brand img { display: block; border-radius: 10px; }
.brand-tool {
  font-weight: 400; font-size: 0.85rem; color: var(--text-muted);
  border-inline-start: 1px solid var(--border); padding-inline-start: 10px;
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--border); }

/* ---------- Ad slots ---------- */
.ad-slot {
  margin: 24px auto;
  text-align: center;
  /* Reserved space so the page never jumps when the ad loads (protects CLS).
     Mobile usually serves up to 300x250/336x280, desktop up to 970x250. */
  min-height: 280px;
  display: flex; align-items: center; justify-content: center;
}
.ad-slot .adsbygoogle { width: 100%; }
@media (min-width: 768px) {
  .ad-slot[data-ad="main"] { min-height: 250px; }
}

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 32px 0 20px; }
.hero h1 { font-size: clamp(1.5rem, 4vw, 2.25rem); margin: 0 0 12px; line-height: 1.25; }
.hero-sub { color: var(--text-muted); font-size: 1.05rem; margin: 0 auto 20px; max-width: 620px; }
.privacy-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--success) 12%, var(--surface));
  color: var(--success);
  border: 1px solid color-mix(in srgb, var(--success) 35%, transparent);
  padding: 8px 16px; border-radius: 999px;
  font-size: 0.92rem; font-weight: 600;
  margin-top: 4px;
}

/* ---------- Dropzone ---------- */
.dropzone-section { padding: 12px 0 24px; }
.dropzone {
  border: 2px dashed var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--primary); background: var(--surface-2); }
.dropzone.dragover { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); transform: scale(1.005); }
.dz-icon { font-size: 2.6rem; margin-bottom: 8px; }
.dz-title { font-size: 1.1rem; font-weight: 600; margin: 0 0 6px; }
.dz-hint { color: var(--text-muted); font-size: 0.9rem; margin: 0; }

/* ---------- Gallery ---------- */
.gallery-section { padding: 8px 0 24px; }
.gallery-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.gallery-header h2 { font-size: 1.25rem; margin: 0; }
.gallery-tools { display: flex; gap: 4px; align-items: center; }
.tool-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; font-size: 0.85rem; padding: 5px 10px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 6px;
}
.tool-btn:hover { border-color: var(--primary); }
.gallery-hint { color: var(--text-muted); font-size: 0.9rem; margin: 0 0 16px; }
.text-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 0.9rem; padding: 4px 8px; border-radius: 6px; }
.text-btn:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.gallery {
  list-style: none; padding: 0; margin: 0;
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.thumb {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s;
}
.thumb.sortable-ghost { opacity: 0.4; }
.thumb.sortable-drag { box-shadow: var(--shadow-lg); }
.thumb-img-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.thumb-img-wrap img { width: 100%; height: 100%; object-fit: contain; transition: transform 0.2s; }
.thumb-meta { padding: 8px 10px; font-size: 0.78rem; color: var(--text-muted); }
.thumb-name { color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.thumb-dims { display: block; margin-top: 2px; }
.thumb-actions {
  display: flex; gap: 0;
  border-top: 1px solid var(--border);
}
.thumb-actions button {
  flex: 1; background: none; border: none; padding: 8px 4px;
  cursor: pointer; font-size: 0.85rem; color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.thumb-actions button:hover { background: var(--surface-2); color: var(--text); }
.thumb-actions button.del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.thumb-handle {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.65); color: #fff;
  font-size: 0.75rem; letter-spacing: 2px; line-height: 1;
  padding: 7px 8px 7px 10px; border-radius: 999px;
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
  z-index: 2;
}
.thumb-handle:active { cursor: grabbing; }
.gallery.show-hint .thumb-handle { animation: handlePulse 1.1s ease-in-out 2; }
@keyframes handlePulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.3); background: var(--primary); }
}
.thumb-index {
  position: absolute; top: 6px; inset-inline-start: 6px;
  background: rgba(0,0,0,0.65); color: #fff;
  font-size: 0.72rem; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
}

/* ---------- Settings ---------- */
.settings-section { padding: 8px 0 24px; }
.settings-section h2 { font-size: 1.25rem; margin: 0 0 16px; }
.settings-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; font-weight: 600; }
.field select {
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-weight: 400;
}
.field select:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.field select:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Convert ---------- */
.convert-section { padding: 8px 0 32px; text-align: center; }
.convert-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius);
  padding: 16px 36px; font-size: 1.1rem; font-weight: 700;
  cursor: pointer; box-shadow: var(--shadow-lg);
  transition: background 0.15s, transform 0.1s;
  min-width: 240px;
}
.convert-btn:hover:not(:disabled) { background: var(--primary-hover); }
.convert-btn:active:not(:disabled) { transform: scale(0.985); }
.convert-btn:disabled { opacity: 0.6; cursor: wait; }
.convert-icon { font-size: 1.2rem; }

.progress-wrap { margin: 20px auto 0; max-width: 460px; }
.progress-bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width 0.2s; }
.progress-text { font-size: 0.9rem; color: var(--text-muted); margin: 8px 0 0; }

.error-box {
  margin: 16px auto 0; max-width: 620px;
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 0.9rem; text-align: start;
}

/* ---------- Content / SEO ---------- */
.content-section { padding: 24px 0 40px; max-width: 820px; margin: 0 auto; }
.content-section h2 { font-size: 1.4rem; margin: 0 0 12px; }
.content-section h3 { font-size: 1.1rem; margin: 24px 0 8px; }
.content-section p { margin: 0 0 14px; color: var(--text); }
.content-section ul, .content-section ol { padding-inline-start: 22px; margin: 0 0 16px; }
.content-section li { margin-bottom: 6px; }


/* ---------- FAQ (SEO) ---------- */
.faq-section { padding: 8px 0 32px; max-width: 820px; margin: 0 auto; }
.faq-section h2 { font-size: 1.4rem; margin: 0 0 16px; }
.faq-section details {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 10px; padding: 14px 18px;
}
.faq-section summary { cursor: pointer; font-weight: 600; }
.faq-section details p { margin: 10px 0 4px; color: var(--text-muted); font-size: 0.95rem; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 24px 0;
  margin-top: 24px;
}
.footer-inner { text-align: center; }
.footer-inner p { margin: 0 0 8px; color: var(--text-muted); font-size: 0.9rem; }
.footer-links { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.footer-links a { font-size: 0.9rem; }
.footer-brand {
  display: inline-flex; align-items: center; gap: 12px;
  text-decoration: none; color: var(--text);
  font-weight: 700; font-size: 1.1rem; margin-bottom: 4px;
}
.footer-brand:hover { text-decoration: none; }
.footer-brand img { display: block; border-radius: 16px; }
.footer-social { display: flex; gap: 10px; justify-content: center; margin: 12px 0 4px; }
.footer-social a {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
}
.footer-social a:hover { color: var(--text); }
.footer-rights { margin-top: 8px !important; }

/* ---------- Mobile tweaks ---------- */
@media (max-width: 520px) {
  .dropzone { padding: 34px 16px; }
  .convert-btn { width: 100%; min-width: 0; padding: 15px 20px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
  .thumb-meta { font-size: 0.72rem; padding: 6px 8px; }
  .hero { padding: 20px 0 12px; }
  .brand-tool { display: none; }
}

/* ---------- Print ---------- */
@media print {
  .site-header, .site-footer, .ad-slot, .dropzone-section,
  .convert-section, .settings-section { display: none; }
}

/* ---------- Lightbox / Preview Modal ---------- */
.thumb-index {
  /* nudge right to make room for the zoom button */
  inset-inline-start: auto;
  inset-inline-end: 6px;
}

.thumb-zoom {
  position: absolute;
  top: 6px;
  inset-inline-start: 6px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.95rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, transform 0.12s;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2;
}
.thumb-zoom:hover { background: rgba(0, 0, 0, 0.8); transform: scale(1.08); }
.thumb-zoom:active { transform: scale(0.95); }
.thumb-zoom:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 14, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 16px;
}
.lightbox.open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox-stage {
  position: relative;
  max-width: min(1100px, 100%);
  max-height: 100%;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  transform: scale(0.96);
  transition: transform 0.2s ease;
}
.lightbox.open .lightbox-stage { transform: scale(1); }

/* Top bar: filename + counter + close */
.lightbox-topbar {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #eef1f7;
  font-size: 0.9rem;
  padding: 0 4px;
  flex-wrap: wrap;
}
.lightbox-filename {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}
.lightbox-counter {
  color: #a8b0c4;
  font-variant-numeric: tabular-nums;
}
.lightbox-close {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.22); }

/* Image wrapper — has nav arrows absolutely positioned inside */
.lightbox-image-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
}
.lightbox-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  transition: transform 0.2s ease;
  user-select: none;
  -webkit-user-drag: none;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

/* Nav arrows */
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: none;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 3;
}
.lightbox-nav:hover { background: rgba(0,0,0,0.75); }
.lightbox-nav:active { transform: translateY(-50%) scale(0.94); }
.lightbox-nav:disabled { opacity: 0.25; cursor: not-allowed; }
.lightbox-nav.prev { inset-inline-start: 10px; }
.lightbox-nav.next { inset-inline-end: 10px; }

/* Bottom action bar */
.lightbox-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.lightbox-actions button {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}
.lightbox-actions button:hover { background: rgba(255,255,255,0.2); }
.lightbox-actions button.danger { color: #ff8a9a; }
.lightbox-actions button.danger:hover { background: rgba(224, 54, 74, 0.25); border-color: rgba(224,54,74,0.5); }
.lightbox-actions .ok-btn {
  background: var(--primary);
  border-color: var(--primary);
}
.lightbox-actions .ok-btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

/* Prevent body scroll when modal open */
body.lightbox-open { overflow: hidden; }

/* Mobile tweaks */
@media (max-width: 520px) {
  .lightbox { padding: 8px; }
  .lightbox-filename { max-width: 45%; font-size: 0.82rem; }
  .lightbox-nav { width: 38px; height: 38px; font-size: 1.2rem; }
  .lightbox-nav.prev { inset-inline-start: 4px; }
  .lightbox-nav.next { inset-inline-end: 4px; }
  .lightbox-actions button { padding: 8px 14px; font-size: 0.85rem; }
}

/* ---------- Filename field ---------- */
.field input[type="text"] {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 400;
  width: 100%;
}
.field input[type="text"]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: -2px;
  line-height: 1.4;
}