/* Modern CSS Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

html {
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
}

:root {
    /* Premium Emerald Green Accents */
    --primary-hue: 155;
    --primary: hsl(var(--primary-hue), 70%, 45%);
    --primary-dark: hsl(var(--primary-hue), 70%, 35%);
    --primary-light: hsl(var(--primary-hue), 80%, 70%);

    --accent: #10b981;
    --accent-gradient: linear-gradient(135deg, #34d399 0%, #10b981 100%);
    --primary-gradient: linear-gradient(135deg, #059669 0%, #10b981 100%);
    --danger-gradient: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);

    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    /* Light Mode - Less Paper White */
    --bg-color: #f1f5f9;
    /* Slate 100 */
    --text-primary: #0f172a;
    /* Slate 900 */
    --text-secondary: #334155;
    /* Slate 700 */
    --text-tertiary: #64748b;
    /* Slate 500 */

    /* Glass Effect Variables (Light) */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(16, 185, 129, 0.15);
    --glass-highlight: rgba(255, 255, 255, 0.95);
    --glass-shadow: 0 8px 32px 0 rgba(15, 23, 42, 0.08);
    --backdrop-blur: 16px;

    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;

    /* Legacy/Modal Support Variables */
    --bg-secondary: rgba(15, 23, 42, 0.05);
    --border-light: rgba(15, 23, 42, 0.1);
    --surface: var(--glass-bg);
    --border: var(--glass-border);
    --border-hover: var(--primary);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 10px 10px -5px rgba(15, 23, 42, 0.04);
}

/* Dark Mode Overrides - Neutral Dark */
body.dark-mode {
    --bg-color: #0f172a;
    /* Traditional Dark Slate */
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --glass-bg: rgba(30, 41, 59, 0.7);
    /* Slate 800 */
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.03);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    --bg-secondary: rgba(255, 255, 255, 0.05);
    --border-light: rgba(255, 255, 255, 0.1);
    --surface: var(--glass-bg);
    --border: var(--glass-border);
}

body {
    font-family: 'Outfit', 'Inter', sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    z-index: 1;
}

/* Utility class to prevent scrolling when modals are open */
body.no-scroll {
    overflow: hidden;
}

/* Dynamic Background Mesh */
.bg-mesh {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.bg-mesh-item {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 20s infinite ease-in-out;
}

.item-1 {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, #10b981 0%, transparent 70%);
    opacity: 0.15;
    animation-delay: 0s;
}

.item-2 {
    bottom: -10%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, #3b82f6 0%, transparent 70%);
    opacity: 0.1;
    animation-delay: -5s;
}

.item-3 {
    top: 40%;
    left: 40%;
    width: 30vw;
    height: 30vw;
    background: radial-gradient(circle, #8b5cf6 0%, transparent 70%);
    opacity: 0.1;
    animation-delay: -10s;
}

body.dark-mode .bg-mesh-item {
    opacity: 0.3;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(30px, -30px);
    }
}

/* App Wrapper */
.app-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    backdrop-filter: blur(0px);
    /* Fix for some browsers */
    -webkit-backdrop-filter: blur(0px);
}

/* Header */
.main-header {
    background: transparent;
    padding: 2rem 0;
    border-bottom: 1px solid transparent;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

@media (max-width: 480px) {
    .header-content {
        padding: 0 1rem;
    }
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon-wrapper {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: transparent;
    transition: transform 0.3s ease;
}

.logo-icon-wrapper:hover {
    transform: scale(1.05);
}

.logo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.main-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #0f172a, #334155);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.2rem;
}

/* Dark mode handling for text gradient */
body.dark-mode .main-header h1 {
    background: linear-gradient(to right, #f8fafc, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tagline {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

@media (max-width: 480px) {
    .tagline {
        font-size: 0.8rem;
    }
}

/* Applied Glass Styles - Replaces 'composes: glass-panel' */
.glass-panel,
.upload-area,
.controls-panel,
.result-card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--backdrop-blur));
    -webkit-backdrop-filter: blur(var(--backdrop-blur));
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: var(--radius-lg);
}

/* Main Content */
.main-content {
    flex: 1;
    width: 100%;
    max-width: 1024px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

/* Hero Section */
.hero {
    text-align: center;
    margin-bottom: 1rem;
}

.hero-title {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    line-height: 1.1;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

body.dark-mode .hero-title {
    background: linear-gradient(135deg, #f8fafc 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

@media (max-width: 480px) {
    .hero-title {
        font-size: 2.25rem;
    }
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 2rem;
}

.hero-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.btn-hero {
    font-size: 1.2rem;
    padding: 1rem 3rem;
    box-shadow: 0 10px 30px rgba(16, 185, 129, 0.4);
}

.btn-hero:hover {
    box-shadow: 0 15px 40px rgba(16, 185, 129, 0.5);
    transform: translateY(-3px);
}

.hero-secondary-text {
    font-size: 0.9rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

/* Upload Area */
.upload-container {
    width: 100%;
}

.upload-area {
    padding: 4rem 2rem;
    text-align: center;
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    border: 2px dashed var(--glass-border);
}

@media (max-width: 480px) {
    .upload-area {
        padding: 2.5rem 1.5rem;
    }
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary);
    background: rgba(16, 185, 129, 0.05);
    transform: translateY(-4px);
}

body.dark-mode .upload-area:hover {
    background: rgba(16, 185, 129, 0.1);
}

.upload-icon-wrapper {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    background: var(--glass-highlight);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.upload-title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.upload-subtitle {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.upload-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 4px;
}

/* Controls Panel */
.controls-panel {
    padding: 2.5rem;
}

.panel-header {
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 1.5rem;
    margin-bottom: 2rem;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2.5rem;
    margin-bottom: 2.5rem;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-value {
    font-weight: 600;
    color: var(--primary);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.25rem;
}

.original-size-hint {
    font-size: 0.85em;
    font-weight: 500;
    color: var(--primary);
    margin-left: 8px;
    opacity: 1;
}

body.dark-mode .original-size-hint {
    color: var(--primary-light);
    opacity: 1;
}

/* Sliders */
.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--glass-border);
    border-radius: 4px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-gradient);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(79, 172, 254, 0.5);
    border: 2px solid white;
}

.slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-gradient);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(79, 172, 254, 0.5);
    border: 2px solid white;
}

/* Select Input */
.select-input,
.number-input {
    width: 100%;
    padding: 1rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
}

.select-input option {
    background: #1e293b;
    color: #fff;
}

body.light-mode .select-input option {
    background: #fff;
    color: #000;
}

.select-input:focus,
.number-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Input hints */
.input-hint {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    margin-top: 0.5rem;
}

.input-hint-warning {
    color: var(--warning);
    font-weight: 500;
}

/* Checkbox styles */
.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.checkbox-input {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
}

.checkbox-label {
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    border-radius: 99px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    text-decoration: none;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(118, 75, 162, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(118, 75, 162, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(16, 185, 129, 0.05);
}

body.light-mode .btn-secondary {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #e2e8f0;
}

/* Optimize Button Special */
.btn-optimize {
    width: auto;
    min-width: 240px;
    display: flex;
    margin: 2rem auto 0;
    font-size: 1.1rem;
    padding: 1rem 2.5rem;
    background: linear-gradient(135deg, #059669 0%, #10b981 50%, #34d399 100%);
    background-size: 200% auto;
    transition: 0.5s;
}

.btn-optimize:hover {
    background-position: right center;
    box-shadow: 0 10px 30px rgba(120, 75, 160, 0.5);
}

/* Results */
.results-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
}

.result-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    position: relative;
    gap: 0.5rem;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--primary-gradient);
    color: white !important;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    margin-top: 1rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.3);
    filter: brightness(1.1);
}

.download-btn svg {
    flex-shrink: 0;
}

body.dark-mode .download-btn {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.result-card h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Extra safety for long filenames */
    overflow-wrap: break-word;
}

.image-preview {
    width: 100%;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    background: rgba(0, 0, 0, 0.2);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
}

.stats {
    background: rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 1rem;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    text-align: center;
}

body.light-mode .stats {
    background: rgba(255, 255, 255, 0.4);
}

.stat-item {
    display: flex;
    flex-direction: column;
    position: relative;
}

.stat-item:not(:last-child)::after {
    content: '';
    position: absolute;
    right: -0.25rem;
    top: 20%;
    bottom: 20%;
    width: 1px;
    background: var(--glass-border);
    opacity: 0.8;
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: 0.25rem;
}

.stat-value {
    font-weight: 700;
    color: var(--text-primary);
}

.compression-badge {
    text-align: center;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    font-weight: 700;
    margin-bottom: 1rem;
    background: rgba(16, 185, 129, 0.1);
    color: var(--primary);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.initial-stats {
    background: rgba(0, 0, 0, 0.05);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px dashed var(--glass-border);
}

body.light-mode .initial-stats {
    background: rgba(255, 255, 255, 0.4);
}

.initial-stat-item {
    display: flex;
    flex-direction: column;
}

.initial-status-badge {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    background: rgba(16, 185, 129, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.result-card.is-processing {
    opacity: 0.7;
    pointer-events: none;
}

.result-card.is-processing::after {
    content: "Processing...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--primary-gradient);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 99px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: pulse-mini 1.5s infinite ease-in-out;
    z-index: 10;
}

@keyframes pulse-mini {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.05);
        opacity: 0.8;
    }
}

.result-card.has-failed {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.05);
}

.failed-badge {
    background: var(--error);
    color: white;
    text-align: center;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    font-weight: 700;
    margin-top: 1rem;
}

.card-remove-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 32px;
    height: 32px;
    background: var(--error);
    border-radius: 50%;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(255, 65, 108, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.card-remove-btn:hover {
    transform: scale(1.1);
}

/* Batch Tools */
.batch-tools {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--backdrop-blur));
    -webkit-backdrop-filter: blur(var(--backdrop-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-top: 2rem;
}

.batch-tools-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.batch-count {
    font-weight: 700;
    font-size: 1.1rem;
}

.batch-savings {
    color: var(--primary);
    font-weight: 600;
}

.batch-tool-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.batch-grid-wrapper {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--glass-border);
}

.batch-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.75rem;
}

.batch-thumb {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-secondary);
}

.batch-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Footer */
.main-footer {
    text-align: center;
    padding: 3rem 0;
    color: var(--text-tertiary);
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    .hero-title {
        font-size: 2.25rem;
    }

    .main-content {
        padding: 1rem;
        gap: 2rem;
    }

    .controls-panel {
        padding: 1.5rem;
    }

    .results-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {

    /* Header mobile optimization - icon-only theme toggle */
    .header-content {
        flex-wrap: nowrap;
        gap: 0.5rem;
    }

    #themeToggle .btn-text {
        display: none;
    }

    #themeToggle {
        padding: 0.75rem;
        min-width: 44px;
        min-height: 44px;
    }

    #themeToggle::before {
        content: '🌙';
        font-size: 1.2rem;
    }

    body.dark-mode #themeToggle::before {
        content: '☀️';
    }

    .logo-icon-wrapper {
        width: 36px;
        height: 36px;
    }

    .main-header h1 {
        font-size: 1.1rem;
    }

    .tagline {
        font-size: 0.7rem;
        display: none;
    }

    /* Hero mobile optimization */
    .hero-title {
        font-size: 1.5rem;
        line-height: 1.2;
        padding: 0 0.5rem;
    }

    .hero-subtitle {
        font-size: 1rem;
        padding: 0 0.5rem;
    }

    .upload-area {
        padding: 2.5rem 1rem;
    }

    .upload-title {
        font-size: 1.35rem;
    }

    .upload-icon-wrapper {
        width: 60px;
        height: 60px;
        margin-bottom: 1rem;
    }

    .controls-panel {
        padding: 1rem;
    }

    .controls-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    /* Touch-friendly slider thumbs */
    .slider::-webkit-slider-thumb {
        width: 32px;
        height: 32px;
    }

    .slider::-moz-range-thumb {
        width: 32px;
        height: 32px;
    }

    .btn-optimize {
        width: 100%;
        min-width: unset;
        font-size: 1rem;
        padding: 1rem;
    }

    .stats {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 0.75rem;
    }

    .stat-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.25rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    .stat-item::after {
        content: none;
    }

    body.light-mode .stat-item {
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }

    .stat-item:last-child {
        border-bottom: none;
    }

    .stat-label {
        margin-bottom: 0;
    }

    /* Larger touch targets for comparison */
    .comparison-handle {
        width: 48px;
        height: 48px;
        margin-left: -24px;
        margin-top: -24px;
    }

    .comparison-handle-icon {
        width: 4px;
        height: 20px;
    }

    .comparison-actions {
        display: flex;
        gap: 0.5rem;
    }

    .zoom-toggle-btn {
        padding: 0.5rem;
        font-size: 0;
        /* Hide text, show icon only on narrow screens */
    }

    .zoom-toggle-btn svg {
        margin: 0;
    }

    /* Batch tools mobile */
    .batch-tools-header {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }

    .batch-tool-actions {
        width: 100%;
        justify-content: center;
    }

    .batch-tool-actions .btn {
        flex: 1;
        padding: 0.75rem 1rem;
        font-size: 0.85rem;
    }
}

/* Comparison Module Styles - Appended */
.comparison-module {
    position: relative;
    width: 100%;
    margin-bottom: 1rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.comparison-stage {
    position: relative;
    width: 100%;
    height: auto;
    /* Removed fixed 16:9 aspect ratio padding */
    overflow: hidden;
    cursor: ew-resize;
    touch-action: none;
    /* Critical for mobile slider dragging */
    background: transparent;
    line-height: 0;
    /* Remove gap below image */
}

/* Base image (defines height) */
.comparison-image--before {
    position: relative;
    width: 100%;
    height: auto;
    display: block;
    pointer-events: none;
}

/* Overlay layer (clipped by JS) */
.comparison-after-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    /* overflow: hidden; Not strictly needed with clip-path but good for safety */
}

/* Overlay image (matches base size) */
.comparison-image--after {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Ensures it fills the layer exactly */
    display: block;
    pointer-events: none;
}

.comparison-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin-left: -16px;
    margin-top: -16px;
    border-radius: 50%;
    background: var(--accent-gradient);
    border: 2px solid white;
    z-index: 10;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    touch-action: pan-y;
}

.comparison-handle-icon {
    width: 2px;
    height: 12px;
    background: white;
    border-radius: 2px;
}

.comparison-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.comparison-pill {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-secondary);
}

.comparison-pill svg {
    width: 14px;
    height: 14px;
}

/* Card Format Selection */
.card-format-select {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 0.85rem;
    outline: none;
    width: auto;
    min-width: 130px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.card-format-select:hover {
    border-color: var(--primary);
    background: var(--glass-highlight);
}

.card-format-select option {
    background: var(--bg-color);
    color: var(--text-primary);
}

/* ========================================
   SKELETON LOADING STATES
   ======================================== */

@keyframes skeleton-shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

.skeleton-card {
    position: relative;
    overflow: hidden;
}

.skeleton-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(255, 255, 255, 0.1) 50%,
            transparent 100%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite ease-in-out;
    z-index: 5;
    pointer-events: none;
}

body.light-mode .skeleton-card::before {
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(0, 0, 0, 0.05) 50%,
            transparent 100%);
    background-size: 200% 100%;
}

.skeleton-image {
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}

.skeleton-text {
    height: 1rem;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.skeleton-text.skeleton-title {
    width: 60%;
    height: 1.25rem;
}

.skeleton-text.skeleton-stat {
    width: 40%;
}

/* ========================================
   CODEC ERROR & UNSUPPORTED FORMAT
   ======================================== */

.codec-error-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--warning);
    background: rgba(245, 158, 11, 0.1);
    padding: 2px 8px;
    border-radius: 99px;
    margin-left: 0.5rem;
}

.select-input option:disabled {
    color: var(--text-tertiary);
    font-style: italic;
}

/* ========================================
   ACCESSIBILITY: REDUCED MOTION
   ======================================== */

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================================
   ACCESSIBILITY: FOCUS INDICATORS
   ======================================== */

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn:focus-visible,
.select-input:focus-visible,
.slider:focus-visible,
.number-input:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

/* Skip Link for Keyboard Navigation */
.skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    z-index: 9999;
    text-decoration: none;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 1rem;
}