/* ============================================
   Lerntrainer – Globales Stylesheet
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --primary: #4a5568;
    --primary-light: #718096;
    --primary-dark: #2d3748;
    --primary-bg: rgba(74, 85, 104, 0.06);
    --accent: #2b6cb0;
    --accent-light: #4299e1;
    --success: #38a169;
    --danger: #c53030;
    --warning: #d69e2e;

    --bg: #f5f2eb;
    --bg-card: #fffefa;
    --bg-sidebar: #2d2a3e;
    --text: #2d3748;
    --text-light: #718096;
    --text-inverse: #edf2f7;
    --border: #e2ddd3;
    --border-light: #ebe7de;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Bahnschrift', 'DIN Alternate', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover { color: var(--primary-dark); }

/* --- Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    color: var(--text-inverse);
    padding: 1.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 0 0.75rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 1.25rem;
}

.sidebar-brand h1 {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.sidebar-nav { flex: 1; }

.sidebar-nav a {
    display: block;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    color: rgba(237, 242, 247, 0.6);
    font-size: 0.88rem;
    font-weight: 500;
    transition: all var(--transition);
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,0.07);
    color: var(--text-inverse);
}

.sidebar-nav a.active {
    background: rgba(255,255,255,0.12);
    color: var(--text-inverse);
}

.sidebar-section-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(237, 242, 247, 0.35);
    padding: 1.2rem 0.75rem 0.4rem;
    font-weight: 600;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 2rem 2.5rem;
    max-width: 1000px;
}

/* --- Page Header --- */
.page-header {
    margin-bottom: 1.75rem;
}

.page-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.page-header .subtitle {
    color: var(--text-light);
    margin-top: 0.2rem;
    font-size: 0.9rem;
}

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    color: var(--text-light);
    margin-bottom: 0.4rem;
}

.breadcrumb a { color: var(--text-light); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { opacity: 0.4; }

/* --- Module Cards (Grid) --- */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.module-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.4rem;
    transition: all var(--transition);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    color: var(--text);
}

.module-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
    transform: translateY(-1px);
}

.module-card .card-kuerzel {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-light);
    margin-bottom: 0.25rem;
}

.module-card h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.module-card p {
    font-size: 0.82rem;
    color: var(--text-light);
    flex: 1;
}

.module-card .card-meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-light);
    font-size: 0.75rem;
    color: var(--text-light);
}

.module-card.empty-card {
    opacity: 0.55;
    border-style: dashed;
}

.module-card.empty-card:hover {
    transform: none;
    box-shadow: none;
}

/* --- Topic List --- */
.topic-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.topic-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.9rem 1.15rem;
    transition: all var(--transition);
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
}

.topic-item:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
}

.topic-item .topic-info h4 {
    font-size: 0.92rem;
    font-weight: 600;
}

.topic-item .topic-info p {
    font-size: 0.78rem;
    color: var(--text-light);
    margin-top: 0.1rem;
}

.topic-item .topic-arrow {
    font-size: 0.85rem;
    color: var(--text-light);
}

/* --- Trainer Config (Themenauswahl) --- */
.trainer-config {
    max-width: 640px;
}

.config-section {
    margin-bottom: 1.75rem;
}

.config-section h3 {
    font-size: 0.92rem;
    font-weight: 600;
    margin-bottom: 0.6rem;
    color: var(--text);
}

/* Selectable Topic Cards */
.thema-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.6rem;
}

.thema-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.9rem 1rem;
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 3.2rem;
}

.thema-card:hover {
    border-color: var(--primary-light);
}

.thema-card.selected {
    border-color: var(--accent);
    background: rgba(43, 108, 176, 0.05);
}

.thema-card .thema-check {
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 3px;
    border: 2px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    font-size: 0.7rem;
    color: white;
}

.thema-card.selected .thema-check {
    background: var(--accent);
    border-color: var(--accent);
}

.thema-card .thema-name {
    font-size: 0.88rem;
    font-weight: 500;
    line-height: 1.3;
}

.thema-card-all {
    grid-column: 1 / -1;
    border-style: dashed;
}

/* Toggle Switch */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toggle-label {
    font-size: 0.88rem;
    color: var(--text-light);
    transition: color var(--transition);
}

.toggle-label.active {
    color: var(--text);
    font-weight: 600;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 99px;
    cursor: pointer;
    transition: background 0.25s ease;
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    transition: transform 0.25s ease;
}

.toggle-switch input:checked + .toggle-track {
    background: var(--accent);
}

.toggle-switch input:checked + .toggle-track::after {
    transform: translateX(20px);
}

.config-actions {
    padding-top: 0.5rem;
}

/* --- Trainer / Flashcard Area --- */
.trainer-container {
    max-width: 680px;
    margin: 0 auto;
}

.trainer-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.trainer-topbar .stats {
    font-size: 0.82rem;
    color: var(--text-light);
}

.trainer-topbar .stats span {
    margin-left: 1rem;
}

.trainer-topbar .stats .stat-correct { color: var(--success); }
.trainer-topbar .stats .stat-wrong { color: var(--danger); }

.flashcard {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.flashcard-section {
    padding: 1.75rem 1.5rem;
}

.flashcard-section.frage-section {
    /* Frage oben */
}

.flashcard-section.antwort-section {
    border-top: 2px solid var(--border);
    background: rgba(56, 161, 105, 0.03);
}

.flashcard-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-light);
    margin-bottom: 0.6rem;
}

.flashcard-content {
    font-size: 1.05rem;
    line-height: 1.7;
}

.flashcard-content img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin-top: 0.75rem;
}

.flashcard-reveal {
    padding: 1.25rem 1.5rem;
    border-top: 1px dashed var(--border);
    text-align: center;
    cursor: pointer;
    color: var(--text-light);
    font-size: 0.88rem;
    transition: background var(--transition);
}

.flashcard-reveal:hover {
    background: rgba(0,0,0,0.02);
}

/* Progress Bar */
.progress-bar-container {
    margin-bottom: 1.25rem;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-light);
    margin-bottom: 0.35rem;
}

.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 99px;
    transition: width 0.4s ease;
}

/* Buttons */
.trainer-controls {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
}

.btn .shortcut {
    font-size: 0.68rem;
    opacity: 0.6;
    font-weight: 500;
    margin-left: 0.25rem;
}

.btn-primary {
    background: var(--accent);
    color: white;
}
.btn-primary:hover { background: #2c5282; }

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border-light); }

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover { background: #2f855a; }

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #9b2c2c; }

.btn-ghost {
    background: transparent;
    color: var(--text-light);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: rgba(0,0,0,0.03); color: var(--text); }

/* Result Card */
.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    text-align: center;
}

.result-card h3 {
    font-size: 1.2rem;
    margin-bottom: 0.3rem;
}

.result-card .result-stats {
    color: var(--text-light);
    font-size: 0.95rem;
}

.result-card .result-detail {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-light);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-light);
}

.empty-state p {
    font-size: 0.9rem;
}

/* --- Mobile --- */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 200;
    background: var(--bg-sidebar);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.6rem;
    font-size: 1.1rem;
    cursor: pointer;
    font-family: inherit;
}

@media (max-width: 768px) {
    .mobile-toggle { display: block; }

    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 3rem;
    }

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

    .trainer-controls {
        flex-direction: column;
        align-items: stretch;
    }
}

/* --- KaTeX --- */
.katex-display {
    margin: 0.75rem 0;
}

/* ============================================
   Lernzettel
   ============================================ */

/* Kapitelübersicht: Nummern-Badge */
.kapitel-info {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.kapitel-nr {
    flex-shrink: 0;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 50%;
    background: var(--primary-bg);
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Inhalt */
.lernzettel-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem 2.25rem;
    box-shadow: var(--shadow);
    font-size: 0.95rem;
    line-height: 1.75;
    max-width: 820px;
}

.lernzettel-content h1 { display: none; } /* Titel kommt aus dem Page-Header */

.lernzettel-content h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 2rem 0 0.75rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border-light);
}
.lernzettel-content h2:first-child { margin-top: 0; }

.lernzettel-content h3 {
    font-size: 1.02rem;
    font-weight: 600;
    margin: 1.5rem 0 0.5rem;
}

.lernzettel-content p { margin: 0.6rem 0; }

.lernzettel-content ul,
.lernzettel-content ol {
    margin: 0.6rem 0;
    padding-left: 1.4rem;
}
.lernzettel-content li { margin: 0.25rem 0; }

.lernzettel-content table {
    border-collapse: collapse;
    margin: 0.9rem 0;
    width: 100%;
    font-size: 0.9rem;
}
.lernzettel-content th,
.lernzettel-content td {
    border: 1px solid var(--border);
    padding: 0.45rem 0.7rem;
    text-align: left;
    vertical-align: top;
}
.lernzettel-content th {
    background: var(--primary-bg);
    font-weight: 600;
}

.lernzettel-content hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 1.75rem 0;
}

.lernzettel-content code {
    background: var(--primary-bg);
    border-radius: 4px;
    padding: 0.1rem 0.35rem;
    font-size: 0.85em;
}

.lernzettel-content figure,
.lernzettel-content svg {
    max-width: 100%;
}

.lernzettel-content .lz-figure {
    margin: 1rem auto;
    text-align: center;
}
.lernzettel-content .lz-figure .caption {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* --- Farbige Boxen --- */
.lz-box {
    border-radius: var(--radius-sm);
    border: 1px solid;
    margin: 1.1rem 0;
    overflow: hidden;
}

.lz-box-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.4rem 1rem 0.3rem;
}

.lz-box-body { padding: 0.2rem 1rem 0.7rem; }
.lz-box-body > *:first-child { margin-top: 0.2rem; }
.lz-box-body > *:last-child { margin-bottom: 0.2rem; }

.lz-definition { border-color: #b6cbe4; background: rgba(43, 108, 176, 0.05); }
.lz-definition .lz-box-label { color: var(--accent); }

.lz-satz { border-color: #b7d9c4; background: rgba(56, 161, 105, 0.05); }
.lz-satz .lz-box-label { color: var(--success); }

.lz-beispiel { border-color: var(--border); background: rgba(74, 85, 104, 0.03); }
.lz-beispiel .lz-box-label { color: var(--primary); }

.lz-merke { border-color: #e4d3a8; background: rgba(214, 158, 46, 0.07); }
.lz-merke .lz-box-label { color: #97701c; }

.lz-fehler { border-color: #e0b4b4; background: rgba(197, 48, 48, 0.05); }
.lz-fehler .lz-box-label { color: var(--danger); }

.lz-hinweis { border-color: var(--border); background: transparent; }
.lz-hinweis .lz-box-label { color: var(--text-light); }

/* --- Kapitel-Navigation --- */
.lz-nav {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1.25rem;
    max-width: 820px;
}
.lz-nav .btn {
    max-width: 48%;
    text-align: left;
    white-space: normal;
    line-height: 1.3;
}

/* --- Interaktive Widgets --- */
.lz-widget {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin: 1.25rem 0;
    padding: 1rem;
    background: #fdfcf8;
}

.lz-widget canvas {
    width: 100%;
    height: auto;
    display: block;
}

.lz-widget .widget-head {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 0.6rem;
}

.lz-widget .widget-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 0.6rem;
    font-size: 0.85rem;
}

.lz-widget input[type="range"] { flex: 1; min-width: 140px; }

.lz-widget .widget-readout {
    width: 100%;
    font-size: 0.85rem;
    color: var(--text);
}

@media (max-width: 768px) {
    .lernzettel-content { padding: 1.25rem 1rem; }
    .lz-nav { flex-direction: column; }
    .lz-nav .btn { max-width: 100%; }
}

/* --- Utility --- */
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.hidden { display: none !important; }
