/* =============================================================
   QUILL — a reading-first theme for Ghost
   Structure → Hanken Grotesk (sans).  Reading → Source Serif 4.
   ============================================================= */

/* ---------- Design tokens ---------- */
:root {
    --font-sans: var(--gh-font-heading, 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
    --font-serif: var(--gh-font-body, 'Source Serif 4', Georgia, 'Times New Roman', serif);

    /* Light scheme (default) */
    --paper: #fafaf8;
    --surface: #ffffff;
    --ink: #1c1b1a;
    --ink-soft: #39362f;
    --muted: #6e6a64;
    --faint: #9a958c;
    --hairline: #e7e4dd;
    --hairline-soft: #f0ede7;
    --code-bg: #f3f1ea;

    /* Brand accent — overridden by Ghost Admin "accent colour" if set */
    --accent: #1a5e4a;
    --link: var(--accent);

    /* Scale */
    --wrap: 1140px;
    --measure: 680px;
    --radius: 10px;
    --radius-sm: 6px;

    --step: 1.5rem;        /* base vertical rhythm */
    --reading: 1.1875rem;  /* 19px article body */

    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --shadow: 0 1px 2px rgba(20, 18, 14, 0.04), 0 8px 28px rgba(20, 18, 14, 0.06);
}

[data-applied-scheme="dark"] {
    --paper: #131210;
    --surface: #1b1a16;
    --ink: #eceadf;
    --ink-soft: #cbc7bc;
    --muted: #9b968b;
    --faint: #6f6b61;
    --hairline: #2c2a24;
    --hairline-soft: #232220;
    --code-bg: #211f1b;
    --link: color-mix(in srgb, var(--accent) 52%, #ffffff);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.4);
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }

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

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-serif);
    font-size: var(--reading);
    line-height: 1.72;
    font-feature-settings: 'kern', 'liga';
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
}

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

a { color: var(--link); text-decoration: none; }

a:hover { text-decoration: underline; text-underline-offset: 2px; }

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

::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    color: var(--ink);
    line-height: 1.18;
    letter-spacing: -0.018em;
    font-weight: 600;
    margin: 0;
}

.wrap {
    width: 100%;
    max-width: var(--wrap);
    margin-inline: auto;
    padding-inline: 24px;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--ink);
    color: var(--paper);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    z-index: 200;
    font-family: var(--font-sans);
    font-size: 0.9rem;
}
.skip-link:focus { left: 16px; top: 16px; }

/* ---------- Header ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: color-mix(in srgb, var(--paper) 82%, transparent);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--hairline);
}

.site-header-inner {
    display: flex;
    align-items: center;
    gap: 24px;
    min-height: 68px;
}

.site-title {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.32rem;
    letter-spacing: -0.03em;
    color: var(--ink);
}
.site-title:hover { text-decoration: none; color: var(--link); }

.site-logo img { max-height: 30px; width: auto; }

.site-nav { margin-left: auto; }

.nav-list {
    display: flex;
    align-items: center;
    gap: 26px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-item a {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--ink-soft);
    letter-spacing: -0.01em;
    transition: color 0.18s var(--ease);
}
.nav-item a:hover { color: var(--link); text-decoration: none; }
.nav-item--active a { color: var(--link); }

.header-actions { display: flex; align-items: center; gap: 6px; margin-left: 4px; }

.theme-toggle {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--hairline);
    background: transparent;
    color: var(--ink-soft);
    border-radius: 999px;
    cursor: pointer;
    transition: border-color 0.18s var(--ease), color 0.18s var(--ease), background 0.18s var(--ease);
}
.theme-toggle:hover { color: var(--link); border-color: var(--link); }
.theme-toggle svg { grid-area: 1 / 1; }
.icon-moon { display: none; }
[data-applied-scheme="dark"] .icon-sun { display: none; }
[data-applied-scheme="dark"] .icon-moon { display: block; }

.nav-burger { display: none; }

/* ---------- Intro / home masthead ---------- */
.intro {
    padding: clamp(40px, 8vw, 84px) 0 clamp(28px, 5vw, 48px);
    border-bottom: 1px solid var(--hairline-soft);
}
.intro-title {
    font-size: clamp(2.2rem, 6vw, 3.4rem);
    letter-spacing: -0.035em;
    font-weight: 700;
}
.intro-desc {
    font-family: var(--font-serif);
    font-size: clamp(1.05rem, 2.5vw, 1.28rem);
    color: var(--muted);
    max-width: 42ch;
    margin: 16px 0 0;
    line-height: 1.5;
}

/* ---------- Post feed ---------- */
.post-feed {
    display: flex;
    flex-direction: column;
    padding: clamp(28px, 5vw, 52px) 0;
}

/* List rows separated by hairlines */
.post-card {
    display: grid;
    grid-template-columns: 1fr 200px;
    gap: 32px;
    align-items: start;
    padding: 30px 0;
    border-top: 1px solid var(--hairline);
}
.post-feed > .post-card:first-child { border-top: 0; }

.post-card--no-image { grid-template-columns: 1fr; }

.post-card-image {
    grid-column: 2;
    grid-row: 1 / span 5;
    display: block;
    overflow: hidden;
    border-radius: var(--radius-sm);
    aspect-ratio: 4 / 3;
    background: var(--hairline-soft);
}
.post-card-image img {
    width: 100%; height: 100%;
    object-fit: cover;
    transition: transform 0.5s var(--ease);
}
.post-card:hover .post-card-image img { transform: scale(1.04); }

.post-card-body { grid-column: 1; }

.post-card-tag {
    display: inline-block;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--link);
    margin-bottom: 10px;
}
.post-card-tag:hover { text-decoration: none; opacity: 0.75; }

.post-card-title {
    font-size: 1.45rem;
    letter-spacing: -0.022em;
    margin: 0 0 8px;
}
.post-card-title a { color: var(--ink); }
.post-card-title a:hover { color: var(--link); text-decoration: none; }

.post-card-excerpt {
    color: var(--muted);
    font-size: 1.02rem;
    line-height: 1.6;
    margin: 0 0 14px;
    max-width: 60ch;
}

.post-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    color: var(--faint);
}
.post-card-meta .meta-author { color: var(--ink-soft); font-weight: 500; }
.meta-dot { color: var(--faint); }

/* Lead (first) post — larger, image on top */
.post-card--lead {
    display: block;
    border-top: 0;
    padding-top: 0;
    padding-bottom: 44px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--hairline);
}
.post-card--lead .post-card-image {
    width: 100%;
    aspect-ratio: 16 / 8;
    border-radius: var(--radius);
    margin-bottom: 26px;
}
.post-card--lead .post-card-title {
    font-size: clamp(1.7rem, 4vw, 2.5rem);
    letter-spacing: -0.03em;
    margin-bottom: 12px;
}
.post-card--lead .post-card-excerpt {
    font-size: 1.12rem;
    max-width: 64ch;
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 0 64px;
    font-family: var(--font-sans);
    font-size: 0.92rem;
}
.pagination a {
    display: inline-flex;
    align-items: center;
    padding: 9px 18px;
    border: 1px solid var(--hairline);
    border-radius: 999px;
    color: var(--ink-soft);
    font-weight: 500;
    transition: border-color 0.18s var(--ease), color 0.18s var(--ease);
}
.pagination a:hover { border-color: var(--link); color: var(--link); text-decoration: none; }
.pagination .page-number { color: var(--faint); }

/* ---------- Article (reading view) ---------- */
.article { padding-top: clamp(32px, 6vw, 64px); }

/* gh-canvas: centered reading column with wide / full bleed lanes */
.gh-canvas {
    display: grid;
    grid-template-columns:
        [full-start] minmax(24px, 1fr)
        [wide-start] minmax(0, 180px)
        [main-start] min(var(--measure), calc(100% - 48px)) [main-end]
        minmax(0, 180px) [wide-end]
        minmax(24px, 1fr) [full-end];
}
.gh-canvas > * { grid-column: main-start / main-end; }

.article-meta-top { margin-bottom: 18px; }
.article-tag {
    font-family: var(--font-sans);
    font-size: 0.76rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--link);
}

.article-title {
    font-size: clamp(2rem, 5.2vw, 3.1rem);
    letter-spacing: -0.035em;
    line-height: 1.08;
    margin-bottom: 18px;
}

.article-subtitle {
    font-family: var(--font-serif);
    font-size: clamp(1.12rem, 2.6vw, 1.4rem);
    line-height: 1.46;
    color: var(--muted);
    margin: 0 0 28px;
    font-weight: 400;
}

.article-byline {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 0;
    border-top: 1px solid var(--hairline-soft);
    border-bottom: 1px solid var(--hairline-soft);
    margin-bottom: 8px;
}
.byline-avatar img,
.byline-avatar .avatar-fallback {
    width: 42px; height: 42px;
    border-radius: 999px;
    object-fit: cover;
}
.avatar-fallback {
    display: grid;
    place-items: center;
    background: var(--accent);
    color: #fff;
    font-family: var(--font-sans);
    font-weight: 600;
    text-transform: uppercase;
}
.byline-text { display: flex; flex-direction: column; gap: 2px; font-family: var(--font-sans); }
.byline-authors { font-weight: 600; font-size: 0.95rem; color: var(--ink); }
.byline-detail { font-size: 0.84rem; color: var(--faint); }

.article-image {
    margin: clamp(28px, 5vw, 44px) 0;
}
.article-image > img {
    grid-column: wide-start / wide-end;
    width: 100%;
    border-radius: var(--radius);
}
.article-image figcaption {
    grid-column: main-start / main-end;
    text-align: center;
    font-family: var(--font-sans);
    font-size: 0.84rem;
    color: var(--faint);
    margin-top: 12px;
}

/* ---------- gh-content: the reading column ---------- */
.gh-content { padding-top: clamp(28px, 5vw, 40px); }

.gh-content > * { margin: 0 0 var(--step); }

.gh-content > p {
    font-size: var(--reading);
    line-height: 1.74;
    color: var(--ink-soft);
}
.gh-content > p:first-of-type { margin-top: 0; }

.gh-content a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; text-decoration-color: color-mix(in srgb, var(--link) 38%, transparent); }
.gh-content a:hover { text-decoration-color: var(--link); }

.gh-content h2 {
    font-size: 1.7rem;
    letter-spacing: -0.025em;
    margin-top: 2.6rem;
    margin-bottom: 1rem;
}
.gh-content h3 {
    font-size: 1.32rem;
    letter-spacing: -0.02em;
    margin-top: 2rem;
    margin-bottom: 0.8rem;
}
.gh-content h4 { font-size: 1.1rem; margin-top: 1.6rem; }

.gh-content ul, .gh-content ol { padding-left: 1.4em; color: var(--ink-soft); }
.gh-content li { margin-bottom: 0.5em; line-height: 1.7; }
.gh-content li::marker { color: var(--faint); }

.gh-content blockquote {
    border-left: 3px solid var(--accent);
    padding: 4px 0 4px 24px;
    margin-left: 0;
    font-style: italic;
    font-size: 1.22rem;
    line-height: 1.55;
    color: var(--ink);
}

.gh-content hr {
    border: 0;
    height: 1px;
    background: var(--hairline);
    margin: clamp(32px, 6vw, 52px) auto;
    width: 60%;
}

.gh-content img { border-radius: var(--radius-sm); }

.gh-content figure { margin: clamp(24px, 4vw, 36px) 0; }
.gh-content figcaption {
    text-align: center;
    font-family: var(--font-sans);
    font-size: 0.84rem;
    color: var(--faint);
    margin-top: 10px;
}

.gh-content code {
    font-family: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
    font-size: 0.88em;
    background: var(--code-bg);
    padding: 0.16em 0.42em;
    border-radius: 5px;
    color: var(--ink);
}
.gh-content pre {
    background: var(--code-bg);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: 18px 20px;
    overflow-x: auto;
    font-size: 0.9rem;
    line-height: 1.6;
}
.gh-content pre code { background: none; padding: 0; }

.gh-content table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-sans);
    font-size: 0.95rem;
}
.gh-content th, .gh-content td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--hairline);
}
.gh-content th { font-weight: 600; color: var(--ink); }

/* Koenig embeds / wide & full cards */
.kg-width-wide { grid-column: wide-start / wide-end; }
.kg-width-full { grid-column: full-start / full-end; }
.kg-width-full img { width: 100%; border-radius: 0; }
.gh-content .kg-card { margin-top: var(--step); margin-bottom: var(--step); }

/* ---------- Article footer ---------- */
.article-footer { padding-top: 36px; margin-top: 20px; }

.article-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 36px; }
.pill {
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--ink-soft);
    background: var(--surface);
    border: 1px solid var(--hairline);
    padding: 5px 13px;
    border-radius: 999px;
    transition: border-color 0.18s var(--ease), color 0.18s var(--ease);
}
.pill:hover { border-color: var(--link); color: var(--link); text-decoration: none; }

.author-bio {
    display: flex;
    gap: 18px;
    align-items: flex-start;
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
}
.author-bio-avatar img,
.author-bio-avatar .avatar-fallback {
    width: 56px; height: 56px; border-radius: 999px; object-fit: cover; font-size: 1.3rem;
}
.author-bio-text h3 { font-size: 1.12rem; margin-bottom: 4px; }
.author-bio-text h3 a { color: var(--ink); }
.author-bio-text p { font-size: 0.98rem; color: var(--muted); line-height: 1.55; margin: 0 0 8px; }
.author-bio-link { font-family: var(--font-sans); font-size: 0.88rem; font-weight: 500; }

/* ---------- Read next ---------- */
.read-next {
    border-top: 1px solid var(--hairline);
    margin-top: clamp(48px, 8vw, 80px);
    padding: clamp(40px, 6vw, 64px) 0 clamp(24px, 4vw, 40px);
    background: var(--hairline-soft);
}
.read-next-title {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--faint);
    margin-bottom: 24px;
}
.read-next-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 36px;
}
.read-next-grid .post-card { border-top: 0; padding: 0; grid-template-columns: 1fr; }
.read-next-grid .post-card-image {
    grid-column: 1; grid-row: auto;
    aspect-ratio: 16 / 9; width: 100%;
    margin-bottom: 16px; border-radius: var(--radius-sm);
}

/* ---------- Archive headers ---------- */
.archive-header {
    padding: clamp(44px, 8vw, 80px) 0 clamp(20px, 4vw, 36px);
    border-bottom: 1px solid var(--hairline-soft);
}
.archive-eyebrow {
    font-family: var(--font-sans);
    font-size: 0.76rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--link);
}
.archive-title {
    font-size: clamp(2rem, 5vw, 3rem);
    letter-spacing: -0.03em;
    margin: 10px 0 0;
}
.archive-desc { color: var(--muted); max-width: 56ch; margin: 14px 0 0; font-size: 1.08rem; line-height: 1.5; }
.archive-count {
    display: inline-block; margin-top: 16px;
    font-family: var(--font-sans); font-size: 0.85rem; color: var(--faint);
}
.author-head { display: flex; gap: 22px; align-items: center; }
.author-head-avatar { width: 76px; height: 76px; border-radius: 999px; object-fit: cover; }

/* ---------- Error ---------- */
.error-page { padding: clamp(80px, 16vw, 160px) 0; text-align: center; }
.error-code { font-family: var(--font-sans); font-size: clamp(3rem, 12vw, 6rem); font-weight: 700; color: var(--accent); letter-spacing: -0.04em; }
.error-title { font-size: clamp(1.4rem, 4vw, 2rem); margin: 8px 0 12px; }
.error-desc { color: var(--muted); margin-bottom: 28px; }

.button {
    display: inline-block;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.95rem;
    background: var(--accent);
    color: #fff;
    padding: 12px 26px;
    border-radius: 999px;
    transition: opacity 0.18s var(--ease);
}
.button:hover { opacity: 0.88; text-decoration: none; }

/* ---------- Footer ---------- */
.site-footer {
    border-top: 1px solid var(--hairline);
    margin-top: clamp(40px, 8vw, 80px);
    padding: clamp(40px, 6vw, 64px) 0;
}
.site-footer-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 28px 48px;
    align-items: flex-start;
}
.footer-title { font-family: var(--font-sans); font-weight: 700; font-size: 1.2rem; letter-spacing: -0.03em; color: var(--ink); }
.footer-desc { color: var(--muted); font-size: 0.98rem; margin: 8px 0 0; max-width: 36ch; line-height: 1.5; }
.footer-nav { margin-left: auto; }
.footer-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 22px; }
.footer-nav a { font-family: var(--font-sans); font-size: 0.92rem; color: var(--ink-soft); }
.footer-nav a:hover { color: var(--link); text-decoration: none; }
.footer-meta { flex-basis: 100%; }
.footer-meta p { font-family: var(--font-sans); font-size: 0.85rem; color: var(--faint); margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .read-next-grid { grid-template-columns: 1fr; gap: 28px; }
}

@media (max-width: 720px) {
    :root { --reading: 1.0625rem; }   /* 17px on phones */

    .site-header-inner { min-height: 60px; }

    .nav-burger {
        display: grid;
        place-items: center;
        gap: 5px;
        width: 38px; height: 38px;
        border: 1px solid var(--hairline);
        background: transparent;
        border-radius: 999px;
        cursor: pointer;
    }
    .nav-burger span {
        display: block; width: 16px; height: 1.6px;
        background: var(--ink); border-radius: 2px;
        transition: transform 0.22s var(--ease), opacity 0.22s var(--ease);
    }

    .site-nav {
        position: fixed;
        inset: 60px 0 auto 0;
        background: var(--paper);
        border-bottom: 1px solid var(--hairline);
        margin: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s var(--ease);
        box-shadow: var(--shadow);
    }
    .site-nav.is-open { max-height: 70vh; }
    .nav-list {
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        padding: 8px 24px 20px;
    }
    .nav-item { width: 100%; border-bottom: 1px solid var(--hairline-soft); }
    .nav-item a { display: block; padding: 14px 0; font-size: 1.05rem; }

    body.nav-open .nav-burger span:first-child { transform: translateY(3.3px) rotate(45deg); }
    body.nav-open .nav-burger span:last-child { transform: translateY(-3.3px) rotate(-45deg); }

    .post-card { grid-template-columns: 1fr; gap: 0; }
    .post-card-image {
        grid-column: 1; grid-row: auto;
        width: 100%; aspect-ratio: 16 / 9;
        margin-bottom: 16px;
    }

    .post-card--lead .post-card-image { aspect-ratio: 16 / 9; }

    .article-byline { flex-wrap: wrap; }

    .gh-content blockquote { font-size: 1.1rem; }
}

@media (max-width: 460px) {
    .wrap { padding-inline: 18px; }
    .gh-canvas {
        grid-template-columns:
            [full-start] 18px
            [wide-start] 0
            [main-start] calc(100% - 36px) [main-end]
            0 [wide-end]
            18px [full-end];
    }
}
