/* ═══════════════════════════════════════════
   踩地雷 Minesweeper — Style
   ═══════════════════════════════════════════ */

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

body {
    font-family: 'Segoe UI', 'Noto Sans TC', Arial, sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

/* ═══ 設定面板 ═══ */
#settings-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    padding: 20px;
}

.settings-box {
    background: #16213e;
    border-radius: 16px;
    padding: 40px 36px;
    max-width: 460px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,.4);
    text-align: center;
}

.settings-box h1 {
    font-size: 2.2rem;
    margin-bottom: 4px;
    color: #fff;
}

.settings-box .sub {
    color: #8892b0;
    font-size: .95rem;
    margin-bottom: 24px;
}

/* 預設按鈕 */
.preset-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 28px;
}

.btn-preset {
    flex: 1;
    padding: 14px 8px;
    background: #0f3460;
    border: 2px solid #1a5276;
    border-radius: 10px;
    color: #ccd6f6;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
}

.btn-preset:hover {
    background: #1a5276;
    border-color: #e94560;
    transform: translateY(-2px);
}

.btn-preset small {
    font-weight: 400;
    color: #8892b0;
    font-size: .75rem;
}

/* 自訂設定 */
.custom-settings {
    border-top: 1px solid #233554;
    padding-top: 20px;
}

.custom-settings h3 {
    color: #ccd6f6;
    margin-bottom: 16px;
    font-size: 1rem;
}

.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.field-row label {
    color: #8892b0;
    font-size: .9rem;
}

.field-row input {
    width: 90px;
    padding: 8px 10px;
    background: #0a192f;
    border: 1px solid #233554;
    border-radius: 6px;
    color: #e6f1ff;
    font-size: 1rem;
    text-align: center;
    outline: none;
}

.field-row input:focus {
    border-color: #e94560;
}

/* 通用按鈕 */
.btn {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
}

.btn-primary {
    background: #e94560;
    color: #fff;
    margin-top: 8px;
    width: 100%;
    padding: 12px;
}

.btn-primary:hover { background: #c73e54; }

.btn-secondary {
    background: #233554;
    color: #ccd6f6;
}

.btn-secondary:hover { background: #2d4466; }

/* ═══ 遊戲畫面 ═══ */
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    min-height: 100vh;
    width: 100%;
}

/* 工具列 */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 600px;
    padding: 12px 0;
    margin-bottom: 8px;
}

.toolbar-left, .toolbar-right { flex: 1; }
.toolbar-right { text-align: right; }
.toolbar-center { flex: 0 0 auto; }

.counter {
    display: inline-block;
    background: #0a0a0a;
    color: #e94560;
    font-family: 'Courier New', monospace;
    font-size: 1.6rem;
    font-weight: bold;
    padding: 6px 12px;
    border-radius: 6px;
    min-width: 70px;
    text-align: center;
    letter-spacing: 2px;
    border: 2px inset #333;
}

.face-btn {
    font-size: 2rem;
    background: #16213e;
    border: 2px solid #233554;
    border-radius: 10px;
    padding: 4px 12px;
    cursor: pointer;
    transition: transform .1s;
    line-height: 1.2;
}

.face-btn:hover { transform: scale(1.1); }
.face-btn:active { transform: scale(0.95); }

/* 棋盤外框 */
#board-wrapper {
    overflow: auto;
    max-width: 95vw;
    max-height: calc(100vh - 170px);
    border: 3px solid #233554;
    border-radius: 8px;
    background: #0d1b30;
}

/* 棋盤 */
#board {
    border-collapse: collapse;
}

#board td {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    text-align: center;
    vertical-align: middle;
    font-size: .9rem;
    font-weight: 700;
    border: 1px solid #1a2744;
    cursor: pointer;
    transition: background .1s;
    line-height: 32px;
    padding: 0;
}

/* 未翻開 */
td.cell-hidden {
    background: linear-gradient(145deg, #1e3a5f, #162d4a);
    box-shadow: inset 1px 1px 0 rgba(255,255,255,.06),
                inset -1px -1px 0 rgba(0,0,0,.2);
}

td.cell-hidden:hover {
    background: linear-gradient(145deg, #264b73, #1e3a5f);
}

td.cell-hidden:active {
    background: #162d4a;
    box-shadow: inset 2px 2px 4px rgba(0,0,0,.3);
}

/* 已翻開 */
td.cell-revealed {
    background: #0d1b30;
    cursor: default;
}

/* 數字顏色 */
td[data-num="1"] { color: #4fc3f7; }
td[data-num="2"] { color: #66bb6a; }
td[data-num="3"] { color: #ef5350; }
td[data-num="4"] { color: #ab47bc; }
td[data-num="5"] { color: #ff7043; }
td[data-num="6"] { color: #26c6da; }
td[data-num="7"] { color: #ec407a; }
td[data-num="8"] { color: #bdbdbd; }

/* 旗子 */
td.cell-flagged {
    background: linear-gradient(145deg, #1e3a5f, #162d4a);
    font-size: 1.1rem;
}

/* 地雷 */
td.cell-mine {
    background: #3a0f0f;
    font-size: 1.1rem;
}

td.cell-mine-hit {
    background: #e94560;
    font-size: 1.1rem;
}

/* 底部 */
.bottom-bar {
    margin-top: 12px;
    padding: 8px 0 20px;
}

/* ═══ 結果彈窗 ═══ */
#result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.result-box {
    background: #16213e;
    border-radius: 16px;
    padding: 36px 40px;
    text-align: center;
    max-width: 360px;
    width: 100%;
    box-shadow: 0 12px 40px rgba(0,0,0,.5);
    animation: popIn .3s ease;
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

#result-icon { font-size: 3.5rem; margin-bottom: 12px; }
#result-text { font-size: 1.4rem; font-weight: 700; color: #fff; margin-bottom: 6px; }
#result-time { color: #8892b0; font-size: .95rem; margin-bottom: 24px; }

.result-buttons {
    display: flex;
    gap: 10px;
}

.result-buttons .btn {
    flex: 1;
    padding: 12px 16px;
}

.result-buttons .btn-primary { margin-top: 0; width: auto; }

/* ═══ RWD 響應式 ═══ */
@media (max-width: 480px) {
    .settings-box { padding: 28px 20px; }
    .preset-buttons { flex-direction: column; }
    #board td { width: 28px; height: 28px; min-width: 28px; min-height: 28px; font-size: .8rem; line-height: 28px; }
    .counter { font-size: 1.3rem; min-width: 58px; }
    .face-btn { font-size: 1.6rem; }
    .result-box { padding: 28px 24px; }
}

@media (max-width: 360px) {
    #board td { width: 24px; height: 24px; min-width: 24px; min-height: 24px; font-size: .7rem; line-height: 24px; }
}
