:root {
    --bg: #0c1a2b;
    --bg2: #0a1626;
    --panel: #132741;
    --panel-hi: #162d4a;
    --line: #22405f;
    --line-hi: #31597f;
    --text: #e7effb;
    --muted: #8ba6c9;
    --blue: #4a90e2;
    --blue-lite: #8dc0f2;
    --green: #3fc07f;
    --green-lite: #8fe3b6;
    --seg-base: #1f3a56;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Exo 2', system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: var(--text);
    background:
        radial-gradient(1100px 620px at 50% -8%, #16324f 0%, rgba(22, 50, 79, 0) 62%),
        linear-gradient(180deg, #0d1c2e 0%, #0a1626 100%);
    background-attachment: fixed;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.quiz {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.quiz-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: clamp(24px, 5vw, 48px) clamp(16px, 4vw, 44px) 24px;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: #4a90e2 transparent;
}

.quiz-scroll::-webkit-scrollbar {
    width: 8px;
}

.quiz-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.quiz-scroll::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #4a90e2, #2563eb);
    border-radius: 4px;
}

.quiz-scroll::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #60a5fa, #3b82f6);
}

.quiz-scroll-inner {
    margin: 0 auto;
    width: 100%;
    max-width: 760px;
    display: flex;
    flex-direction: column;
}

.quiz-scroll-inner>* {
    flex-shrink: 0;
}

/* ---------- timer ---------- */
.timer-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-bottom: clamp(16px, 3vw, 22px);
}

.timer-wrap[hidden] {
    display: none;
}

.timer-clock {
    width: 48px;
    height: 48px;
    display: block;
}

.timer-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    min-height: 16px;
    line-height: 16px;
    min-width: 180px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
    transition: color .2s ease;
}

.timer-label.warn {
    color: var(--blue-lite);
}

/* ---------- progress ---------- */
.progress {
    display: flex;
    gap: 6px;
    height: 4px;
    margin-bottom: clamp(26px, 5vw, 46px);
}

.progress .seg {
    flex: 1 1 0;
    border-radius: 999px;
    background: var(--seg-base);
    transition: background .3s ease;
}

.progress .seg.green {
    background: var(--green);
}

.progress .seg.blue {
    background: var(--blue);
}

/* ---------- question canvas ---------- */
.q-wrap {
    margin-bottom: clamp(20px, 4vw, 34px);
}

canvas#qCanvas {
    display: block;
    width: 100%;
}

/* ---------- options ---------- */
.options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.opt {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: clamp(12px, 2.2vw, 16px) clamp(14px, 2.4vw, 20px);
    font-family: inherit;
    font-size: clamp(14.5px, 2.05vw, 17px);
    font-weight: 500;
    line-height: 1.35;
    letter-spacing: .005em;
    color: var(--text);
    text-align: left;
    background: var(--panel);
    border: 1.5px solid var(--line);
    border-radius: 14px;
    cursor: pointer;
    outline: none;
    transition: background .18s ease, border-color .18s ease, color .18s ease;
    -webkit-user-select: none;
    user-select: none;
}

.opt:hover:not(:disabled) {
    background: var(--panel-hi);
    border-color: var(--line-hi);
}

.opt:focus-visible {
    border-color: var(--blue);
}

.opt:disabled {
    opacity: 1;
    pointer-events: none;
    cursor: default;
}

.opt .txt {
    flex: 1 1 auto;
    min-width: 0;
}

/* radio (single) */
.radio {
    position: relative;
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #3a5c85;
    transition: border-color .18s ease;
}

.radio::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--blue);
    transform: translate(-50%, -50%) scale(0);
    transition: transform .18s ease, background .18s ease;
}

/* checkbox (multi) */
.checkbox {
    position: relative;
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 2px solid #3a5c85;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color .18s ease, background .18s ease;
}

.checkbox svg {
    width: 14px;
    height: 14px;
    color: #fff;
    opacity: 0;
    transform: scale(0.4);
    transition: opacity .18s ease, transform .18s ease;
    display: block;
}

.opt.selected {
    border-color: var(--blue);
    background: rgba(74, 144, 226, .14);
    color: #cfe2fb;
}

.opt.selected .checkbox {
    border-color: var(--blue);
    background: var(--blue);
}

.opt.selected .checkbox svg {
    opacity: 1;
    transform: scale(1);
}

.opt.wrong {
    border-color: var(--blue);
    background: rgba(74, 144, 226, .14);
    color: #cfe2fb;
}

.opt.wrong .radio {
    border-color: var(--blue);
}

.opt.wrong .radio::after {
    transform: translate(-50%, -50%) scale(1);
    background: var(--blue);
}

.opt.correct {
    border-color: var(--green);
    background: rgba(63, 192, 127, .15);
    color: #d9f7e7;
}

.opt.correct .radio {
    border-color: var(--green);
}

.opt.correct .radio::after {
    transform: translate(-50%, -50%) scale(1);
    background: var(--green);
}

.opt.correct .checkbox {
    border-color: var(--green);
    background: var(--green);
}

.opt.correct .checkbox svg {
    opacity: 1;
    transform: scale(1);
}

@keyframes shake {
    0% {
        transform: translateX(0);
    }

    15% {
        transform: translateX(-8px);
    }

    30% {
        transform: translateX(7px);
    }

    45% {
        transform: translateX(-5px);
    }

    60% {
        transform: translateX(4px);
    }

    80% {
        transform: translateX(-2px);
    }

    100% {
        transform: translateX(0);
    }
}

.opt.shake {
    animation: shake .42s cubic-bezier(.36, .07, .19, .97);
}

/* ---------- actions ---------- */
.actions {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px clamp(16px, 4vw, 44px) calc(20px + env(safe-area-inset-bottom));
    background: transparent;
}

.next {
    font-family: inherit;
    font-size: clamp(15px, 2vw, 17px);
    font-weight: 600;
    letter-spacing: .02em;
    padding: 14px 46px;
    border: 1.5px solid transparent;
    border-radius: 14px;
    background: var(--green);
    color: #04241a;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease, background .18s ease;
}

.next.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.next.show.is-disabled {
    opacity: .4;
    pointer-events: none;
}

.next:hover {
    background: #4ed08d;
}

.next:focus-visible {
    outline: 2px solid var(--green-lite);
    outline-offset: 3px;
}

.next.is-check {
    background: var(--blue);
    color: #06192e;
}

.next.is-check:hover {
    background: #5c9ee6;
}

.next.is-check:focus-visible {
    outline: 2px solid var(--blue-lite);
    outline-offset: 3px;
}

.again {
    font-family: inherit;
    font-size: clamp(15px, 2vw, 17px);
    font-weight: 600;
    letter-spacing: .02em;
    padding: 14px 46px;
    border: 1.5px solid transparent;
    background-clip: padding-box;
    border-radius: 14px;
    background-image: linear-gradient(90deg,
            var(--blue) var(--fill, 0%),
            transparent var(--fill, 0%));
    background-color: transparent;
    color: #fff;
    cursor: pointer;
    display: none;
    margin-top: auto;
    transition: filter .18s ease;
}

.again.show {
    display: block;
}

.again:not(.ready) {
    cursor: wait;
    pointer-events: none;
}

.again.ready:hover {
    filter: brightness(1.12);
}

.again:focus-visible {
    outline: 2px solid var(--blue-lite);
    outline-offset: 3px;
}

/* ---------- page loader ---------- */
.page-loader {
    position: fixed;
    inset: 0;
    background: #0c1a2b;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity .35s ease, visibility .35s ease;
}

.page-loader.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.page-loader__content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-loader__text {
    color: #e7effb;
    font-size: clamp(15px, 2vw, 18px);
    font-weight: 500;
    letter-spacing: .02em;
}

.page-loader__dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 12px;
}

.page-loader__dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #4a90e2;
    animation: pageLoaderBounce 1.2s ease-in-out infinite;
}

.page-loader__dot:nth-child(2) {
    animation-delay: .15s;
}

.page-loader__dot:nth-child(3) {
    animation-delay: .3s;
}

@keyframes pageLoaderBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-5px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .page-loader__dot {
        animation: none;
    }
}

@media (max-width:520px) {
    .next {
        width: 100%;
        padding: 15px 24px;
    }

    .again {
        width: 100%;
        padding: 15px 24px;
    }
}

.quiz-grade-text {
    text-align: center;
    color: var(--text);
    font-size: clamp(19px, 4.3vw, 30px);
    font-weight: 600;
    line-height: 1.42;
    white-space: pre-wrap;
    word-break: break-word;
    padding: 8px 0 14px;
}

.quiz-grade-text[hidden] {
    display: none;
}