:root {
    --bg-color: #ffffff;
    --text-color: #1a1a1a;
    --link-color: #1a1a1a;
    --link-hover: #666666;
    --meta-color: #888888;
    --border-color: #eeeeee;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #121212;
        --text-color: #e0e0e0;
        --link-color: #e0e0e0;
        --link-hover: #999999;
        --border-color: #333333;
        --meta-color: #888888;
    }
}

body {
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    max-width: 680px;
    margin: 0 auto;
    padding: 40px 20px;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

/* Nav */
header {
    margin-bottom: 40px;
}

h1.site-title {
    font-size: 1.2rem;
    font-weight: 500;
    margin: 0 0 10px 0;
    letter-spacing: -0.02em;
}

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

.site-subtitle {
    margin: 0 0 15px 0;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    font-weight: 300;
    color: var(--meta-color);
}

.site-subtitle a {
    color: var(--meta-color);
    text-decoration: none;
    transition: color 0.2s;
}

.site-subtitle a:hover {
    color: var(--text-color);
}

nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 60px; /* From articles */
}

nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

nav a {
    text-decoration: none;
    color: var(--link-hover); /* overridden by article meta color below but let's keep it clean */
    transition: color 0.2s, outline 0.2s;
    outline-offset: 2px;
    border-radius: 2px;
}

article nav {
    margin-bottom: 60px;
    border-bottom: none;
    padding-bottom: 0;
}

article nav a {
    color: var(--meta-color);
}

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

article nav a:hover {
    color: var(--text-color);
}

nav a:focus-visible {
    outline: 2px solid var(--text-color);
    color: var(--link-color);
}

article nav a:focus-visible {
    color: var(--text-color);
}

.nav-separator {
    margin: 0 5px;
    color: var(--border-color);
}

/* Dropdown */
.nav-dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: var(--bg-color);
    min-width: 80px;
    border: 1px solid var(--border-color);
    z-index: 1;
    padding: 5px 0;
    top: 100%;
    left: 0;
}

.dropdown-content a {
    color: var(--link-hover);
    padding: 5px 10px;
    text-decoration: none;
    display: block;
}

.dropdown-content a:hover {
    color: var(--text-color);
    background-color: var(--border-color);
}

.nav-dropdown:hover .dropdown-content {
    display: block;
}

/* Main Content */
main { margin-top: 40px; min-height: 50vh; }
section { margin-bottom: 60px; display: none; }
@media (prefers-reduced-motion: no-preference) {
    section { animation: fadeIn 0.4s ease; }
}
section.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

h2.section-title { font-size: 1.5rem; font-weight: 400; margin-bottom: 5px; letter-spacing: -0.02em; text-wrap: balance; scroll-margin-top: 2rem; }

p.section-desc {
    color: var(--meta-color);
    font-size: 0.95rem;
    margin-top: 0;
    margin-bottom: 25px;
    font-weight: 300;
}

/* Lists */
ul.item-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

ul.item-list li {
    margin-bottom: 15px;
    display: flex;
    align-items: baseline;
}

ul.item-list a {
    color: var(--link-color);
    text-decoration: underline;
    text-decoration-color: transparent;
    text-underline-offset: 4px;
    transition: text-decoration-color 0.2s;
    font-weight: 400;
}

ul.item-list a:hover {
    text-decoration-color: var(--border-color);
}

.item-meta {
    color: var(--meta-color);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    margin-left: 15px;
    flex-shrink: 0;
}

/* Projects */
.project { margin-bottom: 40px; }
.project-header { display: flex; align-items: baseline; margin-bottom: 10px; }
.project-title { color: var(--link-color); text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; transition: text-decoration-color 0.2s; font-weight: 500; font-size: 1.05rem; }
.project-title:hover { text-decoration-color: var(--border-color); }
.project-desc { margin: 0 0 10px 0; font-size: 0.95rem; color: var(--text-color); font-weight: 300; line-height: 1.6; }
.project-core { margin: 0; font-size: 0.8rem; color: var(--meta-color); font-family: 'IBM Plex Mono', monospace; }

/* Sub-projects */
.sub-projects { margin-top: 15px; padding-left: 20px; border-left: 1px solid var(--border-color); }
.sub-project { display: flex; align-items: baseline; padding: 6px 0; }
.sub-project a { color: var(--link-color); text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; transition: text-decoration-color 0.2s; font-size: 0.9rem; font-weight: 400; }
.sub-project a:hover { text-decoration-color: var(--border-color); }
.sub-project .item-meta { margin-left: 10px; }

/* Grid */
.grid-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-top: 20px;
    align-items: start;
}

.grid-item {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    overflow: hidden;
    border-radius: 2px;
}

.grid-item img {
    width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
    transition: opacity 0.2s;
}
.grid-item img:hover { opacity: 0.8; }

/* Lightbox */
.lightbox {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
}
.lightbox.active { display: flex; }
.lightbox img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

/* Article specific */
article {
    margin-bottom: 80px;
}

h1 {
    font-size: 1.8rem;
    font-weight: 500;
    line-height: 1.3;
    margin-bottom: 10px;
    letter-spacing: -0.02em;
    text-wrap: balance;
}

.post-meta {
    color: var(--meta-color);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    margin-bottom: 40px;
}

h2 {
    font-size: 1.3rem;
    font-weight: 500;
    margin-top: 40px;
    margin-bottom: 15px;
}

h3 {
    font-size: 1.1rem;
    font-weight: 500;
    margin-top: 30px;
    margin-bottom: 10px;
}

p {
    margin-bottom: 20px;
    font-weight: 300;
}

blockquote {
    margin: 0 0 20px 0;
    padding: 15px 20px;
    background-color: var(--bg-color);
    border-left: 3px solid var(--border-color);
    font-weight: 300;
    color: var(--text-color);
}

article ul, article ol {
    margin-bottom: 20px;
    padding-left: 20px;
    font-weight: 300;
}

article li {
    margin-bottom: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

th, td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 300;
}

th {
    font-weight: 500;
    border-bottom: 2px solid var(--border-color);
}

code {
    background-color: var(--border-color);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.9em;
}

article img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 30px 0 10px 0;
    border: 1px solid var(--border-color);
}

.img-caption {
    font-size: 0.85rem;
    color: var(--meta-color);
    text-align: center;
    margin-bottom: 30px;
}

hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 40px 0;
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--text-color);
    color: var(--bg-color);
    padding: 8px;
    z-index: 100;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}

/* Footer */
footer {
    margin-top: 80px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--meta-color);
    display: flex;
    justify-content: space-between;
}

article + footer {
    margin-top: 0;
}

footer a {
    color: var(--meta-color);
    text-decoration: none;
}
footer a:hover {
    text-decoration: underline;
}

/* ── Tablet (≤768px) ── */
@media (max-width: 768px) {
    body { padding: 30px 16px; }
    header { margin-bottom: 30px; }
    nav { margin-bottom: 40px; gap: 10px; }
    nav ul { gap: 12px; }
    h1 { font-size: 1.5rem; }
    h2.section-title { font-size: 1.3rem; }
    .grid-container { gap: 10px; }
    section { margin-bottom: 40px; }
    footer { margin-top: 50px; }
    table { font-size: 0.8rem; }
    th, td { padding: 8px 6px; }

    /* Dropdown: prevent hover-only on touch screens */
    .nav-dropdown .dropdown-content { left: auto; right: 0; }
}

/* ── Mobile (≤480px) ── */
@media (max-width: 480px) {
    body { padding: 20px 14px; }
    header { margin-bottom: 20px; }
    nav {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 30px;
    }
    nav ul { gap: 10px; }
    h1 { font-size: 1.3rem; line-height: 1.4; }
    h2.section-title { font-size: 1.15rem; }
    h2 { font-size: 1.1rem; margin-top: 30px; }
    h3 { font-size: 1rem; margin-top: 20px; }
    p { font-size: 0.92rem; }

    /* Item list: stack vertically */
    ul.item-list li {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }
    .item-meta { margin-left: 0; }

    /* Project section */
    .project { margin-bottom: 30px; }
    .project-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    .project-desc { font-size: 0.9rem; }
    .project-core { font-size: 0.75rem; }

    /* Photo grid: single column */
    .grid-container {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Sub-projects */
    .sub-projects { padding-left: 14px; }
    .sub-project {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }
    .sub-project .item-meta { margin-left: 0; }

    /* Footer: stack */
    footer {
        flex-direction: column;
        gap: 6px;
        margin-top: 40px;
    }

    /* Table horizontal scroll */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Article content */
    blockquote { padding: 10px 14px; font-size: 0.9rem; }
    .post-meta { margin-bottom: 25px; font-size: 0.8rem; }
    article ul, article ol { padding-left: 16px; }
    article img { margin: 20px 0 8px 0; }
    .img-caption { font-size: 0.8rem; margin-bottom: 20px; }
    code { font-size: 0.82em; padding: 1px 4px; }
    hr { margin: 25px 0; }

    /* Lightbox: fullscreen on mobile */
    .lightbox img { max-width: 96%; max-height: 85%; }

    /* Nav separator: hide on mobile for cleaner look */
    .nav-separator { display: none; }

    /* Dropdown: full-width on mobile */
    .dropdown-content {
        position: static;
        border: none;
        padding: 5px 0 0 10px;
    }
    .nav-dropdown:hover .dropdown-content { display: flex; gap: 12px; }

    /* Touch-friendly: larger tap targets */
    nav a { padding: 4px 2px; }
    ul.item-list a { padding: 2px 0; }
}