:root {
  --bg: #1b1440;
  --bg2: #2a1f5e;
  --card: #34287a;
  --ink: #ffffff;
  --muted: #b9b2e6;
  --gold: #ffd23f;
  --green: #3ddc84;
  --red: #ff5a6e;
  --blue: #4cc9f0;
  --orange: #ff9f1c;
  --pink: #f15bb5;
  --radius: 16px;
  --font: "Fredoka", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 20% 0%, #3b2a8a 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; }
input { font-family: inherit; }

.screen {
  display: none;
  position: fixed; inset: 0;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  max-width: 720px; margin: 0 auto;
}
.screen.active { display: flex; }

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
}
.topbar h2 { flex: 1; text-align: center; margin: 0; font-size: 20px; }
.topbar.slim { padding: 6px 10px; gap: 6px; }
.topbar.slim .chip { flex: 1; text-align: center; }
.chip {
  background: rgba(255,255,255,.1); border-radius: 999px;
  padding: 6px 12px; font-weight: 600; font-size: 15px; white-space: nowrap;
}
.icon-btn {
  background: rgba(255,255,255,.12); border-radius: 12px;
  width: 40px; height: 40px; font-size: 20px; flex: none;
}
.topbar > .icon-btn:last-child { margin-left: auto; }
.bar { flex: 1; height: 12px; background: rgba(255,255,255,.12); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--gold)); transition: width .3s; }

/* ---------- Start ---------- */
.logo {
  text-align: center; font-size: 42px; margin: 4px 0 8px; letter-spacing: .5px;
  text-shadow: 0 4px 0 #0006;
}
.logo span { color: var(--gold); }
.lang-row, .unit-row { display: flex; gap: 8px; padding: 0 16px; overflow-x: auto; scrollbar-width: none; }
.lang-row { justify-content: safe center; margin-bottom: 10px; }
.unit-row { margin-bottom: 14px; }
.lang-btn {
  flex: none; background: var(--card); border-radius: 12px; padding: 7px 10px; font-size: 14px; font-weight: 600;
  border: 2px solid transparent;
}
.lang-btn.on { border-color: var(--gold); }
.lang-btn[disabled] { opacity: .4; }
.unit-btn {
  flex: none; background: rgba(255,255,255,.08); border-radius: 999px; padding: 8px 14px;
  font-size: 14px; border: 2px solid transparent; color: var(--muted);
}
.unit-btn.on { background: var(--card); border-color: var(--blue); color: #fff; }

.game-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 0 16px 16px; overflow-y: auto;
}
.game-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  border-radius: 20px; padding: 16px; min-height: 150px;
  box-shadow: 0 6px 0 #0005; transition: transform .1s;
}
.game-card:active { transform: translateY(4px); box-shadow: 0 2px 0 #0005; }
.game-card.tetris { background: linear-gradient(145deg, #7b2ff7, #4361ee); }
.game-card.runner { background: linear-gradient(145deg, #ff595e, #ff924c); }
.game-card.training { background: linear-gradient(145deg, #06d6a0, #118ab2); }
.game-card.progress { background: linear-gradient(145deg, #f15bb5, #9b5de5); }
.gc-icon { font-size: 36px; }
.gc-title { font-size: 20px; font-weight: 700; }
.gc-sub { font-size: 13px; opacity: .9; line-height: 1.25; }
.gc-best { margin-top: auto; font-size: 13px; font-weight: 600; color: var(--gold); }

/* ---------- Scroll-Seiten ---------- */
.scroll { overflow-y: auto; padding: 0 16px 24px; flex: 1; }
.panel { background: var(--bg2); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.panel h3 { margin: 0 0 10px; font-size: 17px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; }
.row + .row { border-top: 1px solid rgba(255,255,255,.08); }
.seg { display: flex; background: rgba(255,255,255,.08); border-radius: 12px; padding: 3px; }
.seg button { background: none; padding: 7px 10px; border-radius: 10px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: #fff; }
.switch { width: 52px; height: 30px; border-radius: 99px; background: rgba(255,255,255,.15); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch.on { background: var(--green); }
.switch.on::after { left: 25px; }
.stack { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: rgba(255,255,255,.1); margin: 6px 0 4px; }
.stack .s-sitzt { background: var(--green); }
.stack .s-lernen { background: var(--orange); }
.legend { font-size: 13px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.word-list { list-style: none; padding: 0; margin: 0; }
.word-list li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; font-size: 15px; border-top: 1px solid rgba(255,255,255,.06); }
.word-list li span:last-child { color: var(--muted); text-align: right; }
.btn {
  display: inline-block; background: var(--gold); color: #2b1d00; font-weight: 700; font-size: 17px;
  padding: 12px 22px; border-radius: 14px; box-shadow: 0 4px 0 #a07c00;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #a07c00; }
.btn.ghost { background: rgba(255,255,255,.12); color: #fff; box-shadow: 0 4px 0 #0004; }
.btn.small { font-size: 14px; padding: 8px 14px; }

/* ---------- Fragen ---------- */
.qpanel { padding: 4px 12px 8px; text-align: center; }
.q-prompt { font-size: 22px; font-weight: 700; min-height: 30px; line-height: 1.2; }
.q-sub { font-size: 13px; color: var(--muted); min-height: 18px; margin-top: 2px; }
.q-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-top: 8px; }
.opt {
  background: var(--card); border-radius: 12px; padding: 10px 8px; font-size: 15px; font-weight: 600;
  box-shadow: 0 4px 0 #0005; line-height: 1.15; min-height: 46px;
}
.opt:active { transform: translateY(3px); box-shadow: 0 1px 0 #0005; }
.opt.right { background: var(--green); color: #053; }
.opt.wrong { background: var(--red); }
.opt[disabled] { opacity: .85; }

/* ---------- Training ---------- */
.tr-body { flex: 1; display: flex; flex-direction: column; padding: 8px 16px 20px; overflow-y: auto; }
.tr-type { text-align: center; font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--blue); font-weight: 700; }
.tr-emoji { text-align: center; font-size: 56px; min-height: 66px; }
.tr-prompt { text-align: center; font-size: 28px; font-weight: 700; margin: 6px 0; line-height: 1.2; }
.tr-sub { text-align: center; color: var(--muted); font-size: 15px; margin-bottom: 14px; }
.tr-opts { display: grid; gap: 10px; }
.tr-opts .opt { font-size: 18px; padding: 14px; }
.tr-input {
  width: 100%; font-size: 22px; padding: 14px; border-radius: 14px; border: 3px solid var(--card);
  background: #120d2e; color: #fff; text-align: center; outline: none;
}
.tr-input:focus { border-color: var(--blue); }
.tr-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.speak-btn { font-size: 40px; background: var(--card); width: 90px; height: 90px; border-radius: 50%; margin: 8px auto; display: block; box-shadow: 0 5px 0 #0005; }
.tiles { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; min-height: 52px; }
.tile { background: var(--card); min-width: 42px; height: 46px; border-radius: 10px; font-size: 22px; font-weight: 700; box-shadow: 0 4px 0 #0005; padding: 0 8px; }
.tile.used { visibility: hidden; }
.answer-line { min-height: 54px; border-bottom: 3px dashed var(--muted); display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 6px; }
.feedback { border-radius: var(--radius); padding: 14px; margin-top: 14px; text-align: center; }
.feedback.ok { background: rgba(61,220,132,.18); border: 2px solid var(--green); }
.feedback.no { background: rgba(255,90,110,.15); border: 2px solid var(--red); }
.feedback.mid { background: rgba(255,159,28,.15); border: 2px solid var(--orange); }
.feedback .big { font-size: 20px; font-weight: 700; margin: 4px 0; }
.note { font-family: inherit; width: 100%; margin-top: 10px; border-radius: 10px; border: 0; background: #120d2e; color: #fff; padding: 10px; font-size: 14px; }
.flip { perspective: 900px; margin: 10px 0; }
.flip-card { background: var(--card); border-radius: 20px; min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px; text-align: center; font-size: 26px; font-weight: 700; box-shadow: 0 6px 0 #0005; }
.flip-card small { font-size: 14px; color: var(--muted); font-weight: 400; margin-top: 8px; }

/* ---------- Spiele ---------- */
.game-screen { background: #0f0b26; }
.board-wrap { flex: 1; display: flex; justify-content: center; align-items: center; min-height: 0; padding: 0 8px; }
.board-wrap canvas { border-radius: 10px; background: #0b0820; box-shadow: 0 0 0 3px #3a2f86, 0 0 30px #4361ee44; touch-action: none; }
.pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; padding: 10px 12px 12px; }
.pad button { background: var(--card); height: 56px; border-radius: 14px; font-size: 24px; box-shadow: 0 4px 0 #0006; touch-action: manipulation; }
.pad button:active { transform: translateY(3px); box-shadow: 0 1px 0 #0006; }
.runner-wrap { flex: 1; min-height: 0; position: relative; }
.runner-wrap canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.runner-q { min-height: 64px; }
#t-q { min-height: 142px; }
#t-q .opt { font-size: 14px; padding: 8px 6px; }
.hint { text-align: center; font-size: 12px; color: var(--muted); padding: 6px; }

.overlay {
  display: none; position: absolute; inset: 0; background: rgba(10,6,30,.85);
  flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 12px;
  z-index: 5;
}
.overlay.show { display: flex; }
.overlay h2 { font-size: 34px; margin: 0; }
.overlay p { color: var(--muted); margin: 0; max-width: 420px; line-height: 1.4; }
.overlay .boss { font-size: 70px; }
.overlay .tr-input { max-width: 420px; }
.hearts-row { font-size: 30px; letter-spacing: 4px; }

#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: #000c; padding: 10px 18px; border-radius: 99px; font-weight: 600; opacity: 0;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 560px) {
  .game-grid { grid-template-columns: 1fr 1fr; }
  .logo { font-size: 52px; }
}
