/*
 * video.css - video frame and GIF tool
 * The filmstrip, the selection state and the GIF controls for the
 * ffmpeg.wasm powered tool.
 */

/* ========== source picker ========== */
.video-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 2rem 1.25rem;
    background: var(--surface-muted);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    text-align: center;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.video-dropzone.is-dragging {
    border-color: var(--primary-color);
    background: var(--primary-soft);
}

.video-dropzone > i {
    font-size: 1.9rem;
    color: var(--primary-color);
}

.video-dropzone h3 {
    font-size: 1rem;
    font-weight: 700;
}

.video-dropzone p {
    color: var(--light-text);
    font-size: 0.85rem;
}

.video-file {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.9rem;
    padding: 0.75rem 0.9rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.video-file strong {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.9rem;
    word-break: break-all;
}

.video-file strong i {
    color: var(--primary-color);
}

.video-file span {
    color: var(--light-text);
    font-size: 0.8rem;
}

/* ========== status and progress ========== */
.video-status {
    min-height: 1.4rem;
    margin-top: 0.9rem;
    color: var(--light-text);
    font-size: 0.85rem;
}

.video-status.is-error {
    color: var(--primary-hover);
    font-weight: 600;
    white-space: pre-wrap;
}

/* Working and finished states get a filled green banner: the WASM engine can
   run for a minute without reporting progress, so the line has to be loud. */
.video-status.is-working,
.video-status.is-success {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    border: 1px solid #b6e3c5;
    border-radius: var(--border-radius);
    color: #15803d;
    background: #e7f6ec;
    font-size: 0.92rem;
    font-weight: 700;
}

.video-status.is-working {
    animation: video-status-pulse 1.6s ease-in-out infinite;
}

.video-status.is-working::before {
    content: '';
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(21, 128, 61, 0.25);
    border-top-color: #15803d;
    border-radius: 50%;
    animation: video-status-spin 0.7s linear infinite;
}

@keyframes video-status-spin {
    to { transform: rotate(360deg); }
}

@keyframes video-status-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.22); }
    50% { box-shadow: 0 0 0 7px rgba(22, 163, 74, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .video-status.is-working,
    .video-status.is-working::before {
        animation: none;
    }
}

.video-progress {
    height: 6px;
    margin-top: 0.6rem;
    overflow: hidden;
    background: var(--border-color);
    border-radius: 999px;
}

.video-progress-bar {
    width: 0;
    height: 100%;
    background: var(--primary-color);
    border-radius: 999px;
    transition: width 0.25s ease;
}

/* ========== filmstrip ========== */
.frame-strip-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 1.5rem 0 0.75rem;
}

.frame-strip-head h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.98rem;
}

.frame-strip-head h3 i {
    color: var(--primary-color);
}

.frame-settings {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.frame-settings select {
    padding: 0.4rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.82rem;
}

.frame-settings .btn {
    padding: 0.42rem 0.8rem;
    font-size: 0.82rem;
}

.frame-strip {
    position: relative;
    display: flex;
    gap: 0.55rem;
    padding: 0.75rem;
    overflow-x: auto;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    scrollbar-width: thin;
}

/* ========== extra audio track ========== */
.audio-source {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.55rem;
}

.audio-source .btn {
    padding: 0.42rem 0.8rem;
    font-size: 0.82rem;
}

.audio-source-name {
    overflow: hidden;
    max-width: 100%;
    color: var(--text-color);
    font-size: 0.82rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audio-remove {
    padding: 0;
    color: var(--primary-hover);
    background: none;
    border: 0;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
}

.audio-remove:hover {
    text-decoration: underline;
}

/* ========== photo slideshow strip ========== */
.slide-strip-wrap {
    position: relative;
}

.slide-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.slide-card {
    flex: 0 0 auto;
    width: 132px;
    padding: 0.4rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: grab;
    transition: box-shadow 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

.slide-card:hover {
    box-shadow: var(--box-shadow);
}

.slide-card.is-dragging {
    opacity: 0.45;
}

.slide-card.is-target {
    transform: translateY(-3px);
    border-color: var(--primary-color);
}

.slide-thumb {
    position: relative;
    overflow: hidden;
    height: 84px;
    background: #0f172a;
    border-radius: 7px;
}

.slide-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.slide-grip {
    position: absolute;
    top: 4px;
    left: 4px;
    min-width: 1.35rem;
    padding: 0.05rem 0.3rem;
    color: #fff;
    background: rgba(15, 23, 42, 0.78);
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    text-align: center;
}

.slide-name {
    margin: 0.35rem 0 0.25rem;
    overflow: hidden;
    font-size: 0.76rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.slide-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
}

.slide-field {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    color: var(--light-text);
    font-size: 0.72rem;
}

.slide-duration {
    width: 3.4rem;
    padding: 0.15rem 0.25rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.78rem;
}

.slide-remove {
    padding: 0.2rem 0.35rem;
    color: var(--light-text);
    background: none;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
}

.slide-remove:hover {
    color: var(--primary-hover);
    background: #fdeaea;
}

.slide-size {
    margin: 0.2rem 0 0;
    color: var(--light-text);
    font-size: 0.68rem;
}

.slide-check {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-color);
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
}

.slide-check input {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.slide-strip-note {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.5rem 0 0.75rem;
    color: var(--light-text);
    font-size: 0.82rem;
}

.slide-strip-note i {
    color: var(--primary-color);
}

.slide-join {
    flex: 0 0 auto;
    align-self: center;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    max-width: 116px;
    padding: 0.3rem 0.5rem;
    overflow: hidden;
    color: var(--primary-hover);
    background: #fdeaea;
    border: 1px solid rgba(239, 68, 68, 0.28);
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.slide-join:hover {
    background: #f8d7d7;
}

/* ========== cut markers and transition popover ========== */
.video-timeline {
    position: relative;
}

.cut-layer {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    pointer-events: none;
}

.cut-marker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 16px;
    margin-left: -8px;
    padding: 0;
    background: transparent;
    border: 0;
    cursor: ew-resize;
    pointer-events: auto;
    touch-action: none;
}

.cut-marker-line {
    position: absolute;
    top: 6px;
    bottom: 6px;
    left: 50%;
    width: 3px;
    margin-left: -1.5px;
    background: var(--primary-color);
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.75);
    transition: width 0.15s ease, background-color 0.15s ease;
}

.cut-marker-badge {
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 150px;
    padding: 0.14rem 0.45rem;
    overflow: hidden;
    color: #fff;
    background: var(--primary-color);
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.cut-marker:hover .cut-marker-line,
.cut-marker:focus-visible .cut-marker-line,
.cut-marker.is-dragging .cut-marker-line {
    width: 5px;
    background: var(--primary-hover);
}

.cut-marker:focus-visible {
    outline: 2px solid var(--primary-hover);
    outline-offset: 2px;
}

.cut-marker.is-dragging .cut-marker-badge,
.cut-marker:hover .cut-marker-badge {
    background: var(--primary-hover);
}

.cut-popover {
    position: absolute;
    top: calc(100% + 8px);
    z-index: 30;
    width: 252px;
    padding: 0.75rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.cut-popover[hidden] {
    display: none;
}

.cut-popover-title {
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
    font-weight: 700;
}

.cut-popover-list {
    max-height: 240px;
    overflow-y: auto;
}

.cut-popover-group {
    margin: 0.5rem 0 0.2rem;
    color: var(--light-text);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.cut-popover-item {
    display: block;
    width: 100%;
    padding: 0.34rem 0.5rem;
    color: var(--text-color);
    background: transparent;
    border: 0;
    border-radius: 7px;
    font-size: 0.82rem;
    text-align: left;
    cursor: pointer;
}

.cut-popover-item:hover {
    background: #f1f5f9;
}

.cut-popover-item.is-active {
    color: var(--primary-hover);
    background: #fdeaea;
    font-weight: 700;
}

.cut-popover-remove {
    display: block;
    width: 100%;
    margin-top: 0.55rem;
    padding: 0.4rem;
    color: #b91c1c;
    background: #fdeaea;
    border: 0;
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
}

.cut-popover-remove:hover {
    background: #f8d7d7;
}

.frame-strip-hint {
    padding: 0.75rem 0;
    color: var(--light-text);
    font-size: 0.85rem;
}

.frame-cell {
    position: relative;
    flex: 0 0 auto;
    width: 148px;
    padding: 0;
    background: #0f172a;
    border: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.frame-cell:hover {
    transform: translateY(-2px);
}

.frame-cell img {
    display: block;
    width: 100%;
    height: 83px;
    object-fit: cover;
    background: #0f172a;
}

.frame-cell.is-start,
.frame-cell.is-end {
    border-color: var(--primary-color);
}

.frame-cell.is-in-range {
    border-color: rgba(239, 68, 68, 0.55);
}

.frame-cell:not(.is-start):not(.is-end):not(.is-in-range) {
    opacity: 0.78;
}

.frame-time {
    display: block;
    padding: 0.25rem 0.35rem;
    color: #fff;
    background: rgba(15, 23, 42, 0.82);
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.frame-badge {
    position: absolute;
    top: 0.35rem;
    left: 0.35rem;
    padding: 0.1rem 0.45rem;
    color: #fff;
    background: var(--primary-color);
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* ========== selection and actions ========== */
.selection-info {
    margin-top: 0.85rem;
    padding: 0.7rem 0.9rem;
    background: var(--primary-soft);
    border: 1px solid rgba(239, 68, 68, 0.28);
    border-radius: var(--border-radius);
    color: var(--text-color);
    font-size: 0.86rem;
}

.video-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0.9rem;
    margin-top: 1.25rem;
}

.video-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.85rem 0.95rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.video-field label {
    font-size: 0.82rem;
    font-weight: 700;
}

.video-field select {
    padding: 0.45rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.85rem;
}

.video-field small {
    color: var(--light-text);
    font-size: 0.75rem;
}

.video-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1.25rem;
}

.video-actions .btn {
    flex: 1 1 200px;
}

/* ========== timeline ========== */
.timeline-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-top: 1.1rem;
    padding: 0.8rem 0.95rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.timeline-row label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex: 0 0 auto;
    font-size: 0.85rem;
    font-weight: 700;
}

.timeline-row label i {
    color: var(--primary-color);
}

.timeline-row input[type='range'] {
    flex: 1;
    min-width: 120px;
    accent-color: var(--primary-color);
}

.field-note {
    color: var(--light-text);
    font-size: 0.75rem;
    font-weight: 500;
}

/* ========== GIF result ========== */
.gif-panel {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.gif-panel h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
    font-size: 0.98rem;
}

.gif-panel h3 i {
    color: var(--primary-color);
}

.gif-preview {
    display: block;
    max-width: 100%;
    max-height: 320px;
    margin-bottom: 0.75rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.gif-meta {
    margin-bottom: 0.9rem;
    color: var(--light-text);
    font-size: 0.83rem;
}

.result-video {
    display: block;
    width: 100%;
    max-width: 520px;
    max-height: 320px;
    margin-bottom: 0.85rem;
    background: #0f172a;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.video-credits {
    margin-top: 1.25rem;
    color: var(--light-text);
    font-size: 0.76rem;
    line-height: 1.6;
}

.video-credits i {
    margin-right: 0.3rem;
}

.video-credits a {
    color: var(--light-text);
    text-decoration: underline;
}

/* ========== busy state ========== */
body.is-busy .video-dropzone,
body.is-busy .frame-strip {
    pointer-events: none;
    opacity: 0.72;
}

@media (max-width: 620px) {
    .frame-cell {
        width: 120px;
    }

    .frame-cell img {
        height: 68px;
    }

    .video-actions .btn {
        flex: 1 1 100%;
    }
}
