:root {
    color-scheme: light;
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-soft: #edf3fa;
    --surface-raised: #ffffff;
    --text: #172335;
    --muted: #64748b;
    --line: #dbe3ee;
    --primary: #173b6d;
    --primary-hover: #0e2d56;
    --primary-soft: #e7effa;
    --accent: #db8439;
    --success: #17734b;
    --success-soft: #e6f5ed;
    --danger: #b33a46;
    --danger-soft: #fbeaec;
    --warning: #9a5e13;
    --warning-soft: #fff3dc;
    --shadow: 0 14px 36px rgba(28, 48, 79, .09);
    --radius: 18px;
    --radius-sm: 11px;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d1521;
    --surface: #141f2e;
    --surface-soft: #1a283a;
    --surface-raised: #182536;
    --text: #edf3fa;
    --muted: #a5b4c6;
    --line: #2c3b50;
    --primary: #78a9e8;
    --primary-hover: #9dc3f4;
    --primary-soft: #1b3658;
    --accent: #f0a35d;
    --success: #68d39d;
    --success-soft: #153c30;
    --danger: #ff8b96;
    --danger-soft: #48242a;
    --warning: #f1bd6e;
    --warning-soft: #45351d;
    --shadow: 0 18px 44px rgba(0, 0, 0, .28);
}

@media (prefers-color-scheme: dark) {
    html[data-theme="system"] {
        color-scheme: dark;
        --bg: #0d1521;
        --surface: #141f2e;
        --surface-soft: #1a283a;
        --surface-raised: #182536;
        --text: #edf3fa;
        --muted: #a5b4c6;
        --line: #2c3b50;
        --primary: #78a9e8;
        --primary-hover: #9dc3f4;
        --primary-soft: #1b3658;
        --accent: #f0a35d;
        --success: #68d39d;
        --success-soft: #153c30;
        --danger: #ff8b96;
        --danger-soft: #48242a;
        --warning: #f1bd6e;
        --warning-soft: #45351d;
        --shadow: 0 18px 44px rgba(0, 0, 0, .28);
    }
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.55;
}
a { color: var(--primary); text-decoration-thickness: .08em; text-underline-offset: .2em; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: .75rem 1rem; background: var(--surface); }
.skip-link:focus { top: 1rem; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 18%);
    background: color-mix(in srgb, var(--surface), transparent 5%);
    backdrop-filter: blur(14px);
}
.topbar__inner { max-width: 1180px; min-height: 72px; margin: 0 auto; padding: .65rem 1.2rem; display: flex; align-items: center; gap: 1.25rem; }
.brand { display: flex; align-items: center; gap: .7rem; color: var(--text); text-decoration: none; margin-right: auto; }
.brand__mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--primary); color: var(--surface); font-weight: 850; letter-spacing: -.04em; }
html[data-theme="dark"] .brand__mark { color: #0d1521; }
.brand__copy { display: flex; flex-direction: column; line-height: 1.2; }
.brand__copy strong { font-size: .98rem; }
.brand__copy small { color: var(--muted); font-size: .74rem; }
.desktop-nav { display: flex; align-items: center; gap: .15rem; }
.desktop-nav a { color: var(--muted); padding: .65rem .8rem; border-radius: 10px; text-decoration: none; font-weight: 650; font-size: .9rem; }
.desktop-nav a:hover, .desktop-nav a.is-active { color: var(--primary); background: var(--primary-soft); }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); cursor: pointer; }
.icon-button:hover { border-color: var(--primary); }

.container { width: min(1120px, calc(100% - 2rem)); margin: 0 auto; padding: 2.1rem 0 4rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-head h1, .hero h1 { margin: 0; font-size: clamp(1.75rem, 4vw, 2.65rem); line-height: 1.12; letter-spacing: -.035em; }
.page-head p, .hero p { color: var(--muted); margin: .45rem 0 0; }
.eyebrow { margin: 0 0 .4rem; color: var(--accent); font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

.grid { display: grid; gap: 1rem; }
.grid--stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--two { grid-template-columns: minmax(0, 1.5fr) minmax(280px, .8fr); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.card--flat { box-shadow: none; }
.stat-card { min-height: 132px; display: flex; flex-direction: column; justify-content: space-between; }
.stat-card__label { color: var(--muted); font-weight: 650; font-size: .88rem; }
.stat-card__value { display: block; font-size: clamp(1.65rem, 4vw, 2.35rem); font-weight: 850; letter-spacing: -.04em; }
.stat-card__meta { color: var(--muted); font-size: .82rem; }
.section { margin-top: 1.6rem; }
.section__head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .8rem; }
.section__head h2 { margin: 0; font-size: 1.16rem; }
.section__head a { font-size: .88rem; }

.study-action { position: relative; min-height: 154px; display: flex; flex-direction: column; align-items: flex-start; overflow: hidden; text-decoration: none; color: var(--text); }
.study-action::after { content: "→"; position: absolute; right: 1.25rem; bottom: .9rem; font-size: 1.5rem; color: var(--primary); }
.study-action:hover { border-color: color-mix(in srgb, var(--primary), var(--line) 55%); transform: translateY(-1px); }
.study-action h3 { margin: .2rem 0 .3rem; font-size: 1.15rem; }
.study-action p { color: var(--muted); margin: 0; max-width: 35rem; font-size: .9rem; }
.study-action__count { display: inline-flex; align-items: center; min-height: 27px; padding: .15rem .55rem; border-radius: 999px; color: var(--primary); background: var(--primary-soft); font-size: .78rem; font-weight: 800; }
.study-action--review .study-action__count { color: var(--danger); background: var(--danger-soft); }

.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .45rem; border: 1px solid transparent; border-radius: 11px; padding: .65rem 1rem; background: var(--primary); color: white; text-decoration: none; font-weight: 750; cursor: pointer; }
.button:hover { background: var(--primary-hover); }
.button--secondary { border-color: var(--line); background: var(--surface); color: var(--text); }
.button--secondary:hover { background: var(--surface-soft); }
.button--danger { background: var(--danger); color: #fff; }
.button--danger:hover { filter: brightness(.9); }
.button--ghost { background: transparent; color: var(--primary); padding-inline: .5rem; }
.button--ghost:hover { background: var(--primary-soft); }
.button--full { width: 100%; }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: .7rem; }

.alert { margin-bottom: 1rem; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .8rem 1rem; background: var(--surface); }
.alert--success { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success), transparent 65%); }
.alert--error { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger), transparent 65%); }
.alert--warning { color: var(--warning); background: var(--warning-soft); }
.alert--info { color: var(--primary); background: var(--primary-soft); }

.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field label, .field legend { font-weight: 700; font-size: .9rem; }
.field small, .help { color: var(--muted); }
.input, .select, .textarea { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 10px; padding: .68rem .78rem; background: var(--surface); color: var(--text); }
.textarea { min-height: 108px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 3px solid color-mix(in srgb, var(--primary), transparent 76%); border-color: var(--primary); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.checkbox { display: flex; align-items: flex-start; gap: .6rem; }
.checkbox input { width: 20px; height: 20px; margin-top: .15rem; accent-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid .span-two { grid-column: 1 / -1; }

.login-shell { min-height: calc(100vh - 170px); display: grid; place-items: center; padding-block: 2rem; }
.login-card { width: min(430px, 100%); padding: clamp(1.35rem, 4vw, 2rem); }
.login-card h1 { margin: 0; font-size: 1.7rem; }
.login-card > p { color: var(--muted); margin: .4rem 0 1.5rem; }

.session-shell { width: min(820px, 100%); margin: 0 auto; }
.session-top { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: .7rem; }
.session-top strong { font-size: .9rem; }
.session-top span { color: var(--muted); font-size: .85rem; }
progress { width: 100%; height: 10px; border: 0; border-radius: 999px; overflow: hidden; background: var(--surface-soft); }
progress::-webkit-progress-bar { background: var(--surface-soft); }
progress::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 999px; }
.question-card { margin-top: 1.2rem; padding: clamp(1.1rem, 3.5vw, 2rem); }
.question-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: 1rem; color: var(--muted); font-size: .78rem; font-weight: 700; }
.question-card h1 { margin: 0 0 1.35rem; font-size: clamp(1.3rem, 3vw, 1.75rem); line-height: 1.35; letter-spacing: -.018em; }
.answers { display: grid; gap: .7rem; border: 0; padding: 0; margin: 0; }
.answer { position: relative; display: grid; grid-template-columns: 42px 1fr; align-items: start; gap: .8rem; border: 1px solid var(--line); border-radius: 14px; padding: .9rem; background: var(--surface); cursor: pointer; }
.answer:hover { border-color: var(--primary); background: var(--primary-soft); }
.answer--choice { width: 100%; color: var(--text); font: inherit; text-align: left; }
.answer--choice:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary), transparent 68%); outline-offset: 2px; }
.answer--choice:active { transform: scale(.995); }
.answer input { position: absolute; opacity: 0; pointer-events: none; }
.answer__letter { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--surface-soft); color: var(--primary); font-weight: 850; }
.answer input:checked + .answer__letter { background: var(--primary); color: #fff; }
.answer:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary), transparent 72%); }
.answer__text { padding-top: .35rem; }
.question-actions { margin-top: 1.1rem; display: flex; justify-content: space-between; align-items: center; gap: .7rem; }
.result { border-radius: 14px; padding: 1rem; margin-bottom: 1rem; }
.result h2 { margin: 0 0 .25rem; font-size: 1.2rem; }
.result p { margin: 0; }
.result--correct { background: var(--success-soft); color: var(--success); }
.result--wrong { background: var(--danger-soft); color: var(--danger); }
.answer--correct { border-color: var(--success); background: var(--success-soft); }
.answer--wrong { border-color: var(--danger); background: var(--danger-soft); }
.session-summary { text-align: center; padding: clamp(1.5rem, 5vw, 3rem); }
.session-summary__score { display: block; margin: .5rem 0; font-size: clamp(2.5rem, 8vw, 4.5rem); font-weight: 900; letter-spacing: -.06em; color: var(--primary); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: .8rem .9rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .045em; }
tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; gap: .45rem; justify-content: flex-end; }
.pill { display: inline-flex; padding: .18rem .55rem; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: .75rem; font-weight: 750; white-space: nowrap; }
.pill--success { color: var(--success); background: var(--success-soft); }
.pill--danger { color: var(--danger); background: var(--danger-soft); }
.category-list { display: grid; gap: .85rem; }
.category-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(160px, .55fr) 86px; gap: 1rem; align-items: center; }
.category-row strong { display: block; }
.category-row small { color: var(--muted); }
.category-row__score { text-align: right; font-weight: 800; }
.filter-bar { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(180px, .55fr) minmax(130px, .35fr) auto; gap: .65rem; margin-bottom: 1rem; }
.pagination { display: flex; justify-content: center; gap: .4rem; margin-top: 1rem; }
.pagination a, .pagination span { min-width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; text-decoration: none; background: var(--surface); }
.pagination .is-current { background: var(--primary); border-color: var(--primary); color: #fff; }
.danger-zone { border-color: color-mix(in srgb, var(--danger), transparent 45%); }
.danger-zone h2 { color: var(--danger); }
.muted { color: var(--muted); }
.empty { padding: 2rem; text-align: center; color: var(--muted); }
.mobile-nav { display: none; }

@media (max-width: 850px) {
    .desktop-nav { display: none; }
    .grid--stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid--two { grid-template-columns: 1fr; }
    .category-row { grid-template-columns: 1fr 96px; }
    .category-row progress { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 620px) {
    .topbar__inner { min-height: 62px; padding-inline: .8rem; }
    .brand__mark { width: 38px; height: 38px; }
    .brand__copy small { display: none; }
    .container { width: min(100% - 1.2rem, 1120px); padding-top: 1.25rem; }
    .with-mobile-nav { padding-bottom: calc(6.5rem + env(safe-area-inset-bottom)); }
    .page-head { align-items: flex-start; flex-direction: column; }
    .grid--actions, .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-two { grid-column: auto; }
    .study-action { min-height: 142px; }
    .card { border-radius: 15px; padding: 1rem; box-shadow: none; }
    .stat-card { min-height: 112px; }
    .filter-bar { grid-template-columns: 1fr; }
    .filter-bar .button { width: 100%; }
    .question-card { padding: 1rem; }
    .answer { grid-template-columns: 38px 1fr; padding: .8rem; }
    .question-actions { align-items: stretch; flex-direction: column-reverse; }
    .question-actions .button { width: 100%; }
    .mobile-nav {
        position: fixed;
        z-index: 40;
        left: .55rem;
        right: .55rem;
        bottom: calc(.55rem + env(safe-area-inset-bottom));
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
        padding: .35rem;
        border: 1px solid var(--line);
        border-radius: 17px;
        background: color-mix(in srgb, var(--surface), transparent 4%);
        box-shadow: 0 14px 38px rgba(0, 0, 0, .2);
        backdrop-filter: blur(16px);
    }
    .mobile-nav a { min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .05rem; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 750; }
    .mobile-nav a span { font-size: 1.05rem; }
    .mobile-nav a.is-active { color: var(--primary); background: var(--primary-soft); }
    .table-wrap table { min-width: 680px; }
}

@media (max-width: 390px) {
    .grid--stats { grid-template-columns: 1fr 1fr; gap: .65rem; }
    .stat-card__label { font-size: .78rem; }
    .stat-card__value { font-size: 1.55rem; }
}

@media (prefers-reduced-motion: no-preference) {
    .card, .button, .answer { transition: background-color .16s ease, border-color .16s ease, transform .16s ease; }
}
