/* ============================================================
   KidsLearningPro – Hauptstylesheet
   Vanilla CSS, keine externen Abhängigkeiten
   ============================================================ */

:root {
    --primary:      #2563EB;
    --primary-dark: #1D4ED8;
    --primary-light:#DBEAFE;
    --success:      #16A34A;
    --success-light:#DCFCE7;
    --danger:       #DC2626;
    --danger-light: #FEE2E2;
    --warning:      #D97706;
    --warning-light:#FEF3C7;
    --xp-color:     #F59E0B;
    --streak-color: #EF4444;
    --bg:           #F0F4FF;
    --surface:      #FFFFFF;
    --border:       #E2E8F0;
    --text:         #1E293B;
    --text-muted:   #64748B;
    --radius:       12px;
    --radius-sm:    8px;
    --shadow:       0 2px 12px rgba(0,0,0,.08);
    --shadow-lg:    0 8px 32px rgba(0,0,0,.12);
    --nav-h:        64px;
    --sidebar-w:    220px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}
img { max-width: 100%; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { color: var(--primary); text-decoration: none; }

/* ---- Layout ---- */
#app { min-height: 100vh; display: flex; flex-direction: column; }

.app-shell {
    display: flex;
    flex: 1;
    padding-top: var(--nav-h);
}

/* Top-Navigation */
.topnav {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    height: var(--nav-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 1rem;
    gap: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.topnav .logo {
    font-size: 1.2rem; font-weight: 800;
    color: var(--primary); display: flex; align-items: center; gap: .4rem;
    white-space: nowrap;
}
.topnav .logo span { font-size: 1.4rem; }
.topnav-center { flex: 1; display: flex; align-items: center; gap: .5rem; }
.topnav-right   { display: flex; align-items: center; gap: .75rem; }

/* XP-Leiste in Navbar */
.xp-bar-mini {
    display: flex; align-items: center; gap: .5rem;
    font-size: .8rem; color: var(--text-muted);
}
.xp-bar-mini .xp-track {
    width: 100px; height: 8px;
    background: var(--border); border-radius: 4px; overflow: hidden;
}
.xp-bar-mini .xp-fill {
    height: 100%; background: var(--xp-color); border-radius: 4px;
    transition: width .4s ease;
}
.xp-bar-mini .level-badge {
    background: var(--xp-color); color: #fff;
    font-weight: 700; font-size: .75rem;
    padding: 2px 7px; border-radius: 10px;
}
.streak-badge {
    display: flex; align-items: center; gap: .25rem;
    font-weight: 600; font-size: .85rem;
    color: var(--streak-color);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: fixed; top: var(--nav-h); bottom: 0; left: 0;
    overflow-y: auto; padding: 1rem 0;
    display: flex; flex-direction: column;
}
.sidebar-nav { list-style: none; flex: 1; }
.sidebar-nav li a {
    display: flex; align-items: center; gap: .65rem;
    padding: .7rem 1.25rem; color: var(--text);
    font-size: .95rem; border-radius: 0;
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}
.sidebar-nav li a:hover    { background: var(--primary-light); }
.sidebar-nav li a.active   {
    background: var(--primary-light); color: var(--primary);
    font-weight: 600; border-left-color: var(--primary);
}
.sidebar-nav li a .nav-icon { font-size: 1.2rem; width: 1.4rem; text-align: center; }

/* Main content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 1.5rem;
    min-height: calc(100vh - var(--nav-h));
}

/* ---- Karten ---- */
.card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.25rem;
    border: 1px solid var(--border);
}
.card-title {
    font-size: 1rem; font-weight: 700; margin-bottom: .75rem;
    display: flex; align-items: center; gap: .5rem;
}
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.card-grid-sm {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

/* Fach-Karte */
.subject-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 1.25rem; cursor: pointer;
    border: 2px solid transparent;
    transition: transform .15s, box-shadow .15s, border-color .15s;
    display: flex; flex-direction: column; align-items: center;
    gap: .6rem; text-align: center;
    box-shadow: var(--shadow);
}
.subject-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.subject-card .s-icon {
    width: 56px; height: 56px; border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.8rem;
}
.subject-card .s-name { font-weight: 700; font-size: .95rem; }
.subject-card .s-progress { font-size: .8rem; color: var(--text-muted); }
.subject-card .progress-bar {
    width: 100%; height: 6px; background: var(--border);
    border-radius: 3px; overflow: hidden; margin-top: .25rem;
}
.subject-card .progress-fill { height: 100%; border-radius: 3px; transition: width .4s; }

/* Themen-Liste */
.topic-item {
    display: flex; align-items: center; gap: 1rem;
    padding: .85rem 1rem; background: var(--surface);
    border-radius: var(--radius-sm); cursor: pointer;
    border: 1px solid var(--border);
    transition: background .15s, transform .1s;
    margin-bottom: .5rem;
}
.topic-item:hover { background: var(--primary-light); transform: translateX(3px); }
.topic-item .t-status { font-size: 1.1rem; }
.topic-item .t-info { flex: 1; }
.topic-item .t-title { font-weight: 600; font-size: .95rem; }
.topic-item .t-meta  { font-size: .8rem; color: var(--text-muted); margin-top: .1rem; }
.topic-item .t-arrow { color: var(--text-muted); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .6rem 1.25rem; border-radius: var(--radius-sm);
    border: 2px solid transparent; font-size: .95rem;
    font-weight: 600; transition: all .15s; cursor: pointer;
    text-decoration: none;
}
.btn-primary {
    background: var(--primary); color: #fff; border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline {
    background: transparent; color: var(--primary); border-color: var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }
.btn-success {
    background: var(--success); color: #fff; border-color: var(--success);
}
.btn-danger {
    background: var(--danger); color: #fff; border-color: var(--danger);
}
.btn-ghost {
    background: transparent; color: var(--text-muted); border-color: transparent;
}
.btn-ghost:hover { background: var(--border); }
.btn-lg { padding: .85rem 2rem; font-size: 1.05rem; border-radius: var(--radius); }
.btn-sm { padding: .35rem .85rem; font-size: .85rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Aufgaben ---- */
.exercise-box {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
    border: 1px solid var(--border);
}
.exercise-header {
    padding: 1rem 1.25rem;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; gap: .75rem;
}
.exercise-header .ex-num { font-size: .85rem; opacity: .85; }
.exercise-header .ex-pts { margin-left: auto; font-size: .85rem; opacity: .85; }
.exercise-body { padding: 1.25rem; }
.exercise-question { font-size: 1.05rem; font-weight: 500; margin-bottom: 1.25rem; line-height: 1.5; }
.exercise-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--border); background: #FAFAFA; }

/* Antwortoptionen */
.mc-options { display: flex; flex-direction: column; gap: .6rem; }
.mc-option {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem 1rem; border: 2px solid var(--border);
    border-radius: var(--radius-sm); cursor: pointer;
    font-size: .95rem; transition: all .15s; background: var(--surface);
}
.mc-option:hover:not(.disabled) { border-color: var(--primary); background: var(--primary-light); }
.mc-option.selected  { border-color: var(--primary); background: var(--primary-light); }
.mc-option.correct   { border-color: var(--success); background: var(--success-light); color: var(--success); }
.mc-option.wrong     { border-color: var(--danger);  background: var(--danger-light);  color: var(--danger);  }
.mc-option.disabled  { cursor: default; }
.mc-option .opt-letter {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--border); display: flex; align-items: center;
    justify-content: center; font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
.mc-option.selected .opt-letter  { background: var(--primary); color: #fff; }
.mc-option.correct  .opt-letter  { background: var(--success); color: #fff; }
.mc-option.wrong    .opt-letter  { background: var(--danger);  color: #fff; }

/* True/False */
.tf-options { display: flex; gap: 1rem; }
.tf-btn {
    flex: 1; padding: 1rem; border: 2px solid var(--border);
    border-radius: var(--radius-sm); font-size: 1rem; font-weight: 600;
    cursor: pointer; background: var(--surface); transition: all .15s;
}
.tf-btn:hover:not(.disabled) { border-color: var(--primary); }
.tf-btn.selected { border-color: var(--primary); background: var(--primary-light); }
.tf-btn.correct  { border-color: var(--success); background: var(--success-light); }
.tf-btn.wrong    { border-color: var(--danger);  background: var(--danger-light);  }

/* Freitext-Eingabe */
.text-answer {
    width: 100%; padding: .75rem 1rem;
    border: 2px solid var(--border); border-radius: var(--radius-sm);
    font-size: 1rem; resize: vertical; min-height: 80px;
    transition: border-color .15s;
}
.text-answer:focus { outline: none; border-color: var(--primary); }

/* Feedback-Box */
.feedback-box {
    padding: 1rem; border-radius: var(--radius-sm);
    margin-top: 1rem; display: flex; gap: .75rem; align-items: flex-start;
}
.feedback-box.correct { background: var(--success-light); color: var(--success); }
.feedback-box.wrong   { background: var(--danger-light);  color: var(--danger);  }
.feedback-box .feedback-icon { font-size: 1.4rem; }
.feedback-box .feedback-text { font-size: .9rem; }
.feedback-box .feedback-text strong { display: block; font-size: 1rem; margin-bottom: .25rem; }

/* Fortschrittsanzeige */
.progress-header {
    display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem;
}
.progress-track {
    flex: 1; height: 10px; background: var(--border);
    border-radius: 5px; overflow: hidden;
}
.progress-fill-animated {
    height: 100%; background: var(--primary);
    border-radius: 5px; transition: width .4s ease;
}
.progress-count { font-size: .85rem; color: var(--text-muted); white-space: nowrap; }

/* ---- Dashboard ---- */
.dashboard-greeting {
    font-size: 1.6rem; font-weight: 800; margin-bottom: .25rem;
}
.dashboard-sub { color: var(--text-muted); margin-bottom: 1.5rem; }

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 1rem; text-align: center;
    box-shadow: var(--shadow); border: 1px solid var(--border);
}
.stat-card .stat-val { font-size: 1.8rem; font-weight: 800; }
.stat-card .stat-lbl { font-size: .8rem; color: var(--text-muted); margin-top: .2rem; }

/* ---- Chat ---- */
.chat-layout { display: flex; gap: 1rem; height: calc(100vh - var(--nav-h) - 3rem); }
.chat-sidebar {
    width: 240px; background: var(--surface);
    border-radius: var(--radius); border: 1px solid var(--border);
    display: flex; flex-direction: column; overflow: hidden;
}
.chat-sidebar-header {
    padding: 1rem; border-bottom: 1px solid var(--border); font-weight: 700;
}
.chat-sessions { flex: 1; overflow-y: auto; }
.chat-session-item {
    padding: .75rem 1rem; cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: .9rem; transition: background .1s;
}
.chat-session-item:hover  { background: var(--bg); }
.chat-session-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.chat-main {
    flex: 1; background: var(--surface);
    border-radius: var(--radius); border: 1px solid var(--border);
    display: flex; flex-direction: column;
}
.chat-messages {
    flex: 1; overflow-y: auto; padding: 1rem;
    display: flex; flex-direction: column; gap: .75rem;
}
.chat-bubble {
    max-width: 72%; padding: .75rem 1rem;
    border-radius: var(--radius); font-size: .95rem; line-height: 1.5;
}
.chat-bubble.user {
    background: var(--primary); color: #fff;
    align-self: flex-end; border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
    background: var(--bg); color: var(--text);
    align-self: flex-start; border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}
.chat-input-row {
    display: flex; gap: .5rem; padding: 1rem;
    border-top: 1px solid var(--border);
}
.chat-input {
    flex: 1; padding: .65rem 1rem;
    border: 2px solid var(--border); border-radius: var(--radius-sm);
    font-size: .95rem; resize: none;
}
.chat-input:focus { outline: none; border-color: var(--primary); }
.chat-loading { display: flex; gap: .4rem; align-items: center; padding: .25rem; }
.chat-loading span {
    width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted);
    animation: bounce .8s infinite alternate;
}
.chat-loading span:nth-child(2) { animation-delay: .2s; }
.chat-loading span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { to { transform: translateY(-6px); opacity: .5; } }

/* ---- Spiele ---- */
.game-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 1.25rem; cursor: pointer;
    border: 2px solid var(--border);
    transition: transform .15s, box-shadow .15s;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: .6rem;
}
.game-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.game-card .g-icon { font-size: 2.5rem; }
.game-card .g-name { font-weight: 700; }
.game-card .g-desc { font-size: .85rem; color: var(--text-muted); }
.game-card .g-best { font-size: .8rem; color: var(--xp-color); font-weight: 600; }

/* Memory-Spiel */
.memory-grid {
    display: grid; gap: .75rem;
    grid-template-columns: repeat(4, 1fr);
}
.memory-card {
    aspect-ratio: 1; border-radius: var(--radius-sm);
    cursor: pointer; perspective: 600px;
    position: relative;
}
.memory-card-inner {
    width: 100%; height: 100%;
    transition: transform .35s;
    transform-style: preserve-3d;
    position: relative;
}
.memory-card.flipped .memory-card-inner { transform: rotateY(180deg); }
.memory-card-front, .memory-card-back {
    position: absolute; inset: 0;
    border-radius: var(--radius-sm);
    backface-visibility: hidden;
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem; padding: .5rem; text-align: center;
    border: 2px solid var(--border);
}
.memory-card-front { background: var(--primary); color: #fff; font-size: 1.5rem; }
.memory-card-back  { background: var(--surface); transform: rotateY(180deg); }
.memory-card.matched .memory-card-back { border-color: var(--success); background: var(--success-light); }

/* Quiz-Spiel */
.quiz-timer {
    font-size: 2rem; font-weight: 800; text-align: center;
    color: var(--primary); margin-bottom: 1rem;
}
.quiz-score { font-size: 1.2rem; font-weight: 700; color: var(--xp-color); }

/* Mathe-Blitz */
.math-problem {
    font-size: 3rem; font-weight: 800; text-align: center;
    color: var(--text); margin: 1rem 0;
    font-variant-numeric: tabular-nums;
}
.math-answer {
    font-size: 2rem; text-align: center; width: 100%;
    border: 3px solid var(--border); border-radius: var(--radius);
    padding: .75rem; font-weight: 700;
}
.math-answer:focus { outline: none; border-color: var(--primary); }

/* ---- Profil & Belohnungen ---- */
.profile-header {
    display: flex; align-items: center; gap: 1.5rem; margin-bottom: 1.5rem;
}
.avatar {
    width: 72px; height: 72px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; font-weight: 800; flex-shrink: 0;
}
.level-info .level-num { font-size: 1.4rem; font-weight: 800; }
.level-info .level-name { color: var(--text-muted); font-size: .9rem; }
.xp-bar-large {
    height: 14px; background: var(--border);
    border-radius: 7px; overflow: hidden; margin: .5rem 0;
}
.xp-bar-large .xp-fill { height: 100%; background: var(--xp-color); border-radius: 7px; }
.xp-label { font-size: .85rem; color: var(--text-muted); }

.badges-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem; margin-top: .75rem;
}
.badge-item {
    display: flex; flex-direction: column; align-items: center; gap: .4rem;
    padding: .75rem .5rem; border-radius: var(--radius-sm);
    background: var(--bg); text-align: center;
}
.badge-item .badge-icon { font-size: 2rem; }
.badge-item .badge-name { font-size: .75rem; font-weight: 600; color: var(--text-muted); }
.badge-item.earned { background: var(--warning-light); }
.badge-item.earned .badge-name { color: var(--warning); }

/* Leaderboard */
.leaderboard { list-style: none; }
.lb-row {
    display: flex; align-items: center; gap: 1rem;
    padding: .75rem 1rem; border-bottom: 1px solid var(--border);
}
.lb-row:last-child { border-bottom: none; }
.lb-rank { font-size: 1.2rem; font-weight: 800; width: 32px; text-align: center; }
.lb-rank.gold   { color: #F59E0B; }
.lb-rank.silver { color: #94A3B8; }
.lb-rank.bronze { color: #B45309; }
.lb-name { flex: 1; font-weight: 600; }
.lb-xp   { font-size: .9rem; color: var(--xp-color); font-weight: 700; }

/* ---- Auth-Screens ---- */
.auth-screen {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, #7C3AED 100%);
    padding: 1rem;
}
.auth-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 2rem; width: 100%; max-width: 420px;
    box-shadow: var(--shadow-lg);
}
.auth-logo {
    text-align: center; font-size: 1.8rem; font-weight: 800;
    color: var(--primary); margin-bottom: .25rem;
}
.auth-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 1.75rem; font-size: .95rem; }

/* ---- Formulare ---- */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .9rem; }
.form-input {
    width: 100%; padding: .7rem 1rem;
    border: 2px solid var(--border); border-radius: var(--radius-sm);
    font-size: 1rem; transition: border-color .15s;
}
.form-input:focus { outline: none; border-color: var(--primary); }
.form-input.error { border-color: var(--danger); }
.form-error { color: var(--danger); font-size: .85rem; margin-top: .35rem; }
.form-hint  { color: var(--text-muted); font-size: .8rem; margin-top: .25rem; }

/* ---- Alerts ---- */
.alert {
    padding: .85rem 1rem; border-radius: var(--radius-sm);
    margin-bottom: 1rem; font-size: .9rem;
    display: flex; align-items: center; gap: .6rem;
}
.alert-error   { background: var(--danger-light);  color: var(--danger);  }
.alert-success { background: var(--success-light); color: var(--success); }
.alert-info    { background: var(--primary-light); color: var(--primary); }

/* ---- Breadcrumb ---- */
.breadcrumb {
    display: flex; align-items: center; gap: .4rem;
    font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem;
}
.breadcrumb a { color: var(--primary); }
.breadcrumb .sep { color: var(--border); }

/* ---- Section-Header ---- */
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.section-title { font-size: 1.15rem; font-weight: 800; }

/* ---- Divider ---- */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ---- Loading Spinner ---- */
.spinner {
    display: inline-block; width: 32px; height: 32px;
    border: 3px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner-sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center {
    display: flex; justify-content: center; align-items: center;
    padding: 3rem; gap: 1rem; color: var(--text-muted);
}

/* ---- Leer-State ---- */
.empty-state {
    text-align: center; padding: 3rem 1rem; color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: .75rem; }
.empty-state .empty-title { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-bottom: .5rem; }

/* ---- Tags ---- */
.tag {
    display: inline-block; padding: .2rem .6rem;
    border-radius: 10px; font-size: .75rem; font-weight: 600;
}
.tag-basis      { background: var(--success-light); color: var(--success); }
.tag-standard   { background: var(--primary-light); color: var(--primary); }
.tag-vertiefung { background: var(--warning-light); color: var(--warning); }

/* ---- Notizen-Box ---- */
.note-box {
    background: var(--warning-light); border-left: 4px solid var(--warning);
    padding: .85rem 1rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: .9rem; margin: 1rem 0;
}

/* ---- Exam-Ergebnis ---- */
.grade-display {
    text-align: center; padding: 2rem;
}
.grade-circle {
    width: 120px; height: 120px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; margin: 0 auto 1rem;
    box-shadow: 0 4px 24px rgba(37,99,235,.3);
}
.grade-circle .grade-num { font-size: 3rem; font-weight: 900; line-height: 1; }
.grade-circle .grade-lbl { font-size: .75rem; opacity: .85; }

/* ---- Responsiv ---- */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 1rem; }
    .memory-grid { grid-template-columns: repeat(3, 1fr); }
    .chat-sidebar { display: none; }
    .chat-layout  { flex-direction: column; }
    .chat-main    { flex: 1; }
    .card-grid    { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .card-grid { grid-template-columns: 1fr; }
    .memory-grid { grid-template-columns: repeat(3, 1fr); }
    .stats-row { grid-template-columns: 1fr 1fr; }
}
