/* Exploding Hamsters – Nachbau, eigenes Stylesheet.
   Farbwelt orientiert am Original (dunkles Violett, Gold-Akzente). */

@font-face {
    font-family: 'Fredoka';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('../assets/fonts/fredoka-latin.woff2') format('woff2');
}

:root {
    /* werden per JS an die Fenstergröße angepasst */
    --s: 1;        /* globaler Skalierungsfaktor   */
    --w: 78px;     /* Kantenlänge eines Feldes     */
    --pw: 58px;    /* Kantenlänge eines Stein-Tiles */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
    font-weight: 600;
}

html, body {
    height: 100%;
}

body {
    background: #2b1b54;
    color: #fff;
    text-align: center;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.container {
    max-width: calc(440px * var(--s));
    margin: 0 auto;
    padding: calc(25px * var(--s));
}

/* ── Kopfbereich ─────────────────────────────── */

.header {
    height: calc(110px * var(--s));
    margin-bottom: calc(28px * var(--s));
    display: flex;
    flex-direction: column;
}

.flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: calc(14px * var(--s));
}

#highscore {
    display: flex;
    align-items: center;
    color: #fbcc4c;
}

#highscore img {
    width: calc(44px * var(--s));
    height: calc(44px * var(--s));
}

#best {
    margin-left: 10px;
    color: #ffd83a;
    letter-spacing: 1.5px;
    font-size: var(--bestsize, 24px);
}

#restart-btn {
    width: calc(44px * var(--s));
    height: calc(44px * var(--s));
    border: 2px solid rgba(196, 127, 230, 0.55);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    color: #e8d6ff;
    font-size: calc(24px * var(--s));
    line-height: 1;
    cursor: pointer;
}

#restart-btn:active {
    transform: scale(0.92);
}

.score-area {
    position: relative;
    display: inline-block;
}

#score {
    position: relative;
    z-index: 1;
    color: #f4e1ff;
    letter-spacing: 2px;
    font-size: var(--scoresize, 40px);
    text-shadow: 0 3px 8px rgba(0, 0, 0, 0.55);
}

/* Flamme hinter dem Punktestand, solange ein Lauf aktiv ist */
.grace-dots {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, calc(-50% - 6px));
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.grace-dots.streak-active {
    opacity: 1;
}

.grace-dot {
    display: block;
    width: calc(100px * var(--s));
    height: calc(100px * var(--s));
    background: url('../assets/icons/fire.png') center/contain no-repeat;
}

.grace-dots.streak-active .grace-dot {
    animation: fire-flicker 0.8s ease-in-out infinite alternate;
    transform-origin: center bottom;
}

.grace-dots[data-grace="2"] .grace-dot { opacity: 0.7; }
.grace-dots[data-grace="1"] .grace-dot { opacity: 0.45; }

@keyframes fire-flicker {
    from { transform: scale(1); }
    to   { transform: scale(1.06); }
}

/* ── Spielfeld ───────────────────────────────── */

#board-wrapper {
    position: relative;
    width: fit-content;
    margin: 0 auto;
}

#board {
    width: calc(var(--w) * 5);
    border: 3px solid #3d2070;
    border-radius: 8px;
    background: #100828;
    padding: 1px;
    box-sizing: content-box;
    overflow: hidden;
}

.square {
    float: left;
    width: var(--w);
    aspect-ratio: 1 / 1;
    background-color: #1f1240;
    border: 1px solid #100828;
    border-radius: 5px;
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

.square.highlight {
    filter: brightness(150%);
}

/* Hamster-Typen (Spielfeld und Steine) */
.t0 { background-image: url('../assets/hamsters/1.png'); }
.t1 { background-image: url('../assets/hamsters/2.png'); }
.t2 { background-image: url('../assets/hamsters/3.png'); }
.t3 { background-image: url('../assets/hamsters/4.png'); }

/* ── Steine-Ablage ───────────────────────────── */

#pieces {
    display: grid;
    grid-template-columns: repeat(3, 33.33%);
    justify-items: center;
}

.piece {
    width: var(--pw);
    height: var(--pw);
    /* unsichtbarer Rand = größere Greiffläche */
    border-top: calc(80px * var(--s)) solid transparent;
    border-bottom: calc(80px * var(--s)) solid transparent;
    border-left: calc(30px * var(--s)) solid transparent;
    border-right: calc(30px * var(--s)) solid transparent;
    box-sizing: content-box;
    cursor: grab;
    position: relative;
    touch-action: none;
    transition: transform 0.15s ease-out;
}

.piece.horizontal {
    border-left-width: calc(80px * var(--s));
    border-right-width: calc(80px * var(--s));
    margin-left: calc(-1 * var(--pw));
}

.piece.vertical {
    margin-top: calc(var(--pw) / 2);
}

/* Senkrechte und einzelne Steine liegen über den breiten unsichtbaren
   Greifrändern der waagerechten Nachbarn, sonst schnappt man sich beim
   mittleren Stein versehentlich den rechten. */
.piece.vertical,
.piece.single {
    z-index: 2;
}

.piece.dragging {
    transition: none;
    cursor: grabbing;
    z-index: 999;
}

.piece.used {
    visibility: hidden;
    pointer-events: none;
}

.tile {
    width: 100%;
    aspect-ratio: 1 / 1;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    border-radius: 5px;
    position: relative;
}

.tile.second {
    position: absolute;
    display: none;
}

.piece.horizontal .tile.second {
    display: block;
    top: 0;
    left: 100%;
}

.piece.vertical .tile.second {
    display: block;
    top: -100%;
    left: 0;
}

.piece.appear {
    animation: piece-grow 0.3s ease-out backwards;
}

@keyframes piece-grow {
    0%   { transform: scale(0);    opacity: 0; }
    50%  { transform: scale(1.05); opacity: 0.8; }
    100% { transform: scale(1);    opacity: 1; }
}

/* ── Punkte-Einblendung ──────────────────────── */

#points {
    position: absolute;
    display: none;
    z-index: 9999;
    color: #fff;
    font-size: calc(36px * var(--s));
    line-height: 1.1;
    white-space: nowrap;
    pointer-events: none;
}

#points.streak,
#points.combo {
    font-size: calc(42px * var(--s));
}

#points.streak {
    color: #f4e1ff;
    text-shadow:
        -3px -3px 0 #6b3fc4, 0 -3px 0 #6b3fc4, 3px -3px 0 #6b3fc4,
        -3px  0   0 #6b3fc4,                   3px  0   0 #6b3fc4,
        -3px  3px 0 #6b3fc4, 0  3px 0 #6b3fc4, 3px  3px 0 #6b3fc4,
        0 5px 0 #2b1b54, 0 0 12px rgba(0, 0, 0, 0.85);
}

#points.combo {
    color: #ffd83a;
    text-shadow:
        -3px -3px 0 #ff4500, 0 -3px 0 #ff4500, 3px -3px 0 #ff4500,
        -3px  0   0 #ff4500,                   3px  0   0 #ff4500,
        -3px  3px 0 #ff4500, 0  3px 0 #ff4500, 3px  3px 0 #ff4500,
        0 5px 0 #6b1a00, 0 0 12px rgba(0, 0, 0, 0.85);
}

#points .streaknumber {
    margin-left: 6px;
    color: #ffd83a;
    font-size: calc(54px * var(--s));
}

#points.grow {
    animation: points-grow 0.25s steps(5, end) forwards;
}

#points.shrink {
    animation: points-shrink 0.18s steps(4, end) forwards;
}

@keyframes points-grow {
    0%   { transform: scale(0);    opacity: 0; }
    25%  { transform: scale(0.6);  opacity: 1; }
    50%  { transform: scale(1.3);  opacity: 1; }
    75%  { transform: scale(0.95); opacity: 1; }
    100% { transform: scale(1);    opacity: 1; }
}

@keyframes points-shrink {
    0%   { transform: scale(1);   opacity: 1; }
    50%  { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(0);   opacity: 0; }
}

/* ── Game Over ───────────────────────────────── */

#gameover {
    display: none;
    position: absolute;
    inset: -1px;
    z-index: 5;
    background: #000000bf;
    border-radius: 8px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#gameover.visible {
    display: flex;
    opacity: 1;
}

#gameover .message {
    font-size: calc(28px * var(--s));
}

#gameover-screen {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: #2b1b54;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#gameover-screen.visible {
    display: flex;
}

#gameover-screen h1 {
    font-size: 38px;
    margin-bottom: 40px;
    letter-spacing: 2px;
}

#go-normal,
#go-newbest {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#go-normal.hidden,
#go-newbest.hidden {
    display: none;
}

.go-label {
    font-size: 16px;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: #b794d4;
    margin-bottom: 6px;
}

.go-score {
    font-size: 52px;
    font-weight: 700;
    margin-bottom: 30px;
}

.go-best {
    font-size: 42px;
    font-weight: 700;
    color: #fbcc4c;
    text-shadow: 0 0 12px rgba(251, 204, 76, 0.4);
    margin-bottom: 40px;
}

.go-trophy {
    width: 100px;
    height: 100px;
    margin-bottom: 24px;
    animation: trophy-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

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

.go-newbest-label {
    font-size: 22px;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: #fbcc4c;
    margin-bottom: 16px;
    text-shadow: 0 0 12px rgba(251, 204, 76, 0.4);
}

.go-newbest-score {
    font-size: 64px;
    font-weight: 700;
    color: #fbcc4c;
    text-shadow: 0 0 20px rgba(251, 204, 76, 0.4);
    margin-bottom: 40px;
}

#go-restart {
    padding: 14px 40px;
    border-radius: 12px;
    border: 2px solid #ffd83a;
    background: linear-gradient(to bottom, #ffe066 0%, #ffb01f 55%, #ff7a1f 100%);
    color: #2b1b54;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.6px;
    cursor: pointer;
    transform: scale(0);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.55),
        inset 0 -3px 0 rgba(120, 40, 0, 0.25),
        0 5px 0 #6b1a00,
        0 8px 22px rgba(255, 120, 30, 0.45);
}

#go-restart.visible {
    transform: scale(1);
}

#go-restart:active {
    transform: translateY(3px) scale(0.98);
}
