:root {
  --bg1: #6c4cf1;
  --bg2: #a855f7;
  --card: #ffffff;
  --primary: #6c4cf1;
  --primary-dark: #5235d6;
  --soft: #f4f2fd;
  --soft: color-mix(in srgb, var(--primary) 12%, #fff);
  --line: #e7e4f5;
  --line: color-mix(in srgb, var(--primary) 16%, #e8e8ef);
  --ink: #1f1b3a;
  --muted: #6b6889;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --gold: #f59e0b;
  --radius: 20px;
  --shadow: 0 10px 30px rgba(31, 27, 58, 0.15);
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  background-color: var(--bg1);
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--bg1);
  line-height: 1.45;
}
/* Festes Lila hinter allem – auf iOS füllt `background-attachment: fixed` den Statusbalken nicht. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(135deg, var(--bg1), var(--bg2));
  pointer-events: none;
}
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

#app {
  max-width: 1000px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(48px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.center-screen { min-height: 90vh; display: grid; place-items: center; }
.loader { animation: bounce 1s infinite; filter: drop-shadow(0 10px 20px rgba(31, 27, 58, .3)); }
@keyframes bounce { 50% { transform: translateY(-16px); } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card.narrow { max-width: 440px; width: 100%; margin: 0 auto; }

/* Buttons & Formulare */
.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 20px;
  font-weight: 700;
  background: var(--soft);
  color: var(--primary-dark);
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { background: color-mix(in srgb, var(--primary) 22%, #fff); }
.btn:active { transform: translateY(2px); }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-dark); }
.btn.primary:hover { background: var(--bg2); }
.btn.primary:active { box-shadow: 0 1px 0 var(--primary-dark); }
.btn.big { font-size: 1.25rem; padding: 16px 28px; width: 100%; }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.ghost { background: rgba(255, 255, 255, .18); color: #fff; }
.btn.ghost:hover { background: rgba(255, 255, 255, .3); }
.btn.sm { padding: 7px 12px; border-radius: 10px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-weight: 700; font-size: .9rem; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .grow { flex: 1 1 160px; }

/* Kopfzeile */
.topbar { display: flex; align-items: center; gap: 12px; color: #fff; margin-bottom: 16px; flex-wrap: wrap; }
.topbar .who { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 200px; }
.topbar .avatar { font-size: 2.6rem; background: rgba(255, 255, 255, .2); border-radius: 50%; width: 64px; height: 64px; display: grid; place-items: center; cursor: pointer; }
.topbar .avatar:hover { background: rgba(255, 255, 255, .35); }
.topbar h1 { margin: 0; font-size: 1.4rem; }
.topbar .sub { opacity: .9; font-size: .95rem; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; padding-bottom: 2px; }
.tab { border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 700; background: rgba(255, 255, 255, .2); color: #fff; white-space: nowrap; }
.tab.active { background: #fff; color: var(--primary-dark); }

/* Login */
.login-title { color: #fff; text-align: center; margin: 5vh 0 24px; }
.login-title h1 { font-size: 2.4rem; letter-spacing: -.5px; margin-bottom: .2em; }
.login-title .logo { display: block; margin: 0 auto 10px; border-radius: 26px; box-shadow: 0 0 0 4px rgba(255, 255, 255, .35), var(--shadow); }
.kid-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; max-width: 700px; margin: 0 auto 24px; }
.kid-tile { border: 0; background: #fff; border-radius: var(--radius); padding: 22px 12px; box-shadow: var(--shadow); font-weight: 800; font-size: 1.15rem; transition: transform .12s; }
.kid-tile:hover { transform: translateY(-4px) scale(1.03); }
.kid-tile .emoji { display: block; font-size: 3.6rem; margin-bottom: 6px; }
.login-foot { text-align: center; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0; }
.pin-dots span { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--primary); }
.pin-dots span.on { background: var(--primary); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 280px; margin: 0 auto; }
.pinpad button { font-size: 1.6rem; padding: 14px 0; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-5px); } }

/* Kinder-Home */
.xpbar { height: 16px; background: rgba(255, 255, 255, .25); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.xpbar > div { height: 100%; background: linear-gradient(90deg, #fde047, #f59e0b); border-radius: 999px; transition: width .6s; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border-radius: 16px; padding: 14px; text-align: center; box-shadow: var(--shadow); }
.stat .big { font-size: 1.6rem; font-weight: 800; display: block; }
.stat .lbl { font-size: .82rem; color: var(--muted); }
.goal-done { background: var(--good-bg); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 700; }
.chip.on { border-color: var(--primary); background: var(--soft); color: var(--primary-dark); }
.chip .pct { font-weight: 600; color: var(--muted); font-size: .8rem; margin-left: 4px; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.mode { border: 2px solid var(--line); background: #fff; border-radius: 16px; padding: 12px; text-align: left; }
.mode.on { border-color: var(--primary); background: var(--soft); }
.mode .icon { font-size: 1.7rem; display: block; }
.mode b { display: block; }
.mode span.d { font-size: .8rem; color: var(--muted); }
.mode:disabled { opacity: .45; }

.awards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.award { border-radius: 16px; padding: 14px 10px; text-align: center; background: var(--soft); }
.award .emoji { font-size: 2.6rem; display: block; }
.award b { display: block; font-size: .95rem; }
.award .d { font-size: .78rem; color: var(--muted); }
.award.locked { filter: grayscale(1); opacity: .45; }
.award.earned { background: linear-gradient(160deg, #fef9c3, #fde68a); }

/* Test */
.test-head { display: flex; align-items: center; gap: 12px; color: #fff; margin-bottom: 14px; }
.test-head .bar { flex: 1; height: 14px; background: rgba(255, 255, 255, .25); border-radius: 999px; overflow: hidden; }
.test-head .bar > div { height: 100%; background: #4ade80; border-radius: 999px; transition: width .3s; }
.combo { font-weight: 800; min-width: 56px; text-align: right; }
.question { text-align: center; padding: 28px 20px; }
.question .hint { color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.question .word { font-size: clamp(1.8rem, 6vw, 2.8rem); font-weight: 800; margin-bottom: 8px; word-break: break-word; }
.speak { border: 0; background: var(--soft); border-radius: 50%; width: 48px; height: 48px; font-size: 1.4rem; }
.speak.huge { width: 110px; height: 110px; font-size: 3.2rem; margin: 6px 0 12px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
@media (max-width: 560px) { .options { grid-template-columns: 1fr; } }
.option { border: 3px solid var(--line); background: #fff; border-radius: 16px; padding: 18px 12px; font-size: 1.15rem; font-weight: 700; }
.option:hover:not(:disabled) { border-color: var(--primary); }
.option.correct { border-color: var(--good); background: var(--good-bg); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.answer-form { display: flex; gap: 10px; margin-top: 20px; }
.answer-form input { font-size: 1.3rem; text-align: center; }
.feedback { margin-top: 18px; border-radius: 16px; padding: 14px; font-weight: 700; }
.feedback.ok { background: var(--good-bg); color: #14532d; }
.feedback.no { background: var(--bad-bg); color: #7f1d1d; }
.feedback .sol { font-size: 1.3rem; display: block; }

/* Ergebnis */
.result { text-align: center; }
.stars { font-size: 3.4rem; letter-spacing: 6px; }
.stars .off { filter: grayscale(1); opacity: .3; }
.score { font-size: 2.4rem; font-weight: 800; }
.banner { background: linear-gradient(160deg, #fef9c3, #fde68a); border-radius: 16px; padding: 14px; margin: 14px 0; font-weight: 700; animation: pop .5s; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.06); } }
.review { text-align: left; margin: 16px 0; }
.review li { padding: 6px 0; border-bottom: 1px solid var(--line); list-style: none; }
.review ul { padding: 0; margin: 0; }
.ok-t { color: var(--good); font-weight: 700; }
.no-t { color: var(--bad); font-weight: 700; }

/* Eltern */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; color: var(--muted); padding: 6px 8px; }
td { padding: 6px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
td input[type=text] { padding: 7px 10px; border-color: transparent; background: transparent; }
td input[type=text]:hover { border-color: var(--line); }
td input[type=text]:focus { border-color: var(--primary); background: #fff; }
tr.inactive input[type=text] { text-decoration: line-through; color: var(--muted); }
td.added { white-space: nowrap; color: var(--muted); font-size: .85rem; }
.kid-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.kid-head .emoji { font-size: 2.8rem; }
.kid-head h2 { margin: 0; }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 16px; }
.mini { background: var(--soft); border-radius: 14px; padding: 10px; text-align: center; }
.mini b { display: block; font-size: 1.3rem; }
.mini span { font-size: .78rem; color: var(--muted); }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 90px; margin: 6px 0 4px; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 6px 6px 0 0; overflow: hidden; background: var(--soft); }
.chart .wrongpart { background: #fca5a5; }
.chart .okpart { background: #4ade80; }
.chart-labels { display: flex; gap: 4px; font-size: .65rem; color: var(--muted); text-align: center; }
.chart-labels span { flex: 1; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }
details { border-top: 1px solid var(--line); padding: 8px 0; }
summary { cursor: pointer; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
summary .pill { margin-left: auto; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 700; background: var(--soft); }
.pill.good { background: var(--good-bg); color: #14532d; }
.pill.mid { background: #fef3c7; color: #78350f; }
.pill.bad { background: var(--bad-bg); color: #7f1d1d; }
.avatar-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.avatar-pick button { border: 2px solid var(--line); background: #fff; border-radius: 12px; font-size: 1.5rem; width: 46px; height: 46px; }
.avatar-pick button.on { border-color: var(--primary); background: var(--soft); }
.color-pick { display: flex; flex-wrap: wrap; gap: 10px; }
.color-pick button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--line);
  padding: 0;
}
.color-pick button.on { box-shadow: 0 0 0 3px var(--ink); }
.checks { display: flex; flex-wrap: wrap; gap: 12px; }
.checks label { display: flex; align-items: center; gap: 6px; font-weight: 600; margin: 0; }
.switch { width: 20px; height: 20px; accent-color: var(--primary); }
code { background: var(--soft); border-radius: 6px; padding: 2px 6px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 80px); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px; font-weight: 700; transition: transform .3s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { transform: translate(-50%, 0); }
#toast.err { background: var(--bad); }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
#confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* Arbeitsblatt drucken */
#sheet { display: none; }
@media print {
  html, body { background: #fff; }
  body::before { display: none; }
  #app > *:not(#sheet), #toast, #confetti { display: none !important; }
  #app { max-width: none; padding: 0; }
  #sheet { display: block; font-family: Georgia, serif; color: #000; }
  #sheet h1 { font-size: 1.5rem; }
  #sheet .meta { display: flex; justify-content: space-between; margin: 12px 0 18px; }
  #sheet td { border: 0; border-bottom: 1px solid #999; padding: 12px 6px; font-size: 1.05rem; }
  #sheet td.n { width: 36px; color: #555; }
  #sheet td.p { width: 45%; }
  #sheet .solutions { page-break-before: always; }
}
