/* ===== 라이트 모드 (낮의 잔디밭) ===== */
:root {
    --bg-main: #4a7c2e;
    --bar-bg: #5d4037;
    --bar-bg-dark: #3e2723;
    --cell-light-a: #8bc34a;
    --cell-light-b: #7cb342;
    --cell-dark-a: #e8d5b7;
    --cell-dark-b: #d7c4a6;
    --cell-hover: rgba(255,255,255,0.15);
    --flag-red: #e53935;
    --text-color: #2c3e50;
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ===== 다크 모드 (밤의 광산) ===== */
[data-theme="dark"] {
    --bg-main: #0f172a;
    --bar-bg: #1e293b;
    --bar-bg-dark: #0f172a;
    --cell-light-a: #334155;
    --cell-light-b: #1e293b;
    --cell-dark-a: #64748b;
    --cell-dark-b: #475569;
    --cell-hover: rgba(255,255,255,0.1);
    --flag-red: #ef4444;
    --text-color: #f8fafc;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
    touch-action: none;
    font-family: var(--font-family);
    background: var(--bg-main);
}

#game-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-main);
}

/* ===== TOP BAR ===== */
#top-bar {
    background: var(--bar-bg);
    display: flex;
    flex-direction: column;
    z-index: 20;
    flex-shrink: 0;
    border-bottom: 3px solid var(--bar-bg-dark);
}

#top-row-1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px 4px;
}

#top-row-2 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 14px 6px;
    border-top: 1px solid rgba(255,255,255,0.1);
    overflow: hidden;
}

.bar-label {
    font-size: 13px;
    font-weight: 700;
    color: rgba(255,255,255,0.85);
}

.bar-record {
    display: flex;
    align-items: center;
    gap: 6px;
}

.record-item {
    font-size: 12px;
    font-weight: 700;
    color: rgba(255,255,255,0.75);
}

.record-item span {
    color: #ffd54f;
}

.record-divider {
    color: rgba(255,255,255,0.25);
    font-size: 12px;
}

#difficulty-wrapper select {
    background: #fff;
    border: 2px solid var(--bar-bg-dark);
    border-radius: 6px;
    padding: 4px 8px;
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 14px;
    color: var(--text-color);
    cursor: pointer;
}

#top-center {
    display: flex;
    gap: 16px;
    align-items: center;
}

.top-stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-icon {
    font-size: 22px;
}

#flag-count, #timer {
    font-size: 22px;
    font-weight: 900;
    color: #fff;
    min-width: 36px;
    text-align: left;
}

#top-right-btns {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    border-radius: 50%;
    transition: transform 0.15s;
    filter: brightness(1.1);
}

.icon-btn:active {
    transform: scale(0.88);
}

/* ===== BOARD ===== */
#board-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow: hidden;
    padding: 0;
}

#board {
    display: grid;
    gap: 0px;
}

/* ===== MODE TOGGLE ===== */
#mode-bar {
    display: flex;
    justify-content: center;
    padding: 6px 0;
    background: var(--bar-bg);
    border-top: 2px solid var(--bar-bg-dark);
    flex-shrink: 0;
    z-index: 20;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 32px;
    border-radius: 25px;
    border: none;
    font-family: var(--font-family);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

.mode-btn:active {
    transform: scale(0.95);
}

.mode-btn #mode-icon {
    font-size: 22px;
}

.mode-dig {
    background: linear-gradient(135deg, #6d9b3a, #4a7c2e);
    color: #fff;
}

.mode-flag {
    background: linear-gradient(135deg, #e53935, #c62828);
    color: #fff;
}

.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    cursor: pointer;
    position: relative;
    transition: transform 0.08s;
    border: 0.5px solid rgba(0,0,0,0.05);
}

.cell:active {
    transform: scale(0.92);
}

/* Covered cells - checkered green pattern */
.cell.covered {
    background: var(--cell-light-a);
}

.cell.covered.checker {
    background: var(--cell-light-b);
}

.cell.covered:hover {
    filter: brightness(1.08);
}

/* Revealed cells - checkered tan pattern */
.cell.revealed {
    background: var(--cell-dark-a);
}

.cell.revealed.checker {
    background: var(--cell-dark-b);
}

/* Flag */
.cell .flag {
    font-size: 1em;
    animation: flagPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes flagPop {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

/* Numbers */
.cell.n1 { color: #1565c0; }
.cell.n2 { color: #2e7d32; }
.cell.n3 { color: #c62828; }
.cell.n4 { color: #6a1b9a; }
.cell.n5 { color: #e65100; }
.cell.n6 { color: #00838f; }
.cell.n7 { color: #37474f; }
.cell.n8 { color: #78909c; }

/* Mine exploded */
.cell.mine-hit {
    background: #ff5252 !important;
    animation: mineExplode 0.4s ease-out;
}

.cell.mine-revealed {
    animation: mineReveal 0.3s ease-out;
}

@keyframes mineExplode {
    0% { transform: scale(1); }
    30% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

@keyframes mineReveal {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Mine colors */
.mine-color-0 { color: #e53935; }
.mine-color-1 { color: #ff9800; }
.mine-color-2 { color: #ffeb3b; }
.mine-color-3 { color: #4caf50; }
.mine-color-4 { color: #00bcd4; }
.mine-color-5 { color: #2196f3; }
.mine-color-6 { color: #9c27b0; }
.mine-color-7 { color: #e91e63; }

/* Particles */
.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 1px;
    pointer-events: none;
    z-index: 50;
}

@keyframes particleFly {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) rotate(720deg);
    }
}

/* ===== MODALS ===== */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.hidden {
    display: none !important;
}

.modal-content {
    width: 88%;
    max-width: 380px;
    padding: 28px;
    border-radius: 24px;
    text-align: center;
    color: var(--text-color);
    animation: modalIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.glass {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
}

h1 {
    font-size: 30px;
    font-weight: 900;
    margin-bottom: 12px;
    color: var(--bar-bg);
}

h2 {
    font-size: 22px;
    margin-bottom: 16px;
}

p {
    font-size: 15px;
    line-height: 1.6;
    margin-bottom: 20px;
    color: #666;
}

/* Difficulty selector on start screen */
.diff-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.diff-btn {
    flex: 1;
    padding: 12px 6px;
    border-radius: 14px;
    border: 2px solid #ddd;
    background: #f5f5f5;
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-color);
}

.diff-btn small {
    font-size: 11px;
    font-weight: 400;
    color: #888;
}

.diff-btn.active {
    border-color: var(--bar-bg);
    background: var(--bar-bg);
    color: #fff;
    box-shadow: 0 4px 12px rgba(93, 64, 55, 0.3);
}

.diff-btn.active small {
    color: rgba(255,255,255,0.7);
}

/* Buttons */
.primary-btn, .secondary-btn {
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    border: none;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    font-family: var(--font-family);
    transition: transform 0.1s, opacity 0.2s;
}

.primary-btn {
    background: linear-gradient(135deg, #6d9b3a, #4a7c2e);
    color: white;
    box-shadow: 0 5px 15px rgba(74, 124, 46, 0.35);
}

.secondary-btn {
    background: #e0e0e0;
    color: #444;
    margin-top: 8px;
}

.primary-btn:active, .secondary-btn:active {
    transform: scale(0.97);
}

/* Results */
.result-emoji {
    font-size: 56px;
    margin-bottom: 8px;
}

.final-score-container {
    margin: 12px 0;
}

.final-label {
    display: block;
    font-size: 14px;
    color: #888;
}

#final-score {
    font-size: 52px;
    font-weight: 900;
    color: var(--bar-bg);
}

.highscore-container {
    font-weight: 700;
    margin-bottom: 16px;
    color: #666;
}

#new-record {
    background: linear-gradient(135deg, #ffd54f, #ffb300);
    color: #5d4037;
    padding: 6px 18px;
    border-radius: 20px;
    display: inline-block;
    font-weight: 900;
    animation: pulse 1s infinite;
    margin-bottom: 16px;
    font-size: 15px;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

/* Settings */
.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    text-align: left;
}

.setting-item span {
    font-weight: 700;
}

input[type="range"] {
    width: 60%;
    accent-color: var(--bar-bg);
}

/* PC mode */
@media (min-aspect-ratio: 1/1) {
    #game-container {
        max-width: min(420px, 56vh);
        border-left: 3px solid #3e6b1e;
        border-right: 3px solid #3e6b1e;
        box-shadow: 0 0 40px rgba(0,0,0,0.3);
    }
}
