/* ==========================================================================
   cmatskas theme, hand-written, no framework.
   Accent: emerald. Change --a-l (light) and --a-d (dark) to re-colour the site.
   ========================================================================== */

/* ---- Fonts (self-hosted, variable) ------------------------------------- */
@font-face { font-family: "Inter"; src: url("../fonts/inter-var.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("../fonts/source-serif-4-var.woff2") format("woff2"); font-weight: 200 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("../fonts/source-serif-4-var-italic.woff2") format("woff2"); font-weight: 200 900; font-style: italic; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("../fonts/jetbrains-mono-var.woff2") format("woff2"); font-weight: 100 800; font-style: normal; font-display: swap; }

/* ---- Design tokens ------------------------------------------------------ */
:root {
    --a-l: #0B7A5A;          /* emerald, light mode (5.0:1 on --bg) */
    --a-d: #2DD4A7;          /* emerald, dark mode (10:1 on --bg) */
    --accent: var(--a-l);
    --accent-soft: color-mix(in srgb, var(--accent) 11%, transparent);
    --bg: #FAF8F5;
    --card: #fff;
    --ink: #14151A;
    --muted: #5d6270;
    --line: #e6e1d8;
    --code-bg: #0f1420;
    --code-ink: #e6eaf2;
    --on-accent: #fff;
    /* Ghost's optional custom-font setting overrides these when an admin picks one */
    --sans: var(--gh-font-heading, "Inter"), system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --serif: var(--gh-font-body, "Source Serif 4"), Georgia, "Times New Roman", serif;
    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light;
}
:root[data-theme="dark"] {
    --accent: var(--a-d);
    --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
    --bg: #0D1117; --card: #151B23; --ink: #E6EAF2; --muted: #9aa4b2; --line: #252d38;
    --code-bg: #0a0e14;
    --on-accent: #0D1117;
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --accent: var(--a-d);
        --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
        --bg: #0D1117; --card: #151B23; --ink: #E6EAF2; --muted: #9aa4b2; --line: #252d38;
        --code-bg: #0a0e14;
        --on-accent: #0D1117;
        color-scheme: dark;
    }
}

/* ---- Base --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 24px; }
body { background: var(--bg); color: var(--ink); font: 17px/1.6 var(--sans); -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; }
img, svg, video { max-width: 100%; height: auto; }
a { color: inherit; }
ul, ol { padding: 0; }
button { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; background: var(--accent); color: var(--on-accent); padding: 8px 12px; z-index: 99; border-radius: 6px; }
.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 24px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---- Header ------------------------------------------------------------- */
.site-header { display: flex; align-items: center; justify-content: space-between; padding-top: 22px; padding-bottom: 22px; gap: 16px; }
.mark { font: 600 18px var(--mono); text-decoration: none; }
.mark i { color: var(--accent); font-style: normal; animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.main-nav { display: flex; align-items: center; gap: 8px; position: relative; }
.nav-menu { display: flex; align-items: center; gap: 24px; margin-right: 10px; }
.nav { list-style: none; display: flex; gap: 24px; }
.nav a, .nav-subscribe { text-decoration: none; color: var(--muted); font-size: 15px; }
.nav a:hover, .nav-subscribe:hover, .nav .nav-current a { color: var(--accent); }
.icon-btn { background: none; border: 1px solid var(--line); width: 38px; height: 38px; border-radius: 999px; cursor: pointer; display: grid; place-items: center; color: var(--ink); }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.nav-toggle { display: none; }

/* ---- Shared bits -------------------------------------------------------- */
.meta { font: 13px var(--mono); color: var(--muted); }
.kicker { font: 600 12px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.sec { font: 600 13px var(--mono); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 8px 0 18px; }
.lead { font-size: 20px; color: var(--muted); max-width: 34em; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.pill { display: inline-block; font: 600 12px var(--mono); color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 3px 9px; text-decoration: none; }
.pill:hover { text-decoration: underline; }
.social { display: flex; gap: 10px; list-style: none; }
.social a { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); transition: .15s; }
.social a:hover { color: var(--accent); border-color: var(--accent); }
.social svg { width: 17px; height: 17px; fill: currentColor; }
.btn { font: 600 15px var(--sans); background: var(--accent); color: var(--on-accent); border: 0; border-radius: 10px; padding: 11px 20px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--accent); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
kbd { font: 12px var(--mono); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; }

/* ---- Home --------------------------------------------------------------- */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 40px; align-items: center; padding: 56px 0 28px; }
.hero h1 { font: 700 clamp(38px, 6vw, 60px)/1.05 var(--sans); letter-spacing: -.03em; margin-bottom: 16px; }
.hero .lead { margin-bottom: 22px; }
.avatar { width: 160px; height: 160px; border-radius: 50%; padding: 4px; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 35%, #fff)); }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; object-position: 50% 25%; display: block; border: 4px solid var(--bg); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0 36px; }
.chip { font: 500 13px var(--mono); border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 13px; text-decoration: none; }
.chip b { color: var(--accent); font-weight: 600; margin-left: 6px; }
.chip:hover { border-color: var(--accent); }
.chip-all { color: var(--accent); background: transparent; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.card { border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 10px; transition: .18s; overflow: hidden; }
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 10px 30px -14px color-mix(in srgb, var(--accent) 55%, transparent); }
.card h3 { font: 650 21px/1.28 var(--sans); letter-spacing: -.015em; }
.card h3 a, .featured h3 a { text-decoration: none; }
.card h3 a:hover, .featured h3 a:hover { color: var(--accent); }
.card p { color: var(--muted); font-size: 15.5px; }
.card .meta { margin-top: auto; padding-top: 8px; }
.card-img { margin: -24px -24px 6px; display: block; }
.card-img img { display: block; width: 100%; aspect-ratio: 21/9; object-fit: cover; }
.featured { grid-column: 1 / -1; display: grid; grid-template-columns: 1.1fr 1fr; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: var(--card); }
.featured .art { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 30%, #05060c), var(--accent) 62%, color-mix(in srgb, var(--accent) 45%, #fff)); min-height: 260px; display: grid; place-items: center; color: #fff; font: 600 15px var(--mono); padding: 24px; text-decoration: none; }
.featured .art pre { font: inherit; white-space: pre-wrap; opacity: .95; }
.featured .art-img { padding: 0; background: var(--line); }
.featured .art-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.featured .txt { padding: 32px; display: flex; flex-direction: column; gap: 10px; }
.featured h3 { font: 700 28px/1.2 var(--sans); letter-spacing: -.02em; }
.featured p { color: var(--muted); }
.featured .meta { margin-top: auto; }
.more { margin: 28px 0 0; text-align: center; }
.more a { color: var(--accent); font-weight: 600; text-decoration: none; }
.more a:hover { text-decoration: underline; }
.pager { display: flex; justify-content: space-between; align-items: center; margin: 32px 0 0; font: 14px var(--mono); }
.pager a { color: var(--accent); text-decoration: none; font-weight: 600; }
.pager-info { color: var(--muted); }

/* ---- Subscribe ---------------------------------------------------------- */
.sub { margin: 64px 0 0; padding: 40px; border-radius: 20px; background: linear-gradient(135deg, var(--accent-soft), transparent); border: 1px solid var(--line); display: flex; gap: 28px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.sub h3 { font: 700 24px var(--sans); letter-spacing: -.02em; }
.sub p { color: var(--muted); }
.sub form { display: flex; gap: 8px; flex-wrap: wrap; position: relative; }
.sub input { font: inherit; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); min-width: 230px; }
.sub .loading, .sub .success { display: none; }
.sub form.loading .idle, .sub form.success .idle { display: none; }
.sub form.loading .loading, .sub form.success .success { display: inline; }
.form-msg { font-size: 14px; width: 100%; }
.form-msg.error { color: #c2410c; }

/* ---- Footer ------------------------------------------------------------- */
.site-footer { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; padding-top: 40px; padding-bottom: 56px; color: var(--muted); font-size: 14px; margin-top: 24px; }

/* ---- Archive / topics / error ------------------------------------------ */
.archive-head { padding: 56px 0 28px; }
.archive-head h1 { font: 700 clamp(32px, 5vw, 46px)/1.1 var(--sans); letter-spacing: -.03em; margin: 8px 0 12px; }
.author-head { display: flex; gap: 24px; align-items: center; }
.author-img { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; }
.archive-list { list-style: none; max-width: 780px; }
.archive-list li { display: grid; grid-template-columns: 112px 1fr auto; gap: 16px; align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--line); }
.archive-list time { font: 13px var(--mono); color: var(--muted); }
.archive-list a:not(.pill) { text-decoration: none; font-weight: 500; }
.archive-list a:not(.pill):hover { color: var(--accent); }
.archive-year { display: block !important; font: 700 28px var(--sans); letter-spacing: -.02em; color: var(--accent); padding: 36px 0 6px !important; border-bottom: 2px solid var(--line) !important; }
.topic-grid { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.topic { min-width: 0; display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; min-height: 96px; padding: 18px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); text-decoration: none; transition: .18s; }
.topic:hover { transform: translateY(-3px); border-color: var(--accent); }
.topic b { font: 650 19px var(--sans); overflow-wrap: anywhere; }
.topic span { font: 13px var(--mono); color: var(--muted); white-space: nowrap; }
.error-page { padding-top: 72px; padding-bottom: 24px; }
.error-page h1 { font: 700 clamp(32px, 5vw, 48px)/1.1 var(--sans); letter-spacing: -.03em; margin: 8px 0 18px; }
.error-page .lead, .error-page .actions { margin-bottom: 24px; }
.error-page .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.error-page .sec { margin-top: 40px; }
.term { background: var(--code-bg); color: var(--code-ink); font: 14.5px/1.7 var(--mono); padding: 18px 20px; border-radius: 14px; max-width: 520px; margin-bottom: 20px; }
.plain-list { list-style: none; } .plain-list li { padding: 8px 0; border-bottom: 1px solid var(--line); } .plain-list a { text-decoration: none; font-weight: 500; } .plain-list a:hover { color: var(--accent); }
.plain-list .meta { margin-left: 8px; }

/* ---- Post --------------------------------------------------------------- */
#progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--accent); z-index: 50; }
.post-head, .single .post-head { max-width: 760px; margin: 0 auto; padding: 48px 24px 8px; }
.post-head h1 { font: 700 clamp(32px, 5vw, 46px)/1.12 var(--sans); letter-spacing: -.03em; margin: 14px 0; }
.post-head .lead { margin-bottom: 14px; }
.byline { display: flex; align-items: center; flex-wrap: wrap; gap: 0 6px; }
.byline a { text-decoration: none; } .byline a:hover { color: var(--accent); }
.mini { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; object-position: 50% 25%; margin-right: 4px; }
.feature { max-width: 1000px; margin: 24px auto 0; padding: 0 24px; }
.feature img { width: 100%; border-radius: 16px; display: block; }
.feature figcaption { font-size: 14px; color: var(--muted); text-align: center; margin-top: 10px; }
.layout { display: block; max-width: 760px; margin: 0 auto; padding: 24px; }
.post[data-toc="true"].has-toc .layout { display: grid; grid-template-columns: 200px minmax(0, 700px); gap: 48px; max-width: 1000px; }
.toc { position: sticky; top: 24px; align-self: start; font-size: 14px; max-height: calc(100vh - 48px); overflow: auto; }
.toc[hidden] { display: none; }
.toc h4 { font: 600 12px var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: 10px; }
.toc a { display: block; padding: 6px 0 6px 12px; border-left: 2px solid var(--line); color: var(--muted); text-decoration: none; }
.toc a.sub-item { padding-left: 26px; font-size: 13px; }
.toc a:hover { color: var(--ink); }
.toc a.active { border-color: var(--accent); color: var(--ink); }
.prose { font: 19.5px/1.75 var(--serif); min-width: 0; overflow-wrap: break-word; }
.prose > * + * { margin-top: 1.3em; }
.prose h2, .prose h3, .prose h4 { font-family: var(--sans); letter-spacing: -.02em; line-height: 1.25; margin-top: 2em; }
.prose h2 { font-size: 27px; font-weight: 700; } .prose h3 { font-size: 22px; font-weight: 650; } .prose h4 { font-size: 18px; font-weight: 650; }
.prose h2 + *, .prose h3 + * { margin-top: .6em; }
.prose a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.prose a:hover { text-decoration-thickness: 2px; }
.prose ul, .prose ol { padding-left: 1.4em; } .prose li + li { margin-top: .4em; }
.prose code { font: .84em var(--mono); background: var(--accent-soft); padding: 2px 6px; border-radius: 5px; }
.prose blockquote { border-left: 3px solid var(--accent); padding: 4px 0 4px 20px; font-style: italic; font-size: 1.05em; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.prose img { border-radius: 10px; }
.prose figure { margin-left: 0; margin-right: 0; } .prose figcaption { font: 14px var(--sans); color: var(--muted); text-align: center; margin-top: 8px; }
.prose table { width: 100%; border-collapse: collapse; font: 15px/1.5 var(--sans); display: block; overflow-x: auto; }
.prose th, .prose td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.prose th { font-weight: 650; }
.prose iframe { max-width: 100%; border-radius: 10px; }

/* Code blocks (enhanced by main.js, with a sensible no-JS fallback) */
.prose pre { background: var(--code-bg); color: var(--code-ink); border-radius: 14px; border: 1px solid var(--line); padding: 18px; overflow: auto; font: 14.5px/1.65 var(--mono); }
.prose pre code { background: none; padding: 0; font: inherit; color: inherit; }
.code { border-radius: 14px; overflow: hidden; background: var(--code-bg); border: 1px solid var(--line); }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 9px 14px; background: rgba(255,255,255,.05); color: #9aa4b2; font: 12px var(--mono); }
.code-head button { background: rgba(255,255,255,.08); color: #d6dbe6; border: 0; border-radius: 6px; padding: 4px 10px; font: inherit; cursor: pointer; }
.code-head button:hover { background: rgba(255,255,255,.16); }
.code pre { border: 0; border-radius: 0; margin: 0; }
.hljs-comment, .hljs-quote { color: #7d8799; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag { color: #c792ea; }
.hljs-string, .hljs-regexp, .hljs-addition { color: #9ece6a; }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-variable, .hljs-template-variable { color: #ff9e64; }
.hljs-title, .hljs-section, .hljs-title.function_, .hljs-title.class_ { color: #7dcfff; }
.hljs-built_in, .hljs-type, .hljs-class .hljs-title { color: #e0af68; }
.hljs-attr, .hljs-attribute, .hljs-name, .hljs-tag { color: #7aa2f7; }
.hljs-meta, .hljs-deletion { color: #f7768e; }

/* Ghost editor cards */
.kg-width-wide { width: min(1000px, 94vw); position: relative; left: 50%; transform: translateX(-50%); }
.kg-width-full { width: 100vw; position: relative; left: 50%; transform: translateX(-50%); }
.kg-width-full img, .kg-width-wide img { width: 100%; border-radius: 0; }
.kg-image-card img, .kg-gallery-image img { display: block; margin: 0 auto; }
.kg-gallery-container { display: flex; flex-direction: column; gap: 8px; }
.kg-gallery-row { display: flex; gap: 8px; } .kg-gallery-image { flex: 1 1 0; } .kg-gallery-image img { width: 100%; height: 100%; object-fit: cover; }
.kg-bookmark-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); font-family: var(--sans); }
.kg-bookmark-container { display: flex; text-decoration: none; color: inherit; }
.kg-bookmark-content { padding: 16px 18px; flex: 1; min-width: 0; }
.kg-bookmark-title { font-weight: 650; } .kg-bookmark-description { font-size: 14px; color: var(--muted); margin-top: 4px; }
.kg-bookmark-metadata { font-size: 13px; color: var(--muted); margin-top: 10px; display: flex; align-items: center; gap: 6px; }
.kg-bookmark-icon { width: 18px; height: 18px; border-radius: 4px; }
.kg-bookmark-thumbnail { width: 30%; max-width: 220px; position: relative; } .kg-bookmark-thumbnail img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 0; }
.kg-callout-card { display: flex; gap: 12px; padding: 16px 20px; border-radius: 12px; background: var(--accent-soft); font-family: var(--sans); font-size: 16px; }
.kg-embed-card { display: flex; justify-content: center; }
.kg-video-card video { width: 100%; }
.kg-toggle-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; font-family: var(--sans); }

/* Post footer */
.post-foot { max-width: 1000px; margin: 24px auto 0; padding: 0 24px 24px; }
.author-card { display: flex; gap: 18px; align-items: center; padding: 24px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 40px; max-width: 700px; margin-left: auto; margin-right: auto; }
.author-card img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; object-position: 50% 25%; flex: none; }
.author-name { font-weight: 650; } .author-name a { text-decoration: none; } .author-name a:hover { color: var(--accent); }
.author-bio { color: var(--muted); font-size: 15px; }
.prev-next { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 40px; }
.prev-next a { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; text-decoration: none; background: var(--card); }
.prev-next a:hover { border-color: var(--accent); }
.prev-next small { font: 12px var(--mono); color: var(--muted); }
.prev-next .next { text-align: right; grid-column: 2; }
.prev-next .prev { grid-column: 1; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 820px) {
    .hero { grid-template-columns: 1fr; padding-top: 32px; } .avatar { display: none; }
    .featured { grid-template-columns: 1fr; } .grid { grid-template-columns: 1fr; }
    .post[data-toc="true"].has-toc .layout { display: block; } .toc { display: none; }
    .topic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .archive-list li { grid-template-columns: 1fr; gap: 2px; } .archive-list .pill { justify-self: start; }
    .nav-toggle { display: grid; }
    .nav-menu { display: none; position: absolute; top: 48px; right: 0; flex-direction: column; align-items: flex-start; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 20px; min-width: 180px; z-index: 40; margin: 0; }
    .nav-menu.open { display: flex; } .nav { flex-direction: column; gap: 12px; }
    .kg-bookmark-container { flex-direction: column; } .kg-bookmark-thumbnail { width: 100%; max-width: none; height: 160px; }
    .sub { padding: 28px; } .prev-next { grid-template-columns: 1fr; } .prev-next .next, .prev-next .prev { grid-column: 1; text-align: left; }
}
@media (max-width: 480px) { .topic-grid { grid-template-columns: 1fr; } .sub input { min-width: 0; width: 100%; } .sub form { width: 100%; } }
@media print { .site-header, .site-footer, .sub, .toc, #progress, .prev-next { display: none; } body { background: #fff; color: #000; } }
