/* ===================== RESET & BASE ===================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #90a4ae;
    --accent-blue: #64b5f6;
    --accent-purple: #bb86fc;
    --accent-green: #4caf50;
    --border-color: #2d2d2d;
    --code-bg: #0d1117;
    --shadow: rgba(0, 0, 0, 0.3);
}

body.light-theme {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e0e0e0;
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --accent-blue: #1565c0;
    --accent-purple: #6a0dad;
    --accent-green: #2e7d32;
    --border-color: #cccccc;
    --code-bg: #f0f0f0;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ===================== HEADER ===================== */
header {
    text-align: center;
    margin-bottom: 50px;
    position: relative;
}

h1 {
    color: var(--accent-blue);
    margin-bottom: 15px;
    font-size: 2.5rem;
    font-weight: 300;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 300;
}

/* ===================== THEME TOGGLE ===================== */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
    z-index: 1000;
}

.theme-toggle:hover {
    background: var(--accent-blue);
    color: #fff;
}

/* ===================== SCROLL TO TOP ===================== */
.scroll-top {
    position: fixed;
    bottom: 30px;
    right: 20px;
    background: var(--accent-blue);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, background 0.2s ease;
    z-index: 1000;
}

.scroll-top.visible {
    opacity: 1;
    pointer-events: all;
}

.scroll-top:hover {
    background: var(--accent-purple);
}

/* ===================== SEARCH ===================== */
.search-bar {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
}

.search-bar input {
    width: 100%;
    max-width: 500px;
    padding: 10px 18px;
    border-radius: 25px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.search-bar input:focus {
    border-color: var(--accent-blue);
}

/* ===================== TOC SIDEBAR ===================== */
.layout {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    position: sticky;
    top: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
}

.sidebar h3 {
    color: var(--accent-purple);
    margin-bottom: 15px;
    font-size: 1rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.sidebar ul {
    list-style: none;
    padding: 0;
}

.sidebar ul li {
    margin-bottom: 8px;
}

.sidebar ul li a {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-decoration: none;
    transition: color 0.2s ease;
    display: block;
    padding: 3px 0;
}

.sidebar ul li a:hover {
    color: var(--accent-blue);
}

.sidebar ul li .toc-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

.posts-container {
    flex: 1;
    min-width: 0;
}

/* ===================== BLOG POSTS ===================== */
.blog-post {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 35px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    scroll-margin-top: 20px;
}

.blog-post:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--shadow);
}

.post-image {
    object-fit: cover;
    margin: 0 auto 25px auto;
    display: block;
    max-width: 100px;
    max-height: 100px;
    float: right;
    border-radius: 8px;
}

.post-title {
    color: var(--accent-purple);
    margin-bottom: 10px;
    font-size: 1.6rem;
    font-weight: 400;
    line-height: 1.3;
}

.post-meta {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.post-date {
    color: var(--accent-blue);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.post-date::before {
    content: "📅";
    font-size: 0.8em;
}

.reading-time {
    color: var(--text-secondary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.reading-time::before {
    content: "⏱️";
    font-size: 0.8em;
}

/* ===================== POST CONTENT (Markdown) ===================== */
.post-content {
    line-height: 1.8;
    color: var(--text-primary);
}

.post-content h2 {
    color: var(--accent-purple);
    font-size: 1.4rem;
    font-weight: 600;
    margin: 25px 0 15px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--accent-blue);
}

.post-content h3 {
    color: var(--accent-blue);
    font-size: 1.2rem;
    font-weight: 600;
    margin: 20px 0 12px 0;
}

.post-content p {
    margin-bottom: 15px;
}

.post-content ul,
.post-content ol {
    margin: 15px 0;
    padding-left: 30px;
}

.post-content li {
    margin-bottom: 6px;
}

.post-content a {
    color: var(--accent-blue);
    text-decoration: underline;
}

.post-content blockquote {
    border-left: 4px solid var(--accent-blue);
    padding: 10px 20px;
    margin: 20px 0;
    color: var(--text-secondary);
    font-style: italic;
    background: var(--bg-tertiary);
    border-radius: 0 8px 8px 0;
}

.post-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 25px 0;
}

.post-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.post-content th {
    background: var(--bg-tertiary);
    color: var(--accent-purple);
    padding: 10px 14px;
    text-align: left;
    border: 1px solid var(--border-color);
}

.post-content td {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
}

.post-content tr:nth-child(even) {
    background: var(--bg-tertiary);
}

/* ===================== CODE ===================== */
.post-content pre {
    background: var(--code-bg);
    color: var(--text-primary);
    padding: 38px 20px 18px 20px;
    border-radius: 8px;
    margin: 20px 0;
    overflow-x: auto;
    font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    border: 1px solid var(--border-color);
    position: relative;
}

.post-content pre::before {
    content: "{}";
    position: absolute;
    top: 10px;
    left: 15px;
    color: var(--accent-blue);
    font-size: 0.8rem;
    opacity: 0.6;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 3px 9px;
    font-size: 0.72rem;
    font-family: inherit;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
}

body.light-theme .copy-btn {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.12);
}

.post-content pre:hover .copy-btn,
.copy-btn:focus-visible,
.copy-btn[data-copied="true"] {
    opacity: 1;
    pointer-events: all;
}

.copy-btn:hover {
    background: var(--accent-blue);
    color: #fff;
}

.copy-btn[data-copied="true"] {
    background: var(--accent-green);
    color: #fff;
    border-color: transparent;
}

@media (hover: none) {
    .copy-btn {
        opacity: 1;
        pointer-events: all;
    }
}

/* ===================== SYNTAX HIGHLIGHTING (Dark) ===================== */
.post-content pre code.hljs {
    background: transparent;
    color: #e6edf3;
}

.post-content .hljs-keyword,
.post-content .hljs-selector-tag,
.post-content .hljs-doctag { color: #ff7b72; }

.post-content .hljs-string,
.post-content .hljs-attr-value,
.post-content .hljs-regexp,
.post-content .hljs-symbol,
.post-content .hljs-variable,
.post-content .hljs-template-variable { color: #a5d6ff; }

.post-content .hljs-number,
.post-content .hljs-literal,
.post-content .hljs-attribute,
.post-content .hljs-attr,
.post-content .hljs-operator,
.post-content .hljs-punctuation,
.post-content .hljs-meta,
.post-content .hljs-bullet { color: #79c0ff; }

.post-content .hljs-comment,
.post-content .hljs-quote { color: #8b949e; font-style: italic; }

.post-content .hljs-title,
.post-content .hljs-title.function_,
.post-content .hljs-section { color: #d2a8ff; }

.post-content .hljs-built_in,
.post-content .hljs-type,
.post-content .hljs-class .hljs-title { color: #ffa657; }

.post-content .hljs-name,
.post-content .hljs-tag { color: #7ee787; }

/* ===================== SYNTAX HIGHLIGHTING (Light) ===================== */
body.light-theme .post-content pre code.hljs { color: #24292f; }

body.light-theme .post-content .hljs-keyword,
body.light-theme .post-content .hljs-selector-tag,
body.light-theme .post-content .hljs-doctag { color: #cf222e; }

body.light-theme .post-content .hljs-string,
body.light-theme .post-content .hljs-attr-value,
body.light-theme .post-content .hljs-regexp,
body.light-theme .post-content .hljs-symbol,
body.light-theme .post-content .hljs-variable,
body.light-theme .post-content .hljs-template-variable { color: #0a3069; }

body.light-theme .post-content .hljs-number,
body.light-theme .post-content .hljs-literal,
body.light-theme .post-content .hljs-attribute,
body.light-theme .post-content .hljs-attr,
body.light-theme .post-content .hljs-operator,
body.light-theme .post-content .hljs-punctuation,
body.light-theme .post-content .hljs-meta,
body.light-theme .post-content .hljs-bullet { color: #0550ae; }

body.light-theme .post-content .hljs-comment,
body.light-theme .post-content .hljs-quote { color: #6e7781; font-style: italic; }

body.light-theme .post-content .hljs-title,
body.light-theme .post-content .hljs-title.function_,
body.light-theme .post-content .hljs-section { color: #8250df; }

body.light-theme .post-content .hljs-built_in,
body.light-theme .post-content .hljs-type,
body.light-theme .post-content .hljs-class .hljs-title { color: #953800; }

body.light-theme .post-content .hljs-name,
body.light-theme .post-content .hljs-tag { color: #116329; }

.post-content code {
    font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
}

.post-content :not(pre) > code {
    background: var(--bg-tertiary);
    color: var(--accent-purple);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    border: 1px solid var(--border-color);
}

/* ===================== TAGS ===================== */
.tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 15px;
}

.tag {
    background: var(--bg-tertiary);
    color: var(--accent-blue);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    border: 1px solid var(--accent-blue);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tag:hover,
.tag.active {
    background: var(--accent-blue);
    color: #fff;
}

/* ===================== NO RESULTS ===================== */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

/* ===================== LOADING ===================== */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.spinner {
    border: 3px solid var(--bg-tertiary);
    border-left-color: var(--accent-blue);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===================== FOOTER ===================== */
footer {
    text-align: center;
    margin-top: 60px;
    color: #757575;
    font-size: 0.9rem;
}

/* ===================== PRINT ===================== */
@media print {
    .theme-toggle,
    .scroll-top,
    .search-bar,
    .sidebar {
        display: none !important;
    }

    .layout {
        display: block;
    }

    .blog-post {
        break-inside: avoid;
        border: none;
        box-shadow: none;
    }

    body {
        background: white;
        color: black;
    }
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 900px) {
    .sidebar {
        display: none;
    }

    .layout {
        display: block;
    }
}

@media (max-width: 768px) {
    body { padding: 15px; }
    h1 { font-size: 2rem; }

    .blog-post {
        padding: 20px;
        margin-bottom: 25px;
    }

    .post-image {
        width: 100%;
        float: none;
        margin-bottom: 20px;
    }

    .post-title { font-size: 1.4rem; }
}

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--accent-blue); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-purple); }
