:root {
    color-scheme: light dark;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --fg: #1b2430;
    --muted: #5b6776;
    --border: #e0e5ec;
    --accent: #336791;
    --accent-hover: #2a5578;
    --accent-fg: #ffffff;
    --ok: #1f8a4c;
    --ok-bg: #e6f4ec;
    --bad: #c0392b;
    --bad-bg: #fbeaea;
    --radius: 16px;
}

/* Тема из профиля (users.theme): data-theme="light" или "dark" задаёт её явно, без атрибута — как в системе.
   Атрибут ставит public/js/accent.js. Тёмные значения повторены для системной и для явно выбранной тёмной темы. */

:root[data-theme="light"] {
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #121417;
        --surface: #1b1f24;
        --fg: #e6e9ee;
        --muted: #98a2b0;
        --border: #2c333b;
        --accent: #78acd7;
        --accent-hover: #94bfe2;
        --accent-fg: #0f2030;
        --ok: #4cc38a;
        --ok-bg: #14291f;
        --bad: #ff7b72;
        --bad-bg: #2e1a1a;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121417;
    --surface: #1b1f24;
    --fg: #e6e9ee;
    --muted: #98a2b0;
    --border: #2c333b;
    --accent: #78acd7;
    --accent-hover: #94bfe2;
    --accent-fg: #0f2030;
    --ok: #4cc38a;
    --ok-bg: #14291f;
    --bad: #ff7b72;
    --bad-bg: #2e1a1a;
}

/* Цвет кнопок и ссылок из профиля (users.accent); атрибут ставит public/js/accent.js. Синий — значения выше. */

:root[data-accent="beige"] {
    --accent: #8a6a3f;
    --accent-hover: #74572f;
    --accent-fg: #ffffff;
}

:root[data-accent="green"] {
    --accent: #2e6b52;
    --accent-hover: #255845;
    --accent-fg: #ffffff;
}

:root[data-accent="graphite"] {
    --accent: #454f5a;
    --accent-hover: #37404a;
    --accent-fg: #ffffff;
}

@media (prefers-color-scheme: dark) {
    :root[data-accent="beige"]:not([data-theme="light"]) {
        --accent: #e8c98a;
        --accent-hover: #f0d6a2;
        --accent-fg: #1e1a14;
    }

    :root[data-accent="green"]:not([data-theme="light"]) {
        --accent: #6fb59a;
        --accent-hover: #82c4aa;
        --accent-fg: #0d1a14;
    }

    :root[data-accent="graphite"]:not([data-theme="light"]) {
        --accent: #9aa5b1;
        --accent-hover: #adb7c2;
        --accent-fg: #12161a;
    }
}

:root[data-theme="dark"][data-accent="beige"] {
    --accent: #e8c98a;
    --accent-hover: #f0d6a2;
    --accent-fg: #1e1a14;
}

:root[data-theme="dark"][data-accent="green"] {
    --accent: #6fb59a;
    --accent-hover: #82c4aa;
    --accent-fg: #0d1a14;
}

:root[data-theme="dark"][data-accent="graphite"] {
    --accent: #9aa5b1;
    --accent-hover: #adb7c2;
    --accent-fg: #12161a;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    padding: 32px 16px 64px;
    background: var(--bg);
    color: var(--fg);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 17px;
    line-height: 1.55;
}

main {
    max-width: 720px;
    margin: 0 auto;
}

h1 {
    margin: 0 0 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 1.6rem;
    line-height: 1.25;
}

h2 {
    margin: 0 0 16px;
    font-size: 1.15rem;
    color: var(--muted);
    font-weight: 600;
}

#error {
    margin-bottom: 16px;
    padding: 12px 16px;
    border: 1px solid var(--bad);
    border-radius: var(--radius);
    background: var(--bad-bg);
    color: var(--bad);
}

/* Категории */
.cards {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
}

.card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s;
}

.card::after {
    content: "›";
    font-size: 1.6rem;
    line-height: 1;
    color: var(--muted);
}

.card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

/* Вопрос */
.question {
    margin: 0 0 20px;
    font-size: 1.25rem;
    line-height: 1.45;
    font-weight: 600;
}

.options {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
}

.option {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}

.option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.option .badge {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 50%;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.option .text {
    padding-top: 2px;
    overflow-wrap: anywhere;
}

.option:hover {
    border-color: var(--accent);
}

.option:has(input:checked) {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.option:has(input:checked) .badge {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-fg);
}

.option:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.option.locked {
    cursor: default;
}

.option.locked.correct {
    border-color: var(--ok);
    background: var(--ok-bg);
}

.option.locked.correct .badge {
    background: var(--ok);
    border-color: var(--ok);
    color: var(--bg);
}

.option.locked.wrong {
    border-color: var(--bad);
    background: var(--bad-bg);
}

.option.locked.wrong .badge {
    background: var(--bad);
    border-color: var(--bad);
    color: var(--bg);
}

/* Результат */
.result {
    margin-top: 24px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.result p {
    margin: 0 0 8px;
}

.result .status {
    font-size: 1.15rem;
    font-weight: 700;
}

.result .status.ok {
    color: var(--ok);
}

.result .status.bad {
    color: var(--bad);
}

.result .explanation {
    margin-bottom: 16px;
    color: var(--muted);
}

/* Кнопки */
button {
    font: inherit;
}

.btn,
.btn-secondary {
    padding: 11px 22px;
    border-radius: var(--radius);
    border: 1px solid var(--accent);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn {
    background: var(--accent);
    color: var(--accent-fg);
}

.btn:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-secondary {
    background: transparent;
    color: var(--accent);
}

.btn-secondary:hover {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.card:focus-visible,
.btn:focus-visible,
.btn-secondary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

#back,
#check-back,
#finish-back,
#exam-setup-back,
#history-back {
    margin-bottom: 24px;
}

#finish-view p {
    margin: 0 0 16px;
    font-size: 1.15rem;
}

.card-name {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.card-count {
    margin-right: 12px;
    color: var(--muted);
    font-size: 0.9rem;
    white-space: nowrap;
}

.training-history-item {
    display: grid;
    gap: 6px;
    width: 100%;
    margin-bottom: 12px;
    text-align: left;
    overflow-wrap: anywhere;
}

.training-history-item span {
    color: var(--muted);
    font-size: 0.9rem;
}

.training-question h3 {
    margin-top: 0;
}

.progress {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 0.95rem;
}

fieldset {
    margin: 0 0 20px;
    padding: 0;
    border: 0;
}

legend {
    margin-bottom: 10px;
    padding: 0;
    color: var(--muted);
    font-weight: 600;
}

.chips {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.chip {
    padding: 10px 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}

.chip input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.chip:hover {
    border-color: var(--accent);
}

.chip:has(input:checked) {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.chip:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.option.check .badge {
    border-radius: 6px;
    color: transparent;
}

.option.check:has(input:checked) .badge {
    color: var(--accent-fg);
}

.exam-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.exam-bar .progress {
    margin: 0;
}

.timer {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.top-actions {
    margin: 0 0 24px;
}

.btn-secondary:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.history-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 12px;
    align-items: baseline;
}

.history-row .status {
    margin: 0;
    font-size: 1rem;
}

.history-date,
.history-time {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.score {
    margin: 0 0 4px;
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1.1;
}

.plain {
    margin: 0 0 24px;
    padding: 0;
    list-style: none;
}

.plain li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.error-card {
    margin-bottom: 12px;
}

.error-card .question {
    font-size: 1.05rem;
}

.hint {
    margin: -8px 0 16px;
    color: var(--accent);
    font-size: 0.95rem;
    font-weight: 600;
}

code,
pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 400;
}

code {
    padding: 1px 5px;
    border-radius: 5px;
    background: color-mix(in srgb, var(--fg) 10%, transparent);
    font-size: 0.92em;
}

pre {
    margin: 10px 0;
    padding: 12px 14px;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--fg) 6%, var(--surface));
    font-size: 0.92rem;
    line-height: 1.5;
    white-space: pre;
}

pre code {
    padding: 0;
    background: none;
    font-size: inherit;
}

.option.multi .badge {
    border-radius: 6px;
}

.answer-block p {
    margin: 0 0 4px;
}

.answer-line {
    margin: 0 0 6px 4px;
}

.option-note {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.45;
}

.option.locked.wrong .option-note {
    color: var(--bad);
}

.answer-line .option-note {
    margin-top: 2px;
}

/* Вход и пользователь */

.user-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin: -8px 0 20px;
}

.user-email {
    color: var(--muted);
    font-size: 0.95rem;
    overflow-wrap: anywhere;
}

.user-bar .btn-secondary {
    padding: 6px 14px;
}

.release {
    margin: 40px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}

.accent-picker {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 0.95rem;
}

.accent-picker select {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
}

.accent-picker select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 420px;
    margin-bottom: 16px;
}

.login-form input {
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
}

.login-form input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.login-form .btn {
    align-self: flex-start;
}

.link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    text-decoration: underline;
    cursor: pointer;
}

#login-sent-view p,
#privacy-view p,
.confirm-text {
    margin: 0 0 16px;
}

.resume {
    margin: 0 0 24px;
}

.resume p {
    margin: 0;
}

.resume .actions {
    margin-top: 14px;
}

.card-link {
    display: inline-block;
    margin: 6px 0 4px 4px;
    font-size: 0.95rem;
}

/* Материал для изучения */

.material {
    overflow-wrap: anywhere;
}

.material h2 {
    margin: 0 0 12px;
    font-size: 1.5rem;
    color: var(--fg);
}

.material h3 {
    margin: 36px 0 12px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    font-size: 1.3rem;
    color: var(--fg);
}

.material h4 {
    margin: 22px 0 8px;
    font-size: 1.05rem;
    color: var(--accent);
}

.material p,
.material ul {
    margin: 0 0 12px;
}

.material ul {
    padding-left: 22px;
}

.material li {
    margin-bottom: 6px;
}

/* Статистика */

.back {
    margin-bottom: 24px;
}

.table-wrap {
    margin: 0 0 28px;
    overflow-x: auto;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.stats-table th,
.stats-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.stats-table th {
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
}

.stats-table th.num,
.stats-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.stats-table tr.clickable {
    cursor: pointer;
}

.stats-table tr.clickable:hover td {
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.stats-table tr.clickable:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.hard-list {
    margin: 0 0 24px;
    padding-left: 24px;
}

.hard-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.hard-meta {
    color: var(--muted);
    font-size: 0.9rem;
}

@media (max-width: 480px) {
    body {
        padding: 20px 12px 48px;
        font-size: 16px;
    }

    h1 {
        font-size: 1.35rem;
    }

    .question {
        font-size: 1.1rem;
    }

    .card {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 4px 12px;
    }

    .card-name,
    .card-count {
        grid-column: 1;
    }

    .card-count {
        margin-right: 0;
    }

    .card::after {
        grid-column: 2;
        grid-row: 1 / span 2;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}

/* Режим «Подходит или нет» */
.mode-switch {
    display: flex;
    gap: 8px;
    margin: 0 0 20px;
}

.mode-btn {
    flex: 1 1 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.mode-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-fg);
}

.mode-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.check-label {
    margin: 0 0 8px;
    color: var(--muted);
}

.check-option {
    margin-bottom: 4px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow-wrap: anywhere;
}

.check-option.right {
    border-color: var(--ok);
    background: var(--ok-bg);
}

.check-option.wrong {
    border-color: var(--bad);
    background: var(--bad-bg);
}
/* Личный помощник: длинные SQL-фрагменты не расширяют карточку на мобильном экране. */
.ai-assistant { margin: 1rem 0; padding-top: 1rem; border-top: 1px solid var(--border); }
.ai-modes { margin: 0 0 1rem; padding: .7rem; border: 1px solid var(--border); border-radius: var(--radius); }
.ai-modes label { display: inline-flex; align-items: center; gap: .4rem; margin: .3rem .8rem .3rem 0; }
.ai-message { margin: 1rem 0; }
.ai-message-user {
    padding: .65rem .85rem;
    border-inline-start: 4px solid var(--accent);
    border-radius: 8px;
    background: color-mix(in srgb, var(--accent) 24%, var(--surface));
}
.ai-message-user > strong { color: color-mix(in srgb, var(--accent) 40%, var(--fg)); }
.ai-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-assistant > .hint { margin: 4px 0 0; }
.ai-loading::before { content: ''; display: inline-block; box-sizing: border-box;
    width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
    border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
    animation: ai-spin .8s linear infinite; }
@keyframes ai-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .ai-loading::before { animation: none; }
}
.ai-composer { padding: 16px 14px 12px; border: 1px solid var(--border); border-radius: 22px;
    background: var(--surface); box-shadow: 0 3px 16px #00000006; }
.ai-composer:focus-within { border-color: var(--accent); }
.ai-form textarea { display: block; box-sizing: border-box; width: 100%; min-height: 48px; max-height: 200px;
    margin: 0; padding: 0 2px; font: inherit; font-size: 16px; line-height: 24px;
    color: var(--fg); background: transparent; border: 0; border-radius: 0; resize: none; overflow-y: auto; }
.ai-form textarea:focus { outline: none; }
.ai-form textarea::placeholder { color: var(--muted); opacity: 1; }
.ai-send { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px;
    margin: 8px 0 0 auto; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
    background: var(--fg); color: var(--surface); }
.ai-send svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round; }
.ai-send:hover:not(:disabled) { opacity: .8; }
.ai-send:disabled { opacity: .35; cursor: not-allowed; }
.ai-send:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.ai-input-hint { margin: 10px 4px 0; color: var(--muted); font-size: .75rem; line-height: 1.5; text-align: center; }
.ai-sources a { display: block; margin: .4rem 0; overflow-wrap: anywhere; color: var(--accent); }

/* Основные разделы и компактные настройки аккаунта. */
.profile-menu { position: relative; display: block; margin: -8px 0 18px; text-align: right; }
.profile-menu summary { display: inline-block; cursor: pointer; padding: 7px 14px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted); }
.profile-menu summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.profile-panel { position: absolute; z-index: 20; right: 0; top: calc(100% + 8px); display: grid; gap: 14px; width: min(330px, calc(100vw - 32px)); padding: 20px; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 32px #0003; }
.profile-panel .accent-picker { justify-content: space-between; }
.profile-panel .user-email { overflow-wrap: anywhere; }
.main-nav { position: sticky; top: 12px; z-index: 15; display: flex; gap: 6px; margin: 0 0 28px; padding: 5px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.main-nav a { flex: 1; display: flex; justify-content: center; align-items: center; text-decoration: none; text-align: center; padding: 10px 6px; border-radius: 7px; color: var(--muted); font-size: .94rem; font-weight: 600; }
.main-nav a[aria-current="page"] { background: var(--accent); color: var(--accent-fg); }
.main-nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.result-links { display: grid; gap: 12px; }
.result-links button { text-align: left; }
#ai-view .ai-assistant { padding-top: 0; margin-top: 0; border-top: 0; }
@media (max-width: 600px) {
    body:has(#main-nav:not([hidden])) { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
    .main-nav { position: fixed; z-index: 15; top: auto; bottom: 0; left: 0; right: 0; margin: 0; border-radius: 0; padding: 7px 5px calc(7px + env(safe-area-inset-bottom)); gap: 2px; box-shadow: 0 -3px 16px #0002; }
    .main-nav a { padding: 11px 3px; font-size: .75rem; min-height: 46px; }
}

h2[tabindex="-1"]:focus { outline: none; }

#question-text, #check-question-text { scroll-margin-top: 100px; }
#question-text:focus, #check-question-text:focus { outline: none; }
@media (max-width: 600px) {
    #question-text, #check-question-text { scroll-margin-top: 20px; }
}

/* Компактная настройка и навигация экзамена без подсказок о верности. */
.exam-setup-summary { margin: 18px 0; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.exam-setup-summary p { margin: 0 0 8px; }
.exam-setup-summary .btn { margin-top: 6px; }
.exam-topics-settings, .exam-overview { margin: 18px 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); }
.exam-topics-settings summary, .exam-overview summary { cursor: pointer; min-height: 30px; font-weight: 600; }
.exam-topics-settings fieldset { margin-top: 16px; }
.exam-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; }
.exam-number { min-height: 52px; padding: 6px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--fg); cursor: pointer; font-weight: 600; }
.exam-number-status { display: block; font-size: .7rem; line-height: 1.2; color: var(--muted); }
.exam-number[data-state="answered"] { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.exam-number[data-state="skipped"]:not(.current) { border-style: dashed; }
.exam-number.current { border: 2px solid var(--accent); }
.exam-number:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.exam-number:disabled { opacity: .5; cursor: default; }
.exam-bar { scroll-margin-top: 100px; }
#exam-question:focus { outline: none; }
@media (max-width: 600px) { .exam-bar { scroll-margin-top: 20px; } }

.exam-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 12px 0; color: var(--muted); font-size: .85rem; }

/* Разбор располагается под сводкой, чтобы история помещалась на телефоне. */
.history-review { grid-column: 1 / -1; justify-self: start; }
@media (max-width: 600px) {
    .history-row { grid-template-columns: minmax(0, 1fr) auto; }
    .history-date, .history-time { grid-column: 1 / -1; }
}

/* Общая оболочка: бренд, разделы и профиль в единой шапке. */
body { padding: 24px 28px 56px; font-size: 16px; -webkit-font-smoothing: antialiased; }
main { max-width: 1080px; }
.app-header { position: sticky; top: 16px; z-index: 30; display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto; align-items: center; gap: 24px;
    margin: 0 0 42px; padding: 16px 20px; border: 1px solid var(--border); border-radius: 20px;
    background: var(--surface); box-shadow: 0 4px 24px #00000005; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { flex: 0 0 auto; border-radius: 12px; }
.brand h1 { margin: 0; padding: 0; border: 0; font-size: 1.15rem; font-weight: 720; letter-spacing: -.035em; white-space: nowrap; }
.brand p { margin: 3px 0 0; font-size: .72rem; color: var(--muted); }
.version-badge { display: inline-flex; padding: 1px 6px; margin-left: 3px; border-radius: 5px;
    font-size: .72rem; letter-spacing: 0; vertical-align: middle; color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.app-header .profile-menu { grid-column: 3; grid-row: 1; justify-self: end; margin: 0; }
.app-header .profile-menu summary { display: flex; align-items: center; justify-content: center; gap: 8px;
    min-width: 44px; min-height: 44px; padding: 8px; border: 1px solid transparent; border-radius: 50%; color: var(--fg);
    background: color-mix(in srgb, var(--fg) 4%, var(--surface)); list-style: none; }
.app-header .profile-menu summary::-webkit-details-marker { display: none; }
.app-header .profile-menu summary:hover, .app-header .profile-menu[open] summary {
    border-color: var(--border); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.profile-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.profile-panel { top: calc(100% + 14px); border-radius: 18px; padding: 24px; box-shadow: 0 16px 50px #0002; }
.app-header .main-nav { grid-column: 2; grid-row: 1; position: static; margin: 0; border: 0;
    padding: 4px; gap: 3px; border-radius: 12px; background: color-mix(in srgb, var(--fg) 4%, var(--surface)); }
.app-header .main-nav a { flex: 0 1 auto; min-height: 40px; padding: 8px 13px; font-size: .82rem; white-space: nowrap; border-radius: 9px; }
.app-header .main-nav a[aria-current="page"] { color: var(--fg); background: var(--surface); box-shadow: 0 1px 5px #00000012; }
.app-header .main-nav a:hover { color: var(--fg); }
main > section:not(#categories-view):not(#stats-view):not(#results-view) { max-width: 860px; margin-inline: auto; }
h2 { color: var(--fg); font-size: 1.3rem; letter-spacing: -.025em; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 24px; }
.section-heading h2 { margin: 0; font-size: 1.85rem; font-weight: 720; letter-spacing: -.045em; line-height: 1.2; }
.eyebrow { margin: 0 0 8px; color: var(--muted); font-size: .75rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; }
.practice-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 24px; }
.practice-toolbar .top-actions, .practice-toolbar .mode-switch { margin: 0; }
.practice-toolbar .mode-switch { flex: 0 1 420px; }
.mode-switch { padding: 4px; gap: 4px; background: color-mix(in srgb, var(--fg) 5%, var(--surface)); border: 1px solid var(--border); border-radius: 12px; }
.mode-btn { min-height: 42px; padding: 8px 16px; border: 1px solid transparent; border-radius: 8px;
    font-size: .88rem; font-weight: 600; color: var(--muted); background: transparent; }
.mode-btn.active { border-color: var(--border); color: var(--fg); background: var(--surface); box-shadow: 0 1px 4px #00000008; }
.mode-btn:disabled { opacity: .55; cursor: wait; }
.btn, .btn-secondary { min-height: 44px; padding: 11px 18px; border-radius: 11px; font-size: .9rem; }
.btn { box-shadow: 0 2px 5px #0000000a; }
.btn-secondary { border-color: var(--border); color: var(--fg); background: var(--surface); }
.btn-secondary:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.cards > li { min-width: 0; padding-bottom: 14px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface);
    transition: border-color .15s, box-shadow .15s; }
.cards > li:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); box-shadow: 0 5px 18px #00000005; }
.card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; align-items: start;
    min-height: 100px; padding: 22px 22px 12px; border: 0; background: transparent; border-radius: 15px; }
.card:hover { transform: none; }
.card-name { grid-column: 1; font-size: 1rem; font-weight: 620; line-height: 1.45; }
.card-count { grid-column: 1; margin: 0; white-space: normal; font-size: .78rem; line-height: 1.5; }
.card::after { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 1.5rem; color: var(--muted); }
.cards .card-link { display: inline-block; margin: 3px 0 0 22px; font-size: .78rem; min-height: 28px; }
.card-videos { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px;
    margin: 4px 22px 0; color: var(--muted); font-size: .78rem; }
.card-videos .link { min-height: 28px; }
.result-links { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.result-links button { min-height: 112px; padding: 24px; border-radius: 16px; font-size: 1rem; line-height: 1.5; }
.result { box-shadow: 0 2px 8px #00000003; }
.history-row { padding: 18px 0; }
.release { margin-top: 48px; font-size: .75rem; opacity: .85; }
#login-view, #login-sent-view, #login-confirm-view { padding: 32px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); }

/* Личная статистика: определения показателей и адаптивная таблица. */
.stats-switch { max-width: 540px; margin-bottom: 24px; }
.stats-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.metric-card { display: flex; flex-direction: column; align-items: start; gap: 8px; padding: 24px;
    border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
.metric-label { color: var(--muted); font-size: .8rem; }
.metric-value { font-size: 2.1rem; font-weight: 650; letter-spacing: -.055em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.metric-detail { color: var(--muted); font-size: .78rem; }
.stats-note { margin: 0 0 24px; color: var(--muted); font-size: .85rem; line-height: 1.65; max-width: 850px; }
.personal-stats { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
.personal-stats-table { font-size: .85rem; }
.personal-stats-table th.num { white-space: normal; }
.personal-stats-table th { font-size: .72rem; font-weight: 600; background: color-mix(in srgb, var(--fg) 2%, var(--surface)); }
.personal-stats-table th, .personal-stats-table td { padding: 18px 20px; }
.personal-stats-table td:first-child { font-weight: 550; min-width: 180px; }
.personal-stats-table tbody tr:last-child td { border-bottom: 0; }
.personal-stats-table progress { display: block; width: 100%; min-width: 80px; max-width: 140px; height: 4px;
    margin: 9px 0 0 auto; appearance: none; border: 0; border-radius: 8px; background: var(--border); accent-color: var(--accent); }
.personal-stats-table progress::-webkit-progress-bar { background: var(--border); border-radius: 8px; }
.personal-stats-table progress::-webkit-progress-value { background: var(--accent); border-radius: 8px; }
.personal-stats-table progress::-moz-progress-bar { background: var(--accent); border-radius: 8px; }

@media (min-width: 601px) and (max-width: 960px) {
    .app-header { grid-template-columns: 1fr auto; gap: 16px; }
    .app-header .profile-menu { grid-column: 2; }
    .app-header .main-nav { grid-column: 1 / -1; grid-row: 2; }
    .app-header .main-nav a { flex: 1; }
    .personal-stats-table th, .personal-stats-table td { padding: 15px 12px; }
}
#connection-status {
    display: none;
}

@media (max-width: 600px), (display-mode: standalone) and (pointer: coarse) {
    #connection-status {
        display: block;
        margin: 0;
    }

    #connection-status:not(:empty) {
        display: table;
        margin: 0 0 12px;
        padding: 4px 10px;
        border-radius: 8px;
        background: #ffd78a;
        color: #452900;
        font-size: .85rem;
        font-weight: 600;
    }
}

@media (max-width: 600px) {
    body { padding: 16px 16px 40px; }
    body:has(#main-nav:not([hidden])) { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
    .app-header { position: relative; top: 0; display: flex; justify-content: space-between; gap: 8px;
        margin-bottom: 30px; padding: 0 0 18px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0;
        background: transparent; box-shadow: none; }
    .brand { gap: 10px; }
    .brand img { width: 34px; height: 34px; }
    .brand h1 { font-size: 1.05rem; }
    .brand p { font-size: .65rem; }
    .profile-panel { width: min(330px, calc(100vw - 32px)); padding: 20px; }
    .app-header .main-nav { position: fixed; top: auto; bottom: calc(12px + env(safe-area-inset-bottom));
        left: 12px; right: 12px; padding: 5px; gap: 2px; border: 1px solid var(--border); border-radius: 18px;
        background: var(--surface); box-shadow: 0 8px 32px #00000018; }
    .app-header .main-nav a { flex: 1; min-height: 46px; padding: 9px 4px; font-size: .7rem; white-space: normal; border-radius: 12px; }
    .app-header .main-nav a[aria-current="page"] { background: var(--accent); color: var(--accent-fg); box-shadow: none; }
    .section-heading h2 { font-size: 1.6rem; }
    .section-heading { margin-bottom: 20px; }
    .practice-toolbar { flex-direction: column; align-items: stretch; gap: 12px; }
    .practice-toolbar .top-actions { justify-content: flex-end; }
    .practice-toolbar .top-actions .btn-secondary { min-height: 36px; padding: 6px 12px; font-size: .76rem; background: transparent; }
    .mode-btn { padding: 9px 8px; font-size: .79rem; }
    .cards, .result-links { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .card { padding: 18px 18px 10px; min-height: 88px; }
    .card-name { font-size: .95rem; }
    .cards .card-link { margin-left: 18px; }
    .card-videos { margin-inline: 18px; }
    .result-links button { min-height: 80px; padding: 20px; }
    .stats-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .metric-card { padding: 16px; gap: 6px; }
    .metric-card:first-child { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; }
    .metric-card:first-child .metric-label { width: 100%; }
    .metric-value { font-size: 1.8rem; }
    .metric-label, .metric-detail { font-size: .72rem; }
    .personal-stats { overflow: visible; border: 0; border-radius: 0; background: transparent; }
    .personal-stats-table { display: block; }
    .personal-stats-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .personal-stats-table tbody { display: grid; gap: 12px; }
    .personal-stats-table tr { display: grid; padding: 18px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
    .personal-stats-table td { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
        gap: 8px 12px; padding: 8px 0; border: 0; }
    .personal-stats-table td:first-child { display: block; min-width: 0; margin-bottom: 12px; padding: 0; text-align: left; font-size: .95rem; }
    .personal-stats-table td.num { white-space: normal; }
    .personal-stats-table td:not(:first-child)::before { content: attr(data-label); color: var(--muted); text-align: left; font-size: .76rem; }
    .personal-stats-table progress { grid-column: 1 / -1; width: 100%; max-width: none; margin: 0 0 2px; }
    #login-view, #login-sent-view, #login-confirm-view { padding: 24px; }
}

.nav-icon, .nav-label-short { display: none; }
@media (max-width: 600px) {
    .practice-toolbar .mode-switch { flex: none; width: 100%; }
    .app-header .main-nav a { flex-direction: column; gap: 4px; min-height: 58px; padding: 7px 3px; font-size: .66rem; }
    .nav-icon, .nav-label-short { display: block; }
    .nav-label-full { display: none; }
}
.sync-panel { max-width: 960px; margin: 1rem auto; padding: 1rem; overflow-wrap: anywhere; }
.sync-panel p { margin: 0 0 .6rem; }
#sync-conflicts { margin-top: 1rem; }
#sync-conflicts button { margin: .3rem; }

.ai-unavailable #ai-home, .ai-unavailable #ai-question, .ai-unavailable #ai-check { display: none; }
