/* static.css — общие примитивы сайтов redata.dev (static.redata.dev/css/static.css).
 *
 * Слои каскада: всё здесь лежит в @layer, поэтому любое правило страницы или
 * локального css сайта (без слоя) побеждает любое правило отсюда, независимо
 * от специфичности. Порядок слоёв — порядок силы:
 *   reset       сброс отступов, картинки, движение
 *   base        токены (:root), шрифт и ритм, элементы: заголовки, ссылки, код, списки
 *   layout      каркас страницы: header, nav, main, footer, section
 *   components  готовые блоки: кнопки, breadcrumb, dropdown, data-table, scroll-x
 *
 * Как перекрыть: написать своё правило вне @layer — оно сильнее. Усиливать
 * селекторы и писать !important не нужно.
 *
 * До 2026-11-17 файл назывался global.css. 2026-11-17: слои, токены вместо
 * повторяющихся чисел, .data-table и .scroll-x, min-width: 0 для содержимого
 * main (flex-элемент иначе не ужимается уже своего содержимого и широкая
 * таблица уезжает за экран телефона). Внешний вид существующих страниц не
 * менялся: значения те же, только собраны. Удалено неиспользуемое (пять токенов,
 * пустые правила). Выпадашки меню — на Alpine (x-show), шапка и меню общие
 * (components/ на static, js/site.js). Размеры шрифта не менялись: html 16px / body 18px и заголовки
 * в rem подобраны под устройства и ориентации, владелец их читаемостью доволен.
 */

@layer reset, base, layout, components;

/* Переход между страницами сайта — плавный (cross-document View Transitions);
   браузер без поддержки переходит как обычно. При prefers-reduced-motion
   выключается в слое reset. */
@view-transition {
    navigation: auto;
}

/* ---------- шрифты (вне слоёв: @font-face в каскаде не участвует) ---------- */

@font-face {
    font-family: "mononoki-Regular";
    src: url("//static.redata.dev/fonts/mononoki-Regular.otf") format("opentype");
    font-display: swap;
}

@font-face {
    font-family: "Roboto Mono";
    src: url("//static.redata.dev/fonts/RobotoMono-Regular.ttf") format("truetype");
    font-display: swap;
}

/* для одиночных тегов, которые нужно акцентировать */
@font-face {
    font-family: "MonaspaceNeon-Regular";
    src: url("//static.redata.dev/fonts/MonaspaceNeon-Regular.otf") format("opentype");
    font-display: swap;
}

/* для блоков кода на тёмном фоне */
@font-face {
    font-family: "MonaspaceNeon-ExtraLight";
    src: url("//static.redata.dev/fonts/MonaspaceNeon-ExtraLight.otf") format("opentype");
    font-display: swap;
}

/* для меню */
@font-face {
    font-family: "Poppins";
    src: url("//static.redata.dev/fonts/Poppinsregular.woff2") format("woff2");
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* breadcrumb */
@font-face {
    font-family: "iAWriterDuospace-Regular";
    src: url("//static.redata.dev/fonts/iAWriterDuospace-Regular.otf") format("opentype");
    font-display: swap;
}

/* ================================================================ reset */

@layer reset {
    * {
        margin: 0;
        padding: 0;
        scrollbar-width: auto;
        scrollbar-color: rgb(202, 202, 232) auto;
    }

    /* картинка не шире своего места */
    img, svg, video {
        max-inline-size: 100%;
        block-size: auto;
    }

    @media (prefers-reduced-motion: reduce) {
        @view-transition {
            navigation: none;
        }

        *, *::before, *::after {
            transition-duration: 0.01ms !important;
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
        }
    }
}

/* ================================================================= base */

@layer base {
    :root {
        /* цвета */
        --color-accent: #bcd3e615;
        --color-bg: hsl(215, 38%, 98%);
        --color-surface: #f8f8fa;          /* плашки: шапка, main, пункты меню, логотип */
        --color-footer: #ebeff4;
        --color-navbar: hsl(218, 57%, 40%);
        --color-nav-text: #333;
        --color-bg-secondary: #e9e9e9;
        --color-border: #e3e8ef;           /* линии таблиц и разделители */
        --color-stripe: #f3f6fa;           /* чётные строки таблиц */
        --color-stripe-hover: #e8eef7;
        --color-table-head: #eef2f7;
        --color-btn: #668fc5;
        --color-button-blue: #476fc1;
        --color-button-blue-hover: #5a84e0;
        --color-button-orange: #ff6a2e;
        --color-button-orange-hover: #ff8546;
        --color-table: #118bee;
        --color-secondary: #920de9;
        --color-shadow: #f4f4f4;
        --color-code-bg: #434343;
        --color-code-text: #f8f8f8;
        --color-text: #000;
        --color-text-secondary: #5f5f5f;
        --color-link: #2563eb;

        /* шрифты */
        --font-family: Helvetica, "Roboto Mono", Arial, sans-serif;
        --font-family-code: "mononoki-Regular", monospace;
        --font-family-pre: "MonaspaceNeon-ExtraLight", monospace;
        --font-family-menu: "Poppins", sans-serif;
        --font-family-breadcrumb: "iAWriterDuospace-Regular", monospace;
        --line-height: 1.5;

        /* форма */
        --active-brightness: 0.85;
        --border-radius: 5px;
        --box-shadow: 2px 2px 10px;
        --justify-important: left;
        --justify-normal: left;
        --width-content: 1080px;
    }

    html {
        height: 100%;
        /* rem всегда считается от html, а не от body */
        font-size: 16px;
        font-weight: 400;
        -moz-text-size-adjust: none;
        -webkit-text-size-adjust: none;
        text-size-adjust: none;
    }

    body {
        font-size: 18px; /* базовый размер для desktop */
        margin: auto;
        display: flex;
        flex-direction: column;
        font-family: var(--font-family);
        line-height: var(--line-height);
        background-color: var(--color-bg);
    }

    /* Alpine: элемент с x-cloak скрыт, пока Alpine не снял атрибут */
    [x-cloak] {
        display: none !important;
    }

    /* клавиатурный фокус виден одинаково везде */
    :focus-visible {
        outline: 2px solid var(--color-link);
        outline-offset: 2px;
    }

    /* заголовки — единожды, работают везде через rem */
    h1 { font-size: 1.4rem;  font-weight: 600; }
    h2 { font-size: 1.3rem;  font-weight: 500; }
    h3 { font-size: 1.2rem;  font-weight: 400; }
    h4 { font-size: 1.1rem;  font-weight: 400; }
    h5 { font-size: 1.05rem; font-weight: 400; }
    h6 { font-size: 1rem;    font-weight: 400; }

    h1 strong, h2 strong { font-weight: 700; }
    h3 strong, h4 strong, h5 strong, h6 strong { font-weight: 600; }
    p strong { font-weight: 500; }

    p {
        text-align: left;
        margin-bottom: 0.8rem;
    }

    a {
        color: var(--color-link);
        font-weight: 500;

        &:active {
            filter: brightness(var(--active-brightness));
        }

        i:hover {
            border-bottom: 3px dashed var(--color-link);
        }
    }

    action-link {
        display: inline-block;
    }

    ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }

    small {
        color: var(--color-text-secondary);
    }

    mark {
        padding: 0.1rem;
        background-color: transparent;
    }

    sup {
        background-color: var(--color-secondary);
        border-radius: var(--border-radius);
        color: var(--color-bg);
        font-size: 0.8rem;
        font-weight: bold;
        margin: 0.2rem;
        padding: 0.2rem 0.3rem;
        position: relative;
        top: -2px;
    }

    code {
        background-color: var(--color-code-bg);
        color: var(--color-code-text);
        padding: 0.2rem;
        font-size: 1.05rem;
    }

    pre {
        padding-block: 0.2rem;
        display: flex;
        align-items: stretch;

        code {
            display: block;
            box-sizing: border-box;
            font-family: var(--font-family-pre);
            text-align: left;
            overflow-wrap: break-word;
            width: 100%;
            max-width: 100%;
            overflow-y: auto;
            -webkit-text-size-adjust: none;
            text-size-adjust: none;
            height: 100%;
        }
    }

    details {
        summary {
            list-style: none;
            cursor: pointer;

            &::before {
                content: "+";
                display: inline-block;
                margin-right: 8px;
                font-size: 1.1rem;
            }
        }

        &[open] summary::before {
            content: "-";
        }
    }

    input {
        font-size: 1rem;

        &:disabled {
            background: var(--color-bg-secondary);
            border-color: var(--color-bg-secondary);
            color: var(--color-text-secondary);
            cursor: not-allowed;
        }

        &[type="submit"][disabled]:hover {
            filter: none;
        }
    }

    select, textarea {
        font-size: 1rem;
    }
}

/* =============================================================== layout */

@layer layout {
    header {
        box-sizing: border-box;
        min-height: 2.75rem; /* место шапки занято до прихода фрагмента: контент не прыгает */

        a {
            height: 100%;

            b, em, i, strong {
                margin-inline: 0.5rem;
            }
        }
    }

    #logo {
        max-height: 2.5rem;
        background-color: var(--color-surface);
        padding-right: 1rem;
    }

    nav {
        background-color: var(--color-navbar);

        .nav-menu {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            list-style: none;
            padding: 0;
            margin: 0;
            align-items: center;
            width: 100%;

            li {
                flex: 0 1 auto;
                min-width: fit-content;
                box-sizing: border-box;

                &:first-child {
                    padding: 0;
                }
            }

            a {
                display: inline-block;
                white-space: nowrap;
                text-decoration: none;
                color: var(--color-nav-text);
                font-size: 1em;
                font-family: var(--font-family-menu);
                background-color: var(--color-surface);
                padding: 0.4rem 0.8rem;
                border-radius: 5px;
                text-align: center;

                &:first-child {
                    border-radius: 0;
                }

                &:hover,
                &.active {
                    text-decoration: underline;
                }
            }
        }

        .logo-item {
            flex: 0 0 auto;
            margin-right: auto;

            a {
                display: inline-flex;
                align-items: center;
                margin: 0;
                width: auto;
            }
        }

        #logo {
            max-height: 2.5rem;
            display: block;
        }
    }

    main {
        width: 100%;
        min-width: 0;
        position: relative;
        transition: all 0.1s ease-out;
        display: flex;
        flex-direction: column;
        flex: 1;

        /* flex-элемент не ужимается уже содержимого; без этого широкая
           таблица или <pre> раздвигают страницу за экран телефона */
        > * {
            min-width: 0;
        }

        article {
            padding: 1rem;
        }

        ul, ol {
            padding-left: 1rem;
        }
    }

    footer, header, main {
        background-color: var(--color-surface);
    }

    footer {
        text-align: center;
        font-size: 1rem;
        min-height: 3.5rem; /* как у header */
        background-color: var(--color-footer);
    }

    section {
        width: 96%;
        margin: 0 auto;

        &:hover aside {
            box-shadow: var(--box-shadow) var(--color-bg-secondary);
        }

        a {
            b, em, strong {
                margin-inline: 0.5rem;
            }
        }

        header {
            padding-top: 0;
            width: 100%;
        }

        > div {
            padding-bottom: 1rem;
        }
    }

    article aside a {
        color: var(--color-secondary);
    }

    article .screenshot-list {
        width: 100%;
    }

    /* списки в тексте: маркеры и ритм (после main, чтобы padding 1.2rem
       перекрывал его 1rem при равной специфичности) */
    article, section {
        ul, ol {
            list-style-type: disc;
            list-style-position: outside;
            margin: 0;
            padding-left: 1.2rem;

            li {
                line-height: 1.5;
                margin-block: 0.25rem;

                &::marker {
                    margin-right: 0.4em;
                }
            }
        }
    }

    .img-container {
        display: flex;
        align-items: center;
        justify-content: center;

        > img {
            max-width: 90%;
            padding-block: 0.2rem;
        }
    }

    .same-height-and-width {
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
        width: 100%;
        max-width: 100%;
        justify-content: center;
        overflow: hidden;

        h1, h2, h3, h4, h5, h6 {
            text-align: left;
        }
    }
}

/* =========================================================== components */

@layer components {
    /* ---- кнопки ---- */

    .large-button,
    .medium-button {
        letter-spacing: 0.1rem;
        display: inline-block;
        box-sizing: border-box;
        border-radius: 8px;
        color: #ffffff;
        text-align: center;
        text-decoration: none;
        border-bottom: none;
        cursor: pointer;
        border: none;
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
        transition: box-shadow 0.3s ease, background-color 0.3s ease;
        position: relative;
    }

    .large-button {
        margin-block: 1rem;
        font-size: 1.05rem;
        padding: 12px 30px;
        min-width: 120px;

        &:hover {
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
        }
    }

    .medium-button {
        margin-block: 0.2rem;
        font-size: 1rem;
        padding: 10px 30px;
        min-width: 140px;

        &:hover {
            box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
        }
    }

    .button-blue {
        background-color: var(--color-button-blue);

        &:hover {
            background-color: var(--color-button-blue-hover);
        }
    }

    .button-orange {
        background-color: var(--color-button-orange);

        &:hover {
            background-color: var(--color-button-orange-hover);
        }
    }

    /* ---- breadcrumb ---- */

    .breadcrumb {
        border-bottom: 2px solid black;
        height: 1.05rem;
        list-style: none;
        display: flex;
        padding: 5px;
        border-radius: 2px;
        font-family: var(--font-family-breadcrumb);
        text-transform: uppercase;
        font-weight: 700;
        line-height: 1; /* строка не выше контейнера: текст и стрелка центруются одинаково */

        li {
            margin-right: 5px;
            display: flex;
            align-items: center;

            a {
                height: auto; /* не header a { height: 100% }: иначе текст липнет к верху */
                text-decoration: none;
                color: var(--color-nav-text);

                &:hover {
                    text-decoration: underline;
                }
            }

            &::after {
                content: ">";
                margin-left: 5px;
                color: #666;
            }

            &:last-child {
                &::after {
                    content: "";
                }

                span {
                    color: var(--color-nav-text);
                }
            }
        }
    }

    /* ---- dropdown ---- */

    .dropdown {
        position: relative;

        a[data-toggle="dropdown"] {
            display: flex;
            align-items: center;
            background: transparent;
            color: #ededed;
            padding: 10px 15px;
            border-radius: 4px;
            transition: background 0.3s ease;
            white-space: nowrap;

            &:hover {
                color: #fff;
            }
        }
    }

    .icon-arrow {
        display: inline-block;
        vertical-align: middle;
        margin-left: 5px;
        transition: transform 0.3s ease;

        &.open {
            transform: rotate(180deg);
        }
    }

    .dropdown-menu {
        list-style: none;
        padding: 0;
        margin: 0;
        position: absolute;
        top: 100%;
        left: 0;
        background: #ffffff;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
        border-radius: 6px;
        overflow: hidden;
        box-sizing: border-box;
        z-index: 1000;
        min-width: 140px;

        /* site.js: список уходил бы за правый край окна — прижать к правому краю пункта */
        &.align-end {
            left: auto;
            right: 0;
        }

        li {
            width: 100%;

            a {
                display: block;
                width: 100%;
                padding: 10px 15px;
                box-sizing: border-box;
                text-align: center;
                background-color: #ffffff;
                color: var(--color-nav-text);
                border: none;
                font-weight: 400;
                text-decoration: none;
                border-radius: 0;

                &:hover {
                    background-color: #e8e8e8;
                    color: #000;
                }
            }
        }
    }

    /* ---- scroll-x: блок, который прокручивается по горизонтали, если
       содержимое шире, и служит контейнером для единиц cqi внутри.
       Таблица сама контейнером быть не может — оборачивайте. ---- */

    .scroll-x {
        overflow-x: auto;
        min-width: 0;
        max-width: 100%;
        container-type: inline-size;
        -webkit-overflow-scrolling: touch;
    }

    /* ---- data-table: таблица данных ----
       Умолчания текстовые: слева, по верху, с переносом, светлая шапка.
       Ячейка .num — число: вправо, без переноса, табличные цифры.
       .muted — приглушённое значение (ноль, прочерк).
       Двухэтажная шапка: th.group над группой колонок, th.sub под ней.
       Размеры плавные от ширины контейнера (cqi); без контейнера — от окна.
       Разметка: <table class="data-table"><thead><tr><th>…<th class="num">…
                 <tbody><tr><td>…<td class="num">…  */

    .data-table {
        --_pad-block: clamp(0.35rem, 0.3rem + 0.4cqi, 0.6rem);
        --_pad-inline: clamp(0.4rem, 0.3rem + 0.9cqi, 1rem);

        inline-size: 100%;
        border-collapse: separate;
        border-spacing: 0;
        border: 1px solid var(--color-border);
        border-radius: var(--border-radius);
        overflow: hidden;
        font-size: clamp(0.85rem, 0.75rem + 0.5cqi, 1rem);
        line-height: 1.4;
        font-variant-numeric: tabular-nums;

        th, td {
            padding: var(--_pad-block) var(--_pad-inline);
            text-align: start;
            vertical-align: top;
            border-block-end: 1px solid var(--color-border);
            border-inline-start: 1px solid var(--color-border);
            overflow-wrap: anywhere;
        }

        th:first-child, td:first-child {
            border-inline-start: none;
        }

        thead th {
            background-color: var(--color-table-head);
            color: var(--color-text);
            font-weight: 600;
            vertical-align: bottom;
        }

        th.group {
            text-align: center;
        }

        th.sub {
            font-weight: 400;
        }

        .num {
            text-align: end;
            white-space: nowrap;
        }

        .muted {
            color: var(--color-text-secondary);
        }

        tbody tr:nth-child(even) {
            background-color: var(--color-stripe);
        }

        tbody tr:hover {
            background-color: var(--color-stripe-hover);
        }

        tbody tr:last-child > td {
            border-block-end: none;
        }
    }
}
