/* 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 (white, dark
   gray text, Muli, the blue accent). The dark palette, also the old
   theme's, 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: #aaaaaa;
    --color-border: #d9d9d9;
    --color-accent: #49a8e4;

    --font-sans: Muli, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "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: #282c35;
        --color-surface: #21252c;
        --color-text: #cccccc;
        --color-heading: #ffffff;
        --color-text-light: #999999;
        --color-border: #495061;
    }
}

/* 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: #282c35;
    --color-surface: #21252c;
    --color-text: #cccccc;
    --color-heading: #ffffff;
    --color-text-light: #999999;
    --color-border: #495061;
}

@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: #aaaaaa;
        --color-border: #d9d9d9;
    }
}

/* 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.65;
    color: var(--color-text);
    background: var(--color-background);
    -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;
}

/* Containers, as the old theme sized them: 4vw gutters, and a large
   (960px) and a medium (750px) width inside the full one. */
.container {
    width: 100%;
    max-width: calc(1140px + 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(750px + 8vw);
}

/* Header: the site name, a divider and the menu; the toggle on the right. */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100px;
}

.navbar-left {
    display: flex;
    align-items: center;
    height: 100%;
}

.logo {
    display: flex;
    align-items: center;
}

.logo-image {
    width: auto;
    height: 60px;
}

/* The logo's black lettering would vanish on the dark palette, so a copy
   with light lettering (logo-dark.png) takes its place there. Same
   selectors as the palette overrides above. */
.logo-image.dark { display: none; }

@media (prefers-color-scheme: dark) {
    .logo-image.light { display: none; }
    .logo-image.dark { display: block; }
}

html.theme-toggled .logo-image.light,
body:has(#theme-toggle:checked) .logo-image.light { display: none; }
html.theme-toggled .logo-image.dark,
body:has(#theme-toggle:checked) .logo-image.dark { display: block; }

@media (prefers-color-scheme: dark) {
    html.theme-toggled .logo-image.light,
    body:has(#theme-toggle:checked) .logo-image.light { display: block; }
    html.theme-toggled .logo-image.dark,
    body:has(#theme-toggle:checked) .logo-image.dark { display: none; }
}

.sep {
    display: flex;
    align-items: center;
    height: 40px;
    margin: 0 30px;
    width: 1px;
    background-color: var(--color-border);
}

.main-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 40px;
}

.menu-item-link {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text-light);
    transition: color 0.2s ease;
}

.menu-item-link:hover,
.menu-item-link[aria-current="page"] {
    color: var(--color-heading);
}

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

.page-title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.3;
    color: var(--color-heading);
    margin-bottom: 40px;
}

/* Post cards on the home page: title, date and read time, the excerpt,
   then "Read now" and the author above a rule. */
.post-card + .post-card {
    margin-top: 80px;
}

.post-header {
    margin-bottom: 20px;
}

.post-title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.3;
    color: var(--color-heading);
    margin-bottom: 10px;
}

.post-title a {
    color: inherit;
}

.post-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0 8px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--color-text-light);
}

/* A dot between the date and the read time */
.post-meta > * + *::before {
    content: "•";
    margin-right: 8px;
}

.post-excerpt {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 16px;
}

.post-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 30px;
    padding-top: 10px;
    border-top: 1px solid var(--color-border);
    line-height: 1;
}

/* "Read now": the old theme's play arrow and small capitals */
.post-link {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    color: var(--color-accent);
}

.post-link::before {
    content: "";
    margin-right: 6px;
    border-left: 7px solid currentColor;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
}

.post-author,
.post-markdown {
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text-light);
}

.post-author a,
.post-markdown:hover {
    color: var(--color-heading);
}

.post-author {
    display: flex;
    align-items: center;
    gap: 10px;
}

.post-author-image-link {
    flex-shrink: 0;
}

.post-author-image,
.author-image,
.author-term-image {
    border-radius: 50%;
    object-fit: cover;
}

.post-author-image {
    width: 30px;
    height: 30px;
}

/* The author box under a post: avatar, name and "More posts", with the
   Markdown link on the right. */
.author {
    display: flex;
    align-items: center;
    gap: 25px;
    margin-top: 60px;
    padding-top: 30px;
    border-top: 1px solid var(--color-border);
}

.author-image {
    flex-shrink: 0;
    width: 70px;
    height: 70px;
}

.author-wrapper {
    flex: 1;
    min-width: 0;
}

.author-name {
    font-size: 18px;
    font-weight: 800;
    line-height: 1.3;
    color: var(--color-heading);
}

.author-more {
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text-light);
}

.author-more:hover {
    color: var(--color-heading);
}

/* The author page: the avatar over the name */
.author-term {
    margin-bottom: 40px;
    text-align: center;
}

.author-term-image {
    width: 90px;
    height: 90px;
    margin: 0 auto 15px;
}

.author-term .page-title {
    margin-bottom: 0;
}

.archive-link {
    margin-top: 60px;
    font-size: 14px;
    font-weight: 700;
}

.archive-link a {
    color: var(--color-text-light);
}

.archive-link a:hover {
    color: var(--color-heading);
}

/* Single post: the title and meta centred above the text */
.post-header.single {
    margin-bottom: 50px;
    text-align: center;
}

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

/* A page (Support): the title alone, closer to the text */
.post-header.single.page {
    margin-bottom: 20px;
}

.post-header.single .post-meta {
    justify-content: center;
}

.post-tags {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}

.tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 3px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    font-weight: 700;
}

.tag:hover {
    background: var(--color-accent);
    color: #ffffff;
}

.tags-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.tag-count {
    color: var(--color-text-light);
}

.post-archive-notice {
    margin-bottom: 40px;
    padding: 16px 0;
    text-align: center;
    font-style: italic;
    color: var(--color-text-light);
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}

/* Post body: the 750px column, spaced as the old theme spaced it */
.post-content > * + * {
    margin-top: 30px;
}

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

.post-content h2,
.post-content h3,
.post-content h4 {
    font-weight: 800;
    line-height: 1.3;
    color: var(--color-heading);
}

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

.post-content h2 { font-size: 23px; }
.post-content h3 { font-size: 20px; }
.post-content h4 { font-size: 17px; font-weight: 700; }

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

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

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

/* Ghost lost the address of a few links (the support email among them),
   leaving <a> with no href: show those as the plain text they are. */
.post-content a:not([href]) {
    color: inherit;
    text-decoration: none;
}

/* Lists: the old theme's accent dots and numbered circles in place of
   the markers */
.post-content ul,
.post-content ol {
    padding-left: 40px;
    list-style: none;
}

.post-content ol {
    counter-reset: numbered-list;
}

.post-content li {
    position: relative;
    margin: 15px 0;
}

.post-content ul li::before {
    content: "";
    position: absolute;
    top: 11px;
    left: -18px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-accent);
}

.post-content ol li::before {
    content: counter(numbered-list);
    counter-increment: numbered-list;
    position: absolute;
    top: 2px;
    left: -34px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--color-accent);
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
    line-height: 24px;
    text-align: center;
}

.post-content blockquote {
    margin-left: 60px;
    margin-right: 60px;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-heading);
}

.post-content blockquote strong {
    font-weight: 800;
}

.post-content code {
    padding: 2px 5px;
    border-radius: 3px;
    background: var(--color-surface);
    font-family: var(--font-mono);
    font-size: 0.9em;
}

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

.post-content pre code {
    padding: 0;
    background: none;
}

.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;
    margin-bottom: 45px;
}

.post-content img {
    display: block;
    max-width: 100%;
    height: auto;
    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%;
}

.post-content > .gallery {
    width: min(960px, 92vw);
    margin-left: 50%;
    transform: translateX(-50%);
}

.gallery-row {
    display: flex;
    justify-content: center;
}

.gallery-row + .gallery-row {
    margin-top: 10px;
}

.gallery-image + .gallery-image {
    margin-left: 10px;
}

.post-content .gallery-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Footer: copyright, the site name in the middle, the RSS icon */
.site-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 45px;
    padding-bottom: 45px;
    line-height: 1;
}

.copyright,
.footer-social {
    flex: 2;
}

.copyright {
    font-size: 14px;
}

.footer-social {
    text-align: right;
}

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

.footer-social-item:hover {
    color: var(--color-heading);
}

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

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

    .navbar-left {
        display: contents;
    }

    .sep {
        display: none;
    }

    .navbar-right {
        order: 2;
        margin-left: auto;
    }

    .main-menu {
        order: 3;
        width: 100%;
        gap: 8px 24px;
        margin-top: 14px;
    }

    .logo-image {
        height: 40px;
    }

    .post-content blockquote {
        margin-left: 0;
        margin-right: 0;
    }

    .author {
        flex-wrap: wrap;
    }

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

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

    .post-content > figure {
        margin-top: 30px;
        margin-bottom: 30px;
    }

    .site-footer {
        flex-direction: column;
    }

    .copyright {
        order: 1;
        margin-top: 15px;
    }
}

/* 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;
    }
}
