/* ---------------------------------------------------------------------------
   Design tokens
   --------------------------------------------------------------------------- */

:root {
    color-scheme: light dark;

    --bg: #f8f6f1;
    --bg-soft: #f1eee8;
    --text: #1f1f1f;
    --text-strong: #101010;
    --muted: #5f5a52;
    --line: #ddd7cc;
    --line-strong: #c3bbac;
    --link: #14509e;
    --link-visited: #6b3fa0;
    --code-bg: #f1ede4;
    --code-text: #2b2b2b;
    --quote-bar: #c3bbac;
    --selection: #ffe9a8;

    --font-body: Georgia, "Iowan Old Style", "Times New Roman", serif;
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;

    /* ~17px on a phone, ~19px on a wide screen */
    --size-body: clamp(1.0625rem, 1.0rem + 0.32vw, 1.1875rem);
    --size-ui: clamp(0.875rem, 0.85rem + 0.15vw, 0.9375rem);

    /* reading column: ~860px on desktop, same ballpark as Habr's article body */
    --max-width: 54rem;
    --gutter: clamp(1.125rem, 4vw, 2rem);
    --radius: 6px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17171a;
        --bg-soft: #1e1e22;
        --text: #dedbd4;
        --text-strong: #f2efe9;
        --muted: #9c968c;
        --line: #32323a;
        --line-strong: #45454f;
        --link: #7cb0f2;
        --link-visited: #bda3e8;
        --code-bg: #1e1e23;
        --code-text: #d8d4cc;
        --quote-bar: #45454f;
        --selection: #3c4a63;
    }
}

/* ---------------------------------------------------------------------------
   Base
   --------------------------------------------------------------------------- */

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

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--size-body);
    line-height: 1.7;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    overflow-wrap: break-word;
}

body > main {
    flex: 1 0 auto;
}

::selection {
    background: var(--selection);
}

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

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

a:hover {
    text-decoration-thickness: 2px;
}

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

img {
    max-width: 100%;
    height: auto;
}

hr {
    height: 1px;
    border: 0;
    background: var(--line);
    margin: 2.5rem 0;
}

.container {
    width: 100%;
    max-width: var(--max-width);
    margin-inline: auto;
    padding-inline: max(var(--gutter), env(safe-area-inset-left));
}

/* ---------------------------------------------------------------------------
   Header
   --------------------------------------------------------------------------- */

.site-header {
    border-bottom: 1px solid var(--line);
    margin-bottom: 2rem;
}

.nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem 1.5rem;
    flex-wrap: wrap;
    font-family: var(--font-ui);
    font-size: var(--size-ui);
    padding-block: 0.5rem;
}

.brand {
    color: var(--text-strong);
    text-decoration: none;
    font-weight: 600;
    letter-spacing: -0.01em;
    /* comfortable tap target on touch screens */
    padding-block: 0.55rem;
}

.brand:hover,
.brand:focus-visible {
    text-decoration: underline;
}

.menu {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    margin-inline-start: auto;
}

.menu a {
    color: var(--muted);
    text-decoration: none;
    padding: 0.55rem 0.6rem;
    border-radius: var(--radius);
}

.menu a:hover {
    color: var(--text-strong);
    background: var(--bg-soft);
}

.menu a.is-active {
    color: var(--text-strong);
    font-weight: 600;
}

/* ---------------------------------------------------------------------------
   Home / list pages
   --------------------------------------------------------------------------- */

.hero {
    padding-bottom: 1.5rem;
}

.hero h1 {
    font-size: clamp(2rem, 1.5rem + 2.4vw, 2.75rem);
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin: 0 0 0.5rem;
    color: var(--text-strong);
}

.hero-text {
    color: var(--muted);
    margin: 0;
    max-width: 46rem;
}

.section {
    padding-bottom: 2rem;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--line);
    font-family: var(--font-ui);
}

.section-head h1,
.section-head h2 {
    margin: 0;
    font-size: clamp(1.375rem, 1.2rem + 0.8vw, 1.625rem);
    line-height: 1.25;
    letter-spacing: -0.01em;
    color: var(--text-strong);
}

.link-more {
    font-family: var(--font-ui);
    font-size: var(--size-ui);
    text-decoration: none;
    white-space: nowrap;
}

.link-more:hover {
    text-decoration: underline;
}

.post-card {
    padding-bottom: 1.75rem;
    margin-bottom: 1.75rem;
    border-bottom: 1px solid var(--line);
}

.post-card:last-child {
    border-bottom: 0;
    margin-bottom: 0;
}

.post-card h2,
.post-card h3 {
    margin: 0.25rem 0 0.4rem;
    font-size: clamp(1.3rem, 1.1rem + 1vw, 1.6rem);
    line-height: 1.25;
    letter-spacing: -0.01em;
    font-weight: 600;
}

.post-card h2 a,
.post-card h3 a {
    color: var(--text-strong);
    text-decoration: none;
}

.post-card h2 a:hover,
.post-card h3 a:hover,
.post-card h2 a:focus-visible,
.post-card h3 a:focus-visible {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

.post-date,
.reading-time,
.post-description,
.tag-list {
    font-family: var(--font-ui);
    font-size: var(--size-ui);
    color: var(--muted);
}

.post-date,
.reading-time {
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
}

.post-date {
    margin: 0;
}

.post-description {
    margin: 0.5rem 0 0.6rem;
    line-height: 1.6;
}

.tag-list {
    margin: 0.5rem 0 0;
}

.tag {
    margin-right: 0.5rem;
}

/* ---------------------------------------------------------------------------
   Post page
   --------------------------------------------------------------------------- */

.post-page {
    padding-bottom: 3rem;
}

.post-header {
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--line);
}

.post-header h1 {
    font-size: clamp(1.9rem, 1.4rem + 2.6vw, 2.75rem);
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin: 0.35rem 0 0.6rem;
    color: var(--text-strong);
}

.post-description {
    max-width: 46rem;
}

.post-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem 1rem;
    flex-wrap: wrap;
    font-family: var(--font-ui);
    font-size: var(--size-ui);
    color: var(--muted);
}

.post-meta-row .tag-list {
    margin: 0;
}

/* ---------------------------------------------------------------------------
   Rendered markdown
   --------------------------------------------------------------------------- */

.markdown-body > :first-child {
    margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    font-family: var(--font-ui);
    line-height: 1.25;
    letter-spacing: -0.01em;
    font-weight: 600;
    color: var(--text-strong);
    margin: 2.5rem 0 0.75rem;
    /* keep anchor links clear of the viewport edge when jumping to a heading */
    scroll-margin-top: 1.5rem;
}

.markdown-body h1 {
    font-size: clamp(1.6rem, 1.35rem + 1.2vw, 2rem);
}

.markdown-body h2 {
    font-size: clamp(1.4rem, 1.2rem + 1vw, 1.7rem);
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--line);
}

.markdown-body h3 {
    font-size: clamp(1.2rem, 1.1rem + 0.6vw, 1.375rem);
}

.markdown-body h4 {
    font-size: 1.0625rem;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table,
.markdown-body figure,
.markdown-body details {
    margin: 1.15rem 0;
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 1.5rem;
}

.markdown-body li {
    margin: 0.35rem 0;
}

.markdown-body li > ul,
.markdown-body li > ol {
    margin: 0.35rem 0;
}

.markdown-body strong {
    color: var(--text-strong);
    font-weight: 700;
}

.markdown-body a {
    text-decoration: underline;
}

/* Inline code: must never widen the page on a phone. */
.markdown-body code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--code-bg);
    color: var(--code-text);
    padding: 0.15em 0.35em;
    border: 1px solid var(--line);
    border-radius: 4px;
    overflow-wrap: break-word;
}

/* Code blocks scroll sideways instead of squeezing the text column. */
.markdown-body pre {
    background: var(--code-bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.875rem;
    line-height: 1.55;
    tab-size: 4;
}

.markdown-body pre code {
    background: none;
    border: 0;
    padding: 0;
    font-size: inherit;
    white-space: pre;
    overflow-wrap: normal;
}

.markdown-body blockquote {
    margin-inline: 0;
    padding: 0.35rem 0 0.35rem 1.15rem;
    border-left: 3px solid var(--quote-bar);
    color: var(--muted);
    font-style: italic;
}

.markdown-body blockquote > :first-child {
    margin-top: 0;
}

.markdown-body blockquote > :last-child {
    margin-bottom: 0;
}

/* Wide tables scroll instead of overflowing the viewport (GitHub's approach). */
.markdown-body table {
    display: block;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: collapse;
    font-family: var(--font-ui);
    font-size: var(--size-ui);
}

.markdown-body th,
.markdown-body td {
    border: 1px solid var(--line);
    padding: 0.5rem 0.75rem;
    text-align: left;
    vertical-align: top;
}

.markdown-body th {
    background: var(--bg-soft);
    color: var(--text-strong);
    font-weight: 600;
    white-space: nowrap;
}

.markdown-body img {
    display: block;
    margin-inline: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-soft);
}

.markdown-body figure {
    margin-inline: 0;
}

.markdown-body figcaption {
    margin-top: 0.5rem;
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    color: var(--muted);
    text-align: center;
}

/* ---------------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------------- */

.site-footer {
    flex-shrink: 0;
    margin-top: 3rem;
    padding: 1.5rem 0 calc(2.5rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    font-family: var(--font-ui);
    font-size: var(--size-ui);
    color: var(--muted);
}

.footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem 1.5rem;
    flex-wrap: wrap;
}

.footer-note {
    margin: 0;
}

.footer-links {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--muted);
    text-decoration: none;
    padding-block: 0.4rem;
}

.footer-links a:hover {
    color: var(--text-strong);
    text-decoration: underline;
}

.footer-built {
    margin: 0.75rem 0 0;
    font-size: 0.8125rem;
    opacity: 0.75;
}

/* ---------------------------------------------------------------------------
   Preferences and print
   --------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

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

@media print {
    :root {
        --bg: #fff;
        --text: #000;
        --muted: #444;
        --line: #bbb;
        --code-bg: #f4f4f4;
    }

    .site-header,
    .site-footer,
    .link-more {
        display: none;
    }

    body {
        font-size: 11pt;
    }

    .markdown-body pre,
    .markdown-body blockquote,
    .markdown-body table,
    .markdown-body figure {
        break-inside: avoid;
    }

    .markdown-body a::after {
        content: " (" attr(href) ")";
        font-size: 0.85em;
        color: #555;
    }
}
