/* Базовые стили: сброс, типографика, утилиты, доступность. */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font-ui);
    font-size: var(--fs-15);
    line-height: var(--lh);
    color: var(--text);
    background: var(--canvas);
    font-feature-settings: "cv05" 1;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
    margin: 0 0 var(--sp-4);
    line-height: var(--lh-tight);
    letter-spacing: var(--tracking-tight);
    font-weight: 650;
    word-break: normal;
    overflow-wrap: break-word;
}

h1 {
    font-size: var(--fs-24);
}
h2 {
    font-size: var(--fs-20);
}
h3 {
    font-size: var(--fs-16);
}
h4 {
    font-size: var(--fs-14);
    text-transform: none;
}

p {
    margin: 0 0 var(--sp-4);
    overflow-wrap: break-word;
}

a {
    color: var(--link);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

a:hover {
    color: var(--link-hover);
}

a:not(.btn):not(.chip):not(.nav-link):not(.tree-link):not(.row-link):not(.tab) {
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
}

a:not(.btn):not(.chip):not(.nav-link):not(.tree-link):not(.row-link):not(.tab):hover {
    text-decoration-color: currentColor;
}

ul,
ol {
    margin: 0 0 var(--sp-4);
    padding-left: var(--sp-6);
}

li {
    margin-bottom: var(--sp-2);
}

li::marker {
    color: var(--accent-500);   /* декор, но держит порог графики 3:1 */
}

hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: var(--sp-6) 0;
}

pre,
code {
    font-family: var(--font-mono);
    font-size: var(--fs-13);
}

pre {
    margin: 0;
    padding: var(--sp-5);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    line-height: var(--lh-loose);
}

kbd {
    display: inline-block;
    min-width: 22px;
    padding: 1px 6px;
    font-family: var(--font-ui);
    font-size: var(--fs-12);
    font-weight: 600;
    line-height: 1.6;
    text-align: center;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-sm);
}

img,
svg,
audio,
video {
    max-width: 100%;
}

:focus-visible {
    outline: 2px solid var(--accent-600);
    outline-offset: 2px;
    border-radius: var(--r-xs);
}

::selection {
    background: var(--accent-200);
    color: var(--accent-900);
}

/* Доступность */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px
;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -100px;
    left: var(--sp-4);
    z-index: var(--z-toast);
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface);
    border: 1px solid var(--accent-600);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-3);
    font-weight: 600;
    text-decoration: none;
}

.skip-link:focus {
    top: var(--sp-4);
}

/* Утилиты */
.muted {
    color: var(--text-muted);
}
.subtle {
    color: var(--text-subtle);
}
.small {
    font-size: var(--fs-13);
}
.tiny {
    font-size: var(--fs-12);
}
.strong {
    font-weight: 650;
}
.tnum {
    font-variant-numeric: tabular-nums;
}
.upper {
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    font-size: var(--fs-11);
    font-weight: 700;
    color: var(--text-subtle);
}
.center {
    text-align: center;
}
.nowrap {
    white-space: nowrap;
}
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.mb-0 {
    margin-bottom: 0;
}
.mt-auto {
    margin-top: auto;
}

.row {
    display: flex;
    gap: var(--sp-4);
    align-items: center;
    flex-wrap: wrap;
    min-width: 0;
}

.row-tight {
    gap: var(--sp-2);
}

.row-between {
    justify-content: space-between;
}

.row-end {
    justify-content: flex-end;
}

.col {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    min-width: 0;
}

.stack > * + * {
    margin-top: var(--sp-4);
}

.grid {
    display: grid;
    gap: var(--sp-5);
}

.wrap {
    flex-wrap: wrap;
}

.grow {
    flex: 1 1 auto;
    min-width: 0;
}

.hidden {
    display: none !important;
}

/* Скрытие через атрибут (фильтры без перезагрузки): перебивает grid/flex. */
[hidden] {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media print {
    body {
        background: #fff;
    }
    .topbar,
    .rail,
    .aside,
    .btn,
    .toolbar,
    .mobile-nav {
        display: none !important;
    }
    .card {
        box-shadow: none;
        border-color: #ccc;
        break-inside: avoid;
    }
}
