/* 贪吃蛇游戏 - 极限美化CSS */
:root {
    --primary: #6C63FF;
    --secondary: #36D1DC;
    --accent: #FF6584;
    --dark: #121826;
    --darker: #0D1119;
    --light: #F8F9FA;
    --snake: #4ECDC4;
    --food: #FF6B6B;
    --grid: #1E2430;
    --success: #4CAF50;
    --warning: #FFC107;
    --danger: #F44336;
    --info: #2196F3;
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 15px 50px rgba(0, 0, 0, 0.25);
}

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

body {
    font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg,
            var(--darker) 0%,
            var(--dark) 50%,
            #1a1f2e 100%);
    color: var(--light);
    padding: 2rem;
    overflow-x: hidden;
    position: relative;
}

/* 背景装饰效果 */
body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 15% 85%,
            rgba(108, 99, 255, 0.15) 0%,
            transparent 50%),
        radial-gradient(circle at 85% 15%,
            rgba(54, 209, 220, 0.12) 0%,
            transparent 50%),
        radial-gradient(circle at 50% 50%,
            rgba(255, 101, 132, 0.08) 0%,
            transparent 70%);
    z-index: -1;
    animation: bgPulse 20s ease-in-out infinite alternate;
}

/* 游戏容器 */
#game {
    background: linear-gradient(145deg,
            rgba(30, 36, 48, 0.95) 0%,
            rgba(18, 24, 38, 0.95) 100%);
    display: grid;
    grid-template-columns: repeat(20, 1fr);
    grid-template-rows: repeat(20, 1fr);
    gap: 1px;
    width: 500px;
    height: 500px;
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.05);
    box-shadow:
        inset 0 0 30px rgba(0, 0, 0, 0.7),
        0 20px 50px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.03);
    position: relative;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

/* 网格线装饰 */
#game::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 25px 25px;
    pointer-events: none;
    z-index: 0;
}

/* 蛇身体样式 */
.snake {
    background: linear-gradient(135deg,
            var(--snake) 0%,
            #26a69a 100%);
    border-radius: 4px;
    box-shadow:
        0 0 10px rgba(78, 205, 196, 0.7),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    position: relative;
    z-index: 2;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    animation: snakeSegment 3s ease-in-out infinite;
}

/* 蛇头样式 */
.snake-head {
    background: linear-gradient(135deg,
            var(--secondary) 0%,
            #1de9b6 100%);
    border-radius: 6px;
    box-shadow:
        0 0 15px rgba(54, 209, 220, 0.9),
        0 0 30px rgba(54, 209, 220, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    position: relative;
    z-index: 3;
    animation: snakeHeadGlow 2s ease-in-out infinite alternate;
}

/* 蛇眼睛效果 */
.snake-head::before,
.snake-head::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

.snake-head::before {
    top: 30%;
    left: 30%;
}

.snake-head::after {
    top: 30%;
    right: 30%;
}

/* 食物样式 */
.food {
    background: linear-gradient(135deg,
            var(--food) 0%,
            #ff4757 100%);
    border-radius: 50%;
    box-shadow:
        0 0 20px rgba(255, 107, 107, 0.9),
        0 0 40px rgba(255, 107, 107, 0.5);
    position: relative;
    z-index: 2;
    animation:
        foodPulse 1.5s ease-in-out infinite alternate,
        foodRotate 10s linear infinite;
    transform-style: preserve-3d;
}

/* 食物光泽效果 */
.food::before {
    content: '';
    position: absolute;
    top: 20%;
    left: 20%;
    width: 20%;
    height: 20%;
    background: radial-gradient(circle at 30% 30%,
            rgba(255, 255, 255, 0.9) 0%,
            transparent 70%);
    border-radius: 50%;
    filter: blur(1px);
}

/* 空单元格样式 */
.empty {
    background: rgba(30, 36, 48, 0.6);
    position: relative;
    transition: background-color 0.3s ease;
}

.empty:hover {
    background: rgba(108, 99, 255, 0.1);
}

/* 控制面板 */
#control {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    padding: 1.5rem;
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    max-width: 500px;
    width: 100%;
}

/* 按钮通用样式 */
button {
    padding: 1rem 2rem;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    min-width: 160px;
}

/* 按钮图标 */
button i {
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}

/* 按钮悬停效果 */
button:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

button:hover i {
    transform: scale(1.2);
}

/* 按钮激活效果 */
button:active {
    transform: translateY(-1px);
}

/* 按钮波纹效果 */
button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255, 255, 255, 0.6);
    opacity: 0;
    border-radius: 100%;
    transform: scale(1, 1) translate(-50%);
    transform-origin: 50% 50%;
}

button:focus:not(:active)::after {
    animation: ripple 1s ease-out;
}

/* 启动AI按钮 */
#startAI {
    background: linear-gradient(135deg,
            var(--info) 0%,
            #1E88E5 100%);
    color: white;
    box-shadow:
        0 5px 15px rgba(33, 150, 243, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

#startAI:hover {
    background: linear-gradient(135deg,
            #2196F3 0%,
            #1976D2 100%);
    box-shadow:
        0 8px 25px rgba(33, 150, 243, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* 停止AI按钮 */
#stopAI {
    background: linear-gradient(135deg,
            var(--danger) 0%,
            #E53935 100%);
    color: white;
    box-shadow:
        0 5px 15px rgba(244, 67, 54, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

#stopAI:hover {
    background: linear-gradient(135deg,
            #F44336 0%,
            #D32F2F 100%);
    box-shadow:
        0 8px 25px rgba(244, 67, 54, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* 重置按钮 */
#reset {
    background: linear-gradient(135deg,
            var(--warning) 0%,
            #FFB300 100%);
    color: #333;
    box-shadow:
        0 5px 15px rgba(255, 193, 7, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

#reset:hover {
    background: linear-gradient(135deg,
            #FFC107 0%,
            #FFA000 100%);
    color: #222;
    box-shadow:
        0 8px 25px rgba(255, 193, 7, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* 状态显示 */
#status {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: linear-gradient(135deg,
            rgba(33, 150, 243, 0.1) 0%,
            rgba(33, 150, 243, 0.05) 100%);
    border-radius: 12px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-left: 4px solid var(--info);
    max-width: 500px;
    width: 100%;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    animation: statusPulse 3s ease-in-out infinite;
}

/* 状态图标 */
#status i {
    font-size: 1.5rem;
    color: var(--info);
    animation: iconFloat 3s ease-in-out infinite;
}

/* 游戏标题样式 */
.game-title {
    text-align: center;
    margin-bottom: 2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 1px;
    text-shadow: 0 5px 15px rgba(108, 99, 255, 0.2);
    position: relative;
}

.game-title::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 4px;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    border-radius: 2px;
}

/* 分数显示 */
.score-display {
    display: flex;
    gap: 2rem;
    margin: 1.5rem 0;
    justify-content: center;
}

.score-item {
    text-align: center;
    padding: 1rem 2rem;
    background: var(--glass-bg);
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    min-width: 120px;
}

.score-label {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--secondary);
    text-shadow: 0 0 10px rgba(54, 209, 220, 0.5);
    font-family: 'Courier New', monospace;
}

/* 动画定义 */
@keyframes foodPulse {
    0% {
        transform: scale(1);
        box-shadow:
            0 0 20px rgba(255, 107, 107, 0.9),
            0 0 40px rgba(255, 107, 107, 0.5);
    }

    100% {
        transform: scale(1.1);
        box-shadow:
            0 0 30px rgba(255, 107, 107, 1),
            0 0 60px rgba(255, 107, 107, 0.7);
    }
}

@keyframes foodRotate {
    0% {
        transform: rotateY(0deg);
    }

    100% {
        transform: rotateY(360deg);
    }
}

@keyframes snakeHeadGlow {
    0% {
        box-shadow:
            0 0 15px rgba(54, 209, 220, 0.9),
            0 0 30px rgba(54, 209, 220, 0.4),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }

    100% {
        box-shadow:
            0 0 25px rgba(54, 209, 220, 1),
            0 0 50px rgba(54, 209, 220, 0.6),
            inset 0 1px 0 rgba(255, 255, 255, 0.4);
    }
}

@keyframes snakeSegment {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

@keyframes bgPulse {
    0% {
        opacity: 0.5;
        transform: scale(1);
    }

    100% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

@keyframes ripple {
    0% {
        transform: scale(0, 0);
        opacity: 0.5;
    }

    20% {
        transform: scale(25, 25);
        opacity: 0.3;
    }

    100% {
        opacity: 0;
        transform: scale(40, 40);
    }
}

@keyframes statusPulse {

    0%,
    100% {
        box-shadow:
            0 0 0 0 rgba(33, 150, 243, 0.1),
            var(--shadow-sm);
    }

    50% {
        box-shadow:
            0 0 0 5px rgba(33, 150, 243, 0.1),
            var(--shadow-sm);
    }
}

@keyframes iconFloat {

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

    50% {
        transform: translateY(-5px);
    }
}

/* 游戏网格发光效果 */
#game::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg,
            transparent,
            rgba(108, 99, 255, 0.1),
            rgba(54, 209, 220, 0.1),
            transparent);
    border-radius: 18px;
    z-index: -1;
    animation: borderGlow 4s linear infinite;
    pointer-events: none;
}

@keyframes borderGlow {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

/* 响应式设计 */
@media (max-width: 768px) {
    #game {
        width: 90vw;
        height: 90vw;
        max-width: 400px;
        max-height: 400px;
    }

    #control {
        flex-direction: column;
        align-items: center;
    }

    button {
        width: 100%;
        max-width: 300px;
    }

    .game-title {
        font-size: 2rem;
    }

    .score-item {
        padding: 0.75rem 1rem;
        min-width: 100px;
    }

    .score-value {
        font-size: 1.5rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 1rem;
    }

    #game {
        width: 95vw;
        height: 95vw;
    }

    .game-title {
        font-size: 1.8rem;
    }

    #status {
        font-size: 0.9rem;
        padding: 1rem;
    }
}

/* 加载动画 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

body>* {
    animation: fadeIn 0.8s ease-out forwards;
}

/* 按钮组间距优化 */
#control button:nth-child(1) {
    animation-delay: 0.1s;
}

#control button:nth-child(2) {
    animation-delay: 0.2s;
}

#control button:nth-child(3) {
    animation-delay: 0.3s;
}

/* 键盘快捷键提示 */
.shortcut-hint {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.5);
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    display: none;
}

@media (min-width: 1024px) {
    .shortcut-hint {
        display: block;
    }
}

/* 游戏结束特效 */
.game-over {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {

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

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

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