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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    color: #fff;
}

.game-container {
    max-width: 800px;
    width: 100%;
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.header {
    text-align: center;
    margin-bottom: 15px;
}

.header h1 {
    font-size: 3em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    animation: slideDown 0.6s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.score-board {
    display: flex;
    justify-content: center;
    gap: 40px;
    flex-wrap: wrap;
}

.score {
    background: rgba(255, 255, 255, 0.2);
    padding: 15px 30px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    animation: popIn 0.4s ease-out;
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.score .label {
    display: block;
    font-size: 0.9em;
    opacity: 0.9;
    margin-bottom: 5px;
}

.score .value {
    display: block;
    font-size: 2em;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.game-board-container {
    position: relative;
    margin: 0 auto 15px;
    width: fit-content;
    animation: scaleIn 0.5s ease-out;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

#gameCanvas {
    background: #1a1a2e;
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3),
        0 0 0 2px rgba(255, 255, 255, 0.1);
    display: block;
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.game-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.overlay-content {
    text-align: center;
    padding: 40px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.overlay-content h2 {
    font-size: 2.5em;
    margin-bottom: 20px;
    color: #ffd700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.overlay-content p {
    font-size: 1.2em;
    margin-bottom: 25px;
    opacity: 0.9;
}

.controls {
    text-align: center;
    margin-bottom: 10px;
}

.control-group {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 30px;
    font-size: 1em;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.btn-secondary:active {
    transform: translateY(0);
}

.control-hints {
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    max-width: 400px;
    margin: 0 auto;
}

.control-hints p {
    margin: 5px 0;
    font-size: 0.95em;
}

/* Mobile controls are handled in media query */

@media (max-width: 768px) {
    .header {
        margin-bottom: 10px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
    }

    .header h1 {
        font-size: 1.5em;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .score-board {
        gap: 8px;
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .score {
        padding: 6px 12px;
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
    }

    .score .label {
        margin-bottom: 0;
        font-size: 0.75em;
    }

    .score .value {
        font-size: 1.1em;
    }

    #gameCanvas {
        width: 90vw;
        height: 90vw;
        max-width: 600px;
        max-height: 600px;
    }

    /* 在移动端隐藏操作说明和控制按钮 */
    .control-hints {
        display: none;
    }

    .control-group {
        display: none;
    }

    .mobile-controls {
        display: flex;
        position: fixed;
        bottom: 20px;
        left: 0;
        width: 100%;
        justify-content: center;
        z-index: 1000;
        pointer-events: none;
        /* Allow clicks to pass through container */
    }

    .d-pad {
        pointer-events: auto;
        /* Enable clicks on d-pad */
        background: rgba(255, 255, 255, 0.1);
        padding: 12px;
        border-radius: 20px;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        display: grid;
        grid-template-columns: repeat(3, 60px);
        grid-template-rows: repeat(3, 60px);
        column-gap: 5px;
        row-gap: 2px;
    }

    .d-pad-row {
        display: contents;
        /* 让子元素直接参与grid布局 */
    }

    /* 游戏手柄式布局 */
    .d-pad-btn[data-direction="up"] {
        grid-column: 2;
        grid-row: 1;
    }

    .d-pad-btn[data-direction="left"] {
        grid-column: 1;
        grid-row: 2;
    }

    .d-pad-btn[data-direction="right"] {
        grid-column: 3;
        grid-row: 2;
    }

    .d-pad-btn[data-direction="down"] {
        grid-column: 2;
        grid-row: 3;
    }

    .d-pad-btn {
        width: 60px;
        height: 60px;
        font-size: 24px;
        background: rgba(255, 255, 255, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 12px;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.1s ease;
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
    }

    .d-pad-btn:active {
        background: rgba(255, 255, 255, 0.4);
        transform: scale(0.95);
    }

    .control-group {
        gap: 10px;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5em;
    }

    .score-board {
        gap: 10px;
    }

    .score {
        padding: 8px 15px;
    }

    .score .value {
        font-size: 1.2em;
    }

    .overlay-content {
        padding: 20px;
    }

    .overlay-content h2 {
        font-size: 1.8em;
    }

    .overlay-content p {
        font-size: 1em;
    }
}