* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Arial Rounded MT Bold', sans-serif;
}

/* 竖屏提示 */
.portrait-hint {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    text-align: center;
}

@media screen and (orientation: portrait) {
    .portrait-hint {
        display: flex;
    }
}

.hint-content {
    color: #fff;
    padding: 20px;
}

.rotate-icon {
    font-size: 100px;
    margin-bottom: 20px;
    animation: bounce 1s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: rotate(-90deg) translateY(0); }
    50% { transform: rotate(-90deg) translateY(-20px); }
}

.hint-content p {
    font-size: 24px;
    margin: 10px 0;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

/* 屏幕容器 */
.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen.hidden {
    display: none;
}

/* ========== 儿童风格首页 ========== */
#mode-selection {
    background: linear-gradient(180deg, #FFE5B4 0%, #FFCCE5 30%, #E5CCFF 60%, #CCE5FF 100%);
    position: relative;
    overflow: hidden;
}

/* 装饰元素 */
.decoration {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.float-emoji {
    position: absolute;
    font-size: 40px;
    animation: float 3s ease-in-out infinite;
    opacity: 0.6;
}

.float-emoji:nth-child(1) { top: 10%; left: 10%; animation-delay: 0s; }
.float-emoji:nth-child(2) { top: 20%; right: 15%; animation-delay: 0.5s; }
.float-emoji:nth-child(3) { bottom: 30%; left: 8%; animation-delay: 1s; }
.float-emoji:nth-child(4) { bottom: 20%; right: 10%; animation-delay: 1.5s; }
.float-emoji:nth-child(5) { top: 50%; left: 5%; animation-delay: 2s; }

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(10deg); }
}

/* Logo区域 */
.logo-area {
    text-align: center;
    margin-bottom: 30px;
    z-index: 1;
}

.snake-icon {
    font-size: 80px;
    margin-bottom: 10px;
    animation: wiggle 2s ease-in-out infinite;
    display: inline-block;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(-5deg); }
    50% { transform: rotate(5deg); }
}

#mode-selection h1 {
    font-size: 48px;
    margin-bottom: 10px;
    background: linear-gradient(45deg, #FF6B9D, #4ECDC4, #FFE66D, #FF6B9D);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: rainbow 3s ease infinite;
    text-shadow: none;
    font-weight: bold;
    letter-spacing: 2px;
}

@keyframes rainbow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.subtitle {
    font-size: 24px;
    color: #666;
    font-weight: bold;
}

/* 模式按钮 */
.mode-buttons {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
    z-index: 1;
}

.mode-btn {
    padding: 20px 30px;
    border: none;
    border-radius: 20px;
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    box-shadow: 0 6px 0 rgba(0,0,0,0.2), 0 8px 20px rgba(0,0,0,0.3);
    position: relative;
    top: 0;
}

.mode-btn:active {
    top: 6px;
    box-shadow: 0 0 0 rgba(0,0,0,0.2), 0 2px 10px rgba(0,0,0,0.3);
}

.mode-btn.easy {
    background: linear-gradient(135deg, #56ab2f, #a8e063);
}

.mode-btn.normal {
    background: linear-gradient(135deg, #f093fb, #f5576c);
}

.mode-btn.hard {
    background: linear-gradient(135deg, #fa709a, #fee140);
}

.btn-emoji {
    font-size: 32px;
}

.mode-name {
    font-size: 22px;
}

/* 高分区域 */
.high-score-area {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    padding: 15px 30px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1;
}

.trophy {
    font-size: 32px;
}

.high-score-text {
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* 全屏按钮 */
.fullscreen-btn {
    margin-top: 20px;
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(135deg, #4ECDC4, #44A08D);
    cursor: pointer;
    box-shadow: 0 4px 0 #2E8B7B, 0 6px 15px rgba(0,0,0,0.2);
    transition: all 0.2s;
    position: relative;
    top: 0;
    z-index: 10;
}

.fullscreen-btn:active {
    top: 4px;
    box-shadow: 0 0 0 #2E8B7B, 0 2px 10px rgba(0,0,0,0.2);
}

/* ========== 游戏界面 ========== */
#game-screen {
    background: linear-gradient(180deg, #E3F2FD 0%, #BBDEFB 50%, #90CAF9 100%);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    margin: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    width: calc(100% - 20px);
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #333;
}

.info-item .label {
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 2px;
}

.info-item .value {
    font-size: 18px;
    font-weight: bold;
}

.info-item.target .value {
    color: #FF6B9D;
    font-size: 28px;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.1);
}

.control-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF6B9D, #FF8E53);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 0 #E91E63, 0 6px 15px rgba(0,0,0,0.2);
    transition: all 0.1s;
    position: relative;
    top: 0;
}

.control-btn:active {
    top: 4px;
    box-shadow: 0 0 0 #E91E63, 0 2px 10px rgba(0,0,0,0.2);
}

/* 游戏主体区域 */
.game-main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 10px;
    gap: 20px;
}

/* 控制面板 - 右侧十字排列 */
.control-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

/* 右侧控制按钮区域 */
.right-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

/* 中间一行（左右按钮） */
.middle-row {
    display: flex;
    gap: 15px;
}

.dir-btn {
    width: 70px;
    height: 70px;
    border: none;
    border-radius: 15px;
    font-size: 36px;
    cursor: pointer;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    box-shadow: 0 6px 0 #5a67d8, 0 8px 20px rgba(0,0,0,0.3);
    transition: all 0.1s;
    position: relative;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dir-btn:active {
    top: 6px;
    box-shadow: 0 0 0 #5a67d8, 0 2px 10px rgba(0,0,0,0.3);
}

/* 游戏画布容器 - 扩展 */
.game-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    max-width: calc(100% - 120px); /* 为右侧按钮留空间 */
}

/* 扩展的画布 */
.game-container.expanded {
    max-width: calc(100% - 120px);
}

#gameCanvas {
    background: #fff;
    border: 4px solid #4ECDC4;
    border-radius: 15px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    max-width: 100%;
    max-height: 100%;
}

/* 操作提示 */
.controls-hint {
    padding: 10px;
    text-align: center;
    color: #666;
    font-size: 16px;
    font-weight: bold;
    background: rgba(255,255,255,0.8);
    border-radius: 20px;
    margin: 10px;
}

/* ========== 遮罩层 ========== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    color: #fff;
    padding: 40px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

/* 紧凑模式 - 用于暂停等小型弹窗 */
.overlay-content.compact {
    padding: 25px 35px;
    background: rgba(102, 126, 234, 0.85); /* 半透明背景 */
    backdrop-filter: blur(10px);
    border-radius: 25px;
}

.overlay-content.compact h2 {
    font-size: 28px;
    margin-bottom: 15px;
}

.overlay-content.compact .pause-icon,
.overlay-content.compact .sad-icon {
    font-size: 48px;
    margin-bottom: 8px;
}

/* 小按钮 */
.big-btn.small {
    width: 160px;
    padding: 12px 20px;
    font-size: 16px;
    margin: 8px auto;
    border-radius: 20px;
}

.pause-icon, .sad-icon {
    font-size: 60px;
    margin-bottom: 10px;
}

.overlay-content h2 {
    font-size: 36px;
    margin-bottom: 20px;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.final-score {
    font-size: 28px;
    margin-bottom: 30px;
    font-weight: bold;
}

.big-btn {
    display: block;
    width: 220px;
    padding: 18px 30px;
    margin: 12px auto;
    border: none;
    border-radius: 30px;
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(135deg, #56ab2f, #a8e063);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 6px 0 #3d8b1e, 0 8px 20px rgba(0,0,0,0.3);
    position: relative;
    top: 0;
}

.big-btn.secondary {
    background: linear-gradient(135deg, #f093fb, #f5576c);
    box-shadow: 0 6px 0 #d63384, 0 8px 20px rgba(0,0,0,0.3);
}

.big-btn.secondary:active {
    box-shadow: 0 0 0 #d63384, 0 2px 10px rgba(0,0,0,0.3);
}

.big-btn:active {
    top: 6px;
    box-shadow: 0 0 0 #3d8b1e, 0 2px 10px rgba(0,0,0,0.3);
}

/* ========== 通关庆祝 ========== */
#victory-overlay {
    background: rgba(0, 0, 0, 0.9);
}

#fireworksCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.victory-content {
    position: relative;
    z-index: 10;
    text-align: center;
    color: #fff;
    background: linear-gradient(135deg, #fa709a, #fee140);
    padding: 40px;
    border-radius: 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    max-width: 85%;
    max-height: 85vh;
    overflow-y: auto;
}

/* 紧凑的通关庆祝 */
.victory-content.compact {
    padding: 25px 30px;
}

.victory-content.compact .congrats-text {
    font-size: 32px;
}

.victory-content.compact .victory-subtitle {
    font-size: 18px;
    margin-bottom: 20px;
}

.victory-content.compact .victory-score {
    padding: 15px 30px;
    margin-bottom: 20px;
}

.victory-content.compact .score-number {
    font-size: 42px !important;
}

.celebration-icons {
    font-size: 50px;
    margin-bottom: 10px;
}

.celebration-icons span {
    margin: 0 10px;
    display: inline-block;
    animation: celebrate-bounce 0.6s ease infinite;
}

.celebration-icons span:nth-child(2) { animation-delay: 0.2s; }
.celebration-icons span:nth-child(3) { animation-delay: 0.4s; }

@keyframes celebrate-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.congrats-text {
    font-size: 42px;
    margin-bottom: 10px;
    color: #fff;
    text-shadow: 3px 3px 0px rgba(0,0,0,0.2);
}

.victory-subtitle {
    font-size: 22px;
    margin-bottom: 30px;
    font-weight: bold;
}

.victory-score {
    background: rgba(255, 255, 255, 0.3);
    padding: 20px 40px;
    border-radius: 20px;
    margin-bottom: 30px;
    display: inline-block;
}

.victory-score span {
    display: block;
    font-size: 18px;
    font-weight: bold;
}

.score-number {
    font-size: 56px !important;
    font-weight: bold;
    color: #fff;
    text-shadow: 3px 3px 0px rgba(0,0,0,0.3);
    margin-top: 5px;
}

/* 分数弹出动画 */
.score-popup {
    position: fixed;
    font-size: 36px;
    font-weight: bold;
    pointer-events: none;
    animation: popUp 1s ease-out forwards;
    z-index: 50;
    text-shadow: 3px 3px 0px rgba(0,0,0,0.3);
}

@keyframes popUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-100px) scale(1.8);
    }
}

/* 小屏幕适配 */
@media (max-height: 400px) {
    .top-bar {
        padding: 5px 10px;
        margin: 5px;
    }
    
    .info-item .value {
        font-size: 14px;
    }
    
    .info-item.target .value {
        font-size: 20px;
    }
    
    .control-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .dir-btn {
        width: 55px;
        height: 55px;
        font-size: 28px;
    }
    
    .controls-hint {
        display: none;
    }
    
    .mode-buttons {
        gap: 10px;
    }
    
    .mode-btn {
        padding: 15px 20px;
        min-width: 80px;
    }
    
    .btn-emoji {
        font-size: 24px;
    }
    
    .mode-name {
        font-size: 18px;
    }
    
    #mode-selection h1 {
        font-size: 36px;
    }
    
    .snake-icon {
        font-size: 60px;
    }
    
    .overlay-content {
        padding: 20px;
        border-radius: 20px;
    }
    
    .overlay-content h2 {
        font-size: 24px;
    }
    
    .big-btn {
        width: 160px;
        padding: 12px 20px;
        font-size: 16px;
    }
    
    .victory-content {
        padding: 20px;
    }
    
    .congrats-text {
        font-size: 28px;
    }
}

/* 更小的屏幕 */
@media (max-height: 350px) {
    .logo-area {
        margin-bottom: 10px;
    }
    
    .snake-icon {
        font-size: 40px;
    }
    
    #mode-selection h1 {
        font-size: 28px;
    }
    
    .subtitle {
        font-size: 16px;
    }
    
    .mode-buttons {
        margin-bottom: 15px;
    }
    
    .mode-btn {
        padding: 10px 15px;
        min-width: 70px;
    }
    
    .btn-emoji {
        font-size: 20px;
    }
    
    .mode-name {
        font-size: 14px;
    }
    
    .high-score-area {
        padding: 10px 20px;
    }
    
    .trophy {
        font-size: 24px;
    }
    
    .high-score-text {
        font-size: 18px;
    }
    
    .fullscreen-btn {
        margin-top: 10px;
        padding: 8px 20px;
        font-size: 14px;
    }
}

/* 触摸反馈 */
.touch-feedback {
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255, 107, 157, 0.4);
    pointer-events: none;
    animation: touchRipple 0.6s ease-out forwards;
}

@keyframes touchRipple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(3);
        opacity: 0;
    }
}
