:root {
    --bg-color: #f0f7ff; /* Very Light Pastel Blue */
    --page-bg: #ffffff;
    --sidebar-bg: #e0f2fe; /* Slightly deeper Pastel Blue */
    --accent-primary: #3b82f6;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-soft: rgba(59, 130, 246, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    line-height: 1.7;
    color: var(--text-main);
    background-color: var(--page-bg);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

#layout {
    display: flex;
    min-height: 100vh;
    position: relative;
    background-color: var(--page-bg);
}

/* Toggle Button - Visible everywhere */
#toggle-btn {
    display: block; /* Show on Desktop and Mobile */
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 300; /* Higher than sidebar z-index */
    background: white;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 8px 12px;
    color: var(--text-main);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

#toggle-btn:hover {
    background-color: var(--sidebar-bg);
    color: var(--accent-primary);
}

#sidebar-overlay {
    display: none;
}

/* Sidebar - Permanent on Desktop */
/* Sidebar - Collapsible on Desktop */
#sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-soft);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    padding: 70px 16px 20px 16px;
    flex-shrink: 0;
    z-index: 10;
    transition: width 0.3s ease, opacity 0.3s ease;
    will-change: width;
}

#sidebar.collapsed {
    width: 0;
    opacity: 0;
}

/* All sidebar rows share the same size, padding, and radius */
--sidebar-row-px: 10px;
--sidebar-font:   0.82rem;

.sidebar-section {
    margin-bottom: 2px;
}

.subject-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.subject-header:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

/* Reset h3 so it matches the home-link and search text */
.subject-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1;
}

.subject-header h3 a {
    color: var(--text-main);
    text-decoration: none;
}

.toggle-arrow {
    font-size: 0.6rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.sidebar-topics {
    padding: 2px 0 6px 10px;
}

.sidebar-topics a {
    display: block;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 0.95rem;
    text-decoration: none;
    color: var(--text-muted);
    line-height: 1.35;
    transition: background-color 0.15s, color 0.15s;
}

.sidebar-topics a.active-topic {
    color: var(--accent-primary);
    font-weight: 500;
    background-color: rgba(59, 130, 246, 0.07);
}

.sidebar-topics a:hover {
    background-color: rgba(59, 130, 246, 0.07);
    color: var(--accent-primary);
}

/* Main Content Area */
#main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 60px 40px;
    background-color: var(--page-bg);
    width: 100%;
    min-height: 100vh;
    overflow-x: hidden;
    min-width: 0;
}

#main-wrapper main {
    flex: 1;
}

header {
    margin-bottom: 30px;
}

h1, h2, h3 {
    font-weight: 600;
    margin-top: 1.2em;
    margin-bottom: 0.5em;
}

h1 {
    font-size: 1.4rem;
    margin-top: 0;
}

h2 {
    font-size: 1.25rem;
}

h3 {
    font-size: 1.1rem;
}

a {
    color: #1a1a1a;
    text-underline-offset: 2px;
}

section {
    margin-bottom: 30px;
}

footer {
    margin-top: 60px;
    font-size: 0.75rem;
    color: #888;
    border-top: 1px solid #eee;
    padding: 20px 0;
    text-align: center;
}

.meta {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 15px;
}

.page-index {
    background-color: #f9f9f9;
    padding: 12px 15px;
    margin: 20px 0;
    border-left: 3px solid #eee;
}

.page-index p {
    margin-top: 0;
    margin-bottom: 5px;
    font-size: 0.85rem;
}

.page-index ul {
    margin-bottom: 0;
    font-size: 0.85rem;
}

.minimal-divider {
    border: 0;
    border-top: 1px solid #eee;
    margin: 30px 0;
}

.meta-list {
    list-style: none;
    padding-left: 0;
    font-size: 0.85rem;
    color: #444;
}

.meta-list li {
    margin-bottom: 8px;
}

.setup-option {
    border: 1px solid #eee;
    padding: 12px;
    margin-bottom: 15px;
    font-size: 0.85rem;
}

.setup-option strong {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.minimal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin: 20px 0;
}

.minimal-table th, .minimal-table td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
}

.minimal-table th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    color: #888;
}

.minimal-table tr:nth-child(even) {
    background-color: #fafafa;
}

/* Card & Content Blocks */
.content-block {
    margin-bottom: 40px;
}

.card {
    border: 1px solid var(--border-soft);
    padding: 24px;
    margin-bottom: 20px;
    background-color: #fff;
    width: 100%;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

.card h4 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.example-box {
    background-color: #fcfcfc;
    border-left: 3px solid #1a1a1a;
    padding: 10px 15px;
    margin: 15px 0;
    font-size: 0.85rem;
}

.code-block,
pre.ql-syntax {
    background-color: #f0f4ff;
    color: #3730a3;
    padding: 18px 20px;
    font-family: 'JetBrains Mono', 'Fira Code', 'SFMono-Regular', Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.65;
    overflow-x: auto;
    margin: 20px 0;
    border-radius: 10px;
    border: 1px solid #c7d2fe;
    border-left: 3px solid #818cf8;
}

/* ── Topic content — prevent horizontal overflow ─────────────────────────── */
.topic-content {
    overflow-x: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
}

.topic-content img {
    max-width: 100%;
    height: auto;
}

/* MathJax display equations — scroll horizontally if too wide, don't break layout */
.topic-content .MathJax,
.topic-content mjx-container {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    display: block;
}

/* ── Image captions ──────────────────────────────────────────────────────────── */
.topic-content .img-caption,
.content-block .img-caption {
    text-align: center;
    font-size: 0.85rem;
    color: #64748b;
    font-style: italic;
    margin-top: 4px;
    margin-bottom: 18px;
    line-height: 1.5;
}

/* ── Tables (public topic pages) ──────────────────────────────────────────── */
.topic-content .ql-table-wrap,
.content-block .ql-table-wrap {
    overflow-x: auto;
    margin: 20px 0;
}

.topic-content .ql-table-wrap table,
.content-block .ql-table-wrap table,
.topic-content table,
.content-block table {
    border-collapse: collapse;
    width: 100%;
    margin: 20px 0;
    font-size: 0.9rem;
    border: 1px solid #cbd5e1;
}

.topic-content table th,
.topic-content table td,
.content-block table th,
.content-block table td,
.topic-content .ql-table-wrap th,
.topic-content .ql-table-wrap td,
.content-block .ql-table-wrap th,
.content-block .ql-table-wrap td {
    border: 1px solid #cbd5e1;
    padding: 9px 14px;
    text-align: left;
    vertical-align: top;
}

.topic-content table th,
.content-block table th,
.topic-content .ql-table-wrap th,
.content-block .ql-table-wrap th {
    background: #eff6ff;
    color: #1e40af;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
}

.topic-content table tr:nth-child(even) td,
.content-block table tr:nth-child(even) td,
.topic-content .ql-table-wrap tr:nth-child(even) td,
.content-block .ql-table-wrap tr:nth-child(even) td {
    background: #f8fafc;
}

.topic-content table tr:hover td,
.content-block table tr:hover td,
.topic-content .ql-table-wrap tr:hover td,
.content-block .ql-table-wrap tr:hover td {
    background: #f0f9ff;
}

/* Scrollable on small screens */
@media (max-width: 700px) {
    .topic-content table,
    .content-block table {
        display: block;
        overflow-x: auto;
    }
}

/* ── YouTube embeds (public view) ────────────────────────────────────────────── */
.topic-content .yt-embed-blot,
.content-block .yt-embed-blot {
    margin: 20px 0;
}
.topic-content .yt-embed-blot.yt-video,
.content-block .yt-embed-blot.yt-video {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}
.topic-content .yt-embed-blot.yt-video iframe,
.content-block .yt-embed-blot.yt-video iframe {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
}
.topic-content .yt-embed-blot.yt-short,
.content-block .yt-embed-blot.yt-short {
    width: 280px;
    height: 497px;
    margin: 20px auto;
}
.topic-content .yt-embed-blot.yt-short iframe,
.content-block .yt-embed-blot.yt-short iframe {
    width: 100%; height: 100%;
}
.topic-content .yt-embed-blot iframe,
.content-block .yt-embed-blot iframe {
    border: none;
    border-radius: 8px;
}

.output-block {
    background-color: #f8fafc;
    color: #475569;
    padding: 15px 20px;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    border-radius: 10px;
    border-left: 4px solid var(--accent-primary);
    margin: 20px 0;
}

.diagram-placeholder {
    display: flex;
    justify-content: center;
    padding: 10px;
    background-color: #fcfcfc;
    border: 1px dashed #eee;
    margin: 15px 0;
}

/* Content Flow - Page Look */
.content-block {
    margin-bottom: 60px;
}

.card {
    border: none;
    padding: 0;
    margin-bottom: 40px;
    background-color: transparent;
    width: 100%;
    border-radius: 0;
    box-shadow: none;
    transition: none;
}

.card:hover {
    transform: none;
    box-shadow: none;
}

.card h4 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-soft);
    padding-bottom: 8px;
}

/* Navigation Buttons */
.nav-buttons {
    margin: 60px 0;
}

.btn-minimal {
    display: inline-block;
    padding: 12px 24px;
    border: 1px solid var(--border-soft);
    background-color: var(--bg-color);
    color: var(--text-main);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    font-size: 0.9rem;
}

.btn-minimal:hover {
    background-color: #fff;
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(129, 140, 248, 0.15);
}

@media (max-width: 768px) {
    #sidebar {
        position: absolute;
        z-index: 100;
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: 280px;
        z-index: 200;
        background-color: var(--sidebar-bg);
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
        transform: translateX(0);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

    #sidebar.collapsed {
        transform: translateX(-100%);
        width: 280px; /* Keep width but hide via transform */
        opacity: 1;
        padding-left: 24px;
        padding-right: 24px;
    }

    #main-wrapper {
        padding: 80px 20px 40px 20px;
        width: 100%;
        max-width: 100% !important;
        min-height: 100vh;
    }

    #sidebar.collapsed + #main-wrapper {
        max-width: 100%;
        padding-left: 20px;
        margin: 0;
    }

    #toggle-btn {
        display: block !important; /* Force visible on mobile */
        left: 15px;
        top: 15px;
    }

    /* Add overlay when sidebar is open on mobile */
    .sidebar-open-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.2);
        z-index: 150;
        backdrop-filter: blur(4px);
    }

    .nav-buttons {
        flex-direction: column;
        gap: 10px;
    }

    .btn-minimal {
        text-align: center;
        width: 100%;
    }

    .home-subjects-grid { grid-template-columns: 1fr; }
    .home-tips-row      { flex-direction: column; gap: 16px; }
    .hero-title         { font-size: 1.8rem; }
}

/* ── Sidebar Home Link ───────────────────────────────────────────────────── */
.sidebar-home-link {
    display: flex;
    align-items: center;
    gap: 7px;
    text-decoration: none;
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 600;
    padding: 7px 10px;          /* same as .subject-header */
    border-radius: 6px;          /* same as .subject-header */
    margin-bottom: 4px;
    transition: background 0.15s, color 0.15s;
}
.sidebar-home-link svg {
    width: 13px;
    height: 13px;
    color: var(--accent-primary);
    flex-shrink: 0;
}
.sidebar-home-link:hover {
    background: rgba(59, 130, 246, 0.07);
    color: var(--accent-primary);
}

/* ── Sidebar Search ──────────────────────────────────────────────────────── */
.sidebar-search {
    padding: 4px 0 12px;        /* top gap matches row spacing */
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.09);
}
.sidebar-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.sidebar-search-icon {
    position: absolute;
    left: 10px;                  /* same left offset as row padding */
    width: 13px;
    height: 13px;
    color: #94a3b8;
    pointer-events: none;
    flex-shrink: 0;
}
.sidebar-search-input {
    width: 100%;
    padding: 7px 10px 7px 30px; /* 30px = icon(13) + gap */
    border: 1px solid rgba(59, 130, 246, 0.18);
    border-radius: 6px;          /* matches row radius */
    font-size: 1rem;             /* matches home link */
    background: rgba(255, 255, 255, 0.85);
    color: var(--text-main);
    outline: none;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}
.sidebar-search-input:focus {
    border-color: var(--accent-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.sidebar-search-input::placeholder { color: #94a3b8; }

/* ── Hero Section ────────────────────────────────────────────────────────── */
.hero-section {
    padding: 40px 0 44px;
    margin-bottom: 10px;
}
.hero-eyebrow {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent-primary);
    margin-bottom: 14px;
}
.hero-title {
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.035em;
    line-height: 1.15;
    margin-bottom: 14px;
}
.hero-sub {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.65;
    max-width: 480px;
    margin-bottom: 28px;
}
.hero-search-form  { max-width: 520px; }
.hero-search-wrap  {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1.5px solid rgba(59, 130, 246, 0.2);
    border-radius: 12px;
    padding: 5px 5px 5px 14px;
    gap: 8px;
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.07);
    transition: border-color 0.18s, box-shadow 0.18s;
}
.hero-search-wrap:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.hero-search-icon  {
    width: 16px; height: 16px;
    color: #94a3b8; flex-shrink: 0;
}
.hero-search-input {
    flex: 1;
    border: none; outline: none;
    font-size: 0.95rem;
    color: var(--text-main);
    background: transparent;
    font-family: inherit;
    padding: 7px 0;
    min-width: 0;
    -webkit-appearance: none;
}
.hero-search-input::placeholder { color: #94a3b8; }
.hero-search-btn {
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 18px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    flex-shrink: 0;
    transition: background 0.15s;
}
.hero-search-btn:hover { background: #2563eb; }

/* ── Home Subject Cards ──────────────────────────────────────────────────── */
.home-subjects-section { margin-bottom: 44px; }
.home-section-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 14px;
}
.home-subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
}
.home-subject-card {
    background: #fff;
    border: 1px solid rgba(59, 130, 246, 0.12);
    border-radius: 12px;
    padding: 20px;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}
.home-subject-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.1);
    border-color: var(--accent-primary);
}
.home-card-name  { font-size: 1rem; font-weight: 700; color: var(--text-main); }
.home-card-count { font-size: 0.75rem; color: var(--text-muted); margin-top: 1px; }
.home-card-progress-wrap {
    display: flex; align-items: center; gap: 8px;
}
.home-card-progress-bar {
    flex: 1; height: 4px;
    background: #e2e8f0; border-radius: 2px; overflow: hidden;
}
.home-card-progress-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 2px;
}
.home-card-pct { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; }
.home-card-footer {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.78rem;
}
.home-card-ready { color: var(--text-muted); }
.home-card-cta   { color: var(--accent-primary); font-weight: 600; }

/* ── Home Tips Row ───────────────────────────────────────────────────────── */
.home-tips-row {
    display: flex; gap: 24px;
    padding: 24px 0;
    border-top: 1px solid #f1f5f9;
    margin-top: 8px;
}
.home-tip {
    display: flex; align-items: flex-start; gap: 12px;
    flex: 1;
}
.home-tip-icon { font-size: 1.3rem; line-height: 1; flex-shrink: 0; margin-top: 2px; }
.home-tip strong { display: block; font-size: 0.875rem; font-weight: 600; color: var(--text-main); margin-bottom: 3px; }
.home-tip p { font-size: 0.8rem; color: var(--text-muted); line-height: 1.5; margin: 0; }

/* ── Search Results Page ─────────────────────────────────────────────────── */
.search-page { max-width: 680px; }

.search-page-form { margin-bottom: 28px; }
.search-page-wrap {
    display: flex; align-items: center; gap: 8px;
    background: #fff;
    border: 1.5px solid rgba(59, 130, 246, 0.2);
    border-radius: 12px;
    padding: 5px 5px 5px 14px;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.06);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search-page-wrap:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.search-page-icon { width: 15px; height: 15px; color: #94a3b8; flex-shrink: 0; }
.search-page-input {
    flex: 1; border: none; outline: none;
    font-size: 0.95rem; color: var(--text-main);
    background: transparent; font-family: inherit;
    padding: 7px 0; min-width: 0; -webkit-appearance: none;
}
.search-page-input::placeholder { color: #94a3b8; }
.search-page-btn {
    background: var(--accent-primary); color: #fff;
    border: none; border-radius: 8px;
    padding: 8px 18px; font-size: 0.875rem; font-weight: 600;
    cursor: pointer; font-family: inherit; flex-shrink: 0;
    transition: background 0.15s;
}
.search-page-btn:hover { background: #2563eb; }

.search-result-count {
    font-size: 0.82rem; color: var(--text-muted); margin-bottom: 20px;
}
.search-results-list { display: flex; flex-direction: column; }
.search-result-item {
    padding: 16px 0;
    border-bottom: 1px solid #f1f5f9;
}
.search-result-item:last-child { border-bottom: none; }
.result-meta-row { margin-bottom: 5px; }
.result-kind-tag {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.result-kind-topic   { background: #eff6ff; color: var(--accent-primary); }
.result-kind-subject { background: #f0fdf4; color: #166534; }

.search-result-title {
    display: block;
    font-size: 0.975rem;
    font-weight: 600;
    color: var(--text-main);
    text-decoration: none;
    margin-bottom: 5px;
    transition: color 0.15s;
}
.search-result-title:hover { color: var(--accent-primary); }

.search-result-snippet {
    font-size: 0.83rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0;
}
.search-result-snippet mark {
    background: #fef9c3;
    color: #854d0e;
    border-radius: 2px;
    padding: 0 2px;
    font-style: normal;
}

.search-empty {
    text-align: center;
    padding: 60px 0;
}
.search-empty-icon { font-size: 2.5rem; margin-bottom: 14px; }
.search-empty h2 {
    font-size: 1.1rem; font-weight: 600;
    color: var(--text-main); margin-bottom: 8px;
}
.search-empty p { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 20px; }
.search-home-link {
    font-size: 0.85rem; color: var(--accent-primary); text-decoration: none;
}
.search-home-link:hover { text-decoration: underline; }
