/* Folio — a text-first Ghost theme */

:root {
    --bg: #fbfaf7;
    --text: #1c1b19;
    --muted: #6b6760;
    --faint: #e7e3dc;
    --surface: #f3f0ea;
    --accent: var(--ghost-accent-color, #b4441f);
    --serif: var(--gh-font-heading, var(--folio-serif));
    --body-serif: var(--gh-font-body, var(--folio-serif));
    --folio-serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --wrap: 1040px;
    --text-w: 680px;
    --wide-w: 1000px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #141413;
        --text: #ece9e3;
        --muted: #9d988f;
        --faint: #2b2a27;
        --surface: #1d1c1a;
        --accent: #e8825d;
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #141413;
    --text: #ece9e3;
    --muted: #9d988f;
    --faint: #2b2a27;
    --surface: #1d1c1a;
    --accent: #e8825d;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 17px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-color: var(--faint); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
img { max-width: 100%; height: auto; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.site { min-height: 100vh; display: flex; flex-direction: column; }
.site-main { flex: 1; padding-bottom: 80px; }
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 24px; }
.wrap-text { max-width: calc(var(--text-w) + 48px); margin: 0 auto; padding: 0 24px; }
.wrap-wide { max-width: calc(var(--wide-w) + 48px); margin: 0 auto; padding: 0 24px; }

/* Header */
.site-header { border-bottom: 1px solid var(--faint); }
.header-inner { display: flex; align-items: center; gap: 28px; height: 64px; }
.site-title { font-weight: 600; text-decoration: none; letter-spacing: -0.01em; white-space: nowrap; }
.site-nav { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.site-nav::-webkit-scrollbar { display: none; }
.site-nav .nav { display: flex; gap: 22px; list-style: none; margin: 0; padding: 0; font-size: 15px; white-space: nowrap; }
.site-nav .nav a { text-decoration: none; color: var(--muted); }
.site-nav .nav a:hover, .site-nav .nav-current a { color: var(--text); }
.header-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn { background: none; border: 0; color: var(--muted); padding: 8px; cursor: pointer; border-radius: 6px; display: inline-flex; }
.icon-btn:hover { color: var(--text); background: var(--surface); }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    font: 600 14px/1 var(--sans);
    padding: 10px 16px; border-radius: 6px; border: 1px solid var(--text);
    background: var(--text); color: var(--bg); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: none; color: var(--text); border-color: var(--faint); }

/* Shared labels */
.block { margin-top: 64px; }
.block-label {
    font: 600 12px/1.4 var(--sans); letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--muted); margin: 0 0 18px; text-decoration: none; display: block;
}
.page-title { font-family: var(--serif); font-weight: 500; font-size: 40px; line-height: 1.15; letter-spacing: -0.01em; margin: 0 0 12px; }

/* Intro */
.intro { padding-top: 80px; max-width: 760px; }
.intro-title { font-family: var(--serif); font-weight: 500; font-size: clamp(40px, 6vw, 60px); line-height: 1.05; letter-spacing: -0.02em; margin: 0; }
.intro-lede { font-family: var(--serif); font-size: clamp(19px, 2.2vw, 23px); line-height: 1.45; color: var(--muted); margin: 18px 0 0; }

/* Signup */
.signup { margin-top: 32px; }
.signup-heading { font-size: 14px; color: var(--muted); margin: 0 0 10px; }
.signup-form { display: flex; flex-wrap: wrap; gap: 8px; max-width: 460px; }
.signup-form input {
    flex: 1 1 220px; min-width: 0; font: 16px var(--sans); padding: 10px 14px;
    border: 1px solid var(--faint); border-radius: 6px; background: var(--bg); color: var(--text);
}
.signup-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.signup-msg { display: none; width: 100%; margin: 4px 0 0; font-size: 14px; }
.signup-form.success .signup-success, .signup-form.error .signup-error { display: block; }
.signup-form.success input, .signup-form.success button { display: none; }
.signup-form.loading button { opacity: 0.6; }

/* Featured */
.featured-link { display: block; text-decoration: none; padding: 28px 32px; background: var(--surface); border-radius: 10px; border-left: 3px solid var(--accent); }
.featured-link:hover { color: inherit; }
.featured-link:hover .featured-title { color: var(--accent); }
.featured-title { display: block; font-family: var(--serif); font-size: clamp(24px, 3vw, 32px); line-height: 1.2; font-weight: 500; letter-spacing: -0.01em; }
.featured-excerpt { display: block; margin-top: 10px; color: var(--muted); font-family: var(--serif); font-size: 18px; max-width: 640px; }
.featured-meta { display: block; margin-top: 14px; font-size: 13px; color: var(--muted); }

/* Start here + Projects */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 0 64px; }
.start-list { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.start-list li { counter-increment: s; display: flex; gap: 14px; padding: 10px 0; border-top: 1px solid var(--faint); font-family: var(--serif); font-size: 18px; line-height: 1.35; }
.start-list li::before { content: counter(s, decimal-leading-zero); font: 500 13px/1.9 var(--mono); color: var(--accent); }
.start-list a { text-decoration: none; }
.hub-list { list-style: none; margin: 0; padding: 0; }
.hub-list li { border-top: 1px solid var(--faint); }
.hub-list a { display: block; padding: 10px 0; text-decoration: none; }
.hub-title { display: block; font-weight: 600; font-size: 16px; }
.hub-title::after { content: " \2192"; color: var(--muted); }
.hub-desc { display: block; color: var(--muted); font-size: 15px; line-height: 1.45; }

/* Post list */
.post-list { list-style: none; margin: 0; padding: 0; }
.post-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 20px; align-items: baseline; padding: 11px 0; border-top: 1px solid var(--faint); }
.post-row-date { font: 13px var(--mono); color: var(--muted); }
.post-row-title { font-family: var(--serif); font-size: 19px; line-height: 1.35; text-decoration: none; }
.post-row-tag { font-size: 13px; color: var(--muted); white-space: nowrap; }
.year-heading { font-family: var(--serif); font-size: 26px; font-weight: 500; margin: 48px 0 8px; }

.pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 28px; font-size: 14px; color: var(--muted); }
.pagination a { text-decoration: none; }

/* Topics */
.topic-list { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.topic-list a { display: inline-flex; gap: 8px; padding: 6px 12px; border: 1px solid var(--faint); border-radius: 999px; text-decoration: none; font-size: 14px; }
.topic-list a:hover { border-color: var(--accent); }
.topic-list span { color: var(--muted); }

.archive-header { padding-top: 64px; margin-bottom: 32px; max-width: var(--text-w); }
.archive-desc { color: var(--muted); font-family: var(--serif); font-size: 19px; margin: 0; }

/* Article */
.article-header { padding-top: 72px; }
.article-title { font-family: var(--serif); font-weight: 500; font-size: clamp(34px, 5vw, 48px); line-height: 1.12; letter-spacing: -0.015em; margin: 0; }
.article-dek { font-family: var(--serif); font-size: 21px; line-height: 1.45; color: var(--muted); margin: 16px 0 0; }
.article-meta { font-size: 14px; color: var(--muted); margin: 20px 0 0; padding-bottom: 28px; border-bottom: 1px solid var(--faint); }
.article-image { margin-top: 40px; }
.article-image img { border-radius: 6px; width: 100%; }
.article-image figcaption, .gh-content figcaption { font-size: 14px; color: var(--muted); text-align: center; margin-top: 10px; }
.article-footer { margin-top: 56px; }
.article-footer > :first-child { padding-top: 28px; border-top: 1px solid var(--faint); }
.article-tags { font-size: 14px; color: var(--muted); margin: 0; }
.related { max-width: calc(var(--text-w) + 48px); margin-top: 72px; }

/* Content */
.gh-content {
    display: grid;
    grid-template-columns:
        [full-start] minmax(24px, 1fr)
        [wide-start] minmax(0, calc((var(--wide-w) - var(--text-w)) / 2))
        [main-start] min(var(--text-w), calc(100% - 48px)) [main-end]
        minmax(0, calc((var(--wide-w) - var(--text-w)) / 2)) [wide-end]
        minmax(24px, 1fr) [full-end];
    margin-top: 36px;
}
.gh-content > * { grid-column: main-start / main-end; }
.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%; }
body.font-serif .gh-content { font-family: var(--body-serif); font-size: 20px; line-height: 1.65; }
body.font-sans .gh-content { font-family: var(--gh-font-body, var(--sans)); font-size: 18px; line-height: 1.7; }
.gh-content > * { margin-top: 0; margin-bottom: 0; }
.gh-content > * + * { margin-top: 1.1em; }
.gh-content h2, .gh-content h3, .gh-content h4 { font-family: var(--serif); font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.gh-content h2 { font-size: 1.45em; margin-top: 2em; }
.gh-content h3 { font-size: 1.2em; margin-top: 1.7em; }
.gh-content a { color: var(--accent); text-decoration-color: currentColor; text-decoration-thickness: 1px; }
.gh-content blockquote:not([class]) { border-left: 3px solid var(--accent); margin-left: 0; padding-left: 1.1em; font-style: italic; }
.gh-content blockquote.kg-blockquote-alt { font-size: 1.4em; font-style: italic; text-align: center; color: var(--muted); margin: 1.6em 0; }
.gh-content hr { border: 0; height: 1px; background: var(--faint); margin: 2.4em 0; }
.gh-content pre { font: 15px/1.55 var(--mono); background: var(--surface); padding: 16px 20px; border-radius: 6px; overflow-x: auto; }
.gh-content :not(pre) > code { font: 0.85em var(--mono); background: var(--surface); padding: 2px 5px; border-radius: 4px; }
.gh-content ul, .gh-content ol { padding-left: 1.3em; }
.gh-content li + li { margin-top: 0.4em; }
.gh-content figure { margin-left: 0; margin-right: 0; }
.gh-content table { border-collapse: collapse; font: 15px var(--sans); width: 100%; }
.gh-content th, .gh-content td { border-bottom: 1px solid var(--faint); padding: 8px 10px; text-align: left; }
.gh-content .kg-callout-card { border-radius: 8px; }

/* Footer */
.site-footer { border-top: 1px solid var(--faint); padding: 28px 0; font-size: 14px; color: var(--muted); }
.footer-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; }
.footer-inner .nav { display: flex; flex-wrap: wrap; gap: 18px; list-style: none; margin: 0; padding: 0; }
.footer-inner a { text-decoration: none; }
.footer-inner > a:last-child { margin-left: auto; }

.error-page { padding-top: 120px; }

/* Responsive */
@media (max-width: 800px) {
    .split { grid-template-columns: 1fr; }
    .header-inner { gap: 16px; }
}
@media (max-width: 640px) {
    body { font-size: 16px; }
    .wrap, .wrap-text, .wrap-wide { padding: 0 16px; }
    .header-inner { height: auto; flex-wrap: wrap; padding: 14px 16px 0; gap: 10px 12px; }
    .site-title { flex: 1; }
    .site-nav { order: 3; flex-basis: 100%; padding-bottom: 12px; }
    .intro { padding-top: 48px; }
    .featured-link { padding: 22px 20px; }
    .post-row { grid-template-columns: 1fr; gap: 2px; }
    .post-row-tag { display: none; }
    .block { margin-top: 48px; }
    .gh-content { grid-template-columns: [full-start] 16px [wide-start main-start] minmax(0, 1fr) [main-end wide-end] 16px [full-end]; }
    body.font-serif .gh-content { font-size: 18px; }
}

/* ---------- Hero variants ---------- */
:root { --tok-a: var(--accent); --tok-b: #3f6f8f; --tok-c: #7a8a3a; }
:root[data-theme="dark"] { --tok-b: #7fb0d1; --tok-c: #b5c46a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --tok-b: #7fb0d1; --tok-c: #b5c46a; } }

.intro-portrait, .intro-tokens { max-width: none; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 56px; align-items: center; }
.intro-visual { position: relative; }
.intro-portrait .intro-visual { aspect-ratio: 4 / 5; width: 100%; max-width: 420px; justify-self: end; }
.intro-portrait .hero-photo { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; border-radius: 14px; }
.hero-photo { position: absolute; left: 0; bottom: 8%; width: 66%; margin: 0; aspect-ratio: 4 / 5; border-radius: 10px; overflow: hidden; box-shadow: 0 18px 40px -18px rgba(0,0,0,.35); background: var(--faint); }
.hero-photo img { width: 100%; height: 100%; object-fit: cover; }
.intro-tokens .intro-visual { aspect-ratio: 1 / 1; max-height: 460px; }
.intro-tokens .gen-field { position: absolute; inset: 0; border-radius: 14px; background: var(--surface); }
.intro-tokens .hero-photo { width: 44%; bottom: -5%; left: 5%; }

/* Generated fields */
.gen-field { display: block; overflow: hidden; }
.gen-field svg { display: block; }
.gen-field rect.t-n { fill: var(--text); opacity: .09; }
.gen-field rect.t-o { fill: none; stroke: var(--text); stroke-opacity: .28; stroke-width: 1; }
.gen-field rect.t-a { fill: var(--tok-a); opacity: .85; }
.gen-field rect.t-b { fill: var(--tok-b); opacity: .8; }
.gen-field rect.t-c { fill: var(--tok-c); opacity: .8; }
.gen-field.is-streaming rect { animation: tok-in .5s ease-out both; animation-delay: calc(var(--i) * 6ms); }
@keyframes tok-in { from { opacity: 0; transform: translateY(3px); } }
.gen-banner { height: 220px; border-radius: 8px; background: var(--surface); }

/* Tokenised intro line */
.intro-lede.is-tokenized { line-height: 1.75; }
.tok { border-radius: 4px; padding: 1px 0; box-decoration-break: clone; -webkit-box-decoration-break: clone; transition: background .2s; }
.tok-0 { background: color-mix(in srgb, var(--tok-a) 16%, transparent); }
.tok-1 { background: color-mix(in srgb, var(--tok-b) 16%, transparent); }
.tok-2 { background: color-mix(in srgb, var(--tok-c) 18%, transparent); }
.tok-3 { background: color-mix(in srgb, var(--text) 8%, transparent); }
.tok:hover { background: color-mix(in srgb, var(--tok-a) 40%, transparent); color: var(--text); }
.is-streaming .tok { animation: tok-in .35s ease-out both; animation-delay: calc(var(--i) * 45ms); }

/* Featured card with cover */
.featured-link { position: relative; }
.featured-cover { float: right; width: 34%; aspect-ratio: 16 / 10; margin: 0 0 12px 28px; border-radius: 8px; overflow: hidden; background: var(--bg); }
.featured-cover img { width: 100%; height: 100%; object-fit: cover; }
.featured-link::after { content: ""; display: block; clear: both; }

@media (max-width: 800px) {
    .intro-portrait, .intro-tokens { grid-template-columns: 1fr; gap: 36px; }
    .intro-portrait .intro-visual { justify-self: start; }
    .intro-tokens .intro-visual { aspect-ratio: 16 / 9; }
    .featured-cover { float: none; display: block; width: 100%; margin: 0 0 18px; }
}
@media (prefers-reduced-motion: reduce) { .gen-field rect, .tok { animation: none !important; } }

/* ---------- Diffusion photo reveal ---------- */
.hero-photo img { position: absolute; inset: 0; }
.hero-photo img + img { display: none; }
.hero-photo.is-diffusing img { visibility: hidden; }
.hero-photo canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hero-dots { position: absolute; left: 0; right: 0; bottom: 12px; display: flex; justify-content: center; gap: 6px; }
.hero-dots button { width: 7px; height: 7px; padding: 0; border: 0; border-radius: 50%; background: rgba(255,255,255,.55); cursor: pointer; transition: width .25s, background .25s; }
.hero-dots button.is-on { width: 20px; border-radius: 4px; background: #fff; }

/* ---------- Banner hero (landscape photos) ---------- */
.intro-banner { max-width: none; display: flex; flex-direction: column; padding-top: 32px; }
.intro-banner .intro-visual { order: -1; position: relative; width: 100%; aspect-ratio: 21 / 9; max-height: 560px; }
.intro-banner .hero-photo { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; border-radius: 14px; box-shadow: none; }
.intro-banner .intro-text { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); column-gap: 56px; align-items: end; margin-top: 44px; }
.intro-banner .intro-title { grid-column: 1; }
.intro-banner .intro-lede { grid-column: 1; }
.intro-banner .signup { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; align-self: end; }
@media (max-width: 800px) {
    .intro-banner { padding-top: 16px; }
    .intro-banner .intro-visual { aspect-ratio: 3 / 2; }
    .intro-banner .intro-text { grid-template-columns: 1fr; margin-top: 28px; }
    .intro-banner .signup { grid-column: 1; grid-row: auto; margin-top: 28px; }
}
