* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    background: #2c2c2c;
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#game-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Language Toggle button removed — now in Settings panel */

/* Game Boy Shell */
.gameboy-shell {
    background: linear-gradient(145deg, #bcc3c9, #a0a8b0);
    border-radius: 20px 20px 80px 20px;
    padding: 20px 24px 40px;
    box-shadow:
        0 8px 32px rgba(0,0,0,0.5),
        inset 0 2px 0 rgba(255,255,255,0.3);
}

.gameboy-header {
    text-align: center;
    font-size: 8px;
    letter-spacing: 3px;
    color: #666;
    margin-bottom: 8px;
    font-weight: bold;
}

.screen-bezel {
    background: #4a4a4a;
    border-radius: 12px;
    padding: 20px;
    position: relative;
    box-shadow:
        inset 0 4px 12px rgba(0,0,0,0.5),
        0 1px 0 rgba(255,255,255,0.2);
}

canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    border-radius: 4px;
    touch-action: none;
    max-width: 100%;
    max-height: 100%;
}

/* Overlay shared styles */
.overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    background: rgba(155, 188, 15, 0.97);
    border-radius: 4px;
    z-index: 10;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 10px;
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar but still allow scroll when really needed */
.overlay::-webkit-scrollbar { width: 0; display: none; }
.overlay { scrollbar-width: none; -ms-overflow-style: none; }

/* Menu Screen */
.menu-title {
    font-size: 20px;
    font-weight: bold;
    color: #0F380F;
    text-shadow: 2px 2px 0 #306230;
    margin-bottom: 1px;
    letter-spacing: 2px;
}

.menu-btn {
    background: #0F380F;
    color: #9BBC0F;
    border: none;
    padding: 6px 20px;
    font-size: 13px;
    font-family: monospace;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    min-width: 180px;
    letter-spacing: 1px;
}

.menu-btn:hover {
    background: #306230;
    transform: scale(1.05);
}

.menu-btn:active {
    transform: scale(0.97);
}

/* Ensure ALL menu buttons have identical width for centering */
#menu-screen .menu-btn,
#menu-screen .mode-btn-row {
    width: 220px;
    max-width: 100%;
    box-sizing: border-box;
}

.menu-btn-secondary {
    background: #306230;
}

.menu-hint {
    font-size: 9px;
    color: #306230;
    margin-top: 1px;
}

/* Settings Panel */
.settings-title {
    font-size: 20px;
    font-weight: bold;
    color: #0F380F;
    margin-bottom: 6px;
}

.setting-row {
    width: 80%;
    max-width: 260px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setting-row label {
    font-size: 13px;
    color: #0F380F;
    font-weight: bold;
}

.setting-row select,
.setting-row input[type="range"] {
    width: 100%;
    padding: 6px 8px;
    font-size: 14px;
    font-family: monospace;
    background: #0F380F;
    color: #9BBC0F;
    border: 2px solid #306230;
    border-radius: 4px;
    cursor: pointer;
}

.setting-row select option {
    background: #0F380F;
    color: #9BBC0F;
}

/* Custom range slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    background: #306230;
    border-radius: 4px;
    outline: none;
    padding: 0;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #0F380F;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #9BBC0F;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #0F380F;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #9BBC0F;
}

#volume-value {
    font-weight: normal;
    opacity: 0.7;
}

/* Player Info */
.player-info {
    font-size: 11px;
    color: #306230;
    cursor: pointer;
    padding: 2px 10px;
    background: rgba(15, 56, 15, 0.1);
    border-radius: 4px;
}

.nick-label {
    text-decoration: underline;
    cursor: pointer;
}

.nick-label:hover {
    color: #0F380F;
}

/* Nickname input */
.text-input {
    width: 100%;
    padding: 8px 10px;
    font-size: 14px;
    font-family: monospace;
    background: #0F380F;
    color: #9BBC0F;
    border: 2px solid #306230;
    border-radius: 4px;
    outline: none;
}

.text-input::placeholder {
    color: #4a6a2a;
}

.text-input:focus {
    border-color: #9BBC0F;
}

/* Leaderboard */
.leaderboard-list {
    width: 90%;
    max-height: 55%;
    overflow-y: auto;
    background: rgba(15, 56, 15, 0.15);
    border-radius: 6px;
    padding: 6px;
}

.lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    font-family: monospace;
    color: #0F380F;
}

.lb-table th {
    padding: 4px 6px;
    text-align: left;
    border-bottom: 2px solid #306230;
    font-size: 10px;
    color: #306230;
    text-transform: uppercase;
}

.lb-table td {
    padding: 4px 6px;
    border-bottom: 1px solid rgba(48, 98, 48, 0.2);
}

.lb-table tr:hover {
    background: rgba(15, 56, 15, 0.1);
}

.lb-me {
    background: rgba(15, 56, 15, 0.2) !important;
    font-weight: bold;
}

.lb-loading {
    text-align: center;
    padding: 20px;
    color: #306230;
    font-size: 13px;
}

.my-rank {
    font-size: 12px;
    color: #0F380F;
    font-weight: bold;
    padding: 4px 0;
}

/* Scrollbar for leaderboard */
.leaderboard-list::-webkit-scrollbar {
    width: 6px;
}

.leaderboard-list::-webkit-scrollbar-track {
    background: rgba(15, 56, 15, 0.1);
    border-radius: 3px;
}

.leaderboard-list::-webkit-scrollbar-thumb {
    background: #306230;
    border-radius: 3px;
}

/* Leaderboard Tabs */
.lb-tab-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 6px;
    width: 90%;
}

.lb-tab {
    flex: 1;
    padding: 5px 6px;
    font-size: 11px;
    font-family: monospace;
    font-weight: bold;
    background: rgba(15, 56, 15, 0.15);
    color: #306230;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.lb-tab:hover {
    background: rgba(15, 56, 15, 0.25);
}

.lb-tab.active {
    background: #0F380F;
    color: #9BBC0F;
    border-color: #306230;
}

/* Game Over Panel */
.gameover-title {
    font-size: 26px;
    font-weight: bold;
    color: #0F380F;
    text-shadow: 2px 2px 0 #306230;
    letter-spacing: 3px;
}

.gameover-score {
    font-size: 18px;
    font-weight: bold;
    color: #0F380F;
    font-family: monospace;
}

.gameover-rank {
    font-size: 16px;
    font-weight: bold;
    color: #306230;
    font-family: monospace;
    min-height: 20px;
}

.gameover-best {
    font-size: 14px;
    font-weight: bold;
    color: #0F380F;
    font-family: monospace;
    min-height: 18px;
}

/* ===== Mode Buttons ===== */
.mode-btn-row {
    position: relative;
    display: flex;
    align-items: center;
}

.mode-btn {
    width: 100%;
    min-width: 0;
}

.mode-info-icon {
    position: absolute;
    right: -26px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    background: rgba(15, 56, 15, 0.15);
    color: #306230;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.mode-info-icon:hover,
.mode-info-icon:active {
    background: rgba(15, 56, 15, 0.35);
    color: #0F380F;
}

/* Mode Info Popup */
.mode-info-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #0F380F;
    color: #9BBC0F;
    border: 2px solid #9BBC0F;
    border-radius: 8px;
    padding: 14px 16px;
    font-size: 11px;
    font-family: monospace;
    line-height: 1.6;
    z-index: 20;
    width: 85%;
    max-width: 270px;
    text-align: left;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.mode-info-close {
    position: absolute;
    top: 4px;
    right: 8px;
    background: none;
    border: none;
    color: #9BBC0F;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 4px;
    -webkit-tap-highlight-color: transparent;
}

/* Stats Bubble on Home */
.stats-bubble {
    background: rgba(15, 56, 15, 0.12);
    border: 1px solid #306230;
    border-radius: 8px;
    padding: 3px 10px;
    font-size: 10px;
    font-family: monospace;
    color: #0F380F;
    text-align: center;
    line-height: 1.4;
    position: relative;
    max-width: 240px;
}

.stats-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #306230;
}

.stats-bubble .stats-line {
    display: block;
}

.stats-bubble .stats-score {
    font-weight: bold;
    font-size: 13px;
    color: #0F380F;
}

.stats-bubble .stats-rank {
    color: #306230;
    font-size: 10px;
}

/* Wild-only settings: hidden in standard mode */
.wild-only-setting.hidden {
    display: none !important;
}

/* ===== Game Boy Controls ===== */
.gb-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 8px 4px;
    user-select: none;
    -webkit-user-select: none;
}

/* --- D-Pad --- */
.dpad-container {
    flex: 0 0 auto;
}

.dpad {
    display: grid;
    grid-template-columns: 56px 56px 56px;
    grid-template-rows: 56px 56px 56px;
    gap: 0;
    position: relative;
}

.dpad-btn {
    background: #3a3a3a;
    color: #888;
    border: none;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    z-index: 1;
}

.dpad-btn:active, .dpad-btn.active {
    background: #555;
    color: #bbb;
}

.dpad-up {
    grid-column: 2; grid-row: 1;
    border-radius: 6px 6px 0 0;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.1), 0 -2px 0 #222;
}

.dpad-down {
    grid-column: 2; grid-row: 3;
    border-radius: 0 0 6px 6px;
    box-shadow: inset 0 -2px 4px rgba(255,255,255,0.1), 0 2px 0 #222;
}

.dpad-left {
    grid-column: 1; grid-row: 2;
    border-radius: 6px 0 0 6px;
    box-shadow: inset 2px 0 4px rgba(255,255,255,0.1), -2px 0 0 #222;
}

.dpad-right {
    grid-column: 3; grid-row: 2;
    border-radius: 0 6px 6px 0;
    box-shadow: inset -2px 0 4px rgba(255,255,255,0.1), 2px 0 0 #222;
}

.dpad-center {
    grid-column: 2; grid-row: 2;
    background: #3a3a3a;
    border: none;
    position: relative;
}

.dpad-center::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 16px; height: 16px;
    background: #444;
    border-radius: 50%;
}

/* --- A / B Buttons --- */
.ab-container {
    flex: 0 0 auto;
}

.ab-buttons {
    display: flex;
    gap: 16px;
    transform: rotate(-20deg);
}

.ab-btn-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.gb-round-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    font-family: monospace;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow:
        0 4px 6px rgba(0,0,0,0.4),
        inset 0 2px 2px rgba(255,255,255,0.15);
    transition: transform 0.05s, box-shadow 0.05s;
}

.gb-round-btn:active, .gb-round-btn.active {
    transform: scale(0.93);
    box-shadow:
        0 1px 3px rgba(0,0,0,0.4),
        inset 0 2px 2px rgba(0,0,0,0.1);
}

.btn-a {
    background: #9B1B30;
    color: #e0a0a8;
}

.btn-b {
    background: #9B1B30;
    color: #e0a0a8;
}

.ab-label {
    font-size: 10px;
    color: #666;
    font-weight: bold;
    letter-spacing: 1px;
    transform: rotate(20deg);
}

/* --- SELECT / START --- */
.ss-container {
    display: flex;
    justify-content: center;
    gap: 32px;
    padding: 4px 0;
}

.ss-btn-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.ss-btn {
    width: 52px;
    height: 16px;
    border-radius: 8px;
    background: #6a6a6a;
    border: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
    transition: background 0.1s;
}

.ss-btn:active, .ss-btn.active {
    background: #888;
}

.ss-label {
    font-size: 9px;
    color: #666;
    font-weight: bold;
    letter-spacing: 2px;
}

/* ===== Pause Overlay ===== */
#pause-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(15, 56, 15, 0.85);
    border-radius: 4px;
    z-index: 15;
}

#pause-overlay .pause-text {
    font-size: 28px;
    font-weight: bold;
    color: #9BBC0F;
    font-family: monospace;
    letter-spacing: 4px;
}

#pause-overlay .pause-hint {
    font-size: 12px;
    color: #7a9a0a;
    margin-top: 10px;
    font-family: monospace;
}

/* ===== Desktop: hide Game Boy controls ===== */
@media (hover: hover) and (pointer: fine) {
    .gb-controls, .ss-container {
        display: none;
    }
}

/* Mobile responsive */
@media (max-width: 480px) {
    body {
        align-items: flex-start;
        padding-top: 8px;
    }
    .gameboy-shell {
        padding: 8px 10px 12px;
        border-radius: 10px 10px 30px 10px;
    }
    .screen-bezel {
        padding: 8px;
    }
    .menu-title {
        font-size: 18px;
    }
    .menu-btn {
        padding: 8px 20px;
        font-size: 14px;
        min-width: 150px;
    }
    #menu-screen .menu-btn,
    #menu-screen .mode-btn-row {
        width: 200px;
    }
    .settings-title, .gameover-title {
        font-size: 18px;
    }
    .overlay {
        gap: 6px;
        padding: 8px 8px;
    }
    .setting-row {
        width: 90%;
    }
    .dpad {
        grid-template-columns: 58px 58px 58px;
        grid-template-rows: 58px 58px 58px;
    }
    .gb-round-btn {
        width: 46px;
        height: 46px;
        font-size: 16px;
    }
    .gb-controls {
        padding: 12px 4px 2px;
    }
}

@media (max-width: 360px) {
    body {
        padding-top: 6px;
    }
    .gameboy-shell {
        padding: 4px 6px 8px;
        border-radius: 8px 8px 20px 8px;
    }
    .screen-bezel {
        padding: 4px;
    }
    .gameboy-header {
        font-size: 6px;
        letter-spacing: 1px;
    }
    .menu-title {
        font-size: 16px;
    }
    .menu-btn {
        padding: 7px 16px;
        font-size: 13px;
        min-width: 130px;
    }
    .dpad {
        grid-template-columns: 52px 52px 52px;
        grid-template-rows: 52px 52px 52px;
    }
    .gb-round-btn {
        width: 42px;
        height: 42px;
        font-size: 14px;
    }
    .ab-buttons {
        gap: 10px;
    }
}