:root {
    --ink: #2b2040;
    --bg1: #8fd3ff;
    --bg2: #c9b6ff;
    --card: #fffaf0;
    --c1: #ffd23f;
    --c2: #3bceac;
    --c3: #4d96ff;
    --c4: #ff9f43;
    --c5: #b388ff;
    --del: #ff4d6d;
    --font: "Fredoka", "Baloo 2", ui-rounded, "Arial Rounded MT Bold", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(circle at 15% 20%, rgba(255,255,255,.55) 0 60px, transparent 61px),
        radial-gradient(circle at 85% 80%, rgba(255,255,255,.45) 0 90px, transparent 91px),
        radial-gradient(circle at 80% 15%, rgba(255,255,255,.35) 0 40px, transparent 41px),
        linear-gradient(160deg, var(--bg1), var(--bg2));
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: background-color .3s;
}

body.good { background: linear-gradient(160deg, #8ef0a8, #3bceac); }
body.bad  { background: linear-gradient(160deg, #ff9aa8, #ff4d6d); }

.card {
    position: relative;
    width: 100%;
    max-width: 520px;
    background: var(--card);
    border: 5px solid var(--ink);
    border-radius: 32px;
    box-shadow: 10px 10px 0 var(--ink);
    padding: 44px 20px 28px;
    text-align: center;
}

.badge {
    position: absolute;
    top: -38px;
    left: 50%;
    transform: translateX(-50%) rotate(-12deg);
    width: 72px;
    height: 72px;
    display: grid;
    place-items: center;
    font-size: 40px;
    background: var(--c1);
    border: 5px solid var(--ink);
    border-radius: 50%;
    box-shadow: 4px 4px 0 var(--ink);
}

h1 {
    margin: 0 0 20px;
    font-size: clamp(1.4rem, 5.5vw, 2rem);
    line-height: 1.15;
}

/* --- Anzeige der Länge --- */
.slots {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
}

.slot {
    width: clamp(44px, 14vw, 64px);
    height: clamp(56px, 17vw, 76px);
    display: grid;
    place-items: center;
    font-size: clamp(1.8rem, 8vw, 2.6rem);
    font-weight: 700;
    color: #b7aecb;
    background: #fff;
    border: 4px solid var(--ink);
    border-radius: 16px;
    box-shadow: inset 0 -6px 0 #eee6ff;
}

.slot.filled {
    color: var(--ink);
    background: #fff3b0;
    box-shadow: inset 0 -6px 0 #ffe066;
}

.slot.pop { animation: pop .3s cubic-bezier(.3, 1.8, .5, 1); }

@keyframes pop {
    0%   { transform: scale(.4) rotate(-15deg); }
    100% { transform: scale(1) rotate(0); }
}

.message {
    min-height: 1.6em;
    margin: 10px 0 14px;
    font-size: 1.2rem;
    font-weight: 700;
}

/* --- Tastatur --- */
.keyboard {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.row {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.row:nth-child(2) { transform: translateX(12px); }
.row:nth-child(3) { transform: translateX(-8px); }

@media (max-width: 400px) {
    .row { gap: 7px; }
    .card { padding-left: 12px; padding-right: 12px; }
}

.key {
    --tilt: 0deg;
    width: clamp(48px, 14vw, 68px);
    height: clamp(48px, 14vw, 68px);
    font-family: inherit;
    font-size: clamp(1.4rem, 6vw, 2rem);
    font-weight: 700;
    color: var(--ink);
    border: 4px solid var(--ink);
    border-radius: 18px;
    box-shadow: 0 6px 0 var(--ink);
    transform: rotate(var(--tilt));
    cursor: pointer;
    transition: transform .08s, box-shadow .08s;
    touch-action: manipulation;
}

.key:hover  { transform: rotate(var(--tilt)) translateY(-2px) scale(1.05); }
.key:active { transform: rotate(var(--tilt)) translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.key:focus-visible { outline: 4px dashed var(--ink); outline-offset: 4px; }

.c1 { background: var(--c1); }
.c2 { background: var(--c2); }
.c3 { background: var(--c3); color: #fff; }
.c4 { background: var(--c4); }
.c5 { background: var(--c5); color: #fff; }

.key.delete {
    width: clamp(120px, 36vw, 170px);
    margin-top: 4px;
    --tilt: -2deg;
    background: var(--del);
    color: #fff;
    font-size: clamp(1.4rem, 6vw, 2rem);
}

/* --- Effekte --- */
.flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    z-index: 10;
}

.flash.red   { background: #ff1f3d; animation: flash 1s ease-out; }
.flash.green { background: #19d36b; animation: flash 1.4s ease-out; }

@keyframes flash {
    0%   { opacity: .75; }
    100% { opacity: 0; }
}

.card.shake { animation: shake .5s; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-18px) rotate(-2deg); }
    40% { transform: translateX(16px) rotate(2deg); }
    60% { transform: translateX(-10px); }
    80% { transform: translateX(8px); }
}

.card.win { animation: bounce .7s cubic-bezier(.3, 1.8, .5, 1); }
.card.win .slot.filled { background: #b9f6ca; box-shadow: inset 0 -6px 0 #69f0ae; }

@keyframes bounce {
    0%   { transform: scale(.9); }
    100% { transform: scale(1); }
}

.again {
    margin-top: 22px;
    padding: 12px 26px;
    font-family: inherit;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--ink);
    background: var(--c1);
    border: 4px solid var(--ink);
    border-radius: 999px;
    box-shadow: 0 6px 0 var(--ink);
    cursor: pointer;
}

.again:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }

.confetti {
    position: fixed;
    top: -20px;
    width: 12px;
    height: 18px;
    border: 2px solid var(--ink);
    border-radius: 3px;
    z-index: 20;
    pointer-events: none;
    animation: fall linear forwards;
}

@keyframes fall {
    to { transform: translate(var(--drift), 110vh) rotate(720deg); }
}

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