:root {
  --b1: #E4572E; --b2: #F3A712; --b3: #4C9F70; --b4: #2E86AB; --b5: #7B4EA3; --gold: #F5B700;
  --bg: #FFF8EE; --card: #FFFFFF; --ink: #1F2933; --muted: #6B7280; --line: #E8E1D5;
  --ok: #2E9D5B; --bad: #D64545; --accent: #2E86AB;
  --radius: 18px; --shadow: 0 6px 0 rgba(0,0,0,.08), 0 10px 24px rgba(0,0,0,.06);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
main { max-width: 820px; margin: 0 auto; padding: 16px 16px 48px; }
h1 { font-size: 1.7rem; margin: .4em 0 .2em; }
h2 { font-size: 1.25rem; margin: 1.2em 0 .5em; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin: 14px 0; }
.center { text-align: center; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 14px; padding: 12px 18px; cursor: pointer;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.18); transition: transform .08s, box-shadow .08s;
  min-height: 44px;
}
button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--accent); box-shadow: none; border: 2px solid var(--line); }
button.danger { background: var(--bad); }
button.ok { background: var(--ok); }
button.big { font-size: 1.3rem; padding: 18px 26px; border-radius: 20px; width: 100%; }
button.small { padding: 6px 10px; min-height: 34px; font-size: .9rem; }
input, select, textarea {
  font: inherit; width: 100%; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; font-weight: 700; margin: 12px 0 6px; }
a { color: var(--accent); }

/* Top-Bar */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.avatar { font-size: 2.2rem; width: 58px; height: 58px; display: grid; place-items: center; background: #fff; border-radius: 50%; box-shadow: var(--shadow); flex: none; }
.topbar .name { font-weight: 800; font-size: 1.2rem; }
.pill { display: inline-flex; gap: 6px; align-items: center; background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 800; box-shadow: 0 3px 0 rgba(0,0,0,.08); }
.flame { color: #FF6B1A; }

.xpbar { height: 14px; background: #EFE7DA; border-radius: 999px; overflow: hidden; margin-top: 6px; }
.xpbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), #FF9F1C); border-radius: 999px; transition: width .6s; }

/* Karteikasten */
.kasten { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; align-items: end; margin: 10px 0 6px; }
.fach { position: relative; border-radius: 14px 14px 10px 10px; padding: 8px 4px 10px; color: #fff; text-align: center; min-height: 128px; display: flex; flex-direction: column; justify-content: flex-end; box-shadow: var(--shadow); }
.fach .stack { position: absolute; left: 10%; right: 10%; bottom: 58px; display: flex; flex-direction: column-reverse; align-items: center; }
.fach .stack i { display: block; width: 100%; height: 5px; background: #fff; border-radius: 2px; margin-top: 2px; opacity: .92; box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.fach b { font-size: 1.6rem; line-height: 1; }
.fach small { font-size: .72rem; opacity: .95; }
.fach .lbl { font-weight: 800; font-size: .85rem; }
.fach.active { outline: 4px solid var(--ink); outline-offset: 2px; }
.f1 { background: var(--b1); } .f2 { background: var(--b2); } .f3 { background: var(--b3); } .f4 { background: var(--b4); } .f5 { background: var(--b5); }
.kasten.mini .fach { min-height: 54px; padding: 4px; }
.kasten.mini .fach .stack { display: none; }
.kasten.mini .fach b { font-size: 1rem; }
.pop { animation: pop .5s; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }

.trophy { display: flex; align-items: center; gap: 12px; background: linear-gradient(135deg, #FFF3C4, #FFE08A); border-radius: var(--radius); padding: 12px 16px; font-weight: 800; box-shadow: var(--shadow); }
.trophy .t { font-size: 2rem; }

/* Lernkarte */
.progress { height: 10px; background: #EFE7DA; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); transition: width .3s; }
.stage { perspective: 1200px; margin: 18px 0; }
.flash { position: relative; height: 250px; transform-style: preserve-3d; transition: transform .55s cubic-bezier(.2,.8,.2,1); cursor: pointer; }
.flash.flipped { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: #fff; border-radius: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px; text-align: center; border-top: 12px solid var(--b1); }
.face.back { transform: rotateY(180deg); }
.face .lang { position: absolute; top: 10px; left: 16px; font-size: .75rem; font-weight: 800; letter-spacing: .08em; color: var(--muted); }
.face .word { font-size: clamp(1.6rem, 6vw, 2.5rem); font-weight: 800; word-break: break-word; }
.face .ex { margin-top: 10px; color: var(--muted); font-style: italic; }
.face .newtag { position: absolute; top: 10px; right: 14px; background: var(--gold); color: #3a2a00; font-weight: 800; font-size: .75rem; padding: 3px 8px; border-radius: 999px; }
.speak { background: #EAF4FA; color: var(--accent); box-shadow: none; padding: 6px 12px; min-height: 36px; margin-top: 12px; }
.fly-right { animation: flyR .6s forwards; }
.fly-left { animation: flyL .6s forwards; }
@keyframes flyR { to { transform: translateX(120%) rotate(12deg); opacity: 0; } }
@keyframes flyL { to { transform: translateX(-120%) rotate(-12deg); opacity: 0; } }
.shake { animation: shake .4s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.answer input { font-size: 1.4rem; text-align: center; font-weight: 700; }
.feedback { border-radius: 14px; padding: 12px 14px; font-weight: 700; margin-top: 10px; }
.feedback.ok { background: #E3F6EA; color: #1E6B3E; }
.feedback.bad { background: #FDE8E8; color: #8E2323; }
.feedback .sol { font-size: 1.3rem; }

/* PIN */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.profile { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 10px; text-align: center; cursor: pointer; border: 0; color: var(--ink); }
.profile .avatar { margin: 0 auto 8px; box-shadow: none; background: #FFF3E0; }
.pinpad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; justify-content: center; margin: 16px auto; }
.pinpad button { height: 72px; font-size: 1.6rem; border-radius: 50%; background: #fff; color: var(--ink); }
.pindots { display: flex; gap: 14px; justify-content: center; margin: 12px 0; }
.pindots i { width: 18px; height: 18px; border-radius: 50%; background: #E5DDD0; display: block; }
.pindots i.on { background: var(--accent); }

/* Eltern */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0; }
.tabs button { background: #fff; color: var(--ink); box-shadow: none; border: 2px solid var(--line); white-space: nowrap; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); }
td input { padding: 8px 10px; border-radius: 10px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button { background: #fff; box-shadow: none; border: 2px solid var(--line); font-size: 1.5rem; padding: 4px 8px; min-height: 44px; }
.emoji-pick button.on { border-color: var(--accent); background: #EAF4FA; }
.week { display: flex; gap: 6px; align-items: flex-end; height: 70px; }
.week div { flex: 1; background: var(--b3); border-radius: 6px 6px 2px 2px; min-height: 3px; position: relative; }
.week span { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-size: .72rem; color: var(--muted); }
.spinner { width: 42px; height: 42px; border: 5px solid #E5DDD0; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 700; transition: transform .3s; z-index: 50; max-width: calc(100% - 32px); }
#toast.show { transform: translateX(-50%) translateY(0); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; width: 100%; height: 100%; }

@media (max-width: 520px) {
  .fach { min-height: 110px; }
  .fach small { display: none; }
  .flash { height: 220px; }
  .table-scroll { overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
