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

body {
    background: #1a1a2e;
    color: #e0e0e0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    -webkit-user-select: none;
    user-select: none;
}

.container {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Back link */
.back-link {
    position: absolute;
    top: 0;
    left: 0;
    color: #8888cc;
    text-decoration: none;
    font-size: 1rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: #aaaaee;
}

/* Title */
.title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 20px 0;
    color: #e0e0e0;
    letter-spacing: 2px;
    text-align: center;
}

/* Difficulty selector */
.difficulty-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.diff-btn {
    padding: 10px 26px;
    border: 2px solid #444;
    border-radius: 6px;
    background: #2a2a3e;
    color: #ccc;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.diff-btn:hover {
    background: #3a3a5e;
    border-color: #666;
}

.diff-btn.active {
    background: #4a4a7e;
    border-color: #7777bb;
    color: #fff;
    box-shadow: 0 0 8px rgba(119, 119, 187, 0.4);
}

/* Status bar */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 700px;
    margin-bottom: 14px;
    padding: 12px 24px;
    background: #2a2a3e;
    border-radius: 8px;
    font-size: 1.3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    border: 1px solid #3a3a5e;
}

.mine-counter {
    color: #ff6b6b;
}

.timer {
    color: #6bcfff;
}

/* Grid wrapper */
.grid-wrapper {
    overflow: auto;
    max-width: 100%;
    max-height: 75vh;
    border-radius: 6px;
    border: 3px solid #333;
    background: #bbb;
    touch-action: none;
    -webkit-overflow-scrolling: touch;
}

/* Grid */
.grid {
    display: grid;
    gap: 0;
    background: #bbb;
    touch-action: none;
}

/* Cells */
.cell {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    border: 2px outset #ccc;
    background: #999;
    transition: none;
    line-height: 1;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.cell:hover:not(.revealed):not(.flagged) {
    background: #aaa;
}

/* Visual feedback for long-press */
.cell.long-press-active {
    background: #b8b8d0;
    transform: scale(0.92);
    transition: background 0.15s ease, transform 0.15s ease;
}

.cell.revealed {
    background: #ccc;
    border: 1px solid #aaa;
    cursor: default;
}

.cell.flagged {
    background: #999;
    font-size: 16px;
}

.cell.mine-hit {
    background: #e74c3c;
}

.cell.mine-revealed {
    background: #ccc;
    border: 1px solid #aaa;
}

/* Number colors */
.cell.n1 { color: #0000ff; }
.cell.n2 { color: #008000; }
.cell.n3 { color: #ff0000; }
.cell.n4 { color: #00008b; }
.cell.n5 { color: #8b0000; }
.cell.n6 { color: #008080; }
.cell.n7 { color: #000000; }
.cell.n8 { color: #808080; }

/* Mobile hint */
.mobile-hint {
    display: none;
    margin-top: 12px;
    color: #888;
    font-size: 0.9rem;
    text-align: center;
}

/* How to Play */
.how-to-play {
    margin-top: 20px;
    width: 100%;
    max-width: 700px;
    background: #2a2a3e;
    border: 1px solid #3a3a5e;
    border-radius: 8px;
    overflow: hidden;
}

.how-to-play summary {
    padding: 14px 20px;
    font-size: 1.05rem;
    font-weight: 600;
    color: #ccc;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.how-to-play summary::-webkit-details-marker {
    display: none;
}

.how-to-play summary::before {
    content: '\25B6';
    font-size: 0.7rem;
    transition: transform 0.2s;
    display: inline-block;
}

.how-to-play[open] summary::before {
    transform: rotate(90deg);
}

.how-to-play summary:hover {
    background: #33334e;
}

.how-to-play-content {
    padding: 4px 20px 18px 20px;
    color: #bbb;
    font-size: 0.95rem;
    line-height: 1.7;
}

.how-to-play-content ul {
    list-style: none;
    padding: 0;
}

.how-to-play-content li {
    padding: 4px 0;
    padding-left: 12px;
    position: relative;
}

.how-to-play-content li::before {
    content: '\2022';
    position: absolute;
    left: 0;
    color: #7777bb;
}

.how-to-play-content strong {
    color: #ddd;
}

/* Overlay */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.overlay.active {
    display: flex;
}

.overlay-content {
    background: #2a2a3e;
    border: 2px solid #555;
    border-radius: 16px;
    padding: 40px 50px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.overlay-message {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.overlay-time {
    font-size: 1.1rem;
    color: #aaa;
    margin-bottom: 24px;
}

.play-again-btn {
    padding: 12px 36px;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: #4a4a7e;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s;
}

.play-again-btn:hover {
    background: #5a5a9e;
}

/* ===== Responsive / Mobile ===== */
@media (max-width: 600px) {
    body {
        padding: 8px;
    }

    .title {
        font-size: 1.5rem;
        margin-bottom: 14px;
    }

    .back-link {
        font-size: 0.9rem;
    }

    .diff-btn {
        padding: 8px 16px;
        font-size: 0.9rem;
    }

    .status-bar {
        font-size: 1.15rem;
        padding: 10px 16px;
        max-width: 100%;
    }

    .grid-wrapper {
        max-height: 65vh;
    }

    .mobile-hint {
        display: block;
    }

    .overlay-content {
        padding: 30px 28px;
        margin: 0 16px;
    }

    .overlay-message {
        font-size: 1.5rem;
    }

    .how-to-play {
        max-width: 100%;
    }
}

@media (hover: none) and (pointer: coarse) {
    .mobile-hint {
        display: block;
    }
}
