* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Arial', sans-serif;
    border: none !important;
    outline: none !important;
}
*:focus, *:active {
    outline: none !important;
    box-shadow: none !important;
}

body {
    background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab, #667eea, #764ba2, #f093fb, #f5576c);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 10px;
    border: none !important;
    outline: none !important;
    position: relative;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(100px);
    z-index: 0;
}

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

.container {
    width: 100%;
    margin: 0 auto;
    padding: 0 10px;
    position: relative;
    z-index: 1;
}

.game-container {
    padding: 0;
    text-align: center;
    max-width: 100%;
    margin: 0 auto;
    border: none !important;
    position: relative;
}

.card {
    border: none !important;
    overflow: hidden;
}

.card-body {
    padding: 10px 10px 5px 10px;
    width: 100%;
    background: transparent !important;
}

.card-title{padding-top:10px;}
.score-display {
    color: white;
    font-weight: bold;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.steps-display {
    color: white;
    font-weight: bold;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.countdown-icon {
    color: #ffeaa7;
    font-size: 1.2em;
    font-weight: bold;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

h1 {
    color: white !important;
    margin-bottom: 20px;
    font-size: 1.4em;
    font-weight: bold;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.preview-section {
    margin-bottom: 30px;
    border: none !important;
}

.game-intro-bg {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) top center/contain no-repeat;
    z-index: 1;
}

.control-buttons {
    position: fixed !important;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100 !important;
    display: flex !important;
    gap: 15px !important;
    align-items: center !important;
    justify-content: center !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    width: auto !important;
    background: rgba(255, 255, 255, 0.7) !important;
    padding: 10px 10px !important;
    border-radius: 0 !important;
    backdrop-filter: blur(10px) !important;
}

/* 开始游戏按钮 - 更宽 */
.start-game-overlay, #start-btn {
    padding: 15px 25px !important;
    font-size: 1.4em !important;
    border: none !important;
    border-radius: 50px !important;
    color: white !important;
    font-weight: bold !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
    transition: all 0.3s ease !important;
    min-width: 280px !important;
    max-width: 280px !important;
    width: 280px !important;
    height: auto !important;
    text-align: center !important;
    display: inline-block;
    vertical-align: middle !important;
}

/* 游戏规则和排行榜按钮样式（宽度由后面的规则控制） */
#rules-btn, #leaderboard-btn {
    padding: 12px 18px !important;
    font-size: 1.1em !important;
    border: none !important;
    border-radius: 50px !important;
    color: white !important;
    font-weight: bold !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
    transition: all 0.3s ease !important;
    height: auto !important;
    text-align: center !important;
    display: inline-block;
    vertical-align: middle !important;
}

.start-game-overlay, #start-btn {
    background: linear-gradient(145deg, #ff6b35, #dc3545) !important;
    box-shadow: 0 8px 25px rgba(255, 107, 53, 0.4), 
                0 4px 15px rgba(0, 0, 0, 0.3),
                inset 0 2px 0 rgba(255, 255, 255, 0.3) !important;
    animation: pulse 2s infinite;
}

#rules-btn {
    background: linear-gradient(145deg, #28a745, #20c997) !important;
    box-shadow: 0 8px 25px rgba(40, 167, 69, 0.4), 
                0 4px 15px rgba(0, 0, 0, 0.3),
                inset 0 2px 0 rgba(255, 255, 255, 0.3) !important;
}

#leaderboard-btn {
    background: linear-gradient(145deg, #17a2b8, #138496) !important;
    box-shadow: 0 8px 25px rgba(23, 162, 184, 0.4), 
                0 4px 15px rgba(0, 0, 0, 0.3),
                inset 0 2px 0 rgba(255, 255, 255, 0.3) !important;
}

#leaderboard-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(23, 162, 184, 0.5), 
                0 6px 20px rgba(0, 0, 0, 0.4),
                inset 0 2px 0 rgba(255, 255, 255, 0.4) !important;
    background: linear-gradient(145deg, #138496, #0f6674) !important;
}

.start-game-overlay:hover {
    transform: translateY(-3px) !important;
    box-shadow: 0 12px 35px rgba(255, 107, 53, 0.5), 
                0 6px 20px rgba(0, 0, 0, 0.4),
                inset 0 2px 0 rgba(255, 255, 255, 0.4) !important;
    background: linear-gradient(145deg, #e55a2b, #b02a37) !important;
}

.start-game-overlay:active {
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3), 
                0 2px 8px rgba(0, 0, 0, 0.2) !important;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 8px 25px rgba(255, 107, 53, 0.4), 
                    0 4px 15px rgba(0, 0, 0, 0.3),
                    inset 0 2px 0 rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow: 0 12px 35px rgba(255, 107, 53, 0.6), 
                    0 6px 20px rgba(0, 0, 0, 0.4),
                    inset 0 2px 0 rgba(255, 255, 255, 0.4);
    }
}
#game-rules:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    transform: translateY(-2px);
}
#game-rules h6 {
    color: white !important;
}
#game-rules p {
    margin: 0.25rem 0;
    color: rgba(255, 255, 255, 0.95) !important;
}
.image-container {
    position: relative;
    width: 100%;
    /* 设置为1:2的宽高比 */
    aspect-ratio: 1 / 2;
    margin: 0 auto;
    border: 2px solid #ddd;
    border-radius: 8px;
}
.preview-image, #preview-grid, #puzzle-board {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 97.5%;
}

#puzzle-board {
    display: grid;
    justify-content: center;
    align-content: center;
    border-radius: 8px;
    padding: 0 10px;
}

#puzzle-board.show {
    background: #fff;
}
.preview-image {
    object-fit: cover;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

#preview-grid {
    display: grid;
    pointer-events: none;
    z-index: 10;
}

#preview-grid .grid-cell {
    border: 2px dashed rgba(255, 255, 255, 0.8);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.3);
}

#preview-text {
    color: white;
    font-size: 1.2em;
    font-weight: bold;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.game-info {
    color: white !important;
}

.game-info span {
    color: white !important;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#timer, #moves {
    color: #ffeaa7 !important;
}

.puzzle-section {
    margin-bottom: 30px;
    border: none !important;
}

/* puzzle-board样式已合并到上面 */

.puzzle-piece {
    background-color: #e0e0e0;
    border: 2px solid #999;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    background-repeat: no-repeat;
    transform: scale(1);
    z-index: 1;
    box-shadow: none;
}

.puzzle-piece:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2) !important;
}

.puzzle-piece.selected {
    border-color: #3498db !important;
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.8) !important;
    transform: scale(1.1) !important;
    z-index: 10 !important;
}

/* 选中状态覆盖hover效果 */
.puzzle-piece.selected:hover {
    transform: scale(1.1) !important;
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.8) !important;
}

.game-info {
    margin-bottom: 20px;
    font-size: 1.1em;
}

.game-info span {
    margin: 0 15px;
    font-weight: bold;
    color: #333;
}

#timer {
    color: #e74c3c;
}

#moves {
    color: #27ae60;
}



button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none !important;
    padding: 14px 28px;
    margin: 5px;
    border-radius: 50px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

button:hover::before {
    width: 300px;
    height: 300px;
}

button:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.5);
}

button:active {
    transform: translateY(-1px) scale(0.98);
}

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

button.btn-secondary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    box-shadow: 0 4px 20px rgba(240, 147, 251, 0.4);
}

button.btn-secondary:hover {
    box-shadow: 0 8px 30px rgba(240, 147, 251, 0.5);
}

button.btn-warning {
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    box-shadow: 0 4px 20px rgba(253, 203, 110, 0.4);
}

button.btn-warning:hover {
    box-shadow: 0 8px 30px rgba(253, 203, 110, 0.5);
}

button.btn-lg {
    padding: 10px 15px;
    font-size: 1.6em;
}

#modalButtons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

#modalButtons .btn {
    min-width: 140px;
}

#message {
    font-size: 1.2em;
    font-weight: bold;
    margin-top: 20px;
    opacity: 0;
    transition: opacity 0.5s ease;
}
#message.win-message, #message.error-message {
    opacity: 1;
}

/* 模态框样式 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease;
}

.modal-overlay.d-none {
    display: none !important;
}

.modal-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 10px;
    border-radius: 20px;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.4s ease;
    text-align: center;
}

#modalMessage {
    font-size: 1.1em;
    line-height: 1.8;
}

#modalMessage > div {
    margin-bottom: 15px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.win-message {
    color: #27ae60;
}

.error-message {
    color: #e74c3c;
}

/* Custom fade classes */
.fade {
    opacity: 0;
    transition: opacity 0.5s ease;
}
.fade.show {
    opacity: 1;
}
/* Bootstrap's d-none class */
.d-none {
    display: none !important;
}

/* 适配小屏幕设备 */
@media (max-width: 375px) {
    .game-container {
        padding: 10px;
    }
    h1 {
        font-size: 1.2em;
        margin-bottom: 15px;
    }
    #game-rules {
        width: 100%;
        aspect-ratio: 1 / 2;
        font-size: 10px;
    }
    .image-container {
        width: 100%;
        aspect-ratio: 1 / 2;
    }
    button {
        padding: 10px 20px;
        margin: 0 5px;
        font-size: 0.9em;
    }
    .game-info {
        font-size: 1em;
    }
    .game-info span {
        margin: 0 10px;
    }
}

/* 换一张图和作弊按钮样式 - 与开始游戏按钮保持一致 */
#restart-btn:not(.d-none), #cheat-btn:not(.d-none) {
    padding: 15px 25px !important;
    font-size: 1.4em !important;
    border: none !important;
    border-radius: 50px !important;
    color: white !important;
    font-weight: bold !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
    transition: all 0.3s ease !important;
    min-width: 180px !important;
    max-width: 180px !important;
    width: 180px !important;
    height: auto !important;
    text-align: center !important;
    display: inline-block !important;
    vertical-align: middle !important;
    margin: 0 7.5px !important;
}

#restart-btn:not(.d-none) {
    background: linear-gradient(145deg, #6c757d, #5a6268) !important;
    box-shadow: 0 8px 25px rgba(108, 117, 125, 0.4), 
                0 4px 15px rgba(0, 0, 0, 0.3),
                inset 0 2px 0 rgba(255, 255, 255, 0.3) !important;
}

#cheat-btn:not(.d-none) {
    background: linear-gradient(145deg, #ffc107, #e0a800) !important;
    box-shadow: 0 8px 25px rgba(255, 193, 7, 0.4), 
                0 4px 15px rgba(0, 0, 0, 0.3),
                inset 0 2px 0 rgba(255, 255, 255, 0.3) !important;
}

#restart-btn:not(.d-none):hover {
    transform: translateY(-3px) !important;
    box-shadow: 0 12px 35px rgba(108, 117, 125, 0.5), 
                0 6px 20px rgba(0, 0, 0, 0.4),
                inset 0 2px 0 rgba(255, 255, 255, 0.4) !important;
    background: linear-gradient(145deg, #5a6268, #495057) !important;
}

#cheat-btn:not(.d-none):hover {
    transform: translateY(-3px) !important;
    box-shadow: 0 12px 35px rgba(255, 193, 7, 0.5), 
                0 6px 20px rgba(0, 0, 0, 0.4),
                inset 0 2px 0 rgba(255, 255, 255, 0.4) !important;
    background: linear-gradient(145deg, #e0a800, #d39e00) !important;
}

#restart-btn:not(.d-none):active {
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3), 
                0 2px 8px rgba(0, 0, 0, 0.2) !important;
}

#cheat-btn:not(.d-none):active {
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 15px rgba(255, 193, 7, 0.3), 
                0 2px 8px rgba(0, 0, 0, 0.2) !important;
}

/* 游戏规则弹窗样式 */
.rules-modal {
    max-width: 85vw;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    margin-bottom: 20px;
}

.modal-title {
    margin: 0;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
}

.btn-close {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s;
}

.btn-close:hover {
    background-color: rgba(255,255,255,0.2);
}

.modal-body {
    padding: 0 20px;
}

.rules-content {
    color: white;
    line-height: 1.6;
    font-size: 1rem;
    text-align: justify;
}

.rules-content h1, .rules-content h2, .rules-content h3,
.rules-content h4, .rules-content h5, .rules-content h6 {
    color: #ffeaa7;
    margin-top: 20px;
    margin-bottom: 10px;
}

.rules-content p {
    margin-bottom: 15px;
}

.rules-content ul, .rules-content ol {
    padding-left: 20px;
    margin-bottom: 15px;
}

.rules-content li {
    margin-bottom: 8px;
}

.modal-footer {
    padding: 20px;
    text-align: center;
    border-top: 1px solid rgba(255,255,255,0.2);
    margin-top: 20px;
}

.modal-footer .btn {
    padding: 10px 30px;
    font-size: 1.1rem;
    font-weight: bold;
}

/* 作弊文字按钮样式 */
.cheat-text-btn {
    font-size: 0.8rem !important;
    color: #ffc107 !important;
    cursor: pointer !important;
    text-decoration: none !important;
    margin-left: 10px !important;
    font-weight: normal !important;
}

.cheat-text-btn:hover {
    color: #ffb300 !important;
    text-decoration: none !important;
}

/* 音乐控制按钮样式 */
.music-control {
    position: fixed !important;
    top: 54px !important;
    right: 20px !important;
    width: 30px;
    height: 30px;
    background: rgba(255, 255, 255, 0.8);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    z-index: 9999 !important;
    transition: background 0.2s ease;
    color: #4CAF50;
    padding: 0;
}

.music-control:hover {
    background: rgba(255, 255, 255, 0.95);
    transform: scale(1.1);
}

/* 音乐播放时的缩放动画 */
@keyframes musicPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.music-control.playing {
    animation: musicPulse 1.5s ease-in-out infinite;
}

.music-control.playing:hover {
    animation: musicPulse 1.5s ease-in-out infinite;
}

.music-control::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    background: #f44336;
    transform: translateX(-50%) rotate(-45deg);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.music-control:not(.playing)::after {
    opacity: 1;
}

/* 主要按钮样式统一 */
.control-buttons {
    width: 100% !important;
    max-width: none !important;
    margin: 0 auto;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 5px !important;
    flex-wrap: nowrap !important;
}

/* 重置所有按钮样式，确保一致性 */
#rules-btn, 
#start-btn, 
#leaderboard-btn {
    flex: none !important;
    height: 60px !important;
    padding: 12px 16px !important;
    font-size: 1.2rem !important;
    font-weight: bold !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

/* 按百分比分配宽度（考虑gap间距） */
#rules-btn, #leaderboard-btn {
    width: calc(27% - 5px) !important;
    min-width: auto !important;
    max-width: none !important;
}

/* 开始游戏按钮容器 */
.start-btn-container {
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    width: calc(40% - 0px) !important;
}

#start-btn {
    width: 100% !important;
    min-width: auto !important;
    max-width: none !important;
    position: relative !important;
}

/* 游戏次数气泡 */
.game-chances-bubble {
    position: absolute !important;
    top: -5px !important;
    right: -5px !important;
    background: #ff4444 !important;
    color: white !important;
    border-radius: 50% !important;
    width: 28px !important;
    height: 28px !important;
    font-size: 13px !important;
    font-weight: bold !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3) !important;
    z-index: 9999 !important;
    line-height: 1 !important;
    pointer-events: none !important;
}

/* 游戏次数提示文字 */
.game-chances-text {
    font-size: 11px !important;
    color: rgba(255, 255, 255, 0.8) !important;
    margin-bottom: 4px !important;
    text-align: center !important;
    white-space: nowrap !important;
}

/* 隐藏按钮时覆盖display属性 */
#rules-btn.d-none, 
#start-btn.d-none, 
#leaderboard-btn.d-none {
    display: none !important;
}

/* 隐藏整个按钮容器时的强制规则 */
.control-buttons.d-none {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
}

/* 隐藏气泡容器时的强制规则 */
.start-btn-container.d-none,
.game-chances-bubble.d-none {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* 确保start-game-overlay类不会影响尺寸 */
.start-game-overlay {
    flex: 1 !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 60px !important;
}

/* 响应式设计 */
@media (max-width: 768px) {
    #rules-btn, 
    #start-btn, 
    #leaderboard-btn {
        height: 55px !important;
        font-size: 1.1rem !important;
        padding: 10px 12px !important;
    }
    
    .start-game-overlay {
        height: 55px !important;
    }
}

@media (max-width: 480px) {
    #rules-btn, 
    #start-btn, 
    #leaderboard-btn {
        height: 50px !important;
        font-size: 1rem !important;
        padding: 8px 5px !important;
    }
    
    .start-game-overlay {
        height: 50px !important;
    }
}