/* ==================== CSS Variables ==================== */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-code: #f8f8f8;
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-muted: #6a6a6a;
    --border-color: #e0e0e0;
    --accent-color: #0066cc;
    --accent-hover: #0052a3;
    --code-copy-bg: #e8e8e8;
    --code-copy-hover: #d0d0d0;
    --card-hover-bg: #fafafa;
    --transition-speed: 0.3s;
}

[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-code: #1c2128;
    --text-primary: #e6edf3;
    --text-secondary: #c9d1d9;
    --text-muted: #8b949e;
    --border-color: #30363d;
    --accent-color: #58a6ff;
    --accent-hover: #79b8ff;
    --code-copy-bg: #21262d;
    --code-copy-hover: #30363d;
    --card-hover-bg: #161b22;
}

/* ==================== Base Styles ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* ==================== Header & Navigation ==================== */
header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

nav {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.site-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    font-family: inherit;
    transition: color var(--transition-speed);
}

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

.site-title:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.theme-toggle {
    background: var(--bg-code);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle:hover {
    background: var(--code-copy-hover);
}

.theme-toggle:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* ==================== Main Content ==================== */
main {
    max-width: 800px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    min-height: calc(100vh - 250px);
}

/* ==================== Homepage - Post List ==================== */
.post-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.post-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: inherit;
    display: block;
}

.post-card:hover {
    background-color: var(--card-hover-bg);
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .post-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.post-card h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.post-card .post-meta {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.post-card .post-excerpt {
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ==================== Single Post View ==================== */
.post-view {
    display: none;
}

.post-view.active {
    display: block;
}

.back-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 1rem;
    margin-bottom: 2rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.2s;
}

.back-button:hover {
    background: var(--code-copy-hover);
    border-color: var(--accent-color);
}

.back-button:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

article {
    margin-bottom: 3rem;
}

/* ==================== Typography ==================== */
h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    line-height: 1.2;
}

h2 {
    font-size: 1.5rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

h3 {
    font-size: 1.25rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.post-meta {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color var(--transition-speed);
}

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

a:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* ==================== Code Blocks ==================== */
code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

/* Inline code */
p code,
li code {
    background-color: var(--bg-code);
    color: var(--text-primary);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    border: 1px solid var(--border-color);
}

/* Code block container */
.code-block {
    position: relative;
    margin: 1.5rem 0;
}

.code-header {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.code-language {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.copy-button {
    background-color: var(--code-copy-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.copy-button:hover {
    background-color: var(--code-copy-hover);
}

.copy-button:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.copy-button.copied {
    background-color: var(--accent-color);
    color: #ffffff;
}

pre {
    background-color: var(--bg-code);
    border: 1px solid var(--border-color);
    border-radius: 0 0 6px 6px;
    padding: 1rem;
    overflow-x: auto;
    margin: 0;
}

pre code {
    display: block;
    background: none;
    padding: 0;
    border: none;
    line-height: 1.5;
    white-space: pre;
}

/* ==================== Syntax Highlighting (CSS-based) ==================== */
/* Keywords */
.keyword {
    color: #cf222e;
    font-weight: 600;
}

[data-theme="dark"] .keyword {
    color: #ff7b72;
}

/* Strings */
.string {
    color: #0a3069;
}

[data-theme="dark"] .string {
    color: #a5d6ff;
}

/* Comments */
.comment {
    color: #6e7781;
    font-style: italic;
}

[data-theme="dark"] .comment {
    color: #8b949e;
}

/* Functions */
.function {
    color: #8250df;
    font-weight: 600;
}

[data-theme="dark"] .function {
    color: #d2a8ff;
}

/* Numbers */
.number {
    color: #0550ae;
}

[data-theme="dark"] .number {
    color: #79c0ff;
}

/* Operators */
.operator {
    color: #cf222e;
}

[data-theme="dark"] .operator {
    color: #ff7b72;
}

/* ==================== Lists ==================== */
ul, ol {
    margin-bottom: 1rem;
    padding-left: 2rem;
}

li {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* ==================== Footer ==================== */
footer {
    max-width: 800px;
    margin: 3rem auto 2rem;
    padding: 2rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

/* ==================== Responsive Design ==================== */
@media (max-width: 640px) {
    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.35rem;
    }

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

    .code-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* ==================== Accessibility ==================== */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* ==================== Empty State ==================== */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-state h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}
