/* Engine styling. One file for the whole corpus — same as the template.
 *
 * Same rule as everywhere else: NOT ONE name of a specific site. Color,
 * font and layout are described with variables; a site that needs its
 * own shade overrides the variable instead of copying the file. A copy
 * is two files that silently drift apart, and a month later nobody knows
 * which one is correct.
 *
 * Fonts — system only. An external font pulls in someone else's domain on
 * every page (that breaks the isolation check and slows down rendering),
 * and if it fails to load, text silently falls back to a substitute:
 * the layout "works", but looks different from what was tested.
 */

:root {
    /* Ground and ink. Not pure white: on long technical text pure white
       gives excess contrast and tires the eye faster. */
    --ground: #f7f6f3;
    --surface: #ffffff;
    --ink: #16181d;
    --ink-2: #4a4f5a;
    --ink-3: #767c88;
    --line: #e3ded5;

    /* Brass — the color of the key and the color of action. Keep it in
       one place: links, active menu item, heading underline. */
    --accent: #a86a1f;
    --accent-soft: #f3e8d6;
    --link: #1f5f8b;
    --link-hover: #143f5e;

    --ok: #2e7d4f;
    --warn: #a8631f;
    --bad: #a32f2f;

    --radius: 10px;
    --gap: 1.25rem;
    --width: 74ch;

    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
             "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
                 "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --ground: #14161a;
        --surface: #1b1e24;
        --ink: #e8e6e1;
        --ink-2: #b3b8c2;
        --ink-3: #868d99;
        --line: #2b3038;
        --accent: #d59a4e;
        --accent-soft: #2c2418;
        --link: #7ab3d9;
        --link-hover: #a8cfe9;
    }
}

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

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

body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font: 1rem/1.65 var(--font);
    text-rendering: optimizeLegibility;
}

/* ------------------------------------------------------------------ header */

.header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--line);
}

.header__bar {
    max-width: 68rem;
    margin: 0 auto;
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    gap: var(--gap);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
}
.brand:hover { color: var(--accent); }
.brand .icon { color: var(--accent); }

.menu {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem;
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1 1 auto;
}
.menu a {
    display: block;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius);
    color: var(--ink-2);
    text-decoration: none;
    font-size: 0.95rem;
}
.menu a:hover { background: var(--accent-soft); color: var(--ink); }
.menu [aria-current="page"] > a { color: var(--accent); font-weight: 600; }

/* Burger: checkbox instead of JS, so the toggle works even without
   scripts. On a wide screen the button is hidden and .menu runs as a
   normal row — the rules below only kick in under the breakpoint. */
.menu-toggle { position: absolute; opacity: 0; pointer-events: none; }
.menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    order: 3;
    width: 2.25rem;
    height: 2.25rem;
    margin-left: auto;
    border-radius: var(--radius);
    color: var(--ink-2);
    cursor: pointer;
}
.menu-btn:hover { background: var(--accent-soft); color: var(--ink); }
.menu-toggle:focus-visible + .menu-btn { outline: 2px solid var(--accent); outline-offset: 1px; }

@media (max-width: 720px) {
    .header__bar { flex-wrap: wrap; }
    .menu-btn { display: inline-flex; }
    .header__bar > nav[aria-label] {
        order: 5;
        flex-basis: 100%;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.25s ease;
    }
    .menu-toggle:checked ~ nav[aria-label] {
        max-height: 70vh;
        overflow-y: auto;
    }
    .menu { flex-direction: column; flex-wrap: nowrap; gap: 0.1rem; padding-top: 0.4rem; }
    .menu a { padding: 0.6rem 0.75rem; }
}

.langs { display: flex; gap: 0.35rem; list-style: none; margin: 0; padding: 0; }
.langs a { color: var(--ink-3); text-decoration: none; font-size: 0.85rem; }
.langs [aria-current="page"] a { color: var(--accent); font-weight: 600; }

/* Search field: the index loads on first focus, so the field must look
   functional even before it loads — otherwise a person thinks it's broken. */
.search { position: relative; flex: 0 1 18rem; }
.search input {
    width: 100%;
    padding: 0.4rem 0.6rem 0.4rem 2rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 0.9rem;
}
.search input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.search .icon {
    position: absolute; left: 0.55rem; top: 50%; transform: translateY(-50%);
    color: var(--ink-3); pointer-events: none;
}
.search__results {
    position: absolute; top: calc(100% + 0.35rem); left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 12px 30px rgba(0,0,0,.12);
    list-style: none; margin: 0; padding: 0.25rem;
    max-height: 60vh; overflow: auto;
}
.search__results:empty { display: none; }
.search__results a {
    display: block; padding: 0.4rem 0.5rem; border-radius: 6px;
    color: var(--ink); text-decoration: none; font-size: 0.9rem;
}
.search__results a:hover { background: var(--accent-soft); }

/* ----------------------------------------------------------------- frame */

main { max-width: 68rem; margin: 0 auto; padding: 2rem 1rem 3rem; }

h1, h2, h3, h4 {
    line-height: 1.25;
    letter-spacing: -0.015em;
    text-wrap: balance;
    margin: 2rem 0 0.75rem;
}
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.3rem); margin-top: 0; }
h2 { font-size: 1.45rem; padding-top: 0.4rem; }
h3 { font-size: 1.15rem; }

p { margin: 0 0 1rem; }
a { color: var(--link); text-underline-offset: 0.15em; }
a:hover { color: var(--link-hover); }

/* --------------------------------------------------------------- article */

.article { background: var(--surface); border: 1px solid var(--line);
            border-radius: var(--radius); padding: clamp(1rem, 3vw, 2rem); }
.article .content { max-width: var(--width); }

.meta-row {
    display: flex; flex-wrap: wrap; gap: 0.9rem;
    color: var(--ink-3); font-size: 0.87rem;
    margin: 0 0 1.25rem; padding-bottom: 0.9rem;
    border-bottom: 1px solid var(--line);
}
.meta-row > * { display: inline-flex; align-items: center; gap: 0.35rem; }
.meta-row a { color: var(--ink-2); text-decoration: none; }
.meta-row a:hover { color: var(--accent); }

/* Article images. `height:auto` is mandatory: without it the browser takes
   the height from the attribute and the image drifts out of proportion —
   visible immediately on line wraps. */
.content img { max-width: 100%; height: auto; border-radius: 8px; display: block;
            margin: 1.25rem auto; }
.content figure { margin: 1.5rem 0; }
.content figcaption { color: var(--ink-3); font-size: 0.87rem; text-align: center;
                   margin-top: 0.5rem; }

.content ul, .content ol { padding-left: 1.25rem; margin: 0 0 1rem; }
.content li { margin: 0.35rem 0; }
.content ul { list-style: none; padding-left: 1.1rem; }
.content ul > li { position: relative; }
.content ul > li::before {
    content: ""; position: absolute; left: -0.95rem; top: 0.62em;
    width: 6px; height: 6px; border-radius: 2px; background: var(--accent);
}
.content ol { list-style: decimal; }
.content ol > li::marker { color: var(--accent); font-weight: 600; }

.content blockquote {
    margin: 1.5rem 0; padding: 0.75rem 1rem;
    border-left: 3px solid var(--accent);
    background: var(--accent-soft);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--ink-2);
}

.content code, .content kbd {
    font-family: var(--font-mono); font-size: 0.9em;
    background: var(--accent-soft); padding: 0.1em 0.35em; border-radius: 4px;
}
.content pre {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 0.9rem 1rem;
    overflow-x: auto;
}
.content pre code { background: none; padding: 0; }

/* Tables. A dedicated scrolling wrapper is mandatory: otherwise a wide
   table stretches the PAGE, and on a phone the whole text drifts
   sideways, not just the table. */
.table-wrap { overflow-x: auto; margin: 1.5rem 0;
                   border: 1px solid var(--line); border-radius: var(--radius); }
.content table { border-collapse: collapse; width: 100%; font-size: 0.94rem; }
.content thead th {
    background: var(--accent-soft); color: var(--ink);
    text-align: left; font-weight: 650;
    padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line);
    position: sticky; top: 0;
}
.content td, .content th { padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--line);
                     vertical-align: top; }
.content tbody tr:nth-child(even) { background: color-mix(in srgb, var(--ground) 55%, transparent); }
.content tbody tr:last-child td { border-bottom: 0; }
/* Digits in a column must line up in a column, otherwise comparing them
   by eye is impossible — which is the whole point of a table. */
.content td { font-variant-numeric: tabular-nums; }

/* Footnotes. A back-to-top link is mandatory: without it a reader who
   jumped down loses their place in the text and simply never returns. */
.content sup a, .footnote-link {
    text-decoration: none; font-size: 0.75em; font-weight: 700;
    color: var(--accent); padding: 0 0.15em;
}
.footnotes {
    margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--line);
    color: var(--ink-2); font-size: 0.9rem;
}
.footnotes ol { padding-left: 1.2rem; }
.footnotes li { margin: 0.4rem 0; }
.footnotes li:target { background: var(--accent-soft); border-radius: 6px; }

/* ------------------------------------------------------------------ feeds */

.articles { list-style: none; margin: 0; padding: 0;
             display: grid; gap: 0.9rem;
             grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr)); }
.articles > li {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 1rem 1.1rem;
    transition: border-color .15s ease, transform .15s ease;
}
.articles > li:hover { border-color: var(--accent); transform: translateY(-1px); }
.articles h2, .articles .title { margin: 0 0 0.35rem; font-size: 1.05rem; }
.articles a { color: var(--ink); text-decoration: none; }
.articles a:hover { color: var(--accent); }
.articles p { color: var(--ink-2); font-size: 0.92rem; margin: 0.35rem 0 0; }
.articles time { color: var(--ink-3); font-size: 0.82rem; }

.tags { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem;
         padding: 0; margin: 1.5rem 0 0; }
.tags a {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.2rem 0.6rem; border: 1px solid var(--line);
    border-radius: 999px; font-size: 0.82rem;
    color: var(--ink-2); text-decoration: none; background: var(--surface);
}
.tags a:hover { border-color: var(--accent); color: var(--accent); }

.pagination {
    display: flex; align-items: center; justify-content: center; gap: 1rem;
    margin: 2rem 0 0; color: var(--ink-3); font-size: 0.9rem;
}
.pagination a {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.4rem 0.8rem; border: 1px solid var(--line);
    border-radius: var(--radius); text-decoration: none;
    background: var(--surface); color: var(--ink-2);
}
.pagination a:hover { border-color: var(--accent); color: var(--accent); }

/* ----------------------------------------------------------------- footer */

.footer {
    border-top: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-2);
    font-size: 0.9rem;
}
.footer__bar {
    max-width: 68rem; margin: 0 auto; padding: 2rem 1rem;
    display: grid; gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
}
.footer h2 { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em;
             color: var(--ink-3); margin: 0 0 0.6rem; }
.footer ul { list-style: none; margin: 0; padding: 0; }
.footer li { margin: 0.3rem 0; }
.footer a { color: var(--ink-2); text-decoration: none; }
.footer a:hover { color: var(--accent); }
.footer__bottom {
    border-top: 1px solid var(--line); color: var(--ink-3); font-size: 0.85rem;
    padding: 1rem; text-align: center;
}

/* ------------------------------------------------------------------ misc */

.icon { width: 1em; height: 1em; flex: none; display: inline-block;
          vertical-align: -0.125em; fill: none; stroke: currentColor;
          stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

.sr-only {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

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

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

@media print {
    .header, .footer, .pagination, .search { display: none; }
    body { background: #fff; color: #000; }
    .article { border: 0; padding: 0; }
}

/* --------------------------------------------------------------- ad */
/* Space for the block is reserved IN ADVANCE: without `min-height` the ad
   loads asynchronously and pushes text down after a person has already
   started reading. This isn't cosmetics — it's a layout shift, for which
   search engines lower the page's score, and the reader loses their
   place. */
.ad {
    margin: 1.75rem 0;
    min-height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}
.ad--top { margin-top: 0.5rem; }
.ad ins { display: block; width: 100%; }
@media print { .ad { display: none; } }

/* --------------------------------------------------------------- rating */
.rating {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem;
    margin: 2rem 0 0; padding: 0.9rem 1rem;
    background: var(--accent-soft); border-radius: var(--radius);
    font-size: 0.95rem;
}
.rating__label { color: var(--ink-2); }
.rating__stars { display: inline-flex; gap: 0.1rem; }
.star {
    background: none; border: 0; cursor: pointer; padding: 0 0.1rem;
    font-size: 1.35rem; line-height: 1; color: var(--line);
    transition: color .12s ease, transform .12s ease;
}
.star:hover, .star:focus-visible { transform: scale(1.15); color: var(--accent); }
.star--lit { color: var(--accent); }
/* Hovering a star highlights it and every one to the left — otherwise
   it's unclear what value a click would set. */
.rating__stars:hover .star { color: var(--accent); }
.rating__stars .star:hover ~ .star { color: var(--line); }
.rating__summary { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rating__value { color: var(--ink); }
@media print { .rating { display: none; } }

/* ------------------------------------------------------------ thumbnails */
.articles > li { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
.articles .thumb {
    display: block; margin: -1rem -1.1rem 0; overflow: hidden;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--ground);
    /* The aspect ratio is fixed IN ADVANCE: without it cards jump around
       as images load, and the feed jitters under the cursor. */
    aspect-ratio: 16 / 9;
}
.articles .thumb img {
    width: 100%; height: 100%; object-fit: cover; display: block;
    transition: transform .2s ease;
}
.articles > li:hover .thumb img { transform: scale(1.03); }

.rating--compact { margin: 0 0 1rem; padding: 0.35rem 0; background: none; }
.rating--compact .star { font-size: 1.1rem; }

/* --------------------------------------------------------------- breadcrumbs */
.crumbs { max-width: 68rem; margin: 0 auto; padding: 0.75rem 1rem 0; font-size: 0.85rem; }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.35rem;
             margin: 0; padding: 0; color: var(--ink-3); }
.crumbs li + li::before { content: "/"; margin-right: 0.35rem; color: var(--line); }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs [aria-current="page"] { color: var(--ink-3); }
@media print { .crumbs { display: none; } }
