/* ===========================
   CSS Variables & Themes
   =========================== */
:root {
    --bg: #f0f4ff;
    --card-bg: rgba(255, 255, 255, 0.85);
    --compare-bg: rgba(248, 250, 255, 0.9);
    --text: #1a1d2e;
    --text-muted: #6b7280;
    --card-shadow: rgba(99, 118, 210, 0.12);
    --primary: #4f6ef7;
    --primary-light: #7b93fa;
    --secondary: #06d6a0;
    --accent: #ff6b6b;
    --danger: #d92d34;
    --danger-bg: rgba(217, 45, 52, 0.07);
    --border: rgba(79, 110, 247, 0.2);
    --glass: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(255, 255, 255, 0.8);
    --nav-bg: rgba(255, 255, 255, 0.9);
    --badge-bg: rgba(79, 110, 247, 0.08);
    --feat-bg: rgba(255, 255, 255, 0.75);
    --faq-bg: rgba(255,255,255,0.7);
    --fmt-bg: rgba(79,110,247,0.06);
}

[data-theme="dark"] {
    --bg: #080c1a;
    --card-bg: rgba(15, 20, 40, 0.9);
    --compare-bg: rgba(12, 16, 32, 0.95);
    --text: #e8ecf8;
    --text-muted: #8892b0;
    --card-shadow: rgba(0, 0, 0, 0.4);
    --primary: #6b8aff;
    --primary-light: #8fa5ff;
    --secondary: #06d6a0;
    --danger: #ff7b80;
    --danger-bg: rgba(255, 123, 128, 0.1);
    --border: rgba(107, 138, 255, 0.25);
    --glass: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.1);
    --nav-bg: rgba(10, 14, 28, 0.95);
    --badge-bg: rgba(107, 138, 255, 0.12);
    --feat-bg: rgba(20, 26, 50, 0.8);
    --faq-bg: rgba(15,20,40,0.8);
    --fmt-bg: rgba(107,138,255,0.08);
}

/* ===========================
   Base
   =========================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Vazirmatn', sans-serif;
    font-weight: 400;
    direction: rtl;
    min-height: 100vh;
    line-height: 1.7;
    font-size: 1rem;
    transition: background 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
}

/* ===========================
   Ambient Background
   =========================== */
.ambient {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.35;
    animation: blobFloat 12s ease-in-out infinite;
}

.blob-1 {
    width: 40rem;
    height: 40rem;
    background: radial-gradient(circle, #4f6ef7, transparent);
    top: -15rem;
    right: -10rem;
    animation-delay: 0s;
}

.blob-2 {
    width: 30rem;
    height: 30rem;
    background: radial-gradient(circle, #06d6a0, transparent);
    bottom: 10rem;
    left: -8rem;
    animation-delay: -4s;
}

.blob-3 {
    width: 20rem;
    height: 20rem;
    background: radial-gradient(circle, #ff6b6b, transparent);
    top: 50%;
    right: 20%;
    animation-delay: -8s;
    opacity: 0.15;
}

[data-theme="dark"] .blob { opacity: 0.2; }

@keyframes blobFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(2rem, -2rem) scale(1.05); }
    66% { transform: translate(-1rem, 1.5rem) scale(0.95); }
}

/* ===========================
   Navbar
   =========================== */
#nav-bar {
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    width: 38rem;
    margin: 1rem auto;
    padding: 0.5rem 1.5rem;
    position: relative;
    border-radius: 1rem;
    box-shadow: 0 8px 32px var(--card-shadow);
    border: 1px solid var(--glass-border);
    z-index: 100;
}

.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 3.5rem;
}

.nav-tabs {
    display: flex;
    gap: 0.5rem;
}

#nav-bar .icon {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 0.6rem;
    transition: all 0.25s ease;
    font-size: 0.9rem;
    color: var(--text-muted);
    user-select: none;
}

#nav-bar .icon:hover {
    background: var(--badge-bg);
    color: var(--text);
}

#nav-bar div.icon.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 16px rgba(79, 110, 247, 0.35);
}

[data-theme="dark"] #nav-bar div.icon.active {
    box-shadow: 0 4px 16px rgba(107, 138, 255, 0.3);
}

.tab-icon {
    font-size: 1rem;
}

/* ===========================
   Theme Toggle
   =========================== */
.theme-toggle {
    width: 56px;
    height: 30px;
    border-radius: 30px;
    background: #e5e7eb;
    border: none;
    cursor: pointer;
    padding: 0;
    position: relative;
    transition: background 0.3s ease;
    flex-shrink: 0;
}

.theme-toggle .thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: transform 0.35s ease;
    z-index: 4;
}

.theme-toggle .icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 5;
}

.theme-toggle .sun { left: 5px; opacity: 1; }
.theme-toggle .moon { right: 4px; }

body[data-theme="dark"] .theme-toggle { background: #1f2937; }
body[data-theme="dark"] .theme-toggle .thumb { transform: translateX(26px); }
body[data-theme="dark"] .theme-toggle .sun { opacity: 0; }
body[data-theme="dark"] .theme-toggle .moon { opacity: 1; }

/* ===========================
   Container & Card
   =========================== */
.container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 0.5rem 1.5rem 2rem;
    position: relative;
    z-index: 1;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    width: 38rem;
    padding: 2.5rem;
    border-radius: 1.25rem;
    box-shadow: 0 20px 60px var(--card-shadow);
    border: 1px solid var(--glass-border);
    text-align: center;
    animation: cardReveal 0.6s ease both;
}

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

/* ===========================
   Hero Section
   =========================== */
.hero-section {
    margin-bottom: 2rem;
}

.logo {
    width: 70%;
    max-width: 270px;
    margin-bottom: 1rem;
    border-radius: 7px;
}

h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0.6rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 1.25rem;
}

.trust-badges {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.badge {
    background: var(--badge-bg);
    border: 1px solid var(--border);
    color: var(--primary);
    padding: 0.3rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.78rem;
    font-weight: 500;
    transition: transform 0.2s;
}

.badge:hover { transform: translateY(-2px); }

/* ===========================
   Options
   =========================== */
.options {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    align-items: flex-end;
    margin: 1.5rem 0;
    flex-wrap: wrap;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 10rem;
}

.option-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.opt-icon { font-size: 1rem; }

.custom-select {
    background: var(--glass);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    padding: 0.5rem 0.75rem;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
}

.custom-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.15);
}

.hint {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--badge-bg);
    border-radius: 0.6rem;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--border);
    text-align: right;
    margin-top: 0.5rem;
}

/* ===========================
   Drop Zone
   =========================== */
#drop-zone {
    border: 2px dashed var(--border);
    border-radius: 1rem;
    padding: 2.5rem 1.5rem;
    transition: all 0.3s ease;
    background: var(--glass);
    cursor: default;
    margin-top: 0.5rem;
}

#drop-zone.dragover {
    background: rgba(79, 110, 247, 0.06);
    border-color: var(--primary);
    transform: scale(1.01);
    box-shadow: 0 0 0 6px rgba(79, 110, 247, 0.08);
}

.dz-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
}

.dz-illustration {
    margin-bottom: 0.5rem;
}

.dz-icon-wrap {
    position: relative;
    width: 5rem;
    height: 5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dz-main-icon {
    font-size: 2.5rem;
    position: relative;
    z-index: 2;
    animation: iconPulse 3s ease-in-out infinite;
}

@keyframes iconPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

.dz-ring {
    position: absolute;
    border-radius: 50%;
    border: 1.5px solid var(--primary);
    animation: ringExpand 3s ease-out infinite;
    opacity: 0;
}

.dz-ring-1 {
    width: 4rem; height: 4rem;
    animation-delay: 0.5s;
}

.dz-ring-2 {
    width: 5rem; height: 5rem;
    animation-delay: 1.2s;
}

@keyframes ringExpand {
    0% { transform: scale(0.6); opacity: 0.6; }
    100% { transform: scale(1.2); opacity: 0; }
}

.dz-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.dz-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
}

.browse-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    padding: 0.7rem 2rem;
    border-radius: 2rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: 'Vazirmatn', sans-serif;
    transition: all 0.25s ease;
    box-shadow: 0 6px 20px rgba(79, 110, 247, 0.3);
    margin: 0.4rem 0;
}

.browse-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(79, 110, 247, 0.4);
}

.dz-formats {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
    letter-spacing: 0.03em;
}

/* ===========================
   Progress
   =========================== */
/* .progress-wrapper is gone along with the markup it styled: index.php carried a
   single global progress bar that app.js bound and never updated, because each
   upload renders its own bar inside its own result card. */

.progress-bar {
    width: 100%;
    background: rgba(0,0,0,0.06);
    border-radius: 2rem;
    overflow: hidden;
    height: 0.6rem;
}

[data-theme="dark"] .progress-bar {
    background: rgba(255,255,255,0.06);
}

.progress {
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    transition: width 0.3s ease;
    border-radius: 2rem;
}

.progress-text {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===========================
   Result Cards
   =========================== */
.result-card {
    margin-top: 1.25rem;
    padding: 1.25rem;
    border-radius: 1rem;
    background: var(--compare-bg);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0,0,0,0.06);
    position: relative;
    text-align: right;
    animation: cardReveal 0.4s ease both;
}

.result-card img {
    width: 48%;
    border-radius: 0.6rem;
    display: block;
}

/* The filename heading. Padded away from .removeThis, which is absolutely
   positioned at top/left — and `left` is the *end* side in an RTL document, so
   padding-inline-end is what keeps a long name from running under the ❌.

   A filename is arbitrary user input up to 255 characters with no spaces to wrap
   on, so it is clipped rather than wrapped; app.js sets the full name as the
   element's title attribute so the clipped part stays reachable on hover. */
.file-name {
    display: block;
    padding-inline-end: 1.75rem;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* Filenames are arbitrary: "IMG_2024 (1).jpg" and "عکس پروفایل.png" both have
       to read correctly inside an RTL block. plaintext resolves the direction from
       each name's own first strong character — a hard `direction: ltr` would fix it
       for Latin names and break Persian ones. */
    unicode-bidi: plaintext;
}

.images {
    display: flex;
    gap: 4%;
    margin-top: 0.75rem;
}

.removeThis {
    position: absolute;
    top: 1rem;
    left: 1rem;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.7;
    transition: opacity 0.2s, transform 0.2s;
}

.removeThis:hover {
    opacity: 1;
    transform: scale(1.2);
}

.compare {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
}

.compare div { flex: 1; }

.compare img {
    width: 100%;
    border-radius: 0.6rem;
    margin-bottom: 0.3rem;
}

.percent {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
    font-size: 1rem;
    margin-top: 0.5rem;
}

/* The gradient above paints through the glyphs and hides `color` behind
   -webkit-text-fill-color: transparent, so both variants have to undo all three
   properties — setting `color` alone leaves invisible text. */
.percent.grew,
.percent.unchanged {
    background: none;
    -webkit-background-clip: border-box;
    background-clip: border-box;
    -webkit-text-fill-color: currentColor;
}

/* A format conversion that produced a larger file. Not an error — the operation
   succeeded and this is the honest result — so it borrows --danger for contrast
   without the .error card treatment. */
.percent.grew {
    color: var(--danger);
}

/* Already optimal: the byte fallback kept the original. */
.percent.unchanged {
    color: var(--text-muted);
    font-weight: 600;
}

/* Before/after byte counts. upload.php has always sent these and nothing rendered
   them, so a percentage was the only feedback — with no absolute figure to anchor
   it, "کاهش ۴٪" on a 12MB file and on a 40KB one looked identical. */
.sizes {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.size-item {
    white-space: nowrap;
}

.size-label {
    opacity: 0.75;
}

.download-btn {
    display: inline-block;
    margin-top: 1rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    padding: 0.65rem 1.75rem;
    border-radius: 2rem;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.25s ease;
    box-shadow: 0 4px 16px rgba(79, 110, 247, 0.28);
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(79, 110, 247, 0.38);
}

/* Failed upload: the card keeps its place in the list but drops the
   success scaffolding (progress bar, previews, download button). */
.result-card.error {
    background: var(--danger-bg);
    border-color: var(--danger);
    box-shadow: none;
}

.error-msg {
    margin: 0.35rem 0 0;
    padding-inline-end: 1.75rem;
    color: var(--danger);
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.75;
}

.error-msg::before {
    content: "⚠️";
    margin-inline-end: 0.4rem;
}

/* ===========================
   SEO Section
   =========================== */
.seo-section {
    position: relative;
    z-index: 1;
    padding: 2rem 1.5rem 3rem;
}

.seo-container {
    max-width: 38rem;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Features Grid */
.features-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.feature-card {
    background: var(--feat-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1.25rem;
    text-align: right;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px var(--card-shadow);
}

.feat-icon {
    font-size: 1.8rem;
    margin-bottom: 0.6rem;
}

.feature-card h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
    color: var(--text);
}

.feature-card p {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.65;
}

/* SEO Article */
.seo-article {
    background: var(--feat-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1.75rem;
}

.seo-article h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.seo-article p {
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.75;
    margin-bottom: 1.25rem;
}

.format-table h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.format-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.format-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--fmt-bg);
    border-radius: 0.6rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.fmt-badge {
    padding: 0.2rem 0.5rem;
    border-radius: 0.35rem;
    font-weight: 700;
    font-size: 0.75rem;
    color: #fff;
    flex-shrink: 0;
}

.fmt-jpg  { background: #f59e0b; }
.fmt-png  { background: #3b82f6; }
.fmt-webp { background: #10b981; }
.fmt-gif  { background: #8b5cf6; }

/* FAQ */
.faq-section {
    background: var(--feat-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1.75rem;
}

.faq-section h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text);
}

.faq-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.faq-item {
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow: hidden;
}

.faq-item summary {
    padding: 0.85rem 1rem;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: background 0.2s;
}

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

.faq-item summary::after {
    content: "＋";
    font-size: 0.9rem;
    color: var(--primary);
    transition: transform 0.2s;
}

.faq-item[open] summary::after { transform: rotate(45deg); }

.faq-item summary:hover { background: var(--badge-bg); }

.faq-item p {
    padding: 0.75rem 1rem 1rem;
    font-size: 0.84rem;
    color: var(--text-muted);
    line-height: 1.7;
    border-top: 1px solid var(--border);
}

/* ===========================
   Footer
   =========================== */
.site-footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    position: relative;
    z-index: 1;
    border-top: 1px solid var(--border);
}

/* ===========================
   Utils
   =========================== */
.hidden { display: none !important; }
