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

:root {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --primary-light: #EEF2FF;
    --primary-surface: #F8F7FF;
    --success: #22C55E;
    --success-hover: #16A34A;
    --success-light: #F0FDF4;
    --warning: #F59E0B;
    --warning-light: #FFFBEB;
    --error: #EF4444;
    --error-light: #FEF2F2;
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-tertiary: #94A3B8;
    --bg-primary: #F1F5F9;
    --bg-card: #FFFFFF;
    --bg-input: #F8FAFC;
    --border-color: #E2E8F0;
    --border-hover: #C7D2FE;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.10);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: 1.5rem;
}

.app {
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 3rem);
    display: flex;
    flex-direction: column;
}

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0 1.5rem 0;
    flex-shrink: 0;
}

.app-header .logo {
    width: 40px;
    height: 40px;
    color: var(--primary);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.app-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 400;
}

/* ===== MAIN LAYOUT ===== */
.main-layout {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

/* ===== LEFT: CONTENT SECTION ===== */
.content-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

/* ===== DROP ZONE ===== */
.drop-zone {
    background: var(--bg-card);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.drop-zone:hover {
    border-color: var(--primary);
    background: var(--primary-surface);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: scale(1.01);
    box-shadow: var(--shadow-md);
}

.drop-zone-content {
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.drop-icon {
    width: 40px;
    height: 40px;
    color: var(--primary);
}

.drop-zone h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

.browse-link {
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    pointer-events: all;
    transition: var(--transition);
}

.browse-link:hover {
    color: var(--primary-hover);
}

/* ===== ORIGINAL INFO ===== */
.original-info {
    display: flex;
    gap: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1rem;
    border: 1px solid var(--border-color);
    align-items: center;
    flex-wrap: wrap;
}

.original-info .original-thumb {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-input);
}

.original-info .original-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.original-info .original-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.1rem 0.75rem;
    flex: 1;
}

.original-info .original-meta strong {
    color: var(--text-primary);
}

/* ===== LOADING ===== */
.loading-indicator {
    text-align: center;
    padding: 1.5rem;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.loading-indicator .spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
}

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

/* ===== RESULTS – MODERN GRID ===== */
.results-container {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.results-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* ---- Comparison Grid ---- */
.comparison-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Header row */
.comparison-grid .header-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.comparison-grid .header-row .format-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.comparison-grid .header-row .format-card-header {
    background: transparent;
    padding: 0 0.6rem;
    text-align: center;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.comparison-grid .header-row .format-card-header:first-child {
    /* quality label placeholder – hidden */
    display: none;
}

/* Each quality row */
.quality-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--bg-input);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.quality-row:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
}

.quality-row .row-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 0 0.25rem;
}

.quality-row .row-header .quality-label {
    color: var(--text-primary);
    font-size: 0.9rem;
}

.quality-row .row-header .winner-badge {
    background: var(--success);
    color: white;
    padding: 0.1rem 0.6rem;
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

/* Format cards inside row */
.format-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.format-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 0.6rem;
    border: 2px solid transparent;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.format-card.winner {
    border-color: var(--success);
    background: var(--success-light);
}

.format-card .preview-wrapper {
    width: 100%;
    max-width: 120px;
    margin: 0 auto 0.4rem auto;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
}

.format-card .preview-wrapper:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.format-card .preview-wrapper img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
    max-height: 100px;
}

.format-card .format-label {
    font-weight: 600;
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.format-card .file-size {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.format-card .ratio {
    font-size: 0.65rem;
    color: var(--text-tertiary);
}

.format-card .load-time {
    font-size: 0.65rem;
    color: var(--text-tertiary);
}

.format-card .btn-download-single {
    margin-top: 0.3rem;
    padding: 0.1rem 0.5rem;
    font-size: 0.6rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.format-card .btn-download-single:hover {
    background: var(--primary-hover);
}

.format-card .crown {
    font-size: 1.1rem;
    margin-left: 0.15rem;
}

.format-card .not-supported {
    color: var(--text-tertiary);
    font-size: 0.7rem;
    padding: 0.5rem 0;
}

.results-footer {
    margin-top: 1.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    letter-spacing: 0.01em;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn svg {
    flex-shrink: 0;
    height: 1.2rem;
    width: auto;
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.30);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-small {
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
}

/* ===== RIGHT: CONTROLS ===== */
.controls-section {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.control-group label {
    font-weight: 500;
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.quality-tag {
    background: var(--bg-input);
    padding: 0.1rem 0.6rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.format-tag {
    padding: 0.1rem 0.6rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
}

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    max-width: 700px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-image {
    max-width: 90vw;
    max-height: 90vh;
}

.modal-image .modal-body {
    padding: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.modal-image .modal-body img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    display: block;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: var(--transition);
    line-height: 1;
    padding: 0 0.25rem;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.modal-body table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.modal-body table td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    overflow-wrap: anywhere;
}

.modal-body table td:first-child {
    font-weight: 600;
    color: var(--text-secondary);
    width: 40%;
}

/* ===== FOOTER ===== */
.app-footer {
    text-align: center;
    padding: 1.5rem 0 0.5rem 0;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1.5rem;
    flex-shrink: 0;
}

.app-footer .row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.app-footer svg {
    height: 1.5rem;
    width: auto;
    flex-shrink: 0;
}

.app-footer a {
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: var(--transition);
}

.app-footer a:hover {
    color: var(--primary);
}

/* ===== UTILITIES ===== */
.is-hidden {
    display: none !important;
}

/* ===== SCROLLBAR ===== */
.comparison-grid::-webkit-scrollbar {
    width: 4px;
}
.comparison-grid::-webkit-scrollbar-track {
    background: transparent;
}
.comparison-grid::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}
.comparison-grid::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .controls-section {
        width: 260px;
    }
}

@media (max-width: 820px) {
    .app {
        min-height: auto;
    }

    .main-layout {
        flex-direction: column;
        gap: 1rem;
    }

    .controls-section {
        width: 100%;
    }

    body {
        padding: 1rem;
    }

    .app-footer {
        margin-top: 1rem;
    }

    .original-info {
        flex-direction: column;
        align-items: flex-start;
    }

    .original-info .original-thumb {
        width: 100%;
        height: auto;
        max-width: 120px;
    }

    .format-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .format-card .preview-wrapper {
        max-width: 100%;
    }

    .comparison-grid .header-row .format-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.25rem;
    }
    .app-header .subtitle {
        font-size: 0.75rem;
    }
    .controls-card {
        padding: 1rem;
    }
    .format-cards {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    .quality-row {
        padding: 0.5rem;
    }
    .format-card {
        padding: 0.4rem;
    }
    .format-card .preview-wrapper {
        max-width: 100%;
    }
    .modal-content {
        max-width: 95%;
        margin: 0.5rem;
    }
    .modal-image .modal-body img {
        max-height: 60vh;
    }
    .comparison-grid .header-row .format-cards {
        grid-template-columns: 1fr 1fr;
    }
}

/* ===== AVIF WARNING ===== */
.avif-warning {
    display: inline-block;
    margin-left: 0.3rem;
    color: var(--warning);
    font-size: 0.7rem;
    cursor: help;
    border-bottom: 1px dotted var(--warning);
}

.avif-notice {
    background: var(--warning-light);
    border: 1px solid var(--warning);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.7rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.avif-notice svg {
    flex-shrink: 0;
    width: 1.2rem;
    height: 1.2rem;
    color: var(--warning);
}
