:root {
    --bg: #0f172a;
    --card: #ffffff;
    --muted: #6b7280;
    --text: #0b1220;
    --primary: #6a11cb;
    --primary2: #2575fc;
    --ok: #16a34a;
    --warn: #f59e0b;
    --bad: #ef4444;
    --shadow: 0 14px 35px rgba(0,0,0,0.12);
    --radius: 20px;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
}

body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, "Helvetica Neue", sans-serif;
    background: radial-gradient(1200px 900px at 15% 10%, rgba(106,17,203,0.24), transparent 60%),
                  radial-gradient(1200px 900px at 85% 10%, rgba(37,117,252,0.22), transparent 60%),
                  #f6f8ff;
    min-height: 100vh;
	min-width: 100%;
	width: 100%;
    color: var(--text);
    padding: 0px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
}

.container {
    max-width: 1100px;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-top: -20px;
}

.main-content { 
    padding: 30px; 
}

/* Header */
.header {
    display: none;
    text-align: center;
    margin-bottom: 30px;
    padding: 30px;
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    color: white;
    border-radius: 0 0 25px 25px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 100%;
}

.header h1 {
    margin: 0;
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.header .tagline {
    margin: 10px 0 0;
    font-size: 1.2em;
    opacity: 0.9;
}

/* Animación typing + collapse */
@keyframes blinkCaret {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.type-cursor {
    border-right: 2px solid rgba(255,255,255,0.95);
    padding-right: 2px;
    animation: blinkCaret 0.7s steps(1) infinite;
}

.header.hero-anim {
    overflow: hidden;
    max-height: 500px;
    will-change: transform, max-height, padding, margin, opacity;
    transition: transform 0.65s ease, opacity 0.65s ease, max-height 0.65s ease, padding 0.65s ease, margin 0.65s ease;
}

.header.hero-collapsing {
    transform: translateY(-120%);
    opacity: 0;
    max-height: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
}

/* ============= CÁMARA CON LENTE CUADRADO ============= */
.camera-section {
    margin-bottom: 30px;
}

.camera-box {
    background: #111827;
    border-radius: 0px;
    padding: 0px 0px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border: 0px solid rgba(255, 255, 255, 0.15);
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.camera-box:hover {
    transform: translateY(-5px);
    box-shadow: 
        0 25px 50px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    border-color: rgba(106, 17, 203, 0.4);
}

.square-lens-container {
    position: relative;
    width: 100%;
    margin: 0 auto 25px;
    aspect-ratio: 1;
    max-height: 800px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.square-lens {
    width: 100%;
    height: 100vh;
    background: linear-gradient(135deg, #1a202c, #111827);
    position: relative;
    overflow: hidden;
    box-shadow: 
        inset 0 0 40px rgba(0, 0, 0, 0.8),
        0 15px 35px rgba(0, 0, 0, 0.6);
    border: 8px solid #2d3748;
    border-radius: 12px;
}

.lens-preview {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2d3748, #1a202c);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

.lens-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.lens-preview.active video {
    opacity: 1;
}

.lens-preview-message {
    position: absolute;
    color: rgba(255, 255, 255, 0.8);
    font-size: 16px;
    text-align: center;
    padding: 20px;
    z-index: 3;
    transition: opacity 0.3s ease;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    backdrop-filter: blur(5px);
    top: 20px;
}

.lens-preview.active .lens-preview-message {
    opacity: 0;
}

.lens-preview-message i {
    font-size: 48px;
    margin-bottom: 15px;
    display: block;
    color: rgba(255, 255, 255, 0.9);
}

.shutter-button {
    position: absolute;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    margin: 20px auto;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 
        0 10px 30px rgba(239, 68, 68, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        0 0 0 4px rgba(239, 68, 68, 0.2);
}

.shutter-inner {
    width: 60%;
    height: 60%;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 
        inset 0 2px 4px rgba(0, 0, 0, 0.2),
        0 1px 2px rgba(255, 255, 255, 0.5);
}

@media (min-width: 768px) {
    .shutter-button {
        right: 80px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 500 !important;
    }
    .shutter-button:hover {
        transform: translateX(-50%) scale(1.15);
        box-shadow: 
            0 15px 40px rgba(239, 68, 68, 0.6),
            inset 0 1px 0 rgba(255, 255, 255, 0.4),
            0 0 0 6px rgba(239, 68, 68, 0.3);
        right: 80px;
        top: 50%;
        transform: translateY(-50%);
    }
    .shutter-button:active {
        transform: translateX(-50%) scale(0.95);
        box-shadow: 
            0 5px 20px rgba(239, 68, 68, 0.3),
            inset 0 2px 4px rgba(0, 0, 0, 0.3),
            0 0 0 3px rgba(239, 68, 68, 0.2);
        right: 80px;
        top: 50%;
        transform: translateY(-50%);
    }
    .shutter-button.disabled {
        opacity: 0.5;
        cursor: not-allowed;
        right: 80px;
        top: 50%;
        transform: translateY(-50%);
    }
}

.camera-text {
    color: white;
    margin-bottom: 20px;
    position: absolute;
    bottom: 90px;
    color: white;
    height: 20%;
}

.camera-text h3 {
    font-size: 24px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #ffffff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.camera-text p {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

.upload-fallback {
    display: none;
    position: absolute;
    top: 120px;
    right: 80px;
    z-index: 10;
    width: 50px;
    height: 50px;
    border-radius: 0px;
    right: 80px;
    top: 20%;
    transform: translateY(-50%);
    z-index: 500 !important;
}

.camera-control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #007bff;
    color: white;
    border: none;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.camera-control-btn:hover {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.camera-control-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.4);
}

.camera-control-btn::after {
    content: 'Subir archivo';
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;
}

.camera-control-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

@keyframes cameraFlash {
    0% { 
        opacity: 0;
        transform: scale(0.8);
    }
    50% { 
        opacity: 1;
        transform: scale(1.2);
    }
    100% { 
        opacity: 0;
        transform: scale(1.5);
    }
}

.flash-effect {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
}

.flash-effect.active {
    animation: cameraFlash 0.5s ease-out;
}

/* ============= VISTA PREVIA DE LA FOTO CAPTURADA ============= */
.camera-preview {
    margin-top: 0px;
    display: none;
    background: #f8f9ff;
    border-radius: 0px;
    padding: 0px;
    border: 1px solid rgba(0,0,0,0.08);
    width: 100%;
    height: 95vh;
}

.preview-container {
    width: 100%;
    margin: 0;
    border-radius: 0px;
    overflow: hidden;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 1200px;
    min-height: 300px;
    max-height: 90vh;
}

#cameraCapture {
    width: 100%;
    height: 100%;
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.preview-info {
    text-align: center;
    margin-bottom: 15px;
    color: var(--muted);
    font-size: 13px;
}

.camera-preview-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
}

.capture-controls {
    position: absolute;
    bottom: 30px;
    display: flex;
    gap: 14px;
    flex: 1;
    min-width: 0;
    padding: 15px;
    align-items: center;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
    z-index: 20;
}

.capture-btn {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
    white-space: nowrap;
    transition: all 0.2s;
}

.capture-btn.primary {
    background: var(--primary);
    color: #fff;
}

.capture-btn.secondary {
    background: #f1f5f9;
    color: var(--text);
    border: 1px solid #cbd5e1;
}

.auto-compress-toggle {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* ============= TOGGLE SWITCH ============= */
.toggle-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    white-space: nowrap;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    width: 40px;
    height: 20px;
    background-color: #ccc;
    border-radius: 34px;
    position: relative;
    transition: .4s;
    flex-shrink: 0;
}

.toggle-slider:before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: .4s;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.toggle-label {
    font-weight: 600;
    color: var(--text);
}

/* ============= NIVELES DE COMPRESIÓN ============= */
.level-section {
    margin-top: 26px;
    margin-bottom: 18px;
}

.level-section h2 {
    margin-bottom: 14px;
    font-size: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.level-cards {
    display: flex;
    gap: 12px;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 5px;
}

.level-card {
    flex: 1 1 0;
    min-width: 150px;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 16px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.level-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 28px rgba(0,0,0,0.12);
    border-color: rgba(37,117,252,0.35);
}

.level-card.active {
    border: 0;
    background: linear-gradient(135deg, rgba(106,17,203,0.10), rgba(37,117,252,0.08));
    box-shadow: 0 16px 34px rgba(106,17,203,0.18);
    outline: 2px solid rgba(106,17,203,0.35);
}

.level-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    color: #fff;
    box-shadow: 0 10px 20px rgba(106,17,203,0.25);
    margin-bottom: 10px;
}

.level-name {
    font-size: 16px;
    font-weight: 900;
    margin-bottom: 4px;
}

.level-desc {
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.25;
}

.level-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 999px;
    font-weight: 900;
}

.lossless .level-badge {
    background: rgba(22,163,74,0.12);
    color: var(--ok);
}

.super .level-badge {
    background: rgba(245,158,11,0.12);
    color: var(--warn);
}

.ultra .level-badge {
    background: rgba(239,68,68,0.12);
    color: var(--bad);
}

/* ============= FORMATO DE SALIDA - HORIZONTAL ============= */
.format-section {
    margin: 26px 0 18px;
}

.format-section h2 {
    margin-bottom: 14px;
    font-size: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.format-buttons {
    display: flex;
    gap: 12px;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 5px;
}

.format-btn {
    flex: 1 1 0;
    min-width: 160px;
    padding: 12px 16px;
    border-radius: 12px;
    border: 2px solid #e9ecef;
    background: #f8f9fa;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    font-size: 14px;
    color: #555;
}

.format-btn:hover {
    background: #e9ecef;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.format-btn.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.2);
}

.format-btn.avif {
    border-color: #ff6b35;
}

.format-btn.avif.active {
    background: #ff6b35;
    border-color: #ff6b35;
}

.format-btn i {
    font-size: 16px;
}

.format-btn span {
    font-size: 13px;
}

.format-info {
    margin-top: 12px;
    font-size: 13px;
    color: var(--muted);
    text-align: center;
    padding: 8px 12px;
    background: #f0f8ff;
    border-radius: 8px;
    border-left: 3px solid #007bff;
}

/* ============= MARCA DE AGUA - NUEVA SECCIÓN ============= */
.watermark-section {
    margin: 20px 0 25px;
    background: #fff;
    border-radius: 12px;
    padding: 16px 20px;
    border: 1px solid rgba(0,0,0,0.08);
}

.watermark-toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
}

.watermark-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
}

.watermark-label i {
    color: var(--primary);
    font-size: 18px;
}

.watermark-switch .toggle-slider {
    width: 50px;
    height: 26px;
}

.watermark-switch .toggle-slider:before {
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
}

.watermark-switch input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

.watermark-note {
    margin-top: 12px;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid rgba(0,0,0,0.05);
}

.watermark-note i {
    color: var(--primary);
}

/* ============= BOTÓN DE COMPRESIÓN ============= */
.action-section {
    text-align: center;
    margin-top: 22px;
}

.action-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    color: #fff;
    border: none;
    padding: 16px 32px;
    border-radius: 14px;
    font-size: 18px;
    font-weight: 900;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
    margin-bottom: 18px;
}

.action-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(106, 17, 203, 0.4);
}

.action-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.file-upload {
    margin-top: 15px;
}

.file-upload-btn {
    background: #f1f5f9;
    color: var(--text);
    border: 1px solid #cbd5e1;
    padding: 12px 18px;
    border-radius: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 900;
}

#fileInput {
    display: none;
}

/* ============= RESULTADOS ============= */
.result-section {
    display: none;
    margin-top: 30px;
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.result-section h2 {
    margin-bottom: 20px;
    font-size: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.result-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 15px;
    margin-bottom: 20px;
}

.stat.original,
.stat.output {
    grid-row: 1;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.stat.original {
    grid-column: 1;
}

.stat.output {
    grid-column: 2;
}

.stat.savings {
    grid-row: 2;
    grid-column: 1 / span 2;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white !important;
    border: none;
    border-radius: 12px;
    padding: 25px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.2);
}

.stat .label {
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 8px;
    font-weight: 600;
}

.stat.savings .label {
    color: rgba(255, 255, 255, 0.9) !important;
}

.stat .value {
    font-size: 24px;
    font-weight: bold;
    color: var(--text);
}

.stat.savings .value {
    color: white !important;
    font-size: 28px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

@keyframes pulseSavings {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

.stat.savings {
    animation: pulseSavings 2s ease-in-out;
}

.result-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ============= TOAST ============= */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #111827;
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    box-shadow: 0 12px 26px rgba(0,0,0,0.35);
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    max-width: min(420px, calc(100vw - 40px));
}

.toast.visible {
    display: flex;
    animation: slideIn 0.3s ease;
}

.toast.ok {
    background: var(--ok);
}

.toast.error {
    background: var(--bad);
}

.toast.warn {
    background: var(--warn);
    color: #111827;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ============= FOOTER ============= */
footer {
    margin-top: 30px;
    color: #fff;
    text-align: center;
    opacity: 0.85;
    font-size: 14px;
    width: 100%;
    max-width: 1100px;
}

/* ============= RESPONSIVE ============= */
@media (max-width: 768px) {
    body {
        padding: 14px;
        padding: 0px;
    }
    
    .container {
        margin-top: -25px;
    }
    
    .main-content {
        padding: 20px;
    }
    
    .header h1 {
        font-size: 26px;
    }
    
    .header .tagline {
        font-size: 1em;
    }
    
    .square-lens-container {
        max-height: 400px;
        max-height: 100vh;
        max-height: 100vh;
    }
    
    .square-lens {
        border-width: 6px;
    }
    
    .square-lens-container {
        position: relative;
        width: 100%;
        margin: 0 auto 25px;
        aspect-ratio: 1;
        max-height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .square-lens {
        position: absolute;
        top: 0;
        width: 100%;
        height: 100vh;
        background: linear-gradient(135deg, #1a202c, #111827);
        position: relative;
        overflow: hidden;
        box-shadow: 
            inset 0 0 40px rgba(0, 0, 0, 0.8),
            0 15px 35px rgba(0, 0, 0, 0.6);
        border: 8px solid #2d3748;
        border-radius: 12px;
    }
    
    .lens-preview-message i {
        font-size: 36px;
    }
    
    .lens-preview-message {
        font-size: 14px;
        padding: 15px;
        top: 200px;
    }
    
    .shutter-button {
        width: 70px;
        height: 70px;
        bottom: 20px;
    }
    
    .camera-text h3 {
        font-size: 20px;
    }
    
    .level-cards {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    
    .level-card {
        min-width: 140px;
    }
    
    .format-buttons {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    
    .format-btn {
        min-width: 140px;
    }
    
    .result-stats {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }
    
    .stat.original {
        grid-row: 1;
        grid-column: 1;
    }
    
    .stat.output {
        grid-row: 2;
        grid-column: 1;
    }
    
    .stat.savings {
        grid-row: 3;
        grid-column: 1;
    }
    
    .capture-btn {
        width: 100%;
        min-width: 0;
    }
    
    .action-btn {
        width: 100%;
        justify-content: center;
    }
    
    .camera-control-btn {
        width: 100%;
        justify-content: center;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.camera-preview {
    animation: fadeIn 0.3s ease;
}

.result-section {
    animation: fadeIn 0.5s ease;
}

/* ============= VISTA PREVIA DE FOTO CAPTURADA - EN UNA FILA ============= */
.camera-preview {
    margin-top: 0px;
    display: none;
    background: #f8f9ff;
    border-radius: 0px;
    padding: 0px;
    border: 1px solid rgba(0,0,0,0.08);
    width: 100%;
    height: 95vh;
}

.preview-container {
    width: 100%;
    margin: 0 auto 12px;
    margin: 0;
    border-radius: 0px;
    overflow: hidden;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 1200px;
    min-height: 300px;
    max-height: 90vh;
}

#cameraCapture {
    width: 100%;
    height: 100%;
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.preview-info {
    text-align: center;
    margin-bottom: 15px;
    color: var(--muted);
    font-size: 13px;
}

/* CONTROLES EN UNA SOLA FILA - SIN WRAP */
.camera-preview-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
}

.capture-controls {
    position: absolute;
    bottom: 30px;
    display: flex;
    gap: 14px;
    flex: 1;
    min-width: 0;
    padding: 15px;
    align-items: center;
}

.capture-btn {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
    white-space: nowrap;
    transition: all 0.2s;
}

.capture-btn.primary {
    background: var(--primary);
    color: #fff;
}

.capture-btn.secondary {
    background: #f1f5f9;
    color: var(--text);
    border: 1px solid #cbd5e1;
}

.auto-compress-toggle {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.toggle-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    white-space: nowrap;
}

.toggle-slider {
    width: 40px;
    height: 20px;
    background-color: #ccc;
    border-radius: 34px;
    position: relative;
    transition: .4s;
    flex-shrink: 0;
}

.toggle-slider:before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: .4s;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.toggle-label {
    font-weight: 600;
    color: var(--text);
    display: none;
}

/* ============= NIVELES DE COMPRESIÓN - UNA FILA ============= */
.level-section {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
    margin-bottom: -10px;
}

.level-cards {
    display: flex;
    gap: 8px;
    padding: 2px;
    min-width: min-content;
    flex-wrap: nowrap;
    overflow-x: auto;
    white-space: nowrap;
}

.level-card {
    width: 80px;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    flex: 1 1 auto;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 12px;
    border: 2px solid #e9ecef;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.level-card.active {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(106,17,203,0.05), rgba(37,117,252,0.03));
    box-shadow: 0 4px 12px rgba(106,17,203,0.1);
}

.level-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    color: #fff;
    margin-bottom: 8px;
    font-size: 14px;
}

.level-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.level-desc {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.3;
    margin-bottom: 8px;
    height: 28px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.level-badge {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 700;
    background: rgba(0,0,0,0.05);
}

.lossless .level-badge {
    background: rgba(22,163,74,0.1);
    color: var(--ok);
}

.super .level-badge {
    background: rgba(245,158,11,0.1);
    color: var(--warn);
}

.ultra .level-badge {
    background: rgba(239,68,68,0.1);
    color: var(--bad);
}

/* ============= SELECTOR DE FORMATO - UNA FILA ============= */
.format-selector {
    margin: 15px 0;
}

.format-selector h3 {
    margin-bottom: 10px;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.format-buttons-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    margin-bottom: -8px;
}

.format-buttons {
    display: inline-flex;
    gap: 6px;
    padding: 2px;
    min-width: min-content;
    max-width: 100%;
}

.format-btn {
    flex: 1 1 auto;
    width: 100px;
    padding: 10px 8px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #fff;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    font-size: 13px;
}

.format-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.format-btn.avif.active {
    background: #0077ff;
    border-color: #0077ff;
}

.format-btn i {
    font-size: 14px;
}

.format-btn span {
    font-size: 12px;
}

.preview-info {
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

/* ============= RESULTADOS - UNA FILA ============= */
.result-section {
    flex: 1 1 auto;
    display: flex;
    margin-top: 20px;
    background: #fff;
    border-radius: 16px;
    padding: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.result-section h3 {
    margin-bottom: 15px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text);
}

.result-stats-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.result-stats {
    display: flex;
    gap: 8px;
    padding: 2px;
    min-width: min-content;
}

.stat {
    flex: 1 1 auto;
    width: 100px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 5px 8px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat.savings {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white !important;
    border: none;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.2);
}

.stat .label {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 6px;
    font-weight: 600;
    white-space: nowrap;
}

.stat.savings .label {
    color: rgba(255, 255, 255, 0.95) !important;
}

.stat .value {
    font-size: 18px;
    font-weight: bold;
    color: var(--text);
    line-height: 1.2;
    margin-bottom: 4px;
}

.stat.savings .value {
    color: white !important;
    font-size: 20px;
}

.stat .size-detail {
    font-size: 11px;
    color: #6b7280;
    opacity: 0.8;
    white-space: nowrap;
}

.stat.savings .size-detail {
    color: rgba(255, 255, 255, 0.9) !important;
}

.result-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

/* ============= MEDIA QUERIES ESPECÍFICAS ============= */
@media (min-width: 769px) {
    .level-cards-container,
    .format-buttons-container,
    .result-stats-container {
        overflow-x: visible;
        padding-bottom: 0;
        margin-bottom: 0;
    }
    
    .level-cards,
    .format-buttons,
    .result-stats {
        display: flex;
        justify-content: center;
        width: 100%;
    }
    
    .level-card {
        width: 180px;
    }
    
    .format-btn {
        width: 140px;
    }
    
    .stat {
        width: 160px;
    }
    
    .toggle-label {
        display: inline;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0px;
    }
    
    .main {
        padding: 0px;
    }
    
    .header {
        padding: 0px;
        max-width: 100%;
    }
    
    .header h1 {
        font-size: 22px;
    }
    
    .upload-fallback {
        bottom: 125px;
    }
    
    .shutter-button {
        right: unset;
        left: unset;
        top: unset;
        bottom: unset;
        display: flex;
        position: absolute !important;
        width: 80px;
        height: 80px;
        background: linear-gradient(135deg, #ef4444, #dc2626);
        border-radius: 50%;
        border: none;
        cursor: pointer;
        margin: 0;
        justify-content: center;
        align-items: center;
        transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        box-shadow: 
            0 10px 30px rgba(239, 68, 68, 0.4),
            inset 0 1px 0 rgba(255, 255, 255, 0.3),
            0 0 0 4px rgba(239, 68, 68, 0.2);
        bottom: 100px !important;
        left: 50%;
        transform: translateX(-50%);
        z-index: 400 !important;
    }
    
    .shutter-button:hover {
        position: absolute !important;
        transform: translateX(-50%) scale(1.15);
        box-shadow: 
            0 15px 40px rgba(239, 68, 68, 0.6),
            inset 0 1px 0 rgba(255, 255, 255, 0.4),
            0 0 0 6px rgba(239, 68, 68, 0.3);
        bottom: 100px !important;
        left: 50%;
        transform: translateX(-50%);
        z-index: 400 !important;
    }
    
    .shutter-button:active {
        position: absolute !important;
        transform: translateX(-50%) scale(0.95);
        box-shadow: 
            0 5px 20px rgba(239, 68, 68, 0.3),
            inset 0 2px 4px rgba(0, 0, 0, 0.3),
            0 0 0 3px rgba(239, 68, 68, 0.2);
        bottom: 100px !important;
        left: 50%;
        transform: translateX(-50%);
        z-index: 500 !important;
    }
    
    .shutter-button.disabled {
        opacity: 0.5;
        cursor: not-allowed;
        bottom: 100px !important;
        left: 50%;
        transform: translateX(-50%);
        z-index: 400 !important;
    }
    
    .shutter-inner {
        width: 50%;
        height: 50%;
    }
    
    .camera-text h3 {
        font-size: 18px;
    }
    
    .camera-text p {
        font-size: 13px;
    }
    
    .stat .value {
        font-size: 20px;
    }
    
    .stat.savings .value {
        font-size: 22px;
    }
    
    .camera-section {
        margin-bottom: 18px;
    }
    
    .camera-box {
        width: 100%;
        border: 0 !important;
        background: #0b1220;
        color: #ffffff;
        padding: 0px 0px;
        box-shadow: 0 14px 35px rgba(0,0,0,0.22);
        max-width: 100% !important;
        max-height: 100vh !important;
        height: 91vh;
        position: relative;
        display: flex;
        flex-direction: column;
    }
    
    .square-lens-container {
        max-height: 100%;
        height: 100%;
    }
    
    .camera-text {
        position: absolute;
        bottom: 100px;
        color: white;
        margin-bottom: 20px;
    }
    
    .camera-box:hover {
        background: #0f1b33;
    }
    
    .camera-box h3, 
    .camera-box p {
        color: #e5e7eb;
    }
    
    .camera-icon {
        color: #ffffff;
        opacity: 0.95;
    }
    
    .level-cards {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 10px;
    }
    
    .level-card {
        flex: 1 1 0;
        min-width: 0;
        padding: 14px 2px;
    }
    
    .level-icon {
        width: 38px;
        height: 38px;
        border-radius: 12px;
        margin-bottom: 10px;
    }
    
    .level-name {
        font-size: 14px;
        margin-bottom: 6px;
    }
    
    .level-desc {
        font-size: 11px;
        line-height: 1.2;
    }
    
    .level-badge {
        top: 10px;
        right: 10px;
        font-size: 11px;
        padding: 3px 8px;
    }
    
    .format-selector {
        gap: 2px;
        width: 100%;
        flex-wrap: nowrap;
        display: flex !important;
        flex-wrap: nowrap !important;
        flex-direction: row;
        padding: 2px;
        min-width: min-content;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .format-buttons {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 10px;
        background: #fff;
        border: 1px solid rgba(0,0,0,0.08);
        border-radius: 16px;
        cursor: pointer;
        transition: all 0.2s;
        position: relative;
        width: 80px;
        padding: 2px;
        flex: 1 1 auto;
        padding: 10px;
        background: #f8f9fa;
        border-radius: 12px;
        border: 2px solid #e9ecef;
        text-align: center;
        transition: all 0.3s ease;
        cursor: pointer;
        position: relative;
    }
    
    .format-btn {
        flex: 1 1 0;
        min-width: 0;
        padding: 10px 8px;
        font-size: 12px;
        line-height: 1.1;
    }
    
    .format-btn i {
        font-size: 14px;
    }
    
    .result-stats {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 10px;
    }
    
    .stat {
        flex: 1 1 0;
        min-width: 0;
        padding: 12px 10px;
    }
    
    .stat .value {
        font-size: 18px;
    }
    
    .toggle-label {
        display: inline;
    }

    /* Ajustes watermark en móvil */
    .watermark-toggle-container {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .level-card {
        width: 160px;
    }
    
    .format-btn {
        width: 130px;
    }
    
    .stat {
        width: 150px;
    }
    
    .toggle-label {
        display: inline;
    }
}

@media (max-width: 380px) {
    .level-card {
        width: 140px;
    }
    
    .format-btn {
        width: 110px;
    }
    
    .stat {
        width: 130px;
    }
}

@media (max-width: 340px) {
    .level-card {
        width: 130px;
        padding: 10px;
    }
    
    .format-btn {
        width: 100px;
        padding: 8px 6px;
        font-size: 12px;
    }
    
    .format-btn span {
        font-size: 11px;
    }
    
    .stat {
        width: 120px;
    }
    
    .capture-btn {
        padding: 8px 10px;
        font-size: 12px;
    }
}

.level-cards-container::-webkit-scrollbar,
.format-buttons-container::-webkit-scrollbar,
.result-stats-container::-webkit-scrollbar {
    height: 4px;
}

.level-cards-container::-webkit-scrollbar-track,
.format-buttons-container::-webkit-scrollbar-track,
.result-stats-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.level-cards-container::-webkit-scrollbar-thumb,
.format-buttons-container::-webkit-scrollbar-thumb,
.result-stats-container::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, "Helvetica Neue", sans-serif;
    background: radial-gradient(1200px 900px at 15% 10%, rgba(106,17,203,0.24), transparent 60%),
                  radial-gradient(1200px 900px at 85% 10%, rgba(37,117,252,0.22), transparent 60%),
                  #f6f8ff;
    color: var(--text);
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 8px 40px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 2px 10px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 900;
    letter-spacing: 0.2px;
}

.brand .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary2));
    box-shadow: 0 0 0 4px rgba(106,17,203,0.12);
}

.pill {
    font-size: 12px;
    padding: 7px 10px;
    border-radius: 999px;
    background: #ffffffcc;
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}

header.header {
    text-align: center;
    margin-bottom: 30px;
    padding: 30px;
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    color: white;
    border-radius: 0 0 25px 25px;
    box-shadow: var(--shadow);
}

header.header h1 {
    margin: 0;
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

header.header .tagline {
    margin: 10px 0 0;
    font-size: 1.2em;
    opacity: 0.9;
}

.level-cards::-webkit-scrollbar,
.format-buttons::-webkit-scrollbar {
    height: 4px;
}

.level-cards::-webkit-scrollbar-track,
.format-buttons::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.level-cards::-webkit-scrollbar-thumb,
.format-buttons::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

/* ============= AJUSTES PARA MÓVILES (max-width: 480px) ============= */
@media (max-width: 480px) {
    
    /* === FORMATO DE SALIDA - CENTRADO HORIZONTAL === */
    .format-section {
        margin: 20px 0 15px;
        padding: 0 10px;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .format-section h2 {
        font-size: 20px;
        margin-bottom: 12px;
        text-align: center;
        justify-content: center;
        width: 100%;
    }
    
    .format-buttons {
        display: flex;
        flex-wrap: nowrap;
        gap: 10px;
        padding: 5px 0;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        scroll-snap-type: x mandatory;
    }
    
    .format-btn {
        flex: 0 0 auto;
        min-width: 140px;
        width: auto;
        padding: 12px 16px;
        margin: 0;
        scroll-snap-align: start;
        border-radius: 30px;
        font-size: 14px;
        box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    }
    
    .format-btn:first-child {
        margin-left: 0;
    }
    
    .format-btn:last-child {
        margin-right: 0;
    }
    
    .format-info {
        width: 100%;
        margin-top: 15px;
        font-size: 12px;
        text-align: center;
        padding: 10px 15px;
        border-radius: 20px;
    }
    
    /* === MARCA DE AGUA - CENTRADA === */
    .watermark-section {
        margin: 20px 10px 25px;
        padding: 18px 20px;
        border-radius: 20px;
        width: calc(100% - 20px);
        align-self: center;
    }
    
    .watermark-toggle-container {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        gap: 15px;
    }
    
    .watermark-label {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 15px;
        font-weight: 700;
        white-space: nowrap;
    }
    
    .watermark-label i {
        font-size: 16px;
    }
    
    .watermark-switch {
        flex-shrink: 0;
    }
    
    .watermark-switch .toggle-slider {
        width: 52px;
        height: 28px;
    }
    
    .watermark-switch .toggle-slider:before {
        height: 22px;
        width: 22px;
        left: 3px;
        bottom: 3px;
    }
    
    .watermark-note {
        margin-top: 12px;
        font-size: 11px;
        text-align: center;
        justify-content: center;
        width: 100%;
        padding-top: 12px;
    }
    
    .watermark-note i {
        margin-right: 4px;
    }
}

/* ============= AJUSTES EXTRA PARA PANTALLAS MUY PEQUEÑAS ============= */
@media (max-width: 380px) {
    .format-btn {
        min-width: 130px;
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .watermark-toggle-container {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .watermark-label {
        white-space: normal;
        text-align: center;
    }
}

@media (max-width: 340px) {
    .format-btn {
        min-width: 120px;
        padding: 10px 12px;
        font-size: 12px;
    }
    
    .watermark-section {
        padding: 15px 15px;
    }
}