/* -----------------------------------------------------------------------
   Dieciocho — clean modern light theme
   ----------------------------------------------------------------------- */

:root,
[data-theme="light"] {
    --bg:         #f7f7f7;
    --surface:    #ffffff;
    --border:     #e5e5e5;
    --text:       #111111;
    --muted:      #6b6b6b;
    --accent:     #111111;
    --font-body:  "Inter", system-ui, sans-serif;
    --font-mono:  "JetBrains Mono", monospace;

    /* Override PicoCSS variables */
    --pico-background-color:        #f7f7f7;
    --pico-color:                   #111111;
    --pico-card-background-color:   #ffffff;
    --pico-card-border-color:       #e5e5e5;
    --pico-muted-color:             #6b6b6b;
    --pico-muted-border-color:      #e5e5e5;
    --pico-primary:                 #111111;
    --pico-primary-hover:           #444444;
    --pico-secondary:               #6b6b6b;
    --pico-nav-background-color:    #ffffff;
    --pico-nav-border-color:        #e5e5e5;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg:       #0f0f0f;
    --surface:  #1a1a1a;
    --border:   #2a2a2a;
    --text:     #f0f0f0;
    --muted:    #888888;
    --accent:   #f0f0f0;

    /* Override PicoCSS variables */
    --pico-background-color:        #0f0f0f;
    --pico-color:                   #f0f0f0;
    --pico-card-background-color:   #1a1a1a;
    --pico-card-border-color:       #2a2a2a;
    --pico-muted-color:             #888888;
    --pico-muted-border-color:      #2a2a2a;
    --pico-primary:                 #f0f0f0;
    --pico-primary-hover:           #bbbbbb;
    --pico-secondary:               #888888;
    --pico-nav-background-color:    #1a1a1a;
    --pico-nav-border-color:        #2a2a2a;
    color-scheme: dark;
}

/* -----------------------------------------------------------------------
   Reset / base
   ----------------------------------------------------------------------- */

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

html {
    font-size: 16px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.65;
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 3px;
}

a:hover {
    opacity: 0.6;
}

/* -----------------------------------------------------------------------
   Nav
   ----------------------------------------------------------------------- */

.site-nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-title {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    text-decoration: none;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-link {
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--muted);
}

.nav-link:hover {
    color: var(--text);
    opacity: 1;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    font-family: var(--font-body);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.3rem 0.75rem;
    border-radius: 4px;
    transition: color 0.15s, border-color 0.15s;
}

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

/* -----------------------------------------------------------------------
   Layout
   ----------------------------------------------------------------------- */

.layout {
    display: grid;
    grid-template-columns: 180px 1fr;
    min-height: calc(100vh - 56px);
}

.main-content {
    border-left: 1px solid var(--border);
    min-width: 0;
}

/* -----------------------------------------------------------------------
   Sidebar
   ----------------------------------------------------------------------- */

.chapter-sidebar {
    padding: 2rem 1rem 2rem 1.5rem;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
}

.chapter-sidebar nav {
    background: none;
}

.sidebar-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.sidebar-link {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--muted);
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    transition: color 0.1s, background 0.1s;
}

.sidebar-link:hover {
    color: var(--text);
    background: var(--border);
    opacity: 1;
}

.sidebar-link--active {
    color: var(--text);
    background: var(--border);
}

/* -----------------------------------------------------------------------
   Blog index
   ----------------------------------------------------------------------- */

.blog-index {
    max-width: 680px;
    margin: 3rem auto;
    padding: 0 1.5rem;
    flex: 1;
}

.post-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.post-row {
    padding: 1.25rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.post-row:first-child {
    border-top: 1px solid var(--border);
}

.post-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chapter-label {
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    background: var(--border);
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
}

.post-pill-link {
    display: inline-block;
    text-decoration: none;
}

.post-pill-link:hover {
    opacity: 0.6;
}

.post-preview {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 0.35rem 0 0;
    line-height: 1.5;
}

.chapter-heading {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 1.5rem;
}

.post-date {
    font-size: 0.82rem;
    color: var(--muted);
}

.post-title-link {
    font-size: 1.05rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--text);
    line-height: 1.3;
}

.post-title-link:hover {
    opacity: 0.6;
}

/* -----------------------------------------------------------------------
   Post page
   ----------------------------------------------------------------------- */

.post-page {
    max-width: 680px;
    margin: 3rem auto;
    padding: 0 1.5rem;
    flex: 1;
}

.post-page > article {
    background: none;
    border: none;
    padding: 0;
}

.post-header {
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.post-header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin: 0.5rem 0 0;
}

.post-body {
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text);
}

.post-body h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-top: 2.5rem;
    letter-spacing: -0.02em;
}

.post-body h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 2rem;
}

.post-body p {
    margin: 1.25rem 0;
}

.post-body blockquote {
    border-left: 3px solid var(--border);
    margin: 1.5rem 0;
    padding: 0.25rem 1.25rem;
    color: var(--muted);
}

.post-body pre,
.post-body code {
    font-family: var(--font-mono);
    font-size: 0.88rem;
}

.post-body pre {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem 1.25rem;
    overflow-x: auto;
}

.post-body code:not(pre code) {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.1em 0.35em;
}

.post-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.post-footer {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.back-link {
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--muted);
}

.back-link:hover {
    color: var(--text);
    opacity: 1;
}

/* -----------------------------------------------------------------------
   Footer
   ----------------------------------------------------------------------- */

.site-footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 2rem;
    text-align: center;
}

.footer-copy {
    font-size: 0.8rem;
    color: var(--muted);
    margin: 0;
}

/* -----------------------------------------------------------------------
   404
   ----------------------------------------------------------------------- */

.not-found {
    max-width: 680px;
    margin: 4rem auto;
    padding: 0 1.5rem;
    flex: 1;
}

/* -----------------------------------------------------------------------
   Responsive
   ----------------------------------------------------------------------- */

@media (max-width: 640px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .chapter-sidebar {
        position: static;
        height: auto;
        padding: 1rem 1.5rem 0;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-list {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .main-content {
        border-left: none;
    }

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

    .blog-index,
    .post-page,
    .not-found {
        margin: 2rem auto;
    }

    .post-header h1 {
        font-size: 1.6rem;
    }
}
