:root {
    --bg: #f7f8f7;
    --surface: #ffffff;
    --text: #1d2321;
    --muted: #5e6a66;
    --border: #dfe4e2;
    --accent: #0b7a75;
    --accent-text: #ffffff;
    --mark: #fff0a8;
    --warn: #a33b00;
    color-scheme: light;
}

/* Theme: light unless the browser asks for dark, and data-theme (the «Тема» choice) overrides both. */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #141817;
        --surface: #1c2120;
        --text: #e3e8e6;
        --muted: #9aa6a2;
        --border: #2e3533;
        --accent: #3fb8b0;
        --accent-text: #0d1413;
        --mark: #5c4d00;
        --warn: #ff9d6b;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #141817;
    --surface: #1c2120;
    --text: #e3e8e6;
    --muted: #9aa6a2;
    --border: #2e3533;
    --accent: #3fb8b0;
    --accent-text: #0d1413;
    --mark: #5c4d00;
    --warn: #ff9d6b;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

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

a {
    color: var(--accent);
}

.page {
    max-width: 880px;
    margin: 0 auto;
    padding: 0 16px;
    /* Nothing may widen the page past the screen: a phone would zoom out and scroll sideways. Clip, unlike hidden,
       keeps position: sticky working. */
    overflow-x: clip;
}

h1 {
    font-size: 1.75rem;
    line-height: 1.25;
}

header.site {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
    padding: 20px 0 12px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-size: 1.25rem;
    text-decoration: none;
}

.brand svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

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

.menu-toggle, .menu-button, .menu-backdrop {
    display: none;
}

.search {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 8px 0 12px;
    background: var(--bg);
}

.search-row {
    display: flex;
    gap: 8px;
}

.search input[type=search] {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    font: inherit;
    color: inherit;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.search input[type=search]:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

.search button {
    padding: 10px 18px;
    font: inherit;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.option {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    color: var(--muted);
    font-size: 0.9rem;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.9rem;
}

.filters label:not(.option) {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
}

.filters select, .filters input:not([type=checkbox]) {
    padding: 4px 8px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.intro, .notice, .summary {
    color: var(--muted);
}

.examples a {
    display: inline-block;
    margin: 4px 6px 0 0;
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    text-decoration: none;
    background: var(--surface);
}

.notice.error {
    color: var(--warn);
}

.guideline {
    margin: 16px 0;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.guideline h2 {
    margin: 0;
    font-size: 1.15rem;
    line-height: 1.35;
}

.guideline h2 a {
    color: inherit;
    text-decoration: none;
}

.guideline h2 a:hover {
    text-decoration: underline;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 14px;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.85rem;
}

.badge {
    color: var(--warn);
    font-weight: 600;
}

.passage {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.where {
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
}

.where:hover {
    text-decoration: underline;
}

.text {
    margin: 6px 0 0;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

mark {
    background: var(--mark);
    color: inherit;
    border-radius: 2px;
}

.debug, .status {
    color: var(--muted);
    font-size: 0.8rem;
}

footer.site {
    margin: 32px 0;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.85rem;
}



/* Account links in the header */

.account {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 14px;
    margin-left: auto;
    font-size: 0.9rem;
}

.account .user {
    color: var(--muted);
}

.account form {
    margin: 0;
}

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

/* Login */

.login {
    max-width: 360px;
    margin: 40px auto;
}

.login form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login label:not(.option) {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9rem;
    color: var(--muted);
}

.login input:not([type=checkbox]), select {
    padding: 9px 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.login button, .panel button {
    padding: 10px 18px;
    font: inherit;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.panel button.secondary {
    color: var(--accent);
    background: transparent;
    border: 1px solid var(--accent);
}

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

/* Настройки */

.panel {
    margin: 16px 0;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.panel h2 {
    margin: 0 0 12px;
    font-size: 1.1rem;
}

.panel .row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin: 12px 0 0;
}

.state {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin: 0;
}

.hint {
    color: var(--muted);
    font-size: 0.85rem;
}

.notice.ok {
    color: var(--accent);
}

.table-wrap {
    overflow-x: auto;
}

table.runs {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

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

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

table.runs td:first-child {
    white-space: nowrap;
}

table.runs tr.failed td, .warn {
    color: var(--warn);
}

table.runs tr.skipped td {
    color: var(--muted);
}

@media (max-width: 560px) {
    .guideline, .panel {
        padding: 14px;
    }

    /* The run history stacks: one block per run instead of a table that scrolls sideways. */
    table.runs thead {
        display: none;
    }

    table.runs tr, table.runs td {
        display: block;
    }

    table.runs tr {
        padding: 8px 0;
        border-top: 1px solid var(--border);
    }

    table.runs td {
        padding: 0;
        border: 0;
    }

    table.runs td:nth-child(2), table.runs td:nth-child(3) {
        display: inline;
        color: var(--muted);
    }

    table.runs td:nth-child(2)::after {
        content: " · ";
    }
}

/* «Тема» in the header */

.theme {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--muted);
    font-size: 0.85rem;
}

.theme select {
    padding: 2px 4px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

/* Новые и обновлённые */

.search.updates {
    position: static;
}

.search.updates button {
    padding: 4px 14px;
    font-weight: 600;
}

h2.month {
    margin: 28px 0 0;
    font-size: 1.05rem;
    color: var(--muted);
}

.guideline.compact {
    margin: 10px 0;
    padding: 12px 16px;
}

.guideline.compact h3 {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.35;
}

.guideline.compact h3 a {
    color: inherit;
    text-decoration: none;
}

.guideline.compact h3 a:hover {
    text-decoration: underline;
}

.tag {
    color: var(--accent);
    font-weight: 600;
}

.tag.new {
    padding: 0 8px;
    color: var(--accent-text);
    background: var(--accent);
    border-radius: 999px;
}

/* Ответ по тексту рекомендаций */

.answer {
    margin: 16px 0 24px;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
}

.answer h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.quote {
    margin: 12px 0 0;
}

.quote blockquote {
    margin: 0;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.quote figcaption {
    margin-top: 2px;
    font-size: 0.85rem;
}

.quote figcaption a {
    text-decoration: none;
}

.quote figcaption a:hover {
    text-decoration: underline;
}

.answer .notice {
    margin: 12px 0 0;
}

.answer .hint {
    margin: 10px 0 0;
}

.quote .grade {
    margin-right: 8px;
    font-weight: 600;
    color: var(--muted);
}

/* Рисунки алгоритма и шкал */

.figures figure {
    margin: 16px 0;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

/* The pictures are drawn for white paper; on the dark theme they keep a white background. */
.figures img, .figure-full img {
    display: block;
    background: #ffffff;
}

.figures img {
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}

.figures figcaption {
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.85rem;
}

.figure-full {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #ffffff;
}

.figure-full img {
    max-width: none;
}

/* Ответ сбоку от результатов: справа на широком экране, над результатами на телефоне */

.page:has(.with-aside) {
    max-width: 1260px;
}

.results.with-aside {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-areas: "list aside";
    gap: 0 24px;
    align-items: start;
}

/* A popover (the sheet on a phone), so the browser's popover styles are undone here: beside the results it is an
   ordinary column, shown whether "open" or not. */
.results.with-aside > aside {
    grid-area: aside;
    display: block;
    position: sticky;
    top: 0;
    inset: 0 auto auto;
    width: auto;
    height: auto;
    max-height: 100vh;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    color: inherit;
    background: none;
    border: 0;
}

.results.with-aside > .results-list {
    grid-area: list;
    min-width: 0;
}

.aside-open, .aside-close {
    display: none;
    font: inherit;
    border: 0;
    cursor: pointer;
}

@media (max-width: 960px) {
    .results.with-aside {
        display: block;
    }

    .aside-open {
        display: block;
        position: fixed;
        right: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom));
        z-index: 20;
        padding: 12px 18px;
        font-weight: 600;
        color: var(--accent-text);
        background: var(--accent);
        border-radius: 999px;
        box-shadow: 0 4px 14px rgb(0 0 0 / 30%);
    }

    .results.with-aside > aside {
        position: fixed;
        inset: auto 0 0;
        max-height: 85vh;
        max-height: 85dvh;
        overscroll-behavior: contain;
        padding: 4px 16px calc(16px + env(safe-area-inset-bottom));
        background: var(--bg);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgb(0 0 0 / 30%);
        transform: translateY(105%);
        transition: transform 0.2s ease-out, overlay 0.2s allow-discrete, display 0.2s allow-discrete;
    }

    .results.with-aside > aside:not(:popover-open) {
        display: none;
    }

    .results.with-aside > aside:popover-open {
        transform: none;
    }

    @starting-style {
        .results.with-aside > aside:popover-open {
            transform: translateY(105%);
        }
    }

    .results.with-aside > aside::backdrop {
        background: rgb(0 0 0 / 40%);
    }

    .aside-close {
        display: block;
        width: 100%;
        padding: 10px 0 0;
        text-align: right;
        font-weight: 600;
        color: var(--accent);
        background: none;
    }

    /* The results behind an open sheet stay put. */
    html:has(#answer-sheet:popover-open) {
        overflow: hidden;
    }

    /* The button mustn't cover the end of the last result. */
    .results.with-aside > .results-list {
        padding-bottom: 64px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .results.with-aside > aside {
        transition: none;
    }
}

.ask {
    margin: 16px 0;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
}

.ask h2 {
    margin: 0 0 6px;
    font-size: 1.05rem;
}

.ask p {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 0.9rem;
}

.ask a {
    display: inline-block;
    padding: 8px 16px;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border-radius: 6px;
    text-decoration: none;
}

/* An archived edition or a withdrawn guideline, found with «и недействующие». */
.guideline.archived {
    background: transparent;
    border-style: dashed;
}

.guideline.archived h2 a {
    color: var(--muted);
}

/* Телефон: меню вместо ссылок в шапке, фильтры сеткой, крупнее поля и кнопки */

@media (max-width: 700px) {
    header.site {
        padding: 12px 0 8px;
    }

    .tagline {
        display: none;
    }

    .menu-button {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        margin: -6px -10px -6px auto;
        color: var(--text);
        border-radius: 8px;
        cursor: pointer;
    }

    .menu-button svg {
        width: 24px;
        height: 24px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
    }

    .menu-toggle:checked ~ .menu-button {
        background: var(--surface);
    }

    .menu-toggle:checked ~ .menu-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 39;
    }

    .account {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        z-index: 40;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        min-width: 250px;
        padding: 6px 0;
        font-size: 1rem;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
    }

    .menu-toggle:checked ~ .account {
        display: flex;
    }

    .account > a, .account .theme, .account .user, .account form {
        padding: 10px 16px;
    }

    .account > a {
        text-decoration: none;
    }

    .account .theme {
        justify-content: space-between;
        gap: 12px;
        font-size: 1rem;
    }

    .account .theme select {
        padding: 6px 8px;
    }

    .account .user {
        padding-bottom: 0;
        font-size: 0.85rem;
        border-top: 1px solid var(--border);
    }

    .account .user + form {
        padding-top: 4px;
    }

    .account button.link {
        width: 100%;
        text-align: left;
        text-decoration: none;
    }

    /* Sticky, the form with its filters would cover a fifth of the screen. */
    .search {
        position: static;
        padding-top: 4px;
    }

    .search input[type=search], .search-row button {
        min-height: 46px;
    }

    .filters {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: end;
        gap: 10px 12px;
    }

    .filters label:not(.option) {
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        font-size: 0.85rem;
    }

    .filters select, .filters input:not([type=checkbox]) {
        width: 100%;
        min-height: 42px;
        padding: 6px 10px;
        font-size: 1rem;
    }

    .options {
        flex-direction: column;
        gap: 6px;
        padding-bottom: 2px;
    }

    .option {
        font-size: 0.95rem;
        white-space: nowrap;
    }

    .option input {
        width: 18px;
        height: 18px;
        margin: 0;
    }

    /* «за последние 3 месяца» needs more room than «взрослые». */
    .search.updates .filters {
        grid-template-columns: 1fr auto;
    }

    .search.updates .filters > button {
        grid-column: 1 / -1;
        min-height: 42px;
    }

    h1 {
        font-size: 1.45rem;
    }

    .guideline h2 {
        font-size: 1.08rem;
    }
}
