* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Marker Felt', system-ui, -apple-system, sans-serif;
    background-color: #87CEEB;
    /* Sky blue */
    overflow: hidden;
    touch-action: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 24px;
    z-index: 1000;
    gap: 20px;
}

/* Loading Spinner */
.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#menu,
#game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0.8);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    z-index: 100;
    width: 450px;
    max-width: 90%;
    min-width: 300px;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: #FF6347;
    /* Tomato red */
    text-shadow: 2px 2px 0 #000;
}

h2 {
    font-size: 1.8rem;
    margin-bottom: 15px;
    color: #FF6347;
}

button {
    background-color: #4CAF50;
    /* Green */
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 1.2rem;
    margin: 10px 0;
    cursor: pointer;
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Marker Felt', system-ui, -apple-system, sans-serif;
    box-shadow: 3px 3px 0 #333;
    transition: all 0.2s;
}

button:hover {
    background-color: #45a049;
    transform: scale(1.05);
}

button:active {
    transform: scale(0.95);
    box-shadow: 1px 1px 0 #333;
}

#instructions {
    margin-top: 20px;
    text-align: center;
}

#score-display {
    position: absolute;
    top: 20px;
    right: 20px;
    background-color: rgba(255, 255, 255, 0.7);
    padding: 10px;
    border-radius: 5px;
    font-size: 1.2rem;
    font-weight: bold;
    z-index: 10;
}

#controls-container {
    position: absolute;
    bottom: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    z-index: 50;
}

@media (max-width: 768px) {

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    #menu,
    #game-over {
        width: 90%;
        min-width: 280px;
        max-width: 500px;
        padding: 15px;
        margin-bottom: 90px;
    }

    #menu h1 {
        font-size: 2.2rem;
    }

    #menu #instructions p {
        font-size: 1rem;
        margin-bottom: 12px;
    }

    #menu button {
        width: 100%;
        margin: 8px 0;
    }

    .touch-button {
        width: 80px;
        height: 80px;
        font-size: 24px;
    }

    .left-controls,
    .right-controls {
        bottom: 80px;
    }
}

.hidden {
    display: none !important;
}

#game-over {
    display: flex;
    flex-direction: column;
    width: 450px;
    min-width: 300px;
    max-width: 90vw;
    background: rgba(255, 255, 255, 0.95);
    border: 4px solid #FF6347;
    border-radius: 15px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.5s ease-out;
    overflow: hidden;
    padding-bottom: 15px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#game-over p {
    margin: 10px 0;
    font-size: 1.2rem;
}

#game-over-image {
    width: 100%;
    max-width: 120px;
    margin-bottom: 10px;
    border-bottom: 2px solid #ddd;
}

#score-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
}

#final-score {
    font-size: 2.5rem;
    font-weight: bold;
    color: #FF6347;
    text-shadow: 1px 1px 0 #000;
    display: inline-block;
    margin: 0 5px;
}

#high-score {
    font-size: 1.1rem;
    color: #4CAF50;
    margin-top: 5px;
}

#score-submission {
    margin: 15px 0;
}

.input-group {
    display: flex;
    margin-bottom: 10px;
    height: 42px;
}

.input-group input {
    flex: 1;
    padding: 0 12px;
    border: 2px solid #ccc;
    border-radius: 4px 0 0 4px;
    font-size: 16px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    text-transform: uppercase;
    height: 100%;
    box-sizing: border-box;
    line-height: 38px;
}

.input-group input:focus {
    outline: none;
    border-color: #4CAF50;
}

.input-group input.input-error {
    border-color: #f44336;
    background-color: #ffebee;
    animation: shake 0.5s;
}

.input-group button {
    padding: 0 15px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    font-size: 16px;
    height: 100%;
    box-sizing: border-box;
    line-height: 42px;
    vertical-align: middle;
    display: flex;
    align-items: center;
    justify-content: center;
}

#submit-score-btn {
    margin: 0;
}

.input-group button:hover {
    background-color: #45a049;
}

.input-group button:disabled {
    background-color: #cccccc;
    color: #888888;
    cursor: not-allowed;
    border: 1px solid #aaaaaa;
}

/* Tooltip style for button title */
.input-group button[title]:disabled {
    position: relative;
}

.input-group button[title]:disabled:hover::after {
    content: attr(title);
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 10px;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 10;
}

#submit-message {
    padding: 8px 12px;
    margin-top: 10px;
    border-radius: 4px;
    font-size: 14px;
}

#submit-message.error {
    background-color: #ffebee;
    color: #f44336;
    border: 1px solid #f44336;
}

#submit-message.success {
    background-color: #e8f5e9;
    color: #4CAF50;
    border: 1px solid #4CAF50;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }
}

#game-over-leaderboard {
    width: 90%;
    margin: 0 auto 15px auto;
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 8px;
    background-color: rgba(255, 255, 255, 0.8);
}

#game-over-leaderboard h3 {
    margin: 0 0 8px 0;
    font-size: 1.2rem;
    color: #4CAF50;
    text-align: center;
}

#quick-scores-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#quick-scores-list li {
    display: grid;
    grid-template-columns: 30px 1fr 60px;
    padding: 4px 0;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}

#quick-scores-list li:last-child {
    border-bottom: none;
}

#quick-scores-list li.current-player {
    background-color: rgba(255, 215, 0, 0.2);
    font-weight: bold;
}

.small-spinner {
    width: 20px;
    height: 20px;
    margin: 10px auto;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: #4CAF50;
    animation: spin 1s ease-in-out infinite;
    display: none;
}

.game-over-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 5px;
}

.small-text {
    font-size: 0.8rem;
    color: #666;
    margin-top: 5px;
}

/* Mobile Touch Controls */
.mobile-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 30%;
    max-height: 250px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
    padding-bottom: 60px;
    z-index: 50;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: auto;
    /* Enable clicks for the buttons */
}

/* Position the buttons in a staggered layout */
.left-controls {
    position: absolute;
    bottom: 90px;
    left: 20px;
    display: grid;
    grid-template-areas:
        "w"
        "q";
    grid-gap: 15px;
}

.right-controls {
    position: absolute;
    bottom: 90px;
    right: 20px;
    display: grid;
    grid-template-areas:
        "p"
        "o";
    grid-gap: 15px;
}

/* Position each button in its grid area */
#q-button {
    grid-area: q;
    margin-left: 20px;
    /* Offset to the right */
}

#w-button {
    grid-area: w;
    margin-left: 0;
}

#o-button {
    grid-area: o;
    margin-right: 20px;
    /* Offset to the left */
}

#p-button {
    grid-area: p;
    margin-right: 0;
    margin-left: 20px;
    /* Offset to the right from O button */
}

.touch-button {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
    color: #333;
    border: 3px solid rgba(0, 0, 0, 0.2);
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.touch-button.active {
    background-color: rgba(76, 175, 80, 0.7);
    transform: scale(0.95);
    color: white;
}

.touch-button.left-wing {
    background-color: rgba(33, 150, 243, 0.5);
}

.touch-button.right-wing {
    background-color: rgba(33, 150, 243, 0.5);
}

.touch-button.left-leg {
    background-color: rgba(255, 152, 0, 0.5);
}

.touch-button.right-leg {
    background-color: rgba(255, 152, 0, 0.5);
}

.touch-button.left-wing.active {
    background-color: rgba(33, 150, 243, 0.9);
}

.touch-button.right-wing.active {
    background-color: rgba(33, 150, 243, 0.9);
}

.touch-button.left-leg.active {
    background-color: rgba(255, 152, 0, 0.9);
}

.touch-button.right-leg.active {
    background-color: rgba(255, 152, 0, 0.9);
}

@media (orientation: landscape) {
    .mobile-controls {
        bottom: 10px;
    }

    .touch-button {
        width: 60px;
        height: 60px;
        font-size: 20px;
    }
}

/* Hide mobile controls on desktop */
@media (min-width: 1024px) {
    .mobile-controls {
        display: none;
    }
}

/* Hide the joystick zones since we're not using them anymore */
.joystick-zone {
    display: none;
}

/* Leaderboard Styles */
#leaderboard-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 10px;
    z-index: 200;
    width: 80%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    border: 3px solid #FF6347;
    animation: fadeIn 0.3s ease-out;
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #FFD54F;
}

.leaderboard-header h3 {
    margin: 0;
    font-size: 1.8rem;
    color: #FF6347;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.2);
}

#close-leaderboard {
    background: none;
    border: none;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #666;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    box-shadow: none;
    transition: all 0.2s;
}

#close-leaderboard:hover {
    color: #FF6347;
    background-color: rgba(255, 99, 71, 0.1);
}

#scores-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 60vh;
    overflow-y: auto;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.5);
    font-family: 'Courier New', monospace;
}

#scores-list li {
    display: grid;
    grid-template-columns: 40px 2fr 1fr auto;
    gap: 10px;
    padding: 12px 15px;
    border-bottom: 1px solid #ddd;
    align-items: center;
    transition: background-color 0.2s;
    font-family: 'Courier New', monospace;
    font-weight: bold;
}

#scores-list li:nth-child(odd) {
    background-color: rgba(76, 175, 80, 0.1);
}

#scores-list li:last-child {
    border-bottom: none;
}

#scores-list li.current-player {
    background-color: rgba(255, 213, 79, 0.3);
    font-weight: bold;
    border-left: 5px solid #FFD54F;
}

#scores-list li:hover {
    background-color: rgba(76, 175, 80, 0.2);
}

#scores-list li.current-player:hover {
    background-color: rgba(255, 213, 79, 0.4);
}

#scores-list li span:first-child {
    font-weight: bold;
    color: #4CAF50;
    text-align: center;
}

#scores-list li span:nth-child(2) {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#scores-list li span:nth-child(3) {
    font-weight: bold;
    color: #FF6347;
    text-align: right;
}

#scores-list li span.date {
    color: #777;
    font-size: 0.9em;
    text-align: right;
}

#scores-list li:nth-child(1) span:first-child,
#scores-list li:nth-child(2) span:first-child,
#scores-list li:nth-child(3) span:first-child {
    font-size: 1.2em;
}

#scores-list li:nth-child(1) {
    background-color: rgba(255, 215, 0, 0.2);
    border-left: 5px solid gold;
}

#scores-list li:nth-child(2) {
    background-color: rgba(192, 192, 192, 0.2);
    border-left: 5px solid silver;
}

#scores-list li:nth-child(3) {
    background-color: rgba(205, 127, 50, 0.2);
    border-left: 5px solid #cd7f32;
}

.small-spinner {
    width: 30px;
    height: 30px;
    margin: 10px auto;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: #4CAF50;
    animation: spin 1s ease-in-out infinite;
    display: none;
}

/* Button highlight for double spacebar feedback */
.button-highlight {
    transform: scale(1.1);
    background-color: #64DD17;
    box-shadow: 0 0 10px #64DD17;
    transition: all 0.2s ease;
}