/* 經典踩地雷 現代玻璃質感樣式表 */
:root {
    --bg-page: #faf8ef;
    --bg-container: #bbada0;
    --bg-cell: #ccc0b3;
    --text-dark: #776e65;
    --text-light: #f9f6f2;
    
    /* 預設為初級網格寬度 (9x9) */
    --cols: 9;
    --grid-gap: 4px;
    --grid-padding: 8px;
    --cell-size: 36px;
    --grid-width: calc((var(--cell-size) * var(--cols)) + (var(--grid-gap) * (var(--cols) - 1)) + (var(--grid-padding) * 2));
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-dark);
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 主應用容器 */
.app-container {
    width: 100%;
    max-width: var(--grid-width);
    height: calc(100vh - 44px);
    height: calc(100dvh - 44px);
    margin-top: 44px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: max-width 0.25s ease-in-out;
}

/* 頂部資訊區 */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 6px;
}

.logo-text {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-dark);
    line-height: 1;
}

.subtitle-text {
    font-size: 0.72rem;
    color: #8f7a66;
    margin-top: 2px;
    font-weight: 600;
}

.difficulty-selector {
    display: flex;
    gap: 4px;
}

.diff-btn {
    background: #e5dec9;
    color: var(--text-dark);
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.diff-btn.active {
    background: #8f7a66;
    color: #ffffff;
}

.diff-btn:hover:not(.active) {
    background: #d8cfb4;
}

/* 狀態面板 (時間與雷數) */
.status-panel {
    background: #bbada0;
    border-radius: 8px;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.status-box {
    background: #332d29;
    padding: 4px 10px;
    border-radius: 6px;
    min-width: 60px;
    text-align: center;
    border: 2px solid #8f7a66;
}

.status-label {
    font-size: 0.55rem;
    font-weight: 800;
    color: #eee4da;
    display: block;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.status-val {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1.25rem;
    font-weight: bold;
    color: #f2b179;
    display: block;
}

.smiley-btn {
    background: #e5dec9;
    border: 2px solid #8f7a66;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background-color 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.smiley-btn:active {
    transform: scale(0.9);
    background: #d8cfb4;
}

/* 模式選擇器 (挖地雷/插旗) */
.mode-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.mode-btn {
    flex: 1;
    background: #e5dec9;
    color: var(--text-dark);
    border: 2px solid #bbada0;
    border-radius: 6px;
    padding: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.mode-btn.active {
    background: #8f7a66;
    color: #ffffff;
    border-color: #7f6a56;
}

/* 遊戲網格區 */
.game-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 6px 0;
}

.mines-container {
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    grid-gap: var(--grid-gap);
    background: var(--bg-container);
    border-radius: 10px;
    padding: var(--grid-padding);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 100%;
}

.mine-cell {
    aspect-ratio: 1 / 1;
    background: #e5dec9;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.15rem;
    cursor: pointer;
    box-shadow: inset -2px -2px 0px rgba(0, 0, 0, 0.15), inset 2px 2px 0px rgba(255, 255, 255, 0.7);
    transition: background-color 0.1s, box-shadow 0.1s;
}

.mine-cell:active:not(.revealed):not(.flagged) {
    background: #ccc0b3;
    box-shadow: none;
}

/* 已開啟格子樣式 */
.mine-cell.revealed {
    background: #ccc0b3;
    box-shadow: none;
}

/* 插旗格子樣式 */
.mine-cell.flagged {
    color: #ff0000;
}

/* 踩雷格與爆炸格 */
.mine-cell.mine {
    background: #f65e3b;
    box-shadow: none;
}

.mine-cell.exploded {
    background: #f65e3b;
    box-shadow: 0 0 10px rgba(246, 94, 59, 0.8);
    animation: explodePulse 0.4s infinite alternate;
}

.mine-cell.flag-wrong {
    background: #ede0c8;
    position: relative;
}

.mine-cell.flag-wrong::after {
    content: "❌";
    font-size: 0.7rem;
    position: absolute;
    top: 1px;
    right: 1px;
}

/* 數字配色 */
.cell-1 { color: #2196F3; }
.cell-2 { color: #4CAF50; }
.cell-3 { color: #F44336; }
.cell-4 { color: #3F51B5; }
.cell-5 { color: #795548; }
.cell-6 { color: #00BCD4; }
.cell-7 { color: #000000; }
.cell-8 { color: #808080; }

/* 排行榜與 Modal 樣式 */
.leaderboard-section {
    background: var(--bg-container);
    border-radius: 8px;
    padding: 8px 12px;
    margin-top: 6px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.leaderboard-header h3 {
    font-size: 0.85rem;
    color: #eee4da;
    font-weight: 800;
    margin-bottom: 6px;
    text-align: center;
    letter-spacing: 0.5px;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    color: #ffffff;
}

.leaderboard-table th, .leaderboard-table td {
    padding: 4px 6px;
    text-align: center;
}

.leaderboard-table th {
    color: #eee4da;
    font-weight: 700;
    border-bottom: 1.5px solid rgba(238, 228, 218, 0.25);
}

.leaderboard-table td {
    border-bottom: 1px solid rgba(238, 228, 218, 0.12);
    font-weight: 600;
}

.leaderboard-table tr:last-child td {
    border-bottom: none;
}

.leaderboard-rank-1 { color: #f2b179; font-weight: 800; }
.leaderboard-rank-2 { color: #edcf72; font-weight: 800; }
.leaderboard-rank-3 { color: #eee4da; font-weight: 800; }

.game-instruction {
    font-size: 0.65rem;
    color: #8f7a66;
    line-height: 1.4;
    text-align: center;
    border-top: 1px solid #e5dec9;
    padding-top: 8px;
    margin-top: 4px;
}

/* Modal 覆蓋層與彈窗 */
.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(238, 228, 218, 0.73);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    z-index: 10;
    animation: fadeIn 0.3s ease-out;
}

.modal-card {
    background: #faf8ef;
    padding: 24px;
    border-radius: 12px;
    width: 85%;
    max-width: 310px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    border: 3px solid #bbada0;
    text-align: center;
    animation: pop 180ms ease-out;
}

.modal-card h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-dark);
    margin-bottom: 8px;
}

#player-name-input {
    width: 100%;
    padding: 10px;
    border: 2px solid #bbada0;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-dark);
    background: #ffffff;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

#player-name-input:focus {
    border-color: #8f7a66;
}

.primary-btn {
    background: #8f7a66;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 8px 20px;
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s, transform 0.1s;
}

.primary-btn:hover {
    background: #7f6a56;
}

.primary-btn:active {
    transform: scale(0.97);
}

.hidden {
    display: none !important;
}

/* Animations */
@keyframes explodePulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.08); box-shadow: 0 0 12px rgba(246, 94, 59, 1); }
}

@keyframes pop {
    0% { transform: scale(0.85); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

/* 行動端與響應式適配 */
@media (max-width: 520px) {
    :root {
        --grid-gap: 2px;
        --grid-padding: 4px;
        /* 小螢幕下，根據寬度動態計算最適合的單格尺寸，以適應 9, 12, 16 欄寬度 */
        --cell-size: calc((100vw - 32px - (var(--grid-padding) * 2) - (var(--grid-gap) * (var(--cols) - 1))) / var(--cols));
    }
    
    .app-container {
        padding: 8px 12px;
    }

    .logo-text {
        font-size: 1.6rem;
    }

    .subtitle-text {
        font-size: 0.65rem;
    }

    .status-panel {
        padding: 6px 12px;
        margin-bottom: 6px;
    }

    .status-box {
        min-width: 50px;
        padding: 2px 6px;
    }
    
    .status-val {
        font-size: 1.1rem;
    }

    .smiley-btn {
        width: 32px;
        height: 32px;
        font-size: 1.1rem;
    }

    .mode-selector {
        margin-bottom: 6px;
    }

    .mode-btn {
        padding: 6px;
        font-size: 0.78rem;
    }

    .mine-cell {
        font-size: 0.95rem;
        border-radius: 3px;
        box-shadow: inset -1.5px -1.5px 0px rgba(0, 0, 0, 0.15), inset 1.5px 1.5px 0px rgba(255, 255, 255, 0.7);
    }
    
    .leaderboard-section {
        padding: 6px 8px;
        margin-top: 4px;
    }
    
    .leaderboard-table {
        font-size: 0.7rem;
    }
    
    .leaderboard-table th, .leaderboard-table td {
        padding: 2px 3px;
    }

    .game-instruction {
        padding-top: 6px;
        margin-top: 4px;
        font-size: 0.6rem;
    }
}
