/* Add this at the top of your CSS file */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

body {
    margin: 0;
    padding: 0;
    background: url('scales-grey.webp');
    background-repeat: repeat;
    background-size: 200px 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

.back-link {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 50;
    font-family: 'Press Start 2P', cursive;
    font-size: 11px;
    color: #00ff00;
    text-decoration: none;
    border: 2px solid #00ff00;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 12px;
    text-shadow: 1px 1px 0 #000;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.3);
    transition: all 0.2s ease;
}
.back-link:hover {
    background: #00ff00;
    color: #000;
}

/* Game container and canvas styles */
.game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 70px 0 40px;
}

.canvas-container {
    position: relative;
    width: min(80vw, 80vh, 460px);
    height: min(80vw, 80vh, 460px);
    /* Capture swipes without the browser scrolling/zooming the page. */
    touch-action: none;
}

/* Background image styling */
.board-background {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    object-fit: contain;
    z-index: 0;
    opacity: 0.6;
    pointer-events: none;
}

canvas {
    position: relative;
    border: 2px solid #00ff00;
    z-index: 1;
    background: transparent;
    width: 100%;
    height: 100%;
    box-shadow: 0 0 18px rgba(0, 255, 0, 0.25);
}

/* Game over text styling */
.game-over {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 1000;
    width: 100%;
}

.game-over-text {
    font-family: 'Press Start 2P', cursive;
    color: #ff0000;
    font-size: 40px;
    text-transform: uppercase;
    letter-spacing: 4px;
    animation: textGlitch 0.5s infinite;
    text-shadow:
        4px 4px 0 #000,
        -4px -4px 0 #000,
        4px -4px 0 #000,
        -4px 4px 0 #000,
        0 0 8px #ff0000;
    margin-bottom: 16px;
}

.final-score {
    font-family: 'Press Start 2P', cursive;
    color: #00ff00;
    font-size: 14px;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 14px;
}

.name-entry {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 8px;
}
#nameInput {
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    background: #000;
    color: #00ff00;
    border: 2px solid #00ff00;
    padding: 8px;
    width: 150px;
    text-transform: uppercase;
    outline: none;
}
#nameInput::placeholder { color: rgba(0, 255, 0, 0.4); }
#submitScoreBtn {
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    background: #000;
    color: #00ff00;
    border: 2px solid #00ff00;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}
#submitScoreBtn:hover { background: #00ff00; color: #000; }
#submitScoreBtn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

.submit-msg {
    font-family: 'Press Start 2P', cursive;
    font-size: 9px;
    color: #00ff00;
    min-height: 12px;
    margin-bottom: 12px;
    text-shadow: 1px 1px 0 #000;
}

@keyframes textGlitch {
    0% {
        transform: translate(0);
        text-shadow: 4px 4px 0 #000, -4px -4px 0 #000, 0 0 8px #ff0000;
    }
    25% {
        transform: translate(-2px, 2px);
        text-shadow: -4px -4px 0 #000, 4px 4px 0 #000, 0 0 8px #ff0000;
        color: #ff3300;
    }
    50% {
        transform: translate(2px, -2px);
        text-shadow: 4px -4px 0 #000, -4px 4px 0 #000, 0 0 8px #ff0000;
        color: #ff0000;
    }
    75% {
        transform: translate(-2px, -2px);
        text-shadow: -4px 4px 0 #000, 4px -4px 0 #000, 0 0 8px #ff0000;
        color: #ff3300;
    }
    100% {
        transform: translate(0);
        text-shadow: 4px 4px 0 #000, -4px -4px 0 #000, 0 0 8px #ff0000;
        color: #ff0000;
    }
}

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

.restart-text {
    font-family: 'Press Start 2P', cursive;
    color: #00ff00;
    font-size: 12px;
    margin-top: 8px;
    text-shadow: 2px 2px 0 #000;
    animation: blink 1s infinite;
}

.score-container {
    display: flex;
    justify-content: space-between;
    width: min(80vw, 80vh, 460px);
    margin-bottom: 20px;
    font-family: 'Press Start 2P', cursive;
    color: #00ff00;
    font-size: 14px;
}

.instructions {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Press Start 2P', cursive;
    color: #00ff00;
    font-size: 14px;
    text-align: center;
    text-shadow: 2px 2px 0 #000;
    z-index: 2;
    /* Let taps fall through to the board so "tap to start" works. */
    pointer-events: none;
}

.restart-text { cursor: pointer; }

/* On-screen directional pad — hidden on desktop, shown on small screens. */
.dpad {
    display: none;
    margin-top: 18px;
    grid-template-columns: repeat(3, 58px);
    grid-template-rows: repeat(3, 58px);
    gap: 6px;
    justify-content: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
.dpad-btn {
    font-family: 'Press Start 2P', cursive;
    font-size: 16px;
    background: rgba(0, 0, 0, 0.7);
    color: #00ff00;
    border: 2px solid #00ff00;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.3);
    text-shadow: 1px 1px 0 #000;
    cursor: pointer;
    touch-action: none;
}
.dpad-btn:active { background: #00ff00; color: #000; }
.dpad .up    { grid-column: 2; grid-row: 1; }
.dpad .left  { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down  { grid-column: 2; grid-row: 3; }

@media (max-width: 560px) {
    .dpad { display: grid; }
}

h1 {
    font-family: 'Press Start 2P', cursive;
    color: #00ff00;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 20px;
    font-size: clamp(20px, 5vw, 32px);
}

/* Leaderboard */
.leaderboard {
    margin-top: 26px;
    width: min(80vw, 80vh, 460px);
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #00ff00;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.2);
    padding: 14px 16px;
}
.leaderboard-title {
    font-family: 'Press Start 2P', cursive;
    color: #00ff00;
    font-size: 12px;
    text-align: center;
    margin-bottom: 12px;
    text-shadow: 2px 2px 0 #000;
}
#leaderboardList {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: rank;
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    color: #00ff00;
}
#leaderboardList li {
    counter-increment: rank;
    display: flex;
    align-items: center;
    padding: 6px 4px;
    border-bottom: 1px dashed rgba(0, 255, 0, 0.2);
}
#leaderboardList li:last-child { border-bottom: none; }
#leaderboardList li::before {
    content: counter(rank) ".";
    width: 28px;
    color: rgba(0, 255, 0, 0.6);
}
#leaderboardList li .lb-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-transform: uppercase;
}
#leaderboardList li .lb-score { color: #fff; text-shadow: 0 0 6px #00ff00; }
#leaderboardList li.lb-empty {
    justify-content: center;
    color: rgba(0, 255, 0, 0.5);
}
#leaderboardList li.lb-empty::before { content: ""; width: 0; }

.music-controls {
    margin-top: 20px;
}

.music-controls button {
    font-family: 'Press Start 2P', cursive;
    background: #000;
    color: #00ff00;
    border: 2px solid #00ff00;
    padding: 10px;
    margin: 0 5px;
    cursor: pointer;
    text-shadow: 1px 1px 0 #000;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.3);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    font-size: 10px;
}

.music-controls button:hover {
    background: #00ff00;
    color: #000;
    box-shadow: 0 0 12px rgba(0, 255, 0, 0.5);
    transform: translateY(-2px);
}

.music-controls button:active {
    transform: translateY(1px);
}

.music-controls button[style*="opacity: 0.5"] {
    cursor: default;
    pointer-events: none;
    filter: grayscale(50%);
}
