:root {
    --bg-color: #fcfcfc;
    --text-color: #111;
    --red-hatch: rgba(228, 62, 59, 0.4);
    --orange-hatch: rgba(243, 156, 18, 0.4);
    --blue-hatch: rgba(52, 152, 219, 0.4);
    --green-hatch: rgba(46, 204, 113, 0.4);
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Kalam', cursive;
    margin: 0;
    padding: 3rem 2rem;
    overflow-x: hidden;
}

body.modal-open { overflow: hidden; }

.board {
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
}

.sketchy-border {
    border: 2px solid #222;
    border-radius: 2% 6% 5% 4% / 1% 1% 2% 4%;
    position: relative;
    background: transparent;
}

.sketchy-border::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%; width: 100%; height: 100%;
    border: 1px solid #222;
    border-radius: 1% 1% 2% 4% / 2% 6% 5% 4%;
    transform: translate(-50%, -50%) scale(1.01) rotate(0.3deg);
    pointer-events: none; z-index: -1;
}

.hatched-red {
    background: repeating-linear-gradient(60deg, transparent, transparent 5px, var(--red-hatch) 5px, var(--red-hatch) 6px);
    background-color: #fff;
}
.hatched-red-small {
    background: repeating-linear-gradient(60deg, transparent, transparent 4px, var(--red-hatch) 4px, var(--red-hatch) 5px);
    background-color: #fff;
}
.hatched-orange-small {
    background: repeating-linear-gradient(60deg, transparent, transparent 4px, var(--orange-hatch) 4px, var(--orange-hatch) 5px);
    background-color: #fff;
}
.hatched-blue-small {
    background: repeating-linear-gradient(60deg, transparent, transparent 4px, var(--blue-hatch) 4px, var(--blue-hatch) 5px);
    background-color: #fff;
}
.hatched-green-small {
    background: repeating-linear-gradient(60deg, transparent, transparent 4px, var(--green-hatch) 4px, var(--green-hatch) 5px);
    background-color: #fff;
}

.title-banner { text-align: center; padding: 1.5rem 2rem; margin-bottom: 4rem; transform: rotate(-0.5deg); }
.title-banner h1 { font-size: 3.5rem; margin: 0; letter-spacing: 2px; }

.section-title { display: inline-block; padding: 0.5rem 1.5rem; margin-bottom: 2rem; transform: rotate(-1.5deg); margin-left: 1rem; }
.section-title h2 { font-size: 2.2rem; margin: 0; }

.search-container {
    max-width: 600px;
    margin: 0 auto 3rem auto;
    background: #fff;
    padding: 0.2rem;
    transform: rotate(0.5deg);
    transition: transform 0.2s;
}

.search-container:focus-within {
    transform: scale(1.02) rotate(-0.5deg);
    box-shadow: 2px 4px 12px rgba(0,0,0,0.08);
}

#search-bar {
    width: 100%;
    padding: 0.8rem 1rem;
    font-family: 'Kalam', cursive;
    font-size: 1.5rem;
    border: none;
    outline: none;
    background: transparent;
    color: #222;
    box-sizing: border-box;
}

#search-bar::placeholder { color: #999; }

.card.hidden { display: none !important; }
.card.highlight { box-shadow: 0 0 15px rgba(230, 126, 34, 0.6); border-color: #e67e22; }

.canvas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 3rem; margin-bottom: 5rem; padding: 1rem;
}

.nav-bar {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
}

.nav-btn {
    display: inline-block;
    padding: 0.8rem 1.5rem;
    font-family: 'Kalam', cursive;
    font-size: 1.4rem;
    font-weight: bold;
    color: #fff;
    background-color: #e67e22;
    text-decoration: none;
    transition: transform 0.2s, background-color 0.2s;
    transform: rotate(2deg);
}

.nav-btn:hover {
    transform: rotate(-1deg) scale(1.05);
    background-color: #d35400;
}

.hatched-orange {
    background: repeating-linear-gradient(60deg, transparent, transparent 5px, var(--orange-hatch) 5px, var(--orange-hatch) 6px);
    background-color: #fff;
}

.card {
    padding: 1.5rem; background: #fff;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex; flex-direction: column; cursor: pointer;
}
.card:hover { transform: scale(1.05) rotate(1deg) !important; box-shadow: 4px 6px 12px rgba(0,0,0,0.08); }

.card-qnum { font-size: 1.5rem; font-weight: bold; color: #e67e22; margin-bottom: 0.5rem; border-bottom: 2px solid #e67e22; display: inline-block; }
.card-desc { font-size: 1.25rem; line-height: 1.4; margin-bottom: 1.5rem; flex-grow: 1; }
.card-file { font-size: 1.1rem; color: #2980b9; padding-top: 0.8rem; margin-top: auto; text-align: right; border-top: 2px dashed #ccc; }

.arrow { position: absolute; width: 60px; height: 60px; background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M10,50 Q50,10 90,50" fill="none" stroke="%23e67e22" stroke-width="3" stroke-linecap="round"/><path d="M75,35 L90,50 L75,65" fill="none" stroke="%23e67e22" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></svg>'); opacity: 0.7; pointer-events: none; }

/* Modal */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(5px); z-index: 1000;
    justify-content: center; align-items: center;
}

.modal-content {
    background: #fff; width: 95%; max-width: 1000px; max-height: 90vh;
    padding: 2.5rem 3rem; position: relative;
    box-sizing: border-box;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    display: flex;
    flex-direction: column;
}

#modal-body {
    overflow-y: auto;
    flex-grow: 1;
    padding-right: 1rem;
}

@keyframes popIn { 0% { transform: scale(0.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.close-btn { position: absolute; top: 10px; right: 25px; font-size: 3rem; cursor: pointer; color: #e74c3c; transition: transform 0.2s; z-index: 100; }
.close-btn:hover { transform: scale(1.2) rotate(10deg); }

.modal-title { font-size: 2rem; margin-top: 0; margin-bottom: 1.5rem; display: inline-block; padding: 0.5rem 1rem; }

/* Flowchart */
.visual-section { margin-bottom: 2rem; }
.mermaid-container {
    background: #fdfcf9;
    padding: 1.5rem;
    max-height: 45vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
}

.mermaid-container svg {
    max-width: 100%;
    height: auto !important;
    max-height: 100%;
}

.explanation-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

@media (max-width: 768px) {
    .explanation-grid { grid-template-columns: 1fr; }
}

.explanation-section h3 { font-size: 1.6rem; color: #2980b9; margin-bottom: 0.8rem; border-bottom: 2px dashed #2980b9; display: inline-block; }
.explanation-section p { font-size: 1.3rem; line-height: 1.5; color: #34495e; margin: 0; }

.file-tag { margin-top: 2rem; }
.code-path { 
    display: inline-block; padding: 0.5rem 1rem; 
    font-family: 'Courier New', Courier, monospace; 
    font-size: 1.2rem; color: #c0392b; 
    background: #fff; text-decoration: none; 
    transition: transform 0.2s, box-shadow 0.2s;
}
.code-path:hover {
    transform: scale(1.02) rotate(-1deg);
    box-shadow: 2px 4px 10px rgba(192, 57, 43, 0.2);
    color: #e74c3c;
}

/* Learn Page Layout */
.learn-container {
    display: flex;
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem 2rem;
    gap: 3rem;
    height: 100vh;
    box-sizing: border-box;
    overflow: hidden;
}

.toc-sidebar {
    width: 320px;
    flex-shrink: 0;
    background: #fff;
    padding: 1.5rem;
    overflow-y: auto;
    height: calc(100vh - 6rem);
    position: relative;
    top: 4rem;
}

#toc-list { list-style: none; padding: 0; margin: 0; }
#toc-list li { margin-bottom: 0.5rem; }
#toc-list a {
    text-decoration: none;
    color: #333;
    font-size: 1.2rem;
    display: block;
    padding: 0.8rem;
    border-bottom: 2px dashed #eee;
    transition: all 0.2s;
}
#toc-list a:hover {
    color: #e67e22;
    border-bottom: 2px dashed #e67e22;
    transform: translateX(5px);
    background: rgba(230, 126, 34, 0.05);
}

.learn-content {
    flex-grow: 1;
    overflow-y: auto;
    height: calc(100vh - 2rem);
    padding-right: 2rem;
    padding-top: 4rem;
    scroll-behavior: smooth;
}

.learn-section {
    background: #fff;
    padding: 3rem;
    margin-bottom: 5rem;
    position: relative;
}

/* Custom Visuals */
.custom-visual {
    background: #fdfcf9;
    padding: 2rem;
    margin: 2rem 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.visual-box {
    background: #fff;
    border: 3px solid #2980b9;
    padding: 1rem 1.5rem;
    text-align: center;
    border-radius: 8px;
    box-shadow: 4px 4px 0 #2980b9;
    font-size: 1.3rem;
    transition: transform 0.2s;
}
.visual-box:hover { transform: translateY(-5px); }

.visual-arrow {
    font-size: 2rem;
    color: #e67e22;
    font-weight: bold;
    text-align: center;
}

/* Feature UI Styles */
.active-toc {
    color: #e74c3c !important;
    font-weight: bold;
    border-bottom: 2px dashed #e74c3c !important;
    transform: translateX(10px) !important;
    background: rgba(231, 76, 60, 0.1) !important;
}

.code-container {
    position: relative;
    display: block;
    width: 100%;
    margin-top: 1rem;
}

.copy-btn {
    position: absolute;
    top: -15px;
    right: 10px;
    background: #fdfcf9;
    border: 2px solid #2980b9;
    padding: 5px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Kalam', cursive;
    font-size: 1rem;
    font-weight: bold;
    color: #2980b9;
    transition: all 0.2s;
    box-shadow: 2px 2px 0 #2980b9;
    z-index: 10;
}

.copy-btn:hover {
    background: #2980b9;
    color: white;
    transform: translateY(-2px);
    box-shadow: 4px 4px 0 #1a5276;
}

/* One-Line Magic Dark Mode */
html.dark-mode {
    filter: invert(0.92) hue-rotate(180deg);
    background: #000;
}
/* Ensure the canvas doesn't look weird if dragged past bounds */
html.dark-mode body {
    background-color: #fff; /* It gets inverted to dark gray/black */
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .nav-bar {
        position: relative !important;
        top: 0 !important; right: 0 !important; left: 0 !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 10px !important;
        padding: 1rem !important;
        box-sizing: border-box;
        margin-bottom: 2rem;
    }
    .board {
        padding-top: 10px !important;
    }
    .explanation-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    .modal-content {
        width: 95% !important;
        padding: 3rem 1rem 1rem 1rem !important; /* Extra top padding for the close button */
        max-height: 95vh;
    }
    .close-btn {
        top: 5px !important;
        right: 15px !important;
        font-size: 2.5rem !important;
    }
    .learn-container {
        flex-direction: column;
        padding-top: 0 !important;
        height: auto !important;
    }
    .toc-sidebar {
        display: none !important; /* Hide TOC on mobile for better reading space */
    }
    .content-area {
        padding: 1rem !important;
    }
    .visual-box {
        width: 100% !important;
        box-sizing: border-box;
    }
    h2.hatched-red-small, h2.hatched-blue-small, h2.hatched-orange-small {
        font-size: 1.5rem !important;
    }
    .auth-container {
        margin: 5vh auto !important;
        padding: 1.5rem !important;
    }
    .hero-title { font-size: 2.5rem !important; padding: 1rem !important; }
    .hero-subtitle { font-size: 1.2rem !important; }
    .action-buttons { flex-direction: column; width: 100%; gap: 1rem; }
    .primary-btn, .secondary-btn { font-size: 1.2rem !important; width: 100%; box-sizing: border-box; text-align: center; }

    /* Learn Canvas specific mobile tweaks */
    .learn-content {
        padding-right: 0 !important;
        padding-top: 1rem !important;
        width: 100% !important;
        box-sizing: border-box;
    }
    .learn-section {
        padding: 1.5rem 1rem !important;
        margin-bottom: 2rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .custom-visual {
        padding: 1rem !important;
        flex-direction: column !important;
    }
    .visual-arrow {
        transform: rotate(90deg);
        margin: 10px 0;
    }
    .code-container pre {
        font-size: 0.95rem !important;
        padding: 1rem !important;
    }
}

/* --- Print Friendly Cheat-Sheet Mode --- */
@media print {
    body, html { overflow: visible !important; height: auto !important; }
    .nav-bar, .toc-sidebar, #progress-bar, .copy-btn { display: none !important; }
    .learn-container { display: block; overflow: visible !important; height: auto !important; }
    .content-area { padding: 0 !important; width: 100% !important; overflow: visible !important; height: auto !important; }
    .learn-section { break-inside: avoid; margin-bottom: 2rem; padding: 1rem; border: 1px solid #ccc; box-shadow: none !important; }
    body.dark-mode, html.dark-mode { filter: none !important; background: white !important; }
    * { color: black !important; background: white !important; }
    .visual-box { border-color: black !important; border-width: 2px !important; }
    pre { border: 1px solid #999 !important; page-break-inside: avoid; }
}
