:root {
    --bg: #f0f7ff;
    --surface: #ffffff;
    --text: #1e3a5f;
    --text-secondary: #6b8cae;
    --accent: #4a90d9;
    --accent-light: #7ab8e8;
    --border: #c5d9ed;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.15), 0 4px 6px -2px rgba(0,0,0,0.08);
    
    /* Typography Scale */
    --font-display: 'Space Grotesk', system-ui, sans-serif;
    --font-body: 'IBM Plex Sans', system-ui, sans-serif;
    
    --text-xs: 0.6875rem;   /* 11px */
    --text-sm: 0.75rem;     /* 12px */
    --text-base: 0.875rem;  /* 14px */
    --text-md: 1rem;        /* 16px */
    --text-lg: 1.125rem;    /* 18px */
    --text-xl: 1.5rem;      /* 24px */
    --text-2xl: 2rem;       /* 32px */
    --text-3xl: 2.5rem;     /* 40px */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

body:has(.upload-container:not([style*="none"])) {
    justify-content: center;
    align-items: center;
}

body:has(.upload-container:not([style*="none"])) .header {
    position: absolute;
    top: 2rem;
    left: 0;
    right: 0;
}

.github-btn {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    transition: all 0.2s ease;
    z-index: 100;
    box-shadow: var(--shadow);
}

.github-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.github-btn svg {
    width: 20px;
    height: 20px;
}

.header {
    padding: 2.5rem 1.5rem 1.5rem;
    text-align: center;
}

.header p {
    font-family: var(--font-body);
    font-size: var(--text-base);
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.03em;
    line-height: 1.5;
}

.upload-container {
    padding: 0 1.5rem;
    margin: 0 auto;
    max-width: 420px;
    width: 100%;
}

.upload-zone {
    border: 1.5px dashed var(--border);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    text-align: center;
    background: var(--surface);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;

}

.upload-zone.dragover {
    border-color: var(--accent);
    background: #e8f3ff;
}

.upload-zone.hidden {
    display: none;
}

.upload-icon {
    width: 32px;
    height: 32px;
    margin: 0 auto 0.75rem;
    color: var(--text-secondary);
    stroke-width: 1.5;
}

.upload-text {
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.375rem;
    letter-spacing: -0.01em;
}

.upload-hint {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

input[type="file"] { display: none; }



.film-container {
    display: none;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    min-height: 50vh;
    min-height: 50dvh;
}

.film-container.visible {
    display: flex;
    animation: fadeIn 0.6s ease;
    flex-direction: column;
}

.original-gif {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    background: var(--bg);
}

.original-gif img {
    max-width: 260px;
    border-radius: 8px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.film-scroll {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    padding: 2rem 1.5rem 1.5rem;
    gap: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    align-items: stretch;
    /* Fixed height based on max frame image height + padding */
    /* height: 340px;
    min-height: 340px; */
}

.film-scroll::-webkit-scrollbar {
    height: 6px;
}

.film-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.film-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.frame-card {
    flex: 0 0 auto;
    width: 260px;
    margin-left: -40px;
    scroll-snap-align: center;
    position: relative;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    z-index: 1;
    -webkit-tap-highlight-color: transparent;
}

.frame-card:first-child {
    margin-left: 0;
}

.frame-card:hover {
    z-index: 9999 !important;
}



.frame-image {
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    position: relative;
    /* Use GIF's actual aspect ratio, fallback to square if not set */
    aspect-ratio: var(--gif-aspect-ratio, 1);
    /* min-height: 200px; */
    max-height: 280px;
}

.frame-image canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background-image: 
        linear-gradient(45deg, #e8f1fa 25%, transparent 25%), 
        linear-gradient(-45deg, #e8f1fa 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #e8f1fa 75%), 
        linear-gradient(-45deg, transparent 75%, #e8f1fa 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

.frame-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    /* background: rgba(30, 58, 95, 0.85); */
    color: #ffffff;
    padding: 0.25rem 0.625rem;
    border-radius: 20px;
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    font-family: var(--font-display);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

/* Redesigned Download Button - Minimal Icon Style */
.frame-download {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 0 solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.2s, transform 0.2s;
    z-index: 5;
    color: var(--text);
}

.frame-download:hover {
    background: rgba(255, 255, 255, 0.9);
    color: var(--text);
}

.frame-card:hover .frame-download {
    opacity: 1;
    transform: scale(1);
}

.frame-download svg {
    width: 16px;
    height: 16px;
    stroke-width: 1;
}

.info-footer {
    display: none;
    padding: 0.875rem 1rem;
    text-align: center;
    /* border-top: 1px solid var(--border); */
    margin-top: auto;
    background: var(--bg);
    font-family: var(--font-body);
}

.info-footer.visible {
    display: block;
    animation: slideUp 0.4s ease;
}

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

.info-content {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.meta-row {
    display: flex;
    gap: 1.25rem;
    justify-content: center;
    flex-wrap: wrap;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--text);
    letter-spacing: 0;
    align-items: center;
}

.meta-item-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.meta-item-inline span:last-child {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: var(--text-base);
}

.meta-separator {
    color: var(--text-secondary);
    font-weight: 400;
    opacity: 0.5;
}

.meta-label-sub {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-weight: 500;
}

.frame-actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    padding: 0 1.5rem 1.5rem;
    margin: 1rem;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: var(--text-sm);
    font-weight: 500;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    font-family: var(--font-display);
    letter-spacing: 0.02em;
}

.btn-icon {
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--text);
    color: var(--surface);
}

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

.loading {
    display: none;
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
    z-index: 50;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.loading.active {
    display: flex;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    animation: fadeIn 0.3s ease;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: 500;
    color: var(--text);
    letter-spacing: 0.02em;
}

.loading-filename {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

@media (max-width: 640px) {
    .github-btn {
        width: 36px;
        height: 36px;
        top: 1rem;
        right: 1rem;
        border-radius: 50%;
    }

    .github-btn svg {
        width: 18px;
        height: 18px;
    }

    .header {
        padding: 1.5rem 1rem 0.75rem;
    }

    .header p {
        font-size: var(--text-sm);
    }

    body:has(.upload-container:not([style*="none"])) .header {
        top: 1rem;
    }

    .upload-container {
        padding: 0 1rem;
        margin: 0 auto;
    }

    .upload-zone {
        padding: 2rem 1.5rem;
    }

    .upload-text {
        font-size: var(--text-base);
    }

    .upload-hint {
        font-size: var(--text-xs);
    }

    .frame-card {
        width: 220px;
        margin-left: -24px;
    }

    .film-container {
        min-height: auto;
        max-height: calc(100dvh - 120px);
        /* justify-content: flex-start; */
        padding-bottom: 1rem;
    }

    .film-scroll {
        padding: 1.5rem 1rem;
        height: auto;
        min-height: 220px;
        max-height: 45vh;
        max-height: 45dvh;
        flex: 0 0 auto;
    }
    
    .frame-image {
        min-height: 140px;
        max-height: 200px;
    }

    .frame-actions {
        padding: 0 1rem 1rem;
        gap: 0.5rem;
        flex: 0 0 auto;
    }

    .original-gif {
        padding: 1rem;
        flex: 0 0 auto;
    }

    .original-gif img {
        max-height: 120px;
    }

    /* Show download button always on mobile */
    .frame-download {
        opacity: 1;
        transform: scale(1);
        width: 28px;
        height: 28px;
        top: 8px;
        right: 8px;
    }

    .frame-download svg {
        width: 14px;
        height: 14px;
    }

    .meta-row {
        gap: 0.75rem;
        font-size: var(--text-xs);
    }

    .meta-item-inline span:last-child {
        font-size: var(--text-sm);
    }

    .info-content {
        gap: 1.25rem;
    }

    .btn-icon {
        width: 36px;
        height: 36px;
        border-radius: 8px;
    }

    .btn-icon svg {
        width: 16px;
        height: 16px;
    }

    .meta-separator {
        display: none;
    }

    .meta-item-inline {
        flex-direction: column;
        gap: 0.125rem;
        align-items: center;
    }
}

@media (hover: hover) {
    .frame-card:nth-child(even) {
        transform: rotate(1deg);
    }
    .frame-card:nth-child(odd) {
        transform: rotate(-0.5deg);
    }
}
