/* Stjernlöf — night-sky Ghost theme.
   Sections: fonts, tokens, base, sky, header, hero, feed, article, content
   cards, footer, motion. */

/* ---------- Fonts (self-hosted, OFL) ---------- */

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("../fonts/inter-latin-ext.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("../fonts/inter-latin.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: "Instrument Serif";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/instrument-serif-latin-ext.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Instrument Serif";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/instrument-serif-latin.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: "Instrument Serif";
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/instrument-serif-latin-italic.woff2") format("woff2");
}
@font-face {
    font-family: "JetBrains Mono";
    font-style: normal;
    font-weight: 100 800;
    font-display: swap;
    src: url("../fonts/jetbrains-mono-latin.woff2") format("woff2");
}

/* ---------- Tokens ---------- */

:root {
    color-scheme: dark;

    --bg: #06070d;
    --bg-raised: #0d0f1a;
    --surface: rgb(255 255 255 / 0.035);
    --surface-hover: rgb(255 255 255 / 0.06);
    --line: rgb(255 255 255 / 0.09);
    --line-strong: rgb(255 255 255 / 0.18);
    --text: #eceef6;
    --text-soft: #a4a9bd;
    --text-faint: #6d7288;
    /* Carried over from the old site: its blue primary and violet accent. */
    --blue: #38a4f5;
    --violet: #8b6cff;
    --accent: var(--ghost-accent-color, var(--blue));
    --star: 236 238 246;
    --sky-top: rgb(56 164 245 / 0.16);
    --sky-side: rgb(139 108 255 / 0.18);

    --font-display: var(--gh-font-heading, "Instrument Serif", "Iowan Old Style", Georgia, serif);
    --font-body: var(--gh-font-body, "Inter", system-ui, -apple-system, "Segoe UI", sans-serif);
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

    --gutter: clamp(16px, 4vw, 40px);
    --wrap: 1180px;
    --radius: 14px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-scheme="light"] {
    color-scheme: light;
    --bg: #f5f2ea;
    --bg-raised: #fffdf8;
    --surface: rgb(20 22 40 / 0.035);
    --surface-hover: rgb(20 22 40 / 0.06);
    --line: rgb(20 22 40 / 0.11);
    --line-strong: rgb(20 22 40 / 0.22);
    --text: #14162a;
    --text-soft: #4d5168;
    --text-faint: #7d8196;
    --blue: #1273c4;
    --violet: #5b3fd6;
    --star: 20 22 42;
    --sky-top: rgb(18 115 196 / 0.10);
    --sky-side: rgb(91 63 214 / 0.10);
}

@media (prefers-color-scheme: light) {
    :root[data-scheme="auto"] {
        color-scheme: light;
        --bg: #f5f2ea;
        --bg-raised: #fffdf8;
        --surface: rgb(20 22 40 / 0.035);
        --surface-hover: rgb(20 22 40 / 0.06);
        --line: rgb(20 22 40 / 0.11);
        --line-strong: rgb(20 22 40 / 0.22);
        --text: #14162a;
        --text-soft: #4d5168;
        --text-faint: #7d8196;
        --blue: #1273c4;
        --violet: #5b3fd6;
        --star: 20 22 42;
        --sky-top: rgb(18 115 196 / 0.10);
        --sky-side: rgb(91 63 214 / 0.10);
    }
}

/* ---------- Base ---------- */

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: 88px;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.65;
    font-feature-settings: "cv11", "ss03";
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

img, video, svg { max-width: 100%; height: auto; }
img { display: block; }
a { color: inherit; }
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 400; text-wrap: balance; }
p { margin: 0; }
button { font: inherit; color: inherit; }
::selection { background: color-mix(in oklab, var(--accent) 45%, transparent); color: var(--text); }

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

.skip-link {
    position: absolute;
    left: var(--gutter);
    top: -100px;
    z-index: 100;
    padding: 10px 16px;
    border-radius: 8px;
    background: var(--text);
    color: var(--bg);
    text-decoration: none;
}
.skip-link:focus { top: 12px; }

.eyebrow, .meta {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-faint);
}
.meta { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.meta-tag { color: var(--accent); text-decoration: none; }
a.meta-tag:hover { text-decoration: underline; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 22px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 30px -8px color-mix(in oklab, var(--accent) 70%, transparent);
}
.button-small { min-height: 36px; padding: 0 16px; font-size: 14px; }
.button-ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.icon-button:hover { background: var(--surface-hover); color: var(--text); }

/* ---------- Sky ---------- */

.sky {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(900px 520px at 78% -8%, var(--sky-top), transparent 70%),
        radial-gradient(760px 600px at -6% 22%, var(--sky-side), transparent 70%),
        var(--bg);
}
.sky-stars { position: absolute; inset: 0; width: 100%; height: 100%; }

.progress {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 60;
    height: 2px;
    background: linear-gradient(90deg, var(--blue), var(--violet));
    transform: scaleX(var(--progress, 0));
    transform-origin: 0 50%;
}

/* ---------- Header ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid transparent;
    transition: background 0.3s, border-color 0.3s, backdrop-filter 0.3s;
}
.site-header.is-scrolled {
    background: color-mix(in oklab, var(--bg) 72%, transparent);
    border-bottom-color: var(--line);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
}
.site-header-inner {
    display: flex;
    align-items: center;
    gap: 12px 28px;
    max-width: var(--wrap);
    min-height: 68px;
    margin: 0 auto;
    padding: 0 var(--gutter);
}
.site-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-display);
    font-size: 26px;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
}
.site-brand img { max-height: 34px; width: auto; }
.site-mark { color: var(--accent); transition: transform 0.8s var(--ease); }
.site-brand:hover .site-mark { transform: rotate(180deg) scale(1.15); }

.site-nav { flex: 1; min-width: 0; }
.nav {
    display: flex;
    gap: 4px 22px;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-x: auto;
    scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
    display: block;
    padding: 8px 0;
    font-size: 14.5px;
    color: var(--text-soft);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.2s;
}
.nav a:hover, .nav .nav-current a { color: var(--text); }
.site-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.site-actions .button { margin-left: 8px; }

.icon-sun { display: none; }
:root[data-scheme="light"] .icon-sun { display: block; }
:root[data-scheme="light"] .icon-moon { display: none; }
@media (prefers-color-scheme: light) {
    :root[data-scheme="auto"] .icon-sun { display: block; }
    :root[data-scheme="auto"] .icon-moon { display: none; }
}

@media (max-width: 720px) {
    .site-header-inner { flex-wrap: wrap; padding-top: 10px; padding-bottom: 6px; }
    .site-nav { order: 3; flex-basis: 100%; }
    .site-brand { font-size: 23px; }
}

/* ---------- Layout ---------- */

.site-main { flex: 1; width: 100%; }

.hero {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: clamp(56px, 12vw, 150px) var(--gutter) clamp(40px, 7vw, 84px);
}
.hero-title {
    max-width: 16ch;
    margin-top: 18px;
    font-family: var(--font-display);
    font-size: clamp(46px, 9.5vw, 124px);
    line-height: 0.96;
    letter-spacing: -0.02em;
}
.hero-lede {
    max-width: 56ch;
    margin-top: 24px;
    font-size: clamp(17px, 2vw, 20px);
    color: var(--text-soft);
}
.hero-archive { padding-top: clamp(40px, 8vw, 96px); }
.hero-archive .hero-title { font-size: clamp(40px, 7vw, 84px); }
.hero-avatar { width: 72px; height: 72px; margin-bottom: 20px; border-radius: 50%; object-fit: cover; }
.hero-error { text-align: center; }
.hero-error .hero-title, .hero-error .hero-lede { margin-left: auto; margin-right: auto; }
.hero-error .button { margin-top: 32px; }

/* ---------- Feed ---------- */

.feed {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
    gap: 20px;
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 0 var(--gutter) 40px;
}
.feed-empty { color: var(--text-faint); }

.post-card {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color 0.3s, transform 0.5s var(--ease), background 0.3s;
}
.post-card:hover { border-color: var(--line-strong); transform: translateY(-3px); }
.post-card-link { position: absolute; inset: 0; z-index: 2; border-radius: inherit; }

/* Pointer-following glow, shared by anything marked data-glow. */
[data-glow] { --mx: 50%; --my: 0%; }
[data-glow]::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    border-radius: inherit;
    background: radial-gradient(420px circle at var(--mx) var(--my), color-mix(in oklab, var(--accent) 22%, transparent), transparent 62%);
    opacity: 0;
    transition: opacity 0.4s;
    pointer-events: none;
}
[data-glow]:hover::before { opacity: 1; }

.post-card-image { aspect-ratio: 16 / 9; overflow: hidden; background: var(--bg-raised); }
.post-card-image img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.9s var(--ease); }
.post-card:hover .post-card-image img { transform: scale(1.04); }

.post-card-body {
    position: relative;
    z-index: 1;
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 14px;
    padding: 24px;
}
.post-card-title {
    font-family: var(--font-display);
    font-size: 30px;
    line-height: 1.08;
    letter-spacing: -0.01em;
}
.post-card-excerpt {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    color: var(--text-soft);
    font-size: 15.5px;
    line-height: 1.55;
}
.post-card.no-image .post-card-body { justify-content: flex-end; min-height: 250px; }
.post-card.no-image .post-card-title { font-size: 36px; }

/* The newest post leads the front page at full width. */
@media (min-width: 760px) {
    .feed-home .post-card:first-child { grid-column: 1 / -1; flex-direction: row; min-height: 380px; }
    .feed-home .post-card:first-child .post-card-image { flex: 1.25; aspect-ratio: auto; }
    .feed-home .post-card:first-child .post-card-body { flex: 1; justify-content: center; padding: clamp(28px, 4vw, 56px); }
    .feed-home .post-card:first-child .post-card-title { font-size: clamp(38px, 4.6vw, 64px); line-height: 1.02; }
    .feed-home .post-card:first-child .post-card-excerpt { font-size: 17px; }
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 16px var(--gutter) 72px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-faint);
}
.pagination a { color: var(--text); text-decoration: none; }
.pagination a:hover { color: var(--accent); }

/* ---------- Article ---------- */

.gh-canvas {
    display: grid;
    grid-template-columns:
        [full-start] minmax(var(--gutter), 1fr)
        [wide-start] minmax(0, 190px)
        [main-start] min(700px, calc(100% - var(--gutter) * 2)) [main-end]
        minmax(0, 190px) [wide-end]
        minmax(var(--gutter), 1fr) [full-end];
}
.gh-canvas > * { grid-column: main-start / main-end; min-width: 0; }
.kg-width-wide { grid-column: wide-start / wide-end; }
.kg-width-full { grid-column: full-start / full-end; }
.kg-width-full img { width: 100%; }

.article { padding-top: clamp(40px, 8vw, 104px); }
.article-header { row-gap: 22px; }
.article-title {
    font-family: var(--font-display);
    font-size: clamp(42px, 7.4vw, 88px);
    line-height: 1;
    letter-spacing: -0.02em;
}
.article-lede { font-size: clamp(19px, 2.2vw, 23px); line-height: 1.45; color: var(--text-soft); }
.article-byline { font-size: 15px; color: var(--text-faint); }
.article-byline a { color: var(--text-soft); text-decoration: none; }
.article-byline a:hover { color: var(--text); }
.article-image { margin: 18px 0 0; }
.article-image img { width: 100%; border-radius: var(--radius); }

figcaption {
    margin-top: 12px;
    font-size: 13.5px;
    line-height: 1.5;
    text-align: center;
    color: var(--text-faint);
}
figcaption a { color: var(--text-soft); }

/* ---------- Post content ---------- */

.gh-content { padding-top: clamp(32px, 5vw, 56px); font-size: clamp(17.5px, 1.4vw, 19.5px); line-height: 1.75; }
.gh-content > * + * { margin-top: 1.5em; }
.gh-content > :first-child { margin-top: 0; }

.gh-content h2, .gh-content h3, .gh-content h4 { font-family: var(--font-display); letter-spacing: -0.01em; line-height: 1.12; }
.gh-content h2 { margin-top: 2.1em; font-size: 2.1em; }
.gh-content h3 { margin-top: 1.9em; font-size: 1.6em; }
.gh-content h4 { margin-top: 1.7em; font-size: 1.3em; }
.gh-content h2 + *, .gh-content h3 + *, .gh-content h4 + * { margin-top: 0.7em; }

.gh-content a {
    color: var(--text);
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
    transition: color 0.2s;
}
.gh-content a:hover { color: var(--accent); }
.gh-content strong { font-weight: 650; }
.gh-content ul, .gh-content ol { padding-left: 1.3em; }
.gh-content li + li { margin-top: 0.45em; }
.gh-content li::marker { color: var(--accent); }

.gh-content blockquote {
    margin-left: 0;
    margin-right: 0;
    padding-left: 1.2em;
    border-left: 2px solid var(--accent);
    font-family: var(--font-display);
    font-size: 1.45em;
    font-style: italic;
    line-height: 1.3;
}
.gh-content blockquote.kg-blockquote-alt { padding: 0; border: 0; font-size: 1.9em; text-align: center; }

.gh-content hr {
    width: 100%;
    height: 1px;
    margin-top: 3em;
    margin-bottom: 3em;
    border: 0;
    background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}

.gh-content :not(pre) > code {
    padding: 0.15em 0.4em;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: 0.86em;
}
.gh-content pre {
    position: relative;
    overflow-x: auto;
    padding: 20px 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-raised);
    font-family: var(--font-mono);
    font-size: 14.5px;
    line-height: 1.6;
    tab-size: 4;
}
.gh-content pre code { font: inherit; }
.copy-code {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-soft);
    font-family: var(--font-mono);
    font-size: 11.5px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}
.gh-content pre:hover .copy-code, .copy-code:focus-visible { opacity: 1; }
.copy-code:hover { color: var(--text); }

.gh-content table {
    display: block;
    width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    font-size: 0.88em;
}
.gh-content th, .gh-content td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; }
.gh-content th { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }

.gh-content figure { margin-left: 0; margin-right: 0; }
.gh-content .kg-image { margin: 0 auto; border-radius: 10px; }
.gh-content .kg-width-full .kg-image { border-radius: 0; }
.gh-content .kg-card + *, .gh-content * + .kg-card { margin-top: 2em; }
.gh-content .kg-embed-card { display: flex; flex-direction: column; align-items: center; }
.gh-content iframe { max-width: 100%; }

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

.article-footer { row-gap: 40px; padding-top: 56px; padding-bottom: 24px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.tag-list a {
    display: block;
    padding: 6px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--text-soft);
    text-decoration: none;
    transition: border-color 0.2s, color 0.2s;
}
.tag-list a:hover { border-color: var(--accent); color: var(--text); }

.subscribe {
    position: relative;
    overflow: hidden;
    padding: clamp(28px, 5vw, 48px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    text-align: center;
}
.subscribe > * { position: relative; z-index: 1; }
.subscribe h2 { font-family: var(--font-display); font-size: clamp(30px, 4vw, 42px); line-height: 1.05; }
.subscribe p { max-width: 46ch; margin: 12px auto 24px; color: var(--text-soft); }

.read-next {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: 20px;
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 40px var(--gutter) 80px;
}
.read-next-item {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    text-decoration: none;
    transition: border-color 0.3s;
}
.read-next-item:hover { border-color: var(--line-strong); }
.read-next-item > * { position: relative; z-index: 1; }
.read-next-newer { text-align: right; }
.read-next-title { font-family: var(--font-display); font-size: 28px; line-height: 1.1; }

/* ---------- Footer ---------- */

.site-footer { margin-top: 40px; border-top: 1px solid var(--line); }
.site-footer-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 28px;
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 28px var(--gutter) 40px;
    font-size: 14px;
    color: var(--text-faint);
}
.site-footer nav { flex: 1; min-width: 0; }
.site-footer-rss { color: var(--text-soft); text-decoration: none; }
.site-footer-rss:hover { color: var(--accent); }

/* ---------- Motion ---------- */

@view-transition { navigation: auto; }

@media (prefers-reduced-motion: no-preference) {
    .hero > *, .article-header > * {
        animation: rise 0.9s var(--ease) both;
    }
    .hero > :nth-child(2), .article-header > :nth-child(2) { animation-delay: 0.07s; }
    .hero > :nth-child(3), .article-header > :nth-child(3) { animation-delay: 0.14s; }
    .article-header > :nth-child(4) { animation-delay: 0.21s; }
    .article-header > :nth-child(5) { animation-delay: 0.28s; }

    .post-card { animation: rise 0.8s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms + 0.15s); }
}

@keyframes rise {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: none; }
}

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