:root {
  --bg: #0d0a1f;
  --bg2: #16122e;
  --card: #1e1839;
  --card2: #272052;
  --line: rgba(255,255,255,.09);
  --text: #f4f2ff;
  --muted: #a9a3c7;
  --accent: #7c6cf6;
  --accent2: #35d0ba;
  --good: #34d399;
  --bad: #f8798a;
  --radius: 18px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; }

/* ---------- Start / Login ---------- */
.start {
  min-height: 100dvh;
  background: url("img/hero.jpg") center / cover no-repeat, radial-gradient(120% 90% at 50% 0%, #241b52 0%, #0d0a1f 70%);
  display: flex; align-items: flex-end; justify-content: center;
  position: relative;
}
.start::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(13,10,31,.15) 0%, rgba(13,10,31,.55) 45%, rgba(13,10,31,.92) 78%);
}
.startInner {
  position: relative; width: 100%; max-width: 420px;
  padding: 24px 22px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
}
.startLogo { width: 84px; height: 84px; border-radius: 24px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.startTitle { font-size: 2.4rem; font-weight: 800; letter-spacing: .5px; margin-top: 14px; text-shadow: 0 2px 18px rgba(0,0,0,.6); }
.startSub { color: #d8d3f2; margin: 6px 0 22px; text-shadow: 0 1px 10px rgba(0,0,0,.6); }
.loginForm { display: grid; gap: 10px; }
.loginForm input {
  width: 100%; padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(20,16,44,.72);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  outline: none;
}
.loginForm input:focus { border-color: var(--accent); }
.btnPrimary {
  padding: 15px 18px; border-radius: 14px; font-weight: 700; font-size: 1.02rem;
  background: linear-gradient(135deg, #8b7bff 0%, #6a54e8 55%, #4f8ef7 100%);
  box-shadow: 0 8px 22px rgba(106,84,232,.45), inset 0 1px 0 rgba(255,255,255,.25);
  color: #fff;
}
.btnPrimary:active { transform: scale(.98); }
.btnPrimary:disabled { opacity: .55; }
.btnGhost {
  margin-top: 12px; padding: 13px 18px; border-radius: 14px; width: 100%;
  border: 1px solid var(--line); background: rgba(255,255,255,.06); color: var(--text); font-weight: 600;
}
.btnGhost.small { width: auto; padding: 10px 16px; font-size: .92rem; }
.startHint { margin-top: 14px; font-size: .85rem; color: var(--muted); }
.formErr { color: var(--bad); font-size: .9rem; }
.formErr.big { margin-top: 12px; }

/* ---------- Layout ---------- */
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; padding: 0 16px calc(30px + env(safe-area-inset-bottom)); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 2px 10px;
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(180deg, var(--bg) 78%, transparent);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 1.1rem; }
.brandIcon { width: 30px; height: 30px; border-radius: 9px; }
.topActions { display: flex; align-items: center; gap: 8px; }
.profileChip {
  display: flex; align-items: center; gap: 7px; padding: 5px 12px 5px 5px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: .92rem;
}
.profileChip .avatar { width: 26px; height: 26px; font-size: .8rem; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%; overflow: hidden;
  background: linear-gradient(135deg, #7c6cf6, #35d0ba); color: #fff; font-weight: 800; font-size: 1.1rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.iconBtn { font-size: 1.4rem; width: 40px; height: 40px; border-radius: 12px; line-height: 1; }
.iconBtn:active { background: var(--card); }
.menuWrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 46px; min-width: 190px; z-index: 40;
  background: var(--card2); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  box-shadow: 0 14px 40px rgba(0,0,0,.55);
}
.menu button { display: block; width: 100%; text-align: left; padding: 13px 16px; font-weight: 600; }
.menu button:active { background: rgba(255,255,255,.07); }

.viewTabs {
  display: flex; gap: 6px; background: var(--bg2); border: 1px solid var(--line);
  padding: 5px; border-radius: 14px; margin: 4px 0 18px;
}
.viewTab { flex: 1; padding: 10px; border-radius: 10px; font-weight: 700; color: var(--muted); }
.viewTab.active { background: var(--card2); color: var(--text); box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }
.countPill {
  display: inline-block; min-width: 20px; padding: 1px 7px; margin-left: 5px;
  background: linear-gradient(135deg, #8b7bff, #4f8ef7); border-radius: 999px; font-size: .78rem; color: #fff;
}
.countPill:empty { display: none; }

.h2 { font-size: .95rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 18px 2px 9px; }
.h2:first-child { margin-top: 0; }

/* ---------- Fach & Stufe ---------- */
.subjectGroup { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.subject {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 12px 4px 10px; border-radius: 16px; font-weight: 700; font-size: .85rem;
  background: var(--card); border: 1.5px solid var(--line); color: var(--muted);
}
.subject.active { border-color: var(--accent); color: var(--text); background: var(--card2); box-shadow: 0 0 0 3px rgba(124,108,246,.22); }
.subIcon {
  width: 46px; height: 46px; border-radius: 14px; font-size: 1.45rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 2px 3px rgba(255,255,255,.35), inset 0 -3px 6px rgba(0,0,0,.3), 0 4px 10px rgba(0,0,0,.35);
}
.subMathe { background: linear-gradient(145deg, #6d5df0, #4534c9); }
.subDeutsch { background: linear-gradient(145deg, #f0a35e, #c96a2b); }
.subEnglisch { background: linear-gradient(145deg, #4f8ef7, #2f5ec9); }
.subNmg { background: linear-gradient(145deg, #3ecf8e, #1e9e63); }

.levelGroup { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.level {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 9px; border-radius: 16px;
  background: var(--card); border: 1.5px solid var(--line); color: var(--muted);
}
.level strong { font-size: .95rem; font-weight: 800; }
.level span { font-size: .62rem; font-weight: 600; text-align: center; }
.level.active { border-color: var(--accent2); color: var(--text); background: var(--card2); box-shadow: 0 0 0 3px rgba(53,208,186,.2); }
.level.active strong { color: var(--accent2); }

.setup input {
  width: 100%; padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--card); outline: none;
}
.setup input:focus { border-color: var(--accent); }
.chipRow { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.chip {
  padding: 7px 13px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
}
.chip:active { background: var(--card2); color: var(--text); }
.bigCta { width: 100%; margin-top: 20px; font-size: 1.1rem; padding: 16px; }

/* ---------- Loading ---------- */
.loading { text-align: center; padding: 34px 0 8px; color: var(--muted); }
.sparkles { display: flex; justify-content: center; gap: 10px; margin-bottom: 14px; }
.sparkles span {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, #8b7bff, #35d0ba);
  animation: bounce 1s infinite ease-in-out;
}
.sparkles span:nth-child(2) { animation-delay: .15s; }
.sparkles span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,100% { transform: translateY(0); opacity:.6 } 50% { transform: translateY(-12px); opacity:1 } }

/* ---------- Lernen ---------- */
.learnMeta { text-align: center; color: var(--muted); font-size: .9rem; margin-bottom: 8px; }
.progressWrap { height: 7px; border-radius: 99px; background: var(--card); overflow: hidden; margin-bottom: 22px; }
.progressBar { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, #7c6cf6, #35d0ba); transition: width .3s ease; }
.cardScene { perspective: 1200px; }
.card {
  position: relative; width: 100%; min-height: 300px; cursor: pointer;
  transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2,.7,.3,1.1);
  outline: none;
}
.card.flipped { transform: rotateY(180deg); }
.cardFace {
  position: absolute; inset: 0; border-radius: 22px; padding: 22px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border: 1px solid var(--line);
}
.cardFront { background: linear-gradient(160deg, #2a2158 0%, #1b1540 100%); box-shadow: 0 16px 40px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.12); }
.cardBack { background: linear-gradient(160deg, #123f37 0%, #152545 100%); transform: rotateY(180deg); box-shadow: 0 16px 40px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.12); }
.cardLabel { font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); position: absolute; top: 16px; left: 20px; }
.cardText { font-size: 1.35rem; font-weight: 700; line-height: 1.45; overflow-wrap: anywhere; }
.cardTap { position: absolute; bottom: 14px; font-size: .78rem; color: var(--muted); }
.answerBtns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.btnAgain, .btnKnown { padding: 15px; border-radius: 14px; font-weight: 800; font-size: 1.02rem; }
.btnAgain { background: rgba(248,121,138,.16); color: var(--bad); border: 1px solid rgba(248,121,138,.4); }
.btnKnown { background: rgba(52,211,153,.16); color: var(--good); border: 1px solid rgba(52,211,153,.4); }
.btnAgain:active, .btnKnown:active { transform: scale(.97); }
.learn .btnGhost.small { display: block; margin: 16px auto 0; }

.summaryBox { text-align: center; padding: 26px 8px 6px; }
.summaryEmoji { font-size: 3rem; }
.summaryTitle { font-size: 1.5rem; font-weight: 800; margin: 10px 0 6px; }
.summaryText { color: var(--muted); margin-bottom: 20px; }
.storyActions { display: grid; gap: 9px; }
.btnSoft {
  padding: 13px; border-radius: 13px; font-weight: 700;
  background: var(--card2); border: 1px solid var(--line);
}
.btnSoft:disabled { opacity: .5; }
.btnDanger {
  padding: 13px; border-radius: 13px; font-weight: 700;
  background: rgba(248,121,138,.14); color: var(--bad); border: 1px solid rgba(248,121,138,.35);
}

/* ---------- Sets-Liste ---------- */
.storyList { list-style: none; display: grid; gap: 10px; }
.setRow {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
}
.setRow .subIcon { width: 42px; height: 42px; font-size: 1.25rem; border-radius: 12px; flex-shrink: 0; }
.setInfo { flex: 1; min-width: 0; }
.setTitle { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.setSub { font-size: .8rem; color: var(--muted); }
.setGo { color: var(--muted); font-size: 1.3rem; }
.emptyHint { color: var(--muted); text-align: center; padding: 30px 12px; }

/* ---------- Sheets ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(5,3,15,.6); backdrop-filter: blur(3px); z-index: 50; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-width: 560px; margin: 0 auto;
  background: var(--bg2); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0; padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  max-height: 82dvh; overflow-y: auto;
}
.sheet.tall { max-height: 90dvh; }
.sheetTitle { font-size: 1.2rem; font-weight: 800; margin-bottom: 14px; }
.sheetHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.profileGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 12px; }
.profileTile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 8px; border-radius: 16px; background: var(--card); border: 1.5px solid var(--line); font-weight: 700;
}
.profileTile:active { border-color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 20px; border-radius: 999px; font-weight: 600; font-size: .92rem; z-index: 90;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}

@media (min-width: 520px) {
  .card { min-height: 340px; }
}

/* ---------- Themen ---------- */
.topicGrid { display: grid; gap: 10px; }
.topicTile {
  display: block; width: 100%; text-align: left;
  padding: 15px 16px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line);
}
.topicTile:active { background: var(--card2); }
.topicHead { display: flex; align-items: center; gap: 10px; }
.topicIcon { font-size: 1.35rem; }
.topicName { font-weight: 800; font-size: 1.05rem; }
.topicSub { color: var(--muted); font-size: .83rem; margin-top: 5px; }
.miniProgress { height: 5px; border-radius: 99px; background: rgba(255,255,255,.08); margin-top: 9px; overflow: hidden; }
.miniProgressFill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #7c6cf6, #35d0ba); }
