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

:root {
    --bg: #12131c;
    --panel: #1e2030;
    --line: #343850;
    --text: #eef0ff;
    --muted: #9096b8;
    --accent: #ff6b8a;
    --covered: #2b2f45;
    --covered-2: #333852;
    --open: #191b28;
    --flag: #ffb347;
    --n1: #6ea8ff; --n2: #5fd08a; --n3: #ff7a7a; --n4: #b48bff;
    --n5: #ffb35c; --n6: #57d8d8; --n7: #ffffff; --n8: #9aa0c4;
}

html, body { height: 100%; overscroll-behavior: none; }

body {
    position: fixed;
    inset: 0;
    overflow: hidden;
    color: var(--text);
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', sans-serif;
    background:
        radial-gradient(circle at 50% 0%, rgba(255, 107, 138, 0.12), transparent 55%),
        linear-gradient(180deg, #0b0c13, #171926);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100dvh;
    max-width: 560px;
    margin: 0 auto;
    padding:
        max(6px, env(safe-area-inset-top))
        max(8px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom))
        max(8px, env(safe-area-inset-left));
}

.toolbar { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; height: 38px; }
.toolbar-spacer { flex: 1; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 31px; padding: 0 10px;
    border: 1px solid var(--line); border-radius: 9px;
    background: var(--panel); color: var(--text);
    font-family: inherit; font-size: 0.88rem; line-height: 1;
    text-decoration: none; cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.icon-btn-text { font-size: 0.76rem; font-weight: 600; }
.icon-btn:active { transform: scale(0.94); border-color: var(--accent); }

.hud { display: flex; gap: 6px; flex: 0 0 auto; margin: 5px 0; }

.hud span {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 4px 2px; border-radius: 9px; background: rgba(255, 255, 255, 0.05);
}

.hud b { font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.hud i { font-style: normal; font-size: 0.58rem; letter-spacing: 0.08em; color: var(--muted); }

/* ===== Board ===== */
.board-area {
    flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 6px;
    overflow: auto;
}

.board {
    display: grid;
    gap: 2px;
    padding: 4px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    touch-action: none;
}

.cellbox {
    display: flex; align-items: center; justify-content: center;
    border-radius: 3px;
    background: linear-gradient(180deg, var(--covered-2), var(--covered));
    font-size: var(--cell-font, 14px);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    cursor: pointer;
}

.cellbox.is-open { background: var(--open); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05); cursor: default; }
.cellbox.is-flag { color: var(--flag); }
.cellbox.is-mine { background: #4a1622; color: #ffd2da; }
.cellbox.is-boom { background: var(--accent); color: #2a0009; }
.cellbox.is-wrong { background: #3a2030; color: #ff9aa8; }
.cellbox.is-press { filter: brightness(1.35); }

.n1 { color: var(--n1); } .n2 { color: var(--n2); } .n3 { color: var(--n3); }
.n4 { color: var(--n4); } .n5 { color: var(--n5); } .n6 { color: var(--n6); }
.n7 { color: var(--n7); } .n8 { color: var(--n8); }

.board-note { font-size: 0.66rem; color: var(--muted); }

/* ===== Tools ===== */
.tools { display: flex; gap: 8px; flex: 0 0 auto; margin-top: 6px; }

.tool {
    flex: 1; min-height: 54px;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid var(--line); border-radius: 13px;
    background: var(--panel); color: var(--text);
    font-family: inherit; font-size: 0.9rem; font-weight: 700;
    cursor: pointer; transition: transform 0.1s ease, border-color 0.1s ease;
}

.tool i { font-style: normal; font-size: 1.15rem; line-height: 1; }
.tool:active { transform: scale(0.97); }
.tool-flag.is-on { border-color: var(--flag); background: rgba(255, 179, 71, 0.18); }

.hint { margin-top: 5px; text-align: center; font-size: 0.66rem; color: var(--muted); }

/* ===== Overlays ===== */
.overlay {
    position: absolute; inset: 0; display: none;
    align-items: center; justify-content: center; padding: 20px;
    background: rgba(6, 6, 12, 0.88);
    backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    z-index: 50;
}

.overlay.is-open { display: flex; }

.panel {
    width: 100%; max-width: 330px;
    display: flex; flex-direction: column; gap: 10px;
    padding: 22px 18px;
    border: 1px solid var(--line); border-radius: 20px;
    background: linear-gradient(180deg, #262a3d, #16182400), #1a1c29;
    text-align: center;
    animation: pop 0.22s ease;
}

@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }

.panel-title { font-size: 1.5rem; font-weight: 800; letter-spacing: 0.08em; color: var(--accent); }
.panel-title.is-win { color: #5fd08a; }

.levels { display: flex; flex-direction: column; gap: 8px; }

.level {
    display: flex; align-items: center; justify-content: space-between;
    padding: 13px 16px;
    border: 1px solid var(--line); border-radius: 13px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.95rem; font-weight: 700; cursor: pointer;
}

.level small { font-size: 0.68rem; font-weight: 500; color: var(--muted); }
.level.is-current { border-color: var(--accent); background: rgba(255, 107, 138, 0.14); }

.switch {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    font-size: 0.8rem; color: var(--muted); cursor: pointer;
}

.switch input { width: 17px; height: 17px; accent-color: var(--accent); }

.btn {
    min-height: 46px; padding: 12px 20px;
    border: 1px solid var(--line); border-radius: 13px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.92rem; font-weight: 700;
    text-decoration: none; display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}

.btn:active { transform: scale(0.97); }
.btn-primary { border-color: transparent; background: linear-gradient(135deg, #ff8fa6, #ff5d80); color: #2a0009; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stat { padding: 9px 6px; border-radius: 11px; background: rgba(255, 255, 255, 0.06); }
.stat b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.64rem; color: var(--muted); }

@media (max-height: 680px) {
    .hud { margin: 3px 0; }
    .tool { min-height: 46px; }
    .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }
