:root {
    --bg-color: #f4f5f7;
    --panel-bg: rgba(255, 255, 255, 0.95);
    --panel-border: rgba(0, 0, 0, 0.08);
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --accent: #d32f2f;
    --accent-hover: #b71c1c;
    --btn-bg: #ffffff;
    --btn-border: #e0e0e0;
    --success: #2e7d32;
    --danger: #d32f2f;
    --font-main: 'Outfit', sans-serif;
    --radius: 16px;
    --transition: 0.3s ease;
}

[data-theme="dark"] {
    --bg-color: #0d1117;
    --panel-bg: rgba(22, 27, 34, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #3182ce;
    --btn-bg: #21262d;
    --btn-border: #30363d;
    --success: #2ea043;
    --danger: #e22134;
}

[data-theme="nord"] {
    --bg-color: #2e3440;
    --panel-bg: rgba(67, 76, 94, 0.8);
    --panel-border: rgba(216, 222, 233, 0.1);
    --text-primary: #eceff4;
    --text-secondary: #d8dee9;
    --accent: #88c0d0;
    --accent-hover: #81a1c1;
    --btn-bg: #4c566a;
    --btn-border: #434c5e;
    --success: #a3be8c;
    --danger: #bf616a;
}

[data-theme="slate-teal"] {
    --bg-color: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.05);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #2dd4bf;
    --accent-hover: #14b8a6;
    --btn-bg: #1e293b;
    --btn-border: #334155;
    --success: #22c55e;
    --danger: #f43f5e;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px;
}

.app-container {
    display: flex;
    width: 100%;
    max-width: 1400px;
    min-height: 90vh;
    /* changed from static height to min-height */
    height: auto;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    overflow: hidden;
    backdrop-filter: blur(20px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* Sidebar Styling */
.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--panel-bg);
    border-right: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    padding: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 32px;
}

.brand ion-icon {
    font-size: 32px;
}

.year-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.year-selector label {
    font-size: 14px;
    color: var(--text-secondary);
}

.year-selector select {
    background: var(--btn-bg);
    color: var(--text-primary);
    border: 1px solid var(--btn-border);
    padding: 12px 16px;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 16px;
    cursor: pointer;
    outline: none;
    transition: var(--transition);
}

.year-selector select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

.progress-section {
    margin-bottom: 32px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.progress-bar-bg {
    height: 6px;
    background: var(--btn-bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.4s ease;
}

.question-grid-container {
    flex-grow: 1;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
}

.question-grid-container h3 {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.question-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    overflow-y: auto;
    padding-right: 8px;
    align-content: start;
}

.question-grid::-webkit-scrollbar {
    width: 6px;
}

.question-grid::-webkit-scrollbar-thumb {
    background: var(--btn-border);
    border-radius: 4px;
}

.grid-btn {
    padding: 6px 0;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    color: var(--text-primary);
    border-radius: 6px;
    font-family: var(--font-main);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
}

.grid-btn:hover {
    background: var(--btn-border);
}

.grid-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.grid-btn.answered {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.grid-btn.bookmarked {
    border: 2px solid #ffbc00;
    /* Distinct border for bookmarks */
    box-shadow: 0 0 5px rgba(255, 188, 0, 0.5);
}

/* Main Content Styling */
.quiz-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 32px 48px;
    overflow-y: auto;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

#question-number-display {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 4px;
}

.type-badge {
    background: var(--btn-bg);
    color: var(--text-secondary);
    border: 1px solid var(--btn-border);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-family: var(--font-main);
    cursor: pointer;
    vertical-align: middle;
    transition: var(--transition);
}

.type-badge:hover {
    color: var(--text-primary);
    background: var(--btn-border);
}

.timer {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--btn-bg);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--btn-border);
}

.question-container {
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.image-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
}

#question-image {
    max-width: 100%;
    max-height: 40vh;
    /* Restore a relative vertical limit to prevent massive cards */
    object-fit: contain;
    object-position: left;
    transition: var(--transition);
    border-radius: 8px;
}

.loading-spinner {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 4px solid var(--btn-border);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: none;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.options-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 32px;
}

.option-btn {
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-primary);
    text-align: left;
}

.option-btn:hover {
    background: var(--btn-border);
    transform: translateY(-2px);
}

.opt-label {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    flex-shrink: 0;
}

.opt-text {
    font-family: var(--font-main);
    font-size: 16px;
}

.option-btn.selected {
    background: rgba(88, 166, 255, 0.1);
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.2);
}

.option-btn.selected .opt-label {
    background: var(--accent);
    color: #fff;
}

.quiz-footer {
    display: flex;
    justify-content: space-between;
}

.nav-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

.nav-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.nav-btn.prev-btn {
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
}

.nav-btn.prev-btn:hover {
    background: var(--btn-border);
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Scrollbar for main view */
.quiz-main::-webkit-scrollbar {
    width: 8px;
}

.quiz-main::-webkit-scrollbar-thumb {
    background: var(--btn-border);
    border-radius: 4px;
}

/* Numerical & Status Styles */
.numerical-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 32px;
    background: var(--btn-bg);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--btn-border);
}

.numerical-container label {
    font-size: 16px;
    color: var(--text-secondary);
}

#num-input {
    background: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--btn-border);
    padding: 16px;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 18px;
    outline: none;
    transition: var(--transition);
}

#num-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

#submit-num-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

#submit-num-btn:hover {
    background: var(--accent-hover);
}

.answer-status-container {
    margin-bottom: 32px;
    padding: 16px 24px;
    border-radius: 12px;
    background: rgba(46, 160, 67, 0.1);
    border: 1px solid var(--success);
}

.answer-status-container h4 {
    margin-bottom: 4px;
    font-size: 18px;
}

.answer-status-container.correct {
    background: rgba(46, 160, 67, 0.1);
    border-color: var(--success);
    color: var(--success);
}

.answer-status-container.incorrect {
    background: rgba(248, 81, 73, 0.1);
    border-color: #f85149;
    color: #f85149;
}

/* Answer Status */
.answer-status-container {
    margin-top: 16px;
    padding: 16px;
    border-radius: 8px;
    text-align: center;
}

.answer-status-container.correct {
    background: rgba(30, 215, 96, 0.1);
    border: 1px solid var(--success);
    color: var(--success);
}

.answer-status-container.incorrect {
    background: rgba(226, 33, 52, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    color: var(--text-primary);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* Mobile Responsiveness */
@media screen and (max-width: 800px) {
    body {
        padding: 0;
    }

    .app-container {
        flex-direction: column;
        border-radius: 0;
        border: none;
        min-height: 100vh;
        height: auto;
        overflow: visible;
    }

    .sidebar {
        display: none;
        width: 100%;
        min-width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--panel-border);
    }

    .sidebar.active {
        display: flex;
    }

    .mobile-nav-toggle {
        display: inline-block !important;
    }

    .question-grid-container {
        max-height: 250px;
    }

    .question-grid {
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    }

    .quiz-main {
        padding: 20px 16px;
        overflow-y: visible;
    }

    .quiz-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .quiz-header>div:first-child {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .options-container {
        grid-template-columns: 1fr;
    }

    .quiz-footer {
        flex-wrap: wrap;
        gap: 12px;
    }

    .nav-btn {
        flex: 1;
        justify-content: center;
        min-width: 120px;
    }
}