*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    font-family: 'Vazirmatn', sans-serif;
    color: #1f1f1f;
    background-color: #e9edf3;
    --img-sky-1: url('../img/sky-texture-1.svg');
    --img-sky-2: url('../img/sky-texture-2.svg');
    --img-sky-3: url('../img/sky-texture-3.svg');
    --img-sky-4: url('../img/sky-texture-4.svg');
    --img-sky-5: url('../img/sky-texture-5.svg');
    --img-ground: url('../img/ground-grid.svg');
    --img-shell-1: url('../img/ground-shell-1.svg');
    --img-shell-2: url('../img/ground-shell-2.svg');
    --img-dino-down: url('../img/dino-foot-down.svg');
    --img-dino-up: url('../img/dino-foot-up.svg');
    --img-dino-hit: url('../img/dino-hit.svg');
    --img-tree-single: url('../img/tree-single.svg');
    --img-tree-double: url('../img/tree-double.svg');
    --img-tree-triple: url('../img/tree-triple.svg');
    --img-enemy: url('../img/enemy-noz.svg');
}

body {
    margin: 0;
    min-height: 100vh;
    background-color: #e9edf3;
    overflow: hidden;
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: clamp(0.75rem, 2vw, 1.5rem);
    width: 100%;
}

.hero {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: min(1100px, calc(100% - 2rem));
}

.panel {
    background: white;
    border-radius: 18px;
    padding: clamp(0.9rem, 2vw, 1.25rem);
    box-shadow: 0 15px 40px rgba(31, 31, 31, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.85rem;
    width: 100%;
    text-align: left;
}

.brand span {
    display: block;
    font-weight: 600;
    font-size: 1.3rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand__logo {
    width: clamp(130px, 16vw, 200px);
    height: auto;
    display: block;
}

.brand small {
    color: #6b7280;
}

.stats {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.stats .label {
    display: block;
    color: #6b7280;
    font-size: 0.9rem;
}

.stats strong {
    font-size: 1.5rem;
    font-weight: 600;
}

.messages {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    gap: 0.5rem;
    flex-direction: column;
}

.messages__item {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.95rem;
}

.messages__item--success {
    background: rgba(22, 163, 74, 0.1);
    color: #15803d;
}

.messages__item--error {
    background: rgba(220, 38, 38, 0.1);
    color: #b91c1c;
}

.game-card {
    background: white;
    border-radius: 20px;
    padding: clamp(0.9rem, 2vw, 1.25rem);
    box-shadow: 0 18px 45px rgba(31, 31, 31, 0.05);
    width: 100%;
}

.status {
    background: #eff6ff;
    color: #1d4ed8;
    padding: 0.75rem 1rem;
    border-radius: 14px;
    margin-bottom: 1rem;
    text-align: center;
    font-weight: 600;
}

.status.status--danger {
    background: rgba(239, 68, 68, 0.12);
    color: #b91c1c;
}

.status.status--success {
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
}

.game-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.score span {
    color: #6b7280;
    font-size: 0.9rem;
}

.score strong {
    display: block;
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: 0.2rem;
}

.game-area {
    position: relative;
    height: clamp(220px, 38vh, 360px);
    overflow: hidden;
    border-radius: 18px;
    background: linear-gradient(180deg, #d1e8ff 0%, #fff 60%);
    border: 1px solid #e5e7eb;
}

/* --- بهبود: اضافه کردن صفحه "بازی تمام شد" --- */
.game-area::after {
    content: 'بازی تمام شد\A\Aبرای شروع مجدد کلیک کنید';
    position: absolute;
    inset: 0;
    background: rgba(31, 41, 55, 0.7);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.6;
    white-space: pre-wrap; /* To respect the newline character \A */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    z-index: 10;
}

.game-card.game-over .game-area::after {
    opacity: 1;
    pointer-events: auto;
}

.game-card.game-over .dino,
.game-card.game-over .cactus {
    filter: blur(3px); /* Blur game elements when game is over */
}

.sky {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 70%;
    background:
        var(--img-sky-5) 0 20% / 90px auto repeat,
        var(--img-sky-4) 60px 35% / 150px auto repeat,
        var(--img-sky-3) 120px 50% / 180px auto repeat,
        var(--img-sky-2) 0 65% / 220px auto repeat,
        var(--img-sky-1) 200px 80% / 250px auto repeat,
        linear-gradient(180deg, #dff1ff 0%, #f7fbff 100%);
    animation: pan 50s linear infinite;
}

.ground {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30%;
    background:
        var(--img-ground) 0 0 / 480px auto repeat-x,
        #f4f1ec;
    border-top: 2px solid #d1c7b7;
    animation: pan 8s linear infinite;
}

.ground::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 0;
    width: 100%;
    height: 6px;
    opacity: 0.35;
    background: repeating-linear-gradient(
            90deg,
            rgba(49, 46, 43, 0.4) 0,
            rgba(49, 46, 43, 0.4) 40px,
            transparent 40px,
            transparent 80px
    );
}

.ground::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background:
        var(--img-shell-1) 15% 50% / 80px 80px no-repeat,
        var(--img-shell-2) 82% 60% / 90px 90px no-repeat;
    opacity: 0.25;
    animation: shellFloat 12s linear infinite;
    pointer-events: none;
}

.dino {
    position: absolute;
    bottom: 18px;
    left: 40px;
    width: 80px;
    height: 90px;
    background: var(--img-dino-down) center/contain no-repeat;
    transition: transform 0.18s ease-out;
    filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.25));
}

/* --- بهبود: انیمیشن پرش --- */
.dino:not(.is-running):not(.is-crashed) {
    background-image: var(--img-dino-up); /* Static pose for jumping */
}

.dino.is-running {
    animation: dinoRun 0.4s steps(1) infinite;
}

.dino.is-crashed {
    animation: none;
    background-image: var(--img-dino-hit);
}

.cactus {
    position: absolute;
    left: 100%;
    bottom: 18px;
    width: 60px;
    height: 95px;
    background: var(--img-tree-single) center/contain no-repeat;
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.25));
    z-index: 3;
}

.cactus.obstacle--tree-double {
    width: 95px;
    height: 120px;
    background-image: var(--img-tree-double);
}

.cactus.obstacle--tree-triple {
    width: 115px;
    height: 135px;
    background-image: var(--img-tree-triple);
}

.cactus.obstacle--enemy {
    width: 80px;
    height: 85px;
    bottom: 24px;
    background-image: var(--img-enemy);
}

.controls {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

button {
    cursor: pointer;
    border: none;
    border-radius: 14px;
    padding: 0.85rem 1.6rem;
    font-size: 1rem;
    font-weight: 600;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button#startButton {
    background: #1d4ed8;
    color: white;
    box-shadow: 0 18px 35px rgba(29, 78, 216, 0.3);
}

button.primary {
    width: 100%;
    background: #059669;
    color: white;
    margin-top: 1rem;
    box-shadow: 0 14px 25px rgba(5, 150, 105, 0.3);
}

button:active {
    transform: scale(0.97);
}

@keyframes pan {
    from {
        background-position: 0;
    }
    to {
        background-position: -400px;
    }
}

@keyframes dinoRun {
    0% {
        background-image: var(--img-dino-down);
    }
    50% {
        background-image: var(--img-dino-up);
    }
    100% {
        background-image: var(--img-dino-down);
    }
}

@keyframes shellFloat {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-60px);
    }
}
