/* 舒尔特方格游戏样式 */

* {
    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;
    margin: 0;
    padding: 10px;
    color: #333;
}

.game-container {
    max-width: 95vw;
    height: 95vh;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
}

.game-sidebar {
    width: 300px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: white;
    padding: 20px 20px 10px 20px;
    flex-shrink: 0;
    overflow-y: auto;
    border-radius: 12px;
}

.game-sidebar h1 {
    font-size: 1.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.description {
    font-size: 0.9em;
    opacity: 0.9;
    margin-bottom: 20px;
}

.game-stats {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    font-size: 0.9em;
    opacity: 0.8;
}

.stat-value {
    font-size: 1.1em;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 8px;
    border-radius: 6px;
    min-width: 60px;
    text-align: center;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.control-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.control-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.control-btn.primary {
    background: #10b981;
    border-color: #10b981;
}

.control-btn.primary:hover:not(:disabled) {
    background: #059669;
    border-color: #059669;
}

/* 桌面端的底部控制区域默认样式 */
.bottom-controls {
    display: block;
}

.bottom-controls .game-stats {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.bottom-controls .controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
}

.game-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

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

.timer {
    background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 1.1em;
    font-weight: bold;
    display: inline-block;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.grid-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
}

.schulte-grid {
    display: grid;
    gap: 4px;
    padding: 20px;
    background: #f8fafc;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

/* 不同尺寸的网格 - 优化为更大尺寸，充分利用空间 */
.grid-3x3 {
    grid-template-columns: repeat(3, min(20vh, 150px));
    grid-template-rows: repeat(3, min(20vh, 150px));
}

.grid-4x4 {
    grid-template-columns: repeat(4, min(16vh, 120px));
    grid-template-rows: repeat(4, min(16vh, 120px));
}

.grid-5x5 {
    grid-template-columns: repeat(5, min(13vh, 100px));
    grid-template-rows: repeat(5, min(13vh, 100px));
}

.grid-6x6 {
    grid-template-columns: repeat(6, min(11vh, 85px));
    grid-template-rows: repeat(6, min(11vh, 85px));
}

.grid-7x7 {
    grid-template-columns: repeat(7, min(9vh, 75px));
    grid-template-rows: repeat(7, min(9vh, 75px));
}

.grid-8x8 {
    grid-template-columns: repeat(8, min(8vh, 65px));
    grid-template-rows: repeat(8, min(8vh, 65px));
}

.grid-9x9 {
    grid-template-columns: repeat(9, min(7vh, 58px));
    grid-template-rows: repeat(9, min(7vh, 58px));
}

.grid-10x10 {
    grid-template-columns: repeat(10, min(6vh, 52px));
    grid-template-rows: repeat(10, min(6vh, 52px));
}

.grid-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background: white; /* 初始白色背景 */
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: min(4vh, 2em);
    font-weight: bold;
    color: #334155;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.grid-cell:hover:not(.correct):not(.error) {
    background: #f1f5f9;
    border-color: #6366f1;
    transform: scale(1.05);
}

/* 正确点击 - 绿色背景 */
.grid-cell.correct {
    background: #10b981 !important;
    color: white !important;
    border-color: #047857 !important;
    cursor: default;
}

/* 错误点击 - 红色背景，1秒后自动恢复 */
.grid-cell.error {
    background: #ef4444 !important;
    color: white !important;
    border-color: #b91c1c !important;
    transition: all 0.3s ease;
}

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

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-3px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(3px);
    }
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    z-index: 1000;
}

.overlay-content {
    background: white;
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
}

.overlay-content h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.8em;
}

.completion-stats {
    margin: 20px 0;
}

.completion-stats p {
    font-size: 1.1em;
    margin: 10px 0;
    color: #666;
}

#newRecord {
    color: #f59e0b;
    font-weight: bold;
    font-size: 1.2em;
}

.instructions {
    margin-bottom: 20px;
}

.instructions h3 {
    color: white;
    margin-bottom: 10px;
    font-size: 1em;
    opacity: 0.9;
}

.game-description {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85em;
    line-height: 1.4;
    margin: 0;
}

.difficulty-guide {
    margin-bottom: 20px;
}

.difficulty-guide h4 {
    color: white;
    margin-bottom: 10px;
    font-size: 1em;
    opacity: 0.9;
}

.difficulty-levels {
    display: grid;
    gap: 6px;
}

.difficulty-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: all 0.3s ease;
}

.difficulty-item:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.difficulty-item.selected {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1);
}

.difficulty-item .level {
    font-weight: bold;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85em;
}

.difficulty-item .desc {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.8em;
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .game-container {
        flex-direction: column;
    }
    
    .game-sidebar {
        width: 100%;
        height: auto;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        padding: 15px 20px;
    }
    
    .game-sidebar h1 {
        margin-bottom: 0;
    }
    
    .description,
    .instructions {
        display: none;
    }
    
    .grid-container {
        min-height: 60vh;
    }
}

/* 移动端竖屏优化 */
@media (max-width: 768px) and (orientation: portrait) {
    body {
        padding: 5px;
    }
    
    .game-container {
        height: 100vh;
        max-height: 100vh;
        flex-direction: column;
        padding: 6px;
    }
    
    .game-sidebar {
        width: calc(100% - 4px);
        padding: 10px 10px 4px 10px;
        overflow: visible;
        flex-shrink: 0;
        border-radius: 10px;
        margin: 2px auto;
    }
    
    .game-main {
        margin: 2px auto;
        width: calc(100% - 4px);
        border-radius: 10px;
        background: white;
    }
    
    .game-sidebar h1 {
        font-size: 1.5em;
        margin-bottom: 12px;
        text-align: center;
        width: 100%;
        font-weight: 600;
    }
    
    .instructions {
        display: block;
        margin-bottom: 12px;
        padding: 12px;
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(5px);
    }
    
    .instructions h3 {
        font-size: 1em;
        margin-bottom: 8px;
        font-weight: 500;
    }
    
    .game-description {
        font-size: 0.9em;
        text-align: left;
        line-height: 1.3;
    }
    
    /* 难度选择：每行4个，共2行 */
    .difficulty-guide {
        margin-bottom: 8px;
        width: 100%;
    }
    
    .difficulty-guide h4 {
        font-size: 1em;
        margin-bottom: 6px;
        text-align: left;
        font-weight: 500;
    }
    
    .difficulty-levels {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, auto);
        gap: 6px;
        margin-bottom: 6px;
        width: 100%;
        justify-items: stretch;
        align-items: stretch;
        padding: 0;
    }
    
    .difficulty-item {
        padding: 8px 6px;
        font-size: 0.8em;
        border-radius: 4px;
        display: flex;
        flex-direction: row;
        text-align: center;
        min-height: 40px;
        justify-content: center;
        align-items: center;
        box-sizing: border-box;
        width: 100%;
        gap: 4px;
    }
    
    .difficulty-item .level {
        font-size: 1em;
        margin-bottom: 0;
        font-weight: 600;
    }
    
    .difficulty-item .desc {
        font-size: 0.9em;
        line-height: 1.2;
        opacity: 0.85;
        font-weight: 400;
    }
    
    /* 用时、最佳成绩、重置共用一行 */
    .bottom-controls {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        gap: 6px;
        margin-bottom: 2px;
        flex-wrap: nowrap;
        flex-direction: row !important;
    }
    
    .game-stats {
        display: flex !important;
        gap: 6px;
        margin: 0;
        flex: 2;
        flex-wrap: nowrap;
        flex-direction: row !important;
    }
    
    .stat-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 4px;
        flex: 1;
        min-width: 0;
    }
    
    .stat-item:first-child {
        justify-content: center;
    }
    
    .stat-item:last-child {
        justify-content: flex-start;
        padding-left: 5px;
    }
    
    .stat-label {
        font-size: 0.75em;
        margin-bottom: 0;
        white-space: nowrap;
        flex-shrink: 0;
        font-weight: 500;
    }
    
    .stat-value {
        font-size: 0.9em;
        padding: 4px 6px;
        border-radius: 4px;
        min-width: 40px;
        text-align: center;
        flex-shrink: 0;
        font-weight: 500;
    }
    
    .controls {
        margin: 0;
        flex: 1;
        display: flex;
        justify-content: center;
    }
    
    .control-btn {
        padding: 6px 15px;
        font-size: 0.8em;
        min-width: 60px;
        font-weight: 500;
        border-radius: 6px;
        width: 100%;
        max-width: 100px;
    }
    
    .game-main {
        flex: 1;
        padding: 0;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .grid-container {
        flex: 1;
        width: 100%;
        max-width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* 移动端网格尺寸优化 - 基于剩余可用高度 */
    .grid-3x3 {
        grid-template-columns: repeat(3, min(25vh, 120px));
        grid-template-rows: repeat(3, min(25vh, 120px));
    }
    
    .grid-4x4 {
        grid-template-columns: repeat(4, min(20vh, 95px));
        grid-template-rows: repeat(4, min(20vh, 95px));
    }
    
    .grid-5x5 {
        grid-template-columns: repeat(5, min(16vh, 75px));
        grid-template-rows: repeat(5, min(16vh, 75px));
    }
    
    .grid-6x6 {
        grid-template-columns: repeat(6, min(13vh, 65px));
        grid-template-rows: repeat(6, min(13vh, 65px));
    }
    
    .grid-7x7 {
        grid-template-columns: repeat(7, min(11vh, 55px));
        grid-template-rows: repeat(7, min(11vh, 55px));
    }
    
    .grid-8x8 {
        grid-template-columns: repeat(8, min(9vh, 48px));
        grid-template-rows: repeat(8, min(9vh, 48px));
    }
    
    .grid-9x9 {
        grid-template-columns: repeat(9, min(8vh, 42px));
        grid-template-rows: repeat(9, min(8vh, 42px));
    }
    
    .grid-10x10 {
        grid-template-columns: repeat(10, min(7vh, 38px));
        grid-template-rows: repeat(10, min(7vh, 38px));
    }
    
    .grid-cell {
        font-size: min(6vh, 1.8em);
        border-radius: 8px;
    }
}

/* 小屏幕横屏模式 */
@media (max-width: 768px) and (orientation: landscape) {
    .game-container {
        flex-direction: row;
    }
    
    .game-sidebar {
        width: 250px;
        height: 100%;
        border-radius: 0 10px 10px 0;
    }
    
    .difficulty-levels {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 超小屏幕 */
@media (max-width: 480px) {
    .difficulty-item .desc {
        display: inline;
        font-size: 0.85em;
        line-height: 1.2;
        font-weight: 400;
    }
    
    .difficulty-item {
        min-height: 44px;
        padding: 7px 5px;
        flex-direction: row;
        gap: 4px;
    }
    
    .difficulty-item .level {
        font-size: 0.95em;
    }
    
    .game-sidebar h1 {
        font-size: 1.4em;
        font-weight: 600;
    }
    
    .instructions {
        padding: 8px;
    }
    
    .game-description {
        font-size: 0.75em;
    }
}
