.question-difficulty .difficulty-icon {
    width: 1.2em;
    height: 1.2em;
    display: inline-block;
    vertical-align: middle;
    margin-right: 0.45em;
    object-fit: contain;
    background: none;
}

.question-difficulty .difficulty-icon {
    color: inherit;
    /* allow embedded SVG to use currentColor */
}

/* fallback for broken images: hide only <img> icons when missing a src attribute; do not hide font icons (span.material-symbols) */
.question-difficulty img.difficulty-icon:not([src]) {
    display: none;
}

/* === Variables and Global Styles === */
:root {
    --primary-bg: #f4f7f9;
    --card-bg: #ffffff;
    --text-color: #333;
    --primary-color: #007bff;
    --correct-color: #28a745;
    --incorrect-color: #dc3545;
    --border-color: #e0e0e0;
    --meta-color: #6c757d;
    --explanation-bg: #e9f5ff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --correct-highlight-bg: #eaf7ec;
    --incorrect-highlight-bg: #fdecea;
    --nav-bg: #ffffff;
    --dropdown-bg: #ffffff;
    --hover-bg: #f8f9fa;
    /* Minimal difficulty pill variables (chosen mix):
       - easy: the blue shade you wanted (from Palette B)
       - medium: neutral grey
       - hard: vivid red
       No palette overrides or additional variants — single source of truth. */
    /* desaturated/darker choices per request */
    --difficulty-easy-bg: #2a5576;
    /* slightly desaturated blue */
    --difficulty-medium-bg: #7f7f7f;
    /* darker neutral grey for legibility */
    --difficulty-hard-bg: #a50020;
    /* slightly desaturated vivid red */
    --progress-mastered: #2ecc71;
    --progress-mostly-correct: #0d6efd;
    --progress-mostly-incorrect: #ff9800;
    --progress-critical: #dc3545;
    --progress-unattempted: #d9dee5;
}

/* Dark mode variables */
[data-theme="dark"] {
    --primary-bg: #1a1a1a;
    --card-bg: #2d2d2d;
    --text-color: #e0e0e0;
    --primary-color: #4a9eff;
    --correct-color: #4caf50;
    --incorrect-color: #f44336;
    --border-color: #404040;
    --meta-color: #b0b0b0;
    --explanation-bg: #2a3f5f;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --correct-highlight-bg: #1e3a1e;
    --incorrect-highlight-bg: #3a1e1e;
    --nav-bg: #2d2d2d;
    --dropdown-bg: #3a3a3a;
    --hover-bg: #3a3a3a;
    --progress-mastered: #49c788;
    --progress-mostly-correct: #4a9eff;
    --progress-mostly-incorrect: #ffb74d;
    --progress-critical: #ff6b6b;
    --progress-unattempted: #3a4049;
}

/* Set default dark-mode pill backgrounds to the dark variants (keeps B/D similar between themes) */
/* No per-theme pill overrides — keep the three difficulty variables stable across themes. */

/* Body-level palette toggles for A/B testing */
/* No palette classes or per-theme overrides — single set of variables above is authoritative. */

html {
    box-sizing: border-box;
}

*,
*:before,
*:after {
    box-sizing: inherit;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    -webkit-text-size-adjust: 100%;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.main-container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* === Main Navigation === */
.main-header {
    background-color: var(--nav-bg);
    box-shadow: var(--shadow);
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    margin-bottom: 2rem;
}

.main-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: nowrap;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.5rem 0;
}

.nav-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.nav-left {
    flex: 1 1 auto;
    justify-content: flex-start;
}

.nav-center {
    flex: 0 0 auto;
    justify-content: center;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

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

.quiz-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-width: 0;
}

.quiz-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--meta-color);
    white-space: nowrap;
}

.quiz-dropdown {
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--dropdown-bg);
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    width: 100%;
    min-width: 0;
    max-width: 320px;
}

[data-theme="dark"] .quiz-dropdown {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23b0b0b0' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
}

.quiz-dropdown:hover {
    border-color: var(--primary-color);
}

.quiz-dropdown:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.nav-link {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--meta-color);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--dropdown-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    color: var(--text-color);
}

.menu-toggle:hover,
.menu-toggle:focus-visible {
    background-color: var(--hover-bg);
    border-color: var(--primary-color);
}

.menu-toggle .material-symbols-outlined {
    font-size: 1.3rem;
    line-height: 1;
}

.theme-toggle {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    /* ensure the icon color follows the site's text color for correct contrast */
    color: var(--text-color);
}

.theme-toggle:hover {
    background-color: var(--hover-bg);
}

.theme-icon {
    display: block;
    line-height: 1;
    /* inherit color from the toggle so mode-specific vars control contrast */
    color: inherit;
    /* slightly larger and heavier for legibility */
    font-size: 1.35rem;
    font-variation-settings: 'wght' 700;
}

/* theme icon SVG tweaks */
.theme-icon svg {
    display: inline-block;
    vertical-align: middle;
    width: 1.25em;
    height: 1.25em;
    fill: currentColor;
}

/* Ensure Material Symbols font is explicitly requested for our icon spans.
   Some browsers or CSPs may block the remote stylesheet; providing a
   local fallback and explicit font-family makes the icon rendering more
   robust and avoids rendering literal text when the symbol font isn't
   available. */
.material-symbols-outlined,
.theme-icon,
.question-difficulty span.material-symbols-outlined.difficulty-icon {
    /* Use the official Material Symbols family and provide a sane fallback stack.
       Include the recommended platform tweaks so the ligatures/glyphs render
       correctly across browsers and when the font is available. */
    font-family: 'Material Symbols Outlined', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-weight: normal;
    font-style: normal;
    font-size: 1em;
    /* size controlled by the specific usages */
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    font-feature-settings: 'liga';
    -webkit-font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
    /* Default variation axes recommended by Google to enable ligatures/glyphs. */
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 48;
}

/* Explicit font-family for the select control and its options to ensure
   consistent sans-serif rendering in both closed and open states. */
.quiz-dropdown {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.quiz-dropdown option {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.mobile-nav-menu {
    display: none;
    flex-direction: column;
    background-color: var(--nav-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow);
    margin: 0.35rem 0 0;
    padding: 0.25rem 0;
}

.mobile-nav-menu.open {
    display: flex;
}

.mobile-nav-menu .nav-link {
    padding: 0.65rem 1rem;
    border-bottom: none;
    border-left: 3px solid transparent;
}

.mobile-nav-menu .nav-link + .nav-link {
    border-top: 1px solid var(--border-color);
}

.mobile-nav-menu .nav-link:hover,
.mobile-nav-menu .nav-link.active {
    border-left-color: var(--primary-color);
}

@media (min-width: 769px) {
    .mobile-nav-menu {
        display: none !important;
    }
}


/* === Quiz Page Styles === */
.quiz-page-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.quiz-header-stats {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.quiz-header-stats h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    color: var(--meta-color);
}

.quiz-header-stats p {
    margin: 0.5rem 0 0 0;
    color: var(--meta-color);
    font-size: 0.9rem;
}

#flashcard-container {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
    min-height: 300px;
}

.question-topic {
    margin-top: 0;
    overflow-wrap: break-word;
    font-size: 1.2rem;
    color: var(--meta-color);
    text-align: center;
    margin-bottom: 2rem;
}

.question-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.question-difficulty {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    background-color: var(--meta-color);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    text-transform: capitalize;
    align-self: flex-start;
}

/* subtle icon before the difficulty label; uses an SVG data-URI that inherits the badge color via currentColor */
.question-difficulty svg {
    display: inline-block;
    width: 1em;
    /* match text height */
    height: 1em;
    flex: 0 0 auto;
    vertical-align: -0.15em;
    /* nudge to better center with text */
    color: inherit;
    /* arc/dot use currentColor */
    shape-rendering: geometricPrecision;
    stroke-linejoin: round;
}

/* local SVG icon inside the difficulty badge */
.question-difficulty .difficulty-icon {
    display: inline-flex;
    /* align icon like text */
    align-items: center;
    justify-content: center;
    width: 1.12em;
    height: 1.12em;
    line-height: 1;
    margin-right: 0.45em;
}

/* dual-markup: show inline SVG by default; show material font when loaded */
.difficulty-svg {
    display: inline-block;
}

.material-symbols-outlined.difficulty-icon {
    /* hide material font until we detect it; when detected, we add .material-loaded to <html> */
    display: none;
}

html.material-loaded .difficulty-svg {
    display: none;
}

html.material-loaded .material-symbols-outlined.difficulty-icon {
    display: inline-flex;
}

/* Specific tuning for Material Symbols (font icons). Keep this narrowly scoped so SVG/img icons are unaffected. */
.question-difficulty span.material-symbols-outlined.difficulty-icon {
    /* tuned to the user's final preference — no offset */
    /* Use a filled glyph for better visibility (FILL = 1). Keep weight/opsz tuned. */
    font-variation-settings: 'FILL' 1, 'wght' 600, 'GRAD' 0, 'opsz' 48;
    font-size: 1.125em;
    width: 1.1em;
    height: 1.1em;
    margin-right: 0.25em;
    line-height: 1;
    vertical-align: middle;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* transform: translateY(var(--difficulty-icon-offset, 0.0025em)); */
}

/* Toggle class to disable the offset for testing pixel-perfect alignment.
       Add `.no-offset` to the badge container (e.g. <div class="question-difficulty no-offset">) */
.question-difficulty.no-offset {
    --difficulty-icon-offset: 0;
}

.question-difficulty .gauge-needle {
    /* needle is colored via inline stroke from JS (for clarity/per-difficulty) */
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 0.15s ease;
}

/* Pointer group inside the inlined SVGs. We use .pointer to target the whole pointer so scaling
   keeps the same rotation origin defined by the group's transform attribute. */
.question-difficulty svg .pointer {
    /* Use view-box as the reference so scaling respects the SVG's coordinate system */
    transform-box: view-box;
    /* set an origin roughly at the pointer's pivot (percentages relative to viewBox) */
    transform-origin: 50% 60%;
    transition: transform 0.18s cubic-bezier(.2, .9, .2, 1);
}

/* On hover enlarge the pointer by 25% while leaving rotation origin in place. */
.question-difficulty:hover svg .pointer {
    transform: scale(1.25);
}

.question-difficulty .difficulty-text {
    line-height: 1;
}



.question-difficulty.easy,
.question-difficulty.leicht {
    background-color: var(--difficulty-easy-bg);
    color: #fff;
}

.question-difficulty.medium,
.question-difficulty.mittel {
    background-color: var(--difficulty-medium-bg);
    color: #fff;
}

/* In dark mode the medium pill's background is a neutral grey; use light text for legibility */
[data-theme="dark"] .question-difficulty.medium,
[data-theme="dark"] .question-difficulty.mittel {
    color: #fff;
}

.question-difficulty.hard,
.question-difficulty.schwer {
    background-color: var(--difficulty-hard-bg);
    color: #fff;
}

/* Note: dark-mode pill backgrounds are set earlier using the --*-dark variables so they
   remain consistent with palette mappings. The old hard-coded override was removed to
   avoid conflicting rules that made the site appear to still use earlier colors. */

.question-text {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    overflow-wrap: break-word;
}

.options {
    display: grid;
    gap: 1rem;
}

.option-label {
    display: block;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.option-label:hover {
    border-color: var(--primary-color);
    background: var(--hover-bg);
}

.option-label input {
    margin-right: 0.5rem;
}

.option-label.disabled {
    cursor: default;
    opacity: 0.7;
    background-color: var(--hover-bg);
}

.option-label.disabled:hover {
    border-color: var(--border-color);
}

.option-label.correct-answer {
    border-color: var(--correct-color);
    background-color: var(--correct-highlight-bg);
    opacity: 1;
}

.option-label.selected-incorrect {
    border-color: var(--incorrect-color);
    background-color: var(--incorrect-highlight-bg);
    opacity: 1;
}

.review-section {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
    margin-top: 1.5rem;
}

.explanation {
    background-color: var(--explanation-bg);
    border-left: 4px solid var(--primary-color);
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
    font-size: 0.95rem;
    line-height: 1.6;
}

.question-meta {
    font-size: 0.9rem;
    color: var(--meta-color);
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.action-button,
.reset-btn {
    display: block;
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    font-weight: bold;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 1.5rem;
    transition: background-color 0.2s;
}

.action-button {
    background-color: var(--primary-color);
}

.action-button:hover {
    background-color: #0056b3;
}

.reset-btn {
    background: var(--incorrect-color);
    padding: 0.75rem;
}

.reset-btn:hover {
    background: #b22222;
}

.quiz-complete {
    text-align: center;
    padding: 2rem;
    background-color: var(--card-bg);
    border-radius: 12px;
}


/* === Stats Page Styles === */
.stats-page-container h1,
.stats-page-container h2 {
    text-align: center;
    color: var(--text-color);
}

.stats-page-container h2 {
    margin-top: 3rem;
    margin-bottom: 1.5rem;
}

.stats-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.summary-card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.summary-card h3 {
    margin: 0 0 0.5rem 0;
    color: var(--meta-color);
    font-size: 1rem;
}

.summary-card .summary-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

#weakest-topic-summary {
    color: var(--incorrect-color);
}

.summary-card p {
    margin: 0.5rem 0 0 0;
    font-size: 0.9rem;
    color: var(--meta-color);
}

.table-container {
    overflow-x: auto;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

#topics-table {
    width: 100%;
    border-collapse: collapse;
}

#topics-table th,
#topics-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

#topics-table th {
    font-weight: 600;
    white-space: nowrap;
}

#topics-table tbody tr:last-child td {
    border-bottom: none;
}

.topic-row[data-depth="0"] {
    font-weight: bold;
}

.toggle-icon {
    cursor: pointer;
    display: inline-block;
    width: 20px;
    text-align: center;
    margin-right: 5px;
}


/* === Shared Components === */
.progress-bar-container {
    position: relative;
    background-color: var(--progress-unattempted);
    border-radius: 0.5rem;
    height: 1rem;
    width: 100%;
    margin: 0.5rem 0;
    overflow: hidden;
}

.progress-bar-track {
    display: flex;
    align-items: stretch;
    height: 100%;
    width: 0%;
    border-radius: inherit;
    overflow: hidden;
    transition: width 0.4s ease-in-out;
}

.progress-segment {
    flex: 0 0 auto;
    min-width: 0;
    height: 100%;
    opacity: 0;
    transition: flex-grow 0.3s ease-in-out, opacity 0.2s ease-in-out;
}

.progress-segment.mastered {
    background-color: var(--progress-mastered);
}

.progress-segment.mostly-correct {
    background-color: var(--progress-mostly-correct);
}

.progress-segment.mostly-incorrect {
    background-color: var(--progress-mostly-incorrect);
}

.progress-segment.critical {
    background-color: var(--progress-critical);
}

.progress-bar {
    background-color: var(--primary-color);
    height: 100%;
    width: 0%;
    border-radius: 0.5rem;
    transition: width 0.4s ease-in-out;
}

.improving {
    color: var(--correct-color);
    font-weight: bold;
}

.declining {
    color: var(--incorrect-color);
    font-weight: bold;
}

.history-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin: 0 2px;
}

.history-dot.correct {
    background-color: var(--correct-color);
}

.history-dot.incorrect {
    background-color: var(--incorrect-color);
}

.katex-display {
    overflow-x: auto;
    padding: 0.5rem 0;
}

/* === Responsive Design === */
@media (max-width: 768px) {
    .main-nav {
        gap: 0.5rem;
        padding: 0.5rem 0;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .nav-center {
        display: none;
    }

    .nav-left {
        flex: 1 1 auto;
    }

    .quiz-selector {
        flex: 1 1 auto;
    }

    .quiz-dropdown {
        width: 100%;
    }

    #topics-table th,
    #topics-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.9rem;
    }

    .main-container {
        padding: 1rem;
    }
}
