:root {
    --heading-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --body-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    /* Light Theme */
    --bg-main: #f5f5f5;
    --bg-container: #fdfdfa;
    --bg-header: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --accent-primary: #d95d39;
    --accent-light: #fdeee8;
    --border-color: #eee;
    --img-shadow: rgba(0, 0, 0, 0.1);
}

/* --- Dark Mode Variables --- */
body.dark-mode {
    --bg-main: #121212;
    --bg-container: #1e1e1e;
    --bg-header: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #aaaaaa;
    --accent-primary: #e87957; /* Slightly brighter accent for dark bg */
    --accent-light: #3a2e29;
    --border-color: #2e2e2e;
    --img-shadow: rgba(0, 0, 0, 0.4);
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--body-font);
    background: var(--bg-main);
    color: var(--text-primary);
    transition: background-color 0.3s, color 0.3s;
}

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

header {
    width: 100%;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-header);
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    min-height: 64px;
    transition: background-color 0.3s, border-color 0.3s;
}

.header-right-group {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.logo {
    font-family: var(--heading-font);
    font-weight: bold;
    font-size: 1.5rem;
    letter-spacing: 2px;
    color: var(--accent-primary);
    text-decoration: none;
}

nav {
    display: flex;
    gap: 1.5rem; /* This adds space between the nav links */
}

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

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

#theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

    #theme-toggle:hover {
        color: var(--accent-primary);
        background-color: var(--accent-light);
    }

    #theme-toggle svg {
        width: 22px;
        height: 22px;
    }

/* CORRECTED ICON LOGIC: Show the icon for the theme you will switch TO. */
.sun-icon {
    display: none;
}

.moon-icon {
    display: block;
}

body.dark-mode .sun-icon {
    display: block;
}

body.dark-mode .moon-icon {
    display: none;
}


.container {
    display: flex;
    max-width: 600px;
    width: 100%;
    margin: 2.5rem auto;
    gap: 3.5rem;
    padding: 0 1rem;
    align-items: flex-start;
    background-color: var(--bg-container);
}

.main-content {
    flex: 3;
    min-width: 0;
    overflow-wrap: break-word;
    max-width: 560px;
}

.aside-toc {
    flex: 1;
    position: sticky;
    top: 100px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    max-width: 25ch;
}

.toc-title {
    font-family: var(--heading-font);
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    border-left: 2px solid var(--border-color);
}

    .toc-list a {
        display: block;
        padding: 0.5rem 1rem;
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 0.95rem;
        transition: all 0.2s ease-in-out;
        border-left: 2px solid transparent;
        margin-left: -2px;
    }

        .toc-list a:hover {
            background-color: var(--accent-light);
            color: var(--accent-primary);
        }

        .toc-list a.active {
            color: var(--accent-primary);
            font-weight: 700;
            border-left-color: var(--accent-primary);
            background-color: var(--accent-light);
        }

    .toc-list .toc-h3 a {
        padding-left: 2rem;
    }

.breadcrumbs {
    font-size: 0.98rem;
    color: var(--text-secondary);
    margin-bottom: 0.7rem;
}

    .breadcrumbs a {
        color: var(--accent-primary);
        text-decoration: none;
    }

        .breadcrumbs a:hover {
            text-decoration: underline;
        }

h1, h2, h3 {
    font-family: var(--heading-font);
    color: var(--text-primary);
}

h1 {
    font-size: 2.8rem;
    margin: 0 0 0.7rem 0;
}

h2 {
    font-size: 2rem;
    margin: 3rem 0 1.5rem 0;
    padding-top: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

h3 {
    font-size: 1.5rem;
    margin: 2rem 0 1rem 0;
}

.meta {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 2rem;
    max-width: 65ch;
    line-height: 1.6;
}

p {
    font-size: 1.1rem;
    line-height: 1.7;
    margin: 0 0 1.5em 0;
    max-width: 65ch;
}

/* --- General Link Styles for Main Content --- */
.meta a,
td a,
.main-content p a,
.main-content ol a,
.main-content ul a {
    color: var(--accent-primary);
    text-decoration: underline;
    transition: color 0.2s;
}
    .meta a,
    td a,
    .main-content p a:hover,
    .main-content ol a:hover,
    .main-content ul a:hover {
        text-decoration-thickness: 2px;
    }

.main-content ul {
    list-style: none;
    padding-left: 0;
    margin: 1.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

    .main-content ul li {
        position: relative;
        padding: 1rem 1rem 1rem 2.5rem;
        background: var(--accent-light);
        border-left: 4px solid var(--accent-primary);
        border-radius: 8px;
        line-height: 1.6;
    }

        .main-content ul li::before {
            content: "→";
            position: absolute;
            left: 1rem;
            color: var(--accent-primary);
            font-weight: bold;
            font-size: 1.2rem;
        }

img {
    max-width: 100%;
    height: auto;
    display: block;
    margin-bottom: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--img-shadow);
}

.callout {
    display: flex;
    align-items: flex-start;
    background: #fffbf5;
    border: 2px solid var(--accent-primary);
    border-radius: 12px;
    padding: 1.5rem;
    margin: 2rem 0;
    box-shadow: 0 4px 16px rgba(217, 93, 57, 0.08);
    font-size: 1rem;
    max-width: 65ch;
    position: relative;
}

.callout-icon {
    margin-right: 1em;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.callout::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent-primary);
    border-radius: 12px 12px 0 0;
}

.callout-content {
    font-family: inherit;
    font-size: 1.1em;
    color: #2d1810;
}

body.dark-mode .callout {
    background: #2a1f1a;
    border-color: var(--accent-primary);
    box-shadow: 0 4px 16px rgba(232, 121, 87, 0.12);
}

body.dark-mode .callout-content {
    color: #f5e6dc;
}

/* Table stays within column width */
.table-wrapper {
    width: 100%;
    max-width: 560px;
    margin: 2rem auto;
    border-radius: 14px;
    box-shadow: 0 2px 16px rgba(60, 60, 60, 0.10);
    overflow: hidden;
    position: relative;
    cursor: pointer;
    transition: box-shadow 0.3s, transform 0.2s;
}

    .table-wrapper:hover {
        box-shadow: 0 4px 20px rgba(60, 60, 60, 0.15);
        transform: translateY(-2px);
    }

/* Expand button overlay */
.table-expand-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: background-color 0.2s;
}

    .table-expand-btn:hover {
        background: #c54d2f;
    }

    .table-expand-btn svg {
        width: 16px;
        height: 16px;
    }

/* Modal/Overlay */
.table-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    padding: 2rem;
    overflow: auto;
    animation: fadeIn 0.2s ease;
}

    .table-modal.active {
        display: flex;
        align-items: center;
        justify-content: center;
    }

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.table-modal-content {
    background: var(--bg-container);
    border-radius: 16px;
    max-width: 1200px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    position: relative;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.table-modal-close {
    position: sticky;
    top: 0;
    right: 0;
    background: var(--accent-primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1rem 1rem 0 auto;
    z-index: 10;
    transition: background-color 0.2s;
}

    .table-modal-close:hover {
        background: #c54d2f;
    }

.table-modal table {
    margin: 0;
    font-size: 1rem;
}

/* Mobile keeps card layout */
@media (max-width: 768px) {
    .table-expand-btn {
        display: none;
    }

    .table-wrapper {
        cursor: default;
        box-shadow: none;
    }

        .table-wrapper:hover {
            transform: none;
        }

    /* Keep your existing mobile card styles */
    .table-wrapper {
        width: 100%;
        margin-left: 0;
        transform: none;
        padding: 0;
        overflow-x: visible;
    }

    table thead {
        display: none;
    }

    table, tbody, tr, td {
        display: block;
        width: 100%;
    }

        tbody tr {
            margin-bottom: 1.5rem;
            border: 1px solid var(--border-color);
            border-radius: 12px;
            padding: 1.25rem;
            background: var(--bg-header);
            box-shadow: 0 2px 8px var(--img-shadow);
        }

    td {
        padding: 0.75rem 0;
        border-bottom: 1px solid var(--border-color);
        text-align: left;
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

        td:last-child {
            border-bottom: none;
        }

        td::before {
            content: attr(data-label);
            font-weight: 700;
            color: var(--accent-primary);
            font-size: 0.85rem;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
}

/* Dark mode adjustments */
body.dark-mode .table-wrapper {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

body.dark-mode .table-modal {
    background: rgba(0, 0, 0, 0.92);
}


.table-modal .table-wrapper {
    max-width: 100%;
    width: 100%;
    cursor: default;
    box-shadow: none;
}

    .table-modal .table-wrapper:hover {
        transform: none;
    }

.table-modal .table-expand-btn {
    display: none;
}

/* Keep dark mode styles */
body.dark-mode .table-wrapper {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

@media (max-width: 900px) {
    .table-wrapper {
        padding: 0 1rem;
    }
}

/***************************/

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: #fff;
    color: #222;
    border-radius: 14px;
    overflow: hidden;
    /* The shadow is now on the wrapper, so we remove it from the table itself for consistency */
    /* box-shadow: 0 2px 16px rgba(60, 60, 60, 0.10); */
    margin-bottom: 0; /* Margin is on the wrapper now */
    font-family: 'Segoe UI', 'Arial', sans-serif;
    transition: background-color 0.3s, color 0.3s;
}

thead {
    background: #f4f6f8;
    transition: background-color 0.3s;
}

th,
td {
    padding: 1rem 1.5rem;
    text-align: left;
    vertical-align: middle;
}

th {
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    border-bottom: 2px solid #e0e3e7;
    transition: border-color 0.3s;
}

tbody tr {
    transition: background 0.2s;
}

    tbody tr:nth-child(even) {
        background: #f7fafd;
    }

    tbody tr:nth-child(odd) {
        background: #fff;
    }

    tbody tr:hover {
        background: #eaf4ff;
    }

td {
    border-bottom: 1px solid #f0f0f0;
    transition: border-color 0.3s;
}

/* --- Dark Mode Table Styles --- */
body.dark-mode .table-wrapper {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

body.dark-mode table {
    background: var(--bg-header);
    color: var(--text-primary);
}

body.dark-mode thead {
    background: #2a2a2a;
}

body.dark-mode th {
    border-bottom-color: #4a4a4a;
}

body.dark-mode tbody tr:nth-child(even) {
    background: var(--bg-main);
}

body.dark-mode tbody tr:nth-child(odd) {
    background: var(--bg-header);
}

body.dark-mode tbody tr:hover {
    background: var(--accent-light);
}

body.dark-mode td {
    border-bottom-color: var(--border-color);
}

/* --- Styles for Mobile Nav Toggle --- */
#mobile-menu-toggle {
    display: none; /* Hidden by default on desktop */
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    color: var(--text-secondary);
    z-index: 1100; /* Ensure it's on top */
}

    #mobile-menu-toggle:hover {
        color: var(--accent-primary);
        background-color: var(--accent-light);
    }

    #mobile-menu-toggle .close-icon {
        display: none;
    }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 2rem;
    margin: 2rem 0;
    justify-items: center; /* center the card horizontally */
}

.card {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 2px 12px rgba(40, 40, 40, 0.06);
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s, background-color 0.3s;
    overflow: hidden;
    max-width: 340px; /* or whatever width you prefer */
    width: 100%;
}

    .card:hover {
        box-shadow: 0 6px 24px rgba(40, 40, 40, 0.13);
    }

.card-thumb {
    max-height: 200px; /* Adjust as needed */
    width: auto;
    object-fit: cover;
    display: block;
    margin: 0 auto;
}

.card-content {
    padding: 1.25rem;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

.main-content .card-title {
    margin: 0 0 0.6rem 0;
    font-size: 1.15rem;
    font-weight: bold;
    color: #ce5523; /* matches your header color */
    transition: color 0.3s;
}

.main-content .card-desc {
    margin: 0;
    color: #444;
    font-size: 0.98rem;
    line-height: 1.5;
    transition: color 0.3s;
}

/* --- Dark Mode Card Styles --- */
body.dark-mode .card {
    background: var(--bg-header);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

    body.dark-mode .card:hover {
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    }

body.dark-mode .main-content .card-title {
    color: var(--accent-primary);
}

body.dark-mode .main-content .card-desc {
    color: var(--text-secondary);
}


hr {
    border: none;
    height: 1px;
    background: linear-gradient(to right, #eee, #ccc, #eee);
    margin: 2em 0;
}

@media (max-width: 1024px) {
    .aside-toc {
        display: none;
    }
}

@media (max-width: 768px) {
    header {
        padding: 0 1rem;
    }

    /* Show the hamburger button */
    #mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Hide desktop nav and style mobile nav container */
    nav {
        display: none; /* Hide it by default */
        position: absolute;
        top: 63px; /* Position below header */
        left: 0;
        width: 100%;
        background: var(--bg-header);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
        flex-direction: column;
        gap: 0;
    }

        /* Show the nav when it's active */
        nav.is-active {
            display: flex;
        }

        /* Style the links inside the mobile nav */
        nav a {
            display: block;
            padding: 1rem 1.5rem;
            border-bottom: 1px solid var(--border-color);
            width: 100%;
            text-align: left;
        }

    /* Prevent body scrolling when menu is open */
    body.no-scroll {
        overflow: hidden;
    }

    .container {
        margin: 1rem 0;
        padding: 0 1rem;
    }

    h1 {
        font-size: 2.2rem;
    }

    p {
        font-size: 1rem;
    }

    .callout {
        flex-direction: column;
        padding: 1em 0.8em;
    }

    .callout-icon {
        margin-bottom: 0.5em;
        margin-right: 0;
    }
}

footer {
    width: 100%;
    background: var(--bg-header);
    color: var(--text-secondary);
    font-size: 1rem;
    text-align: center;
    padding: 2rem 1rem 1.5rem 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: 3rem;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

    footer a {
        color: var(--accent-primary);
        text-decoration: none;
        font-weight: 500;
        margin: 0 0.5rem;
        transition: color 0.2s;
    }

        footer a:hover {
            text-decoration: underline;
        }
