:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --line: #e4e2dc;
  --text: #1b1c20;
  --muted: #6f707a;
  --accent: #f5a524;
  --accent-ink: #1b1c20;
  --accent2: #5b7cfa;
  --good: #22b26b;
  --bad: #ef4f4f;
  --pink: #e8559a;
  --tile: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .05);
  --r: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318; --card: #1b1e25; --line: #2a2e38; --text: #eceef2; --muted: #8b90a0;
    --tile: #232733; --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111318; --card: #1b1e25; --line: #2a2e38; --text: #eceef2; --muted: #8b90a0;
  --tile: #232733; --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  overscroll-behavior: none;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.grow { flex: 1; }
.row { display: flex; gap: 12px; align-items: center; }
.between { justify-content: space-between; }

/* ---------- Layout ---------- */
#app { min-height: 100%; }
.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: in .25s ease-out;
}
@keyframes in { from { opacity: 0; transform: translateY(8px); } }
/* Vollbild-Screens: fixed + inset 0 füllt in iOS-WebKit (auch Chrome) genau den sichtbaren Bereich,
   unabhängig davon, welche Höhe der Browser meldet. */
.home, .end, .game { position: fixed; inset: 0; overflow-y: auto; }
/* vertikal zentriert, bei zu wenig Platz aber oben beginnend und scrollbar */
.home > :first-child, .end > :first-child { margin-top: auto; }
.home > :last-child, .end > :last-child { margin-bottom: auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: var(--shadow);
}

.bar { display: flex; align-items: center; gap: 8px; }
.bar h1 { flex: 1; text-align: center; font-size: 1.15rem; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; background: none; font-size: 1.6rem; border-radius: 12px; cursor: pointer;
}
.icon-btn:active { background: var(--line); }

/* ---------- Buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; cursor: pointer;
  transition: transform .08s;
  box-shadow: var(--shadow);
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.danger { color: var(--bad); }
.btn.big { min-height: 68px; font-size: 1.35rem; border-radius: 20px; }
.btn.wide { width: 100%; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pink); display: inline-block; }

/* ---------- Home ---------- */
.logo { font-size: 3.2rem; font-weight: 800; letter-spacing: -.04em; text-align: center; }
.logo span { color: var(--accent); }
.greet { text-align: center; margin: -8px 0 6px; color: var(--muted); font-size: 1.1rem; }
.menu { display: grid; gap: 10px; }
.level { display: grid; gap: 8px; }
.xpbar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.xpbar i {
  display: block; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--pink));
  transition: width .7s cubic-bezier(.2, .8, .2, 1);
}

/* ---------- Rätsel-Liste ---------- */
.list { display: grid; gap: 10px; }
.puzzle { display: flex; align-items: center; gap: 14px; transition: transform .08s; }
.puzzle:active { transform: scale(.98); }
.puzzle.locked { opacity: .55; }
.puzzle.soon { border-style: dashed; box-shadow: none; }
.picon {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  background: var(--bg); font-size: 1.6rem; font-weight: 700;
}
.best { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.best small { display: block; font-weight: 400; color: var(--muted); font-size: .7rem; }

/* ---------- Highscore ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; }
.tab { padding: 8px 14px; border-radius: 99px; border: 1px solid var(--line); white-space: nowrap; }
.tab.on { background: var(--text); color: var(--bg); }
.scores { list-style: none; margin: 0; padding: 0; }
.scores li { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.scores li:last-child { border: 0; }
.scores small { display: block; font-size: .75rem; }
.scores b { font-variant-numeric: tabular-nums; }
.rank {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg); font-weight: 700; font-size: .9rem;
}
.top1 .rank { background: var(--accent); color: var(--accent-ink); }
.top2 .rank { background: #c9ccd4; color: #1b1c20; }
.top3 .rank { background: #d9a273; color: #1b1c20; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { text-align: center; padding: 12px; }
.stat b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }

/* ---------- Hilfe ---------- */
.prose h2 { font-size: 1.2rem; margin-bottom: 6px; }
.prose h3 { font-size: 1rem; margin: 14px 0 4px; }
.prose p { margin: 6px 0; }
.tools-help { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 10px; }
.tools-help li { display: flex; gap: 12px; align-items: flex-start; }
.tools-help li.locked { opacity: .55; }
.tool-ico {
  min-width: 40px; height: 40px; padding: 0 6px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800;
}

/* ---------- Einstellungen ---------- */
.setting { padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border: 0; }
.setting.col { display: grid; gap: 8px; }
input[type="text"] {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%;
}
input[type="text"]:focus { outline: 2px solid var(--accent); border-color: transparent; }
.switch {
  appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--line);
  position: relative; cursor: pointer; transition: background .2s; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s;
}
.switch:checked { background: var(--good); }
.switch:checked::after { transform: translateX(20px); }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); font-weight: 600; }

/* ---------- Spiel ---------- */
.game { gap: 10px; overflow: hidden; }
.hud { display: flex; align-items: center; gap: 10px; }
.timer { flex: 1; display: flex; align-items: center; gap: 10px; font-weight: 700; font-variant-numeric: tabular-nums; }
.timebar { flex: 1; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.timebar i { display: block; height: 100%; width: 100%; background: var(--accent2); transition: width .1s linear; }
.timer.low .timebar i { background: var(--bad); }
.timer.low span { color: var(--bad); animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.2); } }
.hud-score { min-width: 84px; text-align: right; }
.hud-score b { font-size: 1.6rem; font-variant-numeric: tabular-nums; display: inline-block; }
.hud-score small { display: block; font-size: .75rem; color: var(--muted); white-space: nowrap; }
.hud-score small b { font-size: inherit; color: var(--accent); }
.hud-score.bump b { animation: bump .25s; }
@keyframes bump { 50% { transform: scale(1.25); color: var(--accent); } }

.task { text-align: center; padding: 8px 0; }
.board { flex: 1; min-height: 0; display: grid; place-items: center; container-type: size; }
.board.shake { animation: shake .35s; }
@keyframes shake {
  20% { transform: translateX(-8px); } 40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(5px); }
}

.toolbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tool {
  display: grid; justify-items: center; gap: 4px; padding: 8px 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; cursor: pointer;
}
.tool small { font-size: .7rem; color: var(--muted); white-space: nowrap; }
.tool:active:not(:disabled) { transform: scale(.94); }
.tool:disabled { opacity: .45; cursor: default; }
.tool.locked .tool-ico { background: var(--line); }

/* Zielsumme */
.zs-target { font-size: clamp(3rem, 12vh, 4.5rem); font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.zs-sum { margin-top: 6px; min-height: 1.5em; font-variant-numeric: tabular-nums; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(100cqw, 100cqh); }
.tile {
  aspect-ratio: 1; border-radius: 18px; border: 2px solid var(--line); background: var(--tile);
  font-size: clamp(1.4rem, 8cqmin, 2.4rem); font-weight: 700; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .08s, background .12s, border-color .12s;
}
.tile:active { transform: scale(.94); }
.tile.sel { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.tile.ok { background: var(--good); border-color: var(--good); animation: okpop .28s; }
.tile.no { background: var(--bad); border-color: var(--bad); }
.tile.hint { border-color: var(--accent); animation: glow .8s infinite alternate; }
@keyframes okpop { 50% { transform: scale(1.1); } }
@keyframes glow { to { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 40%, transparent); } }

/* ---------- Ende ---------- */
.final {
  font-size: 5rem; font-weight: 800; text-align: center; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.03em;
}
.badge {
  align-self: center; padding: 6px 14px; border-radius: 99px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); animation: okpop .5s .3s both;
}
.badge.soft { background: var(--line); color: var(--text); }
.unlock { display: flex; gap: 14px; align-items: center; animation: unlock .5s cubic-bezier(.2, 1.6, .4, 1); border-color: var(--accent); }
@keyframes unlock { from { opacity: 0; transform: scale(.6); } }
#unlocks { display: grid; gap: 10px; }
#unlocks:empty { display: none; }

/* ---------- Effekte ---------- */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.pop {
  position: absolute; transform: translate(-50%, -50%); font-weight: 800; font-size: 1.4rem;
  color: var(--good); text-shadow: 0 2px 8px rgba(0, 0, 0, .15); animation: rise 1s ease-out forwards; white-space: nowrap;
}
.pop.big { font-size: 2rem; color: var(--accent); }
.pop.combo { font-size: 1.7rem; color: var(--pink); }
.pop.bad { color: var(--bad); }
@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(1); }
}
.confetti {
  position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(var(--rot)); } }
.toast {
  position: absolute; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 600;
  animation: in .2s; transition: opacity .4s;
}
.toast.out { opacity: 0; }

.modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, .45); animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }
.dialog { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.dialog p { margin: 0; }
.dialog .row > * { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
