:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-color: #2563eb; /* alias for compatibility */
    --secondary: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #ffffff;
    --bg2: #f9fafb;
    --text: #111827;
    --text2: #6b7280;
    --border: #e5e7eb;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg2);
}

.site-home-bar {
    padding: 0.5rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    max-width: 1200px;
    margin: 0 auto;
}
.site-home-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
}
.site-home-link:hover {
    text-decoration: underline;
}

.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }
.course-content { max-width: 900px; margin: 0 auto; padding: 2rem; background: var(--bg); border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

header { text-align: center; margin-bottom: 3rem; padding: 2rem; background: var(--bg); border-radius: 8px; }
h1 { font-size: 2.5rem; color: var(--primary); margin-bottom: 0.5rem; }
h2 { color: var(--primary); margin: 2rem 0 1rem; font-size: 1.5rem; }
h3 { margin-top: 1.5rem; margin-bottom: 0.75rem; font-size: 1.2rem; }

.progress-bar { width: 100%; height: 30px; background: var(--bg2); border-radius: 15px; overflow: hidden; margin: 1rem 0; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); transition: width 0.3s; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; }

.course-header { border-bottom: 2px solid var(--border); padding-bottom: 1rem; margin-bottom: 2rem; }
.course-header h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.course-meta { display: flex; gap: 2rem; color: var(--text2); font-size: 0.9rem; }

.section { margin: 2rem 0; padding: 1.5rem; background: var(--bg2); border-radius: 8px; }
.section h2 { margin-top: 0; }

.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.level-heading { margin-top: 2rem; color: var(--primary); }
.module-card { background: var(--bg2); border: 2px solid var(--border); border-radius: 8px; padding: 1.5rem; transition: all 0.3s; cursor: pointer; text-decoration: none; color: inherit; display: block; }
.module-card.available { background: var(--bg); border: 2px solid var(--primary); box-shadow: 0 2px 8px rgba(37, 99, 235, 0.1); }
.module-card.available:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2); background: #eff6ff; }
.module-card.unavailable { background: #f9fafb; border: 2px solid #e5e7eb; opacity: 0.6; cursor: not-allowed; }
.module-card.completed { border-color: var(--secondary); background: #f0fdf4; }
.module-card.in-progress { border-color: var(--warning); background: #fffbeb; }
.module-card h3 { color: var(--primary); margin-bottom: 0.5rem; font-size: 1.2rem; }
.module-title-with-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.badge-hyperscale, .badge-available, .badge-coming {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    white-space: nowrap;
    display: inline-block;
    flex-shrink: 0;
}
.badge-hyperscale { background: #fef3c7; color: #92400e; }
.badge-available { background: #10b981; color: white; font-weight: bold; }
.badge-coming { background: #9ca3af; color: white; }
.module-meta { display: flex; justify-content: space-between; margin-top: 1rem; font-size: 0.9rem; color: var(--text2); }
.module-status { padding: 0.25rem 0.75rem; border-radius: 12px; font-size: 0.8rem; font-weight: bold; }
.status-pending { background: var(--bg2); color: var(--text2); }
.status-in-progress { background: #fef3c7; color: #92400e; }
.status-completed { background: #d1fae5; color: #065f46; }

/* Resources section: card grid */
.resources { margin: 2.5rem 0; }
.resources h2 { margin-bottom: 1.25rem; }
.resource-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; }
.resource-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 1.5rem;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: all 0.25s ease;
    position: relative;
}
.resource-card:hover {
    border-color: var(--primary);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.12);
    background: #fafbff;
}
.resource-card:hover .resource-arrow { transform: translateX(4px); opacity: 1; }
.resource-icon { font-size: 2rem; margin-bottom: 0.75rem; line-height: 1; }
.resource-title { margin: 0 0 0.5rem 0; font-size: 1.15rem; color: var(--primary); font-weight: 700; }
.resource-desc { margin: 0; font-size: 0.9rem; color: var(--text2); line-height: 1.45; }
.resource-card .resource-desc .glossary-term { color: var(--primary); }
.resource-arrow { position: absolute; top: 1.5rem; right: 1.5rem; font-size: 1.25rem; color: var(--primary); opacity: 0.7; transition: transform 0.2s ease, opacity 0.2s ease; }

.quiz-container { background: var(--bg); border: 2px solid var(--border); border-radius: 8px; padding: 1.5rem; margin: 1.5rem 0; }
.quiz-container .btn { margin-top: 1rem; }
.question { margin-bottom: 1.5rem; }
.question-text { font-weight: bold; margin-bottom: 1rem; }
.option { margin: 0.75rem 0; padding: 0.75rem; background: var(--bg2); border: 2px solid var(--border); border-radius: 6px; cursor: pointer; transition: all 0.2s; }
.option:hover { border-color: var(--primary); background: #eff6ff; }
.option.selected { border-color: var(--primary); background: #dbeafe; }
.option.correct { border-color: var(--secondary); background: #d1fae5; }
.option.incorrect { border-color: var(--danger); background: #fee2e2; }
.question.question-wrong { border-left: 4px solid var(--danger); background: #fef2f2; border-radius: 6px; padding-left: 0.75rem; margin-left: -0.75rem; }
.quiz-results { margin-top: 1.5rem; padding: 1rem; border-radius: 6px; font-weight: bold; }
.quiz-results.passed { background: #d1fae5; color: #065f46; }
.quiz-results.failed { background: #fee2e2; color: #991b1b; }
.quiz-explanations { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid rgba(0,0,0,0.1); font-weight: normal; font-size: 0.95rem; }
.quiz-explanations h4 { margin-bottom: 0.5rem; font-size: 1rem; }
.quiz-explanations ul { margin: 0; padding-left: 1.25rem; }
.quiz-explanations li { margin-bottom: 0.5rem; }

.assignment { background: #fef3c7; border-left: 4px solid var(--warning); padding: 1.5rem; margin: 1.5rem 0; border-radius: 6px; }
.assignment h3 { color: #92400e; margin-top: 0; }

.code-block { background: #1e293b; color: #e2e8f0; padding: 1rem; border-radius: 6px; overflow-x: auto; font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, monospace; font-size: 0.9rem; margin: 1rem 0; }
.code-block pre { margin: 0; white-space: pre; }
.code-block code { display: block; font-family: inherit; font-size: inherit; color: inherit; }
/* Light code block (e.g. manifest snippets) */
.code-block-light { background: #f1f5f9; color: var(--text); padding: 1rem; border-radius: 6px; overflow-x: auto; font-size: 0.9rem; margin: 0.75rem 0; }
.code-block-light code { font-family: ui-monospace, monospace; }
/* Section with less top margin */
.section-tight { margin-top: 1.5rem; }
/* Nested list in info/section */
.list-nested { margin: 0.75rem 0 0 1.25rem; padding-left: 0.5rem; }
.info h3 { margin-top: 0; font-size: 1.1rem; }
.info p:last-child { margin-bottom: 0; }

.navigation { display: flex; justify-content: space-between; margin-top: 2rem; padding-top: 2rem; border-top: 2px solid var(--border); gap: 0.75rem; flex-wrap: wrap; }
.navigation .btn { text-align: center; white-space: nowrap; }

.btn { padding: 0.75rem 1.5rem; border: none; border-radius: 6px; font-size: 1rem; font-weight: bold; cursor: pointer; transition: all 0.2s; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #1d4ed8; transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.btn-secondary { background: var(--bg2); color: var(--text); border: 2px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

@media (max-width: 640px) {
    .navigation { flex-direction: column; align-items: stretch; }
    .navigation .btn { width: 100%; min-height: 48px; white-space: nowrap; }
}

/* In-content links (not nav or buttons) */
.course-content .section a:not(.btn):not(.site-home-link),
.course-content a[href*=".html"]:not(.btn):not(.site-home-link) {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}
.course-content .section a:not(.btn):not(.site-home-link):hover,
.course-content a[href*=".html"]:not(.btn):not(.site-home-link):hover {
    color: var(--primary-hover);
    border-bottom-color: var(--primary);
}
.course-content .section a[target="_blank"]:not(.btn)::after {
    content: " ↗";
    font-size: 0.75em;
    opacity: 0.8;
}

.info { background: #dbeafe; border-left: 4px solid var(--primary); padding: 1rem; margin: 1rem 0; border-radius: 4px; }
.warning { background: #fee2e2; border-left: 4px solid var(--danger); padding: 1rem; margin: 1rem 0; border-radius: 4px; }
.success { background: #d1fae5; border-left: 4px solid var(--secondary); padding: 1rem; margin: 1rem 0; border-radius: 4px; }

/* Block Diagram Styles */
.block-diagram {
    margin: 2rem 0;
    padding: 1.5rem;
    background: var(--bg2);
    border-radius: 8px;
    text-align: center;
}

.diagram-block {
    display: inline-block;
    border: 2px solid var(--primary);
    border-radius: 6px;
    background: var(--bg);
    min-width: 280px;
    margin: 0 auto;
    overflow: hidden;
}

.block-header, .block-body {
    padding: 1rem;
}

.block-header {
    background: #eff6ff;
    border-bottom: 2px solid var(--primary);
}

.block-divider {
    height: 2px;
    background: var(--primary);
}

.block-title {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.block-field {
    text-align: left;
    padding: 0.25rem 0;
    color: var(--text);
    font-size: 0.9rem;
    font-family: ui-monospace, monospace;
}

.diagram-arrow {
    font-size: 1.5rem;
    color: var(--primary);
    margin: 0.75rem 0;
    font-weight: bold;
}

.diagram-label {
    color: var(--text2);
    font-size: 0.9rem;
    margin: 0.5rem 0;
    font-style: italic;
}

/* Glossary Tooltip Styles */
.glossary-term {
    color: var(--primary);
    text-decoration: underline dotted;
    text-underline-offset: 2px;
    cursor: help;
}

.glossary-term:hover {
    color: var(--primary-hover);
    text-decoration-style: solid;
}

.glossary-tooltip {
    display: none;
    position: fixed;
    z-index: 10000;
    background: var(--bg);
    border: 2px solid var(--primary);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-width: 350px;
    min-width: 280px;
    font-size: 0.9rem;
    pointer-events: auto;
}

.tooltip-header {
    background: #eff6ff;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    border-radius: 6px 6px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tooltip-header strong { color: var(--primary); font-size: 1rem; }
.tooltip-category { background: var(--primary); color: white; padding: 0.2rem 0.5rem; border-radius: 12px; font-size: 0.7rem; font-weight: 600; }
.tooltip-body { padding: 1rem; color: var(--text); line-height: 1.5; }
.tooltip-footer { padding: 0.75rem 1rem; border-top: 1px solid var(--border); background: var(--bg2); border-radius: 0 0 6px 6px; }
.tooltip-link { color: var(--primary); text-decoration: none; font-size: 0.85rem; font-weight: 600; }
.tooltip-link:hover { text-decoration: underline; }
.tooltip-def { margin: 0 0 0.5rem 0; font-size: 0.9rem; color: #111; }
.tooltip-def strong { color: #000; }
.tooltip-10yo { margin: 0; font-size: 0.85rem; color: #2563eb; }
.tooltip-10yo em { color: #1e3a8a; font-weight: 700; font-style: normal; }
.tooltip-expand { display: inline-block; color: var(--primary); font-weight: 600; font-size: 0.9rem; text-decoration: none; padding: 0.35rem 0.75rem; border: 1px solid var(--primary); border-radius: 6px; }
.tooltip-expand:hover { background: #eff6ff; text-decoration: none; }

/* Glossary full page: by subcategory */
.glossary-category { margin-bottom: 2.5rem; }
.glossary-category-title { margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 2px solid var(--primary); color: var(--primary); }
.glossary-entries { display: flex; flex-direction: column; gap: 1.5rem; }
.glossary-entry { padding: 1.25rem; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.glossary-entry.glossary-highlight { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2); }
.glossary-term-title { margin: 0 0 0.5rem 0; font-size: 1.2rem; color: var(--primary); }
.glossary-meta { margin-bottom: 0.75rem; }
.glossary-tag { display: inline-block; margin-right: 0.5rem; margin-bottom: 0.25rem; padding: 0.2rem 0.5rem; background: #eff6ff; color: var(--primary); border-radius: 4px; font-size: 0.75rem; }
.glossary-full-def { margin: 0.75rem 0; line-height: 1.5; color: #111; }
.glossary-full-def .glossary-technical-label { color: #000; font-weight: 700; }
.glossary-10yo { margin: 0.75rem 0; line-height: 1.5; color: #2563eb; }
.glossary-10yo .glossary-10yo-label { color: #1e3a8a; font-weight: 700; }
.glossary-competing { margin: 0.75rem 0; line-height: 1.5; padding: 0.75rem; background: var(--bg2); border-radius: 6px; font-size: 0.95rem; color: #475569; }
.glossary-competing .glossary-competing-label { color: #334155; font-weight: 700; }

ul, ol { margin: 1rem 0; padding-left: 2rem; }
li { margin: 0.5rem 0; }
p { margin: 1rem 0; }
table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
th, td { padding: 0.5rem; border: 1px solid var(--border); }
th { background: var(--bg2); }

/* Transaction flow diagram (shared across modules) */
.tx-flow { --hyperscale-bg: #eff6ff; --hyperscale-border: var(--primary); --outside-bg: #f8fafc; --outside-border: #94a3b8; }
.tx-flow-legend { display: flex; gap: 1.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.tx-flow-legend span { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; color: var(--text2); }
.tx-flow-legend .dot-hyperscale { width: 14px; height: 14px; border-radius: 4px; background: var(--hyperscale-bg); border: 2px solid var(--hyperscale-border); }
.tx-flow-legend .dot-outside { width: 14px; height: 14px; border-radius: 4px; background: var(--outside-bg); border: 2px solid var(--outside-border); }
.tx-flow-diagram { display: flex; flex-direction: column; gap: 0; position: relative; }
.flow-step { position: relative; display: flex; align-items: stretch; gap: 0; min-height: 52px; }
.flow-step-lane { width: 4px; flex-shrink: 0; border-radius: 2px; }
.flow-step-lane.hyperscale { background: var(--hyperscale-border); }
.flow-step-lane.outside { background: var(--outside-border); }
.flow-step-body { flex: 1; padding: 0.75rem 1rem; border: 2px solid var(--border); border-radius: 6px; margin-left: 8px; background: var(--bg); cursor: default; }
.flow-step.hyperscale .flow-step-body { border-color: var(--hyperscale-border); background: var(--hyperscale-bg); }
.flow-step.outside .flow-step-body { border-color: var(--outside-border); background: var(--outside-bg); }
.flow-step-arrow { text-align: center; padding: 2px 0; color: var(--text2); font-size: 1.2rem; }
.flow-step-title { font-weight: 700; font-size: 1rem; margin-bottom: 0.25rem; }
.flow-step-desc { font-size: 0.875rem; color: var(--text2); }
.flow-step-body a.crate-link { font-size: 0.8rem; color: var(--primary); }
.flow-step-popup { display: none; position: absolute; left: 100%; top: 50%; transform: translateY(-50%); margin-left: 10px; min-width: 180px; padding: 0.75rem 1rem; background: var(--bg); border: 2px solid var(--hyperscale-border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 10; font-size: 0.875rem; pointer-events: none; }
.flow-step:hover .flow-step-popup { display: block; }
.flow-step-popup h4 { margin: 0 0 0.5rem; font-size: 0.8rem; text-transform: uppercase; color: var(--text2); }
.flow-step-popup ul { margin: 0; padding-left: 1.1rem; }
.flow-step-popup li { margin-bottom: 0.35rem; }
.flow-step-popup a { color: var(--primary); text-decoration: none; }
.flow-step-popup a:hover { text-decoration: underline; }
.flow-step-popup .outside-note { font-style: italic; color: var(--text2); margin-top: 0.5rem; }
@media (max-width: 640px) {
    .flow-step-popup { left: 0; right: 0; margin-left: 0; margin-right: 0; top: 100%; transform: none; margin-top: 6px; }
}

/* Test runner page (test-modules.html) */
.test-wrap { background: var(--bg); padding: 1.5rem; margin: 1rem 0; border-radius: 8px; }
.test-pass { background: #d1fae5; padding: 0.75rem; margin: 0.5rem 0; border-radius: 4px; border-left: 4px solid var(--secondary); }
.test-fail { background: #fee2e2; padding: 0.75rem; margin: 0.5rem 0; border-radius: 4px; border-left: 4px solid var(--danger); }
.test-summary { margin-top: 1rem; font-weight: bold; }