:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --card-border: rgba(255, 255, 255, 0.05);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #ec4899;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --tag-bg: rgba(99, 102, 241, 0.1);
    --tag-color: #818cf8;
    --bangla-bg: rgba(236, 72, 153, 0.1);
    --bangla-color: #f472b6;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    background-image: radial-gradient(circle at top right, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
        radial-gradient(circle at bottom left, rgba(236, 72, 153, 0.1) 0%, transparent 40%);
    background-attachment: fixed;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header & Controls */
.header {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin-bottom: 3rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.logo h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.controls-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    background: rgba(30, 41, 59, 0.5);
    padding: 1rem;
    border-radius: 16px;
    border: 1px solid var(--card-border);
    backdrop-filter: blur(10px);
}

.search-bar {
    position: relative;
    flex: 1;
    min-width: 300px;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

#searchInput {
    width: 100%;
    padding: 0.875rem 1rem 0.875rem 3rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(15, 23, 42, 0.6);
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

#searchInput:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.filter-tabs {
    display: flex;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 12px;
    padding: 0.35rem;
    gap: 0.35rem;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

/* Word Grid */
.results-info {
    margin-bottom: 1.5rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

#showingCount {
    color: white;
    font-weight: 600;
}

.word-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

/* Card Flip */
.flip-container {
    cursor: pointer;
    height: 100%;
}

/* When flipped: front content stays in DOM to hold height but becomes invisible */
.flip-container .card-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    transition: opacity 0.2s ease;
}

.flip-container .card-back-face {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    pointer-events: none;
}

.flip-container.flipped .card-content {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.flip-container.flipped .card-back-face {
    display: flex;
}




.word-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 1.5rem;
    transition: box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    height: 100%;
}

.word-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(to bottom, var(--primary), var(--accent));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.word-card:hover {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
    border-color: rgba(99, 102, 241, 0.3);
}

.word-card:hover::before {
    opacity: 1;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

/* Used by the card markup in `script.js` */
.card-header-word {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
    min-width: 0;
}

.card-header-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.word-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: white;
    text-transform: capitalize;
    margin-bottom: 0.25rem;
}

.word-category {
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    background: var(--tag-bg);
    color: var(--tag-color);
    font-weight: 600;
}

.word-meaning {
    font-size: 1.05rem;
    color: var(--text-main);
    line-height: 1.5;
    margin-bottom: 1rem;
}

.word-bangla {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    background: var(--bangla-bg);
    color: var(--bangla-color);
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(236, 72, 153, 0.2);
}

.mnemonics-section {
    margin-top: auto;
    background: rgba(15, 23, 42, 0.4);
    border-radius: 12px;
    padding: 1rem;
    max-height: 160px;
    overflow-y: auto;
}

.mnemonics-section::-webkit-scrollbar {
    width: 6px;
}

.mnemonics-section::-webkit-scrollbar-track {
    background: transparent;
}

.mnemonics-section::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 10px;
}

.mnemonics-section::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.5);
}

.mnemonics-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.mnemonic-item {
    font-size: 0.95rem;
    color: #cbd5e1;
    line-height: 1.5;
    margin-bottom: 0.5rem;
    padding-left: 1rem;
    position: relative;
}

.mnemonic-item::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--primary);
}

.mnemonic-item:last-child {
    margin-bottom: 0;
}

/* Pagination */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin-top: 2rem;
    padding: 1rem;
}

.page-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: white;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.page-btn:hover:not(:disabled) {
    background: var(--primary);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    font-weight: 500;
    color: var(--text-muted);
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5rem 0;
    gap: 1.5rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Footer Section */
.footer-section {
    margin-top: 4rem;
    padding: 2.5rem 0;
    border-top: 1px solid var(--card-border);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.96rem;
}

.footer-section strong {
    color: var(--text-main);
}

.footer-links {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
}

.github-link {
    color: var(--text-main);
    text-decoration: none;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.github-link:hover {
    color: var(--accent);
}

/* ------------------------------------------
   Mobile/Tablet (desktop styles untouched)
------------------------------------------- */

/* Tablet and below */
@media (max-width: 768px) {
    .app-container {
        padding: 1rem;
    }

    .header {
        margin-bottom: 2rem;
        gap: 1.25rem;
    }

    .logo h1 {
        font-size: 1.75rem;
    }

    .controls-container {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        padding: 0.9rem;
    }

    .results-info {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        flex-wrap: wrap;
    }

    .search-bar {
        min-width: 0;
    }

    #searchInput {
        font-size: 1rem;
    }

    /* Tabs become scrollable instead of wrapping awkwardly */
    .filter-tabs {
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .filter-tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        white-space: nowrap;
        padding: 0.55rem 1rem;
        font-size: 0.92rem;
    }

    .word-grid {
        grid-template-columns: 1fr;
    }

    .word-card {
        padding: 1.25rem;
    }

    .word-title {
        font-size: 1.55rem;
    }

    .pagination-container {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
        padding: 0.5rem 0;
    }

    .page-btn {
        width: 100%;
        max-width: 320px;
        justify-content: center;
    }
}

/* Phones (keep this LAST so it wins the cascade) */
@media (max-width: 480px) {
    body {
        overflow-x: hidden;
    }

    /* Avoid any child forcing horizontal overflow */
    .app-container,
    .controls-container,
    .word-grid,
    .flip-container,
    .word-card {
        min-width: 0;
        max-width: 100%;
    }

    .app-container {
        padding: 1rem;
    }

    /* Top block: prevent overlap and keep centered */
    .controls-container {
        width: 100%;
        max-width: 420px;
        margin: 0 auto;
        gap: 1rem;
    }

    .search-bar {
        min-width: 0;
        width: 100%;
    }

    #searchInput {
        width: 100%;
    }

    /* --- FIX 1: TABS IN TWO LINES --- */
    .filter-tabs {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        /* Allows tabs to wrap to a second line */
        gap: 8px;
        /* Adds spacing between the tabs */
        justify-content: center;
        /* Centers the tabs nicely */
    }

    /* Optional: helps them distribute evenly on two lines */
    .filter-tabs>* {
        flex: 1 1 calc(50% - 10px);
        /* Makes them act roughly like a 2x2 grid */
        text-align: center;
        white-space: nowrap;
        /* Prevents text inside the tab from breaking */
    }

    /* -------------------------------- */

    .results-info {
        width: 100%;
        max-width: 420px;
        margin: 0 auto 1.25rem;
    }

    /* Cards: equal left/right space, no cut off */
    .word-grid {
        width: 100%;
        max-width: 420px;
        margin: 0 auto 3rem;
    }

    .word-card {
        width: 100%;
    }

    /* Long text should wrap instead of pushing layout */
    .word-title,
    .word-meaning,
    .word-bangla,
    .mnemonic-item {
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    /* --- FIX 2: PAGINATION ON ONE LINE --- */
    .pagination-container {
        width: 100%;
        max-width: 420px;
        margin: 0 auto 1.5rem;
        display: flex !important;
        flex-direction: row !important;
        /* Forces items into one line */
        justify-content: center !important;
        /* Centers them together */
        align-items: center !important;
        /* Aligns them vertically */
        gap: 15px;
        /* Adds space between Prev, Page Text, and Next */
    }

    /* Prevents the buttons/text from forcing themselves full width */
    .pagination-container button,
    .pagination-container .page-info {
        width: auto !important;
        margin: 0 !important;
    }

    /* -------------------------------------- */

    .page-info {
        text-align: center;
    }

    /* Footer centered */
    .footer-section {
        text-align: center;
    }

    .footer-links {
        justify-content: center;
    }

    /* Floating button can cause right overflow */
    #scrollToTopBtn {
        right: 1rem !important;
        bottom: 1.25rem !important;
        width: 44px !important;
        height: 44px !important;
    }
}