:root {
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --success-color: #27ae60;
    --error-color: #e74c3c;
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-color: #333;
    --border-radius: 8px;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Focus Styles */
:focus-visible {
    outline: 3px solid var(--secondary-color);
    outline-offset: 2px;
}

button:focus-visible, 
.section-item:focus-visible, 
.answer-item:focus-visible,
.logo-wrapper:focus-visible {
    outline: 3px solid var(--secondary-color);
    outline-offset: 3px;
}

/* Specific focus for dark backgrounds (like header buttons) */
header button:focus-visible {
    outline-color: #fff;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
}

header {
    background-color: var(--primary-color);
    color: white;
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-bottom: 10px;
    padding-left: 0;
    padding-right: 0;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

#favorites-btn {
    background: transparent;
    border: 1px solid white;
    color: white;
    padding: 5px 10px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
    font-size: 0.9rem;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 44px;
    height: 36px;
}

#favorites-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

#favorites-btn.active {
    background: #e67e22;
    border-color: #e67e22;
    color: white;
}

#favorites-btn .star-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.shuffle-container {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.content-shuffle-btn {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 10px 20px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.content-shuffle-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.content-shuffle-btn .shuffle-icon {
    font-size: 1.2rem;
}

.logo-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
    padding: 5px;
    border-radius: var(--border-radius);
    text-align: left;
    max-width: 70%;
}

h1 {
    margin: 0;
    font-size: 1.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-logo {
    height: 40px;
    width: auto;
    border-radius: 4px;
}

#back-btn {
    background: transparent;
    border: 1px solid white;
    color: white;
    padding: 5px 15px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background 0.3s;
}

#back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Sections List */
.sections-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    padding: 0;
    list-style: none;
}

.sections-list li {
    display: flex;
}

.section-item {
    background: var(--card-bg);
    padding: 20px;
    text-align: center;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
    color: var(--primary-color);
    width: 100%;
    border: none;
    font-size: 1rem;
    font-family: inherit;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex: 1;
}

.section-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

/* Questions View */
.question-card {
    background: var(--card-bg);
    margin-bottom: 30px;
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
    margin-bottom: 20px;
}

.question-text {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 0;
    color: var(--primary-color);
    flex: 1;
}

.favorite-btn {
    background: none;
    border: 1px solid #ddd;
    color: #999;
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    padding: 5px 8px;
    border-radius: 50%;
    transition: all 0.2s;
    user-select: none;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.favorite-btn:hover {
    background-color: #f8f9fa;
    border-color: #e67e22;
    color: #e67e22;
}

.favorite-btn.active {
    color: #e67e22;
    border-color: #e67e22;
    background-color: #fffaf0;
}

.question-image {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    display: block;
}

.answers-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

button {
    touch-action: manipulation;
}

.answer-item {
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
    background: #fff;
    font-size: 1rem;
    text-align: left;
    font-family: inherit;
    line-height: 1.6;
    color: inherit;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.answer-item:hover {
    border-color: var(--secondary-color);
    background: #f9f9f9;
}

.answer-item.correct {
    background-color: var(--success-color) !important;
    color: white;
    border-color: var(--success-color);
}

.answer-item.incorrect {
    background-color: var(--error-color) !important;
    color: white;
    border-color: var(--error-color);
}

.answer-item.disabled {
    pointer-events: none;
}

#loading {
    text-align: center;
    font-size: 1.2rem;
    margin-top: 50px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 40px 0;
}

.page-btn {
    padding: 10px 15px;
    border: 1px solid var(--primary-color);
    background: white;
    color: var(--primary-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
}

.page-btn:hover {
    background: var(--primary-color);
    color: white;
}

.page-btn.active {
    background: var(--primary-color);
    color: white;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: var(--border-radius);
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.modal-content h2 {
    margin-top: 0;
    font-size: 1.8rem;
}

.success-text {
    color: var(--success-color);
}

.error-text {
    color: var(--error-color);
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 25px;
}

.modal-buttons button {
    padding: 10px 20px;
    border-radius: var(--border-radius);
    border: none;
    cursor: pointer;
    font-weight: bold;
    background: var(--primary-color);
    color: white;
    transition: background 0.3s;
}

.modal-buttons button:hover {
    background: var(--secondary-color);
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Mobile Responsiveness */
@media screen and (max-width: 768px) {
    .container {
        padding: 10px;
        padding-left: calc(10px + env(safe-area-inset-left));
        padding-right: calc(10px + env(safe-area-inset-right));
    }

    h1 {
        font-size: 1.1rem;
    }

    .logo-wrapper {
        gap: 8px;
        max-width: 50%;
    }

    #favorites-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .header-logo {
        height: 32px;
    }

    #back-btn {
        padding: 5px 10px;
        font-size: 0.8rem;
    }

    .header-actions {
        gap: 5px;
    }

    .sections-list {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
    }

    .section-item {
        padding: 15px;
        font-size: 0.9rem;
    }

    .question-card {
        padding: 15px;
        margin-bottom: 20px;
    }

    .answers-list {
        gap: 12px;
    }

    .question-text {
        font-size: 1rem;
        margin-bottom: 12px;
    }

    .answer-item {
        padding: 12px;
        font-size: 0.95rem;
    }

    .pagination {
        gap: 8px;
        margin: 25px 0;
    }

    .page-btn {
        padding: 8px 12px;
        font-size: 0.9rem;
        min-width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .modal-content {
        padding: 20px;
        width: 85%;
    }

    .modal-content h2 {
        font-size: 1.5rem;
    }

    .modal-buttons {
        flex-direction: column;
        gap: 10px;
    }

    .modal-buttons button {
        width: 100%;
    }
}

@media screen and (max-width: 480px) {
    .sections-list {
        grid-template-columns: 1fr 1fr;
    }

    .question-text {
        font-size: 0.95rem;
    }

    .answer-item {
        padding: 10px;
        font-size: 0.9rem;
    }

    .page-btn {
        padding: 6px 10px;
        font-size: 0.85rem;
        min-width: 36px;
        height: 36px;
    }
}

/* Test Footer Panel */
.test-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: var(--primary-color);
    color: white;
    padding: 10px 0;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.2);
    z-index: 999;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 5px;
    padding-bottom: 5px;
}

.footer-timer {
    display: flex;
    align-items: center;
    gap: 15px;
}

#timer-display {
    font-size: 1.5rem;
    font-weight: bold;
    font-family: monospace;
    min-width: 75px;
}

.timer-controls {
    display: flex;
    gap: 8px;
}

.timer-controls button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid white;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s;
}

.timer-controls button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.footer-counter {
    font-size: 1.1rem;
    font-weight: bold;
}

#questions-left-count {
    color: #e67e22;
    font-size: 1.3rem;
}

@media screen and (max-width: 600px) {
    .footer-content {
        flex-direction: row;
        gap: 10px;
        justify-content: space-around;
    }
    
    #timer-display {
        font-size: 1.2rem;
        min-width: 60px;
    }
    
    .footer-counter {
        font-size: 0.9rem;
    }
    
    #questions-left-count {
        font-size: 1.1rem;
    }
}

/* Adjust main container padding to not be covered by footer */
body:has(.test-footer[style*="display: block"]) {
    padding-bottom: 80px;
}

/* Fallback for browsers that don't support :has */
.has-footer {
    padding-bottom: 80px !important;
}
