:root {
    --bg: #fefcf6;
    --text: #1a1a1a;
    --muted: #3d3d3d;
    --faint: #6e6e6e;
    --code-bg: #f2f1eb;
    --border: #ddd;
    --link: #1a4bbf;
    --visited: #54457f;
    --accent-quote: #7c6f9f;
    --radius: 6px;
    --content-width: 720px;
}

[data-theme="dark"] {
    --bg: #212529;
    --text: #e0e0e0;
    --muted: #aaa;
    --faint: #8c8c8c;
    --code-bg: #2c3034;
    --border: #404550;
    --link: #79a8ff;
    --visited: #b4a7d6;
    --accent-quote: #a892d6;
}

* { box-sizing: border-box; }

html {
    font-family: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 17px;
    color: var(--text);
    background: var(--bg);
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    transition: background-color .2s ease, color .2s ease;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none !important; animation: none !important; }
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

body {
    max-width: 920px;
    margin: 0 auto;
    padding: 1.5rem;
    line-height: 1.5;
    overflow-wrap: break-word;
    overflow-x: hidden;
    animation: fade-in .3s ease;
}

::selection {
    background: color-mix(in srgb, var(--link) 25%, transparent);
    color: var(--text);
}

a { color: var(--link); text-underline-offset: .24rem; transition: color .15s ease; }
a:visited { color: var(--visited); }

img { border-radius: var(--radius); }

h1 { font-size: 1.5rem; margin-top: 0; margin-bottom: 1rem; letter-spacing: -.02em; }
h2 { font-size: 1.3rem; letter-spacing: -.015em; }
h3 { font-size: 1.1rem; letter-spacing: -.01em; }

.skip-link {
    position: absolute; left: -9999px; top: 0; z-index: 100;
    padding: .5rem 1rem; background: var(--bg); color: var(--link);
}
.skip-link:focus { left: .5rem; top: .5rem; }

:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: 2px;
    border-radius: 2px;
}

.site-header {
    display: flex; align-items: center; flex-wrap: wrap;
    gap: .5rem 1rem;
    margin-bottom: 1.5rem; padding-bottom: .75rem;
    border-bottom: 1px solid var(--border);
    transition: border-color .2s ease;
    max-width: var(--content-width);
    margin-left: auto; margin-right: auto;
}
body.home .site-header {
    max-width: none; margin-left: 0; margin-right: 0;
}

.site-title {
    font-weight: 700; font-size: 19px;
    text-decoration: none; color: var(--text);
    display: inline-flex; align-items: center; gap: .5rem;
}
.site-title:visited { color: var(--text); }

.site-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8em;
    height: 1.8em;
    border-radius: 50%;
    background-color: currentColor;
    flex-shrink: 0;
}
.site-logo-mark {
    display: block;
    width: 60%;
    aspect-ratio: 921 / 830;
    background-color: var(--bg);
    -webkit-mask: url("/img/logo.svg") no-repeat center / contain;
    mask: url("/img/logo.svg") no-repeat center / contain;
}

.site-nav { display: flex; gap: 1.1rem; margin-left: auto; }
.site-nav a {
    font-size: .96rem; color: var(--muted);
    text-decoration: none; white-space: nowrap;
}
.site-nav a:hover { color: var(--link); }

.theme-toggle {
    background: none; border: none; cursor: pointer;
    color: var(--text); padding: 0;
    display: flex; align-items: center;
    transition: transform .2s ease;
}
.theme-toggle:hover { transform: rotate(15deg); }
.theme-toggle:active { transform: rotate(15deg) scale(.9); }

@media (max-width: 600px) {
    .site-header {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas: "title title" "nav toggle";
        column-gap: 1rem; row-gap: .6rem;
    }
    .site-title { grid-area: title; font-size: 17px; }
    .site-nav { grid-area: nav; margin-left: 0; gap: 1.25rem; align-self: center; }
    .theme-toggle { grid-area: toggle; align-self: center; margin-left: 0; }
}

.content-column { max-width: var(--content-width); margin: 0 auto; }

.index { display: flex; gap: 2.5rem; }
.index .article-list { flex-grow: 1; min-width: 0; }
.index aside {
    width: 28%; min-width: 0;
    align-self: flex-start;
    padding-left: 1.5rem;
    border-left: 1px solid var(--border);
    transition: border-color .2s ease;
}

.aside-section h4 {
    font-size: .87rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--faint); margin: 0 0 .3rem;
}
.aside-section:first-child h4 { margin-top: 1rem; }
.aside-section ul { list-style: none; padding: 0; margin: 0 0 1.25rem; }
.aside-section li { margin-bottom: .35rem; }
.aside-section a {
    font-size: .96rem;
    text-decoration: none; color: var(--muted);
    display: inline-block;
    transition: color .15s ease, transform .15s ease;
}
.aside-section a:visited { color: var(--muted); }
.aside-section a:hover { color: var(--link); transform: translateX(2px); }

.aside-links a {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
}
.aside-links .icon {
    flex: 0 0 auto;
    color: var(--faint);
    transition: color .15s ease;
}
.aside-links a:hover .icon { color: var(--link); }

.aside-bio p {
    margin: 0 0 1.25rem;
    font-style: italic;
    color: var(--muted);
    font-size: .96rem;
    line-height: 1.5;
}

.post-meta, .footnotes, .post-tags, .post-list .date {
    font-size: .85rem;
    color: var(--muted);
}
.type-label { text-decoration: none; color: inherit; }
.type-label:visited { color: inherit; }

.section-desc { font-size: .95rem; color: var(--muted); font-style: italic; }
.breadcrumbs { margin-bottom: .5rem; font-size: .85rem; color: var(--faint); }

.post-list .post {
    padding: .6rem .5rem;
    border-radius: var(--radius);
    transition: background-color .15s ease;
    background-image: linear-gradient(to right, var(--border) 85%, transparent);
    background-size: 100% 1px;
    background-position: bottom;
    background-repeat: no-repeat;
}
.post-list .post:last-child { background-image: none; }
.post-list .post:hover { background: var(--code-bg); }
.post-list .date { display: block; margin-top: .15rem; }

.post-list a, .toc a, .content-column li a { text-decoration: none; }
.post-list a:hover, .toc a:hover, .content-column li a:hover { text-decoration: underline; }

article a {
    text-decoration: none;
    background-image: linear-gradient(var(--link), var(--link));
    background-size: 0% 1px;
    background-position: 50% 100%;
    background-repeat: no-repeat;
    transition: background-size .25s cubic-bezier(.4,0,.2,1), color .15s ease;
}
article a:hover { background-size: 100% 1px; }
article .anchor, article .footnotes a { background-image: none; }

article ul, article ol { padding-left: 1.5rem; }
article img, article video, article iframe {
    display: block; margin: 0 auto; max-width: 100%;
}
article sup { line-height: 1; }
.content-column li { margin-bottom: .5rem; }

pre, code {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .85rem;
}
code {
    background-color: var(--code-bg);
    padding: .1rem .3rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
pre code { padding: 0; background: none; border: none; }
pre {
    background-color: var(--code-bg);
    padding: .6rem 1rem;
    margin: 1rem 0;
    max-width: 100%;
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: background-color .2s ease, border-color .2s ease;
}

blockquote,
.markdown-alert-note,
.markdown-alert-tip,
.markdown-alert-important,
.markdown-alert-warning,
.markdown-alert-caution {
    background-color: var(--code-bg);
    padding: .5rem 1rem;
    margin: 1rem 0;
    border-radius: var(--radius);
    transition: background-color .2s ease, border-color .2s ease;
    border-left: 3px solid var(--accent-quote);
}
blockquote:not([class*="markdown-alert"]) {
    font-style: italic;
    position: relative;
    padding-left: 2rem;
}
blockquote:not([class*="markdown-alert"])::before {
    content: "\201C";
    position: absolute;
    left: .5rem; top: .1rem;
    font-size: 2.5rem; line-height: 1;
    font-style: normal;
    color: var(--accent-quote);
}
blockquote > p:first-child { margin-top: 0; }
blockquote > p:last-child  { margin-bottom: 0; }

[class*="markdown-alert-"]::before {
    display: block;
    font-weight: 700;
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: .25rem;
}
.markdown-alert-note      { border-left-color: #4a86cf; }
.markdown-alert-note::before    { content: "Заметка"; color: #4a86cf; }
.markdown-alert-tip       { border-left-color: #3a9a5c; }
.markdown-alert-tip::before     { content: "Совет"; color: #3a9a5c; }
.markdown-alert-important { border-left-color: #b87a2a; }
.markdown-alert-important::before { content: "Важно"; color: #b87a2a; }
.markdown-alert-warning   { border-left-color: #c08a20; }
.markdown-alert-warning::before { content: "Предупреждение"; color: #c08a20; }
.markdown-alert-caution   { border-left-color: #cf3030; }
.markdown-alert-caution::before { content: "Осторожно"; color: #cf3030; }

kbd {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .8em;
    padding: .1rem .45rem;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 0 var(--border);
    white-space: nowrap;
}

dl { margin: 1rem 0; }
dt { font-weight: 700; margin-top: .75rem; }
dd { margin: .25rem 0 0 1.25rem; color: var(--muted); }

figure {
    margin: 1.5rem 0;
    text-align: center;
}
figure img { display: block; margin: 0 auto; }
figcaption {
    margin-top: .5rem;
    font-size: .85rem;
    color: var(--faint);
    font-style: italic;
}

.related-posts {
    margin-top: 2.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.related-posts h2 {
    font-size: .87rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--faint);
    margin: 0 0 .75rem;
}

.post-nav {
    margin-top: 2rem;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-size: .9rem;
}
.post-nav .prev, .post-nav .next { max-width: 48%; }
.post-nav .next { margin-left: auto; text-align: right; }
.post-nav a { text-decoration: none; color: var(--muted); display: block; }
.post-nav a:hover { color: var(--link); }
.post-nav .label {
    display: block;
    font-size: .8rem;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: .1rem;
}

.post-ornament {
    display: flex; align-items: center; gap: 1rem;
    margin: 2rem 0; color: var(--muted); font-size: 1.3rem;
}
.post-ornament::before, .post-ornament::after {
    content: ""; flex: 1; height: 1px;
    background: linear-gradient(to var(--dir), var(--border), transparent);
}
.post-ornament::before { --dir: left; }
.post-ornament::after  { --dir: right; }

table { border-collapse: collapse; width: 100%; font-size: .85rem; }
table thead th { border-bottom: 1px solid var(--muted); text-align: left; font-weight: 600; }
table th, table td { padding: .4rem .75rem; border-bottom: 1px solid var(--border); }

hr { border: none; text-align: center; margin: 2rem 0; }
hr::after { content: "* * *"; color: var(--muted); }

.toc { margin: 1rem 0; font-size: .9rem; }
.toc nav ul { padding-left: 1.5rem; margin: .5rem 0; }
.toc nav li { margin-bottom: .25rem; }

.anchor {
    color: var(--faint);
    text-decoration: none;
    font-weight: 400;
    margin-left: .3rem;
    opacity: 0;
    transition: opacity .15s ease;
}
h2:hover .anchor, h3:hover .anchor, h4:hover .anchor,
h5:hover .anchor, h6:hover .anchor, .anchor:focus { opacity: .4; }
.anchor:hover { opacity: 1; }

.post-tags {
    list-style: none; padding: 0;
    display: flex; flex-wrap: wrap; gap: .4rem;
    margin-top: 1.5rem;
}
.post-tags a {
    display: inline-block;
    padding: .2rem .65rem;
    background-color: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    text-decoration: none;
    font-size: .8rem;
    color: var(--muted);
    transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.post-tags a:visited { color: var(--muted); }
.post-tags a:hover {
    background-color: var(--border);
    color: var(--text);
    border-color: var(--faint);
}

.pagination {
    margin-top: 2rem;
    display: flex; gap: 1rem;
    font-size: .9rem;
}
.pagination a { text-decoration: none; color: var(--muted); transition: color .15s ease; }
.pagination a:hover { color: var(--link); }

footer {
    margin-top: 2rem;
    padding: .75rem 0;
    text-align: center;
    font-size: .9rem;
    color: var(--faint);
    border-top: 1px solid var(--border);
    transition: border-color .2s ease;
}
footer a { text-decoration: none; color: var(--muted); }
footer a:visited { color: var(--muted); }
footer a:hover { color: var(--link); }
footer .footer-byline { margin-top: .25rem; }
footer .footer-byline a { color: var(--faint); }
footer .footer-byline a:hover { color: var(--link); }

.back-to-top {
    position: fixed;
    bottom: 1.5rem;
    right: max(.75rem, calc(50% - 480px));
    width: 2rem; height: 2rem;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    color: var(--muted);
    text-decoration: none;
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease, color .15s ease, transform .15s ease;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; }
.back-to-top:visited { color: var(--muted); }
.back-to-top:hover { color: var(--link); transform: translateY(-2px); }

.page { min-height: 100vh; display: flex; flex-direction: column; }
.page-content { flex: 1; }

@media (max-width: 768px) {
    .index aside { width: 35%; padding-left: 1rem; }
    .index { gap: 1.5rem; }
}

@media (max-width: 640px) {
    body { padding: .75rem; }
    h1 { font-size: 1.3rem; }
    .index { display: block; }
    .index aside {
        width: 100%;
        display: flex; flex-wrap: wrap; gap: 0 2rem;
        margin-top: 2rem;
        padding-top: 1.5rem;
        padding-left: 0;
        border-left: none;
        border-top: 1px solid var(--border);
    }
    .index aside .aside-section { min-width: 6rem; flex: 1; }
    .aside-section:first-child h4 { margin-top: 0; }
    pre { font-size: .8rem; padding: .4rem .6rem; }
}

@media print {
    .site-header, footer, .breadcrumbs, .post-tags,
    .related-posts, .pagination, .skip-link, .back-to-top { display: none; }
    body { max-width: 100%; }
    a { color: inherit; text-decoration: underline; }
    a[href]::after { content: " (" attr(href) ")"; font-size: .8em; color: #555; }
    a[href^="#"]::after, a[href^="/"]::after { content: ""; }
}
