/* ===== CSS Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== Light Theme (Default) ===== */
:root {
    --color-bg: #f5f5f7;
    --color-primary: #007aff;
    --color-primary-light: #5ac8fa;
    --color-text: #1d1d1f;
    --color-text-secondary: #86868b;
    --color-text-tertiary: rgba(134, 134, 139, 0.6);
    --color-success: #34c759;
    --color-success-light: #30d158;
    --color-error: #ff3b30;
    --color-error-light: #ff453a;
    --glass-bg: rgba(255, 255, 255, 0.55);
    --glass-border: rgba(255, 255, 255, 0.7);
    --glass-highlight: rgba(255, 255, 255, 0.6);
    --shadow-color: rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 40px var(--shadow-color);
    --input-bg: rgba(255, 255, 255, 0.5);
    --input-border: rgba(255, 255, 255, 0.7);
    --tag-bg: rgba(255, 255, 255, 0.5);
    --tag-border: rgba(255, 255, 255, 0.7);
    --reset-bg: rgba(255, 255, 255, 0.3);
    --reset-border: rgba(255, 255, 255, 0.5);
    --clear-bg: rgba(0, 0, 0, 0.06);
    --clear-hover-bg: rgba(0, 0, 0, 0.1);
    --radius-card: 24px;
    --radius-input: 16px;
    --radius-btn: 14px;
    --radius-tag: 100px;
    --transition-smooth: cubic-bezier(0.16, 1, 0.3, 1);
    --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

/* ===== Dark Theme (Manual Override) ===== */
[data-theme="dark"] {
    --color-bg: #0d0d0f;
    --color-primary: #0a84ff;
    --color-primary-light: #5ac8fa;
    --color-text: #f5f5f7;
    --color-text-secondary: #98989d;
    --color-text-tertiary: rgba(152, 152, 157, 0.6);
    --color-success: #30d158;
    --color-success-light: #34c759;
    --color-error: #ff453a;
    --color-error-light: #ff3b30;
    --glass-bg: rgba(30, 30, 32, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.04);
    --shadow-color: rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px var(--shadow-color);
    --input-bg: rgba(30, 30, 32, 0.6);
    --input-border: rgba(255, 255, 255, 0.1);
    --tag-bg: rgba(30, 30, 32, 0.5);
    --tag-border: rgba(255, 255, 255, 0.1);
    --reset-bg: rgba(30, 30, 32, 0.5);
    --reset-border: rgba(255, 255, 255, 0.1);
    --clear-bg: rgba(255, 255, 255, 0.1);
    --clear-hover-bg: rgba(255, 255, 255, 0.18);
}

/* ===== Dark Theme (System Auto) ===== */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) {
        --color-bg: #0d0d0f;
        --color-primary: #0a84ff;
        --color-primary-light: #5ac8fa;
        --color-text: #f5f5f7;
        --color-text-secondary: #98989d;
        --color-text-tertiary: rgba(152, 152, 157, 0.6);
        --color-success: #30d158;
        --color-success-light: #34c759;
        --color-error: #ff453a;
        --color-error-light: #ff3b30;
        --glass-bg: rgba(30, 30, 32, 0.6);
        --glass-border: rgba(255, 255, 255, 0.08);
        --glass-highlight: rgba(255, 255, 255, 0.04);
        --shadow-color: rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 12px 40px var(--shadow-color);
        --input-bg: rgba(30, 30, 32, 0.6);
        --input-border: rgba(255, 255, 255, 0.1);
        --tag-bg: rgba(30, 30, 32, 0.5);
        --tag-border: rgba(255, 255, 255, 0.1);
        --reset-bg: rgba(30, 30, 32, 0.5);
        --reset-border: rgba(255, 255, 255, 0.1);
        --clear-bg: rgba(255, 255, 255, 0.1);
        --clear-hover-bg: rgba(255, 255, 255, 0.18);
    }
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    color: var(--color-text);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    background: var(--color-bg);
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* ===== Theme Toggle Button ===== */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.theme-toggle:hover {
    transform: scale(1.1);
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-toggle .icon-sun {
    display: none;
}

.theme-toggle .icon-moon {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-toggle .icon-sun {
        display: block;
    }
    :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-toggle .icon-moon {
        display: none;
    }
}

/* ===== Ambient Background ===== */
.ambient-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: orbFloat 20s ease-in-out infinite;
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(0, 122, 255, 0.08), transparent 70%);
    top: -10%;
    left: -10%;
    animation-delay: 0s;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(175, 175, 180, 0.1), transparent 70%);
    bottom: -5%;
    right: -10%;
    animation-delay: -7s;
    animation-duration: 25s;
}

.orb-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, rgba(90, 200, 250, 0.06), transparent 70%);
    top: 40%;
    left: 50%;
    animation-delay: -14s;
    animation-duration: 22s;
}

[data-theme="dark"] .orb-1 {
    background: radial-gradient(circle, rgba(10, 132, 255, 0.12), transparent 70%);
    opacity: 0.3;
}

[data-theme="dark"] .orb-2 {
    background: radial-gradient(circle, rgba(120, 120, 140, 0.08), transparent 70%);
    opacity: 0.25;
}

[data-theme="dark"] .orb-3 {
    background: radial-gradient(circle, rgba(90, 200, 250, 0.08), transparent 70%);
    opacity: 0.2;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) .orb-1 {
        background: radial-gradient(circle, rgba(10, 132, 255, 0.12), transparent 70%);
        opacity: 0.3;
    }
    :root:not([data-theme="light"]):not([data-theme="dark"]) .orb-2 {
        background: radial-gradient(circle, rgba(120, 120, 140, 0.08), transparent 70%);
        opacity: 0.25;
    }
    :root:not([data-theme="light"]):not([data-theme="dark"]) .orb-3 {
        background: radial-gradient(circle, rgba(90, 200, 250, 0.08), transparent 70%);
        opacity: 0.2;
    }
}

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -30px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(15px, 15px) scale(1.02); }
}

/* ===== Glass Card ===== */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(24px) saturate(1.3);
    -webkit-backdrop-filter: blur(24px) saturate(1.3);
    border: 1px solid var(--glass-border);
    box-shadow:
        inset 0 1px 1px var(--glass-highlight),
        inset 0 -1px 1px rgba(255, 255, 255, 0.05),
        var(--shadow-lg);
    border-radius: var(--radius-card);
    transition: all 0.4s var(--transition-smooth);
}

/* ===== Main Layout ===== */
.main-container {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    max-width: 680px;
    margin: 0 auto;
}

/* ===== Hero Section ===== */
.hero-section {
    text-align: center;
    margin-bottom: 28px;
    animation: fadeSlideUp 0.7s var(--transition-smooth) both;
}

.logo-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 12px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 0;
    overflow: visible;
}

.logo-icon img.logo-img {
    height: 40px;
    width: auto;
    object-fit: contain;
    display: block;
}

.logo-icon img.logo-dark {
    display: none;
}

[data-theme="dark"] .logo-icon img.logo-light {
    display: none;
}

[data-theme="dark"] .logo-icon img.logo-dark {
    display: block;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) .logo-icon img.logo-light {
        display: none;
    }
    :root:not([data-theme="light"]):not([data-theme="dark"]) .logo-icon img.logo-dark {
        display: block;
    }
}

.title {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
    transition: color 0.3s ease;
}

.subtitle {
    font-size: 15px;
    color: var(--color-text-secondary);
    font-weight: 400;
    margin-bottom: 16px;
    letter-spacing: 0.01em;
    transition: color 0.3s ease;
}

/* ===== Platform Tags ===== */
.platform-tags {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    background: var(--tag-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--tag-border);
    border-radius: var(--radius-tag);
    box-shadow: 0 2px 8px var(--shadow-color);
    transition: all 0.3s ease;
}

.tag:hover {
    background: var(--glass-bg);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.tag-icon {
    opacity: 0.6;
}

/* ===== Input Card ===== */
.input-card {
    width: 100%;
    padding: 32px;
    animation: fadeSlideUp 0.7s var(--transition-smooth) 0.1s both;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: var(--radius-input);
    padding: 14px 16px;
    transition: all 0.3s ease;
}

.input-wrapper:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1), inset 0 1px 2px var(--glass-highlight);
    background: var(--input-bg);
}

.input-icon {
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--color-text-secondary);
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.input-wrapper:focus-within .input-icon {
    opacity: 0.8;
    color: var(--color-primary);
}

.url-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--font-family);
    font-size: 15px;
    line-height: 1.6;
    color: var(--color-text);
    resize: none;
    min-height: 28px;
    max-height: 80px;
}

.url-input::placeholder {
    color: var(--color-text-tertiary);
    font-weight: 400;
}

.clear-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--clear-bg);
    border-radius: 8px;
    color: var(--color-text-secondary);
    cursor: pointer;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s ease;
    pointer-events: none;
}

.clear-btn.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.clear-btn:hover {
    background: var(--clear-hover-bg);
    color: var(--color-text);
}

.clear-btn:active {
    transform: scale(0.9);
}

.input-hint {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 10px;
    font-size: 12px;
    color: var(--color-text-tertiary);
    padding-left: 4px;
}

.input-hint svg {
    flex-shrink: 0;
    opacity: 0.6;
}

/* ===== Parse Button ===== */
.parse-btn {
    width: 100%;
    margin-top: 18px;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-btn);
    background: var(--color-primary);
    color: white;
    font-family: var(--font-family);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 122, 255, 0.25);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.parse-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.15), transparent 60%);
    opacity: 1;
}

.parse-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 122, 255, 0.35);
    background: #0071eb;
}

.parse-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 12px rgba(0, 122, 255, 0.2);
}

.parse-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-text {
    position: relative;
    z-index: 1;
}

.btn-arrow {
    position: relative;
    z-index: 1;
    transition: transform 0.3s ease;
}

.parse-btn:hover:not(:disabled) .btn-arrow {
    transform: translateX(3px);
}

/* Loading state for button */
.btn-loading .btn-text::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* ===== Loading Area ===== */
.loading-area {
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 40px 0;
    animation: fadeSlideUp 0.5s var(--transition-smooth);
}

.loading-area.visible {
    display: flex;
}

/* Loading Dots Animation */
.loading-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    height: 40px;
}

.loading-dots .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-primary);
    animation: dotBounce 1.4s ease-in-out infinite both;
}

.loading-dots .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots .dot:nth-child(2) {
    animation-delay: -0.16s;
}

.loading-dots .dot:nth-child(3) {
    animation-delay: 0s;
}

@keyframes dotBounce {
    0%, 80%, 100% {
        transform: scale(0.4);
        opacity: 0.3;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.loading-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
    transition: color 0.3s ease;
}

.loading-sub {
    font-size: 13px;
    color: var(--color-text-tertiary);
    transition: color 0.3s ease;
}

/* ===== Error Area ===== */
.error-area {
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 32px 0;
    animation: fadeSlideUp 0.5s var(--transition-smooth);
}

.error-area.visible {
    display: flex;
}

.error-icon {
    margin-bottom: 12px;
    animation: fadeSlideUp 0.4s var(--transition-smooth);
}

.error-text {
    font-size: 15px;
    font-weight: 500;
    color: var(--color-error);
    margin-bottom: 16px;
    text-align: center;
}

.retry-btn {
    padding: 10px 28px;
    border: 1.5px solid var(--color-error);
    background: rgba(255, 59, 48, 0.08);
    color: var(--color-error);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.retry-btn:hover {
    background: var(--color-error);
    color: white;
    box-shadow: 0 4px 16px rgba(255, 59, 48, 0.25);
}

.retry-btn:active {
    transform: scale(0.96);
}

/* ===== Result Area ===== */
.result-area {
    display: none;
    width: 100%;
    margin-top: 20px;
    animation: fadeSlideUp 0.6s var(--transition-smooth);
}

.result-area.visible {
    display: block;
}

.result-card {
    padding: 24px;
}

/* ===== Success Tip ===== */
.success-tip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 12px;
}

.success-tip svg {
    animation: scaleIn 0.4s var(--transition-smooth);
}

.success-tip p {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    animation: fadeSlideUp 0.5s var(--transition-smooth) 0.1s both;
    transition: color 0.3s ease;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.6);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ===== Video Info ===== */
.video-info {
    margin-top: 16px;
    padding: 0 4px;
}

.video-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    transition: color 0.3s ease;
}

.video-source {
    font-size: 13px;
    color: var(--color-text-tertiary);
    margin-top: 4px;
    transition: color 0.3s ease;
}

/* ===== Action Buttons ===== */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 18px;
}

.download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 15px 24px;
    border: none;
    border-radius: var(--radius-btn);
    background: linear-gradient(135deg, var(--color-success), var(--color-success-light));
    color: white;
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(16, 185, 129, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.download-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent 50%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(16, 185, 129, 0.4), inset 0 1px 1px rgba(255, 255, 255, 0.25);
}

.download-btn:hover::before {
    opacity: 1;
}

.download-btn:active {
    transform: translateY(0) scale(0.98);
}

.download-btn span {
    position: relative;
    z-index: 1;
}

.download-btn svg {
    position: relative;
    z-index: 1;
}

.download-btn.btn-success {
    background: linear-gradient(135deg, #059669, #10b981);
    pointer-events: none;
}

.reset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 12px 24px;
    border: 1px solid var(--reset-border);
    background: var(--reset-bg);
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-btn);
    cursor: pointer;
    transition: all 0.3s ease;
}

.reset-btn:hover {
    background: var(--glass-bg);
    color: var(--color-text);
    transform: translateY(-1px);
}

.reset-btn:active {
    transform: scale(0.98);
}

/* ===== Shake Animation ===== */
.shake {
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* ===== Footer ===== */
.footer {
    margin-top: 48px;
    text-align: center;
    animation: fadeSlideUp 0.7s var(--transition-smooth) 0.2s both;
}

.footer-line {
    font-size: 13px;
    color: var(--color-text-secondary);
    opacity: 0.5;
    margin-bottom: 4px;
    letter-spacing: 0.05em;
    transition: color 0.3s ease;
}

.footer-hint {
    font-size: 12px;
    color: var(--color-text-tertiary);
    opacity: 0.7;
    transition: color 0.3s ease;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 122, 255, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 122, 255, 0.28);
}

/* ===== Animations ===== */
@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    :root {
        --radius-card: 20px;
        --radius-input: 14px;
    }

    .main-container {
        padding: 24px 16px;
        justify-content: flex-start;
        padding-top: 60px;
        min-height: 100dvh;
    }

    .title {
        font-size: 24px;
    }

    .subtitle {
        font-size: 14px;
    }

    .input-card {
        padding: 24px;
    }

    .theme-toggle {
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
    }

    .orb {
        filter: blur(60px);
    }

    .orb-1 {
        width: 300px;
        height: 300px;
    }

    .orb-2 {
        width: 250px;
        height: 250px;
    }

    .orb-3 {
        width: 200px;
        height: 200px;
    }
}

@media (max-width: 380px) {
    .input-card {
        padding: 20px;
    }

    .tag {
        padding: 5px 12px;
        font-size: 12px;
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
