/***************/
/* Minesweeper */
/***************/
:root {
    --bg-gray: #bdbdbd;
    --bg-light: #c0c0c0;
    --bg-empty: #dcdcdc;
    --border-light: #fff;
    --border-dark: #7b7b7b;
    --border-inner: #e0e0e0;
    --cell-size: 70px;
    --text-red: #ff2626;
    --text-dark: #222;
}

/* --- */

/****************/
/* BODY / TITLE */
/****************/
body {
    align-items: center;
    background: var(--bg-gray);
    cursor: default;
    display: flex;
    font-family: 'Tahoma', Arial, sans-serif;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
}

.minesweeper-title {
    background: #e0e0e0;
    border: 2px solid #999;
    border-radius: 8px;
    box-shadow: 1px 1px 4px #aaa;
    color: #333;
    font-size: 2em;
    font-family: 'Tahoma', Arial, sans-serif;
    font-weight: bold;
    margin-bottom: 24px;
    padding: 10px 20px;
    text-shadow: 1px 1px 0 #fff;
    text-align: center;
    width: 15em;
}

/* --- */

/*************/
/* DARK MODE */
/*************/
body.dark-mode {
    --bg-gray: #2b2b2b;
    --bg-light: #3a3a3a;
    --bg-empty: #4a4a4a;
    --border-light: #666;
    --border-dark: #000;
    --text-dark: #eee;
    --text-red: #ff6b6b;
    background-color: var(--bg-gray);
}

body.dark-mode .minesweeper-toggle-theme-btn {
    background-color: #f5f5f5;
    color: #000;
}

body.dark-mode .minesweeper-reset-best-btn {
    color: #ccc;
    opacity: 0.6;
}

body.dark-mode .minesweeper-reset-best-btn:hover {
    opacity: 1;
}

body.dark-mode .minesweeper-best-score {
    color: #f5f5f5;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
}

body.dark-mode .minesweeper-safe-clicks-count {
    color: #f5f5f5;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
}

body.dark-mode .minesweeper-game-footer {
    border-top: 1px solid #555;
    background-color: #1e1e1e;
    color: #ccc;
}

.minesweeper-toggle-theme-btn {
    align-items: center;
    border: none;
    border-radius: 8px;
    background-color: #2c2c2c;
    color: #fff;
    cursor: pointer;
    display: flex;
    font-weight: bold;
    font-size: 1.6em;
    justify-content: center;
    left: 20px;
    padding: 20px 40px;
    position: absolute;
    top: 20px;
    transition: background-color 0.3s;
}

/* --- */

/**************/
/* BEST SCORE */
/**************/
.minesweeper-best-score {
    align-items: center;
    box-sizing: border-box;
    color: #222;
    display: flex;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 1.1em;
    font-weight: bold;
    justify-content: space-between;
    letter-spacing: 1px;
    margin-bottom: 25px;
    max-width: 446px; /* Align the Best Score (left) and Reset button (right) to match the width of the level selector buttons below */
    text-align: center;
    text-shadow: 0 1px 0 #fff;
    width: 100%;
}

.minesweeper-best-score .minesweeper-reset-best-btn {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 2em;
    opacity: 0.6;
    transition: opacity 0.5s;
}

.minesweeper-best-score .minesweeper-reset-best-btn:hover {
    opacity: 1;
}

.minesweeper-best-score .minesweeper-reset-best-btn.disabled {
    cursor: default;
    opacity: 0.2;
}

/* --- */

/**********/
/* LEVELS */
/**********/
.minesweeper-level-selector {
    display: flex;
    font-family: 'Tahoma', Arial, sans-serif;
    font-size: 1em;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
}

.minesweeper-level-selector label {
    background-color: #e0e0e0;
    border: 2px solid #aaa;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    min-width: 110px;            
    padding: 6px 12px;
    transition: background 0.2s, transform 0.2s;
    user-select: none;
}

.minesweeper-level-selector input[type="radio"] {
    accent-color: #ff2626;
    margin-right: 6px;
}

.minesweeper-level-selector label:hover {
    background-color: #d0d0d0;
    transform: scale(1.05);
}

.minesweeper-level-selector label:has(input:checked) {
    background-color: #d4ffd4;
    border-color: #00aa00;
    transform: scale(1.05);
}

.minesweeper-level-selector input[type="radio"]:disabled + label,
.minesweeper-level-selector label:has(input:disabled) {
    cursor: not-allowed;
    opacity: 0.5;
    pointer-events: none;
}

/* --- */

/*****************/
/* LIVES / HINTS */
/*****************/
.minesweeper-lives-and-hints {
    align-items: center;
    box-sizing: border-box;
    display: flex;
    font-size: 1.8em;
    justify-content: space-between;
    margin-bottom: 20px;
    width: 100%;
}

.minesweeper-lives-and-hints .minesweeper-hint {
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.3s;
}

.minesweeper-lives-and-hints .minesweeper-hint.active {
    background: yellow;
}

.minesweeper-lives-and-hints .minesweeper-hint.used {
    cursor: default;
    opacity: 0.2;
    pointer-events: none;
}

/* --- */

/*********************************/
/* BOARD / MINES COUNTER / TIMER */
/*********************************/
.minesweeper-game-container {
    align-items: center;
    display: flex;
    flex-direction: column;
    position: relative;
}

.minesweeper-game-container.with-message {
    padding-bottom: 20px;
}

.minesweeper-container {
    border: 3px solid var(--border-light);
    box-shadow: 2px 2px 6px #8884;
    background: var(--bg-gray);
    border-right-color: var(--border-dark);
    border-bottom-color: var(--border-dark);
    display: inline-block;
    padding: 10px;
}

.minesweeper-header {
    align-items: center;
    border: 2px solid var(--border-light);
    background: var(--bg-light);
    border-right-color: var(--border-dark);
    border-bottom-color: var(--border-dark);
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 8px 10px;
}

.minesweeper-counter,
.minesweeper-timer {
    align-items: center;
    border: 2px inset var(--text-dark);
    background: var(--text-dark);
    border-radius: 4px;
    color: var(--text-red);
    display: flex;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 2.2em;
    height: 42px;
    justify-content: center;
    letter-spacing: 2px;
    overflow: hidden;
    padding: 0 5px;
    text-shadow: 0 0 8px #f00;
    width: 80px;
}

.minesweeper-face {
    align-items: center;
    border: 3px outset var(--border-light);
    box-shadow: 1px 1px 0 var(--border-light), inset 2px 2px 5px #aaa;
    background: var(--border-inner);
    border-bottom-color: var(--border-dark);
    border-right-color: var(--border-dark);
    border-radius: 7px;
    cursor: pointer;
    display: flex;
    font-size: 1.8em;
    height: var(--cell-size);
    justify-content: center;
    margin: 0 16px;
    padding: 0;
    transition: background 0.1s;
    user-select: none;
    width: var(--cell-size);
}

.minesweeper-face:active {
    border: 3px inset #bbb;
    background: var(--bg-gray);
}

.minesweeper-board table {
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-gray);
    margin: 0 auto;
    width: 100%;
}

.minesweeper-board td {
    background: var(--bg-light);
    box-sizing: border-box;
    border-top: 3px solid var(--border-light);
    border-left: 3px solid var(--border-light);
    border-bottom: 3px solid var(--border-dark);
    border-right: 3px solid var(--border-dark);
    cursor: default !important;
    font-size: 2em;
    font-weight: bold;
    height: var(--cell-size);
    overflow: hidden;
    text-align: center;
    transition: background 0.08s, border 0.12s;
    user-select: none;
    vertical-align: middle;
    width: var(--cell-size);
}

/* --- */

/***************/
/* CELL STATES */
/***************/
.minesweeper-board td.cell-empty {
    background: var(--bg-empty);
    border-top:    1px solid var(--border-dark);
    border-left:   1px solid var(--border-dark);
    border-bottom: 1px solid var(--border-inner);
    border-right:  1px solid var(--border-inner);
    box-shadow: inset 0 0 2px #aaa;
    color: transparent;
}

.minesweeper-board td.cell-flag {
    font-size: 1.5em;
    opacity: 0.88;
}

.minesweeper-board td.cell-mine {
    background: #ffcdcd;
    font-size: 1.5em;
    line-height: 1;
    opacity: 0.88;
    padding: 0;
    text-align: center;
    transition: background-color 0.5s ease;
    vertical-align: middle;
}

.minesweeper-board td.cell-mine.fadeout {
    background-color: transparent;
    color: transparent;
}

.minesweeper-board td.cell-mine-clicked {
    background-color: #e60000;
    color: var(--text-dark);
    font-size: 1.5em;
    line-height: 1;
    opacity: 1;
    padding: 0;
    text-align: center;
    transition: background-color 0.4s ease;
    vertical-align: middle;
}

.minesweeper-board td.cell-number {
    background: var(--border-inner);
    font-size: 1.5em;
    opacity: 0.88;
}

.minesweeper-board td.cell-temp-reveal {
    background: #ffffd0;
    font-size: 1.5em;
    transition: background-color 0.5s ease;
}

.minesweeper-board td.cell-temp-reveal.fadeout {
    background-color: transparent;
    color: transparent;
}

/* --- */

/**********************/
/* COLORS FOR NUMBERS */
/**********************/
.minesweeper-board .cell-1 { color: #0048ff; }
.minesweeper-board .cell-2 { color: #138a13; }
.minesweeper-board .cell-3 { color: #ff2626; }
.minesweeper-board .cell-4 { color: #00008b; }
.minesweeper-board .cell-5 { color: #8b0000; }
.minesweeper-board .cell-6 { color: #008b8b; }
.minesweeper-board .cell-7 { color: #000; }
.minesweeper-board .cell-8 { color: var(--border-dark); }

/* --- */

/**************/
/* SAFE CLICK */
/**************/
.minesweeper-control-buttons-container {
    align-items: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 25px;
    margin-bottom: 40px;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons {
    align-items: flex-start;
    display: flex;
    gap: 50px;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-safe-click-btn {
    border: none;
    border-radius: 12px;
    background-color: #00aaff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    color: white;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: bold;
    padding: 14px 26px;
    transition: background-color 0.3s ease;
    text-align: center;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-safe-click-btn:hover {
    background-color: #008fcc;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-safe-click-btn:disabled,
.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-safe-click-btn:disabled:hover,
.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-safe-click-btn:disabled:focus {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background-color: #00aaff;
    cursor: default;
    filter: none;
    opacity: 0.4;
}

.minesweeper-control-buttons-container .minesweeper-safe-clicks-count {
    color: #222;
    font-size: 1.1em;
    font-weight: bold;
    font-family: 'Segoe UI', 'Tahoma', sans-serif;
    margin-top: 15px;
    text-align: center;
    text-shadow: 0 1px 0 #fff;
}

.minesweeper-board td.cell-safe-click {
    background-color: #c8f7c5;
    box-shadow: 0 0 10px #4caf50;
    font-size: 1.5em;
    transition: background-color 0.6s, box-shadow 0.6s;
}

.minesweeper-board td.cell-safe-click.fadeout {
    box-shadow: none;
    background-color: transparent;
    color: transparent;
}

/* --- */

/********/
/* UNDO */
/********/
.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-undo-btn {
    border: none;
    border-radius: 12px;
    background-color: #ff8c00;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    color: white;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: bold;
    padding: 14px 26px;
    transition: background-color 0.3s ease;
    text-align: center;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-undo-btn:hover {
    background-color: #e67e00;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-undo-btn:disabled {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background-color: #e67e00;
    cursor: default;
    filter: none;
    opacity: 0.4;
}

/* --- */

/***************/
/* MANUAL MODE */
/***************/
.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-manual-mode-btn {
    border: none;
    border-radius: 12px;
    background-color: #009688;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    color: white;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: bold;
    padding: 14px 26px;
    transition: background-color 0.3s ease;
    text-align: center;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-manual-mode-btn:hover {
    background-color: #00796b;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-manual-mode-btn:disabled {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background-color: #00796b;
    cursor: default;
    filter: none;
    opacity: 0.4;
}

/* --- */

/*************/
/* MEGA HINT */
/*************/
.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-mega-hint-btn {
    border: none;
    border-radius: 12px;
    background-color: #673ab7;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    color: white;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: bold;
    padding: 14px 26px;
    transition: background-color 0.3s ease;
    text-align: center;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-mega-hint-btn:hover {
    background-color: #512da8;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-mega-hint-btn:disabled {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background-color: #512da8;
    cursor: default;
    filter: none;
    opacity: 0.4;
}

/* --- */

/****************/
/* EXTERMINATOR */
/****************/
.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-exterminator-btn {
    border: none;
    border-radius: 12px;
    background-color: #e53935;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    color: white;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: bold;
    padding: 14px 26px;
    transition: background-color 0.3s ease;
    text-align: center;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-exterminator-btn:hover {
    background-color: #c62828;
}

.minesweeper-control-buttons-container .minesweeper-inline-buttons .minesweeper-exterminator-btn:disabled {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background-color: #c62828;
    cursor: default;
    filter: none;
    opacity: 0.4;
}

/* --- */

/***********/
/* MESSAGE */
/***********/
.minesweeper-message {
    bottom: -40px;
    color: var(--text-red);
    display: none;
    font-size: 1.2em;
    font-weight: bold;
    left: 50%;
    line-height: 24px;
    position: absolute;
    text-align: center;
    text-overflow: ellipsis;
    transform: translateX(-50%);
    transition: opacity 0.3s ease;
    white-space: nowrap;
    z-index: 10;
}

.minesweeper-message.active {
    display: block;
}

.minesweeper-message .minesweeper-hint-message {
    color: green;
}

.with-message ~ .minesweeper-control-buttons-container {
  margin-top: 40px;
}

/* --- */

/**********/
/* FOOTER */
/**********/
.minesweeper-game-footer {
    border-top: 1px solid #999;
    background: inherit;
    color: #444;
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: auto;
    padding-top: 20px;
    padding-bottom: 15px;
    text-align: center;
    width: 100%;
}