:root {
    --bg-dark: #090a0f;
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --accent-glow: rgba(139, 92, 246, 0.5); /* Violet glow */
    --accent-color: #8b5cf6;
    --glass-bg: rgba(20, 20, 25, 0.4);
    --glass-border: rgba(255, 255, 255, 0.08);
    --bg-gradient: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
}

[data-theme="light"] {
    --bg-dark: #f8fafc;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.05);
    --bg-gradient: radial-gradient(ellipse at bottom, #e2e8f0 0%, #f1f5f9 100%);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    position: relative;
    background: var(--bg-gradient);
    transition: background 0.4s ease;
}

/* --- Animated Star Background --- */
.stars, .twinkling {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%;
    display: block;
    z-index: -2;
}
.stars {
    background: #000 url('https://raw.githubusercontent.com/manzolo/responsive-stars/master/stars.png') repeat top center;
    transition: opacity 0.4s;
}
[data-theme="light"] .stars, [data-theme="light"] .twinkling { opacity: 0; }
.twinkling {
    background: transparent url('https://raw.githubusercontent.com/manzolo/responsive-stars/master/twinkling.png') repeat top center;
    z-index: -1;
    animation: move-twink-back 200s linear infinite;
}
@keyframes move-twink-back {
    from {background-position: 0 0;}
    to {background-position: -10000px 5000px;}
}

/* --- App Container (Glassmorphism) --- */
.glass-container {
    width: 90%;
    max-width: 480px;
    height: 85vh;
    height: 85dvh;
    background: var(--glass-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    padding: 24px;
    position: relative;
    z-index: 10;
}

.tab-pill {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    padding: 6px;
    margin-bottom: 30px;
    border: 1px solid var(--glass-border);
}
[data-theme="light"] .tab-pill { background: rgba(0,0,0,0.03); }

/* --- Theme Toggle --- */
.theme-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    width: 44px; height: 44px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 100;
    display: flex; justify-content: center; align-items: center;
    backdrop-filter: blur(10px);
    transition: transform 0.2s, background 0.2s;
}
.theme-btn:hover { transform: scale(1.05); }

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 10px 0;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.badge {
    background: var(--accent-color);
    color: white;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 10px;
    position: absolute;
    top: 5px;
    right: 15%;
}

/* --- Views --- */
.view-content {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow-y: auto;
}
.view-content.active-view {
    display: flex;
}
.view-content::-webkit-scrollbar { display: none; }
.hidden { display: none !important; }

/* --- HOME --- */
.header-title {
    text-align: center;
    margin-bottom: 40px;
    margin-top: 20px;
}
.header-title h1 {
    font-size: 3.5rem;
    font-weight: 700;
    letter-spacing: -2px;
    background: linear-gradient(135deg, #fff 0%, #a1a1aa 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}
.header-title p {
    color: var(--text-secondary);
    font-weight: 300;
    font-size: 0.9rem;
    letter-spacing: 1px;
}

.modern-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.input-shell {
    position: relative;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    display: flex;
    align-items: center;
    padding: 0 8px 0 16px;
    transition: box-shadow 0.3s ease, border-color 0.3s;
}
[data-theme="light"] .input-shell { background: rgba(0,0,0,0.03); }
.input-shell:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}

.input-shell svg {
    color: var(--text-secondary);
    margin-right: 12px;
}

.input-shell input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    padding: 20px 8px 20px 0;
    font-family: inherit;
    outline: none;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 36px; height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex; justify-content: center; align-items: center;
    transition: background 0.2s, color 0.2s;
}
.action-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
}
[data-theme="light"] .action-btn:hover { background: rgba(0,0,0,0.05); }

/* --- Progress Bar --- */
.progress-wrapper {
    width: 100%;
    height: 6px;
    background: rgba(0,0,0,0.3);
    border-radius: 10px;
    overflow: hidden;
    margin-top: -10px;
    margin-bottom: 5px;
}
[data-theme="light"] .progress-wrapper { background: rgba(0,0,0,0.1); }
.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-color), #d946ef);
    transition: width 0.3s ease;
}

.btn-glow {
    background: linear-gradient(135deg, var(--accent-color) 0%, #6d28d9 100%);
    color: white;
    border: none;
    padding: 18px;
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 10px 20px var(--accent-glow);
    display: flex;
    justify-content: center;
    align-items: center;
}
.btn-glow:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 25px rgba(139, 92, 246, 0.6);
}
.btn-glow:active { transform: translateY(0); }
.btn-glow:disabled { opacity: 0.7; cursor: not-allowed; }

.full-width { width: 100%; }

.loader {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.status-msg {
    text-align: center;
    font-size: 0.85rem;
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.platforms-supported {
    margin-top: auto;
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    opacity: 0.6;
}
.plat-badge {
    font-size: 0.7rem;
    border: 1px solid var(--text-secondary);
    padding: 4px 12px;
    border-radius: 20px;
    letter-spacing: 0.5px;
}

/* --- HISTORY --- */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.history-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}
.btn-outline-small {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.btn-outline-small:hover { background: rgba(139, 92, 246, 0.1); border-color: var(--accent-color); }

.history-track {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 20px;
}
.history-card {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform 0.2s;
}
[data-theme="light"] .history-card { background: rgba(0,0,0,0.03); }
.history-card:hover { transform: translateY(-2px); }
.history-thumb {
    width: 70px;
    height: 70px;
    border-radius: 10px;
    object-fit: cover;
}
.history-info {
    flex: 1;
    overflow: hidden;
}
.history-info h4 {
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
}
.history-info p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.history-dl {
    background: rgba(255,255,255,0.1);
    color: white;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 500;
}

/* --- MODALS (Glass overlays) --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.glass-modal {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    padding: 30px;
    border-radius: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    position: relative;
    text-align: center;
}

.modal-sub {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 8px 0 24px;
}

.opt-group {
    text-align: left;
    margin-bottom: 20px;
}
.opt-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.radio-neo {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.radio-neo label {
    margin: 0;
    display: flex;
    align-items: center;
    background: rgba(0,0,0,0.3);
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid transparent;
    cursor: pointer;
    color: var(--text-primary);
}
[data-theme="light"] .radio-neo label { background: rgba(0,0,0,0.03); border-color: var(--glass-border); }
.radio-neo input[type="radio"] { margin-right: 12px;  accent-color: var(--accent-color); }
.radio-neo label:has(input:checked) {
    border-color: var(--accent-color);
    background: rgba(139, 92, 246, 0.1);
}

.neo-select {
    width: 100%;
    padding: 14px 16px;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
}
[data-theme="light"] .neo-select { background: rgba(0,0,0,0.03); }
.neo-select option { background: var(--bg-dark); }

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 30px;
}
.btn-text {
    flex: 1;
    background: transparent;
    border: 1px solid var(--glass-border);
    color: white;
    border-radius: 12px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
}
.btn-glow-small {
    flex: 1;
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 14px 0;
    border-radius: 12px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--accent-glow);
}

/* --- RESULT MODAL WITH MEDIA PLAYER --- */
.result-modal {
    padding: 24px;
}
.close-top-right {
    position: absolute;
    top: 16px; right: 16px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: var(--text-primary);
    width: 30px; height: 30px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 10;
}
[data-theme="light"] .close-top-right { background: rgba(0,0,0,0.05); }
.media-container {
    width: 100%;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 20px;
    position: relative;
    /* Aspect ratio fallback */
    min-height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.media-container video {
    width: 100%;
    max-height: 45vh;
    object-fit: contain;
}
.media-container audio {
    width: 90%;
    margin: 40px 0;
}
.media-container img.fallback-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
}
.result-title {
    font-size: 1.1rem;
    line-height: 1.4;
    font-weight: 500;
    margin-bottom: 20px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

/* --- TOAST NOTIFICATIONS --- */
.toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
    pointer-events: none;
}
.toast {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 14px;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    animation: toastIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}
.toast.success { border-left: 4px solid #10b981; }
.toast.error { border-left: 4px solid #f43f5e; }
.toast.info { border-left: 4px solid #3b82f6; }
.toast.hide { animation: toastOut 0.3s ease forwards; }

.toast svg { flex-shrink: 0; }

@keyframes toastIn {
    0% { opacity: 0; transform: translateY(20px) scale(0.9); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(20px) scale(0.9); }
}

/* --- MOBILE PWA ADJUSTMENTS --- */
@media (max-width: 480px) {
    body {
        align-items: flex-start;
    }
    .glass-container {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-width: 100%;
        border-radius: 0;
        border: none;
        box-shadow: none;
        padding: 20px 16px;
    }
    .theme-btn {
        top: 16px;
        right: 16px;
    }
}
