:root {
    --ink: #1d3557;
    --muted: #4a6280;
    --paper: #fff6ea;
    --card: #ffffff;
    --sky: #4c8dff;
    --sun: #ffb703;
    --coral: #fb8500;
    --mint: #2a9d8f;
    --rose: #e63946;
    --line: #ffe0b8;
}

html, body {
    min-height: 100%;
}

body.kid-theme {
    font-family: Nunito, "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 8%, #ffe8a3 0, transparent 28%),
        radial-gradient(circle at 90% 4%, #b9dcff 0, transparent 26%),
        radial-gradient(circle at 80% 90%, #c8f3e4 0, transparent 30%),
        linear-gradient(180deg, #fff8ef 0%, #eef6ff 100%);
    margin-bottom: 0;
}

h1, h2, h3, .navbar-brand, .eyebrow {
    font-family: Nunito, sans-serif;
    font-weight: 800;
}

.site-header {
    background: linear-gradient(90deg, #4c8dff 0%, #6aa4ff 55%, #3ecfb2 100%);
    box-shadow: 0 8px 20px rgba(29, 53, 87, 0.12);
}

.site-header .navbar-brand,
.site-header .nav-link {
    color: #fff;
    font-weight: 800;
}

.site-header .nav-link:hover {
    color: #fff7d6;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: var(--sun);
    color: var(--ink);
    font-size: 20px;
    box-shadow: 0 4px 0 #e09a00;
}

.site-header .navbar-toggler {
    border-color: rgba(255, 255, 255, 0.55);
}

.site-header .navbar-toggler-icon {
    filter: invert(1);
}

.site-main {
    min-height: calc(100vh - 140px);
}

.site-footer {
    padding: 20px 0 28px;
    color: var(--muted);
    font-size: 15px;
    font-weight: 700;
}

.panel-card,
.metric-card,
.hero-panel {
    background: var(--card);
    border: 3px solid #ffe1b5;
    border-radius: 24px;
    box-shadow: 0 10px 0 rgba(251, 133, 0, 0.08);
}

.panel-card {
    padding: 24px;
}

.hero-panel {
    padding: 36px;
}

.hero-panel h1 {
    font-size: clamp(1.9rem, 4vw, 2.8rem);
    margin-bottom: 12px;
}

.lead-text {
    color: var(--muted);
    font-size: 1.15rem;
    font-weight: 700;
}

.eyebrow {
    letter-spacing: 0.04em;
    font-size: 13px;
    color: var(--coral);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.btn-accent,
.btn-ghost,
.btn-danger-ghost {
    border-radius: 999px;
    font-weight: 800;
    padding: 10px 18px;
}

.btn-accent {
    background: var(--coral);
    border: 0;
    color: #fff;
    box-shadow: 0 4px 0 #d56d00;
}

.btn-accent:hover {
    background: #e07700;
    color: #fff;
}

.btn-ghost {
    background: #fff;
    border: 3px solid #d7e7ff;
    color: var(--ink);
}

.btn-ghost:hover,
.site-header .btn-ghost:hover {
    background: #fff7d6;
    color: var(--ink);
}

.site-header .btn-ghost {
    color: #fff;
    background: transparent;
    border-color: rgba(255, 255, 255, 0.45);
}

.site-header.is-panel {
    background: #1d3557;
    box-shadow: 0 10px 24px rgba(29, 53, 87, 0.18);
}

.site-header.is-panel .navbar {
    padding: 10px 0;
}

.panel-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.site-header.is-panel .navbar-collapse {
    flex-grow: 1;
    align-items: center;
    gap: 12px;
}

.panel-menu {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 auto;
    padding: 0;
}

.panel-menu .nav-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    color: rgba(255, 255, 255, 0.82) !important;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.2;
}

.panel-menu .nav-link i {
    font-size: 16px;
}

.panel-menu .nav-link:hover {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.12);
}

.panel-menu .nav-link.is-active {
    color: #1d3557 !important;
    background: #fff;
    box-shadow: 0 4px 0 rgba(255, 183, 3, 0.85);
}

.panel-user {
    margin-left: auto;
}

.panel-user-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 6px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-family: inherit;
}

.panel-user-toggle::after {
    margin-left: 4px;
    opacity: 0.8;
}

.panel-user-toggle:hover,
.panel-user-toggle[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.2);
}

.panel-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--sun);
    color: var(--ink);
    font-weight: 800;
    flex-shrink: 0;
}

.panel-user-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.15;
    text-align: left;
}

.panel-user-meta strong {
    font-size: 14px;
    font-weight: 800;
}

.panel-user-meta small {
    color: #d7e7ff;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.panel-user-menu {
    min-width: 240px;
    padding: 10px;
    border: 0;
    border-radius: 20px;
    box-shadow: 0 16px 32px rgba(29, 53, 87, 0.18);
}

.panel-user-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 6px;
}

.panel-user-summary strong,
.panel-user-summary small {
    display: block;
}

.panel-user-summary small {
    color: var(--muted);
    font-weight: 800;
}

.panel-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 0;
    border-radius: 14px;
    font-weight: 800;
    color: var(--rose);
}

.panel-logout:hover,
.panel-logout:focus {
    background: #ffe1e1;
    color: var(--rose);
}

.btn-danger-ghost {
    background: #fff;
    border: 3px solid #ffd0d0;
    color: var(--rose);
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 24px;
}

.excel-import {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.excel-import .form-control {
    max-width: 360px;
}

.page-head h1 {
    margin: 0;
}

.metric-card {
    padding: 18px;
}

.metric-card span {
    display: block;
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
}

.metric-card strong {
    font-size: 30px;
}

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-grid article {
    background: #fff;
    border: 3px solid #d7e7ff;
    border-radius: 20px;
    padding: 16px;
}

.stat-grid i {
    color: var(--sky);
    font-size: 26px;
}

.stat-grid h3 {
    font-size: 16px;
    margin: 8px 0 4px;
}

.stat-grid p,
.info-strip {
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.info-strip {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 16px 20px;
    border: 3px dashed #ffd79a;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.7);
}

.status-pill {
    display: inline-flex;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 800;
}

.status-pill.is-on {
    background: #d8f3e8;
    color: #1b7a57;
}

.status-pill.is-off {
    background: #ffe1e1;
    color: #b42318;
}

.html-content {
    font-size: 1.05rem;
    overflow-wrap: break-word;
}

.html-content img,
.html-content video,
.html-content iframe {
    max-width: 100%;
    height: auto;
}

.html-content table {
    display: block;
    width: 100%;
    overflow-x: auto;
}

.html-content p:last-child {
    margin-bottom: 0;
}

.option-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 10px;
}

.option-list li,
.choice {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border: 3px solid #d7e7ff;
    border-radius: 18px;
    background: #fff;
}

.option-list li.is-correct,
.choice:has(input:checked) {
    border-color: #7ed9c4;
    background: #f0fffb;
    box-shadow: 0 6px 0 rgba(42, 157, 143, 0.12);
}

.option-list li.is-wrong {
    border-color: #ffb4b4;
    background: #fff5f5;
}

.option-letter,
.choice-letter {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--sky);
    color: #fff;
    font-size: 15px;
    font-weight: 800;
    flex-shrink: 0;
}

.explanation-box {
    background: #fff6d9;
    border: 3px solid #ffe08a;
    border-radius: 16px;
    padding: 14px 16px;
}

.exam-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.exam-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #eef5ff;
    border: 2px solid #d7e7ff;
    border-radius: 999px;
    padding: 8px 14px;
    font-weight: 800;
    color: var(--ink);
}

.exam-list {
    display: grid;
    gap: 14px;
}

.exam-list-item {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px 18px;
    padding: 16px 18px;
    border: 2px solid #e6eef8;
    border-radius: 18px;
    background: #fbfcff;
}

.exam-list-main {
    flex: 1 1 280px;
    min-width: 0;
}

.exam-list-title {
    margin: 0 0 10px;
    font-size: 1.05rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.exam-list-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.exam-list-meta .exam-chip,
.exam-list-meta .status-pill {
    padding: 5px 10px;
    font-size: 12px;
}

.exam-list-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    max-width: 100%;
}

.exam-list-actions form {
    display: inline;
    margin: 0;
}

.exam-list-actions .btn {
    margin: 0;
}

.step-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.step-item {
    background: #fff7e8;
    border: 2px solid #ffe1b5;
    border-radius: 16px;
    padding: 12px;
    text-align: center;
    font-weight: 800;
    font-size: 14px;
}

.step-item span {
    display: block;
    color: var(--coral);
    font-size: 12px;
}

.kid-form .form-control,
.kid-theme .form-control,
.kid-form .form-select,
.kid-theme .form-select {
    border: 3px solid #d7e7ff;
    border-radius: 16px;
    padding: 12px 14px;
    font-weight: 700;
    font-size: 16px;
}

.kid-form .form-control:focus,
.kid-theme .form-control:focus,
.kid-form .form-select:focus,
.kid-theme .form-select:focus {
    border-color: var(--sky);
    box-shadow: 0 0 0 0.2rem rgba(76, 141, 255, 0.18);
}

.kid-form .form-label {
    font-weight: 800;
}

.hp-field {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

body.exam-mode {
    background:
        radial-gradient(circle at 8% 0%, #ffe8a3 0, transparent 24%),
        linear-gradient(180deg, #eaf4ff 0%, #fff8ef 100%);
    margin: 0;
}

body.exam-secure,
body.exam-mode {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body.exam-secure input,
body.exam-secure textarea,
body.exam-secure select {
    -webkit-user-select: text;
    user-select: text;
}

body.exam-secure img,
body.exam-mode img {
    -webkit-user-drag: none;
}

body.exam-print-block {
    visibility: hidden !important;
}

@media print {
    body.exam-secure,
    body.exam-mode {
        visibility: hidden !important;
    }
}

.exam-watermark {
    pointer-events: none;
    position: fixed;
    inset: -20%;
    z-index: 5;
    overflow: hidden;
    opacity: 0.08;
    color: var(--ink);
    font-weight: 800;
    font-size: 22px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    transform: rotate(-18deg);
}

.exam-watermark::before {
    content: attr(data-name) "  •  " attr(data-name) "  •  " attr(data-name) "  •  " attr(data-name) "  •  " attr(data-name);
    display: block;
    line-height: 4.2;
    white-space: pre-wrap;
    word-break: break-all;
}

.exam-focus-lock {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(29, 53, 87, 0.72);
    display: grid;
    place-items: center;
    padding: 24px;
}

.exam-focus-lock[hidden] {
    display: none !important;
}

.exam-focus-lock-card {
    background: #fff;
    border-radius: 24px;
    padding: 28px 24px;
    text-align: center;
    max-width: 360px;
    border: 3px solid #ffe1b5;
}

.exam-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    background: linear-gradient(90deg, #1d3557 0%, #3a6ea5 100%);
    color: #fff;
}

.exam-sticky {
    position: sticky;
    top: 0;
    z-index: 30;
}

.exam-topbar-left {
    min-width: 0;
    flex: 1 1 160px;
}

.exam-topbar-left strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(42vw, 420px);
}

.exam-topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.exam-jump {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 24px;
    background: #f4f8ff;
    border-bottom: 2px solid #d7e7ff;
}

.exam-jump-number {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    color: var(--ink);
    margin: 0;
}

.exam-jump-number input {
    width: 72px;
    height: 40px;
    border: 3px solid #d7e7ff;
    border-radius: 12px;
    text-align: center;
    font-weight: 800;
    font-size: 16px;
}

.exam-jump-select {
    min-width: 150px;
    max-width: 240px;
    height: 40px;
    font-weight: 800;
    font-size: 16px;
    border: 3px solid #d7e7ff;
    border-radius: 12px;
}

.exam-shell {
    display: grid;
    grid-template-columns: minmax(92px, 168px) 1fr;
    gap: 20px;
    padding: 24px;
    max-width: 1100px;
    margin: 0 auto;
}

.question-nav {
    position: sticky;
    top: calc(var(--exam-sticky-height, 148px) + 12px);
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    align-content: start;
    gap: 8px;
    max-height: calc(100vh - var(--exam-sticky-height, 148px) - 24px);
    overflow: auto;
    padding-right: 4px;
}

.q-dot {
    width: 40px;
    height: 40px;
    min-width: 40px;
    flex-shrink: 0;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    border: 3px solid #d7e7ff;
    font-weight: 800;
    font-size: 13px;
}

.q-dot.is-done {
    background: var(--mint);
    color: #fff;
    border-color: var(--mint);
}

.q-dot.is-current {
    border-color: var(--coral);
    box-shadow: 0 0 0 2px rgba(251, 133, 0, 0.25);
}

.question-card {
    margin-bottom: 16px;
    scroll-margin-top: calc(var(--exam-sticky-height, 160px) + 12px);
}

.exam-topbar .small {
    color: #d7e7ff !important;
    font-weight: 800;
}

.exam-timer {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    padding: 8px 16px;
    min-width: 112px;
}

.exam-timer-label {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #d7e7ff;
}

.exam-timer strong {
    font-size: 28px;
    font-weight: 800;
}

.exam-timer.is-low {
    background: var(--rose);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    50% { transform: scale(1.04); }
}

.exam-progress {
    min-width: 160px;
}

.exam-progress .progress {
    height: 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
}

.exam-progress .progress-bar {
    background: var(--sun);
}

.option-choices {
    display: grid;
    gap: 10px;
}

.choice {
    cursor: pointer;
    transition: transform 0.12s ease;
}

.choice:hover {
    transform: translateY(-2px);
}

.choice input {
    margin-top: 8px;
    width: 1.15em;
    height: 1.15em;
}

.score-ring {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    border: 10px solid var(--sun);
    background: #fffdf4;
}

.score-ring strong {
    font-size: 46px;
    line-height: 1;
}

.result-emoji {
    font-size: 48px;
}

.kid-toasts {
    z-index: 2000;
}

.kid-toasts .toast {
    border: 0;
    border-radius: 18px;
    font-weight: 800;
    min-width: 280px;
}

.table > :not(caption) > * > * {
    background: transparent;
}

code {
    background: #eef2f6;
    padding: 2px 6px;
    border-radius: 6px;
    word-break: break-all;
}

@media (max-width: 991.98px) {
    .exam-shell {
        grid-template-columns: 1fr;
        padding: 16px;
        gap: 12px;
    }

    .question-nav {
        position: static;
        display: flex;
        flex-wrap: nowrap;
        max-height: none;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 2px 2px 8px;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 768px) {
    .hero-panel {
        padding: 20px;
    }

    .panel-card {
        padding: 16px;
    }

    .stat-grid,
    .step-list {
        grid-template-columns: 1fr;
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .page-head .d-flex {
        flex-wrap: wrap;
    }

    .site-header .navbar-nav {
        padding: 10px 0 8px;
        width: 100%;
    }

    .panel-menu {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin: 0 0 12px;
    }

    .panel-menu .nav-link {
        width: 100%;
        justify-content: flex-start;
        padding: 12px 14px;
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.08);
    }

    .panel-user {
        width: 100%;
        margin: 0 0 8px;
    }

    .panel-user-toggle,
    .site-header .nav-link,
    .site-header .btn-ghost {
        display: flex;
        width: 100%;
        text-align: left;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .panel-user-menu {
        width: 100%;
    }

    .exam-topbar {
        flex-wrap: wrap;
        padding: 12px 14px;
        gap: 10px;
    }

    .exam-topbar-left {
        flex: 1 1 calc(100% - 140px);
    }

    .exam-topbar-left strong {
        max-width: 100%;
    }

    .exam-progress {
        min-width: 0;
        width: 100%;
        order: 3;
        text-align: left !important;
    }

    .exam-topbar-right {
        margin-left: 0;
        gap: 8px;
    }

    .exam-timer {
        min-width: 96px;
        padding: 6px 12px;
    }

    .exam-timer strong {
        font-size: 22px;
    }

    .exam-jump {
        padding: 8px 12px;
    }

    .exam-jump-select {
        flex: 1 1 100%;
        max-width: none;
    }

    .exam-jump-label {
        display: none;
    }

    .exam-shell {
        padding: 12px;
    }

    #open-finish-modal {
        padding: 8px 12px;
        font-size: 14px;
        white-space: nowrap;
    }

    .choice:hover {
        transform: none;
    }

    .choice {
        min-height: 48px;
    }

    .table .text-nowrap {
        white-space: normal !important;
    }

    .table .btn {
        margin: 0 4px 6px 0;
    }

    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-footer .btn {
        flex: 1 1 100%;
    }

    .score-ring {
        width: 132px;
        height: 132px;
    }

    .score-ring strong {
        font-size: 36px;
    }

    .kid-toasts .toast {
        min-width: 0;
        width: calc(100vw - 24px);
    }

    .kid-form .btn-lg {
        width: 100%;
    }

    .result-hero h1 {
        font-size: 1.5rem;
    }
}
