* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
    -khtml-user-select: none; /* Konqueror HTML */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none; /* Non-prefixed version */
    touch-action: manipulation;
}

:root {
    --primary-color: #4a752c;
    --secondary-color: #a7d948;
    --border-color: #8fbb55;
    --cell-size: 40px;
    --cell-size-mobile: min(11vw, 42px);
    --text-color: #2c3e50;
    --mine-color: #e74c3c;
    --flag-color: #e67e22;
    --header-bg: #0a713a;
    --header-text: #ffffff;
}

html, body {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: var(--header-bg);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    touch-action: manipulation;
}

.container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 5px 8px;
    text-align: center;
    flex-shrink: 0;
}

h1 {
    margin-bottom: 8px;
    font-size: 20px;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f8f8f8;
    border-radius: 5px;
    padding: 5px;
}

.mines-counter, .timer {
    background-color: #000;
    color: #f00;
    font-family: 'Digital', monospace;
    font-size: 18px;
    padding: 3px 8px;
    min-width: 50px;
    text-align: center;
    border-radius: 3px;
}

#reset-button {
    font-size: 22px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 10px;
    transition: transform 0.1s;
}

#reset-button:hover {
    transform: scale(1.1);
}

.difficulty {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.difficulty button {
    padding: 4px 12px;
    background-color: #f0f0f0;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.3s;
    font-size: 14px;
}

.difficulty button.active {
    background-color: var(--primary-color);
    color: white;
}

main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 10px;
    background-color: #f0f0f0;
    position: relative;
    min-height: 0;
    isolation: isolate;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(var(--columns), var(--cell-size));
    grid-template-rows: repeat(var(--rows), var(--cell-size));
    gap: 1px;
    background-color: var(--border-color);
    border: 2px solid var(--border-color);
    border-radius: 3px;
    user-select: none;
    width: fit-content;
    height: fit-content;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
    transform-origin: center center;
    overflow: hidden;
    will-change: transform;
    position: relative;
    z-index: 1;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--secondary-color);
    font-weight: bold;
    font-size: calc(var(--cell-size) * 0.6);
    cursor: pointer;
    transition: background-color 0.2s;
    will-change: transform, background-color;
    backface-visibility: hidden;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    z-index: 1;
}

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

.cell.revealed {
    background-color: #e0e0e0;
}

.cell.mine {
    background-color: var(--mine-color);
}

.cell.flagged {
    position: relative;
}

.cell.flagged::after {
    content: "🚩";
    font-size: 0.8em;
}

/* Number colors */
.cell[data-value="1"] { color: blue; }
.cell[data-value="2"] { color: green; }
.cell[data-value="3"] { color: red; }
.cell[data-value="4"] { color: darkblue; }
.cell[data-value="5"] { color: darkred; }
.cell[data-value="6"] { color: teal; }
.cell[data-value="7"] { color: black; }
.cell[data-value="8"] { color: gray; }

footer {
    text-align: center;
    padding: 3px;
    font-size: 11px;
    color: #666;
    flex-shrink: 0;
}

/* Media queries for responsiveness */
@media (max-width: 768px) {
    :root {
        --cell-size: var(--cell-size-mobile);
    }
    
    .container {
        height: 100%;
        max-height: -webkit-fill-available;
    }
    
    h1 {
        font-size: 18px;
        margin-bottom: 4px;
    }
    
    .mines-counter, .timer {
        font-size: 16px;
        min-width: 45px;
    }
    
    #reset-button {
        font-size: 20px;
        padding: 2px 8px;
    }
    
    .controls {
        gap: 4px;
    }
    
    .difficulty button {
        padding: 3px 10px;
        font-size: 14px;
    }
    
    main {
        padding: 8px;
    }
}

/* For smaller phones */
@media (max-width: 480px) {
    :root {
        --cell-size: 36px;
        --cell-size-mobile: min(10vw, 38px);
    }
    
    header {
        padding: 4px 5px;
    }
    
    h1 {
        font-size: 16px;
        margin-bottom: 2px;
    }
    
    .mines-counter, .timer {
        font-size: 14px;
        min-width: 40px;
        padding: 2px 5px;
    }
    
    #reset-button {
        font-size: 18px;
        padding: 0 6px;
    }
    
    .difficulty button {
        padding: 2px 5px;
        font-size: 12px;
        border-radius: 2px;
        margin: 0 1px;
    }
    
    footer {
        padding: 2px;
        font-size: 10px;
    }
    
    main {
        padding: 5px;
    }
    
    #game-board {
        gap: 1px;
        border-width: 1px;
    }
    
    .cell {
        font-size: calc(var(--cell-size) * 0.55);
    }
}

/* For very small screens */
@media (max-width: 360px) {
    :root {
        --cell-size: 32px;
        --cell-size-mobile: min(9vw, 34px);
    }
    
    h1 {
        font-size: 14px;
    }
    
    .difficulty {
        gap: 2px;
    }
    
    .difficulty button {
        padding: 1px 4px;
        font-size: 11px;
    }
    
    main {
        padding: 3px;
    }
    
    .cell {
        font-size: calc(var(--cell-size) * 0.5);
    }
}

/* Animations */
@keyframes reveal {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.cell.revealed {
    animation: reveal 0.2s ease-out;
}

@keyframes explode {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
    }
}

.cell.mine {
    animation: explode 0.5s ease-out;
}

/* 横屏模式优化 */
@media (orientation: landscape) and (max-height: 500px) {
    header {
        padding: 2px 5px;
    }
    
    h1 {
        font-size: 14px;
        margin-bottom: 1px;
    }
    
    .controls {
        gap: 2px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
    
    .game-info {
        padding: 2px;
        flex: 0 0 auto;
    }
    
    .difficulty {
        flex: 0 0 auto;
    }
    
    footer {
        display: none;
    }
    
    main {
        padding: 2px;
    }
    
    #game-board {
        margin: 0 auto;
    }
}

/* 困难模式下减小单元格大小 */
@media screen and (max-width: 768px) {
    :root {
        --cell-size-mobile: min(10vw, 38px);
    }
}

@media screen and (max-width: 480px) {
    :root {
        --cell-size-mobile: min(9vw, 36px);
    }
}

@media screen and (max-width: 360px) {
    :root {
        --cell-size-mobile: min(8vw, 32px);
    }
}

/* 移动设备上调整单元格大小 */
@media screen and (max-width: 768px) {
    #game-board {
        grid-template-columns: repeat(var(--columns), var(--cell-size-mobile));
        grid-template-rows: repeat(var(--rows), var(--cell-size-mobile));
    }
    
    .cell {
        width: var(--cell-size-mobile);
        height: var(--cell-size-mobile);
        font-size: calc(var(--cell-size-mobile) * 0.6);
    }
} 