*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    /* --- THÈME: MODERNE (Défaut) --- */
    --bg-body: #eef2f7;
    --bg-container: #ffffff;
    --bg-hud: #f8f9fa;
    --text-color: #2c3e50;
    --text-secondary: #7f8c8d;
    --primary-color: #4a90e2;
    --primary-hover: #357abd;
    --secondary-color: #f39c12;
    --danger-color: #e74c3c;
    --success-color: #2ecc71;
    --focus-color: #f1c40f;

    --cell-hidden: #6c7a89;
    --cell-hidden-hover: #7f8c9a;
    --cell-revealed: #ecf0f1;
    --border-color: #e0e0e0;

    --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    --radius: 16px;
    --font-main: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    --cell-border: 1px solid transparent;
    --cell-size: 30px;
    --grid-gap: 2px;
}

/* --- THÈME: RÉTRO 95 --- */
[data-theme="retro"] {
    --bg-body: #008080;
    --bg-container: #c0c0c0;
    --bg-hud: #c0c0c0;
    --text-color: #000000;
    --text-secondary: #444;
    --primary-color: #000080;
    --primary-hover: #1010a0;
    --secondary-color: #800000;
    --danger-color: #ff0000;
    --success-color: #008000;
    --focus-color: #ffff00;

    --cell-hidden: #c0c0c0;
    --cell-hidden-hover: #d0d0d0;
    --cell-revealed: #9e9e9e;
    --border-color: #808080;
    --shadow: 4px 4px 0px #000;
    --radius: 0px;
    --font-main: 'Courier New', monospace;
    --cell-border: 2px outset #ffffff;
}

/* --- THÈME: CYBERPUNK --- */
[data-theme="cyber"] {
    --bg-body: #050510;
    --bg-container: #0a0a1f;
    --bg-hud: #11112b;
    --text-color: #00ffea;
    --text-secondary: #bd00ff;
    --primary-color: #bd00ff;
    --primary-hover: #d54dff;
    --secondary-color: #ff0055;
    --danger-color: #ff0055;
    --success-color: #00ff00;
    --focus-color: #f1c40f;

    --cell-hidden: #1a1a3a;
    --cell-hidden-hover: #252550;
    --cell-revealed: #050510;
    --border-color: #00ffea;
    --shadow: 0 0 20px rgba(0, 255, 234, 0.2);
    --radius: 4px;
    --font-main: 'Verdana', sans-serif;
    --cell-border: 1px solid #00ffea33;
    --grid-gap: 4px;
}

/* --- THÈME: NATURE --- */
[data-theme="nature"] {
    --bg-body: #d4eac8;
    --bg-container: #f1f8e9;
    --bg-hud: #e8f5e9;
    --text-color: #33691e;
    --text-secondary: #558b2f;
    --primary-color: #558b2f;
    --primary-hover: #33691e;
    --secondary-color: #ff6f00;
    --danger-color: #d84315;
    --success-color: #7cb342;
    --focus-color: #ffeb3b;

    --cell-hidden: #aed581;
    --cell-hidden-hover: #9ccc65;
    --cell-revealed: #dcedc8;
    --border-color: #c5e1a5;
    --shadow: 0 10px 20px rgba(51, 105, 30, 0.15);
    --radius: 16px;
    --font-main: 'Georgia', serif;
    --cell-border: 1px dashed #558b2f44;
}

/* --- THÈME: BONBON --- */
[data-theme="candy"] {
    --bg-body: #ffe6f2;
    --bg-container: #fff0f6;
    --bg-hud: #ffe3f1;
    --text-color: #d63384;
    --text-secondary: #f783ac;
    --primary-color: #ff6b6b;
    --primary-hover: #fa5252;
    --secondary-color: #ffd43b;
    --danger-color: #ff6b6b;
    --success-color: #20c997;
    --focus-color: #ffe066;

    --cell-hidden: #ffdeeb;
    --cell-hidden-hover: #fcc2d7;
    --cell-revealed: #ffffff;
    --border-color: #fcc2d7;
    --shadow: 5px 5px 0px #faa2c1;
    --radius: 25px;
    --font-main: 'Comic Sans MS', 'Chalkboard SE', sans-serif;
    --cell-border: 2px solid #fff;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    padding: 12px;
    overflow-x: hidden;
    overflow-y: auto;
    transition: background-color 0.25s ease, color 0.25s ease;
}

input,
select,
textarea {
    user-select: text;
    -webkit-user-select: text;
}

.game-wrapper {
    background-color: var(--bg-container);
    padding: 18px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 10;
    transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
    max-width: 100%;
    margin: auto;
    border: 1px solid var(--border-color);
}

/* --- Header (Top Bar) --- */
.header {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.header-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.app-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.top-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

/* --- Configuration Bar --- */
.config-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    gap: 10px;
    flex-wrap: wrap;
}

.level-group {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 1;
}

.seed-group {
    font-family: monospace;
    font-size: 0.8em;
    color: var(--text-secondary);
    cursor: pointer;
    background: var(--bg-hud);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.seed-group:hover {
    border-color: var(--primary-color);
}

/* --- HUD (Heads-Up Display) --- */
.hud {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    background-color: var(--bg-hud);
    padding: 10px 15px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 15px;
    box-sizing: border-box;
}

[data-theme="retro"] .hud {
    border: 2px inset #fff;
    border-radius: 0;
}

.hud-counter {
    font-size: 1.45em;
    font-weight: 800;
    font-family: monospace;
    font-variant-numeric: tabular-nums;
    min-width: 82px;
    text-align: center;
    color: var(--danger-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.hud-counter.time {
    color: var(--text-color);
}

.stat-icon {
    font-size: 0.8em;
}

/* --- Action Bar (Under Grid) --- */
.action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 15px;
    width: 100%;
}

/* --- Generic Inputs & Buttons --- */
select,
input[type="text"],
input[type="number"],
input[type="password"] {
    padding: 7px 10px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-hud);
    color: var(--text-color);
    font-size: 14px;
    cursor: pointer;
    outline: none;
    font-family: var(--font-main);
}

.btn {
    padding: 0 12px;
    height: 38px;
    background-color: var(--bg-hud);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font-main);
}

[data-theme="retro"] select,
[data-theme="retro"] input[type="text"],
[data-theme="retro"] input[type="number"],
[data-theme="retro"] input[type="password"] {
    border-radius: 0;
}

[data-theme="retro"] .btn {
    border: 2px outset #fff;
    border-radius: 0;
    background: #c0c0c0;
}

[data-theme="retro"] .btn:active {
    border: 2px inset #fff;
}

.btn:hover {
    background-color: var(--bg-body);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn:active {
    transform: translateY(1px);
}

.btn.primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
}

.btn.primary:hover {
    background-color: var(--primary-hover);
    color: white;
}

.btn-icon {
    width: 38px;
    padding: 0;
    font-size: 1.05em;
}

.btn-pause.active {
    background-color: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
}

.btn-hub {
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    padding: 0 12px;
    height: 34px;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-hub:hover {
    background-color: var(--primary-color);
    color: #fff;
}

.btn-logout {
    font-size: 12px;
    padding: 0 9px;
    height: 30px;
}

.auto-login-status {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px 0;
    font-weight: 700;
    color: var(--text-color);
}

html.auto-logging-in #login-form {
    display: none !important;
}

html.auto-logging-in #auto-login-status {
    display: flex;
}

/* --- Grid --- */
.grid-stage {
    position: relative;
    max-width: 100%;
    border-radius: var(--radius);
    overflow: hidden;
}

[data-theme="retro"] .grid-stage {
    border-radius: 0;
}

#grid-container {
    position: relative;
    padding: 8px;
    background: var(--bg-hud);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    max-width: 100%;
    max-height: 65dvh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

[data-theme="retro"] #grid-container {
    border-radius: 0;
    border: 2px inset #fff;
    padding: 2px;
}

#grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 9), var(--cell-size));
    gap: var(--grid-gap);
    user-select: none;
    outline: none;
    margin: 0 auto;
    width: max-content;
}

.pause-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg-container);
    opacity: 0.96;
    display: none;
    flex-direction: column;
    gap: 6px;
    justify-content: center;
    align-items: center;
    font-size: 2em;
    font-weight: 800;
    color: var(--text-color);
    z-index: 50;
    border-radius: var(--radius);
    cursor: pointer;
    backdrop-filter: blur(4px);
}

.pause-overlay.visible {
    display: flex;
}

.pause-sub {
    font-size: 0.42em;
    font-weight: 500;
    opacity: 0.8;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background-color: var(--cell-hidden);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.1s ease, background-color 0.18s ease;
    border: var(--cell-border);
}

[data-theme="retro"] .cell {
    border-radius: 0;
    border-top: 2px solid #fff;
    border-left: 2px solid #fff;
    border-right: 2px solid #808080;
    border-bottom: 2px solid #808080;
}

[data-theme="retro"] .cell.revealed {
    border: 1px solid #808080;
    background-color: var(--cell-revealed);
}

[data-theme="retro"] .cell.flagged {
    color: #800000;
    font-weight: 900;
}

.cell:hover:not(.revealed):not(.flagged) {
    background-color: var(--cell-hidden-hover);
    transform: translateY(-1px);
}

.cell.revealed {
    background-color: var(--cell-revealed);
    cursor: default;
    transform: none;
    animation: fadeIn 0.3s ease-out;
}

.cell.revealed.clickable {
    cursor: pointer;
}

.cell.revealed.clickable:hover {
    filter: brightness(0.9);
}

/* Highlight effect (Voisins) */
.cell.highlight {
    box-shadow: inset 0 0 0 3px var(--focus-color), 0 0 8px var(--focus-color) !important;
    z-index: 20;
    transform: scale(1.08);
}

[data-theme="retro"] .cell.highlight {
    border: 2px inset #fff;
    box-shadow: none !important;
    background-color: var(--focus-color);
    transform: none;
}

/* Focus effect (Souris) */
.cell.focus {
    box-shadow: inset 0 0 0 3px var(--focus-color) !important;
    z-index: 5;
    transform: scale(1.05);
}

.cell.mine {
    background-color: var(--danger-color);
    color: white;
    animation: shake 0.5s;
}

.cell.flagged {
    color: var(--danger-color);
}

/* Hint Animation */
@keyframes hintFlash {
    0% { background-color: var(--success-color); transform: scale(1.1); }
    50% { background-color: var(--cell-hidden); transform: scale(1); }
    100% { background-color: var(--success-color); transform: scale(1.1); }
}

.cell.hint-active {
    animation: hintFlash 1s ease-in-out infinite;
    z-index: 5;
}

/* Colors */
.c1 { color: #3498db; }
.c2 { color: #2ecc71; }
.c3 { color: #e74c3c; }
.c4 { color: #9b59b6; }
.c5 { color: #f1c40f; }
.c6 { color: #1abc9c; }
.c7 { color: var(--text-color); }
.c8 { color: var(--text-secondary); }

[data-theme="retro"] .c1 { color: #0000ff; }
[data-theme="retro"] .c2 { color: #008000; }
[data-theme="retro"] .c3 { color: #ff0000; }
[data-theme="cyber"] .c1 { color: #00ffff; text-shadow: 0 0 5px #00ffff; }
[data-theme="cyber"] .c2 { color: #00ff00; text-shadow: 0 0 5px #00ff00; }
[data-theme="cyber"] .c3 { color: #ff0055; text-shadow: 0 0 5px #ff0055; }

/* Mobile */
.mobile-controls {
    display: none;
    margin-top: 15px;
    gap: 10px;
    width: 100%;
}

.mode-toggle {
    flex: 1;
    padding: 12px;
    text-align: center;
    background: var(--bg-hud);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1.1em;
    cursor: pointer;
    color: var(--text-color);
}

.mode-toggle.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

@media (max-width: 768px) {
    :root { --cell-size: 34px; }
    .mobile-controls { display: flex; }
    .cell { font-size: 20px; }
}

@media (max-width: 600px) {
    body { padding: 8px; }
    .game-wrapper { padding: 12px; width: 100%; }
    .header { gap: 8px; margin-bottom: 10px; padding-bottom: 10px; }
    .hud { padding: 8px 12px; }
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--bg-container);
    color: var(--text-color);
    padding: 26px;
    border-radius: 18px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    transform: scale(0.95);
    transition: transform 0.25s ease;
    max-width: 420px;
    width: 92%;
    max-height: 88dvh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

[data-theme="retro"] .modal-content {
    border-radius: 0;
    border: 3px outset #fff;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.input-group {
    margin: 15px 0;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.input-group input {
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-hud);
    color: var(--text-color);
    box-sizing: border-box;
}

.leaderboard-list {
    list-style: none;
    padding: 0;
    text-align: left;
    margin-top: 12px;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.score-time {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--primary-color);
}

/* Leaderboard Tabs & Filter Toggle */
.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.tab {
    flex: 1;
    padding: 8px 12px;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text-color);
}

.tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.lb-filter-row {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.lb-filter-btn {
    flex: 1;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-hud);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-main);
}

.lb-filter-btn.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-box {
    background: var(--bg-hud);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.stat-value {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--primary-color);
    display: block;
}

.stat-label {
    font-size: 0.9em;
    color: var(--text-secondary);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    background-color: #f00;
    animation: fall linear forwards;
    z-index: 999;
}

@keyframes fall {
    to { transform: translateY(100vh) rotate(720deg); }
}

.particle {
    position: absolute;
    pointer-events: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: pop 0.6s ease-out forwards;
}

@keyframes pop {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* Login Info Display */
.player-info {
    font-size: 0.85em;
    font-weight: 700;
    color: var(--primary-color);
    background: var(--bg-hud);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 999px;
}

/* Admin Styles */
#admin-panel {
    max-width: 800px;
    margin: 0 auto;
}

.admin-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    align-items: flex-end;
}

.admin-table-container {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-hud);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.admin-table th,
.admin-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
}

.admin-table th {
    background: var(--bg-body);
    position: sticky;
    top: 0;
    z-index: 1;
    font-weight: 600;
    color: var(--text-secondary);
}

.admin-table tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.btn-small { padding: 4px 8px; font-size: 0.85em; }
.btn-icon-only { padding: 6px; font-size: 1.1em; border: none; background: transparent; cursor: pointer; }
.btn-icon-only:hover { background-color: rgba(0, 0, 0, 0.05); border-radius: 4px; }
.text-muted { color: #999; font-style: italic; }

.loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
