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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    touch-action: manipulation;
}

.container {
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box;
}

header {
    text-align: center;
    margin-bottom: 15px;
}

header h1 {
    color: white;
    font-size: 2.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    margin: 0;
}

.game-container {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: nowrap;
    max-width: 100%;
}

.game-board-container {
    position: relative;
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* モバイル用次のブロックプレビュー */
.mobile-next-preview {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border-radius: 8px;
    padding: 5px;
    z-index: 10;
}

.mobile-next-preview canvas {
    display: block;
    width: 90px;
    height: 90px;
    opacity: 0.6;
    flex-shrink: 0;
}

#game-canvas {
    display: block;
    background: #1a1a2e;
}

.side-panel {
    background: white;
    border-radius: 10px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    min-width: 320px;
    flex: 1;
    max-width: 400px;
}

.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    padding: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    z-index: 1001;
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}

.panel-section {
    margin-bottom: 25px;
}

.panel-section:last-child {
    margin-bottom: 0;
}

.panel-section h3 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 1.2rem;
    border-bottom: 2px solid #667eea;
    padding-bottom: 5px;
}

#next-canvas {
    display: block;
    background: #1a1a2e;
    border-radius: 5px;
    margin: 0 auto;
}

.controls-help {
    font-size: 0.9rem;
    color: #555;
}

.controls-help p {
    margin-bottom: 8px;
    padding: 5px;
    background: #f0f0f0;
    border-radius: 3px;
}

.score-display, .level-display, .lines-display {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    text-align: center;
}

.score-label {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-bottom: 5px;
}

.score-value {
    font-size: 2rem;
    font-weight: bold;
}

.difficulty-selector, .sound-toggle {
    margin-bottom: 15px;
}

.difficulty-selector label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: bold;
}

.difficulty-selector select {
    width: 100%;
    padding: 10px;
    border: 2px solid #667eea;
    border-radius: 5px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
}

.sound-toggle label {
    display: flex;
    align-items: center;
    color: #555;
    font-weight: bold;
    cursor: pointer;
}

.sound-toggle input[type="checkbox"] {
    margin-right: 10px;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #e0e0e0;
    color: #333;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

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

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn:last-child {
    margin-bottom: 0;
}

.game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.game-over-overlay.hidden {
    display: none;
}

.game-over-content {
    text-align: center;
    color: white;
    padding: 40px;
}

.game-over-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: #ff6b6b;
}

.game-over-content p {
    font-size: 1.5rem;
    margin-bottom: 30px;
}

#restart-btn {
    width: auto;
    padding: 15px 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1.2rem;
    cursor: pointer;
}

.mobile-controls {
    display: none;
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
}

.mobile-row {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 15px;
}

.mobile-btn {
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(102, 126, 234, 0.8);
    border-radius: 15px;
    font-size: 1.5rem;
    font-weight: bold;
    color: rgba(102, 126, 234, 1);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(3px);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mobile-btn:active {
    background: rgba(102, 126, 234, 0.7);
    color: white;
    transform: scale(0.95);
}

footer {
    text-align: center;
    margin-top: 15px;
    color: white;
    font-size: 0.9rem;
    opacity: 0.8;
}

/* レスポンシブデザイン */
@media (max-width: 1400px) {
    .game-container {
        flex-direction: column;
        align-items: center;
        flex-wrap: wrap;
    }

    .side-panel {
        width: 100%;
        max-width: 800px;
    }

    .left-panel, .right-panel {
        display: flex;
        flex-wrap: wrap;
        gap: 20px;
    }

    .panel-section {
        flex: 1;
        min-width: 200px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    header {
        margin-bottom: 10px;
    }

    .game-container {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }

    /* ゲーム画面を最初に表示 */
    .game-board-container {
        order: 1;
        width: 100%;
        max-width: 450px;
    }

    /* 次のブロックパネルを非表示に */
    .left-panel {
        display: none;
    }

    /* モバイル用次のブロックプレビューを表示 */
    .mobile-next-preview {
        display: block;
    }

    /* 右パネルをサイドメニューに */
    .right-panel {
        position: fixed;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 350px;
        height: 100vh;
        padding: 80px 20px 20px 20px;
        background: white;
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.3);
        transition: right 0.3s ease;
        z-index: 1000;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        order: 3;
    }

    .right-panel.menu-open {
        right: 0;
    }

    .mobile-menu-toggle {
        display: block;
    }

    .right-panel .panel-section {
        display: block;
    }

    .left-panel .panel-section:not(:first-child) {
        display: none;
    }

    #game-canvas {
        width: 100%;
        height: auto;
    }

    .mobile-controls {
        display: block;
    }

    .controls-help {
        display: none;
    }

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

    footer {
        margin-top: 10px;
        font-size: 0.8rem;
    }
}

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

    header h1 {
        font-size: 1.4rem;
    }

    #game-canvas {
        width: 100%;
        height: auto;
    }

    .left-panel {
        padding: 10px;
    }

    .left-panel h3 {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    #next-canvas {
        width: 120px;
        height: 120px;
    }

    .mobile-btn {
        width: 60px;
        height: 60px;
        font-size: 1.2rem;
    }

    .mobile-row {
        gap: 10px;
        margin-bottom: 10px;
    }
}
