/*
 * 扫雷
 *
 * 界面照 Victor Zhang 那版复刻（sheepzh/minesweeper）：Windows XP 那种
 * 「银灰底 + 蓝色标题栏 + 立体凸起按钮 + 凹陷棋盘」，棋盘格也是经典灰格子。
 * 只有一点不同：格子放大了（那版是 16px 精灵图，这里 22~32px 画文字数字）。
 */

/* ---------- 卡片 ---------- */

.app-card--sweeper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.app-icon.sweeper-mini {
    border: 0;
    padding: 0;
    cursor: pointer;
    background: transparent;
    overflow: hidden;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .5),
        0 6px 16px rgba(15, 23, 42, .16),
        0 1px 3px rgba(15, 23, 42, .12);
    transition: transform .18s cubic-bezier(.2, .7, .3, 1), box-shadow .18s ease;
}

.app-icon.sweeper-mini:hover {
    transform: translateY(-2px);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .55),
        0 14px 28px rgba(15, 23, 42, .22);
}

.app-icon.sweeper-mini img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    -webkit-user-drag: none;
}

/* ---------- 弹窗（XP 窗口） ---------- */

.sw-panel {
    position: relative;
    width: fit-content;
    min-width: min(320px, 100%);
    max-width: 100%;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    padding: 0 0 8px;
    border: 2px solid #0831d9;
    border-radius: 8px 8px 4px 4px;
    background: #ece9d8;
    color: #1a1a1a;
    box-shadow: 0 26px 70px rgba(8, 12, 22, .38);
    font-family: Tahoma, "Segoe UI", "Microsoft YaHei", sans-serif;
}

/* 标题栏：XP 那条蓝色渐变 */
.sw-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    height: 30px;
    margin: 2px 2px 0;
    /* 关闭别贴着边，跟其它弹层的右留白收到一个区间里 */
    padding: 0 8px 0 9px;
    border-radius: 6px 6px 0 0;
    background: linear-gradient(180deg, #0997ff 0%, #0053ee 8%, #0050ee 40%,
    #0066ff 88%, #005bff 93%, #003dd7 96%, #003dd7 100%);
    color: #ffffff;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: .3px;
    text-shadow: 1px 1px 1px rgba(0, 0, 0, .45);
}

.sw-title {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: inherit;
    font-weight: inherit;
}

.sw-head-ico {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    object-fit: cover;
}

.sw-head .cs-x {
    position: static;
    --cs-x-ico: 14px;
    --cs-x-focus: #ffffff;
    width: 22px;
    height: 21px;
    border: 1px solid #ffffff;
    border-radius: 3px;
    background: linear-gradient(180deg, #4a95f5 0%, #0b57d0 100%);
    color: #ffffff;
}

.sw-head .cs-x:hover {
    background: linear-gradient(180deg, #6aabff 0%, #1a67e0 100%);
}

/* ---------- 难度 + 标记开关（XP 凸起按钮） ---------- */

.sw-bar {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 8px 6px;
}

.sw-levels {
    display: flex;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.sw-level {
    flex: none;
    height: 26px;
    padding: 0 10px;
    border: 1px solid #aca899;
    border-radius: 2px;
    background: #ece9d8;
    color: #1a1a1a;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    box-shadow: inset 1px 1px 0 #ffffff;
}

.sw-level:hover {
    background: #f5f3e9;
}

.sw-level.is-on {
    border-color: #716f64;
    background: #d6d2c2;
    box-shadow: inset 1px 1px 0 #b9b5a5;
    font-weight: 700;
}

/* 标记模式：手机上没法右键，点开它以后单击就是插旗 */
.sw-flagmode {
    flex: none;
    width: 30px;
    height: 26px;
    padding: 0;
    border: 1px solid #aca899;
    border-radius: 2px;
    background: #ece9d8;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    box-shadow: inset 1px 1px 0 #ffffff;
}

.sw-flagmode.is-on {
    border-color: #716f64;
    background: #fff0d8;
    box-shadow: inset 1px 1px 0 #e0b070;
}

/* 缩放按钮只有手机用：桌面格子本来就 22~32px，够点 */
.sw-zoom {
    display: none;
}

/* ---------- 计数条（凹陷） ---------- */

.sw-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 8px 6px;
    padding: 5px 6px;
    border: 2px solid;
    border-color: #9c9c9c #ffffff #ffffff #9c9c9c;
    background: #c0c0c0;
}

.sw-led {
    min-width: 54px;
    padding: 1px 5px;
    border: 1px solid #6b6b6b;
    background: #000000;
    color: #ff2b1f;
    font-family: "Courier New", Consolas, monospace;
    font-size: 21px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: 2px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* 笑脸：XP 那种凸起按钮 */
.sw-face {
    width: 34px;
    height: 34px;
    padding: 0;
    border: 2px solid;
    border-color: #ffffff #808080 #808080 #ffffff;
    background: #c0c0c0;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.sw-face:active {
    border-color: #808080 #ffffff #ffffff #808080;
}

/* ---------- 棋盘 ---------- */

.sw-board-wrap {
    display: flex;
    justify-content: center;
    margin: 0 8px;
    max-width: calc(100vw - 60px);
    overflow: auto;
    padding: 6px;
    border: 2px solid;
    border-color: #ffffff #9f9f9f #9f9f9f #ffffff;
    background: #c0c0c0;
}

.sw-board {
    --sw-tile: 30px;
    display: grid;
    grid-template-columns: repeat(var(--sw-cols), var(--sw-tile));
    grid-auto-rows: var(--sw-tile);
    gap: 0;
    border: 3px solid;
    border-color: #9f9f9f #ffffff #ffffff #9f9f9f;
    background: #c0c0c0;
    user-select: none;
    touch-action: manipulation;
}

/* 格子：未挖开是凸起，挖开是凹下去 */
.sw-tile {
    position: relative;
    padding: 0;
    border: 2px solid;
    border-color: #ffffff #808080 #808080 #ffffff;
    background: #c0c0c0;
    color: #000000;
    font-family: Tahoma, "Segoe UI", "Microsoft YaHei", sans-serif;
    font-size: calc(var(--sw-tile) * .58);
    font-weight: 700;
    line-height: 1;
    cursor: default;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

.sw-tile:focus {
    outline: none;
}

.sw-tile.is-press {
    border-color: #808080 #ffffff #ffffff #808080;
    background: #bdbdbd;
}

.sw-tile.is-open {
    border: 1px solid #a6a6a6;
    background: #bdbdbd;
}

.sw-tile.is-open.is-press {
    background: #b0b0b0;
}

/* 数字配色跟经典 Windows 一致 */
.sw-tile[data-n="1"] { color: #0000ff; }
.sw-tile[data-n="2"] { color: #007b00; }
.sw-tile[data-n="3"] { color: #ff0000; }
.sw-tile[data-n="4"] { color: #00007b; }
.sw-tile[data-n="5"] { color: #7b0000; }
.sw-tile[data-n="6"] { color: #007b7b; }
.sw-tile[data-n="7"] { color: #000000; }
.sw-tile[data-n="8"] { color: #7b7b7b; }

.sw-tile.is-flag {
    font-size: calc(var(--sw-tile) * .52);
    color: #000000;
}

.sw-tile.is-boom {
    background: #ff3b30;
}

.sw-tile.is-mine {
    background: #bdbdbd;
    font-size: calc(var(--sw-tile) * .52);
}

/* 输了以后标错的旗 */
.sw-tile.is-wrong {
    background: #f0b8b4;
}

/* ---------- 底部 ---------- */

.sw-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 10px 0;
    font-size: 11px;
    color: #4b4b4b;
}

.sw-best {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 820px) {
    .sw-board {
        --sw-tile: 28px;
    }
}

/* ==================================================================
 * 手机端：XP 那套皮肤只在桌面用
 *
 * 2px 立体边框 + 银灰底在 390 宽的屏上又土又糊，格子还挤成一片。
 * 这里换成手机扫雷 App 的通行做法：浅灰底、白卡片、圆角格子、
 * 大号数字，难度做成「分段控件」，并且棋盘可以放大 + 滚动。
 * 桌面端不受影响，还是 Victor Zhang 复刻版那套 XP 外观。
 * ================================================================== */

@media (max-width: 720px) {
    /*
     * 手机上这块是整屏白底 App，用不到背后的深色遮罩：
     * 遮罩那层 backdrop-filter 在某些机型上会糊成一大片黑，
     * 面板稍微没铺满就露出来（看着就是「可滑动区域有黑色模糊」）。
     * 索性整层关掉，底色直接给成面板同款浅灰。
     */
    #sweeper-sheet {
        background: #f4f5f8;
    }

    #sweeper-sheet .cs-mask {
        display: none;
    }

    #sweeper-sheet .sw-panel {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        max-height: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: #f4f5f8;
        /* 桌面那圈 70px 黑投影在手机上只会变成脏边 */
        box-shadow: none;
        color: #1c1c1e;
        font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
        /* 长按插旗时别去选中数字、别弹「拷贝 / 查询」菜单 */
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
        overflow: hidden;
    }

    /* 标题栏：白底、无渐变、无阴影 */
    #sweeper-sheet .sw-head {
        flex: none;
        height: calc(52px + env(safe-area-inset-top));
        margin: 0;
        padding: env(safe-area-inset-top) 14px 0;
        border-radius: 0;
        border-bottom: 1px solid #ececf1;
        background: #ffffff;
        color: #1c1c1e;
        font-size: 16px;
        font-weight: 600;
        letter-spacing: 0;
        text-shadow: none;
    }

    #sweeper-sheet .sw-head-ico {
        width: 20px;
        height: 20px;
        border-radius: 5px;
    }

    #sweeper-sheet .sw-head .cs-x {
        --cs-x-ico: 16px;
        width: 30px;
        height: 30px;
        border: 0;
        border-radius: 6px;
        background: #f1f1f5;
        color: #6b6b70;
    }

    #sweeper-sheet .sw-head .cs-x:hover {
        background: #e7e7ec;
    }

    /* 计分条：两个白胶囊，笑脸做成圆形按钮 */
    #sweeper-sheet .sw-hud {
        order: 1;
        flex: none;
        margin: 12px 14px 0;
        padding: 0;
        gap: 8px;
        border: 0;
        background: transparent;
    }

    #sweeper-sheet .sw-led {
        min-width: 0;
        padding: 8px 13px;
        border: 0;
        border-radius: 12px;
        background: #ffffff;
        color: #1c1c1e;
        font-family: inherit;
        font-size: 17px;
        font-weight: 600;
        line-height: 1.2;
        letter-spacing: .4px;
        box-shadow: 0 1px 2px rgba(20, 22, 40, .06);
    }

    /* 两个数字前面挂个小图标，一眼能分出「剩几个雷」和「用了多久」 */
    #sweeper-sheet [data-sw-mines]::before {
        content: "\1F4A3";
        margin-right: 5px;
        font-size: 13px;
    }

    #sweeper-sheet [data-sw-time]::before {
        content: "\23F1";
        margin-right: 5px;
        font-size: 13px;
    }

    #sweeper-sheet .sw-face {
        width: 44px;
        height: 44px;
        border: 0;
        border-radius: 50%;
        background: #ffffff;
        font-size: 22px;
        box-shadow: 0 1px 3px rgba(20, 22, 40, .1);
    }

    #sweeper-sheet .sw-face:active {
        background: #efeff4;
    }

    /* 难度 + 两个圆形开关 */
    #sweeper-sheet .sw-bar {
        order: 2;
        flex: none;
        gap: 8px;
        padding: 10px 14px 8px;
    }

    /* 分段控件 */
    #sweeper-sheet .sw-levels {
        flex: 1;
        gap: 3px;
        padding: 3px;
        border-radius: 12px;
        background: #e9ebf1;
    }

    #sweeper-sheet .sw-level {
        flex: 1;
        height: 34px;
        padding: 0 6px;
        border: 0;
        border-radius: 9px;
        background: transparent;
        color: #5b5b60;
        font-size: 13.5px;
        font-weight: 500;
        box-shadow: none;
    }

    #sweeper-sheet .sw-level.is-on {
        background: #ffffff;
        color: #1c1c1e;
        font-weight: 600;
        box-shadow: 0 1px 3px rgba(20, 22, 40, .13);
    }

    /* 三个按钮必须一起写：sw-stats 原来漏在这条规则外面，手机上还是 XP 那块灰底 2px 圆角，
       宽度又跟着 emoji 走（43 宽 vs 旁边 40），看着就是一个不搭的方块 */
    #sweeper-sheet .sw-flagmode,
    #sweeper-sheet .sw-zoom,
    #sweeper-sheet .sw-stats {
        flex: none;
        /* 基类里 .sw-zoom 是 display:none（桌面不显示），这里必须放出来 */
        display: grid;
        place-items: center;
        width: 40px;
        height: 40px;
        min-width: 0;
        padding: 0;
        border: 0;
        border-radius: 12px;
        background: #ffffff;
        color: #1c1c1e;
        font-size: 17px;
        line-height: 1;
        box-shadow: 0 1px 3px rgba(20, 22, 40, .1);
    }

    #sweeper-sheet .sw-stats:hover {
        background: #f5f6fa;
    }

    /* 插旗模式开着 = 橙色实心，一眼看出「现在点一下是插旗」 */
    #sweeper-sheet .sw-flagmode.is-on {
        background: #ff9f0a;
        color: #ffffff;
        box-shadow: 0 2px 8px rgba(255, 159, 10, .35);
    }

    #sweeper-sheet .sw-zoom {
        font-size: 15px;
    }

    #sweeper-sheet .sw-zoom.is-on {
        background: #1c1c1e;
        color: #ffffff;
    }

    /*
     * 棋盘区：一块画布，铺满剩余高度。
     *
     * 之前是「白卡 + overflow:auto 原生滚动」，在手机上根本拖不动
     * （fixed 全屏层里的内层滚动 + 长按手势会互相打架）。
     * 现在这块只当画布，拖动/缩放由 JS 接管，白卡样式挪到棋盘自己身上。
     *
     * 底色直接给成面板同款浅灰：以前这里是透明的 + 一条 18px 深色渐变
     * 提示「还能拖」，那条带子压在棋盘边上像块脏印子，已经去掉。
     */
    #sweeper-sheet .sw-board-wrap {
        order: 3;
        position: relative;
        display: block;
        flex: 1 1 auto;
        min-height: 0;
        /* 基类里有 max-width: calc(100vw - 60px)，不清掉画布会窄 60px */
        width: auto;
        max-width: none;
        /* 上边留一点，棋盘别顶着难度条 */
        margin: 6px 0 4px;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: #f4f5f8;
        box-shadow: none;
        overflow: hidden;
        /* 手势全归我们自己处理，别让浏览器去滚页面 */
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
    }

    #sweeper-sheet .sw-board {
        position: absolute;
        top: 0;
        left: 0;
        display: grid;
        grid-template-columns: repeat(var(--sw-cols), var(--sw-tile));
        grid-auto-rows: var(--sw-tile);
        gap: 2px;
        width: max-content;
        margin: 0;
        padding: 8px;
        border: 0;
        border-radius: 16px;
        background: #ffffff;
        box-shadow: 0 1px 3px rgba(20, 22, 40, .08);
        /* JS 用 translate + scale 控制位置，原点固定左上角才好算 */
        transform-origin: 0 0;
        will-change: transform;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: none;
    }

    #sweeper-sheet .sw-tile {
        width: var(--sw-tile);
        height: var(--sw-tile);
        border: 0;
        border-radius: 6px;
        background: #c5cfe1;
        color: #1c1c1e;
        font-family: inherit;
        font-size: calc(var(--sw-tile) * .52);
        font-weight: 600;
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, .55),
            inset 0 -1px 0 rgba(20, 22, 40, .1);
        transition: background .1s ease, transform .1s ease;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    #sweeper-sheet .sw-tile.is-press {
        background: #aebbd0;
        transform: scale(.94);
    }

    #sweeper-sheet .sw-tile.is-open {
        border: 0;
        background: #f7f9fc;
        box-shadow: inset 0 0 0 1px #e3e7ee;
        font-weight: 600;
    }

    #sweeper-sheet .sw-tile.is-open.is-press {
        background: #eceef3;
    }

    /* 数字配色用手机 App 那套（比原版纯色柔和一档） */
    #sweeper-sheet .sw-tile[data-n="1"] { color: #1976d2; }
    #sweeper-sheet .sw-tile[data-n="2"] { color: #2e7d32; }
    #sweeper-sheet .sw-tile[data-n="3"] { color: #d32f2f; }
    #sweeper-sheet .sw-tile[data-n="4"] { color: #6a1b9a; }
    #sweeper-sheet .sw-tile[data-n="5"] { color: #a1341b; }
    #sweeper-sheet .sw-tile[data-n="6"] { color: #00838f; }
    #sweeper-sheet .sw-tile[data-n="7"] { color: #37474f; }
    #sweeper-sheet .sw-tile[data-n="8"] { color: #78909c; }

    #sweeper-sheet .sw-tile.is-flag {
        font-size: calc(var(--sw-tile) * .54);
    }

    #sweeper-sheet .sw-tile.is-boom {
        background: #ff453a;
    }

    #sweeper-sheet .sw-tile.is-mine {
        background: #f7f8fa;
    }

    #sweeper-sheet .sw-tile.is-wrong {
        background: #fde2e1;
    }

    /* 底部提示 */
    #sweeper-sheet .sw-foot {
        order: 4;
        flex: none;
        padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
        font-size: 11.5px;
        color: #8a8a8f;
    }
}

/* ---------- 结束 / 胜利浮层（1.6.48） ---------- */

/* 桌面基类没有 relative，浮层覆盖棋盘区全靠它 */
.sw-board-wrap {
    position: relative;
}

.sw-over {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border-radius: 2px;
    background: rgba(236, 233, 216, .9);
    color: #1a1a1a;
    font-family: Tahoma, "Segoe UI", "Microsoft YaHei", sans-serif;
    animation: sw-over-in .2s ease;
}

.sw-over[hidden] {
    display: none;
}

@keyframes sw-over-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.sw-over-text {
    font-size: 19px;
    font-weight: 700;
}

.sw-over-sub {
    font-size: 12.5px;
    color: #5a564d;
}

.sw-over-btns {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.sw-over-btns button,
.sw-stats {
    flex: none;
    min-width: 30px;
    height: 28px;
    padding: 0 12px;
    border: 1px solid #aca899;
    border-radius: 2px;
    background: #ece9d8;
    color: #1a1a1a;
    font-size: 12.5px;
    line-height: 1;
    cursor: pointer;
    box-shadow: inset 1px 1px 0 #ffffff;
}

.sw-over-btns button:hover,
.sw-stats:hover {
    background: #fff0d8;
}
