/* ABOUTME: Stylesheet for the public blog pages. */
/* ABOUTME: Dark/light theme, typography, layout, and content type rendering. */

/* ==========================================================================
   Custom Properties — Dark Theme (Default)
   ========================================================================== */

:root,
[data-theme="dark"] {
    --font-body: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", Menlo, Consolas, monospace;

    --color-bg:             #0d1117;
    --color-bg-raised:      #161b22;
    --color-bg-inset:       #090c10;
    --color-text:           #c9d1d9;
    --color-text-secondary: #8b949e;
    --color-text-muted:     #484f58;
    --color-link:           #d4956a;
    --color-link-hover:     #e8b88a;
    --color-link-visited:   #b08a6a;
    --color-border:         #21262d;
    --color-border-light:   #1b1f27;
    --color-accent:         #d4956a;
    --color-quote-border:   #d4956a;
    --color-quote-mark:     rgba(212, 149, 106, 0.15);
    --color-quote-bg:       rgba(212, 149, 106, 0.04);
    --color-tag-bg:         rgba(212, 149, 106, 0.08);
    --color-tag-text:       #d4956a;
    --color-type-active:    #e8eaed;
    --color-code-bg:        #090c10;
    --color-code-border:    #1b1f27;
    --color-toggle-bg:      rgba(255, 255, 255, 0.06);
    --color-toggle-hover:   rgba(255, 255, 255, 0.1);
}

/* ==========================================================================
   Custom Properties — Light Theme
   ========================================================================== */

[data-theme="light"] {
    --color-bg:             #faf8f5;
    --color-bg-raised:      #ffffff;
    --color-bg-inset:       #f0ede8;
    --color-text:           #24221e;
    --color-text-secondary: #706b63;
    --color-text-muted:     #a8a29e;
    --color-link:           #9a5e31;
    --color-link-hover:     #7c4a24;
    --color-link-visited:   #7a5536;
    --color-border:         #e5e2dc;
    --color-border-light:   #eeebe6;
    --color-accent:         #9a5e31;
    --color-quote-border:   #d4956a;
    --color-quote-mark:     rgba(154, 94, 49, 0.1);
    --color-quote-bg:       rgba(154, 94, 49, 0.03);
    --color-tag-bg:         rgba(154, 94, 49, 0.07);
    --color-tag-text:       #9a5e31;
    --color-type-active:    #24221e;
    --color-code-bg:        #f0ede8;
    --color-code-border:    #e5e2dc;
    --color-toggle-bg:      rgba(0, 0, 0, 0.05);
    --color-toggle-hover:   rgba(0, 0, 0, 0.08);
}

/* ==========================================================================
   Theme Transition (enabled after initial paint to prevent flash)
   ========================================================================== */

html.themed *,
html.themed *::before,
html.themed *::after {
    transition: background-color 0.3s ease, color 0.2s ease, border-color 0.3s ease;
}

/* ==========================================================================
   Selection
   ========================================================================== */

::selection {
    background: rgba(212, 149, 106, 0.25);
    color: inherit;
}

[data-theme="light"] ::selection {
    background: rgba(154, 94, 49, 0.18);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    color: var(--color-text);
    background: var(--color-bg);
    font-size: 16px;
    line-height: 1.7;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Subtle warm glow at top of page — dark mode only */
body::before {
    content: '';
    position: fixed;
    top: -200px;
    left: 50%;
    width: 600px;
    height: 600px;
    transform: translateX(-50%);
    background: radial-gradient(circle, rgba(212, 149, 106, 0.035) 0%, transparent 70%);
    pointer-events: none;
    z-index: -1;
}

[data-theme="light"] body::before {
    display: none;
}

a {
    color: var(--color-link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    text-decoration-color: color-mix(in srgb, var(--color-link) 35%, transparent);
}

a:hover {
    color: var(--color-link-hover);
    text-decoration-color: var(--color-link-hover);
}

a:visited {
    color: var(--color-link-visited);
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    line-height: 1.3;
    color: var(--color-text);
}

p {
    margin: 0 0 1rem 0;
}

p:last-child {
    margin-bottom: 0;
}

img {
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.site-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1.5rem;
    overflow-x: hidden;
}

.content-wrapper {
    display: flex;
    gap: 3rem;
    align-items: flex-start;
}

.main-content {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: break-word;
}

/* ==========================================================================
   Site Header
   ========================================================================== */

.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.75rem 0 1.25rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 2rem;
}

.site-header h1 {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.3px;
    margin: 0;
}

.site-header h1 a {
    color: var(--color-text);
    text-decoration: none;
}

.site-header h1 a:visited {
    color: var(--color-text);
}

.site-header h1 a:hover {
    color: var(--color-accent);
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.site-nav a {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--color-text-secondary);
    text-decoration: none;
    letter-spacing: 0.3px;
}

.site-nav a:visited {
    color: var(--color-text-secondary);
}

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

/* ==========================================================================
   Theme Toggle
   ========================================================================== */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: var(--color-toggle-bg);
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0;
}

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

.theme-toggle svg {
    width: 16px;
    height: 16px;
}

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ==========================================================================
   Type Navigation
   ========================================================================== */

.type-nav {
    margin-bottom: 2.5rem;
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 0.3px;
    line-height: 2;
}

.type-nav a {
    color: var(--color-text-secondary);
    text-decoration: none;
}

.type-nav a:visited {
    color: var(--color-text-secondary);
}

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

.type-nav a.active {
    color: var(--color-type-active);
    font-weight: 600;
}

.type-nav a.active:visited {
    color: var(--color-type-active);
}

.type-nav .type-nav-separator {
    color: var(--color-text-muted);
    margin: 0 0.5rem;
}

/* ==========================================================================
   Date Grouping
   ========================================================================== */

.date-heading {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
    margin-top: 2.5rem;
}

.date-heading:first-child,
.type-nav + .date-heading {
    margin-top: 0;
}

/* ==========================================================================
   Post Styles
   ========================================================================== */

.post {
    padding-bottom: 2rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--color-border-light);
}

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

.post-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
    margin: 0 0 0.75rem 0;
    line-height: 1.35;
}

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

.post-title a:hover {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
    text-decoration-color: color-mix(in srgb, var(--color-link) 40%, transparent);
}

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

/* Post Footer */

.post-footer {
    margin-top: 1.25rem;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--color-text-muted);
    letter-spacing: 0.2px;
}

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

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

.post-footer a:visited {
    color: var(--color-text-muted);
}

.permalink {
    font-weight: 700;
    margin-right: 0.5rem;
    color: var(--color-accent) !important;
}

.permalink:hover {
    color: var(--color-link-hover) !important;
}

.post-tags a {
    text-decoration: none;
}

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

/* Post Content: rendered Markdown */

.post-content {
    margin-top: 0.5rem;
}

.post-content p {
    margin: 0 0 1rem 0;
}

.post-content p:last-child {
    margin-bottom: 0;
}

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

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

.post-content h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 2rem 0 0.75rem;
    letter-spacing: -0.2px;
}

.post-content h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 1.5rem 0 0.5rem;
}

.post-content h4,
.post-content h5,
.post-content h6 {
    font-size: 15px;
    font-weight: 600;
    margin: 1.25rem 0 0.5rem;
}

.post-content ul,
.post-content ol {
    margin: 0 0 1rem 0;
    padding-left: 1.5rem;
}

.post-content li {
    margin-bottom: 0.35rem;
}

.post-content blockquote {
    border-left: 2px solid var(--color-border);
    margin: 1rem 0;
    padding: 0.5rem 1.25rem;
    color: var(--color-text-secondary);
}

.post-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

/* Inline code */

code {
    font-family: var(--font-mono);
    font-size: 0.875em;
}

.post-content code {
    background: var(--color-code-bg);
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.875em;
    border: 1px solid var(--color-code-border);
}

/* Code blocks */

pre {
    margin: 1.25rem 0;
}

pre code {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    border: none;
    padding: 0;
    background: none;
}

.post-content pre {
    background: var(--color-code-bg);
    padding: 1.25rem;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--color-code-border);
}

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

/* ==========================================================================
   Quotation Styles
   ========================================================================== */

.quotation {
    position: relative;
    margin: 0 0 1rem 0;
    padding: 1.25rem 1.75rem;
    border-left: 3px solid var(--color-quote-border);
    background: var(--color-quote-bg);
    border-radius: 0 6px 6px 0;
    font-style: italic;
}

.quotation::before {
    content: "\201C";
    position: absolute;
    top: -8px;
    left: 12px;
    font-size: 48px;
    color: var(--color-quote-mark);
    font-style: normal;
    line-height: 1;
    font-family: Georgia, serif;
}

.quotation::after {
    content: "\201D";
    position: absolute;
    bottom: -18px;
    right: 12px;
    font-size: 48px;
    color: var(--color-quote-mark);
    font-style: normal;
    line-height: 1;
    font-family: Georgia, serif;
}

.quotation p {
    margin: 0 0 0.5rem 0;
}

.quotation p:last-child {
    margin-bottom: 0;
}

.quote-text {
    font-style: italic;
}

.quote-attribution {
    margin-top: 0.75rem;
    font-style: normal;
    color: var(--color-text-secondary);
    font-size: 14px;
}

/* ==========================================================================
   Entry Truncation
   ========================================================================== */

.entry-more {
    font-family: var(--font-mono);
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 13px;
}

.entry-more:hover {
    color: var(--color-accent);
}

.entry-more:visited {
    color: var(--color-text-muted);
}

/* ==========================================================================
   Via Attribution
   ========================================================================== */

.via {
    font-size: 14px;
    font-weight: 400;
    color: var(--color-text-secondary);
}

.via a {
    color: var(--color-text-secondary);
    text-decoration: underline;
}

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

.via a:visited {
    color: var(--color-text-secondary);
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
    width: 260px;
    flex-shrink: 0;
    padding-left: 2rem;
    border-left: 1px solid var(--color-border);
}

.sidebar-section {
    margin-bottom: 2rem;
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

.sidebar-heading {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
}

.sidebar-body {
    font-size: 14px;
    line-height: 1.6;
    color: var(--color-text-secondary);
}

.sidebar-body a {
    color: var(--color-link);
}

.sidebar-body strong {
    color: var(--color-accent);
    font-weight: 600;
}

.sidebar-archive-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 14px;
}

.sidebar-archive-list li {
    margin-bottom: 0.5rem;
}

.sidebar-archive-list a {
    color: var(--color-link);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 13px;
}

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

.archive-count {
    color: var(--color-text-muted);
    font-size: 12px;
    margin-left: 0.25rem;
}

/* Sidebar tag pills */
.sidebar-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
    margin-top: 3rem;
    padding: 1.5rem 0 2rem;
    border-top: 1px solid var(--color-border);
    text-align: center;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--color-text-muted);
    letter-spacing: 0.3px;
}

.site-footer a {
    color: var(--color-text-muted);
    text-decoration: none;
}

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

.site-footer a:visited {
    color: var(--color-text-muted);
}

/* ==========================================================================
   Tag Pills
   ========================================================================== */

.tag-pill {
    display: inline-block;
    background: var(--color-tag-bg);
    color: var(--color-tag-text);
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    font-family: var(--font-mono);
}

.tag-pill:hover {
    text-decoration: none;
    opacity: 0.85;
}

.tag-pill:visited {
    color: var(--color-tag-text);
}

/* ==========================================================================
   Tag Index Page
   ========================================================================== */

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 1rem;
}

.tag-count {
    opacity: 0.7;
    margin-left: 2px;
}

.tag-description {
    color: var(--color-text-secondary);
    font-size: 14px;
    margin: 0 0 1.5rem 0;
}

/* ==========================================================================
   Video Embeds
   ========================================================================== */

.video-embed {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    margin: 1rem 0;
    border-radius: 8px;
}

.video-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* ==========================================================================
   Archive Heading
   ========================================================================== */

.archive-heading {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 2rem 0;
    font-family: var(--font-mono);
    font-size: 13px;
}

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

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

.pagination-disabled {
    color: var(--color-text-muted);
}

.pagination-info {
    color: var(--color-text-secondary);
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.empty-state {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 4rem 0;
}

/* ==========================================================================
   Centered single-column container for standalone content
   ========================================================================== */

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ==========================================================================
   Recent posts section on individual post pages
   ========================================================================== */

.recent-posts {
    border-top: 2px solid var(--color-border);
    padding-top: 1rem;
    margin-top: 2rem;
}

.recent-posts-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.recent-posts-list li {
    margin-bottom: 0.5rem;
    font-size: 14px;
}

.recent-posts-list a {
    color: var(--color-link);
    text-decoration: none;
}

.recent-posts-list a:hover {
    text-decoration: underline;
}

.recent-post-date {
    color: var(--color-text-secondary);
    font-size: 13px;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 959px) {
    .content-wrapper {
        gap: 2rem;
    }

    .sidebar {
        width: 220px;
        padding-left: 1.5rem;
    }
}

@media (max-width: 767px) {
    .content-wrapper {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        order: 1;
        border-left: none;
        border-top: 1px solid var(--color-border);
        padding-left: 0;
        padding-top: 2rem;
        margin-top: 2rem;
    }

    .main-content {
        order: 0;
    }

    .site-container {
        padding: 0 1rem;
    }

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

    .type-nav {
        line-height: 2.2;
    }

    .site-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .site-nav {
        gap: 1rem;
    }

    body::before {
        display: none;
    }
}

/* Header search form (present on every page) */
.header-search { display: inline-block; margin-left: 0.5rem; }
.header-search input[type="search"] {
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-bg-subtle);
    color: var(--color-text);
    font-size: 14px;
    width: 180px;
}
@media (max-width: 767px) { .header-search input[type="search"] { width: 140px; } }

/* In-page search form on /search */
.search-form-inline { display: flex; gap: 0.5rem; margin: 1rem 0; }
.search-form-inline input[type="search"] {
    flex: 1;
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 15px;
}
.search-form-inline button {
    padding: 0.5rem 1rem;
    background: var(--color-link);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* Sort toggle */
.search-sort { font-size: 14px; color: var(--color-text-secondary); margin: 0.5rem 0; }

/* Active filter pills */
.active-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0; }
.active-filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem 0.25rem 0.75rem;
    background: var(--color-bg-subtle);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    font-size: 13px;
    color: var(--color-text);
    text-decoration: none;
    cursor: pointer;
}
.active-filter-pill:hover { background: var(--color-border-light); }
.active-filter-remove { font-size: 16px; line-height: 1; color: var(--color-text-secondary); }

/* Result count */
.search-result-count {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin: 0.5rem 0 1rem 0;
}

/* Empty state */
.search-empty { padding: 2rem 0; color: var(--color-text-secondary); font-size: 15px; }

/* Facet sidebar lists */
.facet-list { list-style: none; padding: 0; margin: 0; }
.facet-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 14px;
}
.facet-list li.active a { font-weight: 600; }
.facet-list li .facet-count {
    color: var(--color-text-secondary);
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Image Lightbox
   ========================================================================== */

/* Content images become click-to-enlarge once lightbox.js enhances them. */
.post-content img.zoomable {
    cursor: zoom-in;
}

/* Background scroll is locked while the lightbox is open so the page behind
   the backdrop does not scroll out from under the reader. */
body.lightbox-open {
    overflow: hidden;
}

.lightbox {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    overflow: auto;
    overscroll-behavior: contain;
}

.lightbox::backdrop {
    background: rgba(0, 0, 0, 0.88);
}

/* Fit-to-viewport mode: center and scale the image down to the screen. The
   [open] guard keeps a closed dialog at the UA default (display: none) so it
   never overlays the page and steals clicks. */
.lightbox[open].is-fit {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.lightbox.is-fit .lightbox-img {
    max-width: 95vw;
    max-height: 95vh;
    width: auto;
    height: auto;
    border-radius: 6px;
    cursor: zoom-in;
}

/* Actual-size mode: natural pixels, scroll to inspect fine detail. The same
   [open] guard as is-fit keeps a closed dialog at the UA default (display:
   none) rather than relying on the bare dialog default. */
.lightbox[open].is-actual {
    display: block;
}

.lightbox.is-actual .lightbox-img {
    display: block;
    margin: auto;
    max-width: none;
    max-height: none;
    width: auto;
    height: auto;
    cursor: zoom-out;
}

.lightbox-close {
    position: fixed;
    top: 0.75rem;
    right: 0.75rem;
    width: 2.25rem;
    height: 2.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    line-height: 1;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 2;
}

.lightbox-close:hover,
.lightbox-close:focus-visible {
    background: rgba(0, 0, 0, 0.8);
}

.lightbox-hint {
    position: fixed;
    bottom: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    padding: 0.3rem 0.75rem;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(0, 0, 0, 0.5);
    border-radius: 100px;
    pointer-events: none;
    z-index: 2;
}
