/* ── PHP Mini CMS — Public Theme ──────────────────────────────────────────── */

/* ── Inter — self-hosted web font (rsms.me/inter, OFL license) ────────────── */

@font-face {
    font-family: 'Inter';
    src: url('/fonts/Inter-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style:  normal;
    font-display: swap;
}

@font-face {
    font-family: 'Inter';
    src: url('/fonts/Inter-Italic.woff2') format('woff2');
    font-weight: 400;
    font-style:  italic;
    font-display: swap;
}

@font-face {
    font-family: 'Inter';
    src: url('/fonts/Inter-SemiBold.woff2') format('woff2');
    font-weight: 600;
    font-style:  normal;
    font-display: swap;
}

@font-face {
    font-family: 'Inter';
    src: url('/fonts/Inter-SemiBoldItalic.woff2') format('woff2');
    font-weight: 600;
    font-style:  italic;
    font-display: swap;
}

@font-face {
    font-family: 'Inter';
    src: url('/fonts/Inter-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style:  normal;
    font-display: swap;
}

@font-face {
    font-family: 'Inter';
    src: url('/fonts/Inter-BoldItalic.woff2') format('woff2');
    font-weight: 700;
    font-style:  italic;
    font-display: swap;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-text:    #1a1a1a;
    --color-muted:   #6b7280;
    --color-border:  #e5e7eb;
    --color-bg:      #ffffff;
    --color-code-bg: #f3f4f6;
    --color-link:    #2563eb;
    --max-content:   700px;
    --max-wide:      900px;
}

/* ── Dark mode tokens ──────────────────────────────────────────────────────── */
/* Applied when the system prefers dark AND the user hasn't manually forced light */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-text:    #e5e7eb;
        --color-muted:   #9ca3af;
        --color-border:  #374151;
        --color-bg:      #181818;
        --color-code-bg: #2a2a2a;
        --color-link:    #60a5fa;
    }
}

/* Applied when the user has manually toggled dark mode */
[data-theme="dark"] {
    --color-text:    #e5e7eb;
    --color-muted:   #9ca3af;
    --color-border:  #374151;
    --color-bg:      #181818;
    --color-code-bg: #2a2a2a;
    --color-link:    #60a5fa;
}

html { font-size: 17px; scroll-behavior: smooth; }


body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.75;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--color-link);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

a:hover { text-decoration-thickness: 2px; }

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

audio { width: 100%; }

/* ── Site header ──────────────────────────────────────────────────────────── */
.site-header {
    border-bottom: 1px solid var(--color-border);
    padding: 1.1rem 1.5rem;
}

.site-header__inner {
    max-width: var(--max-wide);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.site-header__title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
}

.site-header__title:hover { color: var(--color-link); }

.site-nav {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.site-nav a {
    color: var(--color-muted);
    text-decoration: none;
    font-size: .95rem;
    transition: color .15s;
}

.site-nav a:hover { color: var(--color-text); text-decoration: none; }

/* Right-hand side of header: nav + theme toggle grouped together */
.site-header__right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-muted);
    display: flex;
    align-items: center;
    padding: .25rem;
    border-radius: 4px;
    transition: color .15s;
    flex-shrink: 0;
    line-height: 0;
}

.theme-toggle:hover { color: var(--color-text); }
.theme-toggle svg   { width: 1.1rem; height: 1.1rem; }

/* ── Main content area ────────────────────────────────────────────────────── */
.site-main {
    max-width: var(--max-content);
    margin: 3rem auto;
    padding: 0 1.5rem;
}

.site-main--wide {
    max-width: var(--max-wide);
}

/* ── Post / page ──────────────────────────────────────────────────────────── */
.post__header,
.post__content {
    margin-bottom: 2rem;
}

.post__title {
    font-size: 1.65rem;
    line-height: 1.1;
    margin-bottom: .1rem;
}

.post__date {
    display: block;
    font-size: .875rem;
    color: var(--color-muted);
}

/* ── Prose styles ─────────────────────────────────────────────────────────── */
.prose > * + * { margin-top: 1.25em; }

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
    line-height: 1.25;
    margin-top: 2em;
    margin-bottom: .5em;
}

.prose h1 { font-size: 1.75rem; }
.prose h2 { font-size: 1.4rem; }
.prose h3 { font-size: 1.15rem; }
.prose h4, .prose h5, .prose h6 { font-size: 1rem; }

.prose p { margin-top: 1em; }

.prose ul,
.prose ol {
    padding-left: 1.5em;
    margin-top: 1em;
}

.prose li + li { margin-top: .4em; }

.prose blockquote {
    border-left: 3px solid var(--color-border);
    padding-left: 1em;
    color: var(--color-muted);
    font-style: italic;
}

.prose hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 2.5em 0;
}

.prose strong { font-weight: 600; }
.prose em     { font-style: italic; }

.prose table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9em;
    margin-top: 1em;
}

.prose th,
.prose td {
    padding: .5em .75em;
    border: 1px solid var(--color-border);
    text-align: left;
}

.prose th { background: var(--color-code-bg); font-weight: 600; }

/* Code */
.prose code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: .875em;
    background: var(--color-code-bg);
    border-radius: 3px;
    padding: .1em .3em;
}

.prose pre {
    background: var(--color-code-bg);
    border-radius: 6px;
    padding: 1.5em;
    overflow-x: auto;
    line-height: 1.5;
}

/* Wrapper injected by JS — provides the positioning context for the copy
   button so it stays anchored to the visible corner even when the <pre>
   scrolls horizontally. */
.code-block {
    position: relative;
}

.code-copy {
    position: absolute;
    top: .5rem;
    right: .5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--color-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s, color .15s, border-color .15s;
}

.code-block:hover .code-copy { opacity: 1; }

.code-copy:hover {
    color: var(--color-text);
    border-color: var(--color-border);
    background: var(--color-bg);
}

.code-copy--copied { color: #16a34a; opacity: 1; }

.code-copy svg { width: .8rem; height: .8rem; }

.prose pre code {
    background: none;
    padding: 0;
    font-size: .85em;
}

/* ── Syntax highlighting — xcode-dark theme ───────────────────────────────── */

.prose pre.syntax-hl {
    background: #1c1c1e;
    color:      #dfdfe0;
}

/* In dark mode the page bg is #181818 — bump the code block to be clearly distinct */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .prose pre.syntax-hl { background: #2c2c2e; }
}
[data-theme="dark"] .prose pre.syntax-hl { background: #2c2c2e; }

/* Copy button adjustments for dark code blocks */
.code-block--dark .code-copy          { color: #6c7986; }
.code-block--dark .code-copy:hover    { color: #dfdfe0; border-color: #3a3a3c; background: #2c2c2e; }

/* Token colours */
.hljs-comment,
.hljs-quote                    { color: #6c7986; font-style: italic; }

.hljs-keyword,
.hljs-selector-tag,
.hljs-operator                 { color: #ff7ab2; }

.hljs-string,
.hljs-attr,
.hljs-selector-attr            { color: #ff8170; }

.hljs-number,
.hljs-literal                  { color: #d9c97c; }

.hljs-built_in,
.hljs-title,
.hljs-title.function_          { color: #4eb0cc; }

.hljs-type,
.hljs-class .hljs-title,
.hljs-variable                 { color: #dabaff; }

.hljs-meta,
.hljs-params                   { color: #dfdfe0; }

.hljs-addition                 { color: #63da58; background: #1a3320; }
.hljs-deletion                 { color: #ff8170; background: #3d1a18; }

/* Images / media inside prose */
.prose img,
.prose video,
.prose audio { margin-top: 1.5em; }

.prose figure { margin-top: 1.5em; }
.prose figcaption {
    font-size: .8rem;
    color: var(--color-muted);
    margin-top: .4em;
    text-align: center;
}

/* ── Post list / index ────────────────────────────────────────────────────── */
.post-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    align-items: stretch;
}

.post-card {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
    transition: box-shadow .15s, border-color .15s;
}

.post-card:hover {
    border-color: #d1d5db;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.post-card__title {
    font-size: 1.25rem;
    line-height: 1.2;
}

.post-card__title a {
    color: var(--color-text);
    text-decoration: none;
}

.post-card__title a:hover { color: var(--color-link); }

.post-card__date {
    display: block;
    font-size: .8rem;
    color: var(--color-muted);
}

.post-card__excerpt {
    color: var(--color-muted);
    font-size: .9rem;
    flex: 1;
}

.post-card__more {
    font-size: .875rem;
    font-weight: 500;
    margin-top: auto;
    padding-top: .75rem;
}

.post-list__empty {
    color: var(--color-muted);
    font-style: italic;
    grid-column: 1 / -1;
}

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
    font-size: .9rem;
}

.pagination__info { color: var(--color-muted); }

.pagination__prev--disabled,
.pagination__next--disabled {
    color: var(--color-border);
    cursor: default;
    text-decoration: none;
}

/* ── Footnotes ────────────────────────────────────────────────────────────── */
.footnotes {
    font-size: .85rem;
    color: var(--color-muted);
}

.footnotes ol { padding-left: 1.5em; }
.footnotes li + li { margin-top: .4em; }
.footnotes p { margin-top: 0; }

.footnote-ref {
    font-size: .75em;
    vertical-align: super;
    line-height: 0;
    text-decoration: none;
    font-weight: 600;
}

.footnote-backref {
    text-decoration: none;
    margin-left: .25em;
}

/* ── Post navigation (prev / next) ────────────────────────────────────────── */
.post-nav {
    display: flex;
    gap: 2rem;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

.post-nav__prev { max-width: 45%; }

.post-nav__next {
    max-width: 45%;
    margin-left: auto;
}

.post-nav__link {
    display: flex;
    align-items: flex-start;
    gap: 0.4em;
    font-size: .95rem;
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
    line-height: 1.3;
}

.post-nav__next .post-nav__link { justify-content: flex-end; }
.post-nav__next .post-nav__link span:first-child { text-align: right; }

.post-nav__arrow { flex-shrink: 0; }

.post-nav__link:hover { color: var(--color-link); }

@media (max-width: 600px) {
    .post-nav { flex-direction: column; gap: 1rem; }
    .post-nav__prev,
    .post-nav__next { max-width: 100%; margin-left: 0; text-align: left; }
}

/* ── Site footer ──────────────────────────────────────────────────────────── */
.site-footer {
    border-top: 1px solid var(--color-border);
    padding: 1.5rem;
    margin-top: 4rem;
    font-size: .85rem;
    color: var(--color-muted);
}

.site-footer__inner {
    max-width: var(--max-wide);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-footer__links {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.site-footer__feed {
    display: flex;
    align-items: center;
    color: var(--color-muted);
    text-decoration: none;
}
.site-footer__feed:hover { color: #f26522; }
.site-footer__feed svg  { width: 1rem; height: 1rem; }

.site-footer__mastodon {
    display: flex;
    align-items: center;
    color: var(--color-muted);
    text-decoration: none;
}
.site-footer__mastodon:hover { color: #6364ff; }
.site-footer__mastodon svg  { width: 1rem; height: 1rem; }

/* ── Lightbox ─────────────────────────────────────────────────────────────── */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,.85);
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    cursor: zoom-out;
}

.lightbox.is-open { display: flex; }

.lightbox__img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 3px;
    cursor: default;
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
}

.lightbox__close {
    position: fixed;
    top: 1rem;
    right: 1.25rem;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    opacity: .8;
    padding: .25rem .5rem;
}

.lightbox__close:hover { opacity: 1; }

.prose img { cursor: zoom-in; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .post-list { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    html { font-size: 16px; }
    .post__title { font-size: 1.5rem; }
    .post-card__title { font-size: 1.1rem; }
    .site-header { padding: .9rem 1rem; }
    .site-main { margin: 2rem auto; }
}
