/* === THEME VARIABLES & DEFAULTS === */
:root {
    /* Default to Light Theme */
    --c-bg: #ffffff;
    --c-text: #333;
    --c-text-muted: #555;
    --c-link: #337ab7;
    --c-link-hover: #23527c;
    --c-heading: #2b2b2b;
    --c-border: #ddd;
    --c-toc-bg: #f8f8f8;
    --c-code-bg: #f0f0f0;
    --c-prop-setting-bg: #e6f0fA;
    --c-table-header-bg: #f2f2f2;
    --c-note-bg: #e7f4ff;
    --c-note-border: #4a90e2;
    --c-warning-bg: #fff3e0;
    --c-warning-border: #ff9800;
    --c-highlight-bg: rgba(255, 212, 0, 0.4);
    --c-search-result-header: #fffca2;
    --c-search-result-bg: #ffffff;
    --c-search-result-hover: #f8f8f8;
    --c-theme-toggle-icon: '☀️';
    /* --- NEW VARIABLE FOR IMAGE BACKGROUND --- */
    --c-image-matte-bg: #ffffff; 
}

html[data-theme="dark"] {
    /* Dark Theme Overrides */
    --c-bg: #121212;
    --c-text: #e0e0e0;
    --c-text-muted: #888;
    --c-link: #00aaff;
    --c-link-hover: #33bbff;
    --c-heading: #ffffff;
    --c-border: #333;
    --c-toc-bg: #1e1e1e;
    --c-code-bg: #2a2a2a;
    --c-prop-setting-bg: #1d2a3d;
    --c-table-header-bg: #282828;
    --c-note-bg: rgba(0, 170, 255, 0.1);
    --c-note-border: #00aaff;
    --c-warning-bg: rgba(255, 152, 0, 0.1);
    --c-warning-border: #ff9800;
    --c-highlight-bg: rgba(0, 170, 255, 0.3);
    --c-search-result-header: #3a3a2a;
    --c-search-result-bg: #252525;
    --c-search-result-hover: #303030;
    --c-theme-toggle-icon: '🌙';
    /* --- NEW VARIABLE FOR IMAGE BACKGROUND (DARK) --- */
    --c-image-matte-bg: #2a2a2a; /* Use the same color as code blocks for consistency */
}
/* --- END THEME VARIABLES --- */

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--c-text);
    background-color: var(--c-bg);
    margin: 0;
    padding: 0;
    transition: background-color 0.2s ease, color 0.2s ease;
}


.page-container {
    display: flex;
    width: 100%;
}

/* --- TOC Container Styles --- */
#toc {
    width: 280px;
    flex-shrink: 0;
    padding: 20px;
    border-right: 1px solid var(--c-border);
    height: 100vh;
    overflow-y: auto;
    position: sticky;
    top: 0;
    background-color: var(--c-toc-bg);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

#toc h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.2em;
    color: var(--c-heading);
    border-bottom: 1px solid var(--c-border);
    padding-bottom: 5px;
}

#toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

#toc li {
    margin-bottom: 5px;
}

#toc ul ul,
#toc details ul {
    padding-left: 15px;
    margin-top: 5px;
    margin-bottom: 5px;
}

/* --- THEME TOGGLE BUTTON --- */
#theme-toggle {
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 15px;
    background-color: var(--c-code-bg);
    border: 1px solid var(--c-border);
    color: var(--c-text);
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.2s ease;
}
#theme-toggle:hover {
    background-color: var(--c-border);
}
#theme-toggle::before {
    content: var(--c-theme-toggle-icon);
    margin-right: 10px;
    font-size: 1.2em;
    display: inline-block;
    width: 1.2em;
    text-align: center;
}

/* --- Link Styles by Level (Complete) --- */
#toc a {
    text-decoration: none;
    display: block;
    padding: 2px 0;
    transition: color 0.2s ease;
}
#toc a:hover {
    text-decoration: underline;
}
#toc > ul > li > a {
    font-size: 1em;
    font-weight: 600;
    color: var(--c-link);
    padding-bottom: 4px;
}
#toc > ul > li > a:hover {
    color: var(--c-link-hover);
}
#toc > ul > li > ul > li > a {
    font-size: 0.95em;
    font-weight: normal;
    color: var(--c-link);
    opacity: 0.9;
    padding-left: 5px;
}
#toc > ul > li > ul > li > a:hover {
    color: var(--c-link-hover);
    opacity: 1;
}
#toc > ul > li > ul > li summary a {
    display: inline-block;
    font-size: 0.95em;
    font-weight: normal;
    color: var(--c-link);
    opacity: 0.9;
    vertical-align: middle;
}
#toc > ul > li > ul > li summary a:hover {
    color: var(--c-link-hover);
    text-decoration: underline;
    opacity: 1;
}
#toc > ul > li ul ul li a {
    font-size: 0.9em;
    font-weight: normal;
    color: var(--c-text);
    opacity: 0.8;
    padding-left: 10px;
}
#toc > ul > li ul ul li a:hover {
    color: var(--c-text);
    opacity: 1;
}

/* --- <details> / <summary> Styles --- */
#toc summary {
    cursor: pointer;
    list-style: none;
    display: block;
    padding: 2px 0;
    padding-left: 5px;
}
#toc summary::-webkit-details-marker,
#toc summary::marker {
    display: none;
    content: '';
}
#toc summary .toggle-icon {
    display: inline-block;
    width: 1.2em;
    text-align: center;
    font-size: 0.8em;
    font-weight: bold;
    color: var(--c-text-muted);
    vertical-align: middle;
}
#toc details:not([open]) > summary .toggle-icon::before {
    content: '[+]';
}
#toc details[open] > summary .toggle-icon::before {
    content: '[-]';
}

/* --- Main Content Styles --- */
#content {
    flex-grow: 1;
    padding: 20px 40px;
    max-width: 1200px;
}

.body_link {
    font-weight: normal;
    color: var(--c-link);
}
.body_link:hover {
    text-decoration: underline;
    color: var(--c-link-hover);
}

h1, h2, h3, h4 {
    color: var(--c-heading);
    margin-top: 30px;
}
h1 {
    border-bottom: 2px solid var(--c-heading);
    padding-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
h2 {
    border-bottom: 1px solid var(--c-border);
    padding-bottom: 5px;
}

/* --- Code & UI Elements --- */
.ui-element {
    background-color: var(--c-code-bg);
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid var(--c-border);
    font-family: monospace;
}
.prop-setting {
    background-color: var(--c-prop-setting-bg);
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid var(--c-border);
    font-family: monospace;
}
code.ui-element a,
code.prop-setting a {
    color: var(--c-link);
    text-decoration: none;
}
code.ui-element a:hover,
code.prop-setting a:hover {
    text-decoration: underline;
    color: var(--c-link-hover);
}

/* --- Notes & Warnings --- */
.note {
    background-color: var(--c-note-bg);
    border-left: 4px solid var(--c-note-border);
    padding: 10px 15px;
    margin: 15px 0;
}
.warning {
    background-color: var(--c-warning-bg);
    border-left: 4px solid var(--c-warning-border);
    padding: 10px 15px;
    margin: 15px 0;
}

/* --- Images & Icons --- */
img {
    max-width: 100%;
    height: auto;
}
.align-center {
    display: block;
    margin: 10px auto;
    padding: 0;
    border-radius: 10px;
    border: 7px solid var(--c-border);
    border-style: ridge;
}
.imageflex {
    display: flow-root;
    margin-bottom: 25px;
    width: 100%;
}

/* --- MODIFIED .resizable-image --- */
.resizable-image {
    float: right;
    margin-left: 25px;
    margin-bottom: 10px;
    max-width: 45%;
    border: 1px solid var(--c-border);
    /* --- NEW PROPERTIES --- */
    background-color: var(--c-image-matte-bg); /* Apply the theme-aware background */
    padding: 5px; /* Adds space around the image for the matte to be visible */
    border-radius: 8px; /* Give it soft corners */
    box-sizing: border-box; /* Ensures padding is included in the element's total width */
}
/* --- END MODIFICATION --- */


.inline-icon {
    vertical-align: -0.2em;
    margin: 0 3px;
    height: 1em;
    border: none;
}
.icon-text-group {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}
.icon-text-group .icon {
    margin-right: 5px;
    height: 1.1em;
    border: none;
    vertical-align: middle;
}


.brand-logo {
    height: 1.3em;
    display: inline-block;
    vertical-align: middle;
    border: none;
}

.header-logo {
    display: inline-block; /* Changed for box model control */
    height: 1.3em;         /* This will be the height of the image content */
    width: auto;
    margin-left: 1em;
    vertical-align: middle;

    /* New styles to create the padded matte effect */
    background-color: var(--c-code-bg); /* Use the theme's code background color */
    padding: 1px 2px;                  /* Add space around the logo */
    border: 1px solid var(--c-border);    /* Use the theme's border color */
    border-radius: 6px;                 /* A subtle corner radius */
    box-sizing: content-box;            /* Ensures padding adds to the total size */
}


/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}
th, td {
    border: 1px solid var(--c-border);
    padding: 8px 12px;
    text-align: left;
    vertical-align: top;
}
th {
    background-color: var(--c-table-header-bg);
}

/* --- Operator Reference Table --- */
#operator-reference .operator {
    margin-left: 5px;
    font-weight: 500;
}
#operator-reference small {
    display: block;
    font-size: 0.85em;
    color: var(--c-text-muted);
    margin-top: 3px;
}

/* --- Search Styles --- */
#search-container {
    position: relative;
    margin: 1rem 0;
}
#search-input {
    width: 100%;
    padding: 8px 12px;
    padding-right: 30px;
    border: 1px solid var(--c-border);
    background-color: var(--c-bg);
    color: var(--c-text);
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}
#search-clear-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--c-text-muted);
    font-size: 1.2em;
    z-index: 10;
    display: none;
}
#search-results {
    display: none;
    position: absolute;
    width: 100%;
    max-height: 60vh;
    overflow-y: auto;
    background: var(--c-search-result-bg);
    border: 1px solid var(--c-border);
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 1000;
    margin-top: 5px;
    padding: 0;
    list-style: none;
}
.result-page-header {
    padding: 8px 12px;
    background-color: var(--c-search-result-header);
    font-weight: 600;
    color: #333; /* Keep text dark for yellow background */
    position: sticky;
    top: 0;
    border-bottom: 1px solid var(--c-border);
    z-index: 10;
    margin: 0;
}
#search-results a {
    display: block;
    padding: 10px 15px;
    color: var(--c-text);
    text-decoration: none;
    border-bottom: 1px solid var(--c-border);
}
#search-results a:hover {
    background-color: var(--c-search-result-hover);
}
.section-title {
    display: block;
    font-weight: 500;
    color: var(--c-heading);
    margin-bottom: 4px;
}
.excerpt {
    display: block;
    font-size: 0.85em;
    color: var(--c-text-muted);
    line-height: 1.4;
}
mark {
    background-color: var(--c-highlight-bg);
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}

/* --- Footer --- */
footer {
    padding: 15px;
    text-align: center;
    font-size: 0.9em;
    color: var(--c-text-muted);
    margin-top: auto;
    border-top: 1px solid var(--c-border);
    background-color: var(--c-toc-bg); /* Match TOC background */
}