:root {
  --bg: #0f0a1f;
  --bg2: #170f2e;
  --karte: #1e1540;
  --karte2: #2a1f55;
  --rand: #3d2d74;
  --pergament: #f4e7c5;
  --tinte: #2b1d0e;
  --text: #eef0ff;
  --grau: #9aa0c7;
  --gold: #fbbf24;
  --gold-dunkel: #b7860b;
  --lila: #8b5cf6;
  --lila-dunkel: #5b35c4;
  --gruen: #22c55e;
  --gruen-dunkel: #15803d;
  --rot: #ef4444;
  --rot-dunkel: #b91c1c;
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 72% 9%, #fffa 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 85% 42%, #fde68a99 50%, transparent 51%),
    radial-gradient(1px 1px at 33% 62%, #fff7 50%, transparent 51%),
    radial-gradient(1px 1px at 58% 83%, #c4b5fd99 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 6% 91%, #fff6 50%, transparent 51%),
    radial-gradient(1000px 600px at 50% -200px, #3b1f7a 0%, var(--bg) 62%);
  background-attachment: fixed;
  background-color: var(--bg);
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
textarea, input { font: inherit; }

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
}

/* ---------- Kopfzeile ---------- */
.kopf {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.level-plakette {
  flex: none; width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--lila), var(--lila-dunkel));
  box-shadow: 0 4px 0 #3b2290;
  font-weight: 900; font-size: 20px;
}
.xp-block { flex: 1; min-width: 0; }
.xp-titel { font-size: 13px; color: var(--grau); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xp-titel b { color: var(--text); }
.xp-leiste { height: 12px; border-radius: 99px; background: var(--karte2); overflow: hidden; margin-top: 4px; position: relative; }
.xp-fuellung {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), #fde68a);
  box-shadow: 0 0 12px rgba(251, 191, 36, .6);
  transition: width .9s cubic-bezier(.2, .9, .3, 1.2);
}
.xp-zahl { font-size: 12px; color: var(--grau); margin-top: 2px; font-weight: 700; }
.serie {
  flex: none; display: flex; align-items: center; gap: 4px;
  padding: 6px 10px; border-radius: 14px; background: var(--karte);
  font-weight: 900;
}
.serie .flamme { display: inline-block; font-size: 20px; }
.serie.an .flamme { animation: flackern 1.4s infinite ease-in-out; }
.serie.aus { opacity: .55; filter: grayscale(.8); }
.joker { font-size: 12px; color: var(--grau); font-weight: 800; margin-left: 4px; }
.knopf-icon { flex: none; width: 40px; height: 40px; border-radius: 12px; background: var(--karte); font-size: 18px; }
.offline-punkt { width: 8px; height: 8px; border-radius: 50%; background: var(--rot); display: inline-block; margin-left: 4px; }

@keyframes flackern {
  0%, 100% { transform: scale(1) rotate(-3deg); }
  50% { transform: scale(1.15) rotate(3deg); }
}

/* ---------- Karten ---------- */
.karte {
  background: var(--karte);
  border: 1px solid var(--rand);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.karte h2 { margin: 0 0 6px; font-size: 19px; font-weight: 700; font-family: "Cinzel", serif; letter-spacing: .5px; color: #fde68a; }
h1, h2, h3 { font-family: "Cinzel", serif; }
.kapitel-nr { font-size: 11px; font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; color: var(--farbe); }
.karte p { margin: 6px 0; }
.leise { color: var(--grau); font-size: 15px; }
.karte.heute { background: linear-gradient(145deg, #3b1f7a, #1e1540); border-color: #b58b2a; box-shadow: 0 0 24px rgba(181,139,42,.18), inset 0 0 30px rgba(139,92,246,.15); }
.karte.erinnerung { border-style: dashed; }
.karte.erinnerung .merksatz { font-weight: 800; font-size: 18px; }

.knopf {
  display: block; width: 100%;
  padding: 14px 18px; border-radius: 16px;
  font-weight: 900; font-size: 17px; letter-spacing: .3px;
  background: var(--lila); box-shadow: 0 5px 0 var(--lila-dunkel);
  transition: transform .08s, box-shadow .08s;
  margin-top: 10px;
}
.knopf:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--lila-dunkel); }
.knopf.gold { background: var(--gold); color: #3a2a00; box-shadow: 0 5px 0 var(--gold-dunkel); }
.knopf.gold:active { box-shadow: 0 1px 0 var(--gold-dunkel); }
.knopf.gruen { background: var(--gruen); box-shadow: 0 5px 0 var(--gruen-dunkel); }
.knopf.zweit { background: var(--karte2); box-shadow: 0 5px 0 #151938; }
.knopf[disabled] { opacity: .45; pointer-events: none; }

/* ---------- Skill-Karte ---------- */
.gebiet-kopf {
  display: flex; align-items: center; gap: 12px;
  margin: 26px 0 8px; padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--karte); border: 1px solid var(--rand);
  border-left: 6px solid var(--farbe);
}
.gebiet-kopf .symbol { font-size: 28px; }
.gebiet-kopf h3 { margin: 0; font-size: 18px; font-weight: 700; }
.gebiet-kopf .fortschritt { font-size: 13px; color: var(--grau); font-weight: 700; }
.gebiet-kopf .mini-leiste { height: 6px; background: var(--karte2); border-radius: 9px; margin-top: 5px; overflow: hidden; }
.gebiet-kopf .mini-leiste div { height: 100%; background: var(--farbe); border-radius: 9px; }
.gebiet-kopf.gesperrt { opacity: .6; }

.pfad { position: relative; padding: 6px 0 4px; overflow: hidden; }
.knoten-reihe { display: flex; justify-content: center; padding: 10px 0; }
.knoten {
  position: relative; width: 76px; height: 76px; border-radius: 50%;
  outline: 2px solid rgba(253,230,138,.12); outline-offset: 5px;
  display: grid; place-items: center; font-size: 30px; font-weight: 900;
  background: #2a3060; box-shadow: 0 7px 0 #1a1f44;
  transition: transform .1s;
}
.knoten:active { transform: translateY(4px); box-shadow: 0 3px 0 #1a1f44; }
.knoten.fertig { background: radial-gradient(circle at 35% 30%, #fff3c4, #fbbf24 45%, #b7860b); box-shadow: 0 7px 0 var(--gold-dunkel), 0 0 22px rgba(251,191,36,.45); color: #3a2a00; }
.knoten.aktiv { background: radial-gradient(circle at 35% 30%, #fff8, var(--farbe) 55%); box-shadow: 0 7px 0 rgba(0,0,0,.35), 0 0 30px var(--farbe); }
.knoten.aktiv::after {
  content: ""; position: absolute; inset: -9px; border-radius: 50%;
  border: 4px solid var(--farbe); opacity: .7;
  animation: puls 1.6s infinite;
}
.knoten.gesperrt, .knoten.bald { color: #59608f; font-size: 24px; }
.knoten.bald { background: transparent; border: 3px dashed #3a4180; box-shadow: none; }
.knoten .fahne {
  position: absolute; top: -4px; right: -4px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--rot); color: white; font-size: 14px; display: grid; place-items: center;
  box-shadow: 0 2px 0 var(--rot-dunkel); animation: wackeln 2.4s infinite;
}
.knoten-label { text-align: center; font-size: 13px; font-weight: 800; color: var(--grau); margin-top: 10px; max-width: 140px; }
.knoten-wrap { display: flex; flex-direction: column; align-items: center; }
.start-blase {
  background: white; color: var(--bg); font-weight: 900; font-size: 13px;
  padding: 4px 10px; border-radius: 10px; margin-bottom: 10px; position: relative;
  animation: huepfen 1.2s infinite ease-in-out;
}
.start-blase::after { content: ""; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%); border: 6px solid transparent; border-top-color: white; border-bottom: 0; }

@keyframes puls { 0% { transform: scale(.95); opacity: .8; } 100% { transform: scale(1.25); opacity: 0; } }
@keyframes huepfen { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes wackeln { 0%, 90%, 100% { transform: rotate(0); } 93% { transform: rotate(-15deg); } 96% { transform: rotate(15deg); } }

/* ---------- Untere Navigation ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center; gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(13, 16, 36, .94); backdrop-filter: blur(8px);
  border-top: 1px solid var(--rand);
}
.nav button {
  flex: 1; max-width: 160px; padding: 8px 4px; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; font-weight: 800; color: var(--grau);
}
.nav button span { font-size: 22px; }
.nav button.an { background: var(--karte); color: var(--text); }

/* ---------- Lektion ---------- */
.lektion-kopf { display: flex; align-items: center; gap: 12px; padding: calc(14px + env(safe-area-inset-top)) 0 8px; }
.lektion-kopf .schliessen { font-size: 26px; color: var(--grau); width: 36px; }
.fortschritt-leiste { flex: 1; height: 14px; background: var(--karte2); border-radius: 99px; overflow: hidden; }
.fortschritt-leiste div { height: 100%; background: var(--gruen); border-radius: 99px; transition: width .5s cubic-bezier(.2,.9,.3,1.2); box-shadow: inset 0 -4px 0 rgba(0,0,0,.15); }
.lern-karte {
  background: radial-gradient(ellipse at center, #fbf3dc 0%, var(--pergament) 60%, #e3cf9e 100%);
  color: var(--tinte); border: 2px solid #c9a55a; border-radius: 6px;
  box-shadow: 0 12px 30px rgba(0,0,0,.5), inset 0 0 40px rgba(139,94,30,.25);
  padding: 26px 22px; margin: 18px 0; line-height: 1.6; min-height: 220px;
  font-family: "EB Garamond", Georgia, serif; font-size: 21px;
  animation: blaettern .5s cubic-bezier(.2,.9,.3,1.1); transform-origin: left center;
}
.lern-karte strong { color: #7c2d12; }
@keyframes blaettern { from { opacity: 0; transform: perspective(900px) rotateY(-35deg); } to { opacity: 1; transform: none; } }
.phase-label { font-size: 13px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase; color: var(--grau); margin-top: 8px; }
.frage { font-size: 21px; font-weight: 900; margin: 14px 0 16px; animation: reinschieben .35s; }
.antwort {
  display: block; width: 100%; text-align: left;
  padding: 14px 16px; margin: 10px 0; border-radius: 16px;
  background: var(--karte); border: 2px solid var(--rand); box-shadow: 0 4px 0 var(--rand);
  font-weight: 700;
}
.antwort:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--rand); }
.antwort.richtig { background: #14532d; border-color: var(--gruen); box-shadow: 0 4px 0 var(--gruen-dunkel); animation: hochspringen .45s; }
.antwort.falsch { background: #4c1515; border-color: var(--rot); box-shadow: 0 4px 0 var(--rot-dunkel); animation: schuetteln .4s; }
.antwort.gesperrt { pointer-events: none; }
.erklaerung { margin-top: 12px; padding: 14px; border-radius: 16px; animation: reinschieben .3s; font-weight: 700; }
.erklaerung.gut { background: rgba(34,197,94,.15); color: #bbf7d0; }
.erklaerung.schlecht { background: rgba(239,68,68,.15); color: #fecaca; }

@keyframes reinschieben { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes hochspringen { 0% { transform: scale(1); } 40% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes schuetteln { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }

.ergebnis { text-align: center; padding-top: 30px; }
.ergebnis .gross { font-size: 72px; animation: pop .6s cubic-bezier(.2,1.6,.4,1); }
.ergebnis h1 { font-size: 28px; font-weight: 700; margin: 8px 0; color: #fde68a; text-shadow: 0 0 20px rgba(251,191,36,.45); }
.xp-kacheln { display: flex; gap: 10px; justify-content: center; margin: 18px 0; }
.xp-kachel { flex: 1; max-width: 140px; border-radius: 16px; border: 2px solid var(--gold); overflow: hidden; animation: pop .5s backwards; }
.xp-kachel .oben { background: var(--gold); color: #3a2a00; font-size: 12px; font-weight: 900; padding: 4px; text-transform: uppercase; }
.xp-kachel .wert { font-size: 26px; font-weight: 900; padding: 8px; }
.merksatz-karte {
  text-align: left; margin: 16px 0; padding: 18px; border-radius: 6px;
  background: radial-gradient(ellipse at center, #fbf3dc, var(--pergament) 60%, #e3cf9e); color: var(--tinte); border: 2px solid #c9a55a;
  font-family: "EB Garamond", Georgia, serif;
  animation: pop .6s .3s backwards;
}
.merksatz-karte .klein { font-size: 12px; font-weight: 700; color: #7c2d12; text-transform: uppercase; letter-spacing: 2px; font-family: "Cinzel", serif; }
.merksatz-karte .satz { font-size: 21px; font-weight: 600; font-style: italic; margin-top: 6px; }

@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }

.schritt {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left;
  padding: 12px 14px; margin: 8px 0; border-radius: 14px; background: var(--karte); border: 2px solid var(--rand);
  font-weight: 700;
}
.schritt .haken { flex: none; width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--grau); display: grid; place-items: center; font-size: 16px; }
.schritt.an { border-color: var(--gruen); }
.schritt.an .haken { background: var(--gruen); border-color: var(--gruen); animation: pop .35s; }
.notiz, .frage-eingabe {
  width: 100%; min-height: 90px; resize: vertical; margin-top: 8px;
  padding: 12px; border-radius: 14px; border: 2px solid var(--rand);
  background: var(--bg2); color: var(--text);
}
.notiz:focus, .frage-eingabe:focus, .code-eingabe:focus { outline: none; border-color: var(--lila); }

/* ---------- Wissen ---------- */
.statistik { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.stat { background: var(--karte); border: 1px solid var(--rand); border-radius: 16px; padding: 12px 8px; text-align: center; }
.stat .zahl { font-size: 24px; font-weight: 900; }
.stat .was { font-size: 12px; color: var(--grau); font-weight: 800; }
.vitrine { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.abzeichen { text-align: center; padding: 12px 6px; border-radius: 16px; background: var(--karte); border: 1px solid var(--rand); }
.abzeichen .sym { font-size: 34px; display: block; }
.abzeichen .name { font-size: 12px; font-weight: 900; margin-top: 4px; }
.abzeichen .wie { font-size: 11px; color: var(--grau); }
.abzeichen.zu .sym { filter: grayscale(1) brightness(.35); }
.abzeichen.zu .name { color: var(--grau); }
.abzeichen.da { border-color: var(--gold); background: linear-gradient(160deg, #3b2f0b, var(--karte) 60%); }
.wissens-karte {
  width: 100%; text-align: left; perspective: 800px; margin: 10px 0; padding: 0;
}
.wissens-karte .innen {
  position: relative; display: grid; min-height: 96px; transition: transform .5s; transform-style: preserve-3d;
}
.wissens-karte.offen .innen { transform: rotateY(180deg); }
.wissens-karte .seite {
  grid-area: 1 / 1; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 16px; padding: 14px 16px; border: 1px solid var(--rand);
  display: flex; flex-direction: column; justify-content: center;
}
.wissens-karte .vorne { background: var(--karte); }
.wissens-karte .hinten { background: radial-gradient(ellipse at center, #fbf3dc, var(--pergament) 60%, #e3cf9e); color: var(--tinte); border-color: #c9a55a; transform: rotateY(180deg); font-family: "EB Garamond", Georgia, serif; }
.wissens-karte .hinten .satz { font-size: 18px; font-style: italic; }
.wissens-karte .hinten .eigen { color: #6b4f2a; }
.wissens-karte .titel { font-weight: 900; }
.wissens-karte .tipp { font-size: 12px; color: var(--grau); font-weight: 700; }
.wissens-karte .satz { font-weight: 800; }
.wissens-karte .eigen { font-size: 13px; color: var(--grau); margin-top: 6px; }

/* ---------- Frage-Box ---------- */
.frage-eintrag { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--rand); }
.frage-eintrag:first-child { border-top: 0; }
.frage-eintrag .text { flex: 1; font-weight: 700; }
.frage-eintrag .datum { font-size: 12px; color: var(--grau); }
.chip { font-size: 11px; font-weight: 900; padding: 3px 8px; border-radius: 99px; background: var(--karte2); color: var(--grau); white-space: nowrap; }
.chip.lektion { background: rgba(34,197,94,.2); color: #86efac; }
.weg { color: var(--grau); font-size: 18px; padding: 0 4px; }

/* ---------- Anmeldung ---------- */
.anmeldung { text-align: center; padding-top: 18vh; }
.anmeldung .logo { font-size: 72px; animation: huepfen 2s infinite ease-in-out; }
.anmeldung h1 { font-weight: 700; margin: 10px 0 4px; font-size: 38px; color: #fde68a; text-shadow: 0 0 24px rgba(251,191,36,.5); letter-spacing: 2px; }
.code-eingabe {
  width: 100%; padding: 14px; margin-top: 18px; border-radius: 16px; text-align: center;
  border: 2px solid var(--rand); background: var(--bg2); color: var(--text); font-size: 20px; font-weight: 800; letter-spacing: 1px;
}
.fehler { color: #fca5a5; font-weight: 800; margin-top: 10px; min-height: 1.4em; }

/* ---------- Effekte ---------- */
#konfetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 90; }
.xp-flug {
  position: fixed; z-index: 95; pointer-events: none;
  font-weight: 900; font-size: 22px; color: var(--gold);
  text-shadow: 0 2px 0 #3a2a00, 0 0 14px rgba(251,191,36,.7);
  animation: xpflug 1.1s ease-out forwards;
}
@keyframes xpflug { 0% { transform: translate(-50%, 0) scale(.6); opacity: 0; } 20% { transform: translate(-50%, -10px) scale(1.2); opacity: 1; } 100% { transform: translate(-50%, -80px) scale(1); opacity: 0; } }

#toasts { position: fixed; top: calc(70px + env(safe-area-inset-top)); left: 0; right: 0; z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  display: flex; gap: 12px; align-items: center; max-width: 440px; width: 100%;
  padding: 12px 16px; border-radius: 18px; background: var(--karte2); border: 2px solid var(--gold);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: toastrein .5s cubic-bezier(.2,1.4,.4,1), toastraus .4s 3.6s forwards;
  position: relative; overflow: hidden;
}
.toast::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 60px; left: -80px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  animation: glanz 1.2s .4s;
}
.toast .sym { font-size: 32px; }
.toast .t1 { font-size: 12px; font-weight: 900; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; }
.toast .t2 { font-weight: 900; }
@keyframes toastrein { from { transform: translateY(-30px) scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastraus { to { transform: translateY(-20px); opacity: 0; } }
@keyframes glanz { to { left: 110%; } }

#overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 24px;
  background: rgba(8, 10, 26, .88); backdrop-filter: blur(4px);
  animation: einblenden .3s;
}
#overlay[hidden] { display: none; }
.levelup { text-align: center; position: relative; width: 100%; max-width: 360px; }
.levelup .strahlen {
  position: absolute; left: 50%; top: 90px; width: 520px; height: 520px; margin: -260px 0 0 -260px; z-index: -1;
  background: repeating-conic-gradient(rgba(251,191,36,.18) 0 10deg, transparent 10deg 20deg);
  border-radius: 50%; animation: drehen 12s linear infinite;
  mask-image: radial-gradient(circle, black 30%, transparent 70%);
  -webkit-mask-image: radial-gradient(circle, black 30%, transparent 70%);
}
.levelup .stern {
  width: 160px; height: 160px; margin: 10px auto; border-radius: 40px;
  display: grid; place-items: center; font-size: 76px; font-weight: 900; color: white;
  background: linear-gradient(145deg, var(--lila), var(--lila-dunkel));
  box-shadow: 0 10px 0 #3b2290, 0 0 60px rgba(139,92,246,.8);
  animation: pop .8s cubic-bezier(.2,1.6,.4,1);
}
.levelup .zeile1 { font-size: 15px; font-weight: 900; letter-spacing: 3px; color: var(--gold); text-transform: uppercase; margin-top: 18px; }
.levelup .zeile2 { font-size: 30px; font-weight: 700; margin: 6px 0 4px; font-family: "Cinzel", serif; color: #fde68a; }
.levelup .stern { border-radius: 50%; }
@keyframes drehen { to { transform: rotate(360deg); } }
@keyframes einblenden { from { opacity: 0; } to { opacity: 1; } }

.blatt { background: var(--karte); border: 1px solid var(--rand); border-radius: 22px; padding: 20px; width: 100%; max-width: 420px; }
.blatt h2 { margin-top: 0; }
.schalter { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-top: 1px solid var(--rand); font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
