:root {
  --bg: #17133a;
  --frame: #26215c;
  --frame-2: #3c3489;
  --line: #534ab7;
  --text: #eeedfe;
  --muted: #afa9ec;
  --dim: #7f77dd;
  --gold: #ef9f27;
  --gold-dark: #412402;
  --gold-light: #fac775;
  --red: #e24b4a;
  --green: #1d9e75;

  /* Fingerfarben */
  --pinky: #d4537e;
  --pinky-text: #fbeaf0;
  --ring: #d85a30;
  --ring-text: #faece7;
  --middle: #378add;
  --middle-text: #e6f1fb;
  --index: #1d9e75;
  --index-text: #e1f5ee;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: "Fredoka", system-ui, sans-serif;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }

.frame {
  position: relative;
  width: min(540px, calc(100vw - 32px));
  height: min(760px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  background: var(--frame);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.frame.shake { animation: shake .35s; }
@keyframes shake {
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

/* HUD */
.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  font-size: 16px;
}
.badge { background: var(--line); border-radius: 999px; padding: 4px 14px; }
.score { font-family: "JetBrains Mono", monospace; font-size: 24px; }
.score.bump { animation: bump .25s; }
@keyframes bump { 50% { transform: scale(1.25); color: var(--gold-light); } }
.lives { color: #f09595; font-size: 22px; letter-spacing: 2px; }
.hud-right { display: flex; align-items: center; gap: 12px; }
.pause-btn {
  background: var(--frame-2); color: var(--muted); border: none;
  border-radius: 8px; width: 32px; height: 32px; font-size: 12px;
}
.pause-btn:hover { color: var(--text); }

.tempo { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--muted); }
.tempo-range { width: 160px; accent-color: var(--gold); }
.tempo-val { font-family: "JetBrains Mono", monospace; font-size: 14px; min-width: 52px; text-align: right; color: var(--text); }
.lives .lost { opacity: .25; }

/* Spielfeld */
.field { position: relative; flex: 1; overflow: hidden; }
.ground {
  position: absolute; left: 0; right: 0; bottom: 0; height: 8px;
  background: var(--red); opacity: .75;
}
.ground.hit { animation: ground .4s; }
@keyframes ground { 50% { opacity: 1; height: 16px; } }

.block {
  position: absolute; top: 0; left: 0;
  width: 46px; height: 46px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-family: "JetBrains Mono", monospace; font-size: 24px;
  border-bottom: 5px solid rgba(0, 0, 0, .25);
  will-change: transform;
}
.block.new { outline: 3px solid var(--gold-light); outline-offset: 2px; }
.block .wobble { display: inline-block; animation: wobble 1.6s ease-in-out infinite; }
@keyframes wobble { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }

.f-pinky  { background: var(--pinky);  color: var(--pinky-text); }
.f-ring   { background: var(--ring);   color: var(--ring-text); }
.f-middle { background: var(--middle); color: var(--middle-text); }
.f-index  { background: var(--index);  color: var(--index-text); }

.pop { animation: pop .35s ease-out forwards; }
@keyframes pop { to { transform: var(--pos) scale(1.9); opacity: 0; } }
.splat { animation: splat .5s ease-out forwards; }
@keyframes splat { to { transform: var(--pos) scaleY(.2) scaleX(1.8); opacity: 0; } }

.particle {
  position: absolute; width: 9px; height: 9px; border-radius: 3px;
  animation: fly .6s ease-out forwards;
}
@keyframes fly { to { transform: translate(var(--dx), var(--dy)) rotate(240deg); opacity: 0; } }

.points {
  position: absolute; font-size: 18px; font-weight: 600; color: var(--gold-light);
  pointer-events: none; animation: rise .8s ease-out forwards;
}
@keyframes rise { to { transform: translateY(-40px); opacity: 0; } }

.combo {
  position: absolute; top: 6px; left: 0; right: 0; text-align: center;
  font-size: 15px; color: var(--gold-light); opacity: 0; transition: opacity .2s;
}
.combo.show { opacity: 1; }

.banner {
  position: absolute; top: 34%; left: 50%;
  transform: translate(-50%, -50%) scale(.6);
  background: var(--frame-2); border: 2px solid var(--gold); border-radius: 16px;
  padding: 14px 26px; text-align: center; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 5; white-space: nowrap;
}
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.banner .lvl { font-size: 30px; font-weight: 600; color: var(--gold-light); }
.banner .neu { font-size: 16px; color: var(--muted); margin-top: 4px; }
.banner .neu b { font-family: "JetBrains Mono", monospace; color: var(--text); margin: 0 3px; }

/* Wörter-Modus */
.word {
  position: absolute; top: 0; left: 0;
  padding: 8px 14px; border-radius: 11px; white-space: pre;
  font-family: "JetBrains Mono", monospace; font-size: 20px;
  border-bottom: 5px solid rgba(0, 0, 0, .25);
  will-change: transform;
}
.word.new { outline: 3px solid var(--gold-light); outline-offset: 2px; }
.word .done { background: var(--gold-light); color: var(--gold-dark); border-radius: 4px; }

.typebar {
  display: flex; align-items: center; gap: 10px;
  margin: 8px 14px 0; padding: 8px 14px; min-height: 46px;
  background: var(--frame-2); border-radius: 12px;
  font-family: "JetBrains Mono", monospace; font-size: 20px;
}
.typebar #typed { flex: 1; white-space: pre; overflow: hidden; }
.typebar.off #typed { color: #f09595; }
.typebar.shake { animation: shake .35s; }
.typebar .enter { font-family: "Fredoka", sans-serif; font-size: 13px; color: var(--dim); }
.caret {
  display: inline-block; width: 2px; height: 1.1em; margin: 0 -1px;
  background: var(--gold); vertical-align: -3px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.modes { display: flex; gap: 4px; padding: 4px; background: rgba(0, 0, 0, .2); border-radius: 999px; }
.mode { border: none; border-radius: 999px; padding: 6px 18px; background: transparent; color: var(--muted); font-size: 15px; }
.mode.on { background: var(--line); color: var(--text); }
.rank-mode { font-size: 16px; font-weight: 400; color: var(--muted); }

/* Tastatur */
.keyboard {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 8px 16px; background: rgba(0, 0, 0, .15);
}
.krow { display: flex; gap: 4px; }
.key {
  position: relative;
  width: 30px; height: 30px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: "JetBrains Mono", monospace; font-size: 13px;
  background: var(--frame-2); color: var(--dim);
  transition: transform .08s;
}
.key.f-pinky  { background: var(--pinky);  color: var(--pinky-text); }
.key.f-ring   { background: var(--ring);   color: var(--ring-text); }
.key.f-middle { background: var(--middle); color: var(--middle-text); }
.key.f-index  { background: var(--index);  color: var(--index-text); }
.key.wide { width: 56px; font-family: "Fredoka", sans-serif; font-size: 12px; }
.key.home::after {
  content: ""; position: absolute; bottom: 4px; width: 9px; height: 2px;
  border-radius: 1px; background: currentColor;
}
.key.press { transform: scale(.85); filter: brightness(1.4); }
.key.wrong { background: var(--red); color: #fff; }

/* Bildschirme */
.screen {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center;
  background: rgba(38, 33, 92, .94);
}
.hidden { display: none !important; }

.logo { display: flex; gap: 6px; }
.logo .block { position: static; width: 54px; height: 54px; font-size: 30px; animation: bob 2.4s ease-in-out infinite; }
.logo .block:nth-child(2) { animation-delay: .3s; }
.logo .block:nth-child(3) { animation-delay: .6s; }
.logo .block:nth-child(4) { animation-delay: .9s; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
.logo-sub { font-size: 38px; font-weight: 600; letter-spacing: 8px; margin-top: -6px; }
.tagline { color: var(--muted); margin: 0; font-size: 16px; }
.hint { color: var(--dim); font-size: 14px; margin: 4px 0 0; max-width: 360px; }
.hint b { color: var(--muted); font-weight: 600; }
.big { font-size: 44px; font-weight: 600; }

.btn {
  border: none; border-radius: 999px; padding: 12px 26px;
  font-size: 18px; font-weight: 600;
  border-bottom: 4px solid rgba(0, 0, 0, .25);
  transition: transform .1s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px); }
.btn-gold { background: var(--gold); color: var(--gold-dark); }
.btn-green { background: var(--green); color: var(--index-text); padding: 10px 18px; }
.btn-violet { background: var(--line); color: var(--text); }
.link { background: none; border: none; color: var(--dim); font-size: 15px; }
.link:hover { color: var(--text); }

.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 5px; vertical-align: -1px; }

.over-title { color: #f09595; font-size: 20px; }
.final { font-family: "JetBrains Mono", monospace; font-size: 60px; color: var(--gold-light); }
.newrank { background: var(--frame-2); color: var(--gold-light); border-radius: 12px; padding: 8px 16px; }
.name-row { display: flex; gap: 8px; margin-top: 6px; }
.name-row input {
  width: 200px; border: none; border-radius: 10px; padding: 10px 14px;
  font-family: inherit; font-size: 18px; background: var(--text); color: var(--frame);
  outline: none;
}
.name-row input:focus { box-shadow: 0 0 0 3px var(--gold); }
.error { color: #f09595; font-size: 14px; margin: 0; }

.rank-title { font-size: 26px; font-weight: 600; }
.ranking { list-style: none; padding: 0; margin: 4px 0; width: min(360px, 100%); display: flex; flex-direction: column; gap: 5px; }
.ranking li {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center;
  padding: 7px 12px; border-radius: 10px; color: var(--muted); text-align: left;
}
.ranking li:nth-child(-n+3) { background: var(--frame-2); color: var(--text); }
.ranking li.me { background: var(--gold); color: var(--gold-dark); animation: bump .5s; }
.ranking .pos { font-weight: 600; }
.ranking .val { font-family: "JetBrains Mono", monospace; font-size: 14px; }
.ranking .empty { justify-content: center; display: flex; color: var(--dim); }
.rank-buttons { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }

.mute {
  position: fixed; right: 14px; bottom: 14px;
  background: var(--frame-2); color: var(--muted); border: none;
  border-radius: 999px; padding: 6px 14px; font-size: 13px;
}
