/* ==========================================================================
   1. ZMIENNE I MOTYWY (LIGHT & DARK THEME)
   ========================================================================== */

:root {
    --primary: #800000;
    --primary-hover: #a00000;
    --text-main: #2c3e50;
    --text-muted: #666666;
    --text-bold: #000000;
    --border: #e0e0e0;
    --bg-paper: #f4f4f2;
    --white: #ffffff;
    --shadow: rgba(0, 0, 0, 0.05);
    --modal-bg-header: #fdfbf7;
    --modal-border-top: #800000;
}

[data-theme="dark"] {
    --primary: #c62828;
    --primary-hover: #e53935;
    --text-main: #e0e0e0;
    --text-muted: #9e9e9e;
    --text-bold: #ffffff;
    --border: #333333;
    --bg-paper: #121212;
    --white: #1e1e1e;
    --shadow: rgba(0, 0, 0, 0.4);
    --modal-bg-header: #252525;
    --modal-border-top: #c62828;
}

/* ==========================================================================
   2. GŁÓWNY UKŁAD STRONY (LAYOUT) & NAWIGACJA
   ========================================================================== */

html, body {
    height: 100%;
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-paper);
    color: var(--text-main);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

nav {
    background: var(--white);
    border-bottom: 2px solid var(--primary);
    padding: 1rem 2%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 5px var(--shadow);
}

.logo {
    font-family: 'Playfair Display', serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.version-tag {
    font-size: 0.7rem;
    font-weight: bold;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Przycisk hamburgera domyślnie ukryty na komputerze */
.nav-menu-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
    font-size: 1.4rem;
    padding: 4px 10px;
    border-radius: 8px;
    cursor: pointer;
}

/* Kontener przycisków w nagłówku na komputerze (wymuszenie jednej linii) */
.nav-right-links {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
    outline: none;
    white-space: nowrap;
}

.theme-toggle:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* ==========================================================================
   3. WYSZUKIWARKA (UKŁAD DOMYŚLNY / DESKTOP)
   ========================================================================== */

.search-container {
    background: var(--white);
    padding: 2rem 0;
    box-shadow: 0 4px 10px var(--shadow);
}

.search-wrapper {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.desktop-search-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

input[type="text"] {
    flex: 1;
    width: 100%;
    padding: 1.2rem 1.8rem;
    padding-right: 45px !important;
    border: 2px solid var(--border);
    border-radius: 50px;
    font-size: 1.2rem;
    background-color: var(--bg-paper);
    color: var(--text-main);
    outline: none;
    box-sizing: border-box;
    transition: all 0.3s ease;
}

input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(128, 0, 0, 0.15);
}

#clearBtn {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    display: none;
    user-select: none;
}

#clearBtn:hover {
    color: var(--primary);
}

#searchBtn {
    padding: 1.2rem 2.5rem;
    background-color: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease;
}

#searchBtn:hover {
    background-color: var(--primary-hover);
}

.desktop-options-row {
    margin-top: 15px;
    font-size: 0.9rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.radio-label {
    cursor: pointer;
    margin-left: 10px;
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-main);
}

.count-info {
    text-align: right;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ==========================================================================
   4. WŁASNA ROZWIJANA LISTA (CUSTOM DROPDOWN)
   ========================================================================== */

.custom-dropdown {
    position: relative;
    user-select: none;
}

.dropdown-toggle {
    background: var(--white);
    border: 2px solid var(--border);
    color: var(--text-main);
    padding: 1.2rem 1.4rem;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    outline: none;
    white-space: nowrap;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.3s ease;
}

.dropdown-toggle:hover {
    border-color: var(--primary);
}

.dropdown-arrow {
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.custom-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    width: 320px;
    display: none;
    z-index: 9999;
    overflow: hidden;
}

.custom-dropdown.open .dropdown-menu {
    display: block;
}

.dropdown-item {
    padding: 1rem 1.2rem;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover, .dropdown-item.active {
    background-color: var(--bg-paper);
    color: var(--primary);
    font-weight: 600;
}

/* ==========================================================================
   5. LISTA WYNIKÓW I MODALE
   ========================================================================== */

.dictionary-list {
    flex: 1;
    width: 100%;
    max-width: 800px;
    margin: 2rem auto;
    padding: 0 1rem 5rem 1rem;
    box-sizing: border-box;
}

details {
    background: var(--white);
    margin-bottom: 0.8rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    width: 100%;
    box-sizing: border-box;
    box-shadow: 0 2px 4px var(--shadow);
}

summary {
    padding: 1.2rem 1.5rem;
    list-style: none;
    cursor: pointer;
    font-weight: 600;
    font-family: 'Playfair Display', serif;
    font-size: 1.25rem;
    color: var(--primary);
    display: flex;
    justify-content: space-between;
}

summary::after { content: "↓"; color: var(--text-muted); }
details[open] summary::after { content: "↑"; color: var(--primary); }

.content {
    padding: 1.5rem;
    font-size: 1.05rem;
    border-top: 1px solid var(--border);
    color: var(--text-main);
}

.content b { color: var(--text-bold); }

mark {
    background-color: #ffeb3b;
    color: #000000;
    padding: 0 2px;
    border-radius: 3px;
    font-weight: 600;
}

.modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(3px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    padding: 1rem;
    box-sizing: border-box;
}

.modal-box {
    background: var(--white);
    color: var(--text-main);
    width: 100%;
    max-width: 650px;
    max-height: 80vh;
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-top: 5px solid var(--modal-border-top);
    border: 1px solid var(--border);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--modal-bg-header);
}

.modal-header h2 {
    margin: 0;
    font-family: 'Playfair Display', serif;
    color: var(--primary);
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    font-size: 1.05rem;
    line-height: 1.6;
}

footer {
    margin-top: auto;
    width: 100%;
    background-color: var(--white);
    border-top: 1px solid var(--border);
}

footer div {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
    text-align: right;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ==========================================================================
   6. RESPONSYWNOŚĆ (EKRANY MOBILNE / SMARTFONY)
   ========================================================================== */

@media (max-width: 768px) {
    nav {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem 1.2rem;
    }

    .logo {
        font-size: 1rem;
        margin-bottom: 0;
    }

    /* Pokazujemy przycisk hamburgera na telefonie/tablecie */
    .nav-menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Ukrywamy domyślnie opcje w nagłówku i przełączamy w kolumnę po rozwinięciu */
    .nav-right-links {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px dashed var(--border);
        white-space: normal;
    }

    .nav-right-links.open {
        display: flex !important;
    }

    .nav-right-links .theme-toggle, 
    .nav-right-links .lang-btn-top {
        width: 100%;
        text-align: center;
        padding: 10px;
        border-radius: 8px;
    }

    /* Wyszukiwarka w jednej linii na telefonie: pole + lupa + słownik */
    .desktop-search-row {
        gap: 6px;
    }

    .desktop-search-row input[type="text"] {
        padding: 0.7rem 2.2rem 0.7rem 1rem !important;
        font-size: 1rem;
        border-radius: 50px;
    }

    #clearBtn {
        right: 12px !important;
        font-size: 1.2rem;
    }

    /* Przycisk szukaj zamieniony w lupkę */
    #searchBtn {
        padding: 0.7rem 0.9rem;
        font-size: 0;
        border-radius: 50px;
        flex-shrink: 0;
    }

    #searchBtn::before {
        content: "🔍";
        font-size: 0.95rem;
    }

    /* Przycisk wyboru słownika w tej samej linii */
    .custom-dropdown {
        flex-shrink: 0;
    }

    .dropdown-toggle {
        padding: 0.7rem 0.9rem;
        font-size: 0.85rem;
        border-radius: 50px;
        white-space: nowrap;
    }

    .dropdown-menu {
        width: 260px !important;
        right: 0 !important;
        left: auto !important;
    }

    /* Opcje wyszukiwania w drugiej linii */
    .desktop-options-row {
        margin-top: 10px;
        font-size: 0.8rem;
        gap: 6px;
    }

    .radio-label {
        font-size: 0.8rem;
        margin-left: 4px;
    }

    .search-container {
        padding: 1rem 0;
    }
    
    .search-wrapper {
        padding: 0 1rem;
    }

    .dictionary-list {
        margin: 1rem auto;
        padding: 0 0.7rem 3rem 0.7rem;
    }

    summary {
        font-size: 1.1rem;
        padding: 1rem;
    }

    .content {
        padding: 1rem;
        font-size: 1rem;
    }
}

/* Efekt chowania górnych pasków na telefonie przy przewijaniu */
@media (max-width: 768px) {
    nav, .search-container {
        transition: transform 0.3s ease-in-out;
    }
    
    body.hide-header nav,
    body.hide-header .search-container {
        transform: translateY(-100%);
    }
}