:root {
  --bg: #fdf6e3;
  --card: #ffffff;
  --text: #2b2d42;
  --muted: #6b7280;
  --primary: #4f7cff;
  --read: #ff8a5b;
  --num: #3ec28f;
  --write: #b06cf0;
  --ok: #3ec28f;
  --bad: #ff5c5c;
  --shadow: 0 6px 0 rgba(0,0,0,.12);
  --radius: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Nunito", "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 20px;
  touch-action: manipulation;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--primary); color: #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,.15);
}
#title { flex: 1; font-weight: 800; font-size: 24px; text-align: center; }
.stars { font-weight: 800; font-size: 22px; background: rgba(255,255,255,.2); padding: 4px 12px; border-radius: 999px; }
.icon-btn {
  width: 52px; height: 52px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.25); color: #fff; font-size: 24px; cursor: pointer;
}
.icon-btn:active { transform: scale(.92); }

#screen { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; }

/* --- Menüs --- */
.menu { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: auto; width: 100%; max-width: 1000px; }
.tile {
  background: var(--card); border: none; border-radius: var(--radius);
  padding: 26px 16px; cursor: pointer; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-size: 24px; font-weight: 800; color: var(--text); position: relative;
}
.tile .emoji { font-size: 72px; line-height: 1; }
.tile .sub { font-size: 16px; font-weight: 600; color: var(--muted); }
.tile:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.tile.read { border-top: 10px solid var(--read); }
.tile.num  { border-top: 10px solid var(--num); }
.tile.write{ border-top: 10px solid var(--write); }
.tile .badge { position: absolute; top: 10px; right: 14px; font-size: 16px; font-weight: 800; color: #d99a00; }
.tile .lvl { position: absolute; top: 10px; left: 14px; font-size: 14px; font-weight: 800; color: var(--muted); background: #f1f5f9; padding: 2px 10px; border-radius: 999px; }

.menu-head { text-align: center; margin: 6px 0 18px; }
.menu-head h1 { margin: 0; font-size: 32px; }
.menu-head p { margin: 4px 0 0; color: var(--muted); font-size: 18px; }

/* --- Aufgaben --- */
.task { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 20px; max-width: 1000px; width: 100%; margin: 0 auto; }
.progress { width: 100%; height: 14px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width .3s; border-radius: 999px; }

.prompt {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center;
  background: var(--card); border-radius: var(--radius); padding: 18px 28px; box-shadow: var(--shadow);
  font-size: 30px; font-weight: 800; min-height: 90px;
}
.prompt .big { font-size: 96px; line-height: 1; letter-spacing: 4px; }
.prompt .huge { font-size: 120px; line-height: 1; }
.prompt .pic { font-size: 110px; line-height: 1; }
.speak-btn {
  width: 64px; height: 64px; border-radius: 50%; border: none; background: var(--primary); color: #fff; font-size: 28px; cursor: pointer; box-shadow: var(--shadow);
}
.speak-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }

.options { display: grid; gap: 18px; width: 100%; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.options.narrow { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.opt {
  background: var(--card); border: 4px solid transparent; border-radius: var(--radius); padding: 18px; cursor: pointer;
  box-shadow: var(--shadow); font-size: 56px; font-weight: 800; min-height: 120px;
  display: flex; align-items: center; justify-content: center; text-align: center; color: var(--text); line-height: 1.1;
  transition: transform .1s;
}
.opt.word { font-size: 40px; letter-spacing: 2px; }
.opt.pic { font-size: 84px; }
.opt:active { transform: scale(.96); }
.opt.correct { border-color: var(--ok); background: #e9fbf3; animation: pop .4s; }
.opt.wrong { border-color: var(--bad); background: #fff0f0; animation: shake .4s; }
.opt.disabled { pointer-events: none; opacity: .55; }

@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-10px)} 75%{transform:translateX(10px)} }
@keyframes pop { 50%{transform:scale(1.08)} }

/* Wörter bauen */
.slots { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.slot {
  width: 86px; height: 100px; border-radius: 16px; border: 4px dashed #cbd5e1; background: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 56px; font-weight: 800;
}
.slot.filled { border-style: solid; border-color: var(--primary); }
.slot.ok { border-color: var(--ok); background: #e9fbf3; }
.letters { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.letter {
  width: 86px; height: 100px; border-radius: 16px; border: none; background: #fff3cd; box-shadow: var(--shadow);
  font-size: 56px; font-weight: 800; cursor: pointer; color: var(--text);
}
.letter:active { transform: translateY(3px); }
.letter.used { visibility: hidden; }
.letter.wrong { animation: shake .4s; background: #ffd5d5; }

/* Zahlen */
.objects { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 620px; font-size: 54px; line-height: 1; }
.objects.small { font-size: 42px; }
.tenframe { display: grid; grid-template-columns: repeat(5, 64px); gap: 8px; }
.tenframe .cell { width: 64px; height: 64px; border: 3px solid #94a3b8; border-radius: 12px; background: #fff; display: flex; align-items: center; justify-content: center; font-size: 40px; }
.tenframe .cell.a { background: #ffb3b3; }
.tenframe .cell.b { background: #a9d8ff; }
.tenframe .cell.q { background: #fff8d6; color: #d99a00; font-weight: 800; }
.twoframes { display: flex; gap: 24px; flex-wrap: wrap; justify-content: center; }
.numline { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.numline .n { width: 72px; height: 84px; border-radius: 14px; background: #fff; box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; font-size: 42px; font-weight: 800; }
.numline .n.q { background: #fff8d6; color: #d99a00; border: 4px dashed #d99a00; }
.equation { display: flex; align-items: center; gap: 14px; font-size: 72px; font-weight: 800; }
.equation .q { display: inline-flex; align-items: center; justify-content: center; width: 96px; height: 96px; border-radius: 18px; border: 4px dashed #d99a00; background: #fff8d6; color: #d99a00; }
.sign { font-size: 54px; }

/* Schreiben */
.write-wrap { display: flex; gap: 20px; width: 100%; flex: 1; flex-wrap: wrap; justify-content: center; align-items: stretch; }
.write-side { display: flex; flex-direction: column; gap: 12px; min-width: 200px; }
.write-side .pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-height: 60vh; overflow: auto; padding: 4px; }
.write-side .pick button { height: 56px; border-radius: 12px; border: none; background: #fff; box-shadow: 0 3px 0 rgba(0,0,0,.12); font-size: 26px; font-weight: 800; cursor: pointer; color: var(--text); }
.write-side .pick button.active { background: var(--write); color: #fff; }
.tracer { position: relative; flex: 1; min-width: 300px; min-height: 320px; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tracer canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.tracer .guide { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 300px; font-weight: 800; color: #e5e7eb; pointer-events: none; }
.tracer .lines { position: absolute; inset: 0; pointer-events: none; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btn {
  border: none; border-radius: 16px; padding: 14px 24px; font-size: 20px; font-weight: 800; cursor: pointer;
  background: var(--primary); color: #fff; box-shadow: var(--shadow);
}
.btn.secondary { background: #fff; color: var(--text); }
.btn.big { font-size: 26px; padding: 18px 36px; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.btn.color { width: 52px; height: 52px; border-radius: 50%; padding: 0; }

/* Ergebnis */
.result { text-align: center; margin: auto; }
.result .big-stars { font-size: 90px; letter-spacing: 8px; }
.result h2 { font-size: 36px; margin: 10px 0; }
.result p { color: var(--muted); font-size: 22px; }

/* Feedback-Overlay */
.feedback {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 160px; pointer-events: none; z-index: 50; animation: fb .7s forwards;
}
@keyframes fb { 0%{opacity:0; transform:scale(.4)} 30%{opacity:1; transform:scale(1.1)} 70%{opacity:1; transform:scale(1)} 100%{opacity:0} }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; width: 100%; height: 100%; }

@media (max-width: 700px) {
  body { font-size: 18px; }
  .prompt { font-size: 24px; padding: 12px 16px; }
  .prompt .big { font-size: 72px; }
  .prompt .pic, .prompt .huge { font-size: 84px; }
  .opt { font-size: 44px; min-height: 96px; padding: 12px; }
  .opt.pic { font-size: 64px; }
  .slot, .letter { width: 64px; height: 76px; font-size: 42px; }
  .tenframe { grid-template-columns: repeat(5, 48px); }
  .tenframe .cell { width: 48px; height: 48px; font-size: 30px; }
  .equation { font-size: 54px; }
  .equation .q { width: 72px; height: 72px; }
  .tracer .guide { font-size: 200px; }
}
