/* ==========================================================================
   Main Stylesheet — Statistical Analysis with Python FDP
   Dark mode by default, uses CSS variables throughout.
   ========================================================================== */

/* ── CSS Variables (Dark Theme — Default) ─────────────────────────────── */
:root,
[data-theme="dark"] {
    /* Backgrounds */
    --bg: #0d1117;
    --bg-alt: #161b22;
    --surface: #1c2333;
    --surface-hover: #212a3b;
    --surface-raised: #252d3f;

    /* Text */
    --text: #e6edf3;
    --text-light: #8b949e;
    --text-muted: #6e7681;
    --text-heading: #f0f6fc;

    /* Borders */
    --border: #30363d;
    --border-light: #21262d;

    /* Primary (blue) */
    --primary: #58a6ff;
    --primary-light: #79c0ff;
    --primary-dark: #388bfd;
    --primary-bg: rgba(56, 139, 253, 0.15);

    /* Accent (purple/indigo) */
    --accent: #a371f7;
    --accent-light: #c297ff;
    --accent-dark: #8957e5;

    /* Semantic colors */
    --success: #3fb950;
    --success-bg: rgba(63, 185, 80, 0.15);
    --warning: #d29922;
    --warning-bg: rgba(210, 153, 34, 0.15);
    --danger: #f85149;
    --danger-bg: rgba(248, 81, 73, 0.15);
    --info: #58a6ff;
    --info-bg: rgba(88, 166, 255, 0.15);

    /* Gradient backgrounds */
    --gradient-hero: linear-gradient(135deg, #0d1117 0%, #161b22 40%, #1a1a3e 70%, #2c1f52 100%);
    --gradient-card: linear-gradient(135deg, #1c2333 0%, #212a3b 100%);
    --gradient-header: linear-gradient(135deg, #1a1a3e 0%, #2c1f52 100%);

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

    /* Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
    --font-size-4xl: 2.25rem;

    /* Layout */
    --max-width: 1200px;
    --content-width: 800px;
    --header-height: 64px;
}

/* ── Light Theme Overrides ────────────────────────────────────────────── */
[data-theme="light"] {
    --bg: #ffffff;
    --bg-alt: #f6f8fa;
    --surface: #f0f2f5;
    --surface-hover: #e8eaed;
    --surface-raised: #ffffff;

    --text: #1f2328;
    --text-light: #656d76;
    --text-muted: #8b949e;
    --text-heading: #1f2328;

    --border: #d0d7de;
    --border-light: #e8eaed;

    --primary: #0969da;
    --primary-light: #218bff;
    --primary-dark: #0550ae;
    --primary-bg: rgba(9, 105, 218, 0.08);

    --accent: #8250df;
    --accent-light: #9a6eff;
    --accent-dark: #6e40c9;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

    --gradient-hero: linear-gradient(135deg, #f6f8fa 0%, #e8eaed 40%, #eef2ff 70%, #f5f0ff 100%);
    --gradient-card: linear-gradient(135deg, #ffffff 0%, #f6f8fa 100%);
    --gradient-header: linear-gradient(135deg, #1a1a3e 0%, #2c1f52 100%);
}

/* ── Reset & Base ──────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    background: var(--bg);
    color: var(--text);
}

body {
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: 1.7;
    color: var(--text);
    background-color: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Typography ────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-heading);
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 0.5em;
}

h1 { font-size: var(--font-size-4xl); }
h2 { font-size: var(--font-size-3xl); }
h3 { font-size: var(--font-size-2xl); }
h4 { font-size: var(--font-size-xl); }
h5 { font-size: var(--font-size-lg); }
h6 { font-size: var(--font-size-base); }

p {
    margin-bottom: 1rem;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-light);
    text-decoration: underline;
}

code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--surface);
    padding: 0.15em 0.4em;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    color: var(--accent-light);
}

pre {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    overflow-x: auto;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 1.25rem;
}

pre code {
    background: transparent;
    border: none;
    padding: 0;
    color: var(--text);
}

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

li {
    margin-bottom: 0.25rem;
}

blockquote {
    border-left: 4px solid var(--primary);
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    background: var(--surface);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: var(--text-light);
}

strong {
    color: var(--text-heading);
    font-weight: 600;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
}

/* ── Tables ────────────────────────────────────────────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
    font-size: var(--font-size-sm);
}

thead {
    background: var(--surface);
}

th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--text-heading);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border-light);
}

tbody tr:hover {
    background: var(--surface-hover);
}

/* ── Layout ────────────────────────────────────────────────────────────── */
main {
    flex: 1;
    width: 100%;
}

.module-container,
.page-container {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

/* ── Site Header ──────────────────────────────────────────────────────── */
#header-container {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    min-height: var(--header-height);
}

/* Fallback: if header is empty, ensure the sticky bar still has background */
#header-container:empty {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: var(--header-height);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.site-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-heading);
    font-weight: 700;
    font-size: var(--font-size-lg);
    text-decoration: none;
    white-space: nowrap;
}

.site-logo:hover {
    color: var(--primary);
    text-decoration: none;
}

.logo-icon {
    font-size: 1.4rem;
}

/* ── Navigation ────────────────────────────────────────────────────────── */
.site-nav .nav-list {
    display: flex;
    list-style: none;
    gap: 0.25rem;
    padding: 0;
    margin: 0;
}

.site-nav .nav-list > li > a {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text-light);
    font-size: var(--font-size-sm);
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    text-decoration: none;
}

.site-nav .nav-list > li > a:hover {
    color: var(--text);
    background: var(--surface-hover);
}

/* Dropdown */
.nav-dropdown {
    position: relative;
}

.nav-dropdown-btn {
    background: none;
    border: none;
    padding: 0.5rem 0.75rem;
    color: var(--text-light);
    font-size: var(--font-size-sm);
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.25rem;
    transition: all var(--transition-fast);
}

.nav-dropdown-btn:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.dropdown-arrow {
    font-size: 0.6rem;
    transition: transform var(--transition-fast);
}

.nav-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 260px;
    padding: 0.5rem;
    list-style: none;
    z-index: 200;
}

.nav-dropdown.open .nav-dropdown-menu {
    display: block;
}

.nav-dropdown-menu li a {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text);
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background var(--transition-fast);
}

.nav-dropdown-menu li a:hover {
    background: var(--surface-hover);
    text-decoration: none;
}

/* ── Header Controls ───────────────────────────────────────────────────── */
.header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-light);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    line-height: 1;
}

.theme-toggle-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-dark { display: none; }

/* Mobile menu toggle */
.mobile-menu-btn {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.menu-bar {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: all var(--transition-fast);
}

/* ── Site Footer ──────────────────────────────────────────────────────── */
.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 3rem 1.5rem 1.5rem;
    margin-top: auto;
}

.footer-inner {
    max-width: var(--max-width);
    margin: 0 auto;
}

.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-col h3 {
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.footer-col ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-col ul li {
    margin-bottom: 0.35rem;
}

.footer-col ul li a {
    color: var(--text-light);
    font-size: var(--font-size-sm);
    text-decoration: none;
}

.footer-col ul li a:hover {
    color: var(--primary);
}

.footer-col p {
    color: var(--text-light);
    font-size: var(--font-size-sm);
    line-height: 1.6;
}

.footer-bottom {
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
    text-align: center;
}

.footer-bottom p {
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    margin: 0;
}

/* ── Module/Chapter Header ─────────────────────────────────────────────── */
.module-header,
.chapter-header {
    background: var(--gradient-header);
    color: #fff;
    padding: 2.5rem 2rem;
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
    text-align: center;
}

.module-header h1,
.chapter-header h1 {
    color: #fff;
    font-size: var(--font-size-4xl);
    margin-bottom: 0.5rem;
}

.module-header .module-meta,
.chapter-header .chapter-meta {
    color: rgba(255, 255, 255, 0.7);
    font-size: var(--font-size-sm);
}

.module-meta span,
.chapter-meta span {
    margin: 0 0.5rem;
}

.module-meta span:first-child,
.chapter-meta span:first-child {
    margin-left: 0;
}

/* ── Module Navigation ─────────────────────────────────────────────────── */
.module-nav-top,
.module-nav-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.module-nav-bottom {
    border-bottom: none;
    border-top: 1px solid var(--border);
    margin-top: 3rem;
    padding-top: 1.5rem;
}

.module-nav-top a,
.module-nav-bottom a {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
    font-weight: 500;
    font-size: var(--font-size-sm);
}

.module-nav-top a:hover,
.module-nav-bottom a:hover {
    text-decoration: none;
    color: var(--primary-light);
}

.nav-prev::before { content: "\2190"; }
.nav-next::after { content: "\2192"; }

/* ── Learning Objectives ───────────────────────────────────────────────── */
.learning-objectives {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.learning-objectives h2 {
    font-size: var(--font-size-lg);
    margin-bottom: 0.75rem;
    color: var(--primary-light);
}

.learning-objectives ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.learning-objectives ul li {
    padding: 0.3rem 0 0.3rem 1.5rem;
    position: relative;
}

.learning-objectives ul li::before {
    content: "\2713";
    position: absolute;
    left: 0;
    color: var(--success);
    font-weight: bold;
}

/* ── Prerequisites / Setup ─────────────────────────────────────────────── */
.prerequisites {
    background: var(--info-bg);
    border: 1px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.prerequisites h2 {
    font-size: var(--font-size-lg);
    color: var(--primary-light);
}

.prerequisites code {
    background: var(--surface);
}

/* ── Content Sections ──────────────────────────────────────────────────── */
.content-section {
    margin-bottom: 2.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.content-section:last-child {
    border-bottom: none;
}

.content-section h2 {
    margin-bottom: 0.75rem;
}

.content-section h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

/* ── Key Takeaways ─────────────────────────────────────────────────────── */
.key-takeaways {
    margin: 3rem 0;
}

.key-takeaways h2 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.takeaways-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.takeaway-card {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.takeaway-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.takeaway-number {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--font-size-sm);
}

.takeaway-card p {
    margin: 0;
    font-size: var(--font-size-sm);
    line-height: 1.5;
}

/* ── Hands-On Project ────────────────────────────────────────────────── */
.hands-on-project {
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin: 3rem 0;
}

.hands-on-project h2 {
    color: var(--accent-light);
    margin-bottom: 1rem;
}

.project-brief h3,
.project-steps h3 {
    font-size: var(--font-size-lg);
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.project-steps ol {
    padding-left: 1.5rem;
}

.project-steps ol li {
    margin-bottom: 0.5rem;
}

/* Solution toggle */
.solution-toggle {
    margin-top: 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.solution-toggle > summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--primary);
    background: var(--surface-hover);
    transition: background var(--transition-fast);
    list-style: none;
}

.solution-toggle > summary::-webkit-details-marker {
    display: none;
}

.solution-toggle > summary::before {
    content: "\25B6";
    display: inline-block;
    margin-right: 0.5rem;
    font-size: 0.7rem;
    transition: transform var(--transition-fast);
}

.solution-toggle[open] > summary::before {
    transform: rotate(90deg);
}

.solution-toggle > summary:hover {
    background: var(--surface-raised);
}

.solution-content {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
}

.solution-content h4 {
    margin-top: 0;
}

/* ── Quiz ──────────────────────────────────────────────────────────────── */
.module-quiz,
.chapter-quiz {
    margin: 3rem 0;
    padding: 2rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.module-quiz h2,
.chapter-quiz h2 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.quiz-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.quiz-question {
    padding: 1rem;
    background: var(--bg);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}

.question-text {
    font-weight: 600;
    margin-bottom: 0.75rem;
}

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

.quiz-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.quiz-option:hover {
    background: var(--surface-hover);
}

.quiz-option input[type="radio"] {
    accent-color: var(--primary);
}

.quiz-option.correct {
    background: var(--success-bg);
    border: 1px solid var(--success);
}

.quiz-option.incorrect {
    background: var(--danger-bg);
    border: 1px solid var(--danger);
}

.quiz-feedback {
    padding: 0.75rem;
    margin-top: 0.75rem;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.quiz-feedback.correct {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success);
}

.quiz-feedback.incorrect {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger);
}

.quiz-submit-btn {
    display: block;
    margin: 1.5rem auto 0;
    padding: 0.75rem 2.5rem;
    font-size: var(--font-size-base);
    font-weight: 600;
    font-family: var(--font-sans);
    color: #fff;
    background: var(--primary-dark);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.quiz-submit-btn:hover {
    background: var(--primary);
    box-shadow: var(--shadow-md);
}

.quiz-score {
    text-align: center;
    margin-top: 1rem;
    font-size: var(--font-size-lg);
    font-weight: 700;
}

.quiz-score.passed {
    color: var(--success);
}

.quiz-score.failed {
    color: var(--warning);
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .footer-grid {
        grid-template-columns: 1fr 1fr;
    }

    .module-header h1,
    .chapter-header h1 {
        font-size: var(--font-size-3xl);
    }

    .takeaways-grid {
        grid-template-columns: 1fr;
    }

    .site-nav .nav-list > li > a,
    .nav-dropdown-btn {
        padding: 0.5rem 0.5rem;
        font-size: var(--font-size-xs);
    }

    .site-logo .logo-text {
        display: none;
    }
}

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

    .site-nav {
        display: none;
        position: absolute;
        top: var(--header-height);
        left: 0;
        right: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        padding: 1rem;
    }

    .site-nav.nav-open {
        display: block;
    }

    .site-nav .nav-list {
        flex-direction: column;
    }

    .nav-dropdown-menu {
        position: static;
        box-shadow: none;
        border: none;
        padding-left: 1rem;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .module-container,
    .page-container {
        padding: 1.5rem 1rem 3rem;
    }

    h1 { font-size: var(--font-size-3xl); }
    h2 { font-size: var(--font-size-2xl); }
    h3 { font-size: var(--font-size-xl); }
}

/* ── Utility Classes ───────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: var(--font-size-sm); }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
