/* CSS Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Ensure hidden attribute works */
[hidden] {
    display: none !important;
}

/* Disable transitions on page load to prevent flash */
.no-transition * {
    transition: none !important;
}

/* Kimbie Dark theme (default) */
:root {
    --primary-color: #dc3958;
    --secondary-color: #f79a32;
    --bg-dark: #221a0f;
    --bg-secondary: #2b221a;
    --bg-card: #362b21;
    --text-color: #d3af86;
    --text-light: #a89074;
    --border-color: #4a3f33;
    --code-bg: #1a140c;
    --quote-bg: #2b221a;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -1px rgb(0 0 0 / 0.2);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.4), 0 10px 10px -5px rgb(0 0 0 / 0.3);
    --max-width: 1200px;
}

/* Kimbie Light theme */
[data-theme="light"] {
    --primary-color: #dc3958;
    --secondary-color: #f06431;
    --bg-dark: #fbebd4;
    --bg-secondary: #f5e7d0;
    --bg-card: #faf1e0;
    --text-color: #84613d;
    --text-light: #a57a4c;
    --border-color: #e5d5bb;
    --code-bg: #f5e7d0;
    --quote-bg: #f5e7d0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -1px rgb(0 0 0 / 0.06);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.15), 0 10px 10px -5px rgb(0 0 0 / 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.7;
    color: var(--text-color);
    background: var(--bg-dark);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
    transition: opacity 0.2s ease-in;
}

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

/* Header Styles */
header {
    background: var(--bg-secondary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 2px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
}

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

.logo a:hover {
    color: var(--primary-color);
}

.logo-prefix {
    color: var(--text-light);
}

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

header nav a {
    color: var(--text-light);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

header nav a:hover {
    color: var(--primary-color);
}

/* Theme Toggle Button */
.theme-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Hero Section */
.hero {
    padding: 3rem 0 2rem;
    text-align: center;
}

.hero h2 {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    color: var(--text-color);
    font-weight: 700;
}

.hero p {
    font-size: 1.1rem;
    color: var(--text-light);
}

/* Articles Grid */
.articles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    padding: 2rem 0 4rem;
}

.article-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s, background-color 0.3s;
}

.article-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.article-card-content {
    padding: 1.5rem;
}

.article-card h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.article-card h3 a {
    color: var(--text-color);
    text-decoration: none;
    transition: color 0.2s;
}

.article-card h3 a:hover {
    color: var(--primary-color);
}

.article-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 1rem;
}

.article-excerpt {
    color: var(--text-light);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.read-more {
    display: inline-block;
    color: var(--primary-color);
    font-weight: 600;
    text-decoration: none;
    transition: color 0.2s;
}

.read-more:hover {
    color: var(--secondary-color);
}

/* Article Layout */
.article-layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 3rem;
    padding: 2rem 0 4rem;
    max-width: 1400px;
    margin: 0 auto;
}

.toc-sidebar {
    position: relative;
}

.toc-sticky {
    position: sticky;
    top: 100px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: background-color 0.3s, border-color 0.3s;
}

.toc-sticky h3 {
    font-size: 0.875rem;
    margin-bottom: 1rem;
    color: var(--text-color);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#table-of-contents {
    counter-reset: toc-h2;
}

#table-of-contents a {
    display: block;
    color: var(--text-light);
    text-decoration: none;
    padding: 0.5rem 0.75rem 0.5rem 0;
    font-size: 0.875rem;
    transition: color 0.2s, background 0.2s;
}

#table-of-contents a[data-level="2"] {
    counter-increment: toc-h2;
    counter-reset: toc-h3;
    padding-left: 0;
}

#table-of-contents a[data-level="2"]::before {
    content: counter(toc-h2) ". ";
    font-weight: 700;
    color: var(--primary-color);
}

#table-of-contents a[data-level="3"] {
    counter-increment: toc-h3;
    padding-left: 1.5rem;
}

#table-of-contents a[data-level="3"]::before {
    content: counter(toc-h2) "." counter(toc-h3) " ";
    font-weight: 700;
    color: var(--primary-color);
}

#table-of-contents a:hover {
    color: var(--primary-color);
}

#table-of-contents a.active {
    color: var(--primary-color);
    font-weight: 700;
    background: var(--quote-bg);
    border-left: 3px solid var(--primary-color);
    padding-left: 0.75rem;
}

#table-of-contents a[data-level="3"].active {
    padding-left: 2.25rem;
}

/* Article Content */
.article-content {
    max-width: 800px;
}

#article-header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

#article-header h1 {
    font-size: 2rem;
    line-height: 1.3;
    margin-bottom: 1rem;
    font-weight: 700;
    color: var(--text-color);
}

#article-header .article-meta {
    font-size: 0.875rem;
    color: var(--text-light);
}

/* Article Body Styles */
#article-body h2 {
    font-size: 1.5rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--text-color);
    font-weight: 700;
}

#article-body h3 {
    font-size: 1.25rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-color);
    font-weight: 700;
}

#article-body h4 {
    font-size: 1.1rem;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
    font-weight: 700;
}

#article-body p {
    margin-bottom: 1.25rem;
    line-height: 1.7;
    font-size: 1rem;
}

#article-body a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s;
}

#article-body a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

#article-body ul, #article-body ol {
    margin-bottom: 1.25rem;
    padding-left: 2rem;
}

#article-body li {
    margin-bottom: 0.5rem;
    line-height: 1.7;
}

#article-body li::marker {
    color: var(--primary-color);
}

/* Code Blocks */
#article-body pre {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1.25rem;
    overflow-x: auto;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    transition: background-color 0.3s, border-color 0.3s;
}

#article-body code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Droid Sans Mono', 'Source Code Pro', monospace;
    font-size: 0.9em;
}

#article-body pre code {
    background: none;
    padding: 0;
    color: var(--text-color);
    line-height: 1.6;
}

#article-body p code, #article-body li code {
    background: var(--bg-secondary);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    color: var(--secondary-color);
    font-size: 0.9em;
    border: 1px solid var(--border-color);
}

/* Blockquotes */
#article-body blockquote {
    background: var(--quote-bg);
    border-left: 4px solid var(--quote-border);
    padding: 1rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: 4px;
    font-style: italic;
}

#article-body blockquote p {
    margin-bottom: 0.5rem;
}

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

/* Images */
#article-body img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 1.5rem 0;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

/* Tables */
#article-body table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 1.5rem 0;
    box-shadow: var(--shadow);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

#article-body thead {
    background: var(--bg-secondary);
}

#article-body th {
    padding: 0.75rem;
    text-align: left;
    font-weight: 700;
    color: var(--text-color);
    font-size: 0.875rem;
    border-bottom: 2px solid var(--border-color);
}

#article-body td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

#article-body tbody tr:hover {
    background: var(--bg-secondary);
}

#article-body tbody tr:last-child td {
    border-bottom: none;
}

/* Footer */
footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    margin-top: 4rem;
    text-align: center;
    color: var(--text-light);
    transition: background-color 0.3s, border-color 0.3s, color 0.3s;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }

    header .container {
        padding: 0.75rem 1rem;
    }

    .logo {
        font-size: 1.1rem;
    }

    header nav {
        gap: 0.75rem;
    }

    header nav a {
        font-size: 0.875rem;
    }

    .theme-toggle {
        min-width: 32px;
        min-height: 32px;
        padding: 0.4rem;
    }

    .theme-toggle svg {
        width: 16px;
        height: 16px;
    }

    .article-layout {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        padding: 1rem 0 2rem;
    }

    .toc-sidebar {
        display: none;
    }

    .hero {
        padding: 2rem 0 1.5rem;
    }

    .hero h2 {
        font-size: 1.5rem;
    }

    .hero p {
        font-size: 1rem;
    }

    .articles-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem 0 2rem;
    }

    .article-card-content {
        padding: 1.25rem;
    }

    .article-card h3 {
        font-size: 1.1rem;
    }

    #article-header {
        margin-bottom: 1.5rem;
    }

    #article-header h1 {
        font-size: 1.5rem;
    }

    #article-body h2 {
        font-size: 1.25rem;
        margin-top: 1.5rem;
    }

    #article-body h3 {
        font-size: 1.1rem;
        margin-top: 1.25rem;
    }

    #article-body h4 {
        font-size: 1rem;
    }

    #article-body pre {
        padding: 1rem;
        font-size: 0.85em;
        border-radius: 4px;
    }

    #article-body table {
        font-size: 0.875rem;
    }

    #article-body th,
    #article-body td {
        padding: 0.5rem;
    }
}

