/* =================================================================
   СЛОЙ 1: RESET + ПЕРЕМЕННЫЕ + БАЗА
   Палитра: #2D6A4F (зелёный) + #FAF3E0 (песочный) + #1B1B1B (угольный)
   ================================================================= */

@layer reset, base, components, utilities, pages, compare;

/* --- 1. RESET ----------------------------------------------- */
@layer reset {
    *, *::before, *::after { box-sizing: border-box; }
    * { margin: 0; padding: 0; }
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
        -moz-tab-size: 4;
        tab-size: 4;
    }
    body {
        min-height: 100vh;
        min-height: 100dvh;
        line-height: 1.6;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
    img, picture, video, canvas, svg { display: block; max-width: 100%; }
    input, button, textarea, select { font: inherit; color: inherit; }
    button { background: none; border: none; cursor: pointer; }
    a { color: inherit; text-decoration: none; }
    ul, ol { list-style: none; }
    table { border-collapse: collapse; width: 100%; }
    [hidden] { display: none !important; }
    :focus-visible {
        outline: 3px solid var(--clr-focus);
        outline-offset: 2px;
        border-radius: 4px;
    }
}

/* --- 2. ПЕРЕМЕННЫЕ -------------------------------------------- */
@layer base {
    :root {
        /* === Палитра === */
        --clr-primary:        #2D6A4F;     /* зелёный — основной */
        --clr-primary-dark:   #1B4332;
        --clr-primary-light:  #52B788;
        --clr-primary-soft:   #D8F3DC;

        --clr-accent:         #C77D2D;     /* тёплый акцент — охра */
        --clr-accent-dark:    #9B6325;
        --clr-accent-soft:    #FAEAD0;

        --clr-sand:           #FAF3E0;
        --clr-sand-dark:      #F2E8C9;
        --clr-cream:          #FFFBF2;

        --charcoal:           #1B1B1B;
        --grey-900:           #212529;
        --grey-700:           #495057;
        --grey-500:           #6C757D;
        --grey-300:           #DEE2E6;
        --grey-200:           #E9ECEF;
        --grey-100:           #F8F9FA;

        /* Семантика */
        --clr-bg:             var(--clr-cream);
        --clr-surface:        #FFFFFF;
        --clr-surface-2:      var(--clr-sand);
        --clr-surface-3:      var(--grey-100);
        --clr-text:           var(--charcoal);
        --clr-text-soft:      var(--grey-700);
        --clr-text-faint:     var(--grey-500);
        --clr-border:         var(--grey-300);
        --clr-border-soft:    var(--grey-200);

        --clr-link:           var(--clr-primary);
        --clr-link-hover:     var(--clr-primary-dark);

        --clr-success:        #2D6A4F;
        --clr-warning:        #C77D2D;
        --clr-danger:         #C0392B;
        --clr-info:           #2C7DA0;

        --clr-focus:          #52B788;

        /* Лучшее/худшее в сравнении */
        --clr-best:           #B7E4C7;
        --clr-best-strong:    #2D6A4F;
        --clr-worst:          #F5C2C0;
        --clr-worst-strong:   #C0392B;

        /* === Типографика === */
        --font-sans:          'Manrope', 'PT Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
        --font-mono:          'JetBrains Mono', ui-monospace, 'Cascadia Code', monospace;

        /* Флюидная типографика */
        --fs-2xs: clamp(0.75rem, 0.7rem + 0.15vw, 0.8125rem);     /* 12-13 */
        --fs-xs:  clamp(0.8125rem, 0.78rem + 0.18vw, 0.875rem);   /* 13-14 */
        --fs-sm:  clamp(0.875rem, 0.84rem + 0.2vw, 0.9375rem);    /* 14-15 */
        --fs-base:clamp(1rem,     0.95rem + 0.25vw, 1.0625rem);   /* 16-17 */
        --fs-lg:  clamp(1.125rem, 1.05rem + 0.4vw, 1.25rem);      /* 18-20 */
        --fs-xl:  clamp(1.25rem,  1.1rem + 0.75vw, 1.5rem);       /* 20-24 */
        --fs-2xl: clamp(1.5rem,   1.25rem + 1.25vw, 1.875rem);    /* 24-30 */
        --fs-3xl: clamp(1.875rem, 1.5rem + 1.875vw, 2.5rem);      /* 30-40 */
        --fs-4xl: clamp(2.25rem,  1.75rem + 2.5vw, 3.25rem);      /* 36-52 */
        --fs-5xl: clamp(2.75rem,  2rem + 3.75vw, 4.5rem);         /* 44-72 */

        --lh-tight:    1.2;
        --lh-snug:     1.35;
        --lh-normal:   1.55;
        --lh-loose:    1.7;

        --fw-regular:  400;
        --fw-medium:   500;
        --fw-semibold: 600;
        --fw-bold:     700;
        --fw-extrabold: 800;

        /* === Spacing scale (4/8) === */
        --sp-1:  4px;
        --sp-2:  8px;
        --sp-3:  12px;
        --sp-4:  16px;
        --sp-5:  20px;
        --sp-6:  24px;
        --sp-8:  32px;
        --sp-10: 40px;
        --sp-12: 48px;
        --sp-16: 64px;
        --sp-20: 80px;
        --sp-24: 96px;

        /* === Радиусы === */
        --r-sm: 4px;
        --r-md: 8px;
        --r-lg: 16px;
        --r-xl: 24px;
        --r-full: 9999px;

        /* === Тени (3 уровня) === */
        --shadow-1: 0 1px 2px rgba(27,27,27,.06), 0 1px 1px rgba(27,27,27,.04);
        --shadow-2: 0 4px 12px rgba(27,27,27,.08), 0 2px 4px rgba(27,27,27,.04);
        --shadow-3: 0 12px 32px rgba(27,27,27,.12), 0 4px 8px rgba(27,27,27,.06);

        /* === Контейнер === */
        --container-max: 1320px;
        --container-pad: clamp(16px, 4vw, 48px);

        /* === Анимации === */
        --ease: cubic-bezier(.4, 0, .2, 1);
        --ease-out: cubic-bezier(0, 0, .2, 1);
        --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
        --dur-fast: 150ms;
        --dur-mid: 250ms;
        --dur-slow: 400ms;

        /* === z-index === */
        --z-header: 100;
        --z-drawer: 200;
        --z-dropdown: 150;
        --z-modal: 300;
        --z-toast: 400;

        /* === Шапка === */
        --header-h: 72px;
    }

    /* === ТЁМНАЯ ТЕМА === */
    @media (prefers-color-scheme: dark) {
        :root:not([data-theme="light"]) {
            --clr-bg:             #0F1410;
            --clr-surface:        #161B17;
            --clr-surface-2:      #1F2620;
            --clr-surface-3:      #2A322B;
            --clr-text:           #E8EDE9;
            --clr-text-soft:      #A8B3AC;
            --clr-text-faint:     #7C8980;
            --clr-border:         #2F3833;
            --clr-border-soft:    #232B26;
            --clr-link:           var(--clr-primary-light);
            --clr-link-hover:     #74C69D;
            --clr-sand:           #1F2620;
            --clr-sand-dark:      #232B26;
            --clr-cream:          #0F1410;
            --clr-primary-soft:   #1B4332;
            --clr-accent-soft:    #3D2E15;
            --shadow-1: 0 1px 2px rgba(0,0,0,.4);
            --shadow-2: 0 4px 12px rgba(0,0,0,.5);
            --shadow-3: 0 12px 32px rgba(0,0,0,.6);
            --clr-best:           #1B4332;
            --clr-worst:          #3D1518;
        }
    }
    /* Ручная тёмная тема */
    [data-theme="dark"] {
        --clr-bg:             #0F1410;
        --clr-surface:        #161B17;
        --clr-surface-2:      #1F2620;
        --clr-surface-3:      #2A322B;
        --clr-text:           #E8EDE9;
        --clr-text-soft:      #A8B3AC;
        --clr-text-faint:     #7C8980;
        --clr-border:         #2F3833;
        --clr-border-soft:    #232B26;
        --clr-link:           var(--clr-primary-light);
        --clr-link-hover:     #74C69D;
        --clr-sand:           #1F2620;
        --clr-sand-dark:      #232B26;
        --clr-cream:          #0F1410;
        --clr-primary-soft:   #1B4332;
        --clr-accent-soft:    #3D2E15;
        --shadow-1: 0 1px 2px rgba(0,0,0,.4);
        --shadow-2: 0 4px 12px rgba(0,0,0,.5);
        --shadow-3: 0 12px 32px rgba(0,0,0,.6);
        --clr-best:           #1B4332;
        --clr-worst:          #3D1518;
    }

    /* === БАЗА === */
    html { scroll-behavior: smooth; }
    body {
        font-family: var(--font-sans);
        font-size: var(--fs-base);
        line-height: var(--lh-normal);
        color: var(--clr-text);
        background-color: var(--clr-bg);
        transition: background-color var(--dur-mid) var(--ease),
                    color var(--dur-mid) var(--ease);
    }
    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
            scroll-behavior: auto !important;
        }
    }

    h1, h2, h3, h4, h5, h6 {
        font-weight: var(--fw-bold);
        line-height: var(--lh-tight);
        color: var(--clr-text);
        text-wrap: balance;
    }
    h1 { font-size: var(--fs-3xl); }
    h2 { font-size: var(--fs-2xl); }
    h3 { font-size: var(--fs-xl); }
    h4 { font-size: var(--fs-lg); }

    p { text-wrap: pretty; }

    a { color: var(--clr-link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--clr-link) 30%, transparent); text-underline-offset: 2px; transition: color var(--dur-fast) var(--ease), text-decoration-color var(--dur-fast) var(--ease); }
    a:hover { color: var(--clr-link-hover); text-decoration-color: var(--clr-link-hover); }

    strong, b { font-weight: var(--fw-bold); }

    code { font-family: var(--font-mono); font-size: 0.92em; background: var(--clr-surface-3); padding: 2px 6px; border-radius: var(--r-sm); }

    img { height: auto; }

    /* Контейнер */
    .container {
        width: 100%;
        max-width: var(--container-max);
        margin-inline: auto;
        padding-inline: var(--container-pad);
    }

    /* Visually hidden */
    .visually-hidden {
        position: absolute !important;
        width: 1px; height: 1px;
        padding: 0; margin: -1px;
        overflow: hidden; clip: rect(0, 0, 0, 0);
        white-space: nowrap; border: 0;
    }

    /* === Безопасные зоны (iPhone) === */
    .safe-top    { padding-top: env(safe-area-inset-top); }
    .safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
    .safe-left   { padding-left: env(safe-area-inset-left); }
    .safe-right  { padding-right: env(safe-area-inset-right); }
}

/* --- 3. UTILITIES -------------------------------------------- */
@layer utilities {
    .text-center { text-align: center; }
    .text-left   { text-align: left; }
    .text-right  { text-align: right; }
    .mt-0 { margin-top: 0; }
    .mt-2 { margin-top: var(--sp-2); }
    .mt-4 { margin-top: var(--sp-4); }
    .mt-8 { margin-top: var(--sp-8); }
    .mb-0 { margin-bottom: 0; }
    .mb-2 { margin-bottom: var(--sp-2); }
    .mb-4 { margin-bottom: var(--sp-4); }
    .mb-8 { margin-bottom: var(--sp-8); }

    .prose {
        font-size: var(--fs-base);
        line-height: var(--lh-loose);
        color: var(--clr-text);
    }
    .prose p { margin-bottom: var(--sp-4); }
    .prose h2 { margin-top: var(--sp-8); margin-bottom: var(--sp-4); }
    .prose h3 { margin-top: var(--sp-6); margin-bottom: var(--sp-3); }
    .prose ul, .prose ol { padding-left: var(--sp-6); margin-bottom: var(--sp-4); }
    .prose li { margin-bottom: var(--sp-2); }

    .section-title {
        font-size: var(--fs-xl);
        font-weight: var(--fw-bold);
        margin-bottom: var(--sp-4);
        display: flex;
        align-items: center;
        gap: var(--sp-2);
    }

    .link-more {
        font-weight: var(--fw-semibold);
        color: var(--clr-primary);
        white-space: nowrap;
    }

    .page-head {
        padding: var(--sp-8) 0 var(--sp-6);
    }
    .page-head__title {
        font-size: var(--fs-3xl);
        margin-bottom: var(--sp-2);
    }
    .page-head__sub {
        color: var(--clr-text-soft);
        font-size: var(--fs-base);
    }

    .error-page {
        text-align: center;
        padding: var(--sp-20) 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--sp-4);
    }
    .error-page__code {
        font-size: var(--fs-5xl);
        font-weight: var(--fw-extrabold);
        color: var(--clr-primary);
        line-height: 1;
    }
    .error-page__title { font-size: var(--fs-2xl); }
    .error-page__text, .error-page__sub { color: var(--clr-text-soft); max-width: 600px; }
    .error-page .btn { margin-top: var(--sp-4); }
}
