/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow-y: scroll;
}

/* -------------------------------------------------------------------------
   Theme palette
   -------------------------------------------------------------------------
   Default = light, after the Ghost theme the site used before (Ease: white,
   dark gray text, Roboto, the purple accent). The dark palette kicks in
   either when the OS prefers dark mode (@media prefers-color-scheme), or
   when the user manually toggles the in-page <input id="theme-toggle">
   (see further below). Both rules write to the same CSS custom properties,
   so every rule that references var(--color-*) updates automatically.
   ------------------------------------------------------------------------- */
:root {
    --color-background: #ffffff;
    --color-surface: #f1f1f1;
    --color-text: #333333;
    --color-heading: #1a1a1a;
    --color-text-light: #999999;
    --color-border: #e6e6e6;
    --color-accent: #6c5ce7;

    --font-sans: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
    --font-mono: Menlo, Consolas, Monaco, "Liberation Mono", "Lucida Console", monospace;
}

/* Dark — applied when the OS prefers dark mode. */
@media (prefers-color-scheme: dark) {
    :root {
        --color-background: #18181b;
        --color-surface: #232327;
        --color-text: #c9c9ce;
        --color-heading: #f4f4f5;
        --color-text-light: #8b8b93;
        --color-border: #34343a;
        --color-accent: #a29bfe;
    }
}

/* Manual override: flip to the OPPOSITE of the current system preference.
   Two selectors so both code paths work:
     - html.theme-toggled  → set by a small inline script that mirrors the
       checkbox to localStorage so the choice persists across pages.
     - body:has(#theme-toggle:checked) → pure-CSS fallback when JS is
       disabled (Chromium 105+, Firefox 121+, Safari 15.4+). No
       persistence, but the toggle still works on the current page. */
html.theme-toggled,
body:has(#theme-toggle:checked) {
    --color-background: #18181b;
    --color-surface: #232327;
    --color-text: #c9c9ce;
    --color-heading: #f4f4f5;
    --color-text-light: #8b8b93;
    --color-border: #34343a;
    --color-accent: #a29bfe;
}

@media (prefers-color-scheme: dark) {
    html.theme-toggled,
    body:has(#theme-toggle:checked) {
        --color-background: #ffffff;
        --color-surface: #f1f1f1;
        --color-text: #333333;
        --color-heading: #1a1a1a;
        --color-text-light: #999999;
        --color-border: #e6e6e6;
        --color-accent: #6c5ce7;
    }
}

/* html carries the page background so the toggled palette (set on html by
   the script) paints the whole viewport, not just the body box. */
html.theme-toggled {
    background: var(--color-background);
}

/* Theme toggle widget — checkbox is visually hidden but remains focusable.
   The label in the nav shows a sun or moon depending on the current
   effective theme. Clicking the label toggles the checkbox. */
#theme-toggle {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.theme-toggle {
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    user-select: none;
}

/* Light mode default: show moon (click to go dark). */
.theme-toggle::before { content: "🌙"; }

/* OS dark: show sun (click to go light). */
@media (prefers-color-scheme: dark) {
    .theme-toggle::before { content: "🌞"; }
}

/* When toggled on, flip the icon to match the new effective theme.
   Same two-selector pattern as the palette overrides above. */
html.theme-toggled .theme-toggle::before,
body:has(#theme-toggle:checked) .theme-toggle::before { content: "🌞"; }
@media (prefers-color-scheme: dark) {
    html.theme-toggled .theme-toggle::before,
    body:has(#theme-toggle:checked) .theme-toggle::before { content: "🌙"; }
}

/* Keyboard focus ring on the label when the hidden checkbox is focused. */
#theme-toggle:focus-visible + .theme-toggle {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
    border-radius: 4px;
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.7;
    color: var(--color-text);
    background: var(--color-background);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    word-break: break-word;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a {
    color: var(--color-heading);
    text-decoration: none;
    transition: color 0.1s ease-in-out;
}

a:hover {
    color: var(--color-accent);
}

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

/* Containers, as the old theme sized them: 4vw gutters, and a large
   (960px) and a medium (720px) width inside the full one. */
.container {
    width: 100%;
    max-width: calc(1130px + 8vw);
    margin-left: auto;
    margin-right: auto;
    padding-left: 4vw;
    padding-right: 4vw;
}

.container.large {
    max-width: calc(960px + 8vw);
}

.container.medium {
    max-width: calc(720px + 8vw);
}

/* Header: the app icon on the left; the menu and the toggle on the right,
   above a rule (except on the home page, where the cover follows). */
.navbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 25px;
    min-height: 70px;
    box-shadow: 0 1px 0 var(--color-border);
}

.site-header.home .navbar {
    box-shadow: none;
}

.logo {
    margin-right: auto;
}

.logo-image {
    width: 50px;
    height: 50px;
}

.main-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 25px;
}

.menu-item {
    font-size: 15px;
    line-height: 1;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.menu-item[aria-current="page"] {
    color: var(--color-accent);
}

/* Main content */
.site-main {
    flex: 1;
    padding-top: 60px;
    padding-bottom: 30px;
}

/* ---------------------------------------------------------------- home */

/* The cover: the site's cover image under a dark overlay, with the
   description on top. It stays dark in both themes. */
.site-cover {
    position: relative;
    display: flex;
    min-height: 500px;
    overflow: hidden;
    background: #000000;
}

.cover-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
}

.site-cover::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: rgba(0, 0, 0, 0.8);
}

.cover-content {
    position: relative;
    z-index: 2;
    margin: auto;
    padding: 30px;
    color: #ffffff;
    text-align: center;
}

.cover-description {
    max-width: 750px;
    margin: 0 auto;
    font-size: 30px;
    line-height: 1.4;
    font-weight: 500;
}

.site-main.home {
    padding-top: 90px;
}

/* A section heading over a rule, with a count beside it */
.topic-header {
    display: flex;
    align-items: baseline;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
}

.topic-name {
    font-size: 20px;
    line-height: 1.3;
    font-weight: 700;
    color: var(--color-heading);
}

.topic-count {
    margin-left: 15px;
    color: var(--color-text-light);
}

/* Featured articles: a card per support page, an image over its title */
.featured-wrapper {
    margin-bottom: 90px;
}

.featured-wrapper .topic-header {
    margin-bottom: 45px;
}

.featured-title {
    color: var(--color-accent);
}

.featured-posts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 45px 30px;
}

.featured-image-link {
    position: relative;
    display: block;
    padding-bottom: 50%;
    margin-bottom: 30px;
    overflow: hidden;
    background: var(--color-surface);
}

.featured-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.2s ease-in-out;
}

.featured-image-link:hover .featured-image {
    opacity: 0.85;
}

.featured-post-title {
    font-size: 18px;
    line-height: 1.4;
    font-weight: 500;
}

/* The blog's posts, as a list of titles with a chevron */
.topic-feed {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 0 30px;
}

.topic {
    margin-bottom: 60px;
}

.topic-article-feed {
    list-style: none;
}

.topic-article {
    font-size: 15px;
    line-height: 1.5;
}

.topic-article-link {
    display: flex;
    align-items: baseline;
    padding: 7px 0;
}

.topic-article-link::before {
    content: "";
    flex-shrink: 0;
    width: 6px;
    height: 6px;
    margin: 0 10px 2px 0;
    border-top: 1.5px solid currentColor;
    border-right: 1.5px solid currentColor;
    transform: rotate(45deg);
}

.topic-more {
    display: inline-flex;
    align-items: center;
    margin: 20px 20px 0 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--color-accent);
}

.topic-more::after {
    content: "\2192";
    margin-left: 5px;
    font-size: 13px;
    color: var(--color-text-light);
    transition: transform 0.2s ease-in-out;
}

.topic-more:hover::after {
    transform: translateX(3px);
}

/* ------------------------------------------------- tag and author pages */

/* The page's term (a tag or an author), centred above the posts */
.term {
    margin: 30px 0 60px;
    text-align: center;
}

.term-image {
    width: 80px;
    height: 80px;
    margin: 0 auto 15px;
    border-radius: 50%;
}

.term-name {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--color-accent);
}

/* A row per post: title, excerpt, then the author and date */
.post-feed .post {
    padding: 35px 0 33px;
}

.post-feed .post:first-child {
    padding-top: 0;
}

.post-feed .post + .post {
    border-top: 1px solid var(--color-border);
}

.post-title {
    font-size: 18px;
    line-height: 1.4;
    font-weight: 500;
    color: var(--color-heading);
}

.post-title-link {
    display: block;
}

.post-excerpt {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 10px;
    font-size: 15px;
    line-height: 1.5;
    color: var(--color-text-light);
}

/* The author's avatar, then the name over the date and read time */
.post-meta {
    display: flex;
    align-items: center;
    margin-top: 15px;
    font-size: 13px;
    line-height: 1;
    color: var(--color-text-light);
}

.post-author-image-link {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    margin-right: 10px;
}

.post-author-image {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.post-author-name {
    display: inline-block;
    margin-bottom: 5px;
}

.post-meta-bottom {
    display: flex;
    flex-wrap: wrap;
}

/* A dot between the date and the read time */
.post-length::before {
    content: "\2022";
    padding: 0 6px;
}

/* Tags: small pills */
.post-tags {
    display: flex;
    flex-wrap: wrap;
}

.post-tags.centered {
    justify-content: center;
}

.post-tag {
    display: inline-block;
    margin: 0 8px 8px 0;
    padding: 6px 15px;
    border: 1px solid var(--color-border);
    border-radius: 15px;
    font-size: 13px;
    line-height: 1;
    font-weight: 500;
    background: var(--color-background);
}

.post-tag:hover {
    border-color: var(--color-accent);
}

.tag-count {
    margin-left: 4px;
    color: var(--color-text-light);
}

/* ------------------------------------------------- posts and pages */

.single .post-header {
    margin-bottom: 30px;
}

.single .post-title {
    font-size: 30px;
    line-height: 1.3;
}

.post-archive-notice {
    margin-bottom: 30px;
    font-style: italic;
    color: var(--color-text-light);
}

/* Post body: the 720px column, spaced as the old theme spaced it */
.post-content {
    line-height: 1.9;
}

.post-content > * + * {
    margin-top: 30px;
}

.post-content > * + p,
.post-content > * + ul,
.post-content > * + ol {
    margin-top: 20px;
}

.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6 {
    font-weight: 700;
    line-height: 1.4;
    color: var(--color-heading);
}

.post-content > h1,
.post-content > h2,
.post-content > h3,
.post-content > h4,
.post-content > h5,
.post-content > h6 {
    margin-top: 40px;
}

.post-content h1 { font-size: 26px; }
.post-content h2 { font-size: 23px; }
.post-content h3 { font-size: 20px; }
.post-content h4 { font-size: 17px; }
.post-content h5 { font-size: 15px; }
.post-content h6 { font-size: 13px; text-transform: uppercase; }

.post-content > h1 + p,
.post-content > h2 + p,
.post-content > h3 + p,
.post-content > h4 + p,
.post-content > h5 + p,
.post-content > h6 + p {
    margin-top: 15px;
}

.post-content strong {
    color: var(--color-heading);
}

.post-content a {
    color: var(--color-accent);
}

.post-content a:hover {
    text-decoration: underline;
}

.post-content ul,
.post-content ol {
    padding-left: 20px;
}

.post-content blockquote {
    margin: 0 60px;
    font-size: 22px;
    line-height: 1.45;
    font-weight: 500;
    color: var(--color-text-light);
}

.post-content code {
    font-family: var(--font-mono);
    font-size: 14px;
}

.post-content pre {
    padding: 20px;
    border-radius: 4px;
    background: var(--color-surface);
    overflow-x: auto;
    line-height: 1.45;
}

.post-content hr {
    border: 0;
    border-top: 1px solid var(--color-border);
}

.post-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}

.post-content th,
.post-content td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
}

/* Figures: images with captions */
.post-content > figure {
    margin-top: 45px;
}

.post-content > figure + * {
    margin-top: 45px;
}

.post-content img {
    margin: 0 auto;
}

.post-content figcaption {
    margin-top: 15px;
    font-size: 14px;
    text-align: center;
    color: var(--color-heading);
}

/* The feature image, first in the body, is wider than the text: as wide
   as the large container (960px), centred on the column. */
.post-content > .feature-image {
    width: min(960px, 92vw);
    margin-top: 0;
    margin-left: 50%;
    transform: translateX(-50%);
}

.post-content > .feature-image img {
    width: 100%;
}

/* The post's tags and the Markdown link, under the text */
.post-footer {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-top: 45px;
}

.post-markdown {
    padding-top: 5px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-light);
}

/* Footer: the RSS icon over the copyright, centred */
.site-footer {
    padding-top: 45px;
    padding-bottom: 45px;
    text-align: center;
}

.footer-social-item {
    display: inline-flex;
    color: var(--color-heading);
}

.footer-social-item svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.copyright {
    margin-top: 5px;
    font-size: 14px;
    color: var(--color-text-light);
}

/* Responsive Design */
@media (max-width: 767px) {
    /* The menu moves to its own row under the icon and the toggle. */
    .navbar {
        padding: 10px 0;
    }

    .main-nav {
        order: 3;
        width: 100%;
        justify-content: space-between;
        gap: 8px 16px;
        margin-top: 14px;
    }

    .site-main {
        padding-top: 40px;
    }

    .site-main.home {
        padding-top: 60px;
    }

    .site-cover {
        min-height: 400px;
    }

    .cover-description {
        font-size: 24px;
    }

    .featured-wrapper {
        margin-bottom: 60px;
    }

    .featured-wrapper .topic-header {
        margin-bottom: 30px;
    }

    .single .post-title {
        font-size: 24px;
    }

    .post-content blockquote {
        margin: 0;
    }

    .post-content > figure,
    .post-content > figure + * {
        margin-top: 30px;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: #000;
    }

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

    .post-content a {
        color: #000;
    }

    .post-content pre {
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }
}
