:root {
    --bg-dark: #0f1218;
    --card-bg-start: rgba(30, 38, 52, 0.85);
    --card-bg-end: rgba(18, 23, 33, 0.95);
    --card-border: rgba(255, 255, 255, 0.08);
    --accent: #2C6FC7;
    --accent-glow: rgba(44, 111, 199, 0.55);
    --red: #EF4444;
    --red-glow: rgba(239, 68, 68, 0.55);
    --success: #0AAF6E;
    --text-main: #ffffff;
    --text-sec: #7A8DAB;
    --secondary-bg: #1A202C;
    --radius: 20px;
    --quiz-header-height: 80px;
    --quiz-card-padding: clamp(10px, 1.2vw, 20px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: clip;
    overscroll-behavior: none;
}

body {
    background-color: var(--bg-dark);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-main);
}

.main-wrapper {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-top: var(--quiz-header-height);
}

.quiz-dashboard {
    width: 100%;
    max-width: 1800px;
    margin: 0 auto;
    padding: clamp(10px, 2dvh, 24px) clamp(12px, 2vw, 32px);
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.quiz-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    flex: 1;
    min-height: 0;
}

.quiz-heading {
    margin-bottom: clamp(8px, 1.5dvh, 18px);
    font-size: clamp(22px, 3vw, 28px);
    line-height: 1.1;
}

.quiz-carousel {
    display: flex;
    gap: 16px;
    padding: 6px 0 10px;
    overflow-x: auto;
    overflow-y: hidden;
    min-height: 0;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex: 1;
    align-items: stretch;
}

.quiz-carousel::-webkit-scrollbar {
    display: none;
}

.quiz-card {
    flex: 0 0 85vw;
    max-width: 400px;
    scroll-snap-align: center;
    background: linear-gradient(135deg, var(--card-bg-start) 0%, var(--card-bg-end) 100%);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    position: relative;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card-spacer-top {
    height: clamp(30px, 4.5dvh, 38px);
    flex-shrink: 0;
    width: 100%;
}

.card-tabs {
    height: clamp(30px, 4.5dvh, 38px);
    flex-shrink: 0;
    display: flex;
    background-color: var(--secondary-bg);
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: 1px solid var(--card-border);
    overflow: hidden;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-btn.quiz.active {
    background-color: var(--accent);
    color: #ffffff;
}

.tab-btn.err.active {
    background-color: var(--red);
    color: #ffffff;
}

.card-body {
    padding: 0 var(--quiz-card-padding) clamp(8px, 1.5dvh, 20px);
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    position: relative;
    min-height: 0;
}

.card-tabs + .card-body {
    padding-top: 0;
}

.card-tabs + .card-body .icon-wrapper {
    width: calc(100% + 2 * var(--quiz-card-padding));
    height: auto;
    flex: 1 1 170px;
    min-height: 0;
    max-height: clamp(80px, 26dvh, 260px);
    margin: 0 calc(-1 * var(--quiz-card-padding)) clamp(6px, 1.5dvh, 16px);
    border-radius: 0 0 16px 16px;
    overflow: hidden;
}

.card-tabs + .card-body .icon-wrapper img {
    object-fit: contain;
}

.lock-icon {
    position: absolute;
    top: 10px;
    right: 16px;
    width: 28px;
    height: 28px;
    z-index: 10;
}

.lock-icon[hidden] {
    display: none;
}

.quiz-card.locked .card-body {
    opacity: .4;
}

.icon-wrapper {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 10px 0 20px 0;
}

.icon-glow {
    position: absolute;
    width: 60px;
    height: 60px;
    background: var(--accent-glow);
    border-radius: 50%;
    filter: blur(40px);
    z-index: 0;
    transition: background 0.3s;
}

.icon-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    z-index: 1;
    position: relative;
}

.card-title {
    font-size: clamp(19px, 1.65vw, 28px);
    flex-shrink: 0;
    font-weight: 800;
    color: var(--text-main);
    text-align: center;
    line-height: 1.1;
    margin-bottom: clamp(4px, .8dvh, 8px);
}

.card-desc {
    font-size: clamp(13px, 1.15vw, 17px);
    color: var(--text-sec);
    text-align: center;
    line-height: 1.3;
    margin-bottom: auto;
    min-height: 2.6em;
    height: 2.6em;
    flex-shrink: 0;
}

.state-err {
    display: none;
    color: var(--red);
    font-weight: 700;
}

.info-block {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: clamp(6px, 1.3dvh, 14px) 6px;
    gap: 4px;
    margin: clamp(6px, 1.5dvh, 20px) 0;
    flex-shrink: 0;
}

.info-item {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.info-val {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: clamp(11px, .9vw, 15px);
    font-weight: 800;
    color: var(--text-main);
    white-space: nowrap;
}

.info-icon {
    width: clamp(16px, 1.2vw, 20px);
    height: clamp(16px, 1.2vw, 20px);
    object-fit: contain;
    flex-shrink: 0;
}

.info-label {
    font-size: clamp(9px, .7vw, 11px);
    font-weight: 600;
    color: var(--text-sec);
    white-space: nowrap;
}

.info-divider {
    flex: 0 0 1px;
    width: 1px;
    height: 30px;
    background: rgba(255, 255, 255, 0.1);
}

.action-btn {
    width: 100%;
    height: clamp(36px, 6dvh, 54px);
    flex-shrink: 0;
    border-radius: 14px;
    background-color: var(--accent);
    color: #ffffff;
    font-size: clamp(12px, 1vw, 16px);
    font-weight: 800;
    letter-spacing: 1px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(44, 111, 199, 0.4);
    transition: all 0.3s ease;
}

.card-progress {
    height: 24px;
    flex-shrink: 0;
    background-color: var(--secondary-bg);
    border-radius: 0 0 var(--radius) var(--radius);
    border-top: 1px solid var(--card-border);
    position: relative;
    overflow: visible;
}

.progress-fill {
    height: 100%;
    background-color: var(--accent);
    width: 0%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    min-width: 58px;
    padding: 0 12px;
    transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.3s;
    white-space: nowrap;
    overflow: visible;
    border-radius: 0 0 var(--radius) var(--radius);
}

.progress-text, .progress-count {
    font-size: 13px;
    font-weight: 800;
    color: #ffffff;
    z-index: 2;
}

.progress-text {
    flex: 0 0 auto;
}

.progress-count {
    position: absolute;
    top: 0;
    height: 100%;
    display: flex;
    align-items: center;
    right: 12px;
    color: var(--text-sec);
}

.card-progress.count-in-fill .progress-count {
    color: #ffffff;
}

.progress-fill.is-complete {
    background-color: var(--success) !important;
}

.quiz-card.is-complete .progress-text {
    color: #ffffff;
}

.quiz-card.error-mode .icon-glow {
    background: var(--red-glow);
}

.quiz-card.error-mode .action-btn {
    background-color: var(--red);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.quiz-card.error-mode .progress-fill {
    background-color: rgba(239, 68, 68, 0.8);
}

.quiz-card.error-mode .state-quiz {
    display: none;
}

.quiz-card.error-mode .state-err {
    display: block;
}

.carousel-indicators {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}

.indicator {
    width: 8px;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.indicator.active {
    width: 24px;
    background: var(--accent);
}

.swipe-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
    color: var(--text-sec);
    font-weight: 700;
    font-size: 15px;
}

.swipe-icon {
    width: 24px;
    height: 24px;
    animation: swipeAnim 1.5s infinite ease-in-out;
    color: var(--accent);
}

@keyframes swipeAnim {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(6px); }
}

@media (min-width: 1024px) {
    .quiz-carousel {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        grid-template-rows: minmax(0, 1fr);
        gap: clamp(10px, 1.2vw, 20px);
        padding: 6px 0 16px;
        overflow: clip;
    }

    .quiz-card {
        flex: auto;
        width: 100%;
        max-width: none;
        min-width: 0;
        min-height: 0;
    }

    .quiz-card.featured {
        grid-column: auto;
        max-width: none;
    }
    
    .quiz-card.featured .card-title {
        font-size: clamp(19px, 1.65vw, 28px);
    }

    .quiz-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    }

    .carousel-indicators,
    .swipe-indicator {
        display: none;
    }

    .quiz-theory-card:hover {
        transform: translateY(-3px);
        border-color: rgba(97, 165, 255, .6);
        background: linear-gradient(135deg, rgba(39, 55, 78, .9), rgba(18, 23, 33, .98));
    }

}

.simulation-tabs .mode-multi.active {
    background: linear-gradient(90deg, #7356e8, #a84ddf);
}

.simulation-tabs .mode-solo.active {
    background-color: var(--accent);
}

.quiz-theory-shortcuts {
    display: block;
    margin-top: clamp(6px, 1.5dvh, 20px);
    padding-top: 0;
    min-width: 0;
    flex-shrink: 0;
}

.quiz-section-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: clamp(6px, 1dvh, 12px);
    min-width: 0;
}

.quiz-section-heading h2 {
    margin-top: 4px;
    font-size: clamp(18px, 2.8dvh, 28px);
    line-height: 1.1;
}

.quiz-section-heading a {
    color: #9dc8ff;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.quiz-theory-grid {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    padding: 6px 2px 8px;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    min-width: 0;
    cursor: grab;
    user-select: none;
}

.quiz-theory-grid.is-dragging {
    cursor: grabbing;
    scroll-behavior: auto;
}

.quiz-theory-grid .quiz-theory-card {
    cursor: grab;
    -webkit-user-drag: none;
}

.quiz-theory-grid.is-dragging .quiz-theory-card {
    cursor: grabbing;
}

.quiz-theory-grid img {
    -webkit-user-drag: none;
    user-select: none;
}

.quiz-theory-grid::-webkit-scrollbar {
    display: none;
}

.quiz-theory-card {
    flex: 0 0 auto;
    width: max-content;
    min-height: clamp(56px, 9dvh, 90px);
    display: grid;
    grid-template-columns: 46px max-content 18px;
    align-items: center;
    gap: 10px;
    padding: 12px;
    color: var(--text-main);
    background: linear-gradient(135deg, rgba(30, 38, 52, .78), rgba(18, 23, 33, .94));
    border: 1px solid var(--card-border);
    border-radius: 14px;
    text-decoration: none;
    transition: transform .2s ease, border-color .2s ease, background .2s ease;
}

.quiz-theory-card img {
    width: 46px;
    height: 46px;
    object-fit: cover;
    border-radius: 10px;
    background: transparent;
}

.quiz-theory-number {
    color: var(--text-sec);
    font-size: 12px;
    font-weight: 800;
}

.quiz-theory-card strong {
    color: #9dc8ff;
    font-size: 18px;
}

.quiz-theory-copy {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
}

.quiz-theory-title {
    min-width: 0;
    white-space: nowrap;
}

@media (max-width: 600px) {
    .quiz-theory-shortcuts {
        margin-top: 6px;
        padding-top: 0;
    }

    .quiz-section-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }

    .quiz-section-heading h2 {
        font-size: 22px;
    }

}

.quiz-card.featured .card-tabs + .card-body {
    padding-top: 0;
}

@media (max-width: 1023px) {
    .carousel-indicators { margin-top: 4px; }
    .swipe-indicator { margin-top: 6px; font-size: 12px; }
}

@media (max-width: 768px) {
    .main-wrapper { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
    .quiz-section-heading { align-items: center; flex-direction: row; gap: 10px; }
    .quiz-section-heading h2 { font-size: 16px; }
    .quiz-section-heading a { font-size: 11px; }
}

@media (max-height: 640px) {
    .quiz-heading { font-size: 22px; }
    .card-title, .quiz-card.featured .card-title { font-size: 19px; }
    .card-desc { font-size: 13px; }
    .info-block { padding-block: 6px; margin-block: 6px; }
    .quiz-theory-card { padding-block: 8px; }
}

@media (min-width: 1024px) and (max-width: 1535px) {
    .info-val { flex-direction: column; }
    .tab-btn { font-size: clamp(11px, 1.05vw, 15px); }
}

@media (min-width: 1024px) and (max-width: 1535px) {
    .card-desc { height: 3.9em; }
}

@media (max-height: 560px) {
    .quiz-theory-card { min-height: 48px; grid-template-columns: 32px max-content 18px; }
    .quiz-theory-card img { width: 32px; height: 32px; }
    .quiz-section-heading h2 { font-size: 16px; }
    .quiz-section-heading { margin-bottom: 4px; }
    .card-tabs + .card-body {
        display: grid;
        grid-template-columns: 38px minmax(0, 1fr);
        grid-template-rows: 38px minmax(0, 1fr) auto auto;
        column-gap: 6px;
        padding-top: 6px;
    }
    .card-tabs + .card-body .icon-wrapper {
        width: 38px;
        height: 38px;
        margin: 0;
        border-radius: 6px;
    }
    .card-title, .quiz-card.featured .card-title { margin: 0; font-size: 16px; }
    .card-desc { grid-column: 1 / -1; height: auto; min-height: 0; margin: 0; font-size: 12px; }
    .info-block, .action-btn { grid-column: 1 / -1; }
    .action-btn { height: 32px; }
    .lock-icon { top: 6px; right: 6px; width: 18px; height: 18px; }
}

@media (prefers-reduced-motion: reduce) {
    .quiz-carousel { scroll-behavior: auto; }
    .swipe-icon { animation: none; }
    .quiz-card, .action-btn, .progress-fill, .quiz-theory-card { transition: none; }
}

/* Light surfaces and readable foregrounds; dark styling stays above. */
html[data-theme="light"] .info-block { background: rgba(17,17,17,.035); border-color: var(--card-border); }
html[data-theme="light"] .info-divider { background: var(--card-border); }
html[data-theme="light"] .indicator:not(.active) { background: rgba(17,17,17,.2); }
html[data-theme="light"] .quiz-theory-card { background: linear-gradient(135deg,var(--card-bg-start),var(--card-bg-end)); }
html[data-theme="light"] .quiz-theory-card:hover { background: linear-gradient(135deg,#e4efff,var(--card-bg-start)); }
html[data-theme="light"] :is(.quiz-section-heading a,.quiz-theory-card strong) { color: var(--via-accent); }

/* Light surfaces and readable foregrounds; dark styling stays above. */
html[data-theme="light"] .quiz-card.error-mode { --quiz-error-fill: var(--via-danger); }
html[data-theme="light"] .tab-btn.active { color: #fff; }
html[data-theme="light"] :is(.quiz-card,.quiz-theory-card) { box-shadow: var(--via-shadow); }
html[data-theme="light"] .progress-count { color: var(--via-text); background: var(--secondary-bg); border-radius: 3px; padding-inline: 3px; }
html[data-theme="light"] .card-progress.count-in-fill .progress-count { color: #fff; background: transparent; }
