:root {
    --bg: #0f1226;
    --bg-grad-1: #1a1f4a;
    --bg-grad-2: #0a0d22;
    --panel: rgba(255, 255, 255, 0.06);
    --panel-border: rgba(255, 255, 255, 0.12);
    --text: #e8ecff;
    --text-dim: #9aa3d4;
    --accent: #6c8cff;
    --accent-2: #ff6cb4;
    --danger: #ff5d5d;
    --success: #5dffaf;
    --cell-hidden: linear-gradient(145deg, #4a5290, #2a3060);
    --cell-hidden-hover: linear-gradient(145deg, #5a62a8, #353c75);
    --cell-revealed: #1a1f3a;
    --cell-flagged: linear-gradient(145deg, #ff6cb4, #c4388a);
    --cell-size: 38px;
    --cell-gap: 4px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: radial-gradient(ellipse at top, var(--bg-grad-1), var(--bg-grad-2));
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.app {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.topbar h1 {
    margin: 0;
    font-size: 24px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: 2px;
}

.topbar-actions {
    display: flex;
    gap: 8px;
}

.mode-toggle {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    transition: transform 0.15s, background 0.2s, border-color 0.2s;
}
.mode-toggle:hover { background: rgba(255, 255, 255, 0.12); }
.mode-toggle:active { transform: scale(0.96); }
.mode-toggle.active {
    background: linear-gradient(135deg, var(--accent-2), #ff8ec8);
    border-color: transparent;
    color: white;
    box-shadow: 0 4px 12px rgba(255, 108, 180, 0.35);
}

.lb-toggle {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    transition: transform 0.15s, background 0.2s;
}
.lb-toggle:hover { background: rgba(255, 255, 255, 0.12); }
.lb-toggle:active { transform: scale(0.96); }

.setup {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 10px 14px;
}
.setup label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-dim);
}
.setup input[type=number] {
    width: 64px;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}
.setup input[type=number]:focus { border-color: var(--accent); }
.setup input[type=number]::-webkit-inner-spin-button,
.setup input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border: none;
    color: white;
    padding: 8px 18px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    margin-left: auto;
    transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(108, 140, 255, 0.3);
}
.btn-primary:hover { box-shadow: 0 6px 16px rgba(108, 140, 255, 0.5); }
.btn-primary:active { transform: scale(0.96); }

.hud {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 12px;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 12px 18px;
}
.hud-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: "Courier New", monospace;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--success);
    text-shadow: 0 0 10px rgba(93, 255, 175, 0.4);
}
.hud-cell:first-child { color: var(--danger); text-shadow: 0 0 10px rgba(255, 93, 93, 0.4); }
.hud-icon { font-size: 20px; }

.reset-face {
    width: 48px;
    height: 48px;
    font-size: 28px;
    background: var(--cell-hidden);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.reset-face:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5); }
.reset-face:active { transform: translateY(0) scale(0.95); }
.reset-face.win { background: linear-gradient(145deg, #5dffaf, #2db987); }
.reset-face.lose { background: linear-gradient(145deg, #ff5d5d, #c43838); }

.board-wrap {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 14px;
    overflow: auto;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
}

.board {
    display: grid;
    gap: var(--cell-gap);
    touch-action: manipulation;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--cell-hidden);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    font-weight: 800;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s, background 0.2s, box-shadow 0.2s;
    box-shadow: inset 2px 2px 4px rgba(255, 255, 255, 0.1),
                inset -2px -2px 4px rgba(0, 0, 0, 0.3),
                0 2px 4px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}
.cell:hover:not(.revealed):not(.game-over) {
    background: var(--cell-hidden-hover);
    transform: scale(1.05);
}
.cell:active:not(.revealed):not(.game-over) { transform: scale(0.95); }

.cell.revealed {
    background: var(--cell-revealed);
    box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.5);
    cursor: default;
}

.cell.flagged {
    background: var(--cell-flagged);
}
.cell.flagged::before {
    content: "🚩";
    font-size: 18px;
}

.cell.mine {
    background: linear-gradient(145deg, #ff5d5d, #c43838);
    animation: mine-shake 0.3s ease-out;
}
.cell.mine::before { content: "💣"; font-size: 18px; }

.cell.exploded {
    background: radial-gradient(circle, #fff 0%, #ff5d5d 40%, #c43838 100%);
    animation: mine-explode 0.6s ease-out;
}
.cell.exploded::before { content: "💥"; font-size: 22px; }

.cell.n1 { color: #5dadff; }
.cell.n2 { color: #5dffaf; }
.cell.n3 { color: #ff8c5d; }
.cell.n4 { color: #c25dff; }
.cell.n5 { color: #ff5d5d; }
.cell.n6 { color: #5dffe5; }
.cell.n7 { color: #ffe45d; }
.cell.n8 { color: #ff5dc0; }

.cell.wrong-flag {
    background: linear-gradient(145deg, #ff5d5d, #803030) !important;
}
.cell.wrong-flag::before { content: "❌"; }

@keyframes cell-pop {
    0% { transform: scale(0.6); opacity: 0.4; }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes flag-wave {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(-12deg) scale(1.15); }
    50% { transform: rotate(8deg) scale(1.1); }
    75% { transform: rotate(-4deg) scale(1.05); }
    100% { transform: rotate(0deg) scale(1); }
}

@keyframes mine-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-3px) rotate(-2deg); }
    40% { transform: translateX(3px) rotate(2deg); }
    60% { transform: translateX(-2px) rotate(-1deg); }
    80% { transform: translateX(2px) rotate(1deg); }
}

@keyframes mine-explode {
    0% { transform: scale(1); filter: brightness(1); }
    30% { transform: scale(1.4); filter: brightness(2); }
    60% { transform: scale(1.2); filter: brightness(1.5); }
    100% { transform: scale(1); filter: brightness(1); }
}

@keyframes reveal-wave {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 13, 34, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    animation: overlay-in 0.4s ease-out;
    z-index: 10;
}
.overlay.hidden { display: none; }
.overlay-content {
    text-align: center;
    animation: overlay-content-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.overlay-emoji {
    font-size: 80px;
    animation: emoji-bounce 1s ease-out infinite alternate;
}
.overlay-text {
    font-size: 28px;
    font-weight: 700;
    margin: 12px 0 6px;
}
.overlay-time {
    font-size: 18px;
    color: var(--text-dim);
    font-family: "Courier New", monospace;
    letter-spacing: 1px;
}

@keyframes overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes overlay-content-in {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes emoji-bounce {
    from { transform: translateY(0) scale(1); }
    to { transform: translateY(-10px) scale(1.1); }
}

.leaderboard {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 16px;
}
.leaderboard.hidden { display: none; }
.leaderboard h2 {
    margin: 0 0 6px;
    font-size: 18px;
    background: linear-gradient(135deg, #ffd700, #ff6cb4);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.lb-tip { margin: 0 0 10px; font-size: 12px; color: var(--text-dim); }
.lb-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 13px;
}
.lb-spec { color: var(--text-dim); }
.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
}
.btn-link:hover { background: rgba(108, 140, 255, 0.15); }
.lb-list {
    margin: 0;
    padding: 0 0 0 28px;
    max-height: 240px;
    overflow-y: auto;
}
.lb-list li {
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-family: "Courier New", monospace;
    display: flex;
    justify-content: space-between;
}
.lb-list li:last-child { border-bottom: none; }
.lb-rank { color: var(--text-dim); }
.lb-time { color: var(--success); }
.lb-list .gold { color: #ffd700; }
.lb-list .silver { color: #c0c0c0; }
.lb-list .bronze { color: #cd7f32; }
.lb-list .empty {
    list-style: none;
    text-align: center;
    color: var(--text-dim);
    padding: 14px;
    font-family: inherit;
}

/* 响应式：小屏缩小 */
@media (max-width: 600px) {
    html, body { height: 100%; }
    .app { min-height: 100vh; min-height: -webkit-fill-available; }
    .topbar h1 { font-size: 20px; }
    .mode-toggle, .lb-toggle { padding: 6px 10px; font-size: 12px; }
    .setup { padding: 8px 10px; gap: 6px; }
    .setup input[type=number] { width: 52px; padding: 5px 6px; font-size: 13px; }
    .btn-primary { padding: 7px 14px; font-size: 13px; }
    .hud-cell { font-size: 18px; }
    .reset-face { width: 42px; height: 42px; font-size: 24px; }
    .board-wrap {
        flex: 1;
        min-height: 0;
        padding: 8px;
        border-radius: 12px;
    }
    .overlay-emoji { font-size: 64px; }
    .overlay-text { font-size: 22px; }
}

@media (max-width: 380px) {
    .cell { font-size: 14px; border-radius: 4px; }
}

.hidden { display: none !important; }