* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

:root {
    --vh: 1vh;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: fixed;
}

body {
    font-family: 'Courier New', monospace;
    background: #2c2c2c;
    width: 100%;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* Game Boy 主体 */
.gameboy {
    width: 450px;
    background: linear-gradient(145deg, #b8b8b8, #8a8a8a);
    border-radius: 15px 15px 40px 40px;
    padding: 30px 25px 40px 25px;
    box-shadow: 
        0 30px 80px rgba(0, 0, 0, 0.6),
        inset 0 2px 6px rgba(255, 255, 255, 0.4),
        inset 0 -3px 6px rgba(0, 0, 0, 0.4);
    border: 4px solid #6a6a6a;
    position: relative;
}

/* 顶部扬声器孔 */
.gameboy-top {
    margin-bottom: 20px;
}

.speaker-holes {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.hole {
    width: 6px;
    height: 40px;
    background: #4a4a4a;
    border-radius: 3px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
}

/* 屏幕区域 */
.gameboy-screen-area {
    background: #5a5a5a;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.6);
}

.screen-label {
    text-align: center;
    font-size: 0.8rem;
    color: #3a3a3a;
    letter-spacing: 2px;
    margin-bottom: 8px;
    font-weight: bold;
}

.screen-frame {
    background: #2a2a2a;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 
        inset 0 4px 10px rgba(0, 0, 0, 0.9),
        0 2px 4px rgba(255, 255, 255, 0.1);
}

.screen-inner {
    background: #8bac0f;
    border-radius: 4px;
    padding: 15px;
    display: flex;
    gap: 15px;
    min-height: 400px;
}

/* 游戏信息侧边栏 */
.game-info {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 90px;
}

.info-item {
    background: rgba(15, 56, 15, 0.1);
    border: 2px solid #0f380f;
    border-radius: 4px;
    padding: 8px;
    text-align: center;
}

.info-label {
    font-size: 0.7rem;
    color: #0f380f;
    font-weight: bold;
    margin-bottom: 5px;
    letter-spacing: 1px;
}

.info-value {
    font-size: 1.3rem;
    color: #0f380f;
    font-weight: bold;
}

#previewCanvas {
    display: block;
    margin: 0 auto;
    background: transparent;
    border: none;
    border-radius: 2px;
    image-rendering: pixelated;
    height: 60px;
    width: 60px;
}

/* 游戏屏幕 */
.game-screen {
    flex: 1;
    position: relative;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #8bac0f;
    border: 3px solid #0f380f;
    border-radius: 4px;
    box-shadow: inset 0 2px 6px rgba(15, 56, 15, 0.3);
    image-rendering: pixelated;
}

/* 游戏覆盖层 */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 56, 15, 0.95);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 3px solid #0f380f;
}

.game-overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    color: #9bbc0f;
    padding: 20px;
}

.overlay-content.hidden {
    display: none;
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 15px;
    color: #9bbc0f;
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.5);
    letter-spacing: 3px;
}

.overlay-content p {
    font-size: 0.9rem;
    margin-bottom: 10px;
    color: #8bac0f;
}

.instructions {
    font-size: 0.75rem;
    color: #306230;
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

.difficulty-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 20px 0;
    padding: 0 15px;
    max-width: 100%;
}

.difficulty-display {
    background: rgba(15, 56, 15, 0.3);
    border: 3px solid #0f380f;
    border-radius: 8px;
    padding: 10px 15px;
    width: 65px;
    text-align: center;
    flex-shrink: 0;
}

.difficulty-number {
    font-size: 2rem;
    font-weight: bold;
    color: #9bbc0f;
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.5);
    letter-spacing: -0.05em;
    display: inline-block;
    width: 100%;
}

.btn-nav {
    padding: 8px 12px;
    font-size: 1rem;
    flex-shrink: 0;
    min-width: auto;
}

.btn-start {
    margin-top: 15px;
    padding: 12px 40px;
    font-size: 1rem;
}

.btn {
    padding: 12px 24px;
    border: 3px solid #0f380f;
    border-radius: 8px;
    font-size: 1.04rem;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-family: 'Courier New', monospace;
    background: #9bbc0f;
    color: #0f380f;
    box-shadow: 
        inset -2px -2px 0 rgba(15, 56, 15, 0.3),
        inset 2px 2px 0 rgba(155, 188, 15, 0.5);
    transition: all 0.15s;
    position: relative;
}

.btn:hover {
    background: #8bac0f;
    box-shadow: 
        inset -2px -2px 0 rgba(15, 56, 15, 0.4),
        inset 2px 2px 0 rgba(155, 188, 15, 0.3);
}

.btn:active,
.btn.pressed {
    background: #7a9c0f;
    box-shadow: 
        inset 2px 2px 4px rgba(15, 56, 15, 0.6),
        inset -1px -1px 2px rgba(155, 188, 15, 0.2);
    transform: scale(0.98);
}

.final-score {
    font-size: 1.2rem;
    margin: 15px 0;
    color: #9bbc0f;
}

.final-score span {
    font-weight: bold;
    font-size: 1.5rem;
}

/* 电池指示灯 */
.battery-led {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-size: 0.8rem;
    color: #3a3a3a;
    letter-spacing: 1px;
}

.led {
    width: 8px;
    height: 8px;
    background: #ff0000;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.8);
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* Game Boy Logo */
.gameboy-logo {
    text-align: center;
    margin: 20px 0;
}

.logo-text {
    font-size: 1.8rem;
    font-weight: bold;
    color: #4a4a4a;
    letter-spacing: 8px;
    text-shadow: 
        2px 2px 0 rgba(255, 255, 255, 0.3),
        -1px -1px 0 rgba(0, 0, 0, 0.3);
    font-family: Arial, sans-serif;
    font-style: italic;
}

.logo-subtitle {
    font-size: 0.7rem;
    color: #5a5a5a;
    letter-spacing: 3px;
    margin-top: -5px;
    font-family: Arial, sans-serif;
}

/* 控制区域 */
.gameboy-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 30px 0;
    padding: 0 20px;
}

/* 十字键 */
.controls-left {
    position: relative;
}

.dpad {
    width: 110px;
    height: 110px;
    position: relative;
}

.dpad-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    background: #3a3a3a;
    border-radius: 3px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
    z-index: 1;
}

.dpad-up, .dpad-down, .dpad-left, .dpad-right {
    position: absolute;
    background: #2a2a2a;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #5a5a5a;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 
        0 3px 0 #1a1a1a,
        inset 0 2px 4px rgba(255, 255, 255, 0.1);
    transition: all 0.1s;
}

.dpad-up, .dpad-down {
    width: 30px;
    height: 40px;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-left, .dpad-right {
    width: 40px;
    height: 30px;
    top: 50%;
    transform: translateY(-50%);
}

.dpad-up {
    top: 0;
    border-radius: 8px 8px 0 0;
}

.dpad-down {
    bottom: 0;
    border-radius: 0 0 8px 8px;
}

.dpad-left {
    left: 0;
    border-radius: 8px 0 0 8px;
}

.dpad-right {
    right: 0;
    border-radius: 0 8px 8px 0;
}

.dpad-up:active, .dpad-down:active, .dpad-left:active, .dpad-right:active,
.dpad-up.pressed, .dpad-down.pressed, .dpad-left.pressed, .dpad-right.pressed {
    box-shadow: 
        0 1px 0 #1a1a1a,
        inset 0 2px 4px rgba(0, 0, 0, 0.5);
    background: #1a1a1a;
}

.dpad-up:active, .dpad-up.pressed {
    transform: translateX(-50%) translateY(2px);
}

.dpad-down:active, .dpad-down.pressed {
    transform: translateX(-50%) translateY(-2px);
}

.dpad-left:active, .dpad-left.pressed {
    transform: translateY(-50%) translateX(2px);
}

.dpad-right:active, .dpad-right.pressed {
    transform: translateY(-50%) translateX(-2px);
}

/* A/B 按钮 */
.controls-right {
    text-align: center;
    position: relative;
    right: 30px;
}

.ab-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-btn {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    border: none;
    font-size: 1.3rem;
    font-weight: bold;
    cursor: pointer;
    font-family: Arial, sans-serif;
    box-shadow: 
        0 5px 0 #4a1a1a,
        0 6px 10px rgba(0, 0, 0, 0.5);
    transition: all 0.1s;
}

.btn-single {
    background: linear-gradient(145deg, #d84a4a, #a83838);
}

.game-btn:hover {
    filter: brightness(1.1);
}

.game-btn:active, .game-btn.pressed {
    transform: translateY(4px);
    box-shadow: 
        0 1px 0 #4a1a1a,
        0 2px 5px rgba(0, 0, 0, 0.5);
    filter: brightness(0.9);
}



/* 底部 Start/Select */
.gameboy-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    gap: 10px;
}

.start-select {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: center;
    flex: 1;
    max-width: 320px;
}

.small-btn {
    width: 94px;
    height: 21px;
    background: #3a3a3a;
    border: none;
    border-radius: 34px;
    font-size: 0.72rem;
    color: #7a7a7a;
    cursor: pointer;
    box-shadow: 
        inset 0 4px 6px rgba(0, 0, 0, 0.8),
        0 3px 4px rgba(255, 255, 255, 0.2);
    transform: rotate(-25deg);
    font-weight: bold;
    letter-spacing: 0.4px;
    transition: all 0.1s;
}

.small-btn:hover {
    background: #4a4a4a;
    color: #8a8a8a;
}

.small-btn:active {
    box-shadow: inset 0 5px 10px rgba(0, 0, 0, 0.9);
    transform: rotate(-25deg) translateY(2px);
}

.speaker-bottom {
    width: 60px;
    height: 40px;
    background: #4a4a4a;
    border-radius: 20px;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
    position: relative;
    margin-left: auto;
}

.speaker-bottom::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 30px;
    background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 3px,
        #3a3a3a 3px,
        #3a3a3a 5px
    );
    border-radius: 15px;
}


/* ============================================
   移动端响应式设计
   目标：在一屏内显示所有控制按钮，无需滚动
   ============================================ */
@media (max-width: 500px) {
    /* 基础设置 */
    html, body {
        padding: 0;
        margin: 0;
        width: 100vw;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        overflow: hidden;
        position: fixed;
    }

    body {
        display: flex;
        justify-content: center;
        align-items: flex-start;
    }

    /* Game Boy 主体 - 使用flexbox自适应分配空间 */
    .gameboy {
        width: 100vw;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        padding: 0;
        margin: 0;
        border-radius: 0;
        border: none;
        display: flex;
        flex-direction: column;
        background: linear-gradient(145deg, #b8b8b8, #8a8a8a);
    }

    /* 隐藏装饰性元素以节省空间 */
    .gameboy-top,
    .battery-led,
    .gameboy-logo {
        display: none;
    }

    /* 屏幕区域 - 调整大小 */
    .gameboy-screen-area {
        flex: 0.85; /* 向下移动：从0.7增加到0.85 */
        display: flex;
        flex-direction: column;
        margin: 5px;
        padding: 5px;
        min-height: 0;
    }

    .screen-label {
        display: none;
    }

    .screen-frame {
        flex: 1;
        display: flex;
        flex-direction: column;
        padding: 4px;
        min-height: 0;
    }

    .screen-inner {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding: 4px;
        min-height: 0;
    }

    /* 游戏信息 - 横向排列在顶部，顺序为 TOP SCORE | SCORE | NEXT */
    .game-info {
        display: flex;
        flex-direction: row;
        justify-content: space-between; /* 分散对齐 */
        gap: 0; /* 移除间距，让它们分散 */
        flex-shrink: 0;
        order: -1; /* 移动到顶部 */
        width: 100%; /* 占满宽度 */
    }

    .info-item:nth-child(1) {
        /* NEXT - 移到最右边，右对齐 */
        order: 3;
        text-align: right;
        flex: 0 0 auto; /* 不拉伸，保持内容宽度 */
    }

    .info-item:nth-child(2) {
        /* SCORE - 保持中间，居中对齐 */
        order: 2;
        text-align: center;
        flex: 0 0 auto; /* 不拉伸，保持内容宽度 */
    }

    .info-item:nth-child(3) {
        /* TOP SCORE - 移到最左边，左对齐 */
        order: 1;
        text-align: left;
        flex: 0 0 auto; /* 不拉伸，保持内容宽度 */
    }

    /* 游戏画面 */
    .game-screen {
        flex: 1; /* 恢复为1，让游戏画面充满整个screen-inner */
        min-height: 0;
        padding: 10px 0 15px 0; /* 上边框10px，下边框15px */
    }

    #gameCanvas {
        width: 100%;
        height: 100%;
    }

    .info-item {
        padding: 3px;
    }

    .info-label {
        font-size: 0.5rem;
        margin-bottom: 2px;
    }

    .info-value {
        font-size: 0.8rem;
    }

    #previewCanvas {
        width: 26px; /* 再缩小20%: 32 * 0.8 ≈ 26 */
        height: 26px;
    }

    /* 控制区域 - 紧贴屏幕区下边框 */
    .gameboy-controls {
        flex-shrink: 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 5px 20px 5px 20px; /* 左右增加10px: 10px改为20px */
        margin: 10px 0 0 0; /* 与屏幕区间距10px */
        height: 116px; /* 增加以容纳更大的按钮: 106px dpad + 10px padding */
    }

    .dpad {
        width: 106px; /* 增加5px: 101 + 5 = 106 */
        height: 106px; /* 保持正方形 */
    }

    .dpad-center {
        width: 29px; /* 按比例增加 */
        height: 29px;
    }

    .dpad-up, .dpad-down {
        width: 34px; /* 宽度增加5px: 29 + 5 = 34 */
        height: 52px; /* 长度增加10px: 42 + 10 = 52 */
        font-size: 1.1rem;
    }

    .dpad-left, .dpad-right {
        width: 52px; /* 长度增加10px: 42 + 10 = 52 */
        height: 34px; /* 宽度增加5px: 29 + 5 = 34 */
        font-size: 1.1rem;
    }

    .controls-right {
        right: 10px;
    }

    .game-btn {
        width: 76px; /* 增加10px: 66 + 10 = 76 */
        height: 76px;
        font-size: 1.7rem;
    }

    /* 底部按钮 - 固定在底部 */
    .gameboy-bottom {
        flex-shrink: 0;
        height: 36px;
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 5px;
        padding: 5px;
        margin: auto 0 10px 0; /* 向上移动5px: 5px改为10px */
    }

    .start-select {
        display: flex;
        gap: 5px;
        flex-wrap: nowrap;
    }

    .small-btn {
        width: 91px; /* 增加30%: 70 * 1.3 = 91 */
        height: 26px; /* 增加30%: 20 * 1.3 = 26 */
        font-size: 0.65rem;
        padding: 2px;
        letter-spacing: 0.3px;
    }

    .speaker-bottom {
        display: none;
    }

    /* 覆盖层内容缩小 */
    .overlay-content {
        padding: 10px;
    }

    .overlay-content h2 {
        font-size: 1.3rem;
        margin-bottom: 10px;
    }

    .overlay-content p {
        font-size: 0.75rem;
        margin-bottom: 8px;
    }

    .instructions {
        font-size: 0.6rem;
    }

    .difficulty-selector {
        gap: 6px;
        margin: 10px 0;
    }

    .difficulty-display {
        width: 50px;
        padding: 5px 10px;
    }

    .difficulty-number {
        font-size: 1.6rem;
    }

    .btn-nav {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    .btn-start {
        padding: 8px 20px;
        font-size: 0.8rem;
    }

    .btn {
        padding: 8px 15px;
        font-size: 0.75rem;
    }

    .final-score {
        font-size: 0.9rem;
    }

    .final-score span {
        font-size: 1.2rem;
    }
}
