@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* {
    margin: 0;
    padding: 0;
    color: white;
    font-family: 'Press Start 2P';
}

body {
    background-color: black;
    height: 100vh;
    display: grid;
    grid-template-columns: 1fr 80vh 1fr;
    grid-template-rows: auto;
    grid-template-areas: 
        "header header header"
        "lboard main score"
        "lboard main controls";
    align-items: center;
    justify-items: center;
}

header {
    grid-area: header;
    text-align: center;
}

/* ── Start screen overlay ── */
.startDiv {
    position: absolute;
    display: flex;
    height: 100vh;
    align-items: center;
    justify-content: center;
}

.startDiv div {
    background-color: #ccc;
    z-index: 100;
    cursor: pointer;
    border-radius: 20px;
    box-shadow: 4px 4px 4px #000;
    padding: 20px 30px;
    display: flex;
    height: 32px;
    align-items: center;
}

.startDiv h1 {
    text-shadow: 2px 2px 2px #000;
    font-size: 2em;
    text-decoration: none;
    margin-left: 10px;
    color: #222;
}

.startDiv img {
    height: 40px;
    width: 40px;
}

header h1 {
    font-size: 4em;
}

/* ── Main game grid ── */
main {
    grid-area: main;
    display: grid;
    grid-template-columns: repeat(10, 10%);
    grid-template-rows: repeat(10, 10%);
    width: 80vh;
    height: 80vh;
}

/* Each grid cell */
.block {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
}

/* ── Lives (top-right) ── */
.lives {
    position: absolute;
    top: 0;
    right: 0;
    height: auto;
    display: flex;
    align-items: center;
    margin: 0.5em;
}

.lives li {
    list-style: none;
    background-color: yellow;
    width: 2em;
    height: 2em;
    border-radius: 100%;
    margin: 5px;
}

.lives ul {
    display: flex;
}

/* ── Score & Leaderboard panels ── */
.score {
    grid-area: score;
}

.leaderboard {
    grid-area: lboard;
}

.leaderboard ol {
    margin-left: 2.5em;
    margin-top: 1em;
    text-align: left;
}

.leaderboard ol li {
    font-size: 0.85em;
    padding: 1em 0;
}

div {
    height: 100%;
    text-align: center;
}

div h1 {
    font-size: 1.25em;
    text-decoration: underline;
}

div p {
    margin: 0.5em;
    font-size: 2em;
}

/* ── Player (Pac-Man) ── */
.player-cell {
    display: flex;
    align-items: center;
    justify-content: center;
}

#pacman, .pacman {
    background-color: yellow;
    border-radius: 100%;
    position: relative;
    width: 85%;
    height: 85%;
    flex-shrink: 0;
}

/* ── Enemy ── */
.enemy {
    background-color: green;
    border-radius: 100%;
    height: 90%;
    width: 90%;
    position: relative;
}

/* ── Point (dot) ── */
.point {
    border-radius: 100%;
    background-color: white;
    height: 1vh;
    width: 1vh;
}

/* ── Wall ── */
.wall {
    background-color: blue;
    width: 100%;
    height: 100%;
}

/* ── Pac-Man mouth directions ── */
.up, .down, .left, .right {
    width: 100%;
    height: 100%;
    background-color: black;
    animation: mouth 1.25s infinite steps(1, end);
    position: absolute;
    top: 0;
    left: 0;
}

.mouth.up    { clip-path: polygon(0 0, 100% 0, 50% 50%); }
.mouth.down  { clip-path: polygon(0 100%, 100% 100%, 50% 50%); }
.mouth.left  { clip-path: polygon(0 0, 0 100%, 50% 50%); }
.mouth.right { clip-path: polygon(100% 0, 100% 100%, 50% 50%); }

@keyframes mouth {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* ── On-screen arrow buttons ── */
.controls {
    grid-area: controls;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    grid-template-areas: 
        ". upArrow ."
        "leftArrow . rightArrow"
        ". downArrow .";
    width: 25vh;
    height: 25vh;
}

button {
    background-color: rgb(10, 10, 10);
    border: 1px solid #444;
    cursor: pointer;
    font-size: 1.2em;
    transition: background-color 0.1s;
}

button:hover  { background-color: rgb(40, 40, 40); }
button:active { background-color: rgb(70, 70, 70); }

button:nth-child(1) { grid-area: leftArrow; }
button:nth-child(2) { grid-area: upArrow; }
button:nth-child(3) { grid-area: rightArrow; }
button:nth-child(4) { grid-area: downArrow; }

/* ── Player animations ── */
@keyframes deathAnimation {
    0%   { transform: scale(1);   }
    50%  { transform: scale(0.5); }
    100% { transform: scale(0);   }
}

@keyframes hitAnimation {
    0%, 100% { background-color: yellow; transform: scale(1);    }
    50%       { background-color: red;    transform: scale(0.75); }
}

.dead, #pacman.dead {
    animation: deathAnimation 1.5s ease-in-out forwards;
}

.hit, #pacman.hit {
    animation: hitAnimation 1.5s ease-in-out;
}

/* ── Power-up animations (injected by JS but also defined here for clarity) ── */
@keyframes powerupPulse {
    from { transform: scale(0.85); box-shadow: 0 0 6px 2px #ff0, 0 0 12px 4px #f80; }
    to   { transform: scale(1.05); box-shadow: 0 0 12px 5px #ff0, 0 0 24px 10px #f80; }
}

@keyframes enemyVulnerable {
    from { background-color: #00f; opacity: 1;   }
    to   { background-color: #88f; opacity: 0.7; }
}

/* ── Responsive (mobile) ── */
@media (max-width: 900px) {
    body {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        grid-template-areas:
            "header"
            "main"
            "score"
            "controls";
        height: auto;
    }

    main {
        width: 95vw;
        height: 95vw;
    }

    .leaderboard {
        display: none;
    }

    .controls {
        width: 40vw;
        height: 40vw;
    }
}
