* {
    box-sizing: border-box;
}


html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100%;

    background: #080808;
    color: #f2f2f2;

    font-family:
        Arial,
        "Microsoft YaHei",
        "PingFang SC",
        sans-serif;
}


body {
    min-height: 100vh;
}


button,
input {
    font: inherit;
}


a {
    color: inherit;
    text-decoration: none;
}


/* =====================================================
   页面容器
   ===================================================== */

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}


/* =====================================================
   顶部
   ===================================================== */

.topbar {
    padding: 28px 0 20px;
    border-bottom: 1px solid #242424;
}


.brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}


.brand-left {
    min-width: 0;
}


.brand-title {
    margin: 0;

    font-size: 30px;
    font-weight: 800;
    letter-spacing: 1px;
}


.brand-subtitle {
    margin-top: 7px;

    color: #777;

    font-size: 12px;
    letter-spacing: 2px;
}


/* =====================================================
   顶部右侧按钮
   ===================================================== */

.top-actions {
    display: grid;

    grid-template-columns: auto auto;

    align-items: start;

    gap: 8px;

    flex-shrink: 0;
}


.top-action,
.back-home {
    padding: 9px 14px;

    border: 1px solid #333;
    border-radius: 8px;

    color: #aaa;
    background: #111;

    cursor: pointer;

    transition:
        color .2s,
        border-color .2s,
        background .2s;
}


.top-action:hover,
.back-home:hover {
    color: #fff;

    border-color: #666;

    background: #181818;
}


#back-library {
    grid-column: 1;
    grid-row: 1;
}


.back-home {
    grid-column: 2;
    grid-row: 1;
}


#fullscreen-game {
    grid-column: 2;
    grid-row: 2;
}


/* =====================================================
   搜索
   ===================================================== */

.search-area {
    padding: 22px 0;
}


#game-search {
    width: 100%;
    height: 44px;

    padding: 0 15px;

    border: 1px solid #292929;
    border-radius: 9px;

    outline: none;

    background: #101010;
    color: #fff;

    transition:
        border-color .2s,
        background .2s;
}


#game-search:focus {
    border-color: #555;
}


#game-search::placeholder {
    color: #666;
}


/* =====================================================
   游戏库
   ===================================================== */

.library {
    padding: 8px 0 50px;
}


.library-header {
    display: flex;

    align-items: center;
    justify-content: space-between;

    margin-bottom: 18px;
}


.library-title {
    margin: 0;

    font-size: 19px;
}


.game-count {
    color: #666;

    font-size: 13px;
}


.games-grid {
    display: grid;

    grid-template-columns:
        repeat(auto-fill, minmax(240px, 1fr));

    gap: 18px;
}


/* =====================================================
   游戏卡片
   ===================================================== */

.game-card {
    display: flex;

    flex-direction: column;

    min-width: 0;
    min-height: 390px;

    overflow: hidden;

    border: 1px solid #242424;
    border-radius: 12px;

    background: #101010;

    transition:
        transform .2s,
        border-color .2s,
        background .2s;
}


.game-card:hover {
    transform: translateY(-3px);

    border-color: #454545;

    background: #141414;
}


/* =====================================================
   游戏封面
   ===================================================== */

.game-cover {
    position: relative;

    width: 100%;

    aspect-ratio: 16 / 10;

    overflow: hidden;

    background:
        linear-gradient(
            135deg,
            #181818 0%,
            #101010 100%
        );

    border-bottom: 1px solid #242424;
}


.game-cover::after {
    content: "";

    position: absolute;

    inset: 0;

    background:
        linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0) 55%,
            rgba(0, 0, 0, .18) 100%
        );

    pointer-events: none;
}


.game-cover img {
    display: block;

    width: 100%;
    height: 100%;

    object-fit: cover;

    transition:
        transform .3s,
        opacity .2s;
}


.game-card:hover .game-cover img {
    transform: scale(1.03);
}


/* =====================================================
   图片占位
   ===================================================== */

.game-cover-placeholder {
    position: absolute;

    inset: 0;

    display: flex;

    align-items: center;
    justify-content: center;

    color: #444;

    font-size: 12px;
    letter-spacing: 1px;
}


.game-cover-placeholder::before {
    content: "NES";

    display: flex;

    align-items: center;
    justify-content: center;

    width: 64px;
    height: 64px;

    border: 1px solid #303030;
    border-radius: 50%;

    background: #151515;

    color: #555;

    font-size: 13px;
    font-weight: 700;

    letter-spacing: 2px;
}


/* =====================================================
   游戏卡片内容
   ===================================================== */

.game-card-content {
    display: flex;

    flex-direction: column;

    flex: 1;

    padding: 16px 17px 17px;
}


.game-card h2 {
    margin: 0 0 8px;

    overflow: hidden;

    font-size: 18px;
    line-height: 1.4;

    white-space: nowrap;
    text-overflow: ellipsis;
}


.game-description {
    display: -webkit-box;

    margin: 0;

    overflow: hidden;

    color: #777;

    font-size: 13px;
    line-height: 1.65;

    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}


.game-meta {
    margin-top: 12px;

    color: #555;

    font-size: 11px;
    letter-spacing: .5px;
}


.game-play {
    margin-top: auto;

    padding-top: 16px;
}


.play-button {
    display: block;

    width: 100%;

    padding: 10px 14px;

    border: 1px solid #3a3a3a;
    border-radius: 7px;

    background: #191919;
    color: #fff;

    text-align: center;

    cursor: pointer;

    transition:
        background .2s,
        border-color .2s;
}


.play-button:hover {
    background: #252525;

    border-color: #666;
}


.empty {
    grid-column: 1 / -1;

    padding: 50px 20px;

    border: 1px dashed #292929;
    border-radius: 10px;

    color: #666;

    text-align: center;
}


/* =====================================================
   玩家页面
   ===================================================== */

.player-page {
    display: none;

    padding: 24px 0 50px;
}


.player-header {
    margin-bottom: 18px;
}


.player-title {
    margin: 0;

    font-size: 25px;
}


.player-description {
    margin: 8px 0 0;

    color: #777;

    font-size: 13px;
}


/* =====================================================
   JSNES 掌机容器
   ===================================================== */

.emulator-shell {
    position: relative;

    width: min(100%, 540px);

    margin: 0 auto;

    overflow: hidden;

    border: 1px solid #252525;
    border-radius: 14px;

    background: #101010;

    box-shadow:
        0 18px 50px rgba(0, 0, 0, .35);
}


.handheld-device {
    width: 100%;
}


/* =====================================================
   JSNES 游戏画面
   ===================================================== */

#game {
    position: relative;

    width: 100%;

    aspect-ratio: 4 / 3;

    overflow: hidden;

    background: #000;
}


#game canvas {
    display: block;

    width: 100% !important;
    height: 100% !important;

    object-fit: contain;
}


/* =====================================================
   开始游戏遮罩
   ===================================================== */

#start-overlay {
    position: absolute;

    z-index: 1000;

    inset: 0;

    display: flex;

    align-items: center;
    justify-content: center;

    background:
        radial-gradient(
            circle at center,
            #171717 0%,
            #0a0a0a 55%,
            #050505 100%
        );
}


.start-box {
    width: min(430px, calc(100% - 40px));

    padding: 30px 25px;

    border: 1px solid #2e2e2e;
    border-radius: 14px;

    background: rgba(12, 12, 12, .95);

    text-align: center;
}


.start-box h2 {
    margin: 0 0 8px;

    font-size: 24px;
}


.start-box p {
    margin: 0 0 22px;

    color: #777;

    font-size: 13px;
    line-height: 1.7;
}


#start-game {
    width: 100%;

    padding: 13px 18px;

    border: 1px solid #555;
    border-radius: 8px;

    background: #1c1c1c;
    color: #fff;

    cursor: pointer;

    transition:
        background .2s,
        border-color .2s;
}


#start-game:hover {
    background: #292929;

    border-color: #777;
}


#start-game:disabled {
    opacity: .5;

    cursor: wait;
}


/* =====================================================
   移动端掌机控制器
   ===================================================== */

.touch-controls {
    display: grid;

    grid-template-columns: 1fr auto 1fr;

    align-items: center;

    gap: 16px;

    padding: 22px 22px 24px;

    background: #101010;

    border-top: 1px solid #242424;

    user-select: none;

    -webkit-user-select: none;
    -webkit-touch-callout: none;

    touch-action: none;
}


/* =====================================================
   虚拟摇杆
   ===================================================== */

.dpad {
    position: relative;

    width: 150px;
    height: 150px;

    margin: 0 auto;

    display: flex;

    align-items: center;
    justify-content: center;

    user-select: none;

    -webkit-user-select: none;
    -webkit-touch-callout: none;

    touch-action: none;
}


.joystick-base {
    position: relative;

    width: 132px;
    height: 132px;

    border: 1px solid #383838;
    border-radius: 50%;

    background:
        radial-gradient(
            circle at center,
            #1d1d1d 0%,
            #171717 55%,
            #121212 100%
        );

    box-shadow:
        inset 0 0 0 8px #101010,
        inset 0 0 20px rgba(0, 0, 0, .45);

    user-select: none;

    -webkit-user-select: none;
    -webkit-touch-callout: none;

    touch-action: none;
}


.joystick-base::before {
    content: "";

    position: absolute;

    top: 50%;
    left: 50%;

    width: 86px;
    height: 86px;

    transform: translate(-50%, -50%);

    border: 1px solid #292929;
    border-radius: 50%;

    pointer-events: none;
}


.joystick-base::after {
    content: "";

    position: absolute;

    top: 50%;
    left: 50%;

    width: 2px;
    height: 2px;

    transform: translate(-50%, -50%);

    border-radius: 50%;

    background: #444;

    pointer-events: none;
}


.joystick-knob {
    position: absolute;

    top: 50%;
    left: 50%;

    width: 58px;
    height: 58px;

    transform:
        translate(-50%, -50%);

    border: 1px solid #444;
    border-radius: 50%;

    background:
        radial-gradient(
            circle at 35% 30%,
            #252525 0%,
            #1b1b1b 55%,
            #151515 100%
        );

    box-shadow:
        0 4px 10px rgba(0, 0, 0, .45),
        inset 0 1px 0 rgba(255, 255, 255, .04);

    cursor: pointer;

    user-select: none;

    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;

    touch-action: none;

    transition:
        background .08s,
        border-color .08s;
}


.joystick-knob.pressed {
    border-color: #666;

    background:
        radial-gradient(
            circle at 35% 30%,
            #303030 0%,
            #222 55%,
            #191919 100%
        );
}


/* =====================================================
   中间 Start / Select
   ===================================================== */

.center-controls {
    display: flex;

    flex-direction: column;

    align-items: center;
    justify-content: center;

    gap: 12px;
}


.center-button {
    min-width: 76px;

    padding: 8px 12px;

    border: 1px solid #303030;
    border-radius: 7px;

    background: #171717;
    color: #888;

    font-size: 11px;
    letter-spacing: .8px;

    cursor: pointer;

    user-select: none;

    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;

    touch-action: none;

    transition:
        background .08s,
        border-color .08s,
        color .08s;
}


.center-button:active,
.center-button.pressed {
    background: #292929;

    border-color: #666;

    color: #fff;
}


/* =====================================================
   A / B 按钮
   ===================================================== */

.action-buttons {
    display: flex;

    align-items: center;
    justify-content: center;

    gap: 18px;

    transform: rotate(-8deg);
}


.action-button {
    display: flex;

    align-items: center;
    justify-content: center;

    width: 64px;
    height: 64px;

    padding: 0;

    border: 1px solid #3a3a3a;
    border-radius: 50%;

    background: #1a1a1a;
    color: #aaa;

    font-size: 20px;
    font-weight: 700;

    cursor: pointer;

    user-select: none;

    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;

    touch-action: none;

    transition:
        background .08s,
        border-color .08s,
        color .08s;
}


.action-button:active,
.action-button.pressed {
    background: #292929;

    border-color: #666;

    color: #fff;
}


/* =====================================================
   键位说明
   ===================================================== */

.controls-panel {
    width: min(100%, 540px);

    margin: 18px auto 0;

    padding: 18px;

    border: 1px solid #242424;
    border-radius: 10px;

    background: #101010;
}


.controls-title {
    margin-bottom: 13px;

    color: #aaa;

    font-size: 12px;
    letter-spacing: 1px;
}


.controls {
    display: flex;

    flex-wrap: wrap;

    gap: 8px;
}


.key {
    display: inline-flex;

    align-items: center;

    gap: 7px;

    padding: 7px 10px;

    border: 1px solid #2b2b2b;
    border-radius: 6px;

    background: #151515;

    font-size: 12px;
}


.key kbd {
    min-width: 26px;

    padding: 3px 6px;

    border: 1px solid #444;
    border-radius: 4px;

    background: #202020;
    color: #fff;

    font-family: monospace;

    text-align: center;
}


.key span {
    color: #777;
}


/* =====================================================
   玩家按钮
   ===================================================== */

.player-actions {
    display: none;
}


.player-action {
    padding: 9px 14px;

    border: 1px solid #292929;
    border-radius: 7px;

    background: #101010;
    color: #aaa;

    cursor: pointer;

    transition:
        color .2s,
        border-color .2s,
        background .2s;
}


.player-action:hover {
    color: #fff;

    border-color: #555;

    background: #171717;
}


/* =====================================================
   全屏模式
   ===================================================== */

.emulator-shell:fullscreen {
    display: flex;

    align-items: center;
    justify-content: center;

    width: 100vw;
    height: 100vh;

    min-height: 100vh;

    max-width: none;

    margin: 0;

    border: 0;
    border-radius: 0;

    background: #000;
}


.emulator-shell:fullscreen .handheld-device {
    width: min(540px, 100vw);

    max-height: 100vh;
}


.emulator-shell:fullscreen #game {
    aspect-ratio: 4 / 3;
}


.emulator-shell:-webkit-full-screen {
    display: flex;

    align-items: center;
    justify-content: center;

    width: 100vw;
    height: 100vh;

    min-height: 100vh;

    max-width: none;

    margin: 0;

    border: 0;
    border-radius: 0;

    background: #000;
}


.emulator-shell:-webkit-full-screen .handheld-device {
    width: min(540px, 100vw);

    max-height: 100vh;
}


/* =====================================================
   自定义移动端降级全屏
   ===================================================== */

.emulator-shell.mobile-fullscreen {
    position: fixed;

    top: 0;
    left: 0;

    width: 100vw;
    height: 100vh;

    max-width: none;

    margin: 0;

    z-index: 99999;

    border: 0;
    border-radius: 0;

    display: flex;

    align-items: center;
    justify-content: center;

    background: #000;
}


.emulator-shell.mobile-fullscreen .handheld-device {
    width: min(540px, 100vw);

    max-height: 100vh;
}


/* =====================================================
   Footer
   ===================================================== */

footer {
    padding: 25px 0 35px;

    border-top: 1px solid #202020;

    color: #555;

    font-size: 11px;

    text-align: center;
}


/* =====================================================
   手机适配
   ===================================================== */

@media (max-width: 700px) {

    .page {
        width: min(100% - 20px, 1180px);
    }


    .brand-title {
        font-size: 24px;
    }


    .brand {
        align-items: flex-start;
    }


    .back-home,
    .top-action {
        padding: 8px 10px;

        font-size: 12px;
    }


    .top-actions {
        gap: 5px;
    }


    .player-page {
        padding-top: 18px;
    }


    .player-title {
        font-size: 22px;
    }


    /* =================================================
       手机游戏列表
       ================================================= */

    .games-grid {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));

        gap: 10px;
    }


    .game-card {
        min-height: 330px;

        border-radius: 10px;
    }


    .game-card-content {
        padding: 13px;
    }


    .game-card h2 {
        margin-bottom: 6px;

        font-size: 15px;
    }


    .game-description {
        font-size: 12px;

        line-height: 1.55;

        -webkit-line-clamp: 3;
    }


    .game-meta {
        margin-top: 9px;

        font-size: 10px;
    }


    .game-play {
        padding-top: 12px;
    }


    .play-button {
        padding: 9px 10px;

        font-size: 12px;
    }


    /* =================================================
       掌机
       ================================================= */

    .emulator-shell {
        width: 100%;

        border-radius: 12px;
    }


    #game {
        width: 100%;

        aspect-ratio: 4 / 3;

        min-height: 0;
    }


    .touch-controls {
        grid-template-columns:
            1fr
            auto
            1fr;

        gap: 8px;

        padding:
            18px
            10px
            20px;
    }


    .dpad {
        width: 132px;
        height: 132px;
    }


    .joystick-base {
        width: 116px;
        height: 116px;
    }


    .joystick-base::before {
        width: 76px;
        height: 76px;
    }


    .joystick-knob {
        width: 52px;
        height: 52px;
    }


    .action-buttons {
        gap: 10px;
    }


    .action-button {
        width: 56px;
        height: 56px;

        font-size: 18px;
    }


    .center-button {
        min-width: 66px;

        padding: 7px 9px;

        font-size: 10px;
    }


    .controls-panel {
        width: 100%;
    }


    .controls {
        gap: 6px;
    }


    .key {
        font-size: 11px;
    }

}


/* =====================================================
   小屏手机进一步缩放
   ===================================================== */

@media (max-width: 390px) {

    .games-grid {
        grid-template-columns: 1fr;

        gap: 12px;
    }


    .game-card {
        min-height: 0;
    }


    .game-cover {
        aspect-ratio: 16 / 9;
    }


    .game-card-content {
        padding: 14px;
    }


    .touch-controls {
        padding-left: 6px;
        padding-right: 6px;
    }


    .dpad {
        width: 116px;
        height: 116px;
    }


    .joystick-base {
        width: 102px;
        height: 102px;
    }


    .joystick-base::before {
        width: 66px;
        height: 66px;
    }


    .joystick-knob {
        width: 46px;
        height: 46px;
    }


    .action-buttons {
        gap: 7px;
    }


    .action-button {
        width: 50px;
        height: 50px;

        font-size: 17px;
    }


    .center-button {
        min-width: 58px;

        font-size: 9px;
    }

}