:root {
    color-scheme: light;
    --page: #f4f1ea;
    --panel: #fffdf8;
    --ink: #22211e;
    --muted: #6d6a62;
    --line: #d9d3c7;
    --accent: #b84625;
    --accent-dark: #8f3219;
    --success: #286347;
    --danger: #a43f31;
}

* {
    box-sizing: border-box;
}

body {
    min-width: 320px;
    margin: 0;
    color: var(--ink);
    background: var(--page);
    font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
    font: inherit;
}

button {
    min-height: 40px;
    padding: 0 16px;
    cursor: pointer;
    color: #fffdf8;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: var(--accent);
}

button:hover:not(:disabled) {
    background: var(--accent-dark);
}

button:focus-visible,
input:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent);
    outline-offset: 2px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

button.secondary {
    color: var(--ink);
    border-color: var(--line);
    background: transparent;
}

main {
    width: min(1440px, calc(100% - 32px));
    margin: 0 auto;
    padding: clamp(24px, 5vw, 72px) 0;
}

header {
    display: flex;
    gap: 24px;
    align-items: end;
    justify-content: space-between;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    max-width: 820px;
    font-size: clamp(28px, 5vw, 52px);
    font-weight: 750;
    line-height: 1.05;
    letter-spacing: -0.055em;
}

h1 span {
    color: var(--accent);
}

h2 {
    font-size: 16px;
    letter-spacing: 0.02em;
}

.intro {
    max-width: 740px;
    margin-top: 12px;
    color: var(--muted);
    line-height: 1.6;
}

.header-actions {
    display: flex;
    flex: none;
    flex-direction: column;
    gap: 12px;
    align-items: flex-end;
}

.header-links {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 14px;
    color: var(--ink);
    text-decoration: none;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
}

.header-link:hover {
    border-color: var(--accent);
    color: var(--accent-dark);
}

.header-link:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent);
    outline-offset: 2px;
}

.header-link[aria-disabled="true"] {
    cursor: default;
    opacity: 0.55;
}

.header-link[aria-disabled="true"]:hover {
    border-color: var(--line);
    color: var(--ink);
}

.runtime-badge {
    flex: none;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
    color: var(--success);
    border: 1px solid currentColor;
    border-radius: 999px;
}

.runtime-badge.is-unsupported,
.status[data-status="error"] {
    color: var(--danger);
}

.controls {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 12px;
    align-items: end;
    padding: 24px 0;
}

.source-mode {
    display: inline-flex;
    gap: 0;
    align-items: stretch;
    border: 1px solid var(--line);
    border-radius: 4px;
    overflow: hidden;
    background: var(--panel);
}

.source-mode__button {
    min-height: 40px;
    padding: 0 14px;
    color: var(--muted);
    border: 0;
    border-radius: 0;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
}

.source-mode__button + .source-mode__button {
    border-left: 1px solid var(--line);
}

.source-mode__button:hover:not(:disabled) {
    color: var(--accent-dark);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.source-mode__button.is-active {
    color: #fffdf8;
    background: var(--accent);
}

.source-mode__button.is-active:hover:not(:disabled) {
    color: #fffdf8;
    background: var(--accent-dark);
}

.field {
    display: grid;
    gap: 7px;
}

.field[hidden] {
    display: none;
}

.field label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

input {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--panel);
}

input[type="file"] {
    padding: 7px;
}

.hint {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.layout {
    display: grid;
    grid-template-columns: minmax(280px, 0.58fr) minmax(0, 1.42fr);
    gap: 18px;
    align-items: start;
}

.panel {
    overflow: hidden;
    border: 1px solid var(--line);
    background: var(--panel);
}

.panel-heading {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.status {
    font-size: 12px;
    color: var(--muted);
}

.status[data-status="running"] {
    color: var(--accent);
}

.status[data-status="done"] {
    color: var(--success);
}

video {
    display: block;
    width: 100%;
    max-height: 360px;
    background: #211f1a;
}

.basic-video-info {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    margin: 0;
    border-bottom: 1px solid var(--line);
    background: var(--line);
}

.basic-video-info__item {
    min-width: 0;
    padding: 12px 14px;
    background: var(--panel);
}

.basic-video-info dt {
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.basic-video-info dd {
    margin: 0;
    overflow: hidden;
    color: var(--ink);
    font-size: 13px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

pre {
    min-height: 280px;
    max-height: 520px;
    margin: 0;
    padding: 16px;
    overflow: auto;
    color: #413d35;
    background: #f9f6ef;
    font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.frame-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.frame-counter,
.parse-duration {
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.frames {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    padding: 16px;
}

.empty {
    grid-column: 1 / -1;
    padding: 32px 16px;
    color: var(--muted);
    text-align: center;
    border: 1px dashed var(--line);
}

figure {
    min-width: 0;
    margin: 0;
    border: 1px solid var(--line);
    background: #f9f6ef;
}

figure img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: #211f1a;
}

figcaption {
    padding: 7px 8px;
    overflow: hidden;
    color: var(--muted);
    font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 900px) {
    header,
    .layout {
        display: grid;
        grid-template-columns: 1fr;
        align-items: start;
    }

    .controls {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .controls #startButton,
    .controls #cancelButton {
        justify-self: start;
    }
}

@media (max-width: 600px) {
    main {
        width: min(100% - 20px, 1440px);
    }

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

    .source-mode {
        width: 100%;
    }

    .source-mode__button {
        flex: 1;
    }

    .hint {
        grid-column: auto;
    }

    .basic-video-info {
        grid-template-columns: 1fr;
    }
}