:root {
    --bg-color: #ffffff;
    --text-color: #333333;
    --sidebar-bg: #f4f4f4;
    --sidebar-border: #e0e0e0;
    --link-color: #0066cc;
    --header-bg: #efefef;
    --code-bg: #f5f5f5;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --sidebar-bg: #252525;
    --sidebar-border: #333;
    --link-color: #66b3ff;
    --header-bg: #2d2d2d;
    --code-bg: #333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    /* force zero y-scroll to work around mobile Chrome issues */
    position: fixed;
    width: 100%;
    top: 0;
}

/* Header */
header {
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--sidebar-border);
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px;
    flex-shrink: 0;
}

header img {
    height: calc(50px - 1rem);
    margin-right: 15px;
}

.header-title { font-weight: bold; font-size: 1.1rem; }

.controls { display: flex; gap: 10px; align-items: center; }

button, header a {
  cursor: pointer;
  padding: 7px 10px;
  border: 1px solid var(--sidebar-border);
  background: var(--bg-color);
  color: var(--text-color);
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.9em;
  margin: 0; 
}

header .header-buttons {
  display: flex;
  flex-wrap: nowrap;
}

/* Layout */
.container {
    display: flex;
    flex: 1;
    overflow: hidden; /* Prevent body scroll, allow inner scroll */
}

/* Sidebar ToC */
.sidebar {
    width: 300px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    overflow-y: auto;
    padding: 1rem;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.toc-link { display: block; text-decoration: none; color: var(--text-color); margin-bottom: 0.4rem; font-size: 0.95rem; }
.toc-link:hover { color: var(--link-color); text-decoration: underline; }
.toc-h1 { font-weight: bold; margin-top: 1rem; }
.toc-h2 { margin-left: 1rem; font-size: 0.9rem; }
.toc-h3 { margin-left: 2rem; font-size: 0.85rem; color: var(--text-color); opacity: 0.8; }
.toc-active { color: var(--link-color); font-weight: bold; }

/* Main Content */
main {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    scroll-padding-top: 20px;
}

.content-wrapper {
    max-width: 800px; /* Readable max-width */
    margin: 0 auto;
    line-height: 1.6;
}

a { color: var(--link-color); }
img { max-width: 100%; height: auto; }

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 100;
        transform: translateX(-100%); /* Hidden by default */
        padding-bottom: 4rem;
    }

    .header-title { font-size: 0.9rem; }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 2px 0 5px rgba(0,0,0,0.2);
    }

    #menu-toggle { display: block; }
}

@media (min-width: 769px) {
    #menu-toggle { display: none; }
}
