/* Base Styles & Variables */
:root {
    /* Light Mode Variables (Default) */
    --primary-color: #2563eb;       
    --secondary-color: #1e40af;     
    --text-color: #333333;
    --bg-color: #f9fafb;            
    --container-bg: #ffffff;
    --code-bg: #1e1e1e;             
    --code-text: #d4d4d4;           
    --border-color: #e5e7eb;
    --blockquote-bg: #eff6ff;
    --blockquote-text: #1e3a8a;
    --table-stripe: #f9fafb;
    --th-bg: #f3f4f6;
    --th-text: #374151;
}

/* Dark Mode Overrides */
body.dark-mode {
    --primary-color: #60a5fa;       /* Lighter blue for dark bg */
    --secondary-color: #93c5fd;     
    --text-color: #e5e7eb;          /* Light gray text */
    --bg-color: #111827;            /* Very dark blue/gray bg */
    --container-bg: #1f2937;        /* Dark gray container */
    --code-bg: #111827;             /* Darker code block */
    --code-text: #e5e7eb;           
    --border-color: #374151;
    --blockquote-bg: #1e3a8a;       /* Dark blue blockquote */
    --blockquote-text: #dbeafe;
    --table-stripe: #374151;
    --th-bg: #111827;
    --th-text: #e5e7eb;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    margin: 0;
    padding: 0;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    max-width: 900px;
    margin: 40px auto;
    padding: 40px;
    background-color: var(--container-bg);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border-radius: 8px;
    position: relative; /* For positioning theme toggle */
    transition: background-color 0.3s;
}

/* Theme Toggle Button */
.theme-switch-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 20px;
}

.theme-btn {
    background-color: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.theme-btn:hover {
    background-color: var(--border-color);
}

/* Headings */
h1, h2, h3, h4 {
    color: var(--text-color); /* Changed to var for dark mode support */
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
}

h1 {
    font-size: 2.25rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.3em;
    margin-top: 0;
}

h2 {
    font-size: 1.8rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
}

h3 {
    font-size: 1.5rem;
}

h4 {
    font-size: 1.25rem;
    color: var(--primary-color); /* Updated to use var */
}

/* Paragraphs & Lists */
p { margin-bottom: 1.25em; }
ul, ol { margin-bottom: 1.25em; padding-left: 2em; }
li { margin-bottom: 0.5em; }

/* Code Blocks & Inline Code */
code {
    background-color: rgba(128, 128, 128, 0.15); /* Transparent grey for adaptation */
    color: #db2777; /* Pinkish red */
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-family: "Menlo", "Monaco", "Consolas", "Courier New", monospace;
    font-size: 0.9em;
}

/* Override color for inline code in dark mode if needed, usually pink is fine */
body.dark-mode code {
    color: #f472b6;
}

pre {
    background-color: var(--code-bg);
    color: var(--code-text);
    padding: 1.5em;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1.5em;
    position: relative; /* Essential for copy button positioning */
    border: 1px solid var(--border-color);
}

pre code {
    background-color: transparent;
    color: inherit;
    padding: 0;
    font-size: 0.95em;
}

/* Copy Button Styling */
.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8rem;
    cursor: pointer;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.2s, background-color 0.2s;
}

pre:hover .copy-btn {
    opacity: 1; /* Show on hover */
}

.copy-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.copy-btn.copied {
    background-color: #10b981; /* Green success color */
    border-color: #10b981;
}

/* Images */
.responsive-img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 20px auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

/* Blockquotes */
blockquote {
    border-left: 4px solid var(--primary-color);
    background-color: var(--blockquote-bg);
    margin: 1.5em 0;
    padding: 1em 1.5em;
    border-radius: 0 4px 4px 0;
    color: var(--blockquote-text);
}

blockquote strong {
    color: var(--primary-color);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2em;
    font-size: 0.95rem;
}

thead {
    background-color: var(--th-bg);
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: 600;
    color: var(--th-text);
}

tr:hover {
    background-color: var(--table-stripe); /* Subtle stripe on hover */
}

/* Links */
a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px dotted var(--primary-color);
}

a:hover {
    color: var(--secondary-color);
    border-bottom: 1px solid var(--secondary-color);
}

/* Divider */
hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 3em 0;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 4em;
    padding-top: 2em;
    border-top: 1px solid var(--border-color);
    color: var(--text-color);
    opacity: 0.7;
    font-size: 0.9rem;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        padding: 20px;
        margin: 20px auto;
        width: 90%;
    }
    
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.5rem; }
    
    table {
        display: block;
        overflow-x: auto;
    }

    /* Always show copy button on mobile since there is no hover */
    .copy-btn {
        opacity: 1; 
    }
}
