/* =========================================
   FILE: lecture_styles.css
   USAGE: <link rel="stylesheet" href="lecture_styles.css">
   ========================================= */

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --light-color: #ecf0f1;
    --dark-color: #34495e;
    --success-color: #2ecc71;
    --warning-color: #f39c12;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--dark-color);
    background-color: #f9f9f9;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* --- Typography --- */

header {
    background-color: var(--primary-color);
    color: white;
    padding: 2rem 0;
    text-align: center;
    margin-bottom: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

h1, h2, h3, h4 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: 1.8rem;
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 0.5rem;
    margin-top: 2rem;
}

h3 {
    font-size: 1.4rem;
    margin-top: 1.5rem;
}

h4 {
    font-size: 1.2rem;
    margin-top: 1.2rem;
}

p {
    margin-bottom: 1rem;
}

ul, ol {
    margin-bottom: 1rem;
    padding-left: 2rem;
}

li {
    margin-bottom: 0.5rem;
}

/* --- Sections & Containers --- */

section {
    background-color: white;
    padding: 2rem;
    margin-bottom: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* --- Interactive Elements & Key Terms --- */

.key-term {
    font-weight: bold;
    color: var(--secondary-color);
    position: relative;
    cursor: help;
    border-bottom: 1px dotted var(--secondary-color);
}

.key-term:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--dark-color);
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    width: 250px;
    text-align: center;
    z-index: 1;
    font-weight: normal;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

details {
    background-color: var(--light-color);
    border-radius: 4px;
    margin: 1rem 0;
}

summary {
    padding: 0.8rem 1rem;
    cursor: pointer;
    font-weight: bold;
    color: var(--primary-color);
}

summary:hover {
    background-color: #ddd;
}

.content {
    padding: 1rem;
}

/* --- Tabs --- */

.tabs {
    display: flex;
    margin-bottom: 1rem;
}

.tab {
    padding: 0.5rem 1rem;
    background-color: var(--light-color);
    border: 1px solid #ddd;
    cursor: pointer;
    border-radius: 4px 4px 0 0;
    margin-right: 0.2rem;
}

.tab.active {
    background-color: white;
    border-bottom: 1px solid white;
    color: var(--secondary-color);
    font-weight: bold;
}

.tab-content {
    display: none;
    border: 1px solid #ddd;
    padding: 1rem;
    border-radius: 0 4px 4px 4px;
}

.tab-content.active {
    display: block;
}

/* --- Boxes (Formulas, Highlights, Warnings, Examples, Solutions) --- */

.formula {
    background-color: var(--light-color);
    padding: 1rem;
    border-radius: 4px;
    margin: 1rem 0;
    font-family: 'Courier New', monospace;
    text-align: center;
    overflow-x: auto;
}

.highlight-box {
    background-color: #e8f4f8;
    border-left: 4px solid var(--secondary-color);
    padding: 1rem;
    margin: 1rem 0;
}

.warning-box {
    background-color: #fdf2e9;
    border-left: 4px solid var(--warning-color);
    padding: 1rem;
    margin: 1rem 0;
}

.example-box {
    background-color: #f9ebea;
    border-left: 4px solid var(--accent-color);
    padding: 1rem;
    margin: 1rem 0;
}

.solution-box {
    background-color: #eafaf1;
    border-left: 4px solid var(--success-color);
    padding: 1rem;
    margin: 1rem 0;
}

/* Preface / Introduction Section */
.preface-section {
    background-color: #f9f9f9;
    border-radius: 10px;
    padding: 2rem;
    margin-bottom: 2rem;
    border: 1px solid #eaeaea;
    overflow: hidden; /* Ensures the image doesn't break out of rounded corners */
}

.preface-cover-photo {
    width: 100%;
    max-height: 300px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.preface-section h2 {
    margin-top: 0;
    color: var(--primary-color);
    font-size: 1.8rem;
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 0.5rem;
}

.preface-text {
    line-height: 1.8;
    color: #444;
}

.preface-text p {
    margin-bottom: 1rem;
}

.acknowledgements {
    margin-top: 2rem;
    font-style: italic;
    color: #666;
}

/* --- Try It Yourself & Solution Toggles --- */

.try-yourself {
    background-color: #f5f5f5;
    border: 1px dashed #ccc;
    padding: 1rem;
    margin: 1.5rem 0;
    border-radius: 4px;
}

.try-yourself-title {
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
}

.solution-toggle {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 0.5rem;
}

.solution-toggle:hover {
    background-color: #2980b9;
}

.solution-content {
    display: none;
    margin-top: 1rem;
    padding: 1rem;
    background-color: white;
    border-radius: 4px;
}

.solution-content.show {
    display: block;
}

/* --- Tables --- */

table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

th, td {
    border: 1px solid #ddd;
    padding: 0.8rem;
    text-align: left;
}

th {
    background-color: var(--secondary-color);
    color: white;
}

tr:nth-child(even) {
    background-color: var(--light-color);
}

/* --- Sidebar and Iframe Layout --- */

.app-container {
    display: flex;
    height: calc(100vh - 120px); /* Adjust 120px based on your header/footer height */
    margin: 1.5rem 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.sidebar-toc {
    width: 280px;
    flex-shrink: 0;
    background-color: #f4f4f4;
    border-right: 1px solid #ddd;
    overflow-y: auto;
    padding: 1rem 0;
}

.sidebar-toc h3 {
    margin: 0 1rem 1rem 1rem;
    font-size: 1.1rem;
    color: var(--primary-color);
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 0.5rem;
}

.sidebar-toc ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

.sidebar-toc li a {
    display: block;
    padding: 0.6rem 1rem;
    color: #333;
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}

.sidebar-toc li a:hover {
    background-color: #e9e9e9;
    border-left-color: var(--secondary-color);
}

.sidebar-toc li a.active {
    background-color: white;
    border-left-color: var(--primary-color);
    font-weight: bold;
    color: var(--primary-color);
}

.content-frame {
    flex-grow: 1;
    border: none;
    background: white;
}

/* =========================================
   IFRAME SAFETY OVERRIDES
   ========================================= */
/* This prevents the max-width: 1200px on the body tag inside 
   the units from squishing your new SVG diagrams */
.content-frame body {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 2rem !important;
}


/* =========================================
   CHAPTER HEADER FIX (Inside Iframe)
   ========================================= */

/* 1. Shrink the giant blue box and remove rounded corners for a full-width banner look */
.content-frame header {
    padding: 1.5rem 2rem !important; 
    margin-bottom: 2rem !important;
    border-radius: 0 0 8px 8px !important;
    margin-top: -2rem !important; /* Pulls it flush to the top edge of the iframe */
}

/* 2. Completely hide the redundant "Introduction to Machine Learning" h1 */
.content-frame header h1 {
    display: none !important; 
}

/* 3. Promote the Unit h2 to be the main Chapter Title */
.content-frame header h2 {
    color: white !important; 
    font-size: 1.8rem !important;
    border-bottom: none !important; 
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0.5rem !important;
}

/* 4. Style the Instructor/Semester text */
.content-frame header p {
    margin: 0 !important;
    opacity: 0.85; 
    font-size: 1rem !important;
}


/* --- Diagrams & Code Blocks --- */

.diagram-container {
    text-align: center;
    margin: 1.5rem 0;
    max-width: 100% !important; /* Forces diagrams to scale properly */
}

.diagram {
    display: inline-block;
    font-family: monospace;
    line-height: 1.2;
    white-space: pre;
    background-color: white;
    padding: 1rem;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
    max-width: 100%;
    font-size: 14px;
}

.code-block {
    background-color: #2c3e50;
    color: #f8f8f2;
    padding: 1rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    overflow-x: auto;
    margin: 1rem 0;
}

/* --- Quiz Elements --- */

.quiz-question {
    background-color: var(--light-color);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.quiz-option {
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
}

.quiz-option:hover {
    background-color: #ddd;
}

.quiz-option.correct {
    background-color: var(--success-color);
    color: white;
}

.quiz-option.incorrect {
    background-color: var(--accent-color);
    color: white;
}

.quiz-feedback {
    margin-top: 1rem;
    padding: 0.8rem;
    border-radius: 4px;
    display: none;
}

.quiz-feedback.show {
    display: block;
}

.quiz-feedback.correct {
    background-color: #d4edda;
    color: #155724;
}

.quiz-feedback.incorrect {
    background-color: #f8d7da;
    color: #721c24;
}

/* --- Summary Sections --- */

.key-takeaways {
    background-color: #e8f4f8;
    padding: 1.5rem;
    border-radius: 8px;
    margin: 1.5rem 0;
}

.key-takeaways h3 {
    margin-top: 0;
    color: var(--secondary-color);
}

.common-pitfalls {
    background-color: #fdf2e9;
    padding: 1.5rem;
    border-radius: 8px;
    margin: 1.5rem 0;
}

.common-pitfalls h3 {
    margin-top: 0;
    color: var(--warning-color);
}

.resources {
    background-color: #f9ebea;
    padding: 1.5rem;
    border-radius: 8px;
    margin: 1.5rem 0;
}

.resources h3 {
    margin-top: 0;
    color: var(--accent-color);
}

.resources ul {
    list-style-type: none;
    padding-left: 0;
}

.resources li {
    margin-bottom: 0.8rem;
}

.resources a {
    color: var(--secondary-color);
    text-decoration: none;
}

.resources a:hover {
    text-decoration: underline;
}

/* --- Responsive Design --- */

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    section {
        padding: 1.5rem;
    }

    /* Collapse sidebar on mobile */
    .app-container {
        flex-direction: column;
        height: auto;
    }

    .sidebar-toc {
        width: 100%;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid #ddd;
    }

    .tabs {
        flex-direction: column;
    }

    .tab {
        border-radius: 4px;
        margin-bottom: 0.2rem;
    }

    .tab.active {
        border-bottom: 1px solid #ddd;
    }

    .tab-content {
        border-radius: 4px;
    }
}

/* =========================================
   NUCLEAR IFRAME HEADER FIX
   ========================================= */

/* If the browser detects it is inside an iframe, destroy the blue box */
@media all and (min-resolution:.001dpcm) {
    @supports (animation: none) {
        
        /* 1. Shrink the giant blue box */
        header {
            padding: 1.5rem 2rem !important; 
            margin-bottom: 2rem !important;
            margin-top: 0 !important;
        }

        /* 2. Completely hide the redundant h1 */
        header h1 {
            display: none !important; 
            height: 0 !important;
            visibility: hidden !important;
        }

        /* 3. Make h2 white and big */
        header h2 {
            color: white !important; 
            font-size: 1.8rem !important;
            border-bottom: none !important; 
            padding-bottom: 0 !important;
            margin-top: 0 !important;
            margin-bottom: 0.5rem !important;
        }

        /* 4. Style the subtitle text */
        header p {
            margin: 0 !important;
            opacity: 0.85 !important; 
            font-size: 1rem !important;
        }
        
        /* 5. Stop the 1200px max-width from squishing diagrams */
        body {
            max-width: 100% !important;
        }
    }
}