* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-color: #ffffff;
    --text-color: #2d2d2d;
    --text-secondary: #6b6b6b;
    --link-color: #2d2d2d;
    --link-hover-color: #000000;
    --border-color: #e5e5e5;
    --lang-btn-active: #2d2d2d;
    --lang-btn-active-text: #ffffff;
    --code-block-bg: var(--bg-color);
    --inline-code-bg: #f7f7f7;
    --code-text: var(--text-color);
    /* Muted "editor-like" syntax palette (light) */
    --code-keyword: #2f6f9f;
    --code-string: #2f7a5a;
    --code-number: #6b4ca6;
    --code-comment: #7a7a7a;
    --code-operator: #3b3b3b;
    --code-func: #6a5d00;
    --header-control-height: 32px;
}

body.dark {
    --bg-color: #0a0a0a;
    --text-color: #e5e5e5;
    --text-secondary: #a0a0a0;
    --link-color: #e5e5e5;
    --link-hover-color: #ffffff;
    --border-color: #2a2a2a;
    --lang-btn-active: #e5e5e5;
    --lang-btn-active-text: #0a0a0a;
    --code-block-bg: #0f0f0f;
    --inline-code-bg: #131313;
    --code-text: #e5e5e5;
    /* Muted "editor-like" syntax palette (dark, Cursor-ish) */
    /* slightly desaturated to avoid "neon" on dark background */
    --code-keyword: #7b96c7;
    --code-string: #88a96a;
    --code-number: #a38ad1;
    --code-comment: #5b647f;
    --code-operator: #7aa8bf;
    --code-func: #c19a69;
}

@media (prefers-color-scheme: dark) {
    body:not(.light):not(.dark) {
        --bg-color: #0a0a0a;
        --text-color: #e5e5e5;
        --text-secondary: #a0a0a0;
        --link-color: #e5e5e5;
        --link-hover-color: #ffffff;
        --border-color: #2a2a2a;
        --lang-btn-active: #e5e5e5;
        --lang-btn-active-text: #0a0a0a;
        --code-block-bg: #0f0f0f;
        --inline-code-bg: #131313;
        --code-text: #e5e5e5;
        --code-keyword: #7b96c7;
        --code-string: #88a96a;
        --code-number: #a38ad1;
        --code-comment: #5b647f;
        --code-operator: #7aa8bf;
        --code-func: #c19a69;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    line-height: 1.7;
    color: var(--text-color);
    background-color: var(--bg-color);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 700px;
    width: 100%;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4rem;
    flex-wrap: wrap;
    gap: 1.5rem;
}

h1 {
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--text-color);
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.site-title {
    display: inline-flex;
    flex-direction: column;
    gap: 0.25rem;
}

.site-title__name {
    display: block;
}

.site-title__subtitle {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.02em;
    line-height: 1.4;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.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;
}

.book-nav-btn {
    height: var(--header-control-height);
    padding: 0 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 400;
    transition: all 0.15s ease;
    font-family: inherit;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.book-nav-btn:hover {
    color: var(--text-color);
    border-color: var(--text-color);
}

.book-nav-btn:focus-visible {
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}

.book-nav-fab {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: calc(var(--header-control-height) + 4px);
    height: calc(var(--header-control-height) + 4px);
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-color);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 400;
    transition: all 0.15s ease;
    font-family: inherit;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9997;
}

.book-nav-fab:hover {
    color: var(--text-color);
    border-color: var(--text-color);
}

.book-nav-fab:focus-visible {
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}

.book-nav-fab__icon {
    display: block;
    line-height: 1;
    font-size: 1.1rem;
}

.theme-btn {
    width: var(--header-control-height);
    height: var(--header-control-height);
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 400;
    transition: all 0.15s ease;
    font-family: inherit;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-btn:hover {
    color: var(--text-color);
    border-color: var(--text-color);
}

.theme-icon {
    display: block;
    line-height: 1;
    filter: grayscale(100%);
}

.lang-switcher {
    display: flex;
    gap: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    height: var(--header-control-height);
}

.lang-btn {
    height: 100%;
    padding: 0 0.9rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 400;
    transition: all 0.15s ease;
    font-family: inherit;
    line-height: 1;
    border-right: 1px solid var(--border-color);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.lang-btn:last-child {
    border-right: none;
}

.lang-btn:hover {
    color: var(--text-color);
    background-color: transparent;
}

.lang-btn.active {
    background-color: var(--lang-btn-active);
    color: var(--lang-btn-active-text);
    border-color: var(--lang-btn-active);
}

.lang-btn.active:hover {
    color: var(--lang-btn-active-text);
}

.book-nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 10000;
}

body.dark .book-nav-overlay {
    background: rgba(0, 0, 0, 0.55);
}

.book-nav-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(420px, 92vw);
    background: var(--bg-color);
    border-left: 1px solid var(--border-color);
    z-index: 10001;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
}

.book-nav-drawer.is-open {
    transform: translateX(0);
}

@media (prefers-reduced-motion: reduce) {
    .book-nav-drawer {
        transition: none;
    }
}

.book-nav-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.book-nav-drawer__title {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    line-height: 1.2;
}

.book-nav-drawer__close {
    width: var(--header-control-height);
    height: var(--header-control-height);
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: 400;
    transition: all 0.15s ease;
    font-family: inherit;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-nav-drawer__close:hover {
    color: var(--text-color);
    border-color: var(--text-color);
}

.book-nav-drawer__close:focus-visible {
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}

.book-nav-drawer__body {
    padding: 1rem 1rem;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.book-nav-drawer__section + .book-nav-drawer__section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.book-nav-drawer__section-title {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.75rem;
}

.book-nav-drawer__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.book-nav-drawer__item + .book-nav-drawer__item {
    margin-top: 0.35rem;
}

.book-nav-drawer__link {
    display: block;
    text-decoration: none;
    color: var(--text-color);
    padding: 0.35rem 0.25rem;
    border-radius: 4px;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.book-nav-drawer__link:hover {
    opacity: 0.75;
}

.book-nav-drawer__link.is-active {
    background: var(--inline-code-bg);
}

.book-nav-drawer__link:focus-visible {
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}

.content-section {
    animation: fadeIn 0.2s ease;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.bio {
    margin-bottom: 4rem;
}

.bio p {
    font-size: 1rem;
    margin-bottom: 1.25rem;
    color: var(--text-color);
    line-height: 1.8;
    font-weight: 400;
}

.bio p:last-child {
    margin-bottom: 0;
}

.links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.link-card {
    display: block;
    padding: 1.75rem 0;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.3s ease;
    border-bottom: 1px solid var(--border-color);
}

.link-card:last-child {
    border-bottom: none;
}

.link-card:hover {
    opacity: 0.7;
    color: var(--link-hover-color);
}

.link-card h3 {
    font-size: 0.95rem;
    font-weight: 400;
    margin-bottom: 0.4rem;
    color: inherit;
    letter-spacing: -0.01em;
    transition: color 0.3s ease;
}

.link-card p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
    font-weight: 400;
    transition: color 0.3s ease, opacity 0.3s ease;
}

.link-card:hover p {
    opacity: 0.8;
}

.articles-section {
    margin-top: 4rem;
    padding-top: 4rem;
    border-top: 1px solid var(--border-color);
}

.articles-section h2 {
    font-size: 0.875rem;
    font-weight: 400;
    margin-bottom: 2rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.articles {
    display: flex;
    flex-direction: column;
    gap: 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.article-card {
    display: block;
    padding: 1.75rem 0;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.3s ease;
    border-bottom: 1px solid var(--border-color);
}

.article-card:last-child {
    border-bottom: none;
}

.article-card:hover {
    opacity: 0.7;
    color: var(--link-hover-color);
}

.article-card h3 {
    font-size: 0.95rem;
    font-weight: 400;
    margin-bottom: 0.5rem;
    color: inherit;
    letter-spacing: -0.01em;
    line-height: 1.4;
    transition: color 0.3s ease;
}

.article-card p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.5rem;
    font-weight: 400;
    transition: color 0.3s ease, opacity 0.3s ease;
}

.article-card:hover p {
    opacity: 0.8;
}

.article-source {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

@media (max-width: 600px) {
    body {
        padding: 2rem 1rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        margin-bottom: 3rem;
        gap: 1rem;
    }

    .header-controls {
        width: 100%;
        justify-content: flex-start;
    }

    .bio {
        margin-bottom: 3rem;
    }

    .bio p {
        font-size: 0.95rem;
    }
}

/* Post/Article page styles */
.post {
    animation: fadeIn 0.2s ease;
}

.post-header {
    margin-bottom: 3rem;
}

.post-title {
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--text-color);
    letter-spacing: -0.01em;
    line-height: 1.3;
    margin-bottom: 1rem;
}

.post-content {
    line-height: 1.8;
}

.post-body {
    margin-top: 3rem;
}

.post-body h2 {
    font-size: 1.25rem;
    font-weight: 400;
    color: var(--text-color);
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    letter-spacing: -0.01em;
}

.post-body h3 {
    font-size: 1.1rem;
    font-weight: 400;
    color: var(--text-color);
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    letter-spacing: -0.01em;
}

.post-body h2,
.post-body h3,
.post-body h4,
.post-body h5,
.post-body h6 {
    position: relative;
    scroll-margin-top: 1.25rem;
}

.bio h2,
.bio h3,
.bio h4,
.bio h5,
.bio h6 {
    position: relative;
    scroll-margin-top: 1.25rem;
}

.post-body .heading-anchor {
    position: absolute;
    top: 50%;
    left: -1.6rem;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 3px;
    color: var(--text-secondary);
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
    vertical-align: middle;
    user-select: none;
}

.bio .heading-anchor {
    position: absolute;
    top: 50%;
    left: -1.6rem;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 3px;
    color: var(--text-secondary);
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
    vertical-align: middle;
    user-select: none;
}

.post-body h2:hover .heading-anchor,
.post-body h3:hover .heading-anchor,
.post-body h4:hover .heading-anchor,
.post-body h5:hover .heading-anchor,
.post-body h6:hover .heading-anchor,
.post-body h2:focus-within .heading-anchor,
.post-body h3:focus-within .heading-anchor,
.post-body h4:focus-within .heading-anchor,
.post-body h5:focus-within .heading-anchor,
.post-body h6:focus-within .heading-anchor {
    opacity: 1;
}

.bio h2:hover .heading-anchor,
.bio h3:hover .heading-anchor,
.bio h4:hover .heading-anchor,
.bio h5:hover .heading-anchor,
.bio h6:hover .heading-anchor,
.bio h2:focus-within .heading-anchor,
.bio h3:focus-within .heading-anchor,
.bio h4:focus-within .heading-anchor,
.bio h5:focus-within .heading-anchor,
.bio h6:focus-within .heading-anchor {
    opacity: 1;
}

.post-body .heading-anchor:hover {
    color: var(--text-color);
    background: var(--inline-code-bg);
}

.bio .heading-anchor:hover {
    color: var(--text-color);
    background: var(--inline-code-bg);
}

.post-body .heading-anchor:focus-visible {
    opacity: 1;
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}

.bio .heading-anchor:focus-visible {
    opacity: 1;
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}

.post-body .heading-anchor[data-copied="true"] {
    opacity: 1;
    color: var(--lang-btn-active-text);
    background: var(--lang-btn-active);
}

.bio .heading-anchor[data-copied="true"] {
    opacity: 1;
    color: var(--lang-btn-active-text);
    background: var(--lang-btn-active);
}

.post-body p {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-color);
    margin-bottom: 1.25rem;
}

.post-body ul,
.post-body ol {
    margin-bottom: 1.25rem;
    padding-left: 1.5rem;
}

.post-body li {
    margin-bottom: 0.5rem;
    line-height: 1.8;
}

.post-body a {
    color: var(--link-color);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.post-body a:hover {
    opacity: 0.7;
    color: var(--link-hover-color);
}

/* Links inside home/section content and TOC */
.bio a,
.toc a {
    color: var(--link-color);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.bio a:hover,
.toc a:hover {
    opacity: 0.7;
    color: var(--link-hover-color);
}

.toc ul,
.toc ol {
    margin: 0;
    padding-left: 1.5rem;
}

/* Tables (Markdown) */
.table-wrap {
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap table {
    margin: 0;
    border-collapse: collapse;
    /* allow wide tables to scroll without shrinking the layout */
    width: max-content;
    min-width: 100%;
}

.table-wrap thead th {
    font-weight: 500;
    text-align: left;
    background: var(--inline-code-bg);
}

.table-wrap th,
.table-wrap td {
    border: 1px solid var(--border-color);
    padding: 0.6rem 0.75rem;
    vertical-align: top;
}

.table-wrap table code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.post-body blockquote {
    margin: 1.5rem 0;
    padding-left: 1rem;
    border-left: 2px solid var(--border-color);
    color: var(--text-secondary);
}

.post-body blockquote p {
    margin-bottom: 0.75rem;
}

.post-body blockquote p:last-child {
    margin-bottom: 0;
}

.post-body pre {
    margin: 1.5rem 0;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--code-block-bg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    tab-size: 4;
}

.post-body .highlight {
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--code-block-bg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.post-body .highlight pre {
    margin: 0;
    padding: 0.9rem 1rem;
    border: none;
    border-radius: 0;
    background: transparent !important; /* перебить inline chroma background */
    color: var(--code-text) !important; /* перебить inline chroma base color */
    overflow: visible;
    tab-size: 4;
}

.post-body .highlight code {
    background: transparent !important;
}

.post-body .highlight code,
.post-body .highlight pre code {
    color: var(--code-text) !important;
}

/* Chroma uses inline colors; remap them to a muted editor-like palette */
.post-body .highlight [style*="color:#66d9ef"] { color: var(--code-keyword) !important; } /* keywords (monokai cyan) */
.post-body .highlight [style*="color:#ae81ff"] { color: var(--code-number) !important; } /* numbers (monokai purple) */
.post-body .highlight [style*="color:#e6db74"] { color: var(--code-string) !important; } /* strings (monokai yellow) */
.post-body .highlight [style*="color:#75715e"] { color: var(--code-comment) !important; } /* comments (monokai gray) */
.post-body .highlight [style*="color:#f92672"] { color: var(--code-operator) !important; } /* operators (monokai pink) */
.post-body .highlight [style*="color:#fd971f"] { color: var(--code-func) !important; } /* functions/types (monokai orange) */
.post-body .highlight [style*="color:#a6e22e"] { color: var(--code-string) !important; } /* identifiers (monokai green) */

.post-body pre code {
    display: block;
    padding: 0;
    background: transparent;
    border-radius: 0;
    color: var(--code-text);
    font-size: 0.85rem;
    line-height: 1.55;
}

.post-body :not(pre) > code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    background: var(--inline-code-bg);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    border: 1px solid var(--border-color);
}

.post-body strong {
    font-weight: 500;
    color: var(--text-color);
}

.post-footer {
    margin-top: 4rem;
    padding-top: 3rem;
    border-top: 1px solid var(--border-color);
}

.back-link {
    display: inline-block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s ease;
}

.back-link:hover {
    color: var(--text-color);
}

/* Reading progress bar */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 9999;
    pointer-events: none;
    background-color: transparent;
}

.reading-progress__bar {
    height: 100%;
    width: 100%;
    background-color: var(--text-color);
    transform-origin: left;
    transform: scaleX(0);
    transition: transform 0.1s ease-out;
}

/* Scroll to top button */
.scroll-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: var(--header-control-height);
    height: var(--header-control-height);
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 400;
    transition: all 0.15s ease;
    font-family: inherit;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
}

.scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-to-top:hover {
    color: var(--text-color);
    border-color: var(--text-color);
}

.scroll-to-top__icon {
    display: block;
    line-height: 1;
    font-size: 1.2rem;
}

