/** 
 * STEM Nexus - Core Styling (Vanilla CSS)
 * Implements a rich, vibrant, glassmorphic dark mode UI suitable for educational dashboard.
 */

:root {
    /* Color Palette */
    --bg-base: #090a0f;
    --bg-nav: rgba(14, 16, 25, 0.75);
    --bg-sidebar: rgba(18, 20, 31, 0.6);
    --bg-card: rgba(26, 30, 46, 0.45);
    
    --text-primary: #f8fafc;
    --text-sec: #94a3b8;
    --text-muted: #64748b;
    
    /* Vibrant Accents */
    --accent-blue: #3b82f6;
    --accent-blue-glow: rgba(59, 130, 246, 0.5);
    --accent-purple: #8b5cf6;
    --accent-emerald: #10b981;
    --accent-rose: #f43f5e;
    --accent-amber: #fbbf24;
    
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.15);
    
    /* Layout Dimensions */
    --left-sidebar-w: 280px;
    --right-sidebar-w: 300px;
    --top-nav-h: 72px;
    
    --transition-snappy: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-base);
    /* Dynamic background mesh gradient substitute */
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(139, 92, 246, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(16, 185, 129, 0.05) 0%, transparent 60%);
    background-attachment: fixed;
    overflow: hidden; /* Dashboard app paradigm */
}

h1, h2, h3, h4, h5, .brand {
    font-family: 'Outfit', sans-serif;
}

/* Base utilities */
.text-blue { color: var(--accent-blue); }
.text-emerald { color: var(--accent-emerald); }
.text-purple { color: var(--accent-purple); }
.text-rose { color: var(--accent-rose); }
.text-amber { color: var(--accent-amber); }
.bg-blue { background: rgba(59, 130, 246, 0.2); color: var(--accent-blue); }
.bg-emerald { background: rgba(16, 185, 129, 0.2); color: var(--accent-emerald); }
.bg-rose { background: rgba(244, 63, 94, 0.2); color: var(--accent-rose); }
.bg-amber { background: rgba(251, 191, 36, 0.2); color: var(--accent-amber); }
.text-muted { color: var(--text-muted); }
.mt-2 { margin-top: 0.5rem; }

/* ---------------------------------
   GLOBAL APP CONTAINER
----------------------------------- */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* ---------------------------------
   TOP NAVIGATION BAR
----------------------------------- */
.top-nav {
    height: var(--top-nav-h);
    background: var(--bg-nav);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 100;
}

.nav-left, .nav-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    min-width: 280px;
}

.nav-right {
    justify-content: flex-end;
}

.nav-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.brand span {
    font-weight: 300;
    color: var(--accent-blue);
    -webkit-text-fill-color: var(--accent-blue);
}

.lesson-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.badge {
    background: rgba(139, 92, 246, 0.15);
    color: #c4b5fd;
    border: 1px solid rgba(139, 92, 246, 0.3);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.page-title {
    font-size: 1.15rem;
    font-weight: 500;
}

.page-subtitle {
    font-size: 0.8rem;
    color: var(--text-sec);
    margin-top: 2px;
}

/* Buttons */
.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all var(--transition-snappy);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-highlight);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}
.avatar:hover {
    border-color: var(--accent-emerald);
}

/* Tooltip */
.tooltip-container {
    position: relative;
}

.tooltip-container .tooltip {
    position: absolute;
    top: 130%;
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    background: #1e2235;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    border: 1px solid var(--border-subtle);
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    pointer-events: none;
    z-index: 200;
}
.tooltip-container:hover .tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Inline Word Definition Tooltip */
.def-tooltip {
    position: relative;
    border-bottom: 2px dotted rgba(255, 255, 255, 0.4);
    cursor: help;
    transition: all 0.25s ease;
}

.def-tooltip:hover {
    border-bottom-color: var(--accent-emerald);
    color: var(--accent-emerald);
}

/* Tooltip Body */
.def-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: #1e2235;
    color: #f8fafc;
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 400;
    white-space: normal;
    width: max-content;
    max-width: 260px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid var(--border-subtle);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 1000;
    pointer-events: none;
    line-height: 1.5;
    text-align: left;
}

/* Speech Bubble Tail */
.def-tooltip::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    border-width: 8px 8px 0;
    border-style: solid;
    border-color: #1e2235 transparent transparent transparent;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1001;
    pointer-events: none;
}

/* Small pseudo-element to create border for tail */
/* In pure css, a simple filled tail is usually sufficient due to dark mode matching */

.def-tooltip:hover::after,
.def-tooltip:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* ---------------------------------
   TOP EXTENDED PANEL
----------------------------------- */
.top-extended-panel {
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;             /* vertical clip for collapse animation */
    max-height: 0;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 99;
    flex-shrink: 0;
}

.top-extended-panel.expanded {
    max-height: 250px;
    opacity: 1;
}

.top-extended-panel .extended-content {
    padding: 0.8rem 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    overflow: visible;            /* allow skip btns to remain visible */
}

.extended-options-grid {
    display: flex;
    gap: 0.6rem;
    flex-wrap: nowrap;            /* keep all nav pills on one row */
    justify-content: flex-start;
    align-items: center;
    overflow-x: auto;             /* horizontal scroll when buttons overflow */
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;        /* hide scrollbar (Firefox) */
    -ms-overflow-style: none;     /* hide scrollbar (IE/Edge) */
    flex: 1;
    min-width: 0;                 /* allow flex child to shrink below content */
}
.extended-options-grid::-webkit-scrollbar {
    display: none;                /* hide scrollbar (Chrome/Safari) */
}

.extended-options-grid .tool-btn {
    flex-shrink: 0;               /* prevent nav pills from shrinking */
    white-space: nowrap;          /* keep text on one line */
}
.extended-options-grid .tool-btn:hover {
    transform: translateY(-3px);
}

.extended-options-grid .tool-btn.active-anchor {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent-blue);
    transform: translateY(-3px);
    color: #fff;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.15);
}

/* ── Section Skip Arrows (prev / next in top-extended panel) ── */
.section-skip-btn {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}
.section-skip-btn:hover {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.45);
    color: #6ee7b7;
    box-shadow: 0 0 14px rgba(16, 185, 129, 0.25);
    transform: scale(1.15);
}
.section-skip-btn:active {
    transform: scale(0.92);
}
.section-skip-btn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
    pointer-events: none;
}
.section-skip-prev { margin-right: 0.5rem; }
.section-skip-next { margin-left:  0.5rem; }

.icon-btn.small-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 0.75rem;
}

.transition-icon {
    transition: transform 0.3s ease;
}

.subtitle-group {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}
.subtitle-group .page-subtitle {
    margin-top: 0;
}

/* ---------------------------------
   MAIN WORKSPACE
----------------------------------- */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ---------------------------------
   SIDEBARS (Left & Right)
----------------------------------- */
.sidebar {
    background: var(--bg-sidebar);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    height: 100%;
    overflow-y: auto;
    transition: all var(--transition-snappy);
    z-index: 50;
    flex-shrink: 0; /* do not shrink */
}

/* Scrollbar styling */
.sidebar::-webkit-scrollbar, .main-content::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-track, .main-content::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb, .main-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
}

/* Left Sidebar specific */
.left-sidebar {
    width: var(--left-sidebar-w);
    border-right: 1px solid var(--border-subtle);
}

/* Right Sidebar specific */
.right-sidebar {
    width: var(--right-sidebar-w);
    border-left: 1px solid var(--border-subtle);
}

/* Toggled Collapsed State */
.sidebar.collapsed {
    width: 0 !important;
    border: none;
    padding-left: 0;
    padding-right: 0;
    overflow: hidden;
    opacity: 0;
}

.sidebar-content {
    padding: 1.5rem;
    /* ensure content doesn't crush when collapsing */
    min-width: var(--left-sidebar-w); 
    opacity: 1;
    transition: opacity 0.2s;
}
.right-sidebar .sidebar-content {
    min-width: var(--right-sidebar-w);
}

.sidebar-heading {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-sec);
    margin-bottom: 1.5rem;
}

/* Left Sidebar Nav Lists */
.nav-list {
    list-style: none;
}
.nav-category {
    margin-bottom: 0.5rem;
}
.category-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    font-weight: 500;
}
.category-header:hover {
    background: rgba(255,255,255,0.05);
}
.category-header i:first-child {
    width: 24px;
    font-size: 1.1rem;
}
.category-header > span {
    flex: 1;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.category-header span.subject-suffix {
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}
.category-header .chevron {
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: transform 0.3s;
}

.category-items {
    list-style: none;
    padding-left: 36px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.category-items.open {
    max-height: 1500px; /* Increased to accommodate longer lists of subjects */
    margin-top: 4px;
    margin-bottom: 12px;
}

.nav-link {
    display: block;
    color: var(--text-sec);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    transition: all 0.2s;
    position: relative;
}
.nav-link:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.03);
}
.nav-link.active {
    color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.1);
    font-weight: 500;
}
.nav-link.active::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-blue);
    box-shadow: 0 0 10px var(--accent-blue-glow);
}

/* Right Sidebar Toolkit */
.resource-section {
    margin-bottom: 2rem;
}
.section-title {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tool-btn {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 5px 10px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: all 0.25s;
    text-align: left;
}
.tool-btn:hover {
    background: rgba(255,255,255,0.05);
    border-color: var(--accent-blue);
    transform: translateX(4px);
}
.tool-btn i {
    color: var(--text-sec);
    font-size: 0.82rem;
}

.constant-card {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-subtle);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 3px solid var(--accent-purple);
}
.constant-name {
    font-size: 0.8rem;
    color: var(--text-sec);
    margin-bottom: 4px;
}
.constant-val {
    font-family: 'Courier New', Courier, monospace;
    font-weight: 600;
    color: var(--text-primary);
}

.link-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.reference-link {
    color: var(--text-sec);
    text-decoration: none;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 6px;
    background: rgba(255,255,255,0.02);
    transition: all 0.2s;
}
.reference-link:hover {
    color: var(--text-primary);
    background: rgba(16, 185, 129, 0.1);
}

/* ---------------------------------
   MAIN CONTENT AREA (Middle)
----------------------------------- */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 3rem;
    scroll-behavior: smooth;
}

.content-header {
    margin-bottom: 2rem;
}
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}
.breadcrumbs a {
    color: var(--text-sec);
    text-decoration: none;
    transition: color 0.2s;
}
.breadcrumbs a:hover {
    color: var(--accent-blue);
}
.breadcrumbs span {
    color: var(--text-muted);
}

/* Dashboard Cards Structure */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 24px;
    max-width: 100%;
    margin: 0 auto;
    transition: max-width 0.4s ease;
}

.span-2 { grid-column: span 2; }
.span-full { grid-column: span 4; }

.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    display: flex;
    align-items: center;
    gap: 12px;
}
.icon-wrapper {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}
.card-header h3 {
    font-size: 1.1rem;
    font-weight: 500;
}

.card-body {
    padding: 1.5rem;
    color: var(--text-sec);
    line-height: 1.6;
    flex: 1;
}
.card-body.no-padding {
    padding: 0;
}

.equation-box {
    margin-top: 1rem;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 12px;
    padding: 1rem;
    font-family: 'Outfit', sans-serif;
    font-size: 1.4rem;
    font-style: normal;
    color: var(--accent-blue);
    text-align: center;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}

/* Override KaTeX fonts to use the header font for a cooler, cohesive look */
.katex, .katex * {
    font-family: 'Outfit', sans-serif !important;
    font-style: normal !important;
}

/* Videos and Embeds */
.embed-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 ratio */
    height: 0;
    overflow: hidden;
    background: #000;
}

.embed-container.geogebra {
    padding-bottom: 50%;
    background: rgba(0,0,0,0.5);
}

.video-overlay, .geogebra-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 5;
    background: rgba(0,0,0,0.4);
}

.video-overlay {
    color: var(--text-primary);
    font-size: 1.5rem;
}
.video-overlay i {
    font-size: 4rem;
    color: rgba(255,255,255,0.8);
    transition: transform 0.3s;
}
.embed-container:hover .video-overlay i {
    transform: scale(1.1);
}

.geogebra-overlay {
    background: #1e2235; /* Covers iframe placeholder for aesthetic */
    text-align: center;
    padding: 2rem;
    border-top: 1px solid var(--border-subtle);
}
.geogebra-overlay h4 {
    color: var(--text-primary);
    font-size: 1.2rem;
    margin-top: 10px;
}

/* ---------------------------------
   RESPONSIVENESS
----------------------------------- */
@media (max-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .span-2, .span-full {
        grid-column: span 2;
    }
}

@media (max-width: 900px) {
    .nav-center { display: none; }
    .main-content { padding: 1.5rem; }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .span-2, .span-full {
        grid-column: span 1;
    }
}
