/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #111128;
    --bg-card: rgba(20, 20, 50, 0.6);
    --bg-card-hover: rgba(30, 30, 70, 0.7);
    --border-card: rgba(99, 102, 241, 0.15);
    --border-focus: rgba(139, 92, 246, 0.5);
    --text-primary: #f1f0ff;
    --text-secondary: #a5a3c7;
    --text-muted: #6b6999;
    --accent-1: #6366f1;
    --accent-2: #a855f7;
    --accent-3: #38bdf8;
    --gradient-main: linear-gradient(135deg, #6366f1, #a855f7, #38bdf8);
    --gradient-card: linear-gradient(145deg, rgba(99,102,241,0.08), rgba(168,85,247,0.05));
    --shadow-lg: 0 20px 60px rgba(0,0,0,0.4), 0 0 40px rgba(99,102,241,0.08);
    --shadow-glow: 0 0 30px rgba(99,102,241,0.2);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --font-en: 'Inter', -apple-system, sans-serif;
    --font-ar: 'Noto Kufi Arabic', 'Segoe UI', sans-serif;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-en);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

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

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.25;
    animation: blobFloat 20s ease-in-out infinite;
}
.blob-1 { width: 500px; height: 500px; background: var(--accent-1); top: -10%; left: -5%; animation-delay: 0s; }
.blob-2 { width: 400px; height: 400px; background: var(--accent-2); top: 40%; right: -8%; animation-delay: -7s; }
.blob-3 { width: 350px; height: 350px; background: var(--accent-3); bottom: -5%; left: 30%; animation-delay: -14s; }

@keyframes blobFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(40px, -30px) scale(1.05); }
    66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* ===== HEADER ===== */
header {
    position: sticky; top: 0; z-index: 100;
    background: rgba(10, 10, 26, 0.8);
    backdrop-filter: blur(20px) saturate(1.5);
    border-bottom: 1px solid var(--border-card);
}

.header-inner {
    max-width: 900px; margin: 0 auto;
    padding: 14px 24px;
    display: flex; align-items: center; justify-content: space-between;
}

.logo { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.logo-icon { display: flex; }
.logo-text {
    font-size: 1.35rem; font-weight: 700;
    background: var(--gradient-main); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-badge {
    font-size: 0.8rem; font-weight: 500;
    padding: 5px 14px;
    border-radius: 20px;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--accent-3);
}

/* ===== MAIN ===== */
main {
    position: relative; z-index: 1;
    max-width: 900px; margin: 0 auto;
    padding: 0 24px 60px;
}

/* ===== HERO ===== */
.hero {
    text-align: center;
    padding: 60px 0 40px;
}

.hero-title {
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 14px;
    letter-spacing: -0.02em;
}

.gradient-text {
    background: var(--gradient-main);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    color: var(--text-secondary);
    font-size: 1.05rem;
    max-width: 500px; margin: 0 auto 36px;
}

/* ===== SEARCH ===== */
.search-container { position: relative; max-width: 600px; margin: 0 auto; }

.search-box {
    display: flex; align-items: center; gap: 12px;
    background: var(--bg-card);
    border: 1.5px solid var(--border-card);
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    transition: var(--transition);
    backdrop-filter: blur(12px);
}
.search-box:focus-within {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
    background: rgba(25, 25, 60, 0.7);
}

.search-icon { color: var(--text-muted); flex-shrink: 0; }

#search-input {
    flex: 1; border: none; background: transparent;
    font-family: var(--font-en);
    font-size: 1.05rem; color: var(--text-primary);
    outline: none;
}
#search-input::placeholder { color: var(--text-muted); }

.clear-btn {
    background: rgba(255,255,255,0.06); border: none;
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary); cursor: pointer;
    transition: var(--transition);
}
.clear-btn:hover { background: rgba(255,255,255,0.12); color: var(--text-primary); }

/* Autocomplete */
.autocomplete-dropdown {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    background: rgba(18, 18, 48, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-md);
    max-height: 320px; overflow-y: auto;
    display: none; z-index: 50;
    box-shadow: var(--shadow-lg);
}
.autocomplete-dropdown.active { display: block; }

.ac-item {
    padding: 12px 20px;
    cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    transition: var(--transition);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.selected {
    background: rgba(99, 102, 241, 0.1);
}
.ac-item-word { font-weight: 600; color: var(--text-primary); }
.ac-item-arabic { font-family: var(--font-ar); color: var(--accent-3); font-size: 0.95rem; }

/* ===== RESULT CARD ===== */
.results-section {
    animation: fadeUp 0.5s ease-out;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-card, .video-card {
    background: var(--gradient-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 24px;
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-lg);
}

.word-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.word-main { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }

.word-title {
    font-size: 2.2rem; font-weight: 800;
    background: var(--gradient-main);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

.word-pos {
    font-size: 0.82rem; font-weight: 500;
    padding: 3px 12px;
    border-radius: 20px;
    background: rgba(168, 85, 247, 0.12);
    border: 1px solid rgba(168, 85, 247, 0.25);
    color: var(--accent-2);
    text-transform: lowercase;
}

.speak-btn {
    width: 46px; height: 46px;
    border-radius: 50%; border: 1.5px solid var(--border-card);
    background: rgba(99,102,241,0.08);
    color: var(--accent-1);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: var(--transition);
}
.speak-btn:hover {
    background: rgba(99,102,241,0.2);
    border-color: var(--accent-1);
    transform: scale(1.08);
    box-shadow: 0 0 20px rgba(99,102,241,0.3);
}

.section-label {
    font-size: 0.75rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: flex; align-items: center; gap: 8px;
}

.definition-block, .translation-block, .example-block { margin-bottom: 24px; }
.definition-block:last-child, .translation-block:last-child, .example-block:last-child { margin-bottom: 0; }

.definition-text {
    font-size: 1.1rem; line-height: 1.7;
    color: var(--text-primary);
}

.arabic-text {
    font-family: var(--font-ar);
    font-size: 1.5rem; font-weight: 600;
    color: var(--accent-3);
    line-height: 1.8;
}

.example-text {
    font-size: 1rem; color: var(--text-secondary);
    font-style: italic;
    padding-left: 16px;
    border-left: 3px solid var(--accent-2);
}

/* ===== VIDEO CARD ===== */
.video-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap; gap: 12px;
}

.video-nav { display: flex; align-items: center; gap: 10px; }

.nav-btn {
    width: 36px; height: 36px; border-radius: 50%;
    border: 1px solid var(--border-card);
    background: rgba(255,255,255,0.04);
    color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: var(--transition);
}
.nav-btn:hover { background: rgba(99,102,241,0.15); color: var(--text-primary); border-color: var(--accent-1); }

.video-counter { font-size: 0.85rem; color: var(--text-secondary); min-width: 60px; text-align: center; }

.video-container {
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
    min-height: 340px;
    display: flex; align-items: center; justify-content: center;
}

#youglish-widget { width: 100%; }

/* ===== BROWSE SECTION ===== */
.browse-section {
    margin-top: 50px;
    padding-top: 40px;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.browse-title {
    font-size: 1.4rem; font-weight: 700;
    margin-bottom: 20px; text-align: center;
    color: var(--text-secondary);
}

.letter-grid {
    display: flex; flex-wrap: wrap; gap: 8px;
    justify-content: center;
    margin-bottom: 30px;
}

.letter-btn {
    width: 42px; height: 42px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-card);
    background: rgba(255,255,255,0.03);
    color: var(--text-secondary);
    font-family: var(--font-en);
    font-size: 0.95rem; font-weight: 600;
    cursor: pointer; transition: var(--transition);
    display: flex; align-items: center; justify-content: center;
}
.letter-btn:hover, .letter-btn.active {
    background: rgba(99,102,241,0.15);
    border-color: var(--accent-1);
    color: var(--text-primary);
    box-shadow: 0 0 15px rgba(99,102,241,0.15);
}
.letter-btn.disabled {
    opacity: 0.3; cursor: default;
    pointer-events: none;
}

.word-list-title {
    font-size: 1.1rem; font-weight: 600;
    color: var(--text-secondary); margin-bottom: 16px;
    padding-left: 4px;
}

.word-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}

.wl-item {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.04);
    cursor: pointer; transition: var(--transition);
    display: flex; justify-content: space-between; align-items: center;
}
.wl-item:hover {
    background: rgba(99,102,241,0.1);
    border-color: var(--accent-1);
}
.wl-item-word { font-weight: 500; font-size: 0.95rem; }
.wl-item-arabic { font-family: var(--font-ar); font-size: 0.85rem; color: var(--accent-3); }

/* ===== FOOTER ===== */
footer {
    position: relative; z-index: 1;
    text-align: center;
    padding: 30px 24px;
    color: var(--text-muted);
    font-size: 0.82rem;
    border-top: 1px solid rgba(255,255,255,0.04);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(99,102,241,0.5); }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
    .hero { padding: 40px 0 30px; }
    .hero-title { font-size: 1.6rem; }
    .result-card, .video-card { padding: 22px 18px; }
    .word-title { font-size: 1.7rem; }
    .arabic-text { font-size: 1.25rem; }
    .word-list { grid-template-columns: 1fr; }
    .letter-btn { width: 36px; height: 36px; font-size: 0.85rem; }
}

/* ===== LOADING SPINNER ===== */
.loading-spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(99,102,241,0.2);
    border-top-color: var(--accent-1);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* highlight match */
.highlight {
    background: rgba(99,102,241,0.25);
    border-radius: 3px;
    padding: 0 2px;
}
