/* ====== Base ====== */
:root {
    --bg: #ffffff;
    --ink: #111;
    --muted: #6b7280;
    --rule: #e5e7eb;
    --link: #0a4;
    --link-hover: #083;
    --sidebar-bg: #FAFAF9;
    --maxw: 820px;
    /* content width per screenshot */
}

/* ====== Dark Mode ====== */
[data-theme="dark"] {
    --bg: #1a1a1a;
    --ink: #e5e5e5;
    --muted: #9ca3af;
    --rule: #374151;
    --link: #4ade80;
    --link-hover: #22c55e;
    --sidebar-bg: #1f1f1f;
}

[data-theme="dark"] .tagline {
    color: #a6d09b;
}


[data-theme="dark"] .post:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .searchbar,
[data-theme="dark"] .menu-toggle,
[data-theme="dark"] .tag-filter .tag,
[data-theme="dark"] .taglist li {
    background: #2a2a2a;
    border-color: var(--rule);
}

[data-theme="dark"] .searchbar input::placeholder {
    color: #6b7280;
}

[data-theme="dark"] .icon-btn {
    background: #2a2a2a;
    border-color: var(--rule);
}

[data-theme="dark"] .icon-btn:hover {
    background: #333;
}

[data-theme="dark"] .substack-link {
    background: #252525;
    border-left-color: var(--link);
}

[data-theme="dark"] #filters input:checked+label.tag {
    border-color: #166534;
    background: #14532d;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.6;
}

/* ====== Layout (sidebar + content) ====== */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 320px;
    padding: 28px 24px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--rule);
    display: flex;
    flex-direction: column;
    gap: 20px;
    font-family: 'Zain', sans-serif;
}

/* Reduce brand→tagline spacing on desktop only */
@media (min-width: 721px) {
    .sidebar .brand+.tagline {
        margin-top: -20px;
    }
}

.brand {
    font-family: 'Zain', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: .2px;
    text-decoration: none;
    color: var(--ink);
}

.tagline {
    color: #4f7942;
    margin: 0;
    font-size: .95rem;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.nav a {
    display: block;
    padding: .25rem 0;
    color: inherit;
    text-decoration: none;
    border-radius: 6px;
}

.nav a:hover {
    text-decoration: underline;
}

.nav a.is-active {
    font-weight: 600;
}

.sidebar-tools {
    margin-top: auto;
    display: flex;
    gap: .5rem;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--rule);
    background: #fff;
    border-radius: 999px;
    text-decoration: none;
    font-size: 18px;
    cursor: pointer;
}

.icon-btn:hover {
    background: #fafafa;
}

.sidebar-headshot {
    display: block;
    width: 90%;
    max-width: none;
    height: auto;
    border-radius: 18%;
    margin: 0 auto 14px auto;
    box-shadow: 0 2px 8px rgba(60, 60, 70, 0.07);
}

.content {
    margin-left: 320px;
    padding: 96px 48px 40px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-size: 1.075rem;
    align-items: center;
    /* center the content window */
}

.content>* {
    max-width: none;
    width: 75%;
    /* content window width */
}

/* Allow text wrapping when headshot is present (only on mobile) */
@media (max-width:720px) {
    .content:has(.content-headshot)>* {
        width: 100%;
    }
}

/* ====== Typography ====== */
.h1 {
    font-family: Fraunces, Georgia, serif;
    font-size: clamp(1.8rem, 1.6rem + 1.2vw, 2.4rem);
    line-height: 1.2;
    margin: 0 0 1rem;
}

.h2 {
    font-family: Fraunces, Georgia, serif;
    font-size: 1.375rem;
    margin: 2rem 0 .5rem;
}

.last-updated {
    margin-bottom: 0.5rem;
}

.last-updated+.h2 {
    margin-top: 0.75rem;
}

.lead {
    font-size: 1.125rem;
}

/* ====== Rules & footer ====== */
.rule {
    border: 0;
    height: 1px;
    background: var(--rule);
    margin: 2rem 0;
}

.site-foot {
    color: var(--muted);
    margin: .75rem 0 0;
    padding-top: 0;
    text-align: left;
}

/* Ensure consistent spacing when footer follows a horizontal rule */
.rule+.site-foot {
    margin-top: 0;
}

.rule:has(+ .site-foot) {
    margin-bottom: .75rem;
}

/* ====== Blog list ====== */
.year {
    margin: 2rem 0 .75rem;
    font-weight: 600;
    color: var(--muted);
}

.post-list {
    display: block;
}

.post {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: .5rem 1rem;
    padding: .65rem 0;
    border-top: 1px solid var(--rule);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.post:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.post-head {
    display: block;
}

.post:last-of-type {
    border-bottom: 1px solid var(--rule);
}

.post-title {
    color: inherit;
    text-decoration: none;
}

.post-title:hover,
.post-title:active,
.post-title:focus,
.post-title:visited {
    color: inherit;
    text-decoration: underline;
}

.post-date {
    color: var(--muted);
    white-space: nowrap;
}

.post-updated {
    color: var(--muted);
    font-size: 0.9em;
}

.post-readtime {
    color: var(--muted);
    white-space: nowrap;
    font-size: .9em;
    margin-left: .5rem;
}

.taglist {
    grid-column: 1 / -1;
    list-style: none;
    padding: 0;
    margin: .25rem 0 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

/* On mobile, override taglist to be inline with date */
@media (max-width:720px) {
    .taglist {
        grid-column: auto;
    }
}

.taglist li {
    padding: .15rem .5rem;
    border: 1px solid var(--rule);
    border-radius: 999px;
    font-size: .8rem;
    color: var(--ink);
    background: #fff;
}

.taglist li .tag-link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.taglist li .tag-link:hover {
    color: var(--link);
}

/* ====== Entry (single post) ====== */
.entry-head {
    margin-bottom: 1rem;
}

.entry-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    align-items: center;
    color: var(--muted);
}

.entry-dates {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}

.entry-date-separator {
    color: var(--muted);
}

.entry-updated {
    color: var(--muted);
    font-size: 0.95em;
}

.entry-meta .taglist li {
    color: var(--ink);
}

.substack-link {
    margin: 1rem 0 1.5rem 0;
    padding: 0.75rem 1rem;
    background: #f9fafb;
    border-left: 3px solid var(--link);
    border-radius: 4px;
    font-size: 0.95em;
}

.substack-link p {
    margin: 0;
    color: var(--muted);
}

.substack-link a {
    color: var(--link);
    font-weight: 500;
}

.substack-notice {
    margin: 1.5rem 0 1.5rem 0;
    padding: 0.75rem 1rem;
    background: #f9fafb;
    border-left: 3px solid var(--link);
    border-radius: 4px;
    font-size: 0.95em;
}

.substack-notice p {
    margin: 0;
    color: var(--muted);
}

.substack-notice a {
    color: var(--link);
    font-weight: 500;
    font-style: italic;
    text-decoration: none;
}

.substack-notice a:hover {
    text-decoration: underline;
}

[data-theme="dark"] .substack-notice {
    background: #252525;
    border-left-color: var(--link);
}

/* ====== Links ====== */
a {
    color: var(--link);
}

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

/* ====== Buttons ====== */
a.button {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    background: var(--link);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    transition: background-color 0.2s;
}

a.button:hover {
    background: var(--link-hover);
    color: white;
}

/* ====== Blockquotes ====== */
blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.25rem;
    border-left: 3px solid var(--link);
    background: #f9fafb;
    border-radius: 4px;
    font-style: italic;
    color: var(--ink);
    line-height: 1.6;
}

blockquote p {
    margin: 0;
}

blockquote p:not(:last-child) {
    margin-bottom: 0.5rem;
}

[data-theme="dark"] blockquote {
    background: #252525;
    border-left-color: var(--link);
}

/* ====== Tag Filter (UNION / OR) ====== */
.tag-filter {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin: 0 0 1rem 0;
    position: relative;
    padding-right: 80px;
    /* Make room for reset button */
}

.tag-filter input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.tag-filter .tag {
    padding: .35rem .75rem;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: #fff;
    font-size: .9rem;
    cursor: pointer;
    user-select: none;
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
}

.tag-filter .tag:hover {
    background: #fafafa;
}

[data-theme="dark"] .tag-filter .tag:hover {
    background: #353535;
}

.tag-filter .reset {
    position: absolute;
    top: 0;
    right: 0;
    margin-left: 0;
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
}

/* Ensure all buttons use theme colors on iOS */
button {
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
}

button[type="reset"],
button.reset {
    color: var(--ink);
    -webkit-appearance: none;
    appearance: none;
}

#filters input:checked+label.tag {
    border-color: #b8e3c6;
    background: #e9f8ee;
}

/* When ANY checkbox is checked, start hidden… */
main:has(#tag-css:checked, #tag-web:checked, #tag-writing:checked, #tag-career:checked, #tag-personal:checked) .post {
    display: none;
}

/* …then show posts that match ANY selected tag (UNION) */
main:has(#tag-css:checked) .post[data-tags~="css"] {
    display: grid;
}

main:has(#tag-web:checked) .post[data-tags~="web"] {
    display: grid;
}

main:has(#tag-writing:checked) .post[data-tags~="writing"] {
    display: grid;
}

main:has(#tag-career:checked) .post[data-tags~="career"] {
    display: grid;
}

main:has(#tag-personal:checked) .post[data-tags~="personal"] {
    display: grid;
}

/* ====== Search ====== */
.search-wrap {
    display: grid;
    place-content: start center;
    min-height: auto;
    margin: 0 0 16px 0;
}

.searchbar {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: 1rem;
    line-height: 1.4;
    width: 100%;
    max-width: var(--maxw);
    border: 1px solid var(--rule);
    border-radius: 12px;
    padding: .6rem .8rem;
    margin: 8px 0 20px 0;
    background: #fff;
}

.searchbar .icon {
    font-size: 1.1rem;
    opacity: .6;
}

.searchbar input {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    font: inherit;
    line-height: 1.4;
    background: transparent;
    color: var(--ink);
    padding: .05em 0 .1em 0;
}

.searchbar input::placeholder {
    color: #9ca3af;
}

/* results area; hidden until query typed */
.search-results.is-empty {
    display: none;
}

/* ====== Inline Search Mode ====== */
.inline-search {
    display: none;
}

.content.is-search-open {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding-top: 0;
    padding-bottom: 0;
}

.content.is-search-open>*:not(.inline-search) {
    display: none !important;
}

.content.is-search-open>.inline-search {
    display: grid;
    width: 100%;
    max-width: none;
    min-height: 0;
    place-content: center;
}

/* Override search page defaults when inline */
.content.is-search-open .inline-search {
    min-height: 0;
}

/* Remove default max-width constraint while search is open */
.content.is-search-open>* {
    max-width: none;
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 .75rem;
    border: 1px solid var(--rule);
    background: #fff;
    border-radius: 6px;
    font: inherit;
    cursor: pointer;
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--rule);
    background: #fff;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    transition: background-color 0.2s ease;
}

.theme-toggle:hover {
    background: #fafafa;
}

[data-theme="dark"] .theme-toggle {
    background: #2a2a2a;
    border-color: var(--rule);
}

[data-theme="dark"] .theme-toggle:hover {
    background: #333;
}

/* Desktop: bottom left of sidebar */
@media (min-width: 721px) {
    .theme-toggle {
        margin-top: auto;
        align-self: flex-start;
    }

    .theme-toggle-mobile,
    .sidebar-header-buttons {
        display: none;
    }
}

/* Mobile: next to menu button */
@media (max-width: 720px) {
    .theme-toggle:not(.theme-toggle-mobile) {
        display: none;
    }

    .theme-toggle-mobile {
        display: inline-flex;
        margin: 0;
    }

    .sidebar-header-buttons {
        display: flex;
    }
}

/* ====== Responsive ====== */
@media (max-width:980px) {
    .sidebar {
        width: 308px;
    }

    .content {
        margin-left: 308px;
        padding: 72px 32px 32px;
        min-height: 100vh;
        font-size: 1.05rem;
    }

    .content>* {
        width: 90%;
    }
}

/* Blog header row */
.blog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}

.blog-head .search-wrap {
    margin: 0;
}

.blog-head .searchbar {
    width: 100%;
    max-width: 360px;
    margin: 0;
}

@media (max-width:720px) {
    .sidebar {
        position: sticky;
        top: 0;
        width: auto;
        border-right: 0;
        border-bottom: 1px solid var(--rule);
        padding: 16px 16px;
        text-align: left;
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        column-gap: 12px;
        row-gap: 0px;
        align-items: center;
        background: var(--sidebar-bg);
        z-index: 1000;
        /* keep header above overlay */
    }

    /* Hide avatar and icon tools on mobile */
    .sidebar-headshot,
    .sidebar-tools {
        display: none;
    }

    /* Topbar elements should always sit above the overlay */
    .sidebar .brand,
    .sidebar .tagline,
    .sidebar .menu-toggle,
    .sidebar .theme-toggle,
    .sidebar .sidebar-header-buttons {
        position: relative;
        z-index: 1001;
    }

    /* Show name (links home) and tagline in the topbar */
    .brand {
        display: inline-block;
        margin: 0;
        grid-column: 1;
        grid-row: 1;
        align-self: start;
    }

    .tagline {
        display: block;
        margin: 0;
        margin-top: 0;
        font-size: .9rem;
        grid-column: 1;
        grid-row: 2;
        align-self: end;
    }

    /* Theme toggle and menu button container */
    .sidebar-header-buttons {
        display: flex;
        gap: 8px;
        grid-column: 2;
        grid-row: 1 / span 2;
        align-self: center;
        align-items: center;
    }

    /* Menu button on the right spanning both rows, centered vertically */
    .menu-toggle {
        display: inline-flex;
        width: max-content;
        margin: 0;
    }

    .nav {
        display: none;
        position: absolute;
        left: 0;
        right: 0;
        top: 100%;
        background: var(--sidebar-bg);
        border-bottom: 1px solid var(--rule);
        padding: 12px 16px;
        flex-direction: column;
        gap: .5rem;
        z-index: 20;
    }

    /* Full-window takeover when menu is open, but leave sticky topbar visible */
    .sidebar.is-menu-open .nav {
        display: flex;
        position: fixed;
        inset: 0;
        padding: 96px 24px 24px;
        /* offset topbar height */
        border: 0;
        background: var(--sidebar-bg);
        align-items: flex-start;
        justify-content: flex-start;
        gap: 1rem;
        z-index: 900;
        /* below the sticky header */
    }

    .sidebar.is-menu-open .nav a {
        font-size: 1.25rem;
    }

    /* Disable body scrolling when menu is open */
    body:has(.sidebar.is-menu-open) {
        overflow: hidden;
    }

    .content {
        margin: 0;
        padding: 39px 24px 24px;
        /* Reduced top padding by 30% from 56px */
        min-height: 100vh;
        font-size: 1rem;
        align-items: flex-start;
    }

    /* Uncenter welcome post on mobile - override parent alignment */
    #welcome-post {
        align-self: flex-start;
        width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100% !important;
    }

    .content>* {
        width: 100%;
    }

    .post {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: start;
    }

    /* Ensure post content is left-aligned */
    .post-head,
    .post .taglist {
        text-align: left;
    }

    .post-head {
        order: 1;
    }

    /* Put date and tags on the same line on mobile */
    /* Make them both inline so they appear side-by-side */
    .post-date {
        order: 2;
        display: inline-block;
        margin-right: .5rem;
        margin-top: .25rem;
        white-space: nowrap;
    }

    .taglist {
        order: 2;
        display: inline-flex;
        margin-left: 0;
        margin-top: .25rem;
        vertical-align: middle;
    }

    .blog-head {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        flex-wrap: nowrap;
    }

    .blog-head .h1 {
        flex-shrink: 1;
        min-width: 0;
        font-size: clamp(1.5rem, 1.3rem + 1vw, 2rem);
    }

    .blog-head .search-wrap {
        flex-shrink: 0;
    }

    .blog-head .searchbar {
        max-width: 200px;
        min-width: 120px;
        font-size: 0.9rem;
        padding: .5rem .7rem;
    }

    .blog-head .searchbar input {
        font-size: 0.9rem;
    }
}

/* Content headshot - hidden on desktop (when sidebar is visible) */
.content-headshot {
    display: none;
}

/* When headshot is visible (mobile), wrap content in a block container for proper float behavior */
@media (max-width:720px) {
    .content:has(.content-headshot) {
        display: block;
    }

    .content:has(.content-headshot)>* {
        clear: none;
    }
}

/* Show content headshot on mobile (when menu bar is visible instead of sidebar) */
@media (max-width:720px) {
    .content-headshot {
        display: block;
        float: right;
        width: 30%;
        max-width: 150px;
        margin: 0 0 16px 16px;
        border-radius: 18%;
        object-fit: cover;
        shape-outside: margin-box;
    }
}