/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #e0e0e0;
    --text: #222;
    --header-bg: #f5f5f5;
    --header-border: #ccc;
    --frame-bg: #c0c0c0;
    --frame-highlight: #fff;
    --frame-shadow: #808080;
    --frame-dark-shadow: #404040;
    --cell-bg: #c0c0c0;
    --cell-revealed: #bdbdbd;
    --lcd-bg: #300;
    --lcd-color: #f00;
    --modal-bg: #fff;
    --modal-text: #222;
    --overlay-bg: rgba(0,0,0,0.4);
    --diff-btn-bg: #f0f0f0;
    --diff-btn-hover: #e0e0e0;
    --diff-btn-active-bg: #4a90d9;
    --diff-btn-active-text: #fff;
    --accent: #4a90d9;
}

[data-theme="dark"] {
    --bg: #1a1a2e;
    --text: #e0e0e0;
    --header-bg: #16213e;
    --header-border: #0f3460;
    --frame-bg: #6a6a6a;
    --frame-highlight: #999;
    --frame-shadow: #444;
    --frame-dark-shadow: #222;
    --cell-bg: #6a6a6a;
    --cell-revealed: #555;
    --lcd-bg: #200;
    --lcd-color: #c00;
    --modal-bg: #16213e;
    --modal-text: #e0e0e0;
    --overlay-bg: rgba(0,0,0,0.6);
    --diff-btn-bg: #2a2a4a;
    --diff-btn-hover: #3a3a5a;
    --diff-btn-active-bg: #4a90d9;
    --diff-btn-active-text: #fff;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-user-select: none;
    user-select: none;
    overflow-x: hidden;
}

body {
    display: flex;
    justify-content: center;
}

.app {
    width: 100%;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── Header ── */
.app-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
}

.app-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    transition: background 0.15s;
}

.icon-btn:hover { background: rgba(128,128,128,0.15); }

.icon-btn svg { width: 20px; height: 20px; }

[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ── Game Container ── */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 12px;
    gap: 16px;
    width: 100%;
}

/* ── Classic Minesweeper Frame ── */
.minesweeper-frame {
    background: var(--frame-bg);
    border-top: 3px solid var(--frame-highlight);
    border-left: 3px solid var(--frame-highlight);
    border-right: 3px solid var(--frame-dark-shadow);
    border-bottom: 3px solid var(--frame-dark-shadow);
    padding: 6px;
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
}

/* ── Top Panel (counter, face, timer) ── */
.top-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    border-top: 2px solid var(--frame-shadow);
    border-left: 2px solid var(--frame-shadow);
    border-right: 2px solid var(--frame-highlight);
    border-bottom: 2px solid var(--frame-highlight);
    background: var(--frame-bg);
}

/* ── LCD Display (mine count & timer) ── */
.lcd-display {
    background: var(--lcd-bg);
    color: var(--lcd-color);
    font-family: 'Courier New', monospace;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 2px;
    padding: 2px 4px;
    min-width: 56px;
    text-align: center;
    border-top: 2px solid var(--frame-shadow);
    border-left: 2px solid var(--frame-shadow);
    border-right: 1px solid var(--frame-highlight);
    border-bottom: 1px solid var(--frame-highlight);
    line-height: 1;
}

/* ── Smiley Face Button ── */
.face-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    background: var(--frame-bg);
    border-top: 2px solid var(--frame-highlight);
    border-left: 2px solid var(--frame-highlight);
    border-right: 2px solid var(--frame-shadow);
    border-bottom: 2px solid var(--frame-shadow);
    padding: 0;
}

.face-btn:active {
    border-top: 2px solid var(--frame-shadow);
    border-left: 2px solid var(--frame-shadow);
    border-right: 2px solid var(--frame-highlight);
    border-bottom: 2px solid var(--frame-highlight);
}

/* ── Mine Field Wrapper ── */
.field-wrapper {
    border-top: 3px solid var(--frame-shadow);
    border-left: 3px solid var(--frame-shadow);
    border-right: 3px solid var(--frame-highlight);
    border-bottom: 3px solid var(--frame-highlight);
    overflow: auto;
    max-width: calc(100vw - 40px);
}

.field {
    display: grid;
    background: var(--frame-bg);
}

/* ── Individual Cells ── */
.cell {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    background: var(--cell-bg);
    border-top: 2px solid var(--frame-highlight);
    border-left: 2px solid var(--frame-highlight);
    border-right: 2px solid var(--frame-shadow);
    border-bottom: 2px solid var(--frame-shadow);
    padding: 0;
    line-height: 1;
}

.cell:active:not(.revealed):not(.flagged) {
    border: 1px solid var(--frame-shadow);
    background: var(--cell-revealed);
}

.cell.revealed {
    border: 1px solid var(--frame-shadow);
    background: var(--cell-revealed);
    cursor: default;
}

.cell.flagged {
    font-size: 14px;
}

.cell.mine-hit {
    background: #f00;
    border: 1px solid var(--frame-shadow);
}

.cell.mine-revealed {
    border: 1px solid var(--frame-shadow);
    background: var(--cell-revealed);
}

.cell.mine-wrong {
    border: 1px solid var(--frame-shadow);
    background: var(--cell-revealed);
}

/* Number colors - classic Minesweeper */
.cell.n1 { color: #0000ff; }
.cell.n2 { color: #008000; }
.cell.n3 { color: #ff0000; }
.cell.n4 { color: #000080; }
.cell.n5 { color: #800000; }
.cell.n6 { color: #008080; }
.cell.n7 { color: #000; }
.cell.n8 { color: #808080; }

[data-theme="dark"] .cell.n1 { color: #6b9fff; }
[data-theme="dark"] .cell.n2 { color: #4caf50; }
[data-theme="dark"] .cell.n3 { color: #ff5252; }
[data-theme="dark"] .cell.n4 { color: #7986cb; }
[data-theme="dark"] .cell.n5 { color: #ef5350; }
[data-theme="dark"] .cell.n6 { color: #4dd0e1; }
[data-theme="dark"] .cell.n7 { color: #e0e0e0; }
[data-theme="dark"] .cell.n8 { color: #bbb; }

/* ── Difficulty Bar ── */
.difficulty-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.diff-btn {
    padding: 8px 20px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    border: 1px solid var(--header-border);
    border-radius: 8px;
    background: var(--diff-btn-bg);
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.diff-btn:hover { background: var(--diff-btn-hover); }

.diff-btn.active {
    background: var(--diff-btn-active-bg);
    color: var(--diff-btn-active-text);
    border-color: var(--diff-btn-active-bg);
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--modal-bg);
    color: var(--modal-text);
    border-radius: 16px;
    padding: 32px 28px;
    text-align: center;
    max-width: 340px;
    width: 90%;
    box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}

.win-icon { font-size: 48px; margin-bottom: 8px; }
.modal-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 4px; }
.modal-subtitle { font-size: 0.9rem; opacity: 0.7; margin-bottom: 16px; }

.win-stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-bottom: 20px;
}

.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; opacity: 0.6; text-transform: uppercase; letter-spacing: 0.5px; }

.play-again-btn {
    width: 100%;
    padding: 12px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: opacity 0.15s;
}

.play-again-btn:hover { opacity: 0.9; }

/* ── Responsive ── */
@media (max-width: 480px) {
    .cell {
        width: 20px;
        height: 20px;
        font-size: 11px;
    }
    .lcd-display {
        font-size: 22px;
        min-width: 46px;
    }
    .face-btn {
        width: 30px;
        height: 30px;
        font-size: 18px;
    }
}
