/* ==========================================================================
   CSS Variables and Theme Support
   ========================================================================== */

:root {
    --max-width: 800px;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-serif: Georgia, 'Times New Roman', Times, serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Courier New', monospace;
}

/* Auto theme (follows system preference) */
[data-theme="auto"] {
    --bg-color: #ffffff;
    --text-color: #1a1a1a;
    --text-muted: #666666;
    --border-color: #e5e5e5;
    --link-color: #0066cc;
    --link-hover: #004499;
    --tag-bg: #f0f0f0;
    --tag-text: #333333;
    --code-bg: #f5f5f5;
    --blockquote-border: #ddd;
    --header-bg: #fafafa;
    --draft-bg: #fff3cd;
    --draft-border: #ffc107;
}

@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --bg-color: #1a1a1a;
        --text-color: #e5e5e5;
        --text-muted: #999999;
        --border-color: #333333;
        --link-color: #66b3ff;
        --link-hover: #99ccff;
        --tag-bg: #2a2a2a;
        --tag-text: #cccccc;
        --code-bg: #2a2a2a;
        --blockquote-border: #444;
        --header-bg: #222222;
        --draft-bg: #3d3100;
        --draft-border: #ffc107;
    }
}

/* Light theme (forced) */
[data-theme="light"] {
    --bg-color: #ffffff;
    --text-color: #1a1a1a;
    --text-muted: #666666;
    --border-color: #e5e5e5;
    --link-color: #0066cc;
    --link-hover: #004499;
    --tag-bg: #f0f0f0;
    --tag-text: #333333;
    --code-bg: #f5f5f5;
    --blockquote-border: #ddd;
    --header-bg: #fafafa;
    --draft-bg: #fff3cd;
    --draft-border: #ffc107;
}

/* Dark theme (forced) */
[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #e5e5e5;
    --text-muted: #999999;
    --border-color: #333333;
    --link-color: #66b3ff;
    --link-hover: #99ccff;
    --tag-bg: #2a2a2a;
    --tag-text: #cccccc;
    --code-bg: #2a2a2a;
    --blockquote-border: #444;
    --header-bg: #222222;
    --draft-bg: #3d3100;
    --draft-border: #ffc107;
}

/* ==========================================================================
   Base Styles
   ========================================================================== */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    margin: 0;
    padding: 0;
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

/* ==========================================================================
   Typography
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-serif);
    line-height: 1.3;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

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

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

p {
    margin: 1em 0;
}

code, pre {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background-color: var(--code-bg);
    border-radius: 4px;
}

code {
    padding: 0.2em 0.4em;
}

pre {
    padding: 1rem;
    overflow-x: auto;
}

pre code {
    padding: 0;
    background: none;
}

blockquote {
    margin: 1.5em 0;
    padding: 0.5em 1em;
    border-left: 4px solid var(--blockquote-border);
    font-style: italic;
    color: var(--text-muted);
}

blockquote p:first-child {
    margin-top: 0;
}

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

/* ==========================================================================
   Header and Navigation
   ========================================================================== */

.site-header {
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
}

.site-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.site-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-color);
}

.site-title:hover {
    color: var(--link-color);
    text-decoration: none;
}

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

.nav-links a {
    color: var(--text-muted);
}

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

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

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.875rem;
}

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

/* ==========================================================================
   Content Feed
   ========================================================================== */

.content-feed {
    margin: 2rem 0;
}

.feed-item {
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.feed-item:last-child {
    border-bottom: none;
}

.feed-item h2 {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.item-type {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.item-meta {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
}

.item-meta time {
    margin-right: 1rem;
}

/* Link items */
.link-domain {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.external-link::after {
    content: ' ↗';
    font-size: 0.75em;
}

.permalink {
    font-size: 0.875rem;
}

/* Quotation items */
.quotation {
    font-size: 1.1rem;
    margin: 0.5rem 0;
}

cite {
    font-style: normal;
    color: var(--text-muted);
}

/* ==========================================================================
   Tags
   ========================================================================== */

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.75rem 0;
}

.tag {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    background-color: var(--tag-bg);
    color: var(--tag-text);
    border-radius: 4px;
    font-size: 0.8rem;
    text-decoration: none;
}

.tag:hover {
    background-color: var(--link-color);
    color: white;
    text-decoration: none;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 1.5rem 0;
}

.tag-cloud .tag {
    font-size: 0.9rem;
}

.tag .count {
    opacity: 0.7;
}

.tag-hint {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 2rem;
}

.tag-hint code {
    font-size: 0.85em;
}

/* ==========================================================================
   Article Pages
   ========================================================================== */

article.entry,
article.blogmark,
article.til,
article.quotation {
    margin: 2rem 0;
}

article header h1 {
    margin-top: 0.5rem;
}

article header time {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.body, .commentary, .e-content {
    line-height: 1.7;
}

.body img,
.commentary img,
.e-content img {
    max-width: 100%;
    height: auto;
}

/* Entry navigation */
.entry-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.nav-prev, .nav-next {
    max-width: 45%;
}

/* Via attribution */
.via {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Draft warning */
.draft-warning {
    background-color: var(--draft-bg);
    border: 1px solid var(--draft-border);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

/* ==========================================================================
   Archive Pages
   ========================================================================== */

.archive-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
}

.archive-table th,
.archive-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.archive-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.archive-nav {
    margin: 1.5rem 0;
}

.result-count {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 1rem 0;
}

/* ==========================================================================
   Search
   ========================================================================== */

.search-form {
    display: flex;
    gap: 0.5rem;
    margin: 1.5rem 0;
}

.search-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    background-color: var(--bg-color);
    color: var(--text-color);
}

.search-input:focus {
    outline: none;
    border-color: var(--link-color);
}

.search-button {
    padding: 0.75rem 1.5rem;
    background-color: var(--link-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

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

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

.site-footer {
    margin-top: 3rem;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.875rem;
}

.footer-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

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

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

@media (max-width: 600px) {
    html {
        font-size: 15px;
    }

    .site-nav {
        flex-direction: column;
        align-items: flex-start;
    }

    .entry-nav {
        flex-direction: column;
        gap: 1rem;
    }

    .nav-prev, .nav-next {
        max-width: 100%;
    }

    .search-form {
        flex-direction: column;
    }

    .archive-table {
        font-size: 0.875rem;
    }

    .archive-table th,
    .archive-table td {
        padding: 0.5rem;
    }
}

/* ==========================================================================
   Syntax Highlighting (for code blocks)
   ========================================================================== */

.codehilite {
    background-color: var(--code-bg);
    border-radius: 4px;
    padding: 1rem;
    overflow-x: auto;
}

.codehilite pre {
    margin: 0;
    padding: 0;
}
