:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-2: #f0f2f8;
    --text: #1b2333;
    --muted: #5d6778;
    --border: #dfe3ec;
    --primary: #1f5eff;
    --primary-ink: #ffffff;
    --primary-soft: #e7eeff;
    --success: #13804b;
    --success-soft: #e3f5ea;
    --danger: #c0392b;
    --danger-soft: #fdecea;
    --warning: #9a6200;
    --warning-soft: #fff4dc;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .05);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1420;
        --surface: #171e2d;
        --surface-2: #1f2839;
        --text: #e8ecf4;
        --muted: #9aa5b8;
        --border: #2c3649;
        --primary: #6b96ff;
        --primary-ink: #0f1420;
        --primary-soft: #1d2a4d;
        --success: #4fd08b;
        --success-soft: #15301f;
        --danger: #ff7b6e;
        --danger-soft: #3a1c1a;
        --warning: #ffc560;
        --warning-soft: #3a2c10;
        --shadow: none;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.55 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 1em; }

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.container-narrow { max-width: 760px; }

.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.site-header .container { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.15rem; color: var(--text); letter-spacing: -.01em; }
.brand span { color: var(--primary); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px 14px; align-items: center; flex-wrap: wrap; margin-left: auto; font-size: .95rem; }
.nav a, .nav button { color: var(--muted); }
.nav a.active { color: var(--text); font-weight: 600; }
.nav a.btn { color: var(--primary-ink); }
.link-button { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; color: var(--primary); }

main { padding: 28px 0 56px; min-height: 60vh; }

.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .9rem; padding: 24px 0 40px; }

.notice { background: var(--warning-soft); color: var(--warning); padding: 10px 0; font-size: .95rem; }

.flash { border-radius: 10px; padding: 12px 16px; margin-bottom: 20px; }
.flash-status { background: var(--success-soft); color: var(--success); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-title { margin-top: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }

.hero { padding: 24px 0 8px; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); letter-spacing: -.02em; }
.hero p { font-size: 1.1rem; color: var(--muted); max-width: 640px; }

.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 42px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent;
    font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
    background: var(--primary); color: var(--primary-ink);
}
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { min-height: 34px; padding: 0 12px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

form.inline { display: inline; }

label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .95rem; }
.field { margin-bottom: 16px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .86rem; margin-top: 4px; }
.error { color: var(--danger); font-size: .88rem; margin-top: 4px; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=tel], input[type=search], select, textarea {
    width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: 18px; height: 18px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }

.exam-card h3 { margin-bottom: 4px; }
.exam-card .meta { color: var(--muted); font-size: .9rem; margin-bottom: 12px; }

.price { font-size: 1.6rem; font-weight: 800; }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }
.progress.good > span { background: var(--success); }
.progress.bad > span { background: var(--danger); }

/* Test taking */
.test-bar { position: sticky; top: 60px; z-index: 10; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.25rem; }
.timer.low { color: var(--danger); }
.save-state { font-size: .85rem; color: var(--muted); }

.question { scroll-margin-top: 140px; }
.question-number { font-weight: 700; color: var(--muted); font-size: .9rem; margin-bottom: 6px; }
.question-body { font-size: 1.05rem; margin-bottom: 14px; overflow-x: auto; }
.question-body img { max-width: 100%; height: auto; }
.question-body table { width: auto; min-width: 280px; margin-bottom: 4px; }
.question-body td { font-size: 1.12rem; text-align: center; padding: 12px 28px; }
.question-body th { text-align: center; padding: 8px 28px; }

.options { display: grid; gap: 8px; }
.option { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; font-weight: 400; margin: 0; background: var(--surface); }
.option:hover { border-color: var(--primary); }
.option input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
.option .letter { font-weight: 700; color: var(--muted); }
.option.correct { border-color: var(--success); background: var(--success-soft); }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); }
.option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }

.qnav { display: flex; flex-wrap: wrap; gap: 6px; }
.qnav a { display: inline-flex; width: 34px; height: 34px; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid var(--border); color: var(--muted); font-size: .85rem; font-weight: 600; background: var(--surface); }
.qnav a.answered { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-soft); }
.qnav a:hover { text-decoration: none; border-color: var(--primary); }

.explanation { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); }

.score-big { font-size: 3rem; font-weight: 800; letter-spacing: -.02em; line-height: 1; }

.admin-nav { display: flex; gap: 6px 16px; flex-wrap: wrap; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--border); font-size: .95rem; }
.admin-nav a.active { font-weight: 700; color: var(--text); }

.pagination { display: flex; gap: 6px; flex-wrap: wrap; list-style: none; padding: 0; margin: 16px 0 0; }
.pagination li > * { display: inline-block; padding: 6px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.pagination li.active > * { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.pagination li.disabled > * { color: var(--muted); }

code, pre { background: var(--surface-2); border-radius: 6px; padding: 2px 6px; font-size: .9em; }
pre { padding: 12px; overflow-x: auto; }

@media (max-width: 640px) {
    h1 { font-size: 1.45rem; }
    .card { padding: 16px; }
    .test-bar { top: 0; border-radius: 0; margin-left: -16px; margin-right: -16px; }
    .site-header { position: static; }
}
