.downloader-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.downloader-modal[hidden] {
    display: none;
}

.downloader-backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: modalFadeIn 220ms ease-out both;
}

.downloader-modal.is-closing .downloader-backdrop {
    animation: modalFadeOut 150ms ease-out both;
}

.downloader-dialog {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    max-height: 85dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid transparent;
    border-radius: 20px;
    background: var(--dialog-bg);
    box-shadow: var(--shadow-border), var(--shadow-elevated);
    animation: modalFadeIn 220ms ease-out both;
}

@media (prefers-reduced-motion: no-preference) {
    .downloader-dialog {
        animation: dialogPopIn 280ms cubic-bezier(0.2, 0, 0, 1) both;
    }

    .downloader-modal.is-closing .downloader-dialog {
        animation: dialogPopOut 150ms ease-out both;
    }
}

.downloader-modal.is-closing .downloader-dialog {
    animation: modalFadeOut 150ms ease-out both;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
}

@keyframes modalFadeOut {
    to {
        opacity: 0;
    }
}

@keyframes dialogPopIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
}

@keyframes dialogPopOut {
    to {
        opacity: 0;
        transform: translateY(-8px) scale(0.99);
    }
}

@keyframes resultItemSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

.downloader-item-enter {
    animation: modalFadeIn 240ms ease-out both;
    animation-delay: calc(var(--item-index, 0) * 50ms);
}

@media (prefers-reduced-motion: no-preference) {
    .downloader-item-enter {
        animation-name: resultItemSlideIn;
    }
}

.downloader-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 8px 6px 16px;
}

.downloader-label {
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 700;
}

.downloader-close {
    display: inline-flex;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-size: 1rem;
    touch-action: manipulation;
    transition-property: background-color, color, scale;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.downloader-close:not(:disabled):active {
    scale: 0.96;
}

.platform-switch-wrap {
    padding: 0 12px 10px;
}

.platform-switch {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 4px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--surface-subtle);
    box-shadow: var(--shadow-border);
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.platform-switch-thumb {
    position: absolute;
    top: 4px;
    left: 4px;
    bottom: 4px;
    width: calc(50% - 4px);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow-border-hover);
    transform: translateX(0%);
    transition-property: transform;
    transition-duration: 300ms;
    transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
    pointer-events: none;
}

.platform-switch[data-active="x"] .platform-switch-thumb {
    transform: translateX(100%);
}

.platform-switch-btn {
    position: relative;
    z-index: 1;
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    touch-action: manipulation;
    transition-property: color, scale;
    transition-duration: 160ms;
    transition-timing-function: ease-out;
}

.platform-switch-btn.is-active {
    color: var(--text);
}

.platform-switch-btn.is-active i {
    color: var(--accent);
}

.platform-switch-btn:not(:disabled):active {
    scale: 0.96;
}

.command-bar-wrap {
    padding: 0 12px 12px;
}

.command-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 4px 2px 12px;
    border: 1px solid var(--border-control);
    border-radius: 10px;
    background: var(--surface-subtle);
    transition-property: border-color, background-color;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.command-bar:focus-within {
    border-color: var(--accent);
}

.command-bar:has(:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.command-icon-stack {
    display: grid;
    place-items: center;
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    color: var(--muted);
    font-size: 0.92rem;
    transition: color 150ms ease-out;
}

.command-bar:focus-within .command-icon-stack {
    color: var(--accent);
}

.command-icon-layer {
    grid-area: 1 / 1;
    opacity: 0;
    scale: 0.25;
    filter: blur(4px);
    transition-property: opacity, scale, filter;
    transition-duration: 280ms;
    transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}

.command-icon-stack[data-active-icon="tiktok"] [data-icon-platform="tiktok"],
.command-icon-stack[data-active-icon="x"] [data-icon-platform="x"] {
    opacity: 1;
    scale: 1;
    filter: blur(0px);
}

.downloader-input {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.86rem;
}

.downloader-input:focus {
    outline: none;
}

.downloader-input::placeholder {
    color: var(--subtle);
}

.command-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
}

.input-icon-btn {
    display: inline-flex;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 0.92rem;
    touch-action: manipulation;
    transition-property: background-color, color, scale;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.input-icon-btn[hidden] {
    display: none;
}

.input-icon-btn:not(:disabled):active {
    scale: 0.96;
}

.input-paste-btn {
    display: inline-flex;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--accent);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 700;
    touch-action: manipulation;
    transition-property: background-color, color, scale;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.input-paste-btn[hidden] {
    display: none;
}

.input-paste-btn:not(:disabled):active {
    scale: 0.96;
}

.command-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-top: 1px solid var(--divider);
    background: var(--surface-subtle);
}

.platform-hint {
    min-width: 0;
    color: var(--subtle);
    font-size: 0.76rem;
    line-height: 1.35;
}

.downloader-submit {
    display: inline-flex;
    min-height: 44px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 700;
    touch-action: manipulation;
    transition-property: background-color, scale;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.downloader-submit:not(:disabled):active {
    scale: 0.96;
}

.downloader-submit:disabled {
    opacity: 0.6;
}

.downloader-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 14px;
    border-top: 1px solid var(--divider);
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.4;
    text-align: left;
}

.downloader-status[hidden] {
    display: none;
}

.downloader-status.is-error {
    color: #dc2626;
}

:root:not([data-theme="light"]) .downloader-status.is-error {
    color: #f87171;
}

.downloader-status.is-success {
    color: #16a34a;
}

:root:not([data-theme="light"]) .downloader-status.is-success {
    color: #4ade80;
}

.downloader-result {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px 14px;
    border-top: 1px solid var(--divider);
}

.downloader-result[hidden] {
    display: none;
}

.downloader-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--surface-subtle);
    box-shadow: var(--shadow-border);
}

.downloader-thumb {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--surface);
    outline: 1px solid var(--image-outline);
    outline-offset: -1px;
}

.downloader-meta {
    min-width: 0;
    flex: 1;
}

.downloader-meta-author {
    margin-bottom: 2px;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.72rem;
}

.downloader-meta-title {
    display: -webkit-box;
    overflow: hidden;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.35;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.downloader-media-preview {
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--surface-subtle);
    box-shadow: var(--shadow-border);
}

.downloader-video-player {
    display: block;
    width: 100%;
    max-height: 240px;
    background: #09090b;
    object-fit: contain;
}

.downloader-audio-player {
    display: block;
    width: 100%;
    height: 44px;
}

.downloader-slides-preview {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overscroll-behavior: contain;
    padding: 8px;
    scrollbar-width: thin;
}

.downloader-slide-thumb {
    width: 84px;
    height: 112px;
    flex: 0 0 84px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--surface);
    outline: 1px solid var(--image-outline);
    outline-offset: -1px;
}

.downloader-batch-btn {
    display: flex;
    width: 100%;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--accent-soft);
    box-shadow: var(--shadow-featured);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 700;
    touch-action: manipulation;
    transition-property: background-color, box-shadow, scale;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.downloader-batch-btn:not(:disabled):active {
    scale: 0.96;
}

.downloader-batch-btn:disabled {
    opacity: 0.65;
}

.downloader-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.downloader-item-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.downloader-direct-link {
    display: flex;
    min-width: 0;
    min-height: 46px;
    flex: 1;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--surface-subtle);
    box-shadow: var(--shadow-border);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    touch-action: manipulation;
    transition-property: background-color, box-shadow, scale;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.downloader-direct-link:not(:disabled):active {
    scale: 0.96;
}

.downloader-direct-link.is-downloading {
    opacity: 0.65;
    pointer-events: none;
}

.downloader-item-left {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 9px;
}

.downloader-item-left > i {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 0.88rem;
}

.downloader-item-left > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.download-arrow {
    flex: 0 0 auto;
    margin-left: 8px;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    transition-property: color, translate;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.downloader-share-btn {
    display: inline-flex;
    min-width: 46px;
    min-height: 46px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--surface-subtle);
    box-shadow: var(--shadow-border);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    touch-action: manipulation;
    transition-property: background-color, box-shadow, scale;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.downloader-share-btn:not(:disabled):active {
    scale: 0.96;
}

.downloader-share-btn:disabled {
    opacity: 0.65;
}

.downloader-history {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px 14px;
    border-top: 1px solid var(--divider);
}

.downloader-history[hidden] {
    display: none;
}

.downloader-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.downloader-history-title {
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
}

.downloader-history-clear {
    display: inline-flex;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--subtle);
    font-family: var(--font-sans);
    font-size: 0.76rem;
    font-weight: 600;
    touch-action: manipulation;
    transition-property: background-color, color;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.downloader-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.downloader-history-item {
    display: flex;
    width: 100%;
    min-height: 52px;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--surface-subtle);
    box-shadow: var(--shadow-border);
    color: var(--text);
    font-family: var(--font-sans);
    text-align: left;
    touch-action: manipulation;
    transition-property: background-color, box-shadow, scale;
    transition-duration: 150ms;
    transition-timing-function: ease-out;
}

.downloader-history-item:not(:disabled):active {
    scale: 0.96;
}

.downloader-history-thumb {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    border-radius: 7px;
    object-fit: cover;
    background: var(--surface);
    outline: 1px solid var(--image-outline);
    outline-offset: -1px;
}

.downloader-history-copy {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    gap: 2px;
}

.downloader-history-author {
    color: var(--subtle);
    font-family: var(--font-mono);
    font-size: 0.7rem;
}

.downloader-history-name {
    overflow: hidden;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (hover: hover) and (pointer: fine) {
    .downloader-close:hover {
        background: var(--surface-hover);
        color: var(--text);
    }

    .platform-switch-btn:not(.is-active):hover {
        color: var(--text);
    }

    .input-icon-btn:hover {
        background: var(--surface-hover);
        color: var(--text);
    }

    .input-paste-btn:hover {
        background: var(--accent-soft);
    }

    .downloader-submit:hover:not(:disabled) {
        background: var(--accent-hover);
    }

    .downloader-batch-btn:hover:not(:disabled) {
        background: var(--surface-hover);
        box-shadow: var(--shadow-featured-hover);
    }

    .downloader-direct-link:hover {
        background: var(--surface-hover);
        box-shadow: var(--shadow-featured);
    }

    .downloader-direct-link:hover .download-arrow {
        color: var(--accent);
        translate: 0 2px;
    }

    .downloader-share-btn:hover:not(:disabled) {
        background: var(--surface-hover);
        box-shadow: var(--shadow-border-hover);
    }

    .downloader-history-clear:hover {
        background: var(--surface-hover);
        color: var(--text);
    }

    .downloader-history-item:hover {
        background: var(--surface-hover);
        box-shadow: var(--shadow-border-hover);
    }
}

@media (prefers-reduced-motion: reduce) {
    .command-icon-layer {
        scale: 1 !important;
        filter: none !important;
    }
}
