/* 基础样式和移动端适配 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', cursive, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #f5576c 75%, #ffc371 100%);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    min-height: 100vh;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    position: relative;
}

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

/* 背景装饰 */
.background-decoration {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.floating-elements {
    position: relative;
    width: 100%;
    height: 100%;
}

.floating-star {
    position: absolute;
    font-size: 2rem;
    animation: float 6s ease-in-out infinite;
    opacity: 0.7;
    filter: blur(0.5px);
}

.floating-star:nth-child(1) {
    top: 10%;
    left: 10%;
    animation-delay: 0s;
    animation-duration: 8s;
}

.floating-star:nth-child(2) {
    top: 20%;
    right: 15%;
    animation-delay: 1s;
    animation-duration: 7s;
}

.floating-star:nth-child(3) {
    bottom: 30%;
    left: 20%;
    animation-delay: 2s;
    animation-duration: 9s;
}

.floating-star:nth-child(4) {
    top: 60%;
    right: 10%;
    animation-delay: 3s;
    animation-duration: 6s;
}

.floating-star:nth-child(5) {
    bottom: 20%;
    right: 30%;
    animation-delay: 4s;
    animation-duration: 8s;
}

.floating-star:nth-child(6) {
    top: 40%;
    left: 5%;
    animation-delay: 5s;
    animation-duration: 7s;
}

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

.container {
    max-width: 100vw;
    min-height: 100vh;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 10;
}

/* 游戏标题 */
.game-header {
    text-align: center;
    margin-bottom: 20px;
    width: 100%;
}

.game-title-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.game-title-decoration {
    font-size: 2rem;
    animation: spin 4s linear infinite;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.game-title {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    color: #fff;
    text-shadow: 2px 2px 8px rgba(0,0,0,0.3);
    animation: bounce 2s infinite;
    background: linear-gradient(45deg, #ff6b9d, #ffa8cc, #ff6b9d);
    background-size: 200% 200%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: bounce 2s infinite, textGradient 3s ease infinite;
}

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

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

.score-board {
    display: flex;
    justify-content: space-around;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.8));
    border-radius: 20px;
    padding: 15px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    max-width: 400px;
    margin: 0 auto;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.score-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #fff, #f8f9ff);
    border-radius: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.score-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
}

.score-icon {
    font-size: 1.5rem;
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.2));
}

.score-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.score-label, .moves-label {
    font-size: 0.8rem;
    color: #666;
    font-weight: 600;
    margin-bottom: 2px;
}

.score-value, .moves-value {
    font-size: 1.3rem;
    font-weight: bold;
    color: #ff6b9d;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

/* 主题切换按钮 */
.theme-selector {
    text-align: center;
    margin-top: 15px;
}

.theme-button-container {
    display: inline-block;
    position: relative;
}

.theme-button {
    background: linear-gradient(45deg, #667eea, #764ba2, #f093fb);
    background-size: 200% 200%;
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: clamp(0.8rem, 2.5vw, 1rem);
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    font-family: inherit;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: buttonGradient 3s ease infinite;
}

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

.theme-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.5);
}

.theme-button:active {
    transform: translateY(-1px);
}

.theme-icon {
    font-size: 1.2rem;
}

.theme-text {
    font-size: inherit;
}

/* 开始界面 */
.start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.95), rgba(240, 147, 251, 0.95));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.start-content {
    text-align: center;
    padding: 30px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.85));
    border-radius: 25px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
    max-width: 90%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
}

.start-content::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    animation: shimmer 4s linear infinite;
}

@keyframes shimmer {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.start-decoration {
    font-size: 3rem;
    margin-bottom: 15px;
    animation: bounce 2s infinite;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
}

.welcome-text {
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    color: #667eea;
    margin-bottom: 20px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
    font-weight: bold;
}

.game-rules {
    margin-bottom: 30px;
    text-align: left;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.rule-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #f8f9ff, #e8f4fd);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.rule-item:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.rule-icon {
    font-size: 1.2rem;
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.2));
}

.rule-text {
    font-size: clamp(0.8rem, 2.5vw, 0.95rem);
    color: #666;
    font-weight: 600;
}

.start-button, .restart-button {
    background: linear-gradient(45deg, #667eea, #764ba2, #f093fb);
    background-size: 200% 200%;
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: clamp(1rem, 3.5vw, 1.3rem);
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    font-family: inherit;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: buttonGradient 3s ease infinite;
    position: relative;
    overflow: hidden;
}

.start-button::before, .restart-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: buttonShine 3s ease-in-out infinite;
}

@keyframes buttonShine {
    0% { left: -100%; }
    50% { left: 100%; }
    100% { left: 100%; }
}

.button-icon {
    font-size: 1.3rem;
}

.button-text {
    font-size: inherit;
}

.start-button:hover, .restart-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.5);
}

.start-button:active, .restart-button:active {
    transform: translateY(-1px);
}

/* 游戏区域 */
.game-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    position: relative;
}

.game-board-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 15px;
}

.game-board-decoration {
    font-size: 2.5rem;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
    animation: decorationPulse 3s ease-in-out infinite;
}

.game-board-decoration:first-child {
    animation-delay: 0s;
}

.game-board-decoration:last-child {
    animation-delay: 1.5s;
}

@keyframes decorationPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.1);
        opacity: 1;
    }
}

.game-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 2px;
    background: rgba(255, 255, 255, 0.9);
    padding: 10px;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    width: min(90vw, 90vh);
    height: min(90vw, 90vh);
    max-width: 400px;
    max-height: 400px;
    --cell-size: calc((min(min(90vw, 90vh), 400px) - 20px - 14px) / 8); /* 考虑最大尺寸限制的格子尺寸计算 */
}

.game-cell {
    background: linear-gradient(135deg, #f8f9ff, #e8f4fd);
    border-radius: 20%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--cell-size) * 0.8); /* emoji占格子的80% */
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    border: 2px solid transparent;
}

.game-cell:hover {
    background: linear-gradient(135deg, #fff0f5, #f0f8ff);
    transform: scale(1.05);
}

.game-cell.selected {
    border-color: #ff6b9d;
    background: linear-gradient(135deg, #ffe0e6, #fff0f5);
    animation: pulse 0.5s ease-in-out;
}

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

.game-cell.swapping {
    z-index: 10;
    transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.game-cell.eliminating {
    animation: eliminate 0.6s cubic-bezier(0.25, 0.1, 0.9, 0.9) forwards;
    color: transparent;
}

.game-cell.eliminating::before {
    content: attr(data-emoji);
    position: absolute;
    top: 50%;
    left: 50%;
    font-size: inherit;
    opacity: 1;
    animation: eliminateEmoji 0.6s cubic-bezier(0.25, 0.1, 0.9, 0.9) forwards;
    z-index: 1;
}

@keyframes eliminate {
    0% {
        opacity: 1;
        transform: scale(1);
        background: linear-gradient(135deg, #f8f9ff, #e8f4fd);
    }
    50% {
        opacity: 1;
        transform: scale(1);
        background: linear-gradient(135deg, #f8f9ff, #e8f4fd);
    }
    75% {
        opacity: 0.8;
        transform: scale(0.9);
        background: linear-gradient(135deg, #ffe0e6, #fff0f5);
    }
    90% {
        opacity: 0.4;
        transform: scale(0.6);
        background: linear-gradient(135deg, #ffb3ba, #ffc9dd);
    }
    100% {
        opacity: 0;
        transform: scale(0.3);
        background: linear-gradient(135deg, #ff9a9e, #fecfef);
    }
}

@keyframes eliminateEmoji {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    42% {
        transform: translate(-50%, -50%) scale(1.6);
        opacity: 1;
    }
    58% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    75% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
}

.game-cell.falling {
    animation: fall 0.3s ease-out;
}

@keyframes fall {
    0% {
        transform: translateY(-100%) scale(0.8);
        opacity: 0;
        background: linear-gradient(135deg, rgba(248, 249, 255, 0.3), rgba(232, 244, 253, 0.3));
    }
    33% {
        transform: translateY(-50%) scale(0.9);
        opacity: 0.5;
        background: linear-gradient(135deg, rgba(248, 249, 255, 0.6), rgba(232, 244, 253, 0.6));
    }
    67% {
        transform: translateY(-10%) scale(1.05);
        opacity: 0.8;
        background: linear-gradient(135deg, rgba(248, 249, 255, 0.9), rgba(232, 244, 253, 0.9));
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
        background: linear-gradient(135deg, #f8f9ff, #e8f4fd);
    }
}

/* 游戏结束界面 */
.game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.95), rgba(240, 147, 251, 0.95));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.game-over-content {
    text-align: center;
    padding: 40px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.85));
    border-radius: 25px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
    max-width: 90%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    position: relative;
    overflow: hidden;
}

.game-over-content::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    animation: shimmer 4s linear infinite;
}

.game-over-decoration {
    font-size: 3rem;
    margin-bottom: 15px;
    animation: celebration 2s ease-in-out infinite;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
}

@keyframes celebration {
    0%, 100% {
        transform: scale(1) rotate(0deg);
    }
    25% {
        transform: scale(1.2) rotate(5deg);
    }
    50% {
        transform: scale(1.1) rotate(-5deg);
    }
    75% {
        transform: scale(1.3) rotate(3deg);
    }
}

.game-over-title {
    font-size: clamp(1.3rem, 4vw, 2rem);
    color: #667eea;
    margin-bottom: 20px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

.final-score-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
}

.score-trophy {
    font-size: 4rem;
    margin-bottom: 10px;
    animation: bounce 2s infinite;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
}

.final-score {
    font-size: clamp(1rem, 3.5vw, 1.4rem);
    color: #666;
    font-weight: bold;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .container {
        padding: 5px;
    }
    
    .game-title-container {
        gap: 5px;
    }
    
    .game-title-decoration {
        font-size: 1.5rem;
    }
    
    .game-board-container {
        gap: 8px;
    }
    
    .game-board-decoration {
        font-size: 2rem;
    }
    
    .game-board {
        width: 95vw;
        height: 95vw;
        max-width: 350px;
        max-height: 350px;
        --cell-size: calc((95vw - 20px - 14px) / 8); /* 移动端格子尺寸计算 */
    }
    
    .score-board {
        flex-direction: column;
        gap: 8px;
        padding: 12px;
        max-width: 300px;
    }
    
    .score-item {
        padding: 6px 10px;
    }
    
    .score-icon {
        font-size: 1.2rem;
    }
    
    .score-value, .moves-value {
        font-size: 1.1rem;
    }
    
    .floating-star {
        font-size: 1.5rem;
    }
    
    .theme-button {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
    
    .start-content, .game-over-content {
        padding: 20px;
        max-width: 95%;
    }
    
    .game-rules {
        max-width: 280px;
    }
    
    .rule-item {
        padding: 6px 10px;
        margin-bottom: 8px;
    }
    
    .rule-icon {
        font-size: 1rem;
    }
    
    .rule-text {
        font-size: 0.8rem;
    }
    
    .start-button, .restart-button {
        padding: 12px 24px;
        font-size: 1rem;
    }
    
    .start-decoration, .game-over-decoration {
        font-size: 2.5rem;
    }
    
    .score-trophy {
        font-size: 3rem;
    }
    
    .welcome-text, .game-over-title {
        font-size: clamp(1rem, 3.5vw, 1.5rem);
    }
    
    .final-score {
        font-size: clamp(0.9rem, 3vw, 1.2rem);
    }
}

@media (max-width: 480px) {
    .game-board {
        gap: 1px;
        padding: 5px;
    }
    
    .game-cell {
        border-radius: 20%;
    }
    
    .game-title-container {
        gap: 3px;
    }
    
    .game-title-decoration {
        font-size: 1.2rem;
    }
    
    .game-board-container {
        gap: 5px;
    }
    
    .game-board-decoration {
        font-size: 1.5rem;
    }
    
    .score-board {
        max-width: 280px;
        padding: 10px;
    }
    
    .score-item {
        padding: 4px 8px;
    }
    
    .score-icon {
        font-size: 1rem;
    }
    
    .score-value, .moves-value {
        font-size: 1rem;
    }
    
    .floating-star {
        font-size: 1.2rem;
    }
    
    .theme-button {
        padding: 8px 16px;
        font-size: 0.8rem;
    }
    
    .start-content, .game-over-content {
        padding: 15px;
    }
    
    .game-rules {
        max-width: 250px;
    }
    
    .rule-item {
        padding: 4px 8px;
        margin-bottom: 6px;
    }
    
    .rule-icon {
        font-size: 0.9rem;
    }
    
    .rule-text {
        font-size: 0.75rem;
    }
    
    .start-button, .restart-button {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
    
    .start-decoration, .game-over-decoration {
        font-size: 2rem;
    }
    
    .score-trophy {
        font-size: 2.5rem;
    }
    
    .welcome-text, .game-over-title {
        font-size: clamp(0.9rem, 3vw, 1.2rem);
    }
    
    .final-score {
        font-size: clamp(0.8rem, 2.5vw, 1rem);
    }
    
    .swipe-indicator {
        font-size: 3rem;
        width: 60px;
        height: 60px;
    }
}

/* 全屏模式样式 */
body.fullscreen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #f5576c 75%, #ffc371 100%);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
}

body.fullscreen .container {
    max-width: 100vw;
    height: 100vh;
    padding: 5px;
}

body.fullscreen .game-area {
    flex: 1;
}

body.fullscreen .game-board-container {
    gap: 20px;
}

body.fullscreen .game-board-decoration {
    font-size: 3rem;
}

body.fullscreen .game-board {
    width: min(95vw, 95vh);
    height: min(95vw, 95vh);
    max-width: none;
    max-height: none;
    --cell-size: calc((min(95vw, 95vh) - 10px - 14px) / 8); /* 全屏模式格子尺寸计算 */
}

/* 全屏模式下的移动端适配 */
@media (max-width: 768px) {
    body.fullscreen .game-board-container {
        gap: 15px;
    }
    
    body.fullscreen .game-board-decoration {
        font-size: 2.5rem;
    }
}

@media (max-width: 480px) {
    body.fullscreen .game-board-container {
        gap: 10px;
    }
    
    body.fullscreen .game-board-decoration {
        font-size: 2rem;
    }
}

/* 触摸反馈 */
.game-cell:active {
    transform: scale(0.95);
}

/* 禁用文本选择和拖拽 */
.game-cell {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

/* 触摸反馈效果 */
.game-cell.touch-feedback {
    background: linear-gradient(135deg, #ffeb3b, #ffc107);
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 193, 7, 0.6);
    z-index: 100;
}

/* 滑动方向指示器 */
.swipe-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    font-weight: bold;
    color: #ff6b9d;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 9999;
    animation: swipePulse 0.8s ease-in-out;
    background: rgba(255, 255, 255, 0.9);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

@keyframes swipePulse {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}