:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #172033;
    --muted: #647086;
    --line: #dce3ef;
    --accent: #335cff;
    --accent-dark: #2444c8;
    --danger: #cc2d2d;
    --shadow: 0 20px 60px rgba(23, 32, 51, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top left, #e5ebff, transparent 32rem), var(--bg);
    color: var(--text);
    font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
}

a {
    color: var(--accent);
}

button,
.button-secondary {
    align-items: center;
    background: var(--accent);
    border: 0;
    border-radius: 999px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 700;
    gap: 0.5rem;
    justify-content: center;
    padding: 0.85rem 1.2rem;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.15s ease;
}

button:hover,
.button-secondary:hover {
    background: var(--accent-dark);
    transform: translateY(-1px);
}

button.danger {
    background: var(--danger);
}

button.ghost {
    background: #eef2fb;
    color: var(--text);
}

button.ghost:hover {
    background: #e1e8f7;
}

input[type="file"] {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 1rem;
    padding: 1rem;
    width: 100%;
}

.shell {
    margin: 0 auto;
    max-width: 1040px;
    padding: 4rem 1.25rem;
}

.result-shell {
    max-width: 1280px;
}

.hero {
    margin-bottom: 2rem;
    max-width: 760px;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    font-size: clamp(2.2rem, 6vw, 4.6rem);
    letter-spacing: -0.06em;
    line-height: 0.95;
}

h2 {
    font-size: clamp(1.4rem, 3vw, 2rem);
}

.hero p,
.hint {
    color: var(--muted);
    line-height: 1.65;
}

.eyebrow {
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.card,
.viewer-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
    padding: clamp(1.25rem, 3vw, 2rem);
}

.upload-card {
    max-width: 680px;
}

.upload-card label {
    display: block;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.alert {
    background: #fff2f2;
    border: 1px solid #ffd1d1;
    border-radius: 1rem;
    color: #8f1f1f;
    margin-bottom: 1rem;
    padding: 1rem;
}

.back-link {
    display: inline-block;
    font-weight: 700;
    margin-bottom: 1rem;
    text-decoration: none;
}

.metadata-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    margin: 0;
}

.metadata-grid div {
    background: #f7f9fd;
    border: 1px solid var(--line);
    border-radius: 1rem;
    padding: 1rem;
}

.metadata-grid dt {
    color: var(--muted);
    font-size: 0.82rem;
    margin-bottom: 0.4rem;
}

.metadata-grid dd {
    font-size: 1.15rem;
    font-weight: 800;
    margin: 0;
}

.fps-options {
    display: grid;
    gap: 0.85rem;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    margin: 1.5rem 0;
}

.fps-options label {
    background: #f7f9fd;
    border: 1px solid var(--line);
    border-radius: 1rem;
    cursor: pointer;
    display: grid;
    gap: 0.35rem;
    padding: 1rem;
}

.fps-options span {
    font-weight: 800;
}

.fps-options small {
    color: var(--muted);
}

.existing-frames-card h2 {
    font-size: clamp(1.4rem, 3vw, 2rem);
}

.inline-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.inline-actions form {
    margin: 0;
}

.result-header {
    align-items: start;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.viewer-card {
    overflow: hidden;
    position: sticky;
    top: 1rem;
    z-index: 2;
}

.viewer-card.is-collapsed {
    position: static;
    z-index: auto;
}

.viewer-card.is-collapsed #active-frame,
.viewer-card.is-collapsed #active-name {
    display: none;
}

.viewer-toolbar {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.viewer-card.is-collapsed .viewer-toolbar {
    margin-bottom: 0;
}

.download-link {
    background: #172033;
}

.download-link:hover {
    background: #263248;
}

#active-frame {
    background: #101725;
    border-radius: 1.25rem;
    display: block;
    max-height: 62vh;
    object-fit: contain;
    width: 100%;
}

#active-name {
    margin: 0.75rem 0 0;
    text-align: center;
}

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

.thumb {
    background: #fff;
    border: 2px solid transparent;
    border-radius: 1rem;
    color: var(--text);
    display: grid;
    gap: 0.45rem;
    overflow: hidden;
    padding: 0.45rem;
    text-align: left;
}

.thumb img {
    aspect-ratio: 16 / 9;
    background: #101725;
    border-radius: 0.75rem;
    object-fit: cover;
    width: 100%;
}

.thumb span {
    color: var(--muted);
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thumb.is-active {
    border-color: var(--accent);
}

@media (max-width: 720px) {
    .shell {
        padding: 1.25rem 0.85rem 2rem;
    }

    .result-header {
        display: block;
    }

    .button-secondary {
        margin-top: 1rem;
    }

    .inline-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .inline-actions .button-secondary,
    .inline-actions button {
        justify-content: center;
        width: 100%;
    }

    .viewer-card {
        border-radius: 1.25rem;
        padding: 0.85rem;
        position: static;
    }

    .viewer-toolbar {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .viewer-toolbar strong {
        align-self: center;
        grid-column: 1 / -1;
        text-align: center;
    }

    .viewer-toolbar button,
    .viewer-toolbar .button-secondary {
        padding: 0.75rem 0.85rem;
    }

    #active-frame {
        max-height: 48vh;
    }

    .thumb-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .thumb {
        border-radius: 0.85rem;
        padding: 0.35rem;
    }
}
