/* ==================== 全域重置 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ==================== CSS 變數 ==================== */
:root {
    --bg-dark: #1a1a2e;       /* 深色背景 */
    --bg-medium: #16213e;     /* 中等背景色 */
    --bg-light: #0f3460;      /* 淺色背景/按鈕 */
    --accent: #e94560;        /* 強調色 (紅色) */
    --text: #eee;             /* 文字顏色 */
    --cell-size: 28px;        /* 方塊大小 */
}

/* ==================== 頁面樣式 ==================== */
body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    touch-action: none;  /* 防止觸控裝置的預設行為 */
}

/* ==================== 遊戲容器 ==================== */
.game-container {
    width: 100%;
    max-width: 500px;
    padding: 20px;
    position: relative;
}

/* ==================== 遊戲標題區 ==================== */
.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-header h1 {
    font-size: 2rem;
    margin-bottom: 15px;
    text-shadow: 0 0 10px var(--accent);
}

/* 標題按鈕區域 */
.header-buttons {
    display: inline-flex;
    gap: 8px;
    margin-top: 5px;
}

/* 按鈕樣式重複定義 (保持相容性) */
.header-buttons {
    display: inline-flex;
    gap: 8px;
    vertical-align: middle;
    margin-top: 10px;
}

/* 版本號碼 */
.version {
    font-size: 0.75rem;
    color: #666;
    margin-top: 8px;
}

/* 音效/功能按鈕 */
.sound-btn {
    background: var(--bg-medium);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: transform 0.2s;
}

.sound-btn:hover {
    transform: scale(1.1);
}

/* ==================== 分數面板 ==================== */
.score-board {
    display: flex;
    justify-content: space-around;
    background: var(--bg-medium);
    padding: 15px;
    border-radius: 10px;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-item .label {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 5px;
}

.score-item span:last-child {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent);
}

/* ==================== 遊戲區域 ==================== */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    position: relative;
}

/* 下一個方塊預覽區 */
.next-piece {
    display: flex;
    flex-direction: row;
    align-items: center;
    background: var(--bg-medium);
    padding: 10px 20px;
    border-radius: 10px;
    gap: 15px;
}

/* 遊戲主畫布 */
#game-canvas {
    background: var(--bg-medium);
    border: 3px solid var(--bg-light);
    border-radius: 5px;
    box-shadow: 0 0 20px rgba(233, 69, 96, 0.3);
}

/* 預覽區樣式重複定義 */
.next-piece {
    display: flex;
    flex-direction: row;
    align-items: center;
    background: var(--bg-medium);
    padding: 10px 20px;
    border-radius: 10px;
    gap: 15px;
}

.next-piece .label {
    font-size: 0.9rem;
    color: #888;
}

#next-canvas {
    background: var(--bg-dark);
    border-radius: 5px;
}

/* ==================== 行動裝置控制按鈕 ==================== */
.mobile-controls {
    display: none;
}

/* ==================== 開始畫面覆蓋層 ==================== */
.start-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.start-content {
    background: var(--bg-medium);
    padding: 40px 60px;
    border-radius: 15px;
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.start-content h1 {
    color: var(--accent);
    margin-bottom: 10px;
    font-size: 2.5rem;
    text-shadow: 0 0 20px var(--accent);
}

.start-content p {
    color: #888;
    margin-bottom: 30px;
}

.start-content button {
    padding: 15px 50px;
    font-size: 1.3rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.start-content button:hover {
    transform: scale(1.05);
    box-shadow: 0 0 25px var(--accent);
}

/* ==================== 遊戲結束/暫停畫面 ==================== */
.game-over,
.pause-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;
}

.game-over-content,
.pause-content {
    background: var(--bg-medium);
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    animation: fadeIn 0.3s ease;
}

/* 淡入動畫 */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.game-over h2,
.pause-content h2 {
    color: var(--accent);
    margin-bottom: 20px;
    font-size: 2rem;
}

.game-over button {
    margin-top: 20px;
    padding: 15px 40px;
    font-size: 1.2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.game-over button:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--accent);
}

/* 隱藏類別 */
.hidden {
    display: none !important;
}

/* ==================== 消除行數動畫 ==================== */
@keyframes lineClear {
    0% { transform: scaleX(1); opacity: 1; }
    50% { transform: scaleX(1.1); opacity: 0.5; background: white; }
    100% { transform: scaleX(1); opacity: 1; }
}

/* ==================== 連擊效果文字 ==================== */
.combo-effect {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ffeb3b;
    font-size: 3rem;
    font-weight: bold;
    text-shadow: 0 0 10px #ff9800, 0 0 20px #ff9800, 0 0 30px #f44336;
    pointer-events: none;
    z-index: 50;
    animation: comboPop 1s ease-out forwards;
}

/* 連擊彈出動畫 */
@keyframes comboPop {
    0% { transform: translate(-50%, -10%); opacity: 0; scale: 0.5; }
    20% { transform: translate(-50%, -50%); opacity: 1; scale: 1.2; }
    80% { transform: translate(-50%, -50%); opacity: 1; scale: 1; }
    100% { transform: translate(-50%, -90%); opacity: 0; scale: 1.5; }
}

/* ==================== 行動裝置響應式設計 ==================== */
@media (max-width: 600px) {
    /* 調整方塊大小 */
    :root {
        --cell-size: 22px;
    }
    
    /* 容器自適應 */
    .game-container {
        padding: 10px;
        height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    .game-header {
        position: relative;
    }
    
    .header-buttons {
        position: static;
        justify-content: center;
        margin-top: 10px;
        margin-bottom: 10px;
    }
    
    .game-header h1 {
        font-size: 1.5rem;
    }
    
    .score-board {
        padding: 10px;
    }
    
    .score-item span:last-child {
        font-size: 1.2rem;
    }
    
    .game-area {
        flex: 1;
        align-items: center;
        justify-content: space-between;
    }
    
    .next-piece {
        display: flex;
    }
    
    #game-canvas {
        border-width: 2px;
    }
    
    /* 顯示行動裝置控制按鈕 */
    .mobile-controls {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        background: var(--bg-medium);
        border-radius: 15px;
    }
    
    .control-row {
        display: flex;
        justify-content: center;
        gap: 15px;
    }
    
    .mobile-controls button {
        width: 60px;
        height: 50px;
        font-size: 1.2rem;
        background: var(--bg-light);
        color: white;
        border: none;
        border-radius: 10px;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .mobile-controls button:active {
        background: var(--accent);
        transform: scale(0.95);
    }
    
    #btn-drop {
        width: 100px;
        background: var(--accent);
    }
}

/* ==================== 橫向模式響應式設計 ==================== */
@media (max-height: 700px) and (orientation: landscape) {
    .game-container {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-start;
        height: auto;
    }
    
    .game-header {
        width: 100%;
    }
    
    .game-area {
        flex: 1;
    }
    
    .mobile-controls {
        flex: 0 0 auto;
    }
}
