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

html {
    overflow-y: scroll;
}

/* -------------------------------------------------------------------------
   Theme palette
   -------------------------------------------------------------------------
   Default = Gruvbox Light. 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 {
    /* Light theme — neutral whites/grays with Gruvbox-style accents. */
    --color-bg-dark: #f4f4f5;
    --color-bg-darker: #fafafa;
    --color-bg-light: #e4e4e7;
    --color-fg: #1f2937;
    --color-fg-dim: #4b5563;
    --color-border: #d4d4d8;

    --color-primary: #1f2937;
    --color-secondary: #374151;
    --color-text: #1f2937;
    --color-text-light: #4b5563;
    --color-link: #076678;
    --color-link-hover: #427b58;
    --color-background: #ffffff;
    --color-code-bg: #f4f4f5;
    --color-accent-orange: #af3a03;
    --color-accent-yellow: #b57614;
    --color-accent-green: #79740e;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Courier New", Courier, monospace;
}

/* Gruvbox Dark — applied when the OS prefers dark mode. */
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg-dark: #282828;
        --color-bg-darker: #1e1e1e;
        --color-bg-light: #3c3836;
        --color-fg: #efe6d3;
        --color-fg-dim: #a89984;
        --color-border: #504945;

        --color-primary: #efe6d3;
        --color-secondary: #bdae93;
        --color-text: #efe6d3;
        --color-text-light: #a89984;
        --color-link: #83a598;
        --color-link-hover: #8ec07c;
        --color-background: #1e1e1e;
        --color-code-bg: #282828;
        --color-accent-orange: #fe8019;
        --color-accent-yellow: #fabd2f;
        --color-accent-green: #b8bb26;
    }
}

/* 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-bg-dark: #282828;
    --color-bg-darker: #1e1e1e;
    --color-bg-light: #3c3836;
    --color-fg: #efe6d3;
    --color-fg-dim: #a89984;
    --color-border: #504945;

    --color-primary: #efe6d3;
    --color-secondary: #bdae93;
    --color-text: #efe6d3;
    --color-text-light: #a89984;
    --color-link: #83a598;
    --color-link-hover: #8ec07c;
    --color-background: #1e1e1e;
    --color-code-bg: #282828;
    --color-accent-orange: #fe8019;
    --color-accent-yellow: #fabd2f;
    --color-accent-green: #b8bb26;
}

@media (prefers-color-scheme: dark) {
    html.theme-toggled,
    body:has(#theme-toggle:checked) {
        --color-bg-dark: #f4f4f5;
        --color-bg-darker: #fafafa;
        --color-bg-light: #e4e4e7;
        --color-fg: #1f2937;
        --color-fg-dim: #4b5563;
        --color-border: #d4d4d8;

        --color-primary: #1f2937;
        --color-secondary: #374151;
        --color-text: #1f2937;
        --color-text-light: #4b5563;
        --color-link: #076678;
        --color-link-hover: #427b58;
        --color-background: #ffffff;
        --color-code-bg: #f4f4f5;
        --color-accent-orange: #af3a03;
        --color-accent-yellow: #b57614;
        --color-accent-green: #79740e;
    }
}

/* 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;
    background: none;
    border: 0;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    color: var(--color-text-light);
    transition: color 0.2s ease;
    user-select: none;
}

.theme-toggle:hover {
    color: var(--color-link);
}

/* 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-link);
    outline-offset: 2px;
    border-radius: 4px;
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* Header */
.site-header {
    border-bottom: 1px solid var(--color-border);
    padding: 16px 0;
    margin-bottom: 24px;
}

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

.site-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
}

.site-title a {
    color: var(--color-primary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    margin: 0;
}

.site-title img {
    height: 40px;
    width: auto;
    margin: 0;
}

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

.main-nav a {
    color: var(--color-text-light);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.2s ease;
}

.main-nav a:hover {
    color: var(--color-link);
}

/* Main Content */
.site-main {
    min-height: calc(100vh - 300px);
    padding-bottom: 40px;
}

.site-main .container {
    max-width: 1180px;
}

/* Posts List */
.posts-list {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.post-card {
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 22px;
}

.post-card:last-child {
    border-bottom: none;
}

.post-title {
    font-size: 25px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 7px;
}

.post-title a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

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

.post-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--color-text-light);
    margin-bottom: 10px;
}

.post-meta span {
    display: flex;
    align-items: center;
}

.post-author a,
.post-markdown a {
    color: inherit;
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.post-author a:hover,
.post-markdown a:hover {
    background: var(--color-accent-orange);
    color: var(--color-bg-dark);
}

.post-description {
    font-size: 15px;
    line-height: 1.55;
    color: var(--color-secondary);
    margin-bottom: 10px;
}

.post-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

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

.tag:hover {
    background: var(--color-accent-orange);
    color: var(--color-bg-dark);
}

/* Individual Post */
.post {
    max-width: 800px;
    margin: 0 auto;
}

.post-header {
    margin-bottom: 40px;
    text-align: center;
}

.post-header .post-title {
    font-size: 42px;
    margin-bottom: 16px;
}

.post-header .post-meta {
    justify-content: center;
}

.post-content {
    font-size: 18px;
    font-weight: 400;
    line-height: 1.8;
}

.post-content h2 {
    font-size: 32px;
    font-weight: 700;
    margin: 40px 0 20px;
}

.post-content h3 {
    font-size: 24px;
    font-weight: 700;
    margin: 32px 0 16px;
}

.post-content p {
    margin-bottom: 24px;
}

.post-content ul,
.post-content ol {
    margin-bottom: 24px;
    padding-left: 32px;
}

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

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

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

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

.post-content pre {
    background: var(--color-bg-darker);
    color: var(--color-fg);
    padding: 20px;
    border-radius: 5px;
    overflow-x: auto;
    margin-bottom: 24px;
    border: 1px solid var(--color-border);
    line-height: 1.4;
}

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

.post-content blockquote {
    border-left: 4px solid var(--color-link);
    padding-left: 20px;
    margin: 24px 0;
    font-style: italic;
    color: var(--color-secondary);
}

.post-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 24px auto;
    border-radius: 5px;
}

/* Archive notice */
.post-archive-notice {
    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);
    padding: 16px 0;
    margin-bottom: 40px;
}

/* Page Title */
.page-title {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 40px;
    text-align: center;
}

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

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

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

/* Tags Cloud */
.tags-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    max-width: 800px;
    margin: 0 auto;
}

.tag-cloud-item {
    display: inline-block;
    padding: 8px 16px;
    background: var(--color-code-bg);
    color: var(--color-primary);
    text-decoration: none;
    font-size: 16px;
    border-radius: 5px;
    transition: all 0.2s ease;
}

.tag-cloud-item:hover {
    background: var(--color-accent-orange);
    color: var(--color-bg-dark);
    transform: translateY(-2px);
}

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

.tag-cloud-item:hover .tag-count {
    color: rgba(40, 40, 40, 0.8);
}

/* Footer */
.site-footer {
    border-top: 1px solid var(--color-border);
    padding: 24px 0;
    margin-top: 40px;
    text-align: center;
    color: var(--color-text-light);
    font-size: 13px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    .post-title {
        font-size: 24px;
    }

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

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

    .post-content h3 {
        font-size: 20px;
    }

    .post-meta {
        flex-wrap: wrap;
        justify-content: center;
    }
}

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

    .site-header {
        display: none;
    }

    .site-footer {
        display: none;
    }

    .site-main {
        background: white;
    }

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

    .post-content a:hover {
        text-decoration: underline;
    }

    .post-content code {
        background: #f5f5f5;
        color: #000;
    }

    .post-content pre {
        background: #f5f5f5;
        color: #000;
        border: 1px solid #ddd;
        /* When printed, long lines can't scroll — wrap them so nothing
           gets clipped at the page edge. Indentation/newlines are
           preserved by pre-wrap; overflow-wrap breaks unbreakable
           tokens (long URLs, hashes) at any character. */
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }

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

    .tag {
        display: none;
    }
}
