@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&display=swap');

:root {
    --bg-1: #061322;
    --bg-2: #0b2540;
    --glass: rgba(10, 16, 28, 0.72);
    --border: rgba(255, 255, 255, 0.12);
    --text: #e2e8f0;
    --accent: #ffd54f;
    --accent-strong: #ffb02e;
    font-family: 'Space Grotesk', 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    margin: 0;
    overflow: hidden;
    color: var(--text);
    background: radial-gradient(circle at 15% 20%, rgba(255, 213, 79, 0.18), transparent 35%),
        radial-gradient(circle at 80% 0%, rgba(59, 130, 246, 0.16), transparent 42%),
        linear-gradient(135deg, var(--bg-1), var(--bg-2));
}

#game-container {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
}

.hud-tile,
#score,
#timer,
#home-button {
    position: fixed;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, 0.38), 0 0 18px rgba(255, 213, 79, 0.08);
    padding: 10px 14px;
    backdrop-filter: blur(12px);
    font-weight: 700;
    letter-spacing: 0.02em;
}

#score {
    top: 18px;
    left: 18px;
    font-size: 20px;
} 

#timer {
    top: 70px;
    left: 18px;
    font-size: 18px;
}

#home-button {
    position: fixed;
    top: 18px;
    right: 18px;
    font-size: 18px;
    background: var(--glass);
    padding: 10px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(12px);
}

#home-button a {
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    letter-spacing: 0.06em;
}

/* Countdown overlay */
#countdown-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 50%, rgba(6, 19, 34, 0.85), rgba(6, 19, 34, 0.95));
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#countdown {
    font-size: 150px;
    color: var(--accent);
    font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
    font-weight: 700;
    text-shadow: 3px 3px 5px rgba(0, 0, 0, 0.7);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* End game overlay */
#end-game-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 40%, rgba(6, 19, 34, 0.88), rgba(6, 19, 34, 0.96));
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#end-game-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

#end-game-message {
    padding: 40px;
    text-align: center;
    transform: translateY(20px);
    transition: transform 0.5s ease;
    max-width: 80%;
    background: linear-gradient(155deg, rgba(10, 16, 28, 0.95), rgba(17, 37, 66, 0.85));
    border-radius: 22px;
    border: 1px solid var(--border);
    box-shadow: 0 1.8rem 3.2rem rgba(0, 0, 0, 0.6);
}

#end-game-message h1 {
    font-size: 48px;
    margin-bottom: 20px;
    color: var(--accent);
    text-shadow: 0 6px 14px rgba(0, 0, 0, 0.6);
}

#end-game-message p {
    font-size: 32px;
    margin-bottom: 30px;
    color: var(--text);
    font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.55);
}

#new-game-button {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #0f172a;
    border: none;
    padding: 15px 30px;
    font-size: 24px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
    margin-top: 20px;
    display: block;
    width: 80%;
    margin-left: auto;
    margin-right: auto;
}

#new-game-button:hover {
    background-color: #ffef00;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(255, 215, 0, 1);
}

#name-input-container,
#scoreboard-container {
    margin-top: 14px;
}

#player-name {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    font-size: 16px;
}

#submit-score {
    width: 100%;
    padding: 12px 14px;
    margin-top: 10px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #38bdf8, #2563eb);
    color: #0b1324;
    font-weight: 700;
    cursor: pointer;
}

#scoreboard-list {
    list-style: none;
    padding: 0;
    margin: 10px 0 0 0;
    max-height: 220px;
    overflow-y: auto;
    text-align: left;
}

.score-item {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.score-rank {
    font-weight: 700;
    color: var(--accent);
}

.score-name {
    font-weight: 600;
}

.score-value {
    font-weight: 700;
}

.score-date {
    grid-column: 2 / span 2;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
}

.empty-score {
    padding: 12px;
    text-align: center;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
}

/* Optimize for mobile devices */
@media (max-width: 768px) {
    #game-container {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
    
    #score {
        font-size: 15px;
        padding: 10px 12px;
        top: 10px;
        left: 10px;
    }
    
    #timer {
        font-size: 15px;
        padding: 10px 12px;
        top: 56px;
        left: 10px;
    }
    
    #home-button {
        font-size: 14px;
        padding: 8px 12px;
        top: 10px;
        right: 10px;
    }
    
    #countdown {
        font-size: 100px;
    }
    
    #end-game-message {
        padding: 20px;
        width: 80%;
    }
    
    #end-game-message h1 {
        font-size: 32px;
    }
    
    #end-game-message p {
        font-size: 18px;
    }
    
    #new-game-button {
        padding: 10px 20px;
        font-size: 16px;
    }
}

/* Add hardware acceleration for smoother rendering */
canvas {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Prevent selection and improve touch handling */
body, #game-container, canvas {
    -webkit-touch-callout: none; /* Prevent callout to copy image, etc when tap to hold */
    -webkit-user-select: none;   /* Prevent text selection when tapping */
    -khtml-user-select: none;    /* Same for Konqueror */
    -moz-user-select: none;      /* Firefox */
    -ms-user-select: none;       /* Internet Explorer/Edge */
    user-select: none;           /* Non-prefixed version */
    touch-action: none;          /* Disable browser handling of all touch gestures */
    -webkit-tap-highlight-color: rgba(0,0,0,0); /* Remove tap highlight on mobile */
    overscroll-behavior: none;   /* Prevent pull-to-refresh and overscroll effects */
}

/* Lock the viewport to prevent scrolling */
html, body {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior-y: none; /* Prevent pull-to-refresh */
}

/* Scoreboard styles */
#name-input-container {
    margin: 20px 0;
}

#player-name {
    padding: 10px;
    font-size: 18px;
    border: 2px solid #ffd700;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.9);
    width: 70%;
    margin-bottom: 10px;
}

#submit-score {
    background-color: #ffd700;
    color: #000;
    border: none;
    padding: 10px 20px;
    font-size: 18px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    margin-top: 10px;
}

#submit-score:hover {
    background-color: #ffef00;
    transform: scale(1.05);
}

#scoreboard-container {
    margin: 20px 0;
    width: 100%;
}

#scoreboard-container h2 {
    color: #ffd700;
    font-size: 28px;
    margin-bottom: 15px;
    text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
}

#scoreboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 10px;
    border: 2px solid #ffd700;
    overflow: hidden;
}

.score-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 15px;
    border-bottom: 1px solid rgba(255, 215, 0, 0.3);
    color: white;
}

.score-item:last-child {
    border-bottom: none;
}

.score-rank {
    font-weight: bold;
    color: #ffd700;
    width: 10%;
}

.score-name {
    font-weight: bold;
    width: 40%;
    text-align: left;
}

.score-value {
    color: #ffd700;
    width: 30%;
    text-align: right;
}

.score-date {
    color: #aaa;
    font-size: 0.8em;
    width: 20%;
    text-align: right;
}

.empty-score {
    padding: 15px;
    text-align: center;
    color: #aaa;
    font-style: italic;
}

/* Mobile adjustments for scoreboard */
@media (max-width: 768px) {
    #player-name {
        width: 90%;
        font-size: 16px;
        padding: 8px;
    }
    
    #submit-score {
        font-size: 16px;
        padding: 8px 15px;
    }
    
    #scoreboard-container h2 {
        font-size: 22px;
    }
    
    .score-item {
        padding: 8px 10px;
        font-size: 14px;
    }
    
    .score-date {
        display: none; /* Hide date on mobile to save space */
    }
    
    .score-name {
        width: 50%;
    }
    
    .score-value {
        width: 40%;
    }
}
