        :root {
            --bg: #0f1117;
            --surface: #1a1d27;
            --surface-2: #242836;
            --border: #2e3345;
            --text: #eef0f6;
            --text-muted: #9aa3b5;
            --primary: #6366f1;
            --primary-hover: #818cf8;
            --success: #22c55e;
            --danger: #ef4444;
            --warning: #f59e0b;
            --shadow: 0 8px 32px rgba(0,0,0,.35);
            --radius: 14px;
            --transition: .2s ease;
        }

        [data-theme="light"] {
            --bg: #f0f2f8;
            --surface: #ffffff;
            --surface-2: #f7f8fc;
            --border: #e2e6ef;
            --text: #1a1d27;
            --text-muted: #647089;
            --shadow: 0 8px 32px rgba(15,17,23,.08);
        }

        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

        body {
            font-family: 'Tajawal', sans-serif;
            background: var(--bg);
            color: var(--text);
            min-height: 100vh;
            line-height: 1.6;
            transition: background var(--transition), color var(--transition);
            overflow-x: hidden;
        }

        .page-bg {
            position: fixed;
            inset: 0;
            background:
                radial-gradient(ellipse 80% 60% at 50% -10%, rgba(99,102,241,.18), transparent),
                radial-gradient(ellipse 50% 40% at 100% 100%, rgba(139,92,246,.1), transparent);
            pointer-events: none;
            z-index: 0;
        }

        .container {
            position: relative;
            z-index: 1;
            max-width: 820px;
            margin: 0 auto;
            padding: 24px 16px 48px;
        }

        header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 32px;
            gap: 12px;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .logo-icon {
            width: 50px;
            height: 50px;
            flex: 0 0 50px;
        }

        .logo h1 {
            font-size: 1.35rem;
            font-weight: 800;
            line-height: 1.2;
        }

        .logo p {
            font-size: .75rem;
            color: var(--text-muted);
        }

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

        .language-switcher { display: flex; align-items: center; gap: 7px; color: var(--text-muted); font-size: .78rem; }
        .language-switcher select { min-height: 40px; padding: 0 28px 0 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; outline: none; }
        .language-switcher select:hover, .language-switcher select:focus { border-color: var(--primary); }
        html[dir="ltr"] .language-switcher select { padding: 0 10px 0 28px; }

        .icon-btn {
            width: 40px;
            height: 40px;
            border: 1px solid var(--border);
            background: var(--surface);
            color: var(--text);
            border-radius: 10px;
            cursor: pointer;
            display: grid;
            place-items: center;
            font-size: 1.1rem;
            transition: all var(--transition);
        }

        .icon-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }
        .icon-btn:active:not(:disabled) { transform: translateY(0) scale(.96); }
        .icon-btn:disabled { opacity: .5; cursor: not-allowed; }

        .card {
            background: var(--surface);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 24px;
            box-shadow: var(--shadow);
            margin-bottom: 20px;
        }

        .input-group {
            display: flex;
            gap: 8px;
            margin-bottom: 12px;
        }

        .input-wrap {
            position: relative;
            flex: 1;
        }

        .input-link-icon {
            position: absolute;
            top: 50%;
            right: 17px;
            width: 20px;
            height: 20px;
            color: var(--text-muted);
            transform: translateY(-50%);
            pointer-events: none;
            transition: color var(--transition), transform var(--transition);
        }

        html[dir="ltr"] .input-link-icon { right: auto; left: 17px; }

        .url-input {
            flex: 1;
            width: 100%;
            padding: 15px 48px 15px 16px;
            border: 1px solid var(--border);
            border-radius: 12px;
            background: var(--surface-2);
            color: var(--text);
            font-family: inherit;
            font-size: .95rem;
            outline: none;
            transition: border-color var(--transition), box-shadow var(--transition), background var(--transition), transform var(--transition);
            direction: ltr;
            text-align: left;
        }

        .url-input:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); }
        .url-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,.16); background: var(--surface); }
        .input-wrap:focus-within .input-link-icon { color: var(--primary-hover); transform: translateY(-50%) scale(1.08); }
        .url-input::placeholder { color: var(--text-muted); }

        .btn {
            padding: 14px 20px;
            border: none;
            border-radius: 10px;
            font-family: inherit;
            font-size: .95rem;
            font-weight: 700;
            cursor: pointer;
            transition: all var(--transition);
            white-space: nowrap;
        }

        .btn-primary {
            background: linear-gradient(135deg, var(--primary), #8b5cf6);
            color: #fff;
            width: 100%;
        }

        .btn-primary { box-shadow: 0 10px 24px rgba(99,102,241,.25); }
        .btn-primary:hover:not(:disabled) { opacity: 1; transform: translateY(-2px); box-shadow: 0 14px 28px rgba(99,102,241,.38); }
        .btn-primary:active:not(:disabled) { transform: translateY(0) scale(.985); box-shadow: 0 5px 14px rgba(99,102,241,.28); }
        .btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

        #analyzeBtn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            min-height: 50px;
            transition: transform .22s ease, box-shadow .22s ease, filter .22s ease;
        }

        .btn-icon {
            width: 18px;
            height: 18px;
            flex: 0 0 18px;
            transition: transform .22s ease;
        }

        #analyzeBtn:hover:not(:disabled) .btn-icon { transform: scale(1.08) rotate(-8deg); }
        #analyzeBtn:active:not(:disabled) .btn-icon { transform: scale(.94); }
        #analyzeBtn.is-loading .btn-icon { display: none; }

        .btn.is-loading::before { content: ''; display: inline-block; width: 16px; height: 16px; margin-inline-end: 8px; vertical-align: -3px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }

        .btn-secondary {
            background: var(--surface-2);
            color: var(--text);
            border: 1px solid var(--border);
        }

        .btn-secondary:hover:not(:disabled) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 9%, var(--surface-2)); transform: translateY(-1px); }
        .btn-secondary:active:not(:disabled) { transform: translateY(0) scale(.985); }
        .btn-secondary:disabled { opacity: .5; cursor: not-allowed; }

        .btn-download {
            background: var(--success);
            color: #fff;
            width: 100%;
            margin-top: 16px;
        }

        .btn-download:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 10px 22px rgba(34,197,94,.22); }
        .btn-download:active:not(:disabled) { transform: translateY(0) scale(.985); }
        .btn-download:disabled { opacity: .5; cursor: not-allowed; }

        .alert {
            padding: 12px 16px;
            border-radius: 10px;
            font-size: .9rem;
            margin-bottom: 16px;
            display: none;
        }

        .alert.show { display: block; }
        .alert-error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }
        .alert-warning { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); color: #fcd34d; }
        [data-theme="light"] .alert-error { color: #b91c1c; }
        [data-theme="light"] .alert-warning { color: #92400e; }

        .loader-overlay {
            display: none;
            text-align: center;
            padding: 40px 20px;
        }

        .loader-overlay.show { display: block; }

        .spinner {
            width: 48px;
            height: 48px;
            border: 3px solid var(--border);
            border-top-color: var(--primary);
            border-radius: 50%;
            animation: spin .8s linear infinite;
            margin: 0 auto 16px;
        }

        @keyframes spin { to { transform: rotate(360deg); } }

        .loader-text { color: var(--text-muted); font-size: .95rem; }

        .progress-bar-wrap {
            display: none;
            margin-top: 16px;
        }

        .progress-bar-wrap.show { display: block; }

        .progress-bar {
            height: 6px;
            background: var(--surface-2);
            border-radius: 999px;
            overflow: hidden;
        }

        .progress-bar-fill {
            height: 100%;
            background: linear-gradient(90deg, var(--primary), #8b5cf6);
            border-radius: 999px;
            width: 0%;
            transition: width .3s ease;
            animation: pulse-progress 1.5s ease infinite;
        }

        @keyframes pulse-progress {
            0%, 100% { opacity: 1; }
            50% { opacity: .6; }
        }

        .progress-label {
            font-size: .82rem;
            color: var(--text-muted);
            margin-top: 8px;
            text-align: center;
        }

        #result { display: none; }
        #result.show { display: block; }
        #result.playlist-format-result .media-preview { display: none; }

        #playlistResult { display: none; }
        #playlistResult.show { display: block; }
        .playlist-header { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
        .playlist-thumb { width: 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
        .playlist-actions, .playlist-selection-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
        .playlist-selection-actions { align-items: center; }
        .playlist-selection-actions.hidden { display: none; }
        .playlist-count { color: var(--text-muted); font-size: .82rem; }
        .playlist-items { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; max-height: 320px; overflow-y: auto; }
        .playlist-items.hidden { display: none; }
        .playlist-item { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
        .playlist-item.unavailable { opacity: .55; }
        .playlist-item img { width: 72px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
        .playlist-item-info { flex: 1; min-width: 0; }
        .playlist-item-title { font-size: .86rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .playlist-item-meta { color: var(--text-muted); font-size: .75rem; margin-top: 2px; }

        .media-preview {
            display: grid;
            grid-template-columns: 160px 1fr;
            gap: 20px;
            margin-bottom: 20px;
        }

        .thumbnail-wrap {
            position: relative;
            border-radius: 10px;
            overflow: hidden;
            aspect-ratio: 16/9;
            background: var(--surface-2);
        }

        .thumbnail-wrap img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .duration-badge {
            position: absolute;
            bottom: 6px;
            left: 6px;
            background: rgba(0,0,0,.75);
            color: #fff;
            font-size: .72rem;
            padding: 2px 6px;
            border-radius: 4px;
        }

        .media-info h2 {
            font-size: 1.05rem;
            font-weight: 700;
            margin-bottom: 8px;
            line-height: 1.4;
        }

        .meta-row {
            display: flex;
            flex-wrap: wrap;
            gap: 12px;
            font-size: .85rem;
            color: var(--text-muted);
        }

        .meta-item { display: flex; align-items: center; gap: 4px; }

        .type-tabs {
            display: flex;
            gap: 8px;
            margin-bottom: 16px;
        }

        .type-tab {
            flex: 1;
            padding: 10px;
            border: 1px solid var(--border);
            border-radius: 10px;
            background: var(--surface-2);
            color: var(--text-muted);
            font-family: inherit;
            font-size: .9rem;
            font-weight: 600;
            cursor: pointer;
            transition: all var(--transition);
        }

        .type-tab.active {
            border-color: var(--primary);
            background: rgba(99,102,241,.12);
            color: var(--primary);
        }

        .formats-list {
            display: flex;
            flex-direction: column;
            gap: 8px;
            max-height: 280px;
            overflow-y: auto;
        }

        .format-group { display: flex; flex-direction: column; gap: 8px; }
        .format-group + .format-group { margin-top: 8px; }
        .format-group-title { color: var(--text-muted); font-size: .76rem; font-weight: 700; }

        .format-option {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 12px 14px;
            border: 1px solid var(--border);
            border-radius: 10px;
            cursor: pointer;
            transition: all var(--transition);
        }

        .format-option:hover { border-color: var(--primary); }
        .format-option.selected {
            border-color: var(--primary);
            background: rgba(99,102,241,.1);
        }

        .format-option input { accent-color: var(--primary); }

        .format-details { flex: 1; min-width: 0; }
        .format-label { display: block; font-weight: 600; font-size: .9rem; }
        .format-meta { display: block; font-size: .75rem; color: var(--text-muted); margin-top: 2px; }

        .history-section h3 {
            font-size: 1rem;
            margin-bottom: 12px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .history-clear {
            font-size: .78rem;
            color: var(--text-muted);
            background: none;
            border: none;
            cursor: pointer;
            font-family: inherit;
        }


        .history-list {
            display: flex;
            flex-direction: column;
            gap: 8px;
            max-height: 240px;
            overflow-y: auto;
        }

        .history-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 12px;
            background: var(--surface-2);
            border-radius: 10px;
            border: 1px solid var(--border);
            cursor: pointer;
            transition: border-color var(--transition);
        }

        .history-item:hover { border-color: var(--primary); }

        .history-item img {
            width: 48px;
            height: 36px;
            object-fit: cover;
            border-radius: 6px;
            flex-shrink: 0;
        }

        .history-item-info { flex: 1; min-width: 0; }
        .history-item-title {
            font-size: .82rem;
            font-weight: 600;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .history-item-date { font-size: .72rem; color: var(--text-muted); }

        .history-empty {
            text-align: center;
            color: var(--text-muted);
            font-size: .85rem;
            padding: 20px;
        }

        .page-layout { position: relative; z-index: 1; display: grid; grid-template-columns: 160px minmax(0, 820px) 160px; gap: clamp(20px, 3vw, 44px); justify-content: center; max-width: 1260px; margin: 0 auto; padding: 0 16px; }
        .container { width: 100%; max-width: none; margin: 0; padding: 28px 0 36px; }
        .side-ads { display: flex; flex-direction: column; gap: 20px; padding-top: 112px; }
        .ad-slot { display: grid; place-items: center; border: 1px dashed color-mix(in srgb, var(--border) 80%, var(--primary)); border-radius: 14px; color: var(--text-muted); background: color-mix(in srgb, var(--surface) 72%, transparent); font-size: .72rem; letter-spacing: .03em; }
        .ad-slot--side { width: 160px; min-height: 600px; }
        .ad-slot--banner { width: min(100%, 728px); min-height: 90px; margin: 4px auto 24px; }
        .hero-copy { margin-bottom: 24px; }
        .hero-copy h2 { font-size: clamp(1.3rem, 3vw, 1.7rem); line-height: 1.35; margin-bottom: 7px; }
        .hero-copy p { color: var(--text-muted); font-size: .94rem; }
        .card { border-radius: 18px; padding: clamp(18px, 3vw, 28px); box-shadow: 0 14px 36px rgba(0,0,0,.28); }
        .media-preview { align-items: center; }
        .thumbnail-wrap { border-radius: 14px; box-shadow: 0 8px 22px rgba(0,0,0,.24); }
        .type-tabs { padding: 5px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); }
        .type-tab { border-color: transparent; }
        .type-tab.active { background: rgba(99,102,241,.18); box-shadow: inset 0 0 0 1px rgba(129,140,248,.38); }
        .format-option { border-radius: 12px; padding: 14px 16px; }
        .format-option:hover { background: color-mix(in srgb, var(--primary) 6%, var(--surface-2)); transform: translateX(-2px); }
        html[dir="ltr"] .format-option:hover { transform: translateX(2px); }
        .history-section { margin-top: 4px; }
        .history-list { gap: 10px; max-height: 360px; }
        .history-item { gap: 13px; padding: 12px; border-radius: 14px; cursor: pointer; }
        .history-item:hover { background: color-mix(in srgb, var(--primary) 7%, var(--surface-2)); transform: translateY(-1px); box-shadow: 0 7px 16px rgba(0,0,0,.13); }
        .history-item img, .history-fallback { width: 72px; height: 48px; border-radius: 8px; flex-shrink: 0; background: var(--surface); object-fit: cover; }
        .history-item-title { font-size: .9rem; }
        .history-meta { display: flex; flex-wrap: wrap; gap: 5px 8px; margin-top: 5px; color: var(--text-muted); font-size: .73rem; }
        .history-meta span { white-space: nowrap; }
        .history-open { width: 34px; height: 34px; display: grid; place-items: center; flex-shrink: 0; border: 1px solid var(--border); border-radius: 9px; color: var(--primary-hover); }
        .history-clear:focus-visible, .history-clear:hover { color: var(--danger); text-decoration: underline; }
        .history-clear:active { transform: scale(.97); }
        .type-tab:hover:not(:disabled) { color: var(--text); background: rgba(99,102,241,.08); }
        .type-tab:active:not(:disabled) { transform: scale(.98); }
        .type-tab:disabled { opacity: .5; cursor: not-allowed; }
        footer { margin-top: 22px; padding: 22px 4px 4px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: .8rem; }
        .footer-inner { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
        .footer-brand-block { display: grid; gap: 3px; }
        .footer-brand { width: 138px; height: auto; flex-shrink: 0; }
        .footer-name { color: var(--text); font-size: .88rem; font-weight: 700; }
        .footer-copyright, .footer-tagline { font-size: .78rem; line-height: 1.5; }
        .footer-links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 18px; padding-top: 3px; }
        .footer-links a { color: var(--text-muted); text-decoration: none; transition: color var(--transition); }
        .footer-links a:hover, .footer-links a:focus-visible { color: var(--primary-hover); }
        button:focus-visible, input:focus-visible, a:focus-visible, label:has(input:focus-visible) { outline: 3px solid rgba(129,140,248,.65); outline-offset: 3px; }
        .legal-page { display: none; max-width: 820px; margin: 0 auto 28px; }
        .legal-page.show { display: block; }
        .legal-hero { margin-bottom: 20px; }
        .legal-hero h1 { font-size: clamp(1.55rem, 4vw, 2.15rem); line-height: 1.25; margin-bottom: 8px; }
        .legal-hero p { color: var(--text-muted); }
        .legal-content { display: grid; gap: 14px; }
        .legal-content section { padding: 20px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface); box-shadow: 0 10px 25px rgba(0,0,0,.16); }
        .legal-content h2 { font-size: 1.05rem; margin-bottom: 8px; }
        .legal-content p { color: var(--text-muted); font-size: .93rem; }
        .legal-back { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 20px; color: var(--primary-hover); text-decoration: none; font-weight: 700; }
        .contact-form { display: grid; gap: 14px; }
        .form-field { display: grid; gap: 7px; }
        .form-field label { font-size: .9rem; font-weight: 700; }
        .form-field input, .form-field textarea { width: 100%; padding: 13px 14px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); color: var(--text); font: inherit; transition: border-color var(--transition), box-shadow var(--transition); }
        .form-field textarea { min-height: 132px; resize: vertical; }
        .form-field input:focus, .form-field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,.16); outline: none; }
        .contact-notice { display: none; padding: 12px 14px; border: 1px solid rgba(129,140,248,.32); border-radius: 10px; background: rgba(99,102,241,.12); color: var(--primary-hover); font-size: .88rem; }
        .contact-notice.show { display: block; }

        @media (max-width: 1160px) { .page-layout { width: 100%; min-width: 0; grid-template-columns: minmax(0, 1fr); max-width: 852px; } .container { min-width: 0; } .side-ads { display: none; } }
        @media (max-width: 600px) {
            .page-layout { display: block; width: 100vw; max-width: 100vw; min-width: 0; padding-inline: 16px; }
            .container { width: 100%; max-width: 100%; min-width: 0; }
            .card, .ad-slot--banner, footer { max-width: 100%; }
            .container { padding-top: 18px; padding-bottom: 28px; }
            header { margin-bottom: 22px; }
            .logo { gap: 10px; }
            .logo-icon { width: 52px; height: 52px; flex-basis: 52px; }
            .logo h1 { font-size: 1.22rem; }
            .language-switcher > span { display: none; }
            .input-group { gap: 10px; }
            .btn-secondary { min-height: 48px; }
            .media-preview { gap: 14px; }
            .playlist-header { align-items: flex-start; gap: 12px; }
            .playlist-actions, .playlist-selection-actions { display: grid; grid-template-columns: 1fr; }
            .history-item { align-items: flex-start; }
            .history-open { margin-top: 5px; }
            .footer-inner { align-items: flex-start; flex-direction: column; gap: 18px; }
            .footer-brand { width: 130px; }
            .footer-links { justify-content: flex-start; padding-top: 0; }
            .legal-content section { padding: 17px; }
            .media-preview { grid-template-columns: 1fr; }
            .thumbnail-wrap { max-width: 100%; }
            .input-group { flex-direction: column; }
        }
