/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow-y: scroll;
}

/* -------------------------------------------------------------------------
   Theme palette
   -------------------------------------------------------------------------
   Default = light, after the Ghost theme the site used before: white page,
   dark gray text and a pink accent. The dark palette kicks in either when
   the OS prefers dark mode (@media prefers-color-scheme), or when the user
   manually toggles the in-page <input id="theme-toggle"> (see further
   below). Both rules write to the same CSS custom properties, so every
   rule that references var(--color-*) updates automatically.
   ------------------------------------------------------------------------- */
:root {
    --color-background: #ffffff;
    --color-text: #333333;
    --color-heading: #15171a;
    --color-text-light: #767676;
    --color-border: #e6e6e6;
    --color-surface: #f6f6f6;
    --color-surface-strong: #e6e6e6;
    --color-accent: #ff1a75;
    --color-link: #d1135f;
    --color-link-hover: #15171a;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: "SF Mono", "Fira Code", Menlo, Consolas, "Courier New", monospace;
}

/* Dark — applied when the OS prefers dark mode. */
@media (prefers-color-scheme: dark) {
    :root {
        --color-background: #282c35;
        --color-text: #e2e2e2;
        --color-heading: #ffffff;
        --color-text-light: #9b9b9b;
        --color-border: #3b3e46;
        --color-surface: #2f333c;
        --color-surface-strong: #3b3e46;
        --color-accent: #ff4d94;
        --color-link: #ff6ba6;
        --color-link-hover: #ffffff;
    }
}

/* Manual override: flip to the OPPOSITE of the current system preference.
   Two selectors so both code paths work:
     - html.theme-toggled  → set by a small inline script that mirrors the
       checkbox to localStorage so the choice persists across pages.
     - body:has(#theme-toggle:checked) → pure-CSS fallback when JS is
       disabled (Chromium 105+, Firefox 121+, Safari 15.4+). No
       persistence, but the toggle still works on the current page. */
html.theme-toggled,
body:has(#theme-toggle:checked) {
    --color-background: #282c35;
    --color-text: #e2e2e2;
    --color-heading: #ffffff;
    --color-text-light: #9b9b9b;
    --color-border: #3b3e46;
    --color-surface: #2f333c;
    --color-surface-strong: #3b3e46;
    --color-accent: #ff4d94;
    --color-link: #ff6ba6;
    --color-link-hover: #ffffff;
}

@media (prefers-color-scheme: dark) {
    html.theme-toggled,
    body:has(#theme-toggle:checked) {
        --color-background: #ffffff;
        --color-text: #333333;
        --color-heading: #15171a;
        --color-text-light: #767676;
        --color-border: #e6e6e6;
        --color-surface: #f6f6f6;
        --color-surface-strong: #e6e6e6;
        --color-accent: #ff1a75;
        --color-link: #d1135f;
        --color-link-hover: #15171a;
    }
}

/* html carries the page background so the toggled palette (set on html by
   the script) paints the whole viewport, not just the body box. */
html.theme-toggled {
    background: var(--color-background);
}

/* Theme toggle widget — checkbox is visually hidden but remains focusable.
   The label in the nav shows a sun or moon depending on the current
   effective theme. Clicking the label toggles the checkbox. */
#theme-toggle {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.theme-toggle {
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    user-select: none;
}

/* Light mode default: show moon (click to go dark). */
.theme-toggle::before { content: "🌙"; }

/* OS dark: show sun (click to go light). */
@media (prefers-color-scheme: dark) {
    .theme-toggle::before { content: "🌞"; }
}

/* When toggled on, flip the icon to match the new effective theme.
   Same two-selector pattern as the palette overrides above. */
html.theme-toggled .theme-toggle::before,
body:has(#theme-toggle:checked) .theme-toggle::before { content: "🌞"; }
@media (prefers-color-scheme: dark) {
    html.theme-toggled .theme-toggle::before,
    body:has(#theme-toggle:checked) .theme-toggle::before { content: "🌙"; }
}

/* Keyboard focus ring on the label when the hidden checkbox is focused. */
#theme-toggle:focus-visible + .theme-toggle {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
    border-radius: 4px;
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

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

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 36px;
}

/* Header */
.site-header {
    padding: 32px 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.site-logo {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--color-heading);
    white-space: nowrap;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 28px;
}

.main-nav a {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-heading);
    transition: color 0.2s ease;
}

.main-nav a:hover,
.site-logo:hover {
    color: var(--color-accent);
}

/* Main Content */
.site-main {
    flex: 1;
    padding-bottom: 40px;
}

/* Home page cover line */
.cover-description {
    font-size: 17px;
    color: var(--color-text-light);
    margin: 16px 0 48px;
}

/* Post feed — one compact row per post: date, title, read time. */
.feed-item {
    border-bottom: 1px solid var(--color-border);
}

.feed-item:last-child {
    border-bottom: none;
}

.feed-link {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 0;
    color: var(--color-text);
}

.feed-date {
    display: flex;
    gap: 4px;
    min-width: 96px;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
    color: var(--color-accent);
}

.feed-month {
    text-transform: uppercase;
}

.feed-year {
    color: var(--color-text-light);
    font-weight: 600;
}

.feed-title {
    flex-grow: 1;
    font-size: 17px;
    font-weight: 400;
    line-height: 1.3;
    color: var(--color-heading);
}

.feed-link:hover .feed-title {
    color: var(--color-accent);
}

.feed-length {
    font-size: 14px;
    color: var(--color-text-light);
    white-space: nowrap;
}

.feed-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: var(--color-text-light);
    transition: transform 0.2s ease, color 0.2s ease;
}

.feed-link:hover .feed-icon {
    color: var(--color-accent);
    transform: translateX(3px);
}

.archive-link {
    margin-top: 40px;
    font-size: 15px;
}

.archive-link a {
    color: var(--color-text-light);
}

.archive-link a:hover {
    color: var(--color-accent);
}

/* Page Title (tags, authors, archive, 404, about) */
.page-title {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--color-heading);
    margin: 16px 0 40px;
}

/* Individual Post */
.post-header {
    max-width: 920px;
    margin: 24px auto 48px;
    text-align: center;
}

.post-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 16px;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--color-text-light);
    margin-bottom: 12px;
}

.post-header .post-title {
    font-size: 40px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--color-heading);
    word-break: break-word;
}

.post-tags {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}

.tag {
    display: inline-block;
    padding: 4px 12px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.tag:hover {
    background: var(--color-accent);
    color: #ffffff;
}

.post-archive-notice {
    max-width: 720px;
    margin: 0 auto 40px;
    padding: 16px 0;
    text-align: center;
    font-style: italic;
    color: var(--color-text-light);
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}

/* Post body: a 720px reading column. */
.post-content {
    max-width: 720px;
    margin: 0 auto;
    font-size: 18px;
    line-height: 1.7;
    word-break: break-word;
}

.post-content > * + * {
    margin-top: 28px;
}

.post-content h2,
.post-content h3,
.post-content h4 {
    color: var(--color-heading);
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.post-content > h2,
.post-content > h3,
.post-content > h4 {
    margin-top: 48px;
}

.post-content h2 { font-size: 28px; font-weight: 800; }
.post-content h3 { font-size: 24px; font-weight: 700; }
.post-content h4 { font-size: 20px; font-weight: 700; }

.post-content a {
    color: var(--color-link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

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

.post-content ul,
.post-content ol {
    padding-left: 28px;
}

.post-content li + li {
    margin-top: 8px;
}

.post-content blockquote {
    border-left: 3px solid var(--color-accent);
    padding-left: 20px;
    font-style: italic;
}

.post-content code {
    background: var(--color-surface);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.85em;
}

.post-content pre {
    background: var(--color-surface);
    padding: 20px;
    border-radius: 5px;
    overflow-x: auto;
    line-height: 1.4;
}

.post-content pre code {
    background: none;
    padding: 0;
}

.post-content hr {
    border: 0;
    border-top: 1px solid var(--color-border);
}

/* Figures: images with captions. */
.post-content figure {
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

.post-content > figure,
.post-content > img {
    margin-top: 40px;
    margin-bottom: 40px;
}

.post-content img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}

.post-content figcaption {
    margin-top: 12px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text-light);
}

/* Feature image: wider than the reading column, as in the old theme. */
.post-content > .feature-image {
    width: min(920px, 100vw - 72px);
    margin: 0 0 48px 50%;
    transform: translateX(-50%);
}

.post-content > .feature-image img {
    width: 100%;
}

/* Callout */
.callout {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    background: var(--color-surface);
    border-radius: 6px;
    font-size: 17px;
    line-height: 1.6;
}

.callout-emoji {
    flex-shrink: 0;
    line-height: 1.6;
}

/* Bookmark card: a link to an external page with its title, description
   and thumbnail. */
.bookmark-container {
    display: flex;
    min-height: 148px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    overflow: hidden;
    text-align: left;
    color: var(--color-text);
    text-decoration: none !important;
    transition: border-color 0.2s ease;
}

.post-content .bookmark-container {
    color: var(--color-text);
}

.bookmark-container:hover {
    border-color: var(--color-accent);
}

.bookmark-content {
    flex-grow: 1;
    min-width: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.bookmark-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--color-heading);
}

.bookmark-description {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text-light);
}

.bookmark-metadata {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
}

.post-content .bookmark-icon {
    width: 20px;
    height: 20px;
    margin: 0 8px 0 0;
}

.bookmark-publisher::before {
    content: "•";
    margin: 0 6px;
}

.bookmark-thumbnail {
    position: relative;
    flex: 0 0 33%;
    max-height: 100%;
}

.post-content .bookmark-thumbnail img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Embedded tweet, shown as a plain quote card. */
.embed .tweet {
    max-width: 550px;
    margin: 0 auto;
    padding: 20px 24px;
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-accent);
    border-radius: 6px;
    text-align: left;
    font-style: normal;
    font-size: 16px;
}

.embed .tweet p {
    margin-bottom: 8px;
    font-size: 17px;
}

/* Tags Cloud */
.tags-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.tag-cloud-item {
    display: inline-block;
    padding: 8px 16px;
    background: var(--color-surface);
    border-radius: 5px;
    transition: all 0.2s ease;
}

.tag-cloud-item:hover {
    background: var(--color-accent);
    color: #ffffff;
}

.tag-count {
    color: var(--color-text-light);
    font-size: 14px;
}

.tag-cloud-item:hover .tag-count {
    color: inherit;
}

/* Plain pages (about, 404): same reading column as posts. */
.page-content {
    max-width: 720px;
    margin: 0 auto;
}

.page-content .page-title {
    text-align: center;
}

/* Footer */
.site-footer {
    padding: 56px 0;
    color: var(--color-text-light);
    font-size: 14px;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.footer-nav {
    display: flex;
    gap: 20px;
}

.footer-nav a {
    color: var(--color-text-light);
}

.footer-nav a:hover {
    color: var(--color-accent);
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 20px;
    }

    .site-header {
        padding: 20px 0;
    }

    .header-content {
        flex-direction: column;
        gap: 12px;
    }

    .main-nav {
        gap: 20px;
    }

    .cover-description {
        margin-bottom: 24px;
    }

    .feed-link {
        flex-wrap: wrap;
        gap: 6px 12px;
    }

    .feed-date {
        min-width: 0;
        width: 100%;
    }

    .feed-title {
        flex-basis: calc(100% - 30px);
    }

    .feed-length {
        order: 3;
    }

    .feed-icon {
        display: none;
    }

    .post-header .post-title {
        font-size: 30px;
    }

    .page-title {
        font-size: 28px;
    }

    .post-content {
        font-size: 17px;
    }

    .post-content h2 { font-size: 24px; }
    .post-content h3 { font-size: 21px; }

    .post-content > .feature-image {
        width: calc(100vw - 40px);
    }

    .bookmark-container {
        flex-direction: column-reverse;
    }

    .bookmark-thumbnail {
        flex-basis: auto;
        height: 160px;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: #000;
    }

    .site-header,
    .site-footer,
    .post-footer,
    .tag {
        display: none;
    }

    .post-content a {
        color: #0066cc;
    }

    .post-content pre {
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }
}

/* Post footer: author and Markdown copy. */
.post-footer {
    max-width: 720px;
    margin: 56px auto 0;
    padding-top: 24px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 14px;
    color: var(--color-text-light);
}

.post-footer a {
    color: var(--color-heading);
    font-weight: 600;
}

.post-footer a:hover {
    color: var(--color-accent);
}
