/* ==========================================================================
   1. GLOBAL VARIABLES & BASE
   ========================================================================== */
:root {
    --bg: #f8f9fa;
    --navy: #1a1d23;
    --navy-light: #2c3e50;
    --green: #2ecc71;
    --green-dark: #27ae60;
    --white: #ffffff;
    --shadow: 0 4px 15px rgba(0,0,0,0.1);
    --border: #e0e6ed;
    --text: #2d3748;
}

* { box-sizing: border-box; }
body { 
    background: var(--bg); 
    font-family: 'Inter', 'Segoe UI', sans-serif; 
    margin: 0; 
    color: var(--text);
    line-height: 1.6;
}

.container { width: 92%; max-width: 1100px; margin: auto; }
.no-scroll { overflow: hidden; }

/* ==========================================================================
   2. NAVIGATION & HEADER
   ========================================================================== */
.navbar { 
    background: var(--navy); 
    padding: 1rem 0; 
    position: sticky; 
    top: 0; 
    z-index: 1000; 
}
.flex-nav { display: flex; justify-content: space-between; align-items: center; }

.logo { font-size: 1.5rem; color: white; font-weight: 800; text-decoration: none; }
.logo span { color: var(--green); }

nav a { 
    color: #ccc; 
    margin-left: 20px; 
    text-decoration: none; 
    font-size: 0.9rem; 
    transition: 0.3s; 
}
nav a:hover, nav a.active { color: var(--green); }
nav a.active { font-weight: bold; }

.mobile-toggle { 
    display: none; 
    background: none; 
    border: none; 
    color: white; 
    font-size: 1.5rem; 
    cursor: pointer; 
}

/* ==========================================================================
   3. HERO & DASHBOARD (HOME)
   ========================================================================== */
.hero-modern { 
    background: linear-gradient(135deg, var(--navy) 0%, #34495e 100%); 
    color: white; 
    padding: 6rem 0; 
    text-align: center; 
}
.search-bar { max-width: 600px; margin: 2rem auto; position: relative; }
.search-bar input { 
    width: 100%; padding: 15px 25px; border-radius: 30px; 
    border: none; outline: none; font-size: 1.1rem; 
}
.search-bar button { 
    position: absolute; right: 5px; top: 5px; 
    background: var(--green); color: white; border: none; 
    padding: 10px 20px; border-radius: 25px; cursor: pointer; 
}

.grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); 
    gap: 25px; 
    margin-top: -50px; 
}
.card { 
    background: white; padding: 30px; border-radius: 12px; 
    box-shadow: var(--shadow); text-align: center; 
    cursor: pointer; transition: 0.3s; 
}
.card:hover { transform: translateY(-10px); }
.card i { font-size: 2.5rem; color: var(--green); margin-bottom: 15px; }

/* ==========================================================================
   4. SYLLABUS LAYOUT (SINGLE-PAGE VIEW)
   ========================================================================== */
.syllabus-wrapper { display: flex; min-height: calc(100vh - 70px); position: relative; }

.syllabus-sidebar {
    width: 300px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: all 0.3s ease-in-out;
    z-index: 10;
}

.topic-nav { flex: 1; overflow-y: auto; padding: 15px; }
.topic-link {
    display: flex; padding: 12px 15px; text-decoration: none;
    color: #4a5568; border-radius: 8px; margin-bottom: 4px;
    transition: 0.2s; font-size: 0.95rem;
}
.topic-link:hover { background: #f7fafc; }
.topic-link.active { background: #ebfef2; color: var(--green-dark); font-weight: 600; }
.topic-link .num { width: 45px; font-weight: bold; }

.syllabus-main { flex: 1; background: #fdfdfd; padding: 40px 20px; overflow-y: auto; }
.content-limiter { max-width: 1100px; margin: 0 auto; }

.lesson-entry { 
    background: var(--white); padding: 30px; margin-bottom: 40px; 
    border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.02); 
    border: 1px solid #f0f0f0; 
}
.lesson-entry h2 { margin-top: 0; color: var(--green-dark); font-size: 1.5rem; border-bottom: 2px solid var(--green); padding-bottom: 10px;}
.lesson-text { font-size: 1.05rem; }

.lesson-figure { 
    margin: 30px 0; text-align: center; background: #fff; 
    padding: 15px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); 
}
.lesson-figure img { max-width: 100%; height: auto; border-radius: 5px; }
.lesson-figure figcaption { margin-top: 10px; font-style: italic; color: #718096; }

/* ==========================================================================
   5. SQL INTERPRETER TOOL
   ========================================================================== */
.sql-card { background: #1e1e1e; color: #d4d4d4; border-radius: 8px; overflow: hidden; font-family: 'Consolas', monospace; margin-top: 20px;}
.sql-header { background: #333; padding: 10px 15px; display: flex; justify-content: space-between; align-items: center; color: #fff; font-size: 0.9rem; }
.sql-body { padding: 15px; }
#sqlQueryInput { 
    width: 100%; height: 80px; background: #252526; color: #9cdcfe; 
    border: 1px solid #3e3e42; border-radius: 4px; padding: 10px; 
    font-family: inherit; margin-bottom: 10px; resize: none; outline: none;
}
.btn-run { background: var(--green); color: white; border: none; padding: 8px 20px; border-radius: 4px; cursor: pointer; font-weight: bold; transition: 0.2s; }
.btn-run:hover { background: var(--green-dark); }

.sql-results { background: white; color: #333; min-height: 100px; padding: 15px; border-top: 4px solid #333; }
.sql-results table { width: 100%; border-collapse: collapse; }
.sql-results th { background: #f4f4f4; text-align: left; padding: 8px; border: 1px solid #ddd; }
.sql-results td { padding: 8px; border: 1px solid #ddd; }
.sql-error { color: #e74c3c; font-weight: bold; }

/* ==========================================================================
   6. LOGIC GATE SIMULATOR (HORIZONTAL LAB)
   ========================================================================== */
.logic-lab.horizontal-layout { display: flex; height: 600px; background: #fff; border: 1px solid #ddd; border-radius: 8px; overflow: hidden; }

.lab-sidebar { 
    width: 180px; background: var(--navy-light); color: white; 
    padding: 15px; display: flex; flex-direction: column; border-right: 2px solid #1a252f; 
}
.lab-sidebar h4 { font-size: 0.8rem; margin-bottom: 15px; color: #bdc3c7; text-transform: uppercase; letter-spacing: 1px;}

.tool-buttons button { 
    width: 100%; background: #34495e; color: white; border: none; 
    padding: 10px; margin-bottom: 8px; border-radius: 4px; 
    cursor: pointer; font-size: 0.85rem; transition: 0.2s; 
}
.tool-buttons button:hover { background: var(--green-dark); }
.gate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 10px; }

.lab-main { flex: 1; display: flex; flex-direction: column; position: relative; }
.lab-workspace { 
    flex: 1; position: relative; overflow: hidden;
    background-color: #fdfdfd; 
    background-image: radial-gradient(#e0e0e0 1px, transparent 1px); 
    background-size: 25px 25px; 
}
#wireCanvas { position: absolute; top: 0; left: 0; pointer-events: none; filter: drop-shadow(0 0 2px rgba(46, 204, 113, 0.3)); }

/* Nodes & Components */
.gate-node { position: absolute; width: 75px; background: white; padding: 5px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); cursor: grab; text-align: center; z-index: 5;}
.gate-node .label { font-size: 0.7rem; font-weight: bold; display: block; margin-top: 5px; color: #7f8c8d; }
.gate-img { width: 100%; height: auto; pointer-events: none; }

/* Pins */
.pin { width: 12px; height: 12px; background: var(--navy-light); border: 2px solid #fff; border-radius: 50%; position: absolute; cursor: crosshair; transition: 0.2s; z-index: 10; }
.pin:hover { background: var(--green); transform: scale(1.3); }
.out-pin { right: -6px; top: 22px; }
.pins-in-container { position: absolute; left: -8px; top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: center; gap: 10px; pointer-events: none; }
.in-pin { position: static; pointer-events: auto; }

/* Interactive States */
.val-toggle { background: var(--navy-light); color: white; border: none; padding: 5px 12px; border-radius: 4px; cursor: pointer; font-weight: bold; }
.val-toggle.active-bg { background: var(--green-dark) !important; box-shadow: 0 0 10px rgba(39, 174, 96, 0.4); }

.status-bulb { width: 35px; height: 35px; background: #444; border-radius: 50%; margin: 5px auto; border: 3px solid #222; transition: 0.3s; }
.status-bulb.on { 
    background: #f1c40f; border-color: #f39c12; 
    box-shadow: 0 0 20px 5px rgba(241, 196, 15, 0.6); 
}

.lab-footer { height: 120px; background: #f8f9fa; border-top: 1px solid #eee; padding: 10px; overflow-y: auto; }
.truth-table-container table { width: 100%; border-collapse: collapse; background: white; font-size: 0.9rem; }
.truth-table-container th, .truth-table-container td { border: 1px solid #ddd; padding: 8px; text-align: center; }

/* ==========================================================================
   7. RESPONSIVE DESIGN (MEDIA QUERIES)
   ========================================================================== */

/* Tablet & Mobile Header */
@media (max-width: 768px) {
    .mobile-toggle { display: block; z-index: 1001; }
    #main-nav {
        display: none; position: fixed; top: 0; right: 0;
        width: 70%; height: 100vh; background: var(--navy);
        flex-direction: column; padding-top: 80px; z-index: 1000;
        box-shadow: -5px 0 15px rgba(0,0,0,0.3);
    }
    #main-nav.open { display: flex; }
    #main-nav a { margin: 15px 30px; font-size: 1.2rem; color: white; }
}

/* Tablet & Mobile Syllabus/General Layout */
@media (max-width: 900px) {
    .syllabus-sidebar {
        position: fixed; left: -100%; top: 0; bottom: 0;
        width: 280px; height: 100vh; z-index: 2000;
        box-shadow: 5px 0 15px rgba(0,0,0,0.1);
    }
    .syllabus-sidebar.mobile-active { left: 0; }
    .syllabus-main { width: 100%; padding: 20px 10px; }
    .content-limiter { max-width: 100%; }
    
    .sidebar-toggle-btn {
        display: block; width: 100%; background: var(--green-dark);
        color: white; border: none; padding: 12px; font-size: 1rem; cursor: pointer;
    }
    
    .logic-lab.horizontal-layout { flex-direction: column; height: auto; }
    .lab-sidebar { width: 100%; border-right: none; border-bottom: 2px solid #1a252f; }
    .lab-workspace { height: 400px; }
}

/* Highlight the row matching the current switch states */
.current-state-row {
    background-color: rgba(46, 204, 113, 0.2) !important;
    outline: 2px solid var(--green);
}

.node-rename {
    display: block;
    width: 60px;
    background: transparent;
    border: none;
    border-bottom: 1px dashed #ccc;
    color: #333;
    font-size: 0.7rem;
    text-align: center;
    margin-bottom: 5px;
    outline: none;
}
.node-rename:focus { border-bottom-color: var(--green); }

.res-on { color: var(--green-dark); font-weight: bold; }
.res-off { color: #e74c3c; }

/* Keep the footer table readable */
.truth-table-container table tr { transition: background 0.3s; }

/* Allow the footer to grow with the table */
.lab-footer {
    min-height: 100px; /* Base height */
    height: auto;      /* Remove fixed height */
    background: #f8f9fa;
    border-top: 1px solid #eee;
    padding: 20px;
    overflow: visible; /* Prevent scrollbars */
}

.truth-table-container {
    width: 100%;
}

.truth-table-container table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 0.95rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* Ensure table cells don't squash */
.truth-table-container th, 
.truth-table-container td {
    border: 1px solid #dfe6e9;
    padding: 12px 8px;
    text-align: center;
}

/* Header styling */
.truth-table-container thead th {
    background: #f1f2f6;
    color: #2f3542;
    font-weight: 700;
}

.logic-lab.horizontal-layout {
    display: flex;
    height: auto; /* Change from fixed height to auto */
    min-height: 600px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: visible; /* Let the table be seen */
    flex-direction: row; /* Ensure sidebar stays left */
}

/* On mobile, keep things stacked */
@media (max-width: 900px) {
    .logic-lab.horizontal-layout {
        flex-direction: column;
    }
}
.lab-sidebar button i {
    margin-right: 8px;
    font-size: 0.9rem;
}

.lab-sidebar hr {
    border: none;
    border-top: 1px solid rgba(255,255,255,0.1);
    margin: 15px 0;
}
/* Task Card Styling */
.task-card {
    border-left: 5px solid var(--navy);
    background: #f0f7ff;
}

.task-card h2 {
    color: var(--navy-light);
    border-bottom: 2px solid var(--navy);
}

.task-card hr {
    border: 0;
    border-top: 1px solid #d0d7de;
    margin: 15px 0;
}

.task-card ol {
    padding-left: 20px;
}

.task-card ol li {
    margin-bottom: 10px;
    font-weight: 500;
}
/* --- Desktop State (Default) --- */
.mobile-toggle, 
.sidebar-toggle-btn, 
.close-sidebar { 
    display: none !important; /* Force hide on desktop */
}

/* Navbar Links (Desktop) */
#main-nav {
    display: flex !important;
    flex-direction: row;
    position: static;
    height: auto;
    width: auto;
    background: transparent;
    box-shadow: none;
    padding: 0;
}

/* --- Mobile View Adjustments --- */
@media (max-width: 900px) {
    /* Show the toggle buttons only now */
    .mobile-toggle, 
    .sidebar-toggle-btn { 
        display: block !important; 
    }

    /* Standardize the Sidebar Toggle for Syllabus */
    .sidebar-toggle-btn {
        margin: 10px;
        width: calc(100% - 20px);
        border-radius: 6px;
    }

    /* Hide the Desktop Nav and prepare the Drawer */
    #main-nav {
        display: none !important; /* Hidden until .open class is added */
        position: fixed;
        top: 0;
        right: 0;
        width: 280px;
        height: 100vh;
        background: var(--navy);
        flex-direction: column;
        padding-top: 60px;
        box-shadow: -5px 0 15px rgba(0,0,0,0.3);
    }

    #main-nav.open {
        display: flex !important; /* Reveal via JS */
    }

    .close-sidebar {
        display: block !important;
        color: var(--navy);
        padding: 15px;
        text-align: right;
        cursor: pointer;
    }
}

.pseudo-container {
    display: flex;
    height: 500px;
    gap: 15px;
    padding: 15px;
    background: #f1f2f6;
}

.pseudo-editor-pane, .pseudo-visual-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 8px;
    border: 1px solid #ddd;
    overflow: hidden;
}

.pane-header {
    background: #2c3e50;
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 0.9rem;
}

#pseudoInput {
    flex: 1;
    padding: 15px;
    border: none;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    background: #282c34;
    color: #abb2bf;
}

.trace-content {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
}

.trace-content table {
    width: 100%;
    border-collapse: collapse;
}

.trace-content th, .trace-content td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: center;
    font-family: monospace;
}

.trace-content th { background: #f8f9fa; }

.trace-content td code {
    color: var(--green-dark);
    font-weight: bold;
}
.res-on { background: #d4edda; }

.output-cell {
    background: #f0f9ff;
    color: #0369a1;
    font-weight: 600;
    text-align: left !important;
    padding-left: 15px !important;
    font-family: 'Consolas', monospace;
}

.instr-cell {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Split the visual pane into Table and Console */
.pseudo-visual-pane {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.trace-wrapper { flex: 2; border-bottom: 2px solid #ddd; overflow: hidden; display: flex; flex-direction: column; }
.console-wrapper { flex: 1; overflow: hidden; display: flex; flex-direction: column; background: #1e1e1e; }

/* Console Styling */
.console-content {
    flex: 1;
    background: #1e1e1e;
    color: #f8f8f2;
    font-family: 'Consolas', monospace;
    padding: 10px;
    font-size: 0.9rem;
    overflow-y: auto;
}

.console-line { margin-bottom: 4px; border-bottom: 1px solid #333; padding-bottom: 2px; }
.console-line span { color: var(--green); margin-right: 8px; font-weight: bold; }

.btn-clear {
    background: transparent;
    border: 1px solid #555;
    color: #aaa;
    font-size: 0.7rem;
    padding: 2px 8px;
    cursor: pointer;
    border-radius: 3px;
}
.btn-clear:hover { background: #444; color: #fff; }

/* Adjust Editor for dark mode feel */
#pseudoInput {
    background: #282c34;
    color: #abb2bf;
    caret-color: var(--green);
}

/* --- SCREEN STYLING (The "Nicer Way") --- */
.exam-paper-wrapper {
    background: #e9ecef; /* Darker background to make paper pop */
    padding: 40px 0;
    display: flex;
    justify-content: center;
}

.a4-paper {
    background: white;
    width: 210mm; /* Exact A4 width */
    min-height: 297mm;
    padding: 25mm;
    box-shadow: 0 0 20px rgba(0,0,0,0.15);
    font-family: "Inter", "Times New Roman", serif;
    color: #000;
}

.exam-header-block { border-bottom: 2px solid #000; margin-bottom: 30px; padding-bottom: 10px; }
.meta-row { display: flex; justify-content: space-between; font-weight: bold; font-size: 1.1rem; }
.exam-title { text-align: center; text-transform: uppercase; margin: 20px 0; font-size: 1.6rem; }
.info-line { margin: 15px 0; font-family: monospace; }

.q-block { margin-bottom: 35px; page-break-inside: avoid; }
.q-header { display: flex; gap: 10px; line-height: 1.5; }
.q-num { font-weight: bold; min-width: 25px; }
.q-text { flex: 1; }
.q-marks { font-weight: bold; }

.exam-line { height: 32px; border-bottom: 1px solid #ccc; width: 100%; }

.btn-print-main { background: var(--green); color: white; border: none; padding: 12px 25px; border-radius: 6px; cursor: pointer; font-weight: bold; }

/* --- PRINT STYLING (The Cleanup) --- */
@media print {
    /* Hide everything except the exam paper */
    header, footer, .navbar, .lab-sidebar, .exam-controls, .no-print {
        display: none !important;
    }

    body { background: white !important; }
    
    .exam-paper-wrapper { padding: 0; background: transparent; }
    
    .a4-paper {
        width: 100%;
        margin: 0;
        padding: 0;
        box-shadow: none;
        border: none;
    }

    /* Force the browser to respect the A4 size */
    @page {
        size: A4;
        margin: 15mm;
    }
}
.mark-scheme-item {
    margin-top: 10px;
    padding: 15px;
    background-color: #fff9db; /* Light yellow post-it note feel */
    border-left: 4px solid #fcc419;
    color: #856404;
    font-size: 0.9rem;
    font-style: italic;
    border-radius: 4px;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    margin-right: 10px;
}

/* Ensure the mark scheme is NEVER printed even if visible on screen */
@media print {
    .mark-scheme-item {
        display: none !important;
    }
}

.pastpapers-hub { background: #f4f7f6; min-height: 100vh; padding-bottom: 50px; }
.hub-header { background: var(--navy); color: white; padding: 40px 0; margin-bottom: 30px; }

.filter-bar { margin-top: 20px; }
#paperSearch {
    width: 100%;
    padding: 15px 25px;
    border-radius: 30px;
    border: none;
    font-size: 1rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    outline: none;
}

.papers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
}

.paper-card {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: 0.3s;
    border: 1px solid #eee;
}
.paper-card:hover { transform: translateY(-5px); box-shadow: 0 8px 15px rgba(0,0,0,0.1); }

.card-type-tag {
    padding: 8px;
    text-align: center;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    color: white;
    background: #95a5a6;
}
.card-type-tag.qp { background: #3498db; } /* Blue for Question Paper */
.card-type-tag.ms { background: #27ae60; } /* Green for Mark Scheme */
.card-type-tag.gt { background: #e67e22; } /* Orange for Grade Thresholds */

.card-body { padding: 20px; text-align: center; }
.card-body h3 { margin: 0; color: var(--navy); font-size: 1.3rem; }
.card-body .meta { color: #7f8c8d; margin: 10px 0 20px; font-size: 0.9rem; }

.btn-download {
    display: block;
    background: #f8f9fa;
    color: var(--navy);
    text-decoration: none;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #ddd;
    font-weight: 600;
    transition: 0.2s;
}
.btn-download:hover { background: var(--navy); color: white; }
/* Container Spacing */
.year-section {
    background: white;
    margin-bottom: 40px;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.year-title {
    color: var(--navy);
    font-size: 1.8rem;
    border-bottom: 3px solid var(--green);
    padding-bottom: 10px;
    margin-bottom: 25px;
}

.series-block {
    margin-bottom: 30px;
    padding-left: 15px;
    border-left: 3px solid #eee;
}

.series-title {
    color: var(--navy-light);
    font-size: 1.2rem;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Three-Column Type Grid */
.types-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.type-heading {
    font-size: 0.9rem;
    text-transform: uppercase;
    color: #7f8c8d;
    margin-bottom: 10px;
    letter-spacing: 1px;
}

/* List of Papers */
.paper-list {
    list-style: none;
    padding: 0;
}

.paper-item {
    margin-bottom: 8px;
}

.paper-item a {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: #333;
    font-size: 0.95rem;
    padding: 6px 10px;
    border-radius: 4px;
    background: #f8f9fa;
    transition: 0.2s;
}

.paper-item a:hover {
    background: var(--navy);
    color: white;
}

/* Small codes like QP, MS */
.file-tag {
    font-size: 0.7rem;
    font-weight: 800;
    padding: 2px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    color: white;
    min-width: 25px;
    text-align: center;
}

.file-tag.qp { background: #3498db; }
.file-tag.ms { background: #27ae60; }
.file-tag.gt { background: #e67e22; }
.file-tag.er { background: #9b59b6; }

.sidebar-link {
    display: flex;
    gap: 10px;
    font-variant-numeric: tabular-nums; /* Keeps numbers aligned */
}