:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --bg: #0f172a;
    --drawer-bg: #1e293b;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border: rgba(255, 255, 255, 0.1);
    --text: #f8fafc;
    --text-dim: #94a3b8;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

@media (min-width: 1025px) {
    body {
        overflow: hidden;
    }
}

/* --- Layout --- */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* --- Navbar & Hamburger --- */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    z-index: 2000;
}

.menu-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: var(--transition);
}

.menu-btn:hover {
    background: var(--border);
}

.logo {
    margin-left: 1rem;
    font-weight: 700;
    font-size: 1.2rem;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* --- Drawer (Sidebar) --- */
.drawer {
    position: fixed;
    top: 60px;
    left: -300px;
    width: 300px;
    height: calc(100vh - 60px);
    background: var(--drawer-bg);
    border-right: 1px solid var(--border);
    transition: var(--transition);
    z-index: 1500;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.drawer.open {
    left: 0;
}

.drawer-item {
    padding: 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-dim);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.drawer-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.drawer-item.active {
    background: var(--primary);
    color: #fff;
}

/* --- Main Content Area --- */
main {
    flex-grow: 1;
    margin-top: 60px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: margin-left var(--transition);
}

main.drawer-open {
    margin-left: 300px;
}

@media (max-width: 600px) {
    .logo {
        font-size: 1rem;
        margin-left: 0.5rem;
    }

    .mode-select {
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
    }
}

.master-card {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 0;
    width: 100%;
    max-width: 1400px;
    height: calc(100vh - 160px);
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
}

@media (max-width: 1024px) {
    .master-card {
        grid-template-columns: 1fr;
        height: auto;
        min-height: calc(100vh - 160px);
        margin-bottom: 80px;
        border-radius: 16px;
    }

    .info-panel,
    .action-panel {
        overflow-y: visible;
        height: auto;
        padding: 1.5rem;
    }
}

.info-panel {
    padding: 2.5rem;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    background: rgba(30, 41, 59, 0.5);
}

.action-panel {
    padding: 2.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: rgba(15, 23, 42, 0.4);
}

/* --- Content Styling (Shared) --- */
h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

h2 {
    font-size: 1.5rem;
    margin: 1.5rem 0 1rem;
    color: #fff;
}

p {
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.code-block {
    background: #000;
    padding: 1.5rem;
    border-radius: 12px;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    margin: 1rem 0;
    color: #818cf8;
    border-left: 4px solid var(--primary);
    white-space: pre-wrap;
}

/* --- Navigation Bar (Bottom) --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    z-index: 1000;
}

.nav-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-btn.prev {
    background: rgba(255, 255, 255, 0.1);
}

.current-topic-name {
    font-weight: 600;
    color: var(--text-dim);
    font-size: 0.9rem;
    text-align: center;
}

@media (max-width: 600px) {
    .bottom-nav {
        gap: 0.5rem;
        padding: 0 1rem;
    }

    .nav-btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .current-topic-name {
        display: none;
    }
}

/* Overlay for drawer */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: transparent;
    display: none;
    z-index: 1400;
}

.overlay.active {
    display: block;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Specific Example Styles */
.btn-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.action-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.action-btn:hover {
    transform: translateY(-2px);
}

#console-emulator,
#event-log {
    flex-grow: 1;
    background: #000;
    border-radius: 12px;
    padding: 1rem;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.log-entry {
    margin-bottom: 0.5rem;
    border-bottom: 1px solid #222;
    padding-bottom: 0.2rem;
}

.variable-display {
    background: rgba(0, 0, 0, 0.4);
    padding: 2rem;
    border-radius: 16px;
    border: 1px dashed var(--border);
}

.value {
    font-family: 'Fira Code', monospace;
    color: #fbbf24;
    font-size: 1.2rem;
    transition: transform 0.1s;
}

/* --- Presentation Mode --- */
.presentation-mode p {
    font-size: 1.4rem;
    line-height: 1.8;
}

.presentation-mode h1 {
    font-size: 3.5rem;
}

.presentation-mode h2 {
    font-size: 2.2rem;
    margin: 2rem 0 1.5rem;
}

.presentation-mode .code-block {
    font-size: 1.2rem;
    padding: 2rem;
}

.presentation-mode .action-btn {
    font-size: 1.2rem;
    padding: 1.5rem;
}

.presentation-mode input {
    font-size: 1.4rem !important;
    padding: 1.2rem !important;
}

.presentation-mode .log-entry {
    font-size: 1.2rem;
    margin-bottom: 0.8rem;
}

.presentation-mode #type-res,
.presentation-mode #fn-res {
    font-size: 2.2rem !important;
}

.presentation-mode #math-res {
    font-size: 2.8rem !important;
}

.presentation-mode #count-display {
    font-size: 7rem !important;
}

.presentation-mode .drawer-item {
    font-size: 1.2rem;
    padding: 1.5rem;
}

.mode-select {
    margin-left: auto;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
}

.mode-select option {
    background: var(--bg);
    color: white;
}

/* Guide Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    padding: 2rem;
}

.modal-overlay.active {
    display: flex;
}

.guide-modal {
    background: #1e293b;
    border: 1px solid var(--border);
    border-radius: 24px;
    width: 100%;
    max-width: 900px;
    padding: 2.5rem;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: modalIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.close-modal {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.close-modal:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.step-list {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.step-item {
    display: flex;
    gap: 1.2rem;
    align-items: flex-start;
}

.step-number {
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.step-content h4 {
    color: #fff;
    margin-bottom: 0.4rem;
    font-size: 1.1rem;
}

.step-content p {
    font-size: 0.95rem;
    line-height: 1.5;
    margin: 0;
}

.guide-btn {
    margin-top: 2rem;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: var(--primary-light);
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    transition: var(--transition);
    width: fit-content;
}

.guide-btn:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-2px);
}

/* --- Image Overlay --- */
.image-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    cursor: zoom-out;
    backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-overlay img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.image-overlay.active {
    display: flex;
    opacity: 1;
}

.image-overlay.active img {
    transform: scale(1);
}
