:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1e1b3a;
  --muted: #6b6a85;
  --line: #e4e4f0;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --primary-soft: #eef0ff;
  --good: #059669;
  --good-soft: #d1fae5;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --fire: #f97316;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(30, 27, 58, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12111c;
    --card: #1d1c2b;
    --text: #f1f0ff;
    --muted: #a3a1bf;
    --line: #2e2c42;
    --primary: #818cf8;
    --primary-2: #6366f1;
    --primary-soft: #26254a;
    --good: #34d399;
    --good-soft: #0f3a2e;
    --bad: #f87171;
    --bad-soft: #3f1d1d;
    --warn: #fbbf24;
    --warn-soft: #3d2f0c;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  min-height: 100vh;
}
h1 { font-size: 1.6rem; margin: 0.3em 0; text-align: center; }
h2 { font-size: 1.25rem; margin: 0; }
h3 { font-size: 1.05rem; margin: 0 0 0.6em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.spacer { height: 14px; }

.screen { max-width: 920px; margin: 0 auto; padding: 16px 16px 40px; }
.screen.narrow { max-width: 560px; }
.hero { font-size: 3.5rem; text-align: center; margin-top: 12px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin: 12px 0;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
.grid2 .card { margin: 0; }
@media (min-width: 720px) { .grid2 { grid-template-columns: 1fr 1fr; margin: 12px 0; } }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Buttons */
button { font: inherit; color: inherit; }
.btn {
  display: block; width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 14px; padding: 12px 16px; margin: 8px 0; font-weight: 600; cursor: pointer; text-align: center;
}
.btn.primary { background: var(--primary-2); border-color: var(--primary-2); color: #fff; }
.btn.secondary { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.big { padding: 16px; font-size: 1.1rem; }
.btn.small { width: auto; display: inline-block; padding: 7px 12px; margin: 0; font-size: 0.85rem; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.icon-btn { border: none; background: var(--card); width: 44px; height: 44px; border-radius: 50%; font-size: 1.3rem; cursor: pointer; position: relative; box-shadow: var(--shadow); border: 1px solid var(--line); }
.icon-btn .dot { position: absolute; top: 6px; right: 6px; width: 10px; height: 10px; background: var(--bad); border-radius: 50%; }
.btn-col { display: flex; flex-direction: column; gap: 6px; }
.file-btn { cursor: pointer; }

/* Forms */
label { display: block; margin: 10px 0; font-size: 0.9rem; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input:not([type]), select {
  display: block; width: 100%; margin-top: 4px; padding: 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text);
}
label.toggle { display: flex; align-items: center; gap: 10px; color: var(--text); }
label.toggle input { width: 22px; height: 22px; }
.pin-input { text-align: center; font-size: 1.6rem !important; letter-spacing: 0.4em; }

/* Topbar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.top-actions { display: flex; gap: 8px; }
.who { border: none; background: none; font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 0; }
.avatar { font-size: 1.8rem; }

/* Profile */
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin: 20px 0; }
.profile-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 10px; cursor: pointer; box-shadow: var(--shadow); }
.avatar-big { font-size: 2.8rem; display: block; }
.pname { font-weight: 700; font-size: 1.1rem; margin: 4px 0; }
.avatars { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.avatar-opt { font-size: 1.6rem; width: 48px; height: 48px; border-radius: 12px; border: 2px solid transparent; background: var(--bg); cursor: pointer; }
.avatar-opt.sel { border-color: var(--primary-2); background: var(--primary-soft); }

/* Streak */
.streak-card { text-align: center; }
.streak-card.done { background: linear-gradient(160deg, #fff7ed, var(--card)); }
@media (prefers-color-scheme: dark) { .streak-card.done { background: linear-gradient(160deg, #3a2410, var(--card)); } }
.streak-num { font-size: 2.6rem; font-weight: 800; color: var(--fire); }
.streak-label { font-weight: 700; margin-bottom: 4px; }
.week { display: flex; justify-content: space-between; gap: 4px; margin: 12px 0 8px; }
.wd { flex: 1; font-size: 0.75rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px; }
.wd span { width: 30px; height: 30px; border-radius: 50%; background: var(--bg); border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; }
.wd.on span { background: var(--fire); border-color: var(--fire); }
.wd.today span { border-color: var(--fire); }
.wd.future span { opacity: 0.5; }

/* Bars */
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0; }
.bar > div { height: 100%; background: var(--primary-2); border-radius: 99px; transition: width 0.4s; }
.bar.goal > div { background: var(--good); }
.bar.xp > div { background: linear-gradient(90deg, #f59e0b, #f97316); }

/* Lektionen */
.lessons { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.lesson { display: flex; align-items: center; gap: 12px; text-align: left; border: 2px solid var(--line); border-radius: 14px; background: var(--bg); padding: 10px 12px; cursor: pointer; }
.lesson.sel { border-color: var(--primary-2); background: var(--primary-soft); }
.lesson .check { width: 26px; height: 26px; flex: none; border-radius: 8px; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; background: var(--card); font-weight: 800; color: var(--primary); }
.lesson.sel .check { border-color: var(--primary-2); }
.lesson-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.lesson-title { font-weight: 700; }
.lesson-pct { font-weight: 700; color: var(--muted); font-size: 0.9rem; }
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; margin: 8px 0; }
.seg button { flex: 1; border: none; background: none; padding: 9px 4px; border-radius: 9px; font-size: 0.85rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.sel { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }

/* Quiz */
.quiz-progress { flex: 1; }
.combo { min-width: 56px; text-align: right; font-weight: 800; color: var(--warn); }
.combo.warm { color: var(--fire); }
.combo.hot { color: var(--bad); animation: pulse 0.8s infinite alternate; }
.quiz-card { text-align: center; padding: 26px 18px; margin-top: 20px; }
.qword { font-size: 2rem; font-weight: 800; margin: 18px 0 6px; word-break: break-word; }
.answer { text-align: center; font-size: 1.4rem !important; padding: 14px !important; margin: 16px 0 6px !important; border-width: 2px !important; }
.answer.ok { border-color: var(--good) !important; background: var(--good-soft) !important; }
.answer.bad { border-color: var(--bad) !important; background: var(--bad-soft) !important; }
.feedback { min-height: 2.6em; padding: 8px; border-radius: 12px; font-weight: 600; }
.feedback.ok { color: var(--good); }
.feedback.bad { color: var(--bad); background: var(--bad-soft); }
.feedback.hint { color: var(--warn); background: var(--warn-soft); }
.feedback .xp { color: var(--warn); margin-left: 6px; }
.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes pulse { to { transform: scale(1.15); } }

/* Arbeit */
.exam-card { border: 2px solid var(--primary-2); background: linear-gradient(160deg, var(--primary-soft), var(--card)); }
.exam-card .btn.small { margin-top: 4px; }

/* Geräte */
.pair-code { font-size: 2.6rem; font-weight: 800; letter-spacing: 0.15em; text-align: center; color: var(--primary); margin-top: 12px; }
details.card summary { cursor: pointer; font-weight: 600; }
details.card[open] summary { margin-bottom: 8px; }

/* Papier-Modus */
.paper-box { margin: 18px 0 8px; padding: 22px 12px; border: 2px dashed var(--line); border-radius: 16px; min-height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.paper-box.revealed { border-style: solid; border-color: var(--primary-2); background: var(--primary-soft); }
.paper-icon { font-size: 2.4rem; }
.paper-solution { font-size: 1.9rem; font-weight: 800; color: var(--primary); word-break: break-word; }
.paper-judge { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.paper-judge .btn { padding: 18px 8px; font-size: 1.15rem; margin: 0; }
.judge-ok { background: var(--good); border-color: var(--good); color: #fff; }
.judge-bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

/* Ergebnis */
.stats3, .stats4 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; text-align: center; }
.stats4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 600px) { .stats4 { grid-template-columns: repeat(4, 1fr); } }
.stats3 > div, .stats4 > div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; }
.stats3 b, .stats4 b { display: block; font-size: 1.6rem; }
.stats3 span, .stats4 span { font-size: 0.8rem; color: var(--muted); }
.event { background: var(--warn-soft); color: var(--text); border-radius: 12px; padding: 10px 14px; margin: 8px 0; font-weight: 600; text-align: center; }
.event.big { font-size: 1.2rem; background: var(--primary-soft); }
.event.badge-new { background: var(--good-soft); }
.mistakes { list-style: none; padding: 0; margin: 0; }
.mistakes li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mistakes li:last-child { border: none; }

/* Abzeichen */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.badge { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 10px; text-align: center; opacity: 0.45; filter: grayscale(1); }
.badge.got { opacity: 1; filter: none; border-color: var(--warn); }
.bemoji { font-size: 2.2rem; }
.bname { font-weight: 700; }

/* Belohnungen */
.points { font-size: 2.4rem; font-weight: 800; color: var(--warn); }
.reward { display: flex; align-items: center; gap: 12px; }
.reward .btn { width: auto; margin: 0; }
.remoji { font-size: 2rem; }
.rmain { flex: 1; min-width: 0; }
.rname { font-weight: 700; }
.req-list { list-style: none; padding: 0; margin: 0; }
.req-list li { padding: 6px 0; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.tag { font-size: 0.75rem; padding: 3px 8px; border-radius: 99px; background: var(--line); white-space: nowrap; }
.tag.pending { background: var(--warn-soft); color: var(--warn); }
.tag.approved { background: var(--good-soft); color: var(--good); }
.tag.rejected { background: var(--bad-soft); color: var(--bad); }
.reward-edit { display: grid; grid-template-columns: 56px 1fr; gap: 0 10px; align-items: end; }
.reward-edit label { grid-column: 2; margin: 4px 0; }
.reward-edit .emoji-in { grid-row: 1 / span 3; align-self: start; font-size: 1.6rem; text-align: center; padding: 8px; margin-top: 22px; }
.reward-edit .btn { grid-column: 2; justify-self: start; margin-top: 8px; }

/* Eltern */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0; padding-bottom: 4px; }
.tabs button { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 8px 14px; white-space: nowrap; font-weight: 600; cursor: pointer; }
.tabs button.sel { background: var(--primary-2); border-color: var(--primary-2); color: #fff; }
.kid-row { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; cursor: pointer; }
.kid-main { flex: 1; display: flex; flex-direction: column; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 130px; margin: 8px 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; font-size: 0.65rem; color: var(--muted); }
.chart .stack { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.chart .c { background: #86efac; border-radius: 4px 4px 0 0; }
.chart .c.goal { background: var(--good); }
.chart .w { background: #fca5a5; }
.danger-zone .btn { margin: 6px 0; }

/* Toast & Konfetti */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600;
  opacity: 0; transition: all 0.3s; z-index: 1000; max-width: 90vw; text-align: center; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 999; }
