:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --text: #171a2c;
  --muted: #646a85;
  --border: #dfe2ee;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-soft: #e8e7fd;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #f59e0b;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 6px 20px rgba(20, 24, 50, .07);
  --radius: 16px;
  --nav-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120;
    --surface: #181b2e;
    --surface-2: #22263d;
    --text: #eceefb;
    --muted: #9aa0bf;
    --border: #2d3250;
    --primary: #818cf8;
    --primary-2: #a78bfa;
    --primary-soft: #2a2b55;
    --ok: #4ade80;
    --ok-soft: #12351f;
    --bad: #f87171;
    --bad-soft: #3d1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
button, input, select { font: inherit; color: inherit; }
img { display: block; }

/* ---------- Kopf & Navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 800; font-size: 1.2rem; letter-spacing: -.01em; }
.tabs { display: none; gap: 4px; }
.tabs a, .bottomnav a { text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a { padding: 8px 14px; border-radius: 999px; }
.tabs a.active { background: var(--primary-soft); color: var(--primary); }
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: .75rem; gap: 2px; }
.bottomnav .ico { font-size: 1.25rem; line-height: 1; }
.bottomnav a.active { color: var(--primary); }
@media (min-width: 760px) {
  body { padding-bottom: 32px; }
  .tabs { display: flex; }
  .bottomnav { display: none; }
}

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 32px; outline: none; }
h1 { font-size: 1.7rem; margin: 4px 0 8px; letter-spacing: -.02em; }
h2 { font-size: 1.2rem; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ---------- Bausteine ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 20px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); font-weight: 650; cursor: pointer; text-decoration: none; color: var(--text);
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border-color: transparent; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:focus-visible, .choice:focus-visible, .chip:focus-visible, .tile:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.flag-img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .08), 0 2px 8px rgba(0, 0, 0, .08);
}

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; flex-wrap: wrap; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 600; font-size: .9rem; cursor: pointer; color: var(--text);
}
.chip[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Start ---------- */
.hero {
  border-radius: 24px; padding: 28px 22px; color: #fff;
  background:
    radial-gradient(circle at 85% 15%, rgba(255,255,255,.22), transparent 40%),
    linear-gradient(135deg, #4f46e5, #7c3aed 55%, #db2777);
  box-shadow: var(--shadow);
  overflow: hidden; position: relative;
}
.hero h1 { font-size: 2rem; margin: 0 0 6px; }
.hero p { margin: 0 0 18px; opacity: .92; max-width: 34ch; }
.hero .btn { background: #fff; color: #3b2fc9; border: none; }
.hero .btn.ghost { background: rgba(255,255,255,.16); color: #fff; }
.hero-flags { display: flex; gap: 8px; margin-bottom: 18px; }
.hero-flags img { width: 54px; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.25); transform: rotate(var(--r, 0deg)); }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: 1fr; margin-top: 18px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.feature { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--text); }
.feature strong { font-size: 1.1rem; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.4rem; }
.stat span { font-size: .78rem; color: var(--muted); }

/* ---------- Quiz-Einstellungen ---------- */
.setup { display: grid; gap: 18px; max-width: 640px; margin: 0 auto; }
.field-label { font-weight: 700; margin-bottom: 8px; display: block; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg button { border: none; background: transparent; padding: 10px 6px; border-radius: 9px; font-weight: 650; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.hint { font-size: .85rem; color: var(--muted); margin-top: 6px; }
.highscore { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: 12px; background: var(--primary-soft); color: var(--text); }

/* ---------- Quiz ---------- */
.quiz { max-width: 640px; margin: 0 auto; }
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 700; font-size: .9rem; }
.pill.streak.hot { background: #fff4e0; border-color: #fcd34d; color: #92400e; }
@media (prefers-color-scheme: dark) { .pill.streak.hot { background: #3b2a0a; border-color: #92400e; color: #fcd34d; } }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .3s ease; }
.question-flag { max-width: 420px; margin: 0 auto 18px; }
.question-flag .flag-img { border-radius: 12px; }
.question-name { text-align: center; font-size: 1.7rem; font-weight: 800; margin: 10px 0 18px; letter-spacing: -.01em; }
.question-prompt { text-align: center; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.choices { display: grid; gap: 10px; }
.choices.flags { grid-template-columns: 1fr 1fr; }
.choice {
  position: relative;
  min-height: 56px; padding: 12px 16px;
  border: 2px solid var(--border); border-radius: 14px;
  background: var(--surface); text-align: left; font-weight: 650; font-size: 1.02rem;
  cursor: pointer; color: var(--text);
  display: flex; align-items: center; gap: 12px;
  transition: border-color .15s, background .15s, transform .08s;
}
.choice:hover:not(:disabled) { border-color: var(--primary); }
.choice:active:not(:disabled) { transform: scale(.985); }
.choice .key { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); font-size: .8rem; color: var(--muted); }
.choices.flags .choice { padding: 8px; flex-direction: column; }
.choices.flags .choice { gap: 6px; }
.choices.flags .choice .key { order: 2; width: 22px; height: 22px; font-size: .75rem; }
.choices.flags .choice .cap { order: 3; text-align: center; }
.choice:disabled { cursor: default; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.dim { opacity: .55; }
.choice .cap { font-size: .85rem; font-weight: 600; }
.feedback {
  margin-top: 16px; padding: 14px 16px; border-radius: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  animation: pop .2s ease;
}
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback p { margin: 0; font-weight: 700; }
.feedback p span { display: block; font-weight: 500; color: var(--text); font-size: .92rem; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.shake { animation: shake .3s ease; }

.result { text-align: center; max-width: 560px; margin: 0 auto; }
.score-ring { width: 160px; height: 160px; margin: 10px auto 14px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--surface-2) 0); }
.score-ring > div { width: 128px; height: 128px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; }
.score-ring b { font-size: 2rem; display: block; line-height: 1; }
.badge-new { display: inline-block; padding: 4px 12px; border-radius: 999px; background: #fef3c7; color: #92400e; font-weight: 800; margin-bottom: 8px; }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 18px 0; }
.mini-list { display: grid; gap: 8px; text-align: left; }
.mini-item { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); cursor: pointer; width: 100%; text-align: left; }
.mini-item img { width: 48px; flex: 0 0 auto; }
.mini-item .grow { flex: 1; min-width: 0; }
.mini-item .grow b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Lexikon ---------- */
.toolbar { display: grid; gap: 10px; margin-bottom: 16px; position: sticky; top: 61px; z-index: 5; background: var(--bg); padding: 8px 0; }
.search { position: relative; }
.search input {
  width: 100%; height: 48px; padding: 0 16px 0 42px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  font-size: 1rem;
}
.search input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.search::before { content: "⌕"; position: absolute; left: 14px; top: 50%; transform: translateY(-52%); font-size: 1.3rem; color: var(--muted); }
.toolbar-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.toolbar select { height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--primary); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
@media (max-width: 380px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 8px 8px 10px;
  cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 8px;
  transition: transform .12s ease, box-shadow .12s ease;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.tile .name { font-weight: 650; font-size: .92rem; line-height: 1.25; padding: 0 2px; }
.tile .sub { font-size: .76rem; color: var(--muted); padding: 0 2px; margin-top: -6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.count { font-size: .85rem; color: var(--muted); }
.tag { display: inline-block; font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); margin-left: 4px; vertical-align: middle; }

/* ---------- Detail-Dialog ---------- */
dialog.sheet {
  border: none; padding: 0; color: var(--text); background: var(--surface);
  width: min(520px, 100vw); max-width: 100vw; max-height: 92vh;
  border-radius: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog.sheet::backdrop { background: rgba(10, 12, 30, .55); backdrop-filter: blur(3px); }
@media (max-width: 600px) {
  dialog.sheet { margin: auto 0 0; width: 100vw; border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  dialog.sheet[open] { animation: slideup .22s ease; }
}
@keyframes slideup { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.detail { padding: 20px; }
.detail .flag-img { border-radius: 12px; }
.detail h2 { font-size: 1.6rem; margin: 16px 0 4px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 20px; }
.fact { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.fact span { display: block; font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.fact b { font-size: 1rem; }
.detail-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.close-x { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; border-radius: 50%; border: none; background: rgba(0,0,0,.55); color: #fff; font-size: 1.2rem; cursor: pointer; }

/* ---------- Statistik ---------- */
.stats-list { display: grid; gap: 8px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.bar > div { height: 100%; background: var(--bad); }
.hs-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.hs-table td, .hs-table th { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.hs-table th { color: var(--muted); font-weight: 600; font-size: .8rem; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 50; box-shadow: var(--shadow); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
