:root {
    --bg: #f5f8fd;
    --panel: #ffffff;
    --panel-soft: #f8fbff;
    --panel-glass: rgba(255, 255, 255, .94);
    --panel-strong: rgba(255, 255, 255, .90);
    --topbar-bg: rgba(255, 255, 255, .86);
    --page-start: #fbfdff;
    --ink: #111d3a;
    --muted: #677498;
    --line: #dbe3f1;
    --line-soft: #edf2f8;
    --accent: #245cff;
    --accent-strong: #1748df;
    --accent-soft: #edf3ff;
    --danger: #df2f29;
    --success: #20b26b;
    --shadow: 0 22px 70px rgba(29, 45, 82, .10);
    --question-option-bg: #ffffff;
    --nav-dot: #edf2fa;
    --input-bg: #ffffff;
    --icon-muted: #40547c;
    --soft-label: #7b89aa;
    --body-glow: rgba(36, 92, 255, .07);
}

body[data-theme="dark"] {
    --bg: #0b1220;
    --panel: #111a2d;
    --panel-soft: #16223a;
    --panel-glass: rgba(17, 26, 45, .95);
    --panel-strong: rgba(13, 21, 36, .94);
    --topbar-bg: rgba(14, 23, 39, .92);
    --page-start: #0f1728;
    --ink: #edf4ff;
    --muted: #9aa9c7;
    --line: #263650;
    --line-soft: #1d2b43;
    --accent: #5f86ff;
    --accent-strong: #7c9bff;
    --accent-soft: rgba(95, 134, 255, .16);
    --danger: #ff706b;
    --success: #35d889;
    --shadow: 0 24px 80px rgba(0, 0, 0, .32);
    --question-option-bg: #101a2d;
    --nav-dot: #1b2941;
    --input-bg: #101a2d;
    --icon-muted: #9fb0d5;
    --soft-label: #9aa9c7;
    --body-glow: rgba(95, 134, 255, .12);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 58% 16%, var(--body-glow), transparent 34%),
        linear-gradient(180deg, var(--page-start) 0%, var(--bg) 100%);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    min-height: 48px;
    border: 0;
    border-radius: 8px;
    padding: 0 20px;
    color: white;
    background: linear-gradient(135deg, #3b72ff, var(--accent));
    cursor: pointer;
    font-weight: 700;
    box-shadow: 0 14px 28px rgba(36, 92, 255, .22);
}

button:hover {
    background: linear-gradient(135deg, #2c63f0, var(--accent-strong));
}

button:disabled {
    cursor: not-allowed;
    opacity: .58;
    box-shadow: none;
}

.hidden {
    display: none !important;
}

.test-shell {
    width: min(100%, 1520px);
    min-height: 100vh;
    margin: 0 auto;
}

.test-panel,
.test-dashboard {
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel-glass);
    box-shadow: var(--shadow);
}

.test-panel {
    max-width: 760px;
    margin: 8vh auto 0;
    padding: clamp(26px, 5vw, 52px);
}

.test-panel--intro {
    display: grid;
    place-items: center;
    gap: 16px;
    min-height: 240px;
    text-align: center;
}

.test-panel--auth {
    max-width: 520px;
}

.test-topline,
.test-dashboard-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.test-dashboard {
    margin: 28px;
    padding: clamp(24px, 4vw, 44px);
}

.test-dashboard-header {
    margin-bottom: 28px;
}

.test-dashboard-header h1 {
    margin-bottom: 0;
}

.test-kicker {
    margin-bottom: 10px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
}

h1 {
    margin: 0 0 14px;
    font-size: clamp(32px, 4vw, 52px);
    line-height: 1.08;
    letter-spacing: 0;
}

.test-muted,
.test-description,
.test-card-description {
    margin: 0 0 24px;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.55;
}

.test-description p,
.test-card-description p {
    margin: 0 0 .85em;
}

.test-description p:last-child,
.test-card-description p:last-child {
    margin-bottom: 0;
}

.test-description a,
.test-card-description a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.test-form,
.test-options,
.test-result-list {
    display: grid;
    gap: 16px;
}

.test-code-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 20px;
}

.test-form label,
.test-code-form label {
    display: grid;
    gap: 8px;
}

.test-form span,
.test-code-form span,
.test-meta dt,
.test-card-meta dt {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px 15px;
    color: var(--ink);
    background: var(--input-bg);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(36, 92, 255, .10);
}

textarea {
    min-height: 150px;
    resize: vertical;
}

.test-meta,
.test-card-meta {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 24px 0;
}

.test-meta div,
.test-card-meta div,
.test-result-item {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
    background: var(--panel-soft);
}

.test-meta dd,
.test-card-meta dd {
    margin: 6px 0 0;
    font-size: 18px;
    font-weight: 800;
}

.test-alert {
    margin: 18px 0;
    border: 1px solid rgba(223, 47, 41, .24);
    border-radius: 12px;
    padding: 14px 16px;
    color: var(--danger);
    background: rgba(223, 47, 41, .06);
}

.test-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
    gap: 16px;
}

.test-card {
    display: grid;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    background: var(--panel);
}

.test-card h2 {
    margin: 0;
    font-size: 24px;
    line-height: 1.22;
}

.test-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.test-card-status,
.test-card-mode {
    width: fit-content;
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 12px;
    font-weight: 800;
}

.test-card-mode {
    color: var(--accent);
    background: var(--accent-soft);
}

.test-card-status.is-available {
    color: var(--success);
    background: rgba(32, 178, 107, .11);
}

.test-card-status.is-locked {
    color: var(--danger);
    background: rgba(223, 47, 41, .08);
}

.test-card-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    border-radius: 8px;
    padding: 0 18px;
    color: white;
    background: var(--accent);
    text-decoration: none;
    font-weight: 800;
}

.test-card-action[aria-disabled="true"] {
    pointer-events: none;
    opacity: .55;
}

.test-empty {
    border: 1px dashed var(--line);
    border-radius: 16px;
    padding: 34px;
    text-align: center;
    background: var(--panel-soft);
}

.test-empty h2 {
    margin: 0 0 8px;
    font-size: 26px;
}

.test-empty p {
    margin: 0;
    color: var(--muted);
}

.test-secondary,
.test-icon-button,
.test-mark-button {
    border: 1px solid var(--line);
    color: var(--ink);
    background: var(--panel);
    box-shadow: none;
}

.test-secondary:hover,
.test-icon-button:hover,
.test-mark-button:hover {
    background: var(--panel-soft);
}

.test-loader {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(36, 92, 255, .16);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

.test-runner {
    display: grid;
    grid-template-columns: 288px minmax(0, 1fr);
    min-height: 100vh;
    border: 1px solid var(--line);
    border-radius: 0 0 20px 20px;
    overflow: clip;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.test-sidebar {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    gap: 18px;
    min-height: 100vh;
    border-right: 1px solid var(--line);
    padding: 36px 26px 24px;
    background: var(--panel-strong);
}

.test-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.test-brand-icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 14px;
    color: var(--accent);
    background: var(--accent-soft);
    font-size: 19px;
}

.test-brand h1 {
    margin: 0 0 5px;
    font-size: 22px;
    line-height: 1.15;
}

.test-brand p,
.test-variant span,
.test-sidebar-title,
.test-progress-block span,
.test-time-block span,
.test-marked-row {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
}

.test-variant {
    display: grid;
    gap: 8px;
}

.test-variant span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.test-variant select {
    height: 48px;
    color: var(--ink);
    font-weight: 800;
}

.test-sidebar-section {
    min-height: 0;
    border-top: 1px solid var(--line-soft);
    padding-top: 18px;
}

.test-sidebar-title {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    color: var(--ink);
    font-weight: 800;
}

.test-sidebar-title span:last-child {
    color: var(--muted);
    font-weight: 600;
}

.test-question-nav {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    max-height: calc(100vh - 330px);
    overflow: auto;
    padding-right: 4px;
}

.test-question-nav-item {
    display: grid;
    grid-template-columns: 42px 28px minmax(0, 1fr);
    align-items: center;
    width: 100%;
    min-height: 50px;
    border-radius: 14px;
    padding: 0 10px;
    color: var(--ink);
    background: transparent;
    box-shadow: none;
    font-weight: 800;
    font-size: 17px;
    text-align: center;
}

.test-question-nav-item::before {
    content: "";
    grid-column: 1;
    grid-row: 1;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--nav-dot);
}

.test-question-nav-item > span {
    display: grid;
    place-items: center;
    grid-column: 1;
    grid-row: 1;
    z-index: 1;
    width: 38px;
    height: 38px;
    line-height: 1;
}

.test-question-nav-item.is-current {
    color: var(--accent);
    background: linear-gradient(90deg, var(--accent-soft) 0%, rgba(95, 134, 255, .04) 100%);
    box-shadow: none;
}

.test-question-nav-item.is-current::before {
    background: linear-gradient(135deg, #4d7dff, var(--accent));
    box-shadow: 0 9px 18px rgba(36, 92, 255, .26);
}

.test-question-nav-item.is-current > span {
    color: white;
}

.test-question-nav-item.is-answered::after {
    content: "✓";
    grid-column: 2;
    color: var(--success);
    font-size: 16px;
    font-weight: 900;
}

.test-question-nav-item.is-current::after {
    content: none;
}

.test-mark-button,
.test-marked-row {
    width: 100%;
}

.test-marked-row {
    display: flex;
    justify-content: space-between;
    border: 1px solid var(--line);
    border-top: 0;
    border-radius: 0 0 8px 8px;
    padding: 14px 16px;
    background: var(--panel-soft);
}

.test-marked-row span:last-child {
    display: grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    background: var(--nav-dot);
    color: var(--soft-label);
}

.test-attempt-main {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-width: 0;
    background: linear-gradient(180deg, var(--page-start), var(--bg));
}

.test-attempt-topbar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto auto auto;
    align-items: center;
    gap: 22px;
    min-height: 120px;
    border-bottom: 1px solid var(--line);
    padding: 28px 24px 28px 38px;
    background: var(--topbar-bg);
}

.test-progress-block {
    display: grid;
    grid-template-columns: minmax(140px, 420px) auto;
    gap: 8px 12px;
    align-items: center;
}

.test-progress-block span {
    grid-column: 1 / -1;
    color: var(--ink);
    font-weight: 600;
}

.test-progress-block strong {
    color: var(--muted);
    font-weight: 700;
}

.test-progress-line {
    overflow: hidden;
    height: 9px;
    border-radius: 999px;
    background: var(--line-soft);
}

.test-progress-line span {
    display: block;
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #2862ff, #4a7cff);
}

.test-time-block {
    display: flex;
    align-items: center;
    gap: 13px;
    border-left: 1px solid var(--line);
    padding-left: 22px;
}

.test-time-icon {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    color: var(--accent);
    background: var(--accent-soft);
    font-size: 24px;
}

.test-time-block strong {
    display: block;
    margin-top: 4px;
    font-size: 24px;
    line-height: 1;
}

.test-view-actions {
    display: flex;
    gap: 10px;
    border-left: 1px solid var(--line);
    padding-left: 18px;
}

.test-icon-button {
    width: 48px;
    min-height: 48px;
    padding: 0;
    border-radius: 12px;
    color: var(--icon-muted);
    font-size: 22px;
}

.test-icon-button.is-active {
    border-color: rgba(36, 92, 255, .45);
    color: var(--accent);
    background: var(--accent-soft);
}

.test-finish-button {
    border: 1px solid var(--line);
    color: var(--danger);
    background: var(--panel);
    box-shadow: none;
}

.test-finish-button:hover {
    background: rgba(223, 47, 41, .06);
}

.test-questions {
    display: grid;
    gap: 28px;
    min-width: 0;
    padding: 38px 56px 34px;
}

.test-question-card {
    position: relative;
    min-height: 560px;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: clamp(28px, 4vw, 52px);
    background: var(--panel-glass);
    box-shadow: 0 18px 48px rgba(29, 45, 82, .07);
}

.test-bookmark-button {
    position: absolute;
    top: 30px;
    right: 30px;
    width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 50%;
    color: var(--icon-muted);
    background: var(--panel-soft);
    box-shadow: none;
}

.test-question {
    display: none;
}

.test-question.is-active {
    display: block;
}

.test-question.is-missing {
    border: 1px solid rgba(223, 47, 41, .28);
    border-radius: 14px;
    margin: -14px;
    padding: 14px;
    background: rgba(223, 47, 41, .04);
}

.test-question-number {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    margin-bottom: 24px;
    border-radius: 14px;
    padding: 0 16px;
    color: var(--accent);
    background: var(--accent-soft);
    font-size: 15px;
    font-weight: 800;
}

.test-question-text {
    max-width: 920px;
    margin: 0 0 18px;
    font-size: 28px;
    line-height: 1.25;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.test-question-text > :first-child {
    margin-top: 0;
}

.test-question-text > :last-child {
    margin-bottom: 0;
}

.test-question-text + .test-options {
    margin-top: 26px;
}

.test-question-help {
    margin: 0 0 26px;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.5;
}

.test-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin: 18px 0 22px;
}

.test-images img {
    width: 100%;
    max-height: 280px;
    border: 1px solid var(--line);
    border-radius: 12px;
    object-fit: contain;
    background: var(--panel);
}

.test-option {
    display: flex;
    align-items: center;
    gap: 22px;
    min-height: 76px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 18px 22px;
    background: var(--question-option-bg);
    color: var(--ink);
    font-size: 18px;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.test-option:hover {
    border-color: rgba(36, 92, 255, .42);
    box-shadow: 0 12px 24px rgba(29, 45, 82, .07);
}

.test-option input {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    margin: 0;
    accent-color: var(--accent);
}

.test-report-button {
    min-height: 40px;
    margin-top: 30px;
    padding: 0;
    color: var(--accent);
    background: transparent;
    box-shadow: none;
}

.test-report-button:hover {
    background: transparent;
    color: var(--accent-strong);
}

.test-bottom-nav {
    display: flex;
    justify-content: space-between;
    gap: 18px;
}

.test-bottom-nav button {
    min-width: 148px;
}

.test-session-button {
    justify-self: start;
    margin: 0 0 28px 56px;
}

.test-score {
    margin: 0 0 20px;
    color: var(--success);
    font-size: 28px;
    font-weight: 800;
}

.test-result-item strong {
    color: var(--success);
}

.test-result-item strong[data-wrong] {
    color: var(--danger);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1100px) {
    .test-runner {
        grid-template-columns: 1fr;
    }

    .test-sidebar {
        min-height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 20px;
    }

    .test-question-nav {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        max-height: none;
        overflow: visible;
        padding-right: 0;
    }

    .test-question-nav-item {
        grid-template-columns: 44px 24px minmax(0, 1fr);
    }

    .test-attempt-topbar {
        grid-template-columns: 1fr 1fr;
        padding: 22px;
    }

    .test-time-block,
    .test-view-actions {
        border-left: 0;
        padding-left: 0;
    }

    .test-questions {
        padding: 24px;
    }

    .test-session-button {
        margin-left: 24px;
    }
}

@media (max-width: 720px) {
    .test-shell {
        width: 100%;
    }

    .test-panel,
    .test-dashboard {
        margin: 12px;
        padding: 22px;
        border-radius: 16px;
    }

    .test-topline,
    .test-dashboard-header,
    .test-bottom-nav {
        display: grid;
    }

    .test-code-form,
    .test-meta,
    .test-card-meta,
    .test-attempt-topbar,
    .test-progress-block {
        grid-template-columns: 1fr;
    }

    .test-question-card {
        min-height: 0;
        padding: 24px 18px;
    }

    .test-bookmark-button {
        top: 18px;
        right: 18px;
    }

    .test-question-number {
        margin-bottom: 18px;
    }

    .test-question-text {
        padding-right: 42px;
        font-size: 23px;
    }

    .test-option {
        align-items: flex-start;
        min-height: 64px;
        gap: 14px;
        padding: 15px;
        font-size: 16px;
    }

    h1 {
        font-size: 32px;
    }
}
