/* Black & White Minimalist Theme */
:root {
    --bg-main: #0a0a0a;
    --bg-card: #141414;
    --bg-hover: #1f1f1f;
    --fg-main: #fafafa;
    --fg-muted: #a3a3a3;
    --border-color: #262626;
    --border-hover: #404040;
    --correct-bg: rgba(22, 163, 74, 0.1);
    --correct-border: rgba(22, 163, 74, 0.5);
    --wrong-bg: rgba(220, 38, 38, 0.1);
    --wrong-border: rgba(220, 38, 38, 0.5);
    --sol-bg: #0f0f0f;
}

html, body {
    scroll-behavior: smooth;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    color: var(--fg-main);
    background-color: var(--bg-main);
    position: relative;
    overflow-x: hidden;
}

.layout {
    display: flex;
    min-height: calc(100vh - 56px);
    align-items: stretch;
    gap: 0;
}

/* ═══════════════════════════════════════
   TOP NAVIGATION
═══════════════════════════════════════ */
.top-nav {
    height: 56px;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-left, .nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    background: transparent;
    border: none;
    color: var(--fg-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    transition: color 0.2s ease, background 0.2s ease;
    padding: 0;
}

.menu-toggle:hover {
    color: var(--fg-main);
    background: var(--bg-hover);
}

.nav-title {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--fg-main);
}

.profile-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--fg-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.profile-btn:hover {
    color: var(--fg-main);
    background: var(--bg-hover);
    border-color: var(--border-hover);
}

.nav-right {
    position: relative;
}

.profile-popup {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 16px;
    border-radius: 8px;
    width: 250px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.profile-popup.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.profile-popup p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--fg-muted);
    line-height: 1.5;
}

/* ═══════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════ */
.sidebar {
    width: 60px; /* Width when collapsed */
    min-width: 60px;
    background: transparent;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1), min-width 0.4s cubic-bezier(0.16, 1, 0.3, 1), background 0.4s ease;
    overflow: hidden;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    flex-shrink: 0;
    z-index: 100;
}

body.sidebar-open .sidebar {
    width: min(320px, 85vw);
    min-width: min(320px, 85vw);
    background: var(--bg-main);
}

.sidebar-header {
    height: 60px; /* Fixed height for header */
    padding: 0 16px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid transparent; 
    white-space: nowrap;
    overflow: hidden;
    flex-shrink: 0;
    justify-content: flex-end; 
    transition: padding 0.3s ease;
}

body.sidebar-open .sidebar-header {
    justify-content: space-between;
    border-bottom-color: var(--border-color);
}

/* Text and Badge Container */
.sidebar-title-container {
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    width: 0;
    overflow: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

body.sidebar-open .sidebar-title-container {
    opacity: 1;
    width: auto;
    pointer-events: auto;
    flex: 1;
}

.sidebar-title-full {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--fg-main);
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-header-badge {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--fg-muted);
}

/* Replaced Toggle Button with nav menu toggle styling earlier */

/* Navigation List */
.subject-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    list-style: none;
    padding: 16px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

body.sidebar-open .subject-list {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

/* Subject Group - minimalist collapsible */
.subject-group {
    margin-bottom: 20px;
}
.subject-group:last-child {
    margin-bottom: 0;
}

.subject-title {
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
    padding: 8px 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
    user-select: none;
}

.subject-title:hover {
    color: var(--fg-main);
    background: var(--bg-hover);
}

.subject-title span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 8px;
}

.subject-title .chevron {
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.subject-group.collapsed .chevron {
    transform: rotate(180deg);
}

.chapter-list-container {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    border-left: 1px solid var(--border-color);
    margin-left: 12px;
    padding-left: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.subject-group.collapsed .chapter-list-container {
    display: none;
}

.chapter-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--fg-muted);
    border-radius: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.chapter-item:hover {
    color: var(--fg-main);
    background: var(--bg-hover);
}

.chapter-item.active {
    color: var(--bg-main);
    background: var(--fg-main);
    font-weight: 500;
}

.subject-list::-webkit-scrollbar { width: 6px; }
.subject-list::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 6px;
}

/* ═══════════════════════════════════════
   MAIN AREA
═══════════════════════════════════════ */
.main {
    flex: 1;
    max-width: 860px; 
    margin: 0 auto;
    padding: 40px 32px 60px;
    display: flex;
    flex-direction: column;
}

#chap-title {
    margin: 0 0 40px;
    font-size: 1.8rem;
    font-weight: 400; 
    letter-spacing: -0.02em;
    color: var(--fg-main);
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

#content-area {
    flex: 1;
}

/* ═══════════════════════════════════════
   QUESTIONS
═══════════════════════════════════════ */
.card {
    padding: 0 0 40px;
    margin-bottom: 40px;
    color: var(--fg-main);
    border-bottom: 1px solid var(--border-color);
    animation: fadeIn 0.4s ease-out;
}
.card:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.q-meta {
    font-size: 0.75rem;
    color: var(--fg-muted);
    margin-bottom: 16px;
    font-family: monospace;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card p {
    line-height: 1.6;
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.opt {
    display: flex;
    align-items: flex-start;
    padding: 12px 16px;
    border-radius: 6px;
    cursor: pointer;
    gap: 12px;
    font-size: 0.95rem;
    color: var(--fg-main);
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
    transition: all 0.2s ease;
    background: transparent;
}

.opt:hover {
    border-color: var(--border-hover);
    background: var(--bg-hover);
}

.opt input[type="radio"] {
    accent-color: var(--fg-main);
    margin-top: 4px;
}

.opt div {
    flex: 1;
    line-height: 1.5;
}

/* Button */
.btn-sol {
    background: transparent;
    color: var(--fg-main);
    border: 1px solid var(--fg-main);
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: all 0.2s ease;
    text-transform: uppercase;
}

.btn-sol:hover {
    background: var(--fg-main);
    color: var(--bg-main);
}

.btn-sol:active {
    transform: scale(0.98);
}

/* Solution Box */
.sol-box {
    display: none;
    margin-top: 24px;
    padding: 24px;
    border-radius: 6px;
    background: var(--sol-bg);
    border: 1px solid var(--border-color);
    color: var(--fg-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sol-box strong, .sol-box b {
    color: var(--fg-main);
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.correct {
    background-color: var(--correct-bg);
    border-color: var(--correct-border);
}
.wrong {
    background-color: var(--wrong-bg);
    border-color: var(--wrong-border);
}

img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    background: #fff; /* to ensure visibility of transparent math/text images */
    padding: 4px;
    margin: 8px 0;
}

/* ═══════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════ */
@media (max-width: 768px) {
    .main {
        /* Extra padding at top so button doesn't block text completely if content goes underneath */
        padding: 24px 20px 40px;
    }
    
    .sidebar {
        position: fixed;
        left: 0;
        top: 56px;
        bottom: 0;
        z-index: 999;
        pointer-events: none; /* Let clicks pass through the invisible background */
        border-right: none; /* Remove vertical line when closed */
    }

    body.sidebar-open .sidebar {
        pointer-events: auto; /* Enable clicks inside the open sidebar */
        border-right: 1px solid var(--border-color); /* Add line back when open */
    }

    body.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        z-index: 998;
        /* Make sure the overlay itself can capture clicks to trigger close */
        pointer-events: auto;
    }
}