/* ==========================================================================
   Brainy, a Ghost theme for The Brainy Home
   1. Fonts   2. Tokens   3. Base   4. Header   5. Home: intro + topic tiles
   6. Post lists   7. Archive headers   8. Article   9. Content
   10. Ghost cards   11. Footer, pager, misc   12. Responsive
   ========================================================================== */

/* 1. Fonts: self-hosted, no third-party requests -------------------------- */

@font-face {
    font-family: "Archivo";
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    font-stretch: 62% 125%;
    src: url("../fonts/archivo.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Archivo";
    font-style: normal;
    font-display: swap;
    font-weight: 100 900;
    font-stretch: 62% 125%;
    src: url("../fonts/archivo-ext.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+20A0-20AB, U+20AD-20C0, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Source Serif 4";
    font-style: normal;
    font-display: swap;
    font-weight: 200 900;
    src: url("../fonts/source-serif.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Source Serif 4";
    font-style: normal;
    font-display: swap;
    font-weight: 200 900;
    src: url("../fonts/source-serif-ext.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+20A0-20AB, U+20AD-20C0, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Source Serif 4";
    font-style: italic;
    font-display: swap;
    font-weight: 200 900;
    src: url("../fonts/source-serif-italic.woff2") format("woff2");
}
@font-face {
    font-family: "JetBrains Mono";
    font-style: normal;
    font-display: swap;
    font-weight: 400;
    src: url("../fonts/jetbrains-mono.woff2") format("woff2");
}
@font-face {
    font-family: "JetBrains Mono";
    font-style: normal;
    font-display: swap;
    font-weight: 700;
    src: url("../fonts/jetbrains-mono-bold.woff2") format("woff2");
}

/* 2. Tokens --------------------------------------------------------------- */

:root {
    /* Light: Home Assistant's default theme (frontend core/color tokens) */
    --paper: #FAFAFA;          /* primary-background-color */
    --paper-sunk: #F3F3F3;     /* ha-color-neutral-95 */
    --surface: #FFFFFF;        /* card-background-color */
    --ink: #141414;            /* ha-color-text-primary (neutral-05) */
    --ink-soft: #5E5E5E;       /* ha-color-text-secondary (neutral-40) */
    --line: #E0E0E0;           /* divider-color, rgba(0,0,0,.12) on the page */
    --wall: #CCCCCC;           /* ha-color-neutral-80 */
    --grid: rgba(0, 0, 0, 0.05);
    --signal: #FF9800;         /* accent-color */
    --accent: #009AC7;         /* primary-color (ha-color-primary-40) */
    --link: #009AC7;           /* ha-color-text-link */
    --on-accent: #FFFFFF;
    --focus: #009AC7;
    --code-bg: #202020;        /* ha-color-neutral-10 */
    --code-ink: #E6E6E6;
    --code-line: #363636;
    --inline-code-bg: rgba(0, 0, 0, 0.06);

    --font-head: var(--gh-font-heading, "Archivo"), "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-ui: "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-body: var(--gh-font-body, "Source Serif 4"), "Source Serif 4", "Iowan Old Style", Georgia, serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --measure: 42rem;
    --wide: 62rem;
    --page: 74rem;
    --gutter: clamp(1.25rem, 4vw, 2.5rem);
    --radius-s: 4px;
    --radius-m: 8px;

    color-scheme: light;
}

[data-theme="dark"] {
    /* Dark: Home Assistant's default dark theme */
    --paper: #111111;          /* primary-background-color */
    --paper-sunk: #1C1C1C;
    --surface: #1C1C1C;        /* card-background-color */
    --ink: #E1E1E1;            /* primary-text-color */
    --ink-soft: #9B9B9B;       /* secondary-text-color */
    --line: #2E2E2E;           /* divider-color, rgba(225,225,225,.12) on the page */
    --wall: #4A4A4A;           /* ha-color-neutral-30 */
    --grid: rgba(255, 255, 255, 0.04);
    --signal: #FF9800;
    --accent: #009AC7;
    --link: #37C8FD;           /* ha-color-text-link in dark (primary-60) */
    --on-accent: #FFFFFF;
    --focus: #37C8FD;
    --code-bg: #1C1C1C;
    --code-ink: #E6E6E6;
    --code-line: #363636;
    --inline-code-bg: rgba(255, 255, 255, 0.08);

    /* No `color-scheme: dark` here on purpose: browsers then paint embedded
       iframes that don't declare a scheme (Ghost comments, Portal, search)
       with an opaque white canvas. Scrollbars are coloured by hand instead. */
    scrollbar-color: #4A4A4A #111111;
}

/* 3. Base ----------------------------------------------------------------- */

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

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

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 1rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

img, svg, video { display: block; max-width: 100%; height: auto; }

a { color: inherit; }

::selection { background: color-mix(in oklab, var(--signal) 45%, transparent); }

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

.skip-link {
    position: absolute;
    left: 1rem;
    top: -4rem;
    z-index: 100;
    padding: 0.6rem 1rem;
    background: var(--ink);
    color: var(--paper);
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--radius-s);
}
.skip-link:focus { top: 1rem; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0 1.15rem;
    border: 2px solid var(--accent);
    border-radius: var(--radius-s);
    background: var(--accent);
    color: var(--on-accent);
    font: 650 0.95rem/1 var(--font-ui);
    text-decoration: none;
    cursor: pointer;
}
.button:hover { background: color-mix(in oklab, var(--accent) 85%, var(--ink)); border-color: color-mix(in oklab, var(--accent) 85%, var(--ink)); }
.button--small { min-height: 2.25rem; padding: 0 0.9rem; font-size: 0.875rem; }
.button--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.button--ghost:hover { background: var(--paper-sunk); border-color: var(--wall); }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 0;
    border-radius: var(--radius-s);
    background: transparent;
    color: var(--ink-soft);
    cursor: pointer;
}
.icon-button:hover { color: var(--ink); background: var(--paper-sunk); }

.meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    margin: 0;
    color: var(--ink-soft);
    font: 450 0.875rem/1.4 var(--font-ui);
}

/* Tag chip: a small swatch in the tag colour */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ink);
    font: 650 0.875rem/1.2 var(--font-ui);
    font-stretch: 108%;
    text-decoration: none;
}
.chip::before, .tag-swatch {
    content: "";
    flex: none;
    display: inline-block;
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    background: var(--tag-color, var(--tag-default, var(--tag-auto, var(--accent))));
}
.chip:hover { text-decoration: underline; text-underline-offset: 3px; }

.section-heading {
    margin: 0 0 0.5rem;
    font: 750 1.05rem/1.2 var(--font-head);
    font-stretch: 115%;
    color: var(--ink-soft);
}

/* Built-in topic colours (Home Assistant's named colours), used when a tag has no accent colour set in
   Ghost Admin (an Admin colour always wins). Tiles for tags not listed
   here take the next colour from a rotating palette. */
[data-tag="home-assistant"] { --tag-default: #03A9F4; }   /* light-blue-color */
[data-tag="projects"] { --tag-default: #E91E63; }         /* pink-color */
[data-tag="esphome"] { --tag-default: #926BC7; }          /* purple-color */
[data-tag="weather"] { --tag-default: #FFC107; }          /* amber-color */
[data-tag="news"] { --tag-default: #607D8B; }             /* blue-grey-color */
:is([data-tag="connectivity"], [data-tag="zigbee"], [data-tag="z-wave"], [data-tag="zwave"], [data-tag="thread"], [data-tag="matter"]) { --tag-default: #4CAF50; } /* green-color */
:is([data-tag="reviews"], [data-tag="review"]) { --tag-default: #FF6F22; }         /* deep-orange-color */
:is([data-tag="guides"], [data-tag="setup-guides"], [data-tag="how-to"]) { --tag-default: #2196F3; } /* blue-color */
:is([data-tag="tips"], [data-tag="tips-and-tricks"]) { --tag-default: #CDDC39; }   /* lime-color */
:is([data-tag="my-home"], [data-tag="my-setup"]) { --tag-default: #009688; }       /* teal-color */
.tiles > li:nth-child(6n+1) { --tag-auto: #03A9F4; }
.tiles > li:nth-child(6n+2) { --tag-auto: #E91E63; }
.tiles > li:nth-child(6n+3) { --tag-auto: #926BC7; }
.tiles > li:nth-child(6n+4) { --tag-auto: #FFC107; }
.tiles > li:nth-child(6n+5) { --tag-auto: #4CAF50; }
.tiles > li:nth-child(6n+6) { --tag-auto: #FF9800; }

/* 4. Header --------------------------------------------------------------- */

.site-head {
    border-bottom: 1px solid var(--line);
}
.site-head__inner {
    display: flex;
    align-items: center;
    gap: 2rem;
    max-width: var(--page);
    min-height: 4.5rem;
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    color: var(--ink);
}
.brand__logo { height: 2.75rem; width: auto; }
.brand__logo--dark { display: none; }
[data-theme="dark"] .brand__logo--dark { display: block; }
[data-theme="dark"] .brand__logo--light { display: none; }

.site-nav { margin-right: auto; }
.site-nav .nav {
    display: flex;
    gap: 1.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}
.site-nav .nav a {
    display: block;
    padding: 0.5rem 0;
    color: var(--ink-soft);
    font: 550 0.975rem/1 var(--font-ui);
    text-decoration: none;
}
.site-nav .nav a:hover { color: var(--ink); }
.site-nav .nav-current a {
    color: var(--ink);
    text-decoration: underline 2px var(--accent);
    text-underline-offset: 0.5rem;
}

.site-head__tools { display: flex; align-items: center; gap: 0.25rem; }
.site-head__cta { margin-left: 0.5rem; }
.site-head__link {
    margin-left: 0.5rem;
    color: var(--ink-soft);
    font-weight: 550;
    font-size: 0.95rem;
    text-decoration: none;
}
.site-head__link:hover { color: var(--ink); }

.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

.menu-toggle { display: none; }

/* 5. Home: intro + topic tiles -------------------------------------------- */

.site-main {
    padding-bottom: clamp(3rem, 8vw, 6rem);
}

.intro {
    max-width: var(--page);
    margin: 0 auto;
    padding: clamp(2.5rem, 7vw, 5.5rem) var(--gutter) clamp(2rem, 4vw, 3rem);
}
.intro__title {
    max-width: 17ch;
    margin: 0;
    font: 820 clamp(2.4rem, 1.2rem + 4.6vw, 4.6rem)/1.02 var(--font-head);
    font-stretch: 125%;
    letter-spacing: -0.025em;
    text-wrap: balance;
}

.topics {
    max-width: var(--page);
    margin: 0 auto clamp(3rem, 7vw, 5rem);
    padding: 0 var(--gutter);
}
.topics .section-heading { margin-bottom: 1rem; }

/* Tiles follow the Home Assistant tile card: a round tinted icon,
   the name, and a state line underneath. */
.tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}
.tiles > li { display: flex; flex: 1 1 19rem; }
.tile {
    --tint: var(--tag-color, var(--tag-default, var(--tag-auto, var(--accent))));
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    align-content: start;
    column-gap: 0.85rem;
    row-gap: 0.75rem;
    width: 100%;
    padding: 0.9rem 1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    transition: border-color 140ms ease, background-color 140ms ease;
}
.tile:hover {
    border-color: var(--tint);
    background: color-mix(in oklab, var(--tint) 7%, var(--surface));
}
.tile:focus-visible { outline-offset: 3px; border-radius: 12px; }
.tile__icon {
    display: grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 50%;
    background: color-mix(in srgb, var(--tint) 20%, transparent);
    color: var(--tint);
    transition: background-color 140ms ease;
}
.tile:hover .tile__icon { background: color-mix(in srgb, var(--tint) 30%, transparent); }
.tile__text { display: grid; gap: 0.15rem; min-width: 0; }
.tile__name {
    overflow: hidden;
    font: 680 1.02rem/1.25 var(--font-ui);
    font-stretch: 106%;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tile__state {
    color: var(--ink-soft);
    font-size: 0.875rem;
    line-height: 1.3;
}
.tile__desc {
    grid-column: 1 / -1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    padding-top: 0.7rem;
    border-top: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 0.875rem;
    line-height: 1.45;
}

/* 6. Post lists ----------------------------------------------------------- */

.feed {
    max-width: var(--page);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.post-lead {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
    gap: clamp(1.5rem, 4vw, 3rem);
    align-items: center;
    padding: 1.25rem 0 2.5rem;
}
.post-lead__image img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
}
.post-lead__text { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.9rem; justify-items: start; }
.post-lead__title {
    margin: 0;
    font: 780 clamp(1.7rem, 1.1rem + 2vw, 2.6rem)/1.08 var(--font-head);
    font-stretch: 112%;
    letter-spacing: -0.02em;
    text-wrap: balance;
}
.post-lead__title a, .post-row__title a { text-decoration: none; }
.post-lead__title a:hover, .post-row__title a:hover {
    text-decoration: underline 2px var(--accent);
    text-underline-offset: 0.18em;
}
.post-lead__excerpt {
    margin: 0;
    color: var(--ink-soft);
    font: 400 1.15rem/1.55 var(--font-body);
}

.post-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 15rem;
    gap: 2rem;
    align-items: start;
    padding: 1.75rem 0;
    border-top: 1px solid var(--line);
}
.post-row:not(:has(.post-row__image)) { grid-template-columns: minmax(0, 1fr); }
.post-row__text { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.6rem; justify-items: start; max-width: var(--measure); }
.post-row__title {
    margin: 0;
    font: 740 clamp(1.25rem, 1.05rem + 0.7vw, 1.55rem)/1.18 var(--font-head);
    font-stretch: 110%;
    letter-spacing: -0.012em;
    text-wrap: balance;
}
.post-row__excerpt {
    margin: 0;
    color: var(--ink-soft);
    font: 400 1.05rem/1.55 var(--font-body);
}
.post-row__image img {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
}

.empty {
    padding: 2rem 0;
    color: var(--ink-soft);
    font-family: var(--font-body);
    font-size: 1.1rem;
}

/* 7. Archive headers (tag, author) --------------------------------------- */

.archive-head {
    max-width: var(--page);
    margin: 0 auto;
    padding: clamp(2.5rem, 6vw, 4.5rem) var(--gutter) 2rem;
}
.archive-head__kind {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0 0 0.75rem;
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 0.95rem;
}
.archive-head__title {
    margin: 0;
    font: 820 clamp(2.2rem, 1.3rem + 3.6vw, 3.8rem)/1.04 var(--font-head);
    font-stretch: 122%;
    letter-spacing: -0.025em;
}
.archive-head__desc {
    max-width: 38rem;
    margin: 1rem 0 0;
    color: var(--ink-soft);
    font: 400 1.2rem/1.55 var(--font-body);
}
.archive-head__count, .archive-head__links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin: 1.25rem 0 0;
    color: var(--ink-soft);
    font-size: 0.925rem;
}
.archive-head__links a { color: var(--link); }
.archive-head__avatar {
    width: 5rem;
    height: 5rem;
    margin-bottom: 1.25rem;
    border-radius: 50%;
    border: 2px solid var(--wall);
    object-fit: cover;
}
.feed--archive .post-row:first-child { border-top: 3px solid var(--wall); }

/* 8. Article -------------------------------------------------------------- */

.article__head {
    max-width: calc(var(--measure) + 2 * var(--gutter));
    margin: 0 auto;
    padding: clamp(2.5rem, 6vw, 4.5rem) var(--gutter) 2.25rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.1rem;
    justify-items: start;
}
.article__title {
    max-width: 100%;
    overflow-wrap: break-word;
    margin: 0;
    font: 820 clamp(2.1rem, 1.2rem + 3.4vw, 3.5rem)/1.05 var(--font-head);
    font-stretch: 118%;
    letter-spacing: -0.025em;
    text-wrap: balance;
}
.article__lede {
    margin: 0;
    color: var(--ink-soft);
    font: 400 clamp(1.2rem, 1.1rem + 0.4vw, 1.4rem)/1.5 var(--font-body);
}

.byline {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    margin-top: 0.4rem;
}
.byline__avatar {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    border: 2px solid var(--wall);
    object-fit: cover;
}
.byline__text { display: grid; gap: 0.15rem; }
.byline__name { font-weight: 650; font-size: 0.975rem; }
.byline__name a { text-decoration: none; }
.byline__name a:hover { text-decoration: underline; }

.article__image {
    max-width: calc(var(--wide) + 2 * var(--gutter));
    margin: 0 auto 2.75rem;
    padding: 0 var(--gutter);
}
.article__image img {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
}
.article__image figcaption, .gh-content figcaption {
    margin-top: 0.75rem;
    color: var(--ink-soft);
    font: 450 0.875rem/1.45 var(--font-ui);
    text-align: center;
}

.article--page .article__body { padding-top: 0.5rem; }

/* Table of contents: inline box on small screens, sticky margin list on wide */
.toc {
    width: min(var(--measure), 100% - 2 * var(--gutter));
    margin: 0 auto 2.5rem;
    font-family: var(--font-ui);
}
.toc__box {
    padding: 1rem 1.25rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    background: var(--surface);
}
.toc__title {
    cursor: pointer;
    font: 700 0.95rem/1.3 var(--font-head);
    font-stretch: 112%;
}
.toc__list {
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.15rem;
}
.toc__list a {
    display: block;
    padding: 0.3rem 0 0.3rem 0.85rem;
    border-left: 2px solid transparent;
    color: var(--ink-soft);
    font-size: 0.9rem;
    line-height: 1.35;
    text-decoration: none;
}
.toc__list .toc__sub a { padding-left: 1.7rem; font-size: 0.85rem; }
.toc__list a:hover { color: var(--ink); }
.toc__list a.is-active { color: var(--ink); border-left-color: var(--accent); font-weight: 600; }

.article__foot {
    max-width: calc(var(--measure) + 2 * var(--gutter));
    margin: 3.5rem auto 0;
    padding: 0 var(--gutter);
}
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.5rem;
    margin: 0;
    padding: 1.5rem 0;
    list-style: none;
    border-top: 3px solid var(--wall);
}
.author-card {
    display: flex;
    gap: 1.1rem;
    align-items: flex-start;
    padding: 1.5rem 0;
    border-top: 1px solid var(--line);
}
.author-card__avatar {
    width: 4rem;
    height: 4rem;
    flex: none;
    border-radius: 50%;
    border: 2px solid var(--wall);
    object-fit: cover;
}
.author-card__name {
    margin: 0.2rem 0 0.35rem;
    font: 740 1.15rem/1.2 var(--font-head);
    font-stretch: 112%;
}
.author-card__name a { text-decoration: none; }
.author-card__name a:hover { text-decoration: underline; }
.author-card__bio { margin: 0; color: var(--ink-soft); font: 400 1rem/1.55 var(--font-body); }
.comments { padding-top: 1.5rem; border-top: 1px solid var(--line); }
/* The comments iframe doesn't declare a colour scheme. Browsers paint such an
   iframe with an opaque white canvas when its container is dark, so keep the
   container's scheme light and let Ghost's comments UI handle dark mode itself. */
.gh-comments { color-scheme: light; }

.related {
    max-width: var(--page);
    margin: 4rem auto 0;
    padding: 0 var(--gutter);
}

.post-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    max-width: var(--page);
    margin: 3rem auto 0;
    padding: 0 var(--gutter);
}
.post-nav__link {
    display: grid;
    gap: 0.35rem;
    padding: 1.1rem 1.25rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    text-decoration: none;
}
.post-nav__link:hover { border-color: var(--wall); background: var(--surface); }
.post-nav__link--next { grid-column: 2; text-align: right; }
.post-nav__label { color: var(--ink-soft); font-size: 0.85rem; }
.post-nav__title { font: 700 1.05rem/1.25 var(--font-head); font-stretch: 108%; }

/* 9. Content: the reading column and its breakouts ----------------------- */

.gh-content {
    display: grid;
    grid-template-columns:
        [full-start] minmax(var(--gutter), 1fr)
        [wide-start] minmax(0, calc((var(--wide) - var(--measure)) / 2))
        [main-start] min(var(--measure), 100% - 2 * var(--gutter))
        [main-end] minmax(0, calc((var(--wide) - var(--measure)) / 2))
        [wide-end] minmax(var(--gutter), 1fr) [full-end];
    font: 400 1.175rem/1.68 var(--font-body);
    font-optical-sizing: auto;
    overflow-wrap: break-word;
}
.gh-content > * { grid-column: main-start / main-end; margin: 0; }
.gh-content > * + * { margin-top: 1.4em; }
.gh-content > .kg-width-wide { grid-column: wide-start / wide-end; }
.gh-content > .kg-width-full { grid-column: full-start / full-end; }
.gh-content > .kg-width-full img { width: 100%; border-radius: 0; border-inline: 0; }

.gh-content h2, .gh-content h3, .gh-content h4 {
    position: relative;
    font-family: var(--font-head);
    letter-spacing: -0.012em;
    text-wrap: balance;
    scroll-margin-top: 1.5rem;
}
.gh-content h2 {
    margin-top: 2.3em;
    font-size: clamp(1.5rem, 1.25rem + 0.9vw, 1.9rem);
    font-weight: 780;
    font-stretch: 114%;
    line-height: 1.15;
}
.gh-content h3 {
    margin-top: 2em;
    font-size: clamp(1.2rem, 1.1rem + 0.45vw, 1.4rem);
    font-weight: 740;
    font-stretch: 110%;
    line-height: 1.25;
}
.gh-content h4 { margin-top: 1.8em; font-size: 1.1rem; font-weight: 720; }
.gh-content h2 + *, .gh-content h3 + *, .gh-content h4 + * { margin-top: 0.7em; }

.heading-anchor {
    margin-left: 0.4rem;
    color: var(--line);
    font-weight: 500;
    text-decoration: none;
    opacity: 0;
}
:is(h2, h3, h4):hover > .heading-anchor, .heading-anchor:focus-visible { opacity: 1; }
.heading-anchor:hover { color: var(--accent); }

.gh-content a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
.gh-content a:hover { text-decoration-thickness: 2px; }
.gh-content strong { font-weight: 650; }

.gh-content ul, .gh-content ol { padding-left: 1.3em; }
.gh-content li + li { margin-top: 0.55em; }
.gh-content li::marker { color: var(--accent); }
.gh-content ol li::marker { font: 650 0.95em var(--font-ui); }
.gh-content li > ul, .gh-content li > ol { margin-top: 0.55em; }

.gh-content blockquote:not([class]) {
    padding-left: 1.25rem;
    border-left: 4px solid var(--signal);
    font-style: italic;
    font-size: 1.15em;
    color: var(--ink);
}
.gh-content blockquote.kg-blockquote-alt {
    text-align: center;
    font-style: italic;
    font-size: 1.4em;
    line-height: 1.45;
    padding: 0 1.5rem;
}

.gh-content hr {
    width: 6rem;
    height: 0;
    margin-block: 2.75em;
    border: 0;
    border-top: 3px solid var(--wall);
    justify-self: center;
}

.gh-content code {
    padding: 0.12em 0.36em;
    border-radius: var(--radius-s);
    background: var(--inline-code-bg);
    font-family: var(--font-mono);
    font-size: 0.83em;
}

/* Code blocks are allowed wider than the text so diagrams and long
   shell commands rarely need horizontal scrolling. */
.gh-content > pre, .gh-content > .code-block {
    grid-column: wide-start / wide-end;
    justify-self: center;
    width: min(100%, 52rem);
}
.code-block { position: relative; }
.gh-content pre {
    margin: 0;
    padding: 1.2rem 1.4rem;
    overflow-x: auto;
    border: 1px solid var(--code-line);
    border-radius: var(--radius-m);
    background: var(--code-bg);
    color: var(--code-ink);
    font: 400 0.875rem/1.62 var(--font-mono);
    tab-size: 4;
    -webkit-font-smoothing: auto;
}
.gh-content pre code { padding: 0; background: none; font-size: inherit; color: inherit; }
.code-block--labelled pre { padding-top: 2.6rem; }
.code-block__lang {
    position: absolute;
    top: 0.75rem;
    left: 1.4rem;
    color: #8C9DBA;
    font: 600 0.75rem/1 var(--font-ui);
    pointer-events: none;
}
.code-block__copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    min-height: 1.9rem;
    padding: 0 0.7rem;
    border: 1px solid var(--code-line);
    border-radius: var(--radius-s);
    background: var(--code-bg);
    color: #B8C6DD;
    font: 600 0.75rem/1 var(--font-ui);
    cursor: pointer;
    opacity: 0;
    transition: opacity 120ms ease;
}
.code-block:hover .code-block__copy, .code-block__copy:focus-visible, .code-block__copy.is-copied { opacity: 1; }
.code-block__copy:hover { color: #FFFFFF; border-color: #5B6E91; }
.code-block__copy.is-copied { color: var(--signal); border-color: var(--signal); }
@media (hover: none) { .code-block__copy { opacity: 1; } }

.table-wrap { overflow-x: auto; }
.gh-content > .table-wrap { grid-column: wide-start / wide-end; justify-self: center; width: min(100%, 52rem); }
.gh-content table {
    width: 100%;
    border-collapse: collapse;
    font: 450 0.95rem/1.45 var(--font-ui);
}
.gh-content th {
    text-align: left;
    font-weight: 700;
    border-bottom: 3px solid var(--wall);
}
.gh-content th, .gh-content td { padding: 0.65rem 0.9rem 0.65rem 0; vertical-align: top; }
.gh-content td { border-bottom: 1px solid var(--line); }

.gh-content figure img { border-radius: var(--radius-m); }
.gh-content .kg-image-card img:not(.kg-width-full img) { border: 1px solid var(--line); margin-inline: auto; }
/* Tall screenshots (phones, portrait shots) never fill more than the
   viewport height; small images keep their natural size, centred. */
.kg-image-card .kg-image { width: auto; height: auto; max-width: 100%; max-height: 80vh; margin-inline: auto; }

/* 10. Ghost cards: card_assets supplies the base styles, these adapt them ---- */

.kg-width-wide { position: relative; }
.kg-width-full { position: relative; }

.gh-content .kg-callout-card {
    border-radius: var(--radius-m);
    font-family: var(--font-ui);
    font-size: 1.025rem;
    line-height: 1.55;
}
.gh-content .kg-callout-card-grey { background: var(--paper-sunk); }
.gh-content .kg-callout-card-white { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.gh-content .kg-callout-card-accent { background: var(--accent); color: var(--on-accent); }

.gh-content .kg-bookmark-container {
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    background: var(--surface);
    color: var(--ink);
    font-family: var(--font-ui);
}
.gh-content .kg-bookmark-title { font-weight: 700; }
.gh-content .kg-bookmark-description, .gh-content .kg-bookmark-metadata { color: var(--ink-soft); }

.gh-content .kg-toggle-card, .gh-content .kg-product-card-container, .gh-content .kg-file-card-container {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    box-shadow: none;
    color: var(--ink);
}
.gh-content .kg-toggle-heading-text, .gh-content .kg-product-card-title, .gh-content .kg-file-card-title {
    font-family: var(--font-head);
    font-stretch: 110%;
}
.gh-content .kg-product-card-rating-active.kg-product-card-rating-star svg { fill: #E0A23A; }
.gh-content .kg-button-card .kg-btn { font-family: var(--font-ui); border-radius: var(--radius-s); }
.gh-content .kg-header-card h2 { font-family: var(--font-head); }

/* 11. Footer, pager, misc ------------------------------------------------ */

.pager {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    max-width: var(--page);
    margin: 2.5rem auto 0;
    padding: 0 var(--gutter);
}
.pager > :last-child { justify-self: end; }
.pager__count { color: var(--ink-soft); font-size: 0.925rem; }

.site-foot {
    border-top: 3px solid var(--wall);
    background: var(--paper-sunk);
}
.site-foot__inner {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 2rem 3rem;
    max-width: var(--page);
    margin: 0 auto;
    padding: 3rem var(--gutter) 2.5rem;
}
.site-foot__title {
    font: 780 1.15rem/1 var(--font-head);
    font-stretch: 118%;
    text-decoration: none;
}
.site-foot__about p {
    max-width: 30rem;
    margin: 0.75rem 0 0;
    color: var(--ink-soft);
    font: 400 1.05rem/1.5 var(--font-body);
}
.site-foot__nav .nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem 1.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
    justify-content: flex-end;
}
.site-foot__nav a { color: var(--ink-soft); text-decoration: none; font-weight: 550; }
.site-foot__nav a:hover { color: var(--ink); text-decoration: underline; }
.site-foot__small {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    margin: 0;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 0.875rem;
}
.site-foot__small a { color: inherit; }
.site-foot__small a:hover { color: var(--ink); }

.error-page {
    max-width: calc(var(--measure) + 2 * var(--gutter));
    margin: 0 auto;
    padding: clamp(3rem, 10vw, 7rem) var(--gutter) 2rem;
}
.error-page__code {
    margin: 0;
    color: var(--accent);
    font: 820 4.5rem/1 var(--font-head);
    font-stretch: 125%;
}
.error-page__title {
    margin: 1rem 0 0;
    font: 800 clamp(1.8rem, 1.3rem + 2vw, 2.6rem)/1.1 var(--font-head);
    font-stretch: 116%;
}
.error-page__text { color: var(--ink-soft); font: 400 1.15rem/1.55 var(--font-body); }
.error-page__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 2rem; }

/* 12. Responsive ---------------------------------------------------------- */

@media (min-width: 1200px) {
    /* With a contents list: two columns, the list in the left margin */
    .article.has-toc {
        display: grid;
        grid-template-columns: 13rem minmax(0, 1fr);
        grid-template-areas:
            ".   head"
            ".   image"
            "toc body"
            ".   foot";
        column-gap: 2.5rem;
        max-width: calc(var(--page) + 8rem);
        margin: 0 auto;
        padding-inline: var(--gutter);
    }
    .article.has-toc .article__head { grid-area: head; width: 100%; max-width: var(--measure); padding-inline: 0; }
    .article.has-toc .article__image { grid-area: image; width: 100%; padding-inline: 0; }
    .article.has-toc .article__body { display: contents; }
    .article.has-toc .gh-content { grid-area: body; }
    .article.has-toc .article__foot { grid-area: foot; width: 100%; max-width: var(--measure); padding-inline: 0; }
    .article.has-toc .toc { grid-area: toc; width: auto; margin: 0; }
    .article.has-toc .toc__box {
        position: sticky;
        top: 2rem;
        max-height: calc(100vh - 4rem);
        overflow-y: auto;
        padding: 0;
        border: 0;
        background: none;
    }
    .article.has-toc .toc__title { list-style: none; pointer-events: none; color: var(--ink-soft); font-size: 0.9rem; }
    .article.has-toc .toc__title::-webkit-details-marker { display: none; }
}

@media (max-width: 900px) {
    .post-lead { grid-template-columns: minmax(0, 1fr); }
    .post-row { grid-template-columns: minmax(0, 1fr) 9rem; gap: 1.25rem; }
}

@media (max-width: 760px) {
    .site-head__inner { gap: 0.75rem; }
    .menu-toggle { display: inline-grid; }
    .site-nav {
        display: none;
        position: absolute;
        top: 4.5rem;
        left: 0;
        right: 0;
        z-index: 20;
        padding: 0.5rem var(--gutter) 1.25rem;
        background: var(--paper);
        border-bottom: 3px solid var(--wall);
    }
    .site-head { position: relative; }
    .site-head__tools { margin-left: auto; }
    body.is-menu-open .site-nav { display: block; }
    .site-nav .nav { flex-direction: column; gap: 0; }
    .site-nav .nav a { padding: 0.85rem 0; font-size: 1.05rem; border-bottom: 1px solid var(--line); }
    .site-nav .nav-current a { text-decoration: none; color: var(--accent); }

    .site-head__cta { display: none; }
    .site-foot__inner { grid-template-columns: minmax(0, 1fr); }
    .site-foot__nav .nav { justify-content: flex-start; }
    .post-nav { grid-template-columns: minmax(0, 1fr); }
    .post-nav__link--next { grid-column: 1; }
}

@media (max-width: 560px) {
    .tiles { gap: 0.6rem; }
    .tiles > li { flex-basis: 40%; }
    .tile { grid-template-columns: minmax(0, 1fr); row-gap: 0.6rem; padding: 0.85rem; }
    .tile__name { white-space: normal; }
    .tile__desc { display: none; }
    .brand__logo { height: 2.2rem; }
    .article__title, .archive-head__title { font-size: clamp(1.7rem, 7.4vw, 2.1rem); font-stretch: 104%; letter-spacing: -0.02em; }
    .intro__title { font-stretch: 112%; }
    .post-row { grid-template-columns: minmax(0, 1fr); }
    .post-row__image { order: -1; }
    .gh-content { font-size: 1.1rem; }
    .gh-content pre { border-radius: 0; border-inline: 0; }
    .gh-content > pre, .gh-content > .code-block { grid-column: full-start / full-end; width: 100%; }
}

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

@media print {
    .site-head, .site-foot, .toc, .post-nav, .related, .comments, .code-block__copy { display: none !important; }
    body { background: #fff; color: #000; }
}
