:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --text: #2b2d42;
  --muted: #7a7e96;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --primary-soft: #eef0fe;
  --line: #e6e8f2;
  --ok: #22c55e;
  --ok-soft: #e8f9ef;
  --bad: #ef4444;
  --bad-soft: #fdeeee;
  --gold: #f59e0b;
  --gold-soft: #fdf3df;
  --shadow: 0 6px 24px rgba(43, 45, 66, 0.08);
  --radius: 18px;
  --radius-sm: 12px;
  --nav-h: 66px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

[data-theme="rosa"] {
  --primary: #ec4899;
  --primary-2: #f472b6;
  --primary-soft: #fdeef6;
}
[data-theme="meer"] {
  --primary: #0ea5e9;
  --primary-2: #38bdf8;
  --primary-soft: #e6f7fe;
}
[data-theme="wiese"] {
  --primary: #10b981;
  --primary-2: #34d399;
  --primary-soft: #e7faf3;
}
[data-theme="sonne"] {
  --primary: #f59e0b;
  --primary-2: #fbbf24;
  --primary-soft: #fdf3df;
}

[data-dark="1"] {
  --bg: #14151f;
  --surface: #1e2030;
  --text: #e8e9f2;
  --muted: #9aa0bd;
  --line: #2c2f45;
  --primary-soft: #2a2c48;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
}

body { padding-bottom: calc(var(--nav-h) + var(--safe-b)); }

#app { max-width: 520px; margin: 0 auto; }

#screen { padding: 16px 16px 24px; animation: fadeIn .25s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; }

/* ---------- Top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border-radius: 0 0 20px 20px;
  box-shadow: var(--shadow);
}
#topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 800; flex: 1; }
#topbar .chip {
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,.22); border-radius: 999px;
  padding: 4px 10px; font-size: .8rem; font-weight: 700;
}
#topbar .icon-btn {
  background: rgba(255,255,255,.22); border: 0; color: #fff;
  border-radius: 999px; width: 36px; height: 36px; font-size: 1rem;
  display: grid; place-items: center;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.row { display: flex; align-items: center; gap: 12px; }
.col { flex: 1; min-width: 0; }
.left { text-align: left; }
.center { text-align: center; }
.muted { color: var(--muted); font-size: .85rem; }
.big { font-size: 1.4rem; font-weight: 800; }
h2 { margin: 0 0 10px; font-size: 1.15rem; }
h3 { margin: 4px 0; font-size: 1rem; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; border-radius: 999px; font-weight: 700; font-size: 1rem;
  padding: 13px 22px; color: #fff; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; transition: transform .1s ease, opacity .15s;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.btn-ok { background: linear-gradient(135deg, #10b981, #34d399); }
.btn-ghost { background: var(--primary-soft); color: var(--primary); }
.btn-block { display: flex; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.icon-btn-sm {
  border: 0; background: var(--primary-soft); color: var(--primary);
  border-radius: 10px; width: 38px; height: 38px; font-size: 1rem; flex: none;
}

/* ---------- Big learn button ---------- */
.learn-cta {
  width: 100%; padding: 26px; border-radius: 24px; border: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-size: 1.4rem; font-weight: 800; display: flex;
  flex-direction: column; align-items: center; gap: 8px; box-shadow: var(--shadow);
}
.learn-cta:active { transform: scale(.98); }
.learn-cta small { font-size: .85rem; font-weight: 600; opacity: .85; }

/* ---------- Stats blocks ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-box { background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 12px 8px; text-align: center; }
.stat-box .val { font-size: 1.35rem; font-weight: 800; }
.stat-box .lbl { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; }
.stat-box.gold { background: var(--gold-soft); }
.stat-box.fire { background: linear-gradient(135deg, #fff7ed, #ffedd5); color: #c2410c; }
.stat-box.fire .val { color: #ea580c; }

/* ---------- Rank / progress ---------- */
.rank-hero { display: flex; align-items: center; gap: 14px; }
.rank-avatar {
  width: 64px; height: 64px; border-radius: 20px; font-size: 2rem;
  background: var(--primary-soft); display: grid; place-items: center; flex: none;
}
.rank-title { font-weight: 800; font-size: 1.15rem; }
.bar { background: var(--primary-soft); border-radius: 999px; height: 12px; overflow: hidden; margin: 8px 0 4px; }
.bar > div { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .4s ease; }

/* ---------- Chips / filters ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font-size: .85rem; font-weight: 600; white-space: nowrap;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Words list ---------- */
.word-item { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.word-item:last-child { border-bottom: 0; }
.word-pair { min-width: 0; flex: 1; }
.word-en { color: var(--muted); font-size: .9rem; }
.level-pill {
  font-size: .72rem; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap;
}
.level-new { background: var(--primary-soft); color: var(--primary); }
.level-grow { background: #fff7ed; color: #ea580c; }
.level-master { background: var(--gold-soft); color: #b45309; }

/* ---------- Modals ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(20,21,31,.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface); width: 100%; max-width: 520px;
  border-radius: 24px 24px 0 0; padding: 20px 18px calc(18px + var(--safe-b)); animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; }

/* ---------- Learn mode ---------- */
.learn-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--line); }
.learn-dot.done { background: var(--primary); }
.learn-card {
  background: linear-gradient(145deg, var(--surface), var(--primary-soft));
  border-radius: 24px; box-shadow: var(--shadow); padding: 28px 20px; text-align: center; margin-top: 10px;
}
.dir-label { display: inline-block; font-size: .78rem; font-weight: 700; color: var(--primary); background: var(--primary-soft); border-radius: 999px; padding: 5px 12px; margin-bottom: 14px; }
.learn-prompt { font-size: 2.1rem; font-weight: 800; word-break: break-word; }
.learn-input {
  width: 100%; text-align: center; font-size: 1.35rem; font-weight: 700;
  padding: 16px; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); margin: 18px 0 12px;
  box-sizing: border-box;
}
.learn-input:focus { outline: none; border-color: var(--primary); }
.learn-feedback {
  border-radius: var(--radius-sm); padding: 12px 14px; font-weight: 700; margin-top: 12px; display: none;
}
.feedback-ok { background: var(--ok-soft); color: #15803d; display: inline-block !important; animation: pop .25s ease; }
.feedback-bad { background: var(--bad-soft); color: #b91c1c; display: inline-block !important; animation: shake .3s ease; }
@keyframes pop { 0% { transform: scale(.8); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.combo-flame { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; color: #ea580c; font-size: 1rem; }

.hint-row { display: flex; gap: 10px; margin-top: 8px; }
.hint-row .btn { flex: 1; }

/* ---------- Summary ---------- */
.summary-score { font-size: 2.4rem; font-weight: 800; margin: 6px 0; }
.summary-emoji { font-size: 3rem; }
.sum-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.sum-row { display: flex; justify-content: space-between; align-items: center; font-size: .95rem; }
.sum-row .lbl { color: var(--muted); }

/* ---------- Badges ---------- */
.badge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.badge-card {
  background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 14px 12px; text-align: center;
}
.badge-card.locked { opacity: .45; filter: grayscale(1); }
.badge-ico { font-size: 2.1rem; }
.badge-title { font-weight: 700; font-size: .88rem; margin-top: 6px; }
.badge-desc { font-size: .74rem; color: var(--muted); margin-top: 3px; }

/* ---------- Shop ---------- */
.shop-balance {
  background: var(--gold-soft); border-radius: var(--radius-sm); padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; font-weight: 800; margin-bottom: 16px;
}
.shop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.item-card {
  background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 16px 14px; text-align: center; display: flex; flex-direction: column; gap: 6px;
}
.item-ico { font-size: 2.2rem; }
.item-title { font-weight: 700; font-size: .92rem; }
.item-desc { font-size: .74rem; color: var(--muted); min-height: 28px; }
.item-cost { font-weight: 800; color: var(--gold); }
.shop-grid .btn { font-size: .85rem; padding: 10px 8px; width: 100%; }
.owned-mark { color: var(--ok); font-weight: 800; }

/* ---------- Nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around; align-items: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); height: calc(var(--nav-h) + var(--safe-b));
  max-width: 520px; margin: 0 auto;
}
.nav-btn {
  background: none; border: 0; color: var(--muted); display: flex;
  flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; font-weight: 600;
  padding: 8px 12px; border-radius: 14px; min-width: 62px;
}
.nav-btn.active { color: var(--primary); }
.nav-ico { font-size: 1.4rem; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 60; width: min(90%, 480px); }
.toast {
  background: #22242e; color: #fff; padding: 13px 18px; border-radius: 14px;
  font-weight: 600; margin-bottom: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.3);
  animation: slideDown .25s ease; display: flex; align-items: center; gap: 10px;
}
.toast.ok { background: #15803d; }
.toast.bad { background: #b91c1c; }
.toast.gold { background: linear-gradient(135deg, #b45309, #d97706); }
@keyframes slideDown { from { transform: translateY(-16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Achievement popup ---------- */
.ach-popup {
  text-align: center; padding: 8px 0;
}
.ach-popup .ico { font-size: 3rem; animation: pop .4s ease; }
.ach-popup .t { font-size: 1.2rem; font-weight: 800; margin-top: 6px; }

/* ---------- Confetti ---------- */
#confetti-root { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti-piece { position: absolute; width: 9px; height: 14px; top: -20px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- Admin ---------- */
.admin { max-width: 1000px; }
.admin .nav-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.admin .nav-tabs button.active { background: var(--primary); color: #fff; }
.admin table { border-collapse: collapse; width: 100%; font-size: .85rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.admin th, .admin td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.admin th { background: var(--primary-soft); font-weight: 700; white-space: nowrap; }
.admin tr:hover td { background: var(--primary-soft); }
.admin input, .admin select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }
.admin .mini-btn { padding: 5px 10px; border: 0; border-radius: 8px; font-weight: 600; font-size: .78rem; }
.admin .mini-btn.danger { background: var(--bad-soft); color: #b91c1c; }
.admin .mini-btn.warn { background: #fff7ed; color: #c2410c; }
.admin .mini-btn.ok { background: var(--ok-soft); color: #15803d; }
.admin .stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.admin .stat-c { background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 12px; }
.admin .stat-c .h { font-size: .72rem; color: var(--muted); text-transform: uppercase; }
.admin .stat-c .v { font-size: 1.25rem; font-weight: 800; }
.admin .toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.admin .toolbar input[type=text] { flex: 1; min-width: 180px; }

@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 24px; }
  .badge-grid, .shop-grid { grid-template-columns: repeat(4, 1fr); }
  #screen { padding: 20px 24px 32px; }
}