/* First Visit Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.modal.hidden {
    display: none !important;
}
.modal-content {
    background: #23272f;
    color: #fff;
    border-radius: 14px;
    padding: 32px 40px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.18);
    font-size: 1.1em;
    font-family: 'Roboto', Arial, sans-serif;
    text-align: center;
    min-width: 220px;
    max-width: 90vw;
}
.control-btn.danger {
    background: #d93838 !important;
    color:#fff;
}
.control-btn.danger:hover {
    background:#b52b2b !important;
}
#close-first-visit {
    margin-top: 18px;
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 24px;
    font-size: 1em;
    cursor: pointer;
    font-family: 'Roboto', Arial, sans-serif;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: background 0.2s;
}
#close-first-visit:hover {
    background: #2ecc40;
}
/* Authentication Error Popup Modal */
.auth-error-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.auth-error-modal.hidden {
    display: none !important;
}
.auth-error-modal-content {
    background: #fff;
    color: #d32f2f;
    border-radius: 12px;
    padding: 24px 32px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.18);
    font-size: 1.1em;
    font-family: 'Roboto', Arial, sans-serif;
    text-align: center;
    min-width: 220px;
    max-width: 90vw;
}
.auth-error-close-btn {
    margin-top: 18px;
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 24px;
    font-size: 1em;
    cursor: pointer;
    font-family: 'Roboto', Arial, sans-serif;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: background 0.2s;
}
.auth-error-close-btn:hover {
    background: #4f5fa3;
}
/* Authentication Error Message */
.auth-error-message {
    background: #ffeded;
    color: #d32f2f;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 1em;
    font-family: 'Roboto', Arial, sans-serif;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid #d32f2f;
    text-align: center;
    display: none;
}
/* Leaderboard Section Styling */
.leaderboard-section {
    background: var(--sidebar-bg, #181c24);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    padding: 18px 16px 12px 16px;
    margin-bottom: 18px;
    color: #fff;
    font-family: 'Roboto', Arial, sans-serif;
    font-size: 1rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.leaderboard-section h3 {
    font-family: 'Orbitron', 'Roboto', Arial, sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #667eea;
}

.leaderboard-container ol {
    margin: 0;
    padding-left: 20px;
}

.leaderboard-container li {
    margin-bottom: 6px;
    font-size: 1rem;
    color: #fff;
}

/* Inventory Icons */
.inventory .inv-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
    vertical-align: middle;
    margin-right: 6px;
    image-rendering: pixelated;
}

.inventory-item .item-name {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.inventory-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 4px 6px;
    background: rgba(255,255,255,0.05);
    border-radius: 6px;
    margin-bottom: 6px;
}

.inventory-item .use-item-btn {
    background: #444b5a;
    border: none;
    color: #fff;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.2s;
}
.inventory-item .use-item-btn:hover {
    background: #667eea;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
    font-size: 1rem;
/* Responsive global styles */
@media (max-width: 1200px) {
    body {
        font-size: 0.95rem;
    }
    .game-header {
        padding: 12px 10px;
    }
    .auth-box {
        padding: 24px;
        max-width: 320px;
    }
}

@media (max-width: 900px) {
    body {
        font-size: 0.92rem;
    }
    .game-header {
        flex-direction: column;
        gap: 10px;
        padding: 8px 4px;
    }
    .auth-container {
        padding: 8px;
    }
    .auth-box {
        padding: 16px;
        max-width: 95vw;
    }
    .game-main {
        flex-direction: column;
        height: auto;
    }
    .game-sidebar {
        width: 100%;
        max-width: none;
        min-width: 0;
        position: static;
        margin-bottom: 18px;
        border-right: none;
        border-bottom: 1px solid rgba(255,255,255,0.08);
        padding: 10px 6px;
    }
    .game-center {
        padding: 10px 0;
    }
    .pixel-grid {
        max-width: 100vw;
        height: 300px;
        min-height: 180px;
    }
}

@media (max-width: 600px) {
    body {
        font-size: 0.88rem;
    }
    .game-header {
        flex-direction: column;
        gap: 6px;
        padding: 4px 2px;
    }
    .auth-container {
        padding: 2px;
    }
    .auth-box {
        padding: 8px;
        max-width: 99vw;
    }
    .game-main {
        flex-direction: column;
        height: auto;
    }
    .game-sidebar {
        width: 100%;
        max-width: none;
        min-width: 0;
        border-right: none;
        border-bottom: 1px solid rgba(255,255,255,0.08);
        padding: 4px 1px;
    }
    .game-center {
        padding: 2px 0;
    }
    .grid-container {
        padding: 0 1px;
    }
    .pixel-grid {
        max-width: 100vw;
        height: 300px;
        min-height: 300px;
    }
    .sidebar-section h3 {
        font-size: 1rem;
        margin-bottom: 8px;
    }
    .item-desc {
        font-size: 0.8em;
    }
    .shop-item {
        font-size: 0.95em;
    }
    .profile-modal-content {
        padding: 8px;
    }
}
}

.hidden {
    display: none !important;
}

/* Authentication Styles */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    /* Updated Authentication Styles for Consistency */
    .auth-container {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 100vh;
        background: linear-gradient(135deg, #23272f 0%, #181c24 100%);
        z-index: 100;
    }
    .auth-box {
        background: var(--sidebar-bg, #181c24);
        border-radius: 18px;
        box-shadow: 0 4px 24px rgba(0,0,0,0.18);
        padding: 40px 36px 32px 36px;
        width: 100%;
        max-width: 420px;
        width: 100%;
        box-sizing: border-box;
        text-align: center;
        color: #fff;
        font-family: 'Roboto', Arial, sans-serif;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 18px 8px 12px 8px;
    }
    .auth-form {
        margin-top: 8px;
        display: flex;
        flex-direction: column;
        gap: 8px;
        background: rgba(24,28,36,0.98);
        border-radius: 12px;
        padding: 8px 4px 8px 4px;
        width: 100%;
        box-sizing: border-box;
@media (max-width: 600px) {
    .auth-box {
        max-width: 99vw;
        padding: 2px 1px 4px 1px;
    }
    .auth-form {
        padding: 2px 1px 2px 1px;
        font-size: 0.97em;
        margin-top: 2px;
        gap: 4px;
    }
}
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    }
    .auth-form h2 {
        font-family: 'Orbitron', 'Roboto', Arial, sans-serif;
        font-size: 1.15rem;
        font-weight: 700;
        margin-bottom: 10px;
    color: #667eea;
    }
    .auth-form input {
        padding: 10px 12px;
        border-radius: 8px;
        border: none;
        background: #23272f;
        color: #fff;
        font-size: 1rem;
        font-family: 'Roboto', Arial, sans-serif;
        outline: none;
        box-shadow: 0 1px 4px rgba(0,0,0,0.08);
        transition: background 0.2s;
    }
    .auth-form input:focus {
        background: #181c24;
    }
    .auth-btn {
    background: linear-gradient(90deg, #667eea 0%, #4f5fa3 100%);
    color: #fff;
        font-weight: 700;
        border: none;
        border-radius: 8px;
        padding: 10px 0;
        font-size: 1rem;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        transition: background 0.2s, color 0.2s;
    }
    .auth-btn:hover {
    background: linear-gradient(90deg, #4f5fa3 0%, #667eea 100%);
    color: #fff;
    }

    /* Google Sign-In Button */
    .google-signin-btn {
        width: 100% !important;
        background: linear-gradient(90deg, #667eea 0%, #4f5fa3 100%) !important;
        color: #fff !important;
        border: none !important;
        border-radius: 8px !important;
        padding: 12px 16px !important;
        font-size: 1rem !important;
        font-weight: 700 !important;
        cursor: pointer !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        transition: all 0.2s ease !important;
        font-family: 'Orbitron', 'Roboto', Arial, sans-serif !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
    }
    
    .google-signin-btn:hover {
        background: linear-gradient(90deg, #4f5fa3 0%, #667eea 100%) !important;
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
        transform: translateY(-1px) !important;
    }
    
    .google-signin-btn:active {
        background: linear-gradient(90deg, #3a4a85 0%, #667eea 100%) !important;
        box-shadow: 0 2px 6px rgba(0,0,0,0.2) !important;
        transform: translateY(0) !important;
    }
    
    .google-signin-btn img {
        filter: brightness(0) invert(1) !important;
        margin-right: 8px !important;
    }
    .auth-switch {
        margin-top: 10px;
        font-size: 0.97rem;
        color: #bbb;
    }
    .auth-switch span {
        color: #fdc115;
        cursor: pointer;
        font-weight: 500;
        transition: color 0.2s;
    }
    .auth-switch span:hover {
        color: #fff;
    }
    margin-top: 20px;
    color: #666;
}

.auth-switch span {
    color: #667eea;
    cursor: pointer;
    text-decoration: underline;
}

/* Game Container Styles */
.game-container {
    min-height: 100vh;
    background: #1a1a2e;
    color: white;
}

/* Header Styles */
.game-header {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-wrap: wrap;
    gap: 15px;
        padding: 18px 24px;
        box-sizing: border-box;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.player-info:hover {
    transform: scale(1.05);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #667eea;
    transition: border-color 0.3s ease;
}

.player-info:hover .avatar {
    border-color: #fff;
}

.player-details {
    display: flex;
    flex-direction: column;
}

/* Logout Button (restored styling) */
.logout-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    transition: background 0.25s ease, border-color 0.25s ease;
    font-weight: 500;
}
.logout-btn:hover {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.3);
}

/* Resource Icons */
.resource-icon {
    width: 22px;
    height: 22px;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 0 4px rgba(0,0,0,0.4));
}
.stat-item.resource {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 60px;
}
.stat-item.resource .stat-value {
    font-size: 0.95rem;
}

/* Color Picker Section */
.color-picker-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.color-swatches {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
    gap: 6px;
}
.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.3);
    transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    position: relative;
}
.color-swatch:hover {
    transform: scale(1.08);
    border-color: #fff;
}
.color-swatch.selected {
    box-shadow: 0 0 0 2px #667eea, 0 2px 8px rgba(0,0,0,0.6);
    border-color: #fff;
}

/* Cacher le color picker desktop par défaut */
#color-picker-section-desktop {
    display: none;
}

.selected-color-display {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: #ccc;
}
#selected-color-box {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.4);
    box-shadow: 0 2px 6px rgba(0,0,0,0.5) inset, 0 2px 6px rgba(0,0,0,0.4);
}

@media (max-width: 900px) {
    .stat-item.resource { min-width: 50px; }
    .resource-icon { width: 20px; height: 20px; }
}
@media (max-width: 600px) {
    .color-swatches { grid-template-columns: repeat(auto-fill, minmax(24px, 1fr)); gap: 5px; }
    .color-swatch { width: 24px; height: 24px; }
    #selected-color-box { width: 30px; height: 30px; }
}
@media (max-width: 375px) {
    .color-swatches { grid-template-columns: repeat(auto-fill, minmax(22px, 1fr)); gap: 4px; }
    .color-swatch { width: 22px; height: 22px; }
    #selected-color-box { width: 28px; height: 28px; }
}

.username {
    font-weight: 600;
    font-size: 1.1rem;
}

.level {
    font-size: 0.9rem;
    color: #667eea;
}

.stats {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
}

.stat-item {
    text-align: center;
}

/* Make the messages area flexible but bounded so input never leaves chat box */
.chat-messages {
    flex: 1 1 auto;
    min-height: 110px !important;
    max-height: 280px !important;
    overflow-y: auto;
}
.stat-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: #667eea;
}


.logout-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.icon-btn .icon {
    width: 24px;
    height: 24px;
}

/* Username with Crown */
.username-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.crown-icon {
    font-size: 1rem;
    animation: crown-glow 2s ease-in-out infinite alternate;
}

@keyframes crown-glow {
    from { text-shadow: 0 0 5px #ffd700; }
    to { text-shadow: 0 0 15px #ffd700, 0 0 25px #ffd700; }
}

/* Main Game Area */
.game-main {
    display: flex;
    flex-direction: row;
    height: calc(100vh - 80px);
    box-sizing: border-box;
}

/* Sidebar Styles */
.game-sidebar {
    width: 280px;
    min-width: 180px;
    max-width: 350px;
    background: rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    overflow-y: auto;
    padding: 20px;
    flex-shrink: 0;
}

.game-sidebar.right {
    border-right: none;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-section {
    margin-bottom: 30px;
}

.sidebar-section h3 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 1.2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
}

/* Shop Styles */
/* Shop item description style */
.item-desc {
    font-size: 0.85em;
    color: #888;
    margin: 2px 0 6px 0;
    display: block;
}
.shop-items {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.shop-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: default;
    transition: background-color 0.2s ease;
}

.shop-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.item-name {
    font-weight: 600;
    color: #fff;
}

.item-cost {
    color: #667eea;
    font-size: 0.9rem;
}

.buy-btn {
    cursor: pointer;
    padding: 8px 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.buy-btn:hover {
    background: #5a6fd8;
}

.buy-btn:disabled {
    background: #555;
    cursor: not-allowed;
}

/* Inventory Styles */
.inventory {
    min-height: 100px;
}

.empty-inventory {
    color: #666;
    text-align: center;
    font-style: italic;
}

.inventory-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.item-info {
    display: flex;
    flex-direction: column;
}

.item-name {
    font-weight: 500;
}

.item-type {
    font-size: 0.8rem;
    color: #aaa;
}

.use-item-btn {
    cursor: pointer;
    padding: 8px 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.inventory-stack .use-item-btn {
    cursor: pointer;
    padding: 8px 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.3s ease;
}

.inventory-stack .use-item-btn:hover {
    background: #5a6fd8;
}

.use-item-btn:hover {
    background: #5a6fd8;
}

/* Game Center */
.game-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    min-width: 0;
    overflow: hidden;
}

.grid-container {
    text-align: center;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    position: relative;
    box-sizing: border-box;
}

.pixel-grid {
    touch-action: none;
    width: 100%;
    height: 800px;
    max-height: 70vh;
    background: #2a2a3e;
    border-radius: 12px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.18);
    overflow: hidden;
    box-sizing: border-box;
@media (max-width: 1200px) {
    .game-sidebar {
        width: 180px;
        min-width: 120px;
        padding: 12px 8px;
    }
    .pixel-grid {
        max-width: 1200px;
        height: 600px;
    }
    .game-header {
        padding: 12px 10px;
    }
    /* chat-container fixed heights removed (unified flex layout later) */
    .chat-messages {
        max-height: 35vh;
        min-height: 120px;
        padding: 10px;
    }
    .chat-input-container {
        gap: 8px;
    }
    #chat-input {
        padding: 8px 10px;
        font-size: 0.95rem;
    }
    .chat-send-btn {
        padding: 8px 12px;
        min-width: 55px;
        font-size: 0.95rem;
    }
    .leaderboard-section {
        padding: 16px 14px 10px 14px;
        margin-bottom: 16px;
    }
    .leaderboard-section h3 {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }
    .leaderboard-container ol {
        padding-left: 18px;
    }
    .leaderboard-container li {
        font-size: 0.95rem;
        margin-bottom: 5px;
    }
}
@media (max-width: 900px) {
    .game-sidebar {
        width: 100%;
        max-width: none;
        min-width: 0;
        position: static;
        margin-bottom: 18px;
        border-right: none;
        border-bottom: 1px solid rgba(255,255,255,0.08);
        padding: 10px 6px;
    }
    .game-main {
        flex-direction: column;
        align-items: stretch;
    }
    .sidebar-section {
        margin-bottom: 18px;
    }
    /* chat-container fixed heights removed */
    .chat-messages {
        max-height: 30vh;
        min-height: 100px;
        padding: 10px;
    }
    .chat-message {
        padding: 7px;
        margin-bottom: 8px;
    }
    .chat-username {
        font-size: 0.9rem;
    }
    .chat-text {
        font-size: 0.95rem;
    }
    .chat-input-container {
        gap: 8px;
    }
    #chat-input {
        padding: 10px;
        font-size: 0.95rem;
        min-height: 42px;
    }
    .chat-send-btn {
        min-height: 42px;
        min-width: 60px;
        padding: 10px 14px;
        font-size: 0.95rem;
    }
    .leaderboard-section {
        padding: 16px 14px 10px 14px;
        margin-bottom: 16px;
    }
    .leaderboard-section h3 {
        font-size: 1.05rem;
        margin-bottom: 8px;
    }
    .leaderboard-container ol {
        padding-left: 16px;
    }
    .leaderboard-container li {
        font-size: 0.9rem;
        margin-bottom: 4px;
    }
}
@media (max-width: 600px) {
    .game-header {
        flex-direction: column;
        gap: 8px;
        padding: 8px 4px;
    }
    .game-main {
        flex-direction: column;
        height: auto;
    }
    .game-sidebar {
        width: 100%;
        max-width: none;
        min-width: 0;
        border-right: none;
        border-bottom: 1px solid rgba(255,255,255,0.08);
        padding: 6px 2px;
    }
    .game-center {
        padding: 4px 0;
    }
    .grid-container {
        padding: 0 2px;
    }
    .pixel-grid {
        max-width: 100vw;
        height: 180px;
        min-height: 100px;
    }
    /* chat-container fixed heights removed */
    .chat-messages {
        max-height: 10vh;
        min-height: 80px;
        padding: 8px;
    }
    .chat-message {
        padding: 6px;
        margin-bottom: 6px;
    }
    .chat-username {
        font-size: 0.85rem;
    }
    .chat-text {
        font-size: 0.9rem;
    }
    .leaderboard-section {
        padding: 12px 10px 6px 10px;
        margin-bottom: 12px;
    }
    .leaderboard-section h3 {
        font-size: 0.95rem;
        margin-bottom: 6px;
    }
    .leaderboard-container ol {
        padding-left: 14px;
    }
    .leaderboard-container li {
        font-size: 0.85rem;
        margin-bottom: 3px;
    }
}
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    cursor: grab;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    touch-action: none; /* Prevent default touch behaviors */
}

.pixel-grid:active {
    cursor: grabbing;
}

.grid-wrapper {
    position: relative;
    transform-origin: 0 0;
    transition: transform 0.1s ease;
    will-change: transform; /* Optimize for transforms */
}

/* Grid Lines */
.grid-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.15);
    pointer-events: none;
    z-index: 0;
    transition: opacity 0.3s ease;
}

.grid-line.vertical {
    width: 1px;
    height: 100%;
    background: linear-gradient(to bottom, 
        rgba(255, 255, 255, 0.05) 0%, 
        rgba(255, 255, 255, 0.2) 50%, 
        rgba(255, 255, 255, 0.05) 100%);
}

.grid-line.horizontal {
    height: 1px;
    width: 100%;
    background: linear-gradient(to right, 
        rgba(255, 255, 255, 0.05) 0%, 
        rgba(255, 255, 255, 0.2) 50%, 
        rgba(255, 255, 255, 0.05) 100%);
}

.viewport-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none; /* Let events pass through to grid */
}

.viewport-container .pixel {
    pointer-events: auto; /* Re-enable events for pixels */
}

.pixel {
    width: 8px;
    height: 8px;
    border-radius: 1px;
    cursor: pointer;
    transition: transform 0.1s ease, background-color 0.1s ease;
    position: absolute;
    z-index: 1;
    will-change: transform, background-color; /* Optimize for animations */
}

.pixel:hover {
    transform: scale(1.5);
    z-index: 10;
}

.pixel.filled {
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.pixel.magic {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57);
    background-size: 200% 200%;
    animation: magic-shift 3s ease-in-out infinite;
}

@keyframes magic-shift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.grid-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    margin-top: 12px;
    flex-wrap: wrap;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.control-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s ease;
    font-size: 0.9rem;
    white-space: nowrap;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Chat Styles */
.chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.chat-messages {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
    overflow-y: auto;
    max-height: 40vh;
    min-height: 180px;
}
@media (max-width: 768px) {
    /* chat-container height removed */
    .chat-messages {
        max-height: 12vh;
        min-height: 50px;
        padding: 8px;
    }
    .leaderboard-section {
        padding: 14px 12px 8px 12px;
        margin-bottom: 14px;
    }
    .leaderboard-section h3 {
        font-size: 1rem;
        margin-bottom: 6px;
    }
    .leaderboard-container ol {
        padding-left: 16px;
    }
    .leaderboard-container li {
        font-size: 0.9rem;
        margin-bottom: 4px;
    }
}

.chat-message {
    margin-bottom: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.chat-username {
    font-weight: 600;
    color: #667eea;
    font-size: 0.9rem;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.username-text {
    color: #667eea;
    font-weight: 600;
}

.chat-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.chat-time {
    color: #666;
    font-size: 0.8rem;
    margin-left: auto;
}

.chat-text {
    color: #fff;
    word-wrap: break-word;
}

.chat-input-container {
    display: flex;
    gap: 10px;
    width: 100%;
}

#chat-input {
    flex: 1 1 0;
    min-width: 0;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    box-sizing: border-box;
}

#chat-input::placeholder {
    color: #aaa;
}

.chat-send-btn {
    padding: 10px 15px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s ease;
    flex-shrink: 0;
    min-width: 60px;
}

.chat-send-btn:hover {
    background: #5a6fd8;
}

/* Profile Settings Modal */
.profile-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.profile-modal-content {
    background: #2a2a3e;
    border-radius: 20px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.profile-modal-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.profile-modal-title {
    font-size: 1.5rem;
    color: #667eea;
    font-weight: 700;
    letter-spacing: 1px;
}

.close-modal {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1.2em;
    cursor: pointer;
    font-family: 'Roboto', Arial, sans-serif;
    transition: background 0.3s ease, border-color 0.3s ease;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.close-modal:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #667eea;
}

.profile-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.profile-form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.profile-form-group label {
    color: #fff;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 5px;
}

.profile-form-group input {
    padding: 10px 14px;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: #23233a;
    color: #fff;
    font-size: 1.05rem;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}

.profile-form-group input[type="file"] {
    padding: 8px 12px;
    border: 2px solid #667eea;
    border-radius: 8px;
    background: #23233a;
    color: #fff;
    font-size: 1rem;
    margin-bottom: 16px;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
    font-family: 'Roboto', Arial, sans-serif;
}

.profile-form-group input[type="file"]:hover {
    background: #2a2a3e;
    border-color: #777;
}

.profile-form-group input[type="file"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(136,136,136,0.15);
}

.profile-form-group input[type="file"]::file-selector-button {
    background: #666;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    margin-right: 12px;
    cursor: pointer;
    font-family: 'Roboto', Arial, sans-serif;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.profile-form-group input[type="file"]::file-selector-button:hover {
    background: #667eea;
}

.profile-form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102,126,234,0.15);
}

.profile-picture-preview {
    margin-top: 8px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.profile-picture-preview img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid #667eea;
    box-shadow: 0 2px 8px rgba(102,126,234,0.15);
    object-fit: cover;
    background: #23233a;
}

.profile-picture-preview span {
    color: #fff;
    font-weight: 500;
    font-size: 0.9rem;
}

.profile-save-btn {
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background 0.3s ease;
    font-weight: 600;
    margin-top: 10px;
    box-shadow: 0 2px 8px rgba(102,126,234,0.10);
}

.profile-save-btn:hover {
    background: #5a6fd8;
    box-shadow: 0 4px 16px rgba(102,126,234,0.18);
}

/* Premium Pass Modal */
.premium-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.premium-content {
    background: #2a2a3e;
    border-radius: 20px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 1.5rem;
    color: #667eea;
    font-weight: 700;
    letter-spacing: 1px;
}

.free-trial-banner {
    background: linear-gradient(90deg, #f6d365 0%, #fda085 100%);
    color: #1a1a2e;
    font-weight: 700;
    font-size: 1rem;
    text-align: center;
    padding: 10px 16px;
    border-radius: 10px;
    margin-bottom: 18px;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 12px rgba(253,160,133,0.4);
}

.premium-features h3 {
    color: #fff;
    margin-bottom: 20px;
    font-size: 1.2rem;
}

.benefits-list {
    list-style: none;
    padding: 0;
    margin: 0 0 30px 0;
}

.benefits-list li {
    color: #fff;
    padding: 12px 0;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.benefits-list li:last-child {
    border-bottom: none;
}

.benefits-list .premium-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    margin-right: 10px;
    vertical-align: middle;
}

.premium-price {
    text-align: center;
    margin: 30px 0;
}

.premium-price .price {
    font-size: 2.5rem;
    color: #667eea;
    font-weight: 700;
}

.premium-price .period {
    color: #aaa;
    font-size: 1rem;
    margin-left: 10px;
}

.premium-buy-btn {
    width: 100%;
    padding: 15px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 16px rgba(102,126,234,0.3);
}

.premium-buy-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102,126,234,0.4);
}

/* Shop Modal */
.shop-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.shop-content {
    background: #2a2a3e;
    border-radius: 20px;
    padding: 30px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.shop-sections {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.shop-section h3 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 1.3rem;
    border-bottom: 2px solid rgba(102,126,234,0.3);
    padding-bottom: 10px;
}

.shop-items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.shop-purchase-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    transition: background 0.3s ease, transform 0.2s ease;
}

.shop-purchase-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
}

.shop-purchase-item .item-icon {
    font-size: 2.5rem;
}

.shop-purchase-item .item-icon .shop-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.shop-purchase-item .item-details {
    text-align: center;
}

.shop-purchase-item .item-name {
    color: #fff;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.shop-purchase-item .item-price {
    color: #667eea;
    font-size: 1.3rem;
    font-weight: 700;
}

.purchase-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
    min-width: 80px;
}

.purchase-btn:hover {
    background: #5a6fd8;
    transform: scale(1.05);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Notification System */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.notification {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    padding: 15px 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    max-width: 300px;
    animation: slideIn 0.3s ease;
}

.notification.success {
    border-left: 4px solid #28a745;
}

.notification.error {
    border-left: 4px solid #dc3545;
}

.notification.info {
    border-left: 4px solid #17a2b8;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 1200px) {
    .game-sidebar {
        width: 250px;
    }
}

@media (max-width: 768px) {
    .game-main {
        flex-direction: column;
        height: auto;
    }
    
    .header-actions {
        gap: 10px;
    }
    
    .icon-btn .icon {
        width: 20px;
        height: 20px;
        align-self: center;
    }
    
    .shop-items-grid {
        grid-template-columns: 1fr;
    }
    
    .premium-content, .shop-content {
        margin: 10px;
        padding: 20px;
    }
    
    .benefits-list li {
        font-size: 1rem;
        padding: 10px 0;
    }
    
    .premium-price .price {
        font-size: 2rem;
    }
    
    .game-sidebar {
        width: 100%;
        border-right: none;
        border-left: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        order: 3;
        max-height: 40vh;
        overflow-y: auto;
    }
    
    .game-center {
        order: 1;
        height: 50vh;
        min-height: 300px;
        padding: 15px;
    }
    
    .stats {
        gap: 15px;
    }
    
    .game-header {
        padding: 15px 20px;
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .player-info {
        align-self: center;
    }
    
    .stats {
        justify-content: center;
    }
    
    .logout-btn {
        align-self: center;
    }
    
    .grid-controls {
        flex-direction: row;
        gap: 6px;
        margin-top: 10px;
        max-width: 240px;
    }
    
    .control-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
        border-radius: 5px;
    }
    
    .profile-modal-content {
        margin: 20px;
        padding: 20px;
    }
    
    /* Mobile-specific grid improvements */
    .pixel-grid {
        touch-action: pan-x pan-y pinch-zoom;
        border-radius: 8px;
    }
    
    .pixel {
        min-width: 8px;
        min-height: 8px;
    }
    
    /* Adjust sidebar sections for mobile */
    .sidebar-section {
        margin-bottom: 20px;
    }
    
    .sidebar-section h3 {
        font-size: 1.1rem;
        margin-bottom: 12px;
    }
    
    .leaderboard-section {
        padding: 14px 12px 8px 12px;
        margin-bottom: 16px;
    }
    
    .leaderboard-section h3 {
        font-size: 1.05rem;
        margin-bottom: 8px;
    }
    
    .leaderboard-container ol {
        padding-left: 16px;
    }
    
    .leaderboard-container li {
        font-size: 0.9rem;
        margin-bottom: 4px;
    }
    
    /* Make shop items more compact on mobile */
    .shop-item {
        padding: 12px;
        gap: 6px;
    }
    
    .item-name {
        font-size: 0.95rem;
    }
    
    .item-cost {
        font-size: 0.85rem;
    }
    
    .buy-btn {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    /* Adjust quest display for mobile */
    .quest-item {
        padding: 12px;
        gap: 6px;
    }
    
    .quest-title {
        font-size: 0.95rem;
    }
    
    .quest-desc {
        font-size: 0.85rem;
    }
    
    .quest-reward {
        font-size: 0.85rem;
    }
    
    /* Adjust inventory for mobile */
    .inventory-item {
        padding: 10px;
        margin-bottom: 8px;
    }
    
    .item-info .item-name {
        font-size: 0.9rem;
    }
    
    .item-info .item-type {
        font-size: 0.75rem;
    }
    
    .use-item-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    
    /* Adjust chat for mobile */
    /* chat-container fixed heights removed; messages height controlled by final overrides */
    .chat-messages { padding: 12px; }
    
    .chat-message {
        padding: 6px;
        margin-bottom: 8px;
    }
    
    .chat-username {
        font-size: 0.85rem;
        margin-bottom: 2px;
    }
    
    .chat-text {
        font-size: 0.9rem;
    }
    
    .chat-input-container {
        gap: 8px;
    }
    
    #chat-input {
        min-height: 44px;
        padding: 10px;
        font-size: 0.95rem;
    }
    
    .chat-send-btn {
        min-height: 44px;
        min-width: 60px;
        padding: 10px 15px;
        font-size: 0.95rem;
    }
}

@media (max-width: 480px) {
    .auth-box {
        padding: 30px 20px;
    }
    
    .game-title {
        font-size: 2.5rem;
    }
    
    .game-sidebar {
        padding: 15px;
        max-height: none; /* allow content stacking */
    }
    
    .game-center {
        height: 45vh;
        min-height: 250px;
        padding: 10px;
    }
    
    .sidebar-section {
        margin-bottom: 15px;
    }
    
    .sidebar-section h3 {
        font-size: 1rem;
        margin-bottom: 10px;
    }
    
    .shop-item, .quest-item, .inventory-item {
        padding: 10px;
        gap: 5px;
    }
    
    .item-name, .quest-title {
        font-size: 0.9rem;
    }
    
    .item-cost, .quest-desc, .quest-reward {
        font-size: 0.8rem;
    }
    
    .buy-btn {
        padding: 7px 10px;
        font-size: 0.85rem;
    }
    
    .use-item-btn {
        padding: 5px 8px;
        font-size: 0.75rem;
    }
    
    /* chat-container fixed heights removed */
    .chat-messages { padding: 10px; }
    
    .chat-message {
        padding: 5px;
        margin-bottom: 6px;
    }
    
    .chat-username {
        font-size: 0.8rem;
    }
    
    .chat-text {
        font-size: 0.85rem;
    }
    
    .chat-input-container {
        gap: 6px;
    }
    
    #chat-input {
        min-height: 40px;
        padding: 8px;
        font-size: 0.9rem;
    }
    
    .chat-send-btn {
        min-height: 40px;
        min-width: 50px;
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    .leaderboard-section {
        padding: 10px 8px 6px 8px;
        margin-bottom: 10px;
    }
    
    .leaderboard-section h3 {
        font-size: 0.9rem;
        margin-bottom: 5px;
    }
    
    .leaderboard-container ol {
        padding-left: 14px;
    }
    
    .leaderboard-container li {
        font-size: 0.8rem;
        margin-bottom: 3px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .pixel:hover {
        transform: none;
    }
    
    .pixel:active {
        transform: scale(1.2);
    }
    
    .player-info:hover {
        transform: none;
    }
    
    .buy-btn:hover, .control-btn:hover, .chat-send-btn:hover {
        background: inherit;
    }


    /* Better touch targets for mobile */
    .pixel {
        min-width: 12px;
        min-height: 12px;
    }
    
    .buy-btn, .use-item-btn, .control-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .chat-input-container {
        gap: 8px;
    }
    
    #chat-input {
        min-height: 44px;
    }
    
    .chat-send-btn {
        min-height: 44px;
        min-width: 60px;
    }
    
    /* Improve touch scrolling */
    .game-sidebar {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    
    .chat-messages {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    
    /* Better touch feedback */
    .pixel:active {
        background-color: rgba(255, 255, 255, 0.3) !important;
    }
    
    .buy-btn:active, .use-item-btn:active, .control-btn:active {
        transform: scale(0.95);
    }
}


/* Portrait mode specific optimizations */
@media (orientation: portrait) and (max-width: 768px) {
    .game-main {
        height: auto;
        min-height: 100vh;
    }
    
    .game-center {
        height: 60vh;
        min-height: 350px;
    }
    
    .game-sidebar {
        max-height: none;
        height: auto;
        order: 3;
    }
    
    /* Stack sidebar sections vertically */
    .sidebar-section {
        margin-bottom: 25px;
    }
    
    /* Optimize chat for portrait mode - rely on global clamp override, only adjust padding */
    .chat-messages { padding: 10px; }
    
    .chat-message {
        padding: 8px;
        margin-bottom: 8px;
    }
    
    .chat-username {
        font-size: 0.9rem;
    }
    
    .chat-text {
        font-size: 0.9rem;
        line-height: 1.4;
    }
    
    .chat-input-container {
        gap: 8px;
        margin-top: 8px;
    }
    
    #chat-input {
        min-height: 44px;
        padding: 10px;
        font-size: 0.95rem;
    }
    
    .chat-send-btn {
        min-height: 44px;
        min-width: 60px;
        padding: 10px 15px;
        font-size: 0.95rem;
    }
    
    /* Make grid controls more compact and accessible */
    .grid-controls {
        position: sticky;
        bottom: 8px;
        background: rgba(42, 42, 62, 0.9);
        backdrop-filter: blur(10px);
        border-radius: 12px;
        padding: 10px;
        margin: 0 10px 10px 10px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
        max-width: 260px;
        margin-left: auto;
        margin-right: auto;
    }
    
    /* Improve touch targets */
    .pixel {
        min-width: 14px;
        min-height: 14px;
    }
    
    /* Better spacing for portrait */
    .game-header {
        padding: 20px 15px;
    }
    
    .stats {
        gap: 20px;
    }
    
    .player-info {
        margin-bottom: 10px;
    }
    
    .leaderboard-section {
        padding: 12px 10px 8px 10px;
        margin-bottom: 20px;
    }
    
    .leaderboard-section h3 {
        font-size: 1rem;
        margin-bottom: 8px;
    }
    
    .leaderboard-container ol {
        padding-left: 15px;
    }
    
    .leaderboard-container li {
        font-size: 0.85rem;
        margin-bottom: 4px;
        line-height: 1.3;
    }
}

/* Landscape mobile optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .game-header {
        padding: 10px 20px;
    }
    
    .game-main {
        height: calc(100vh - 60px);
    }
    
    .game-center {
        height: 50vh;
    }
    
    .game-sidebar {
        padding: 15px;
        max-height: 45vh;
    }
    
    .sidebar-section {
        margin-bottom: 15px;
    }
    /* chat-container fixed height removed; rely on global clamp */
    .chat-messages { max-height: 100px; }
}

/* Very small screens (iPhone SE, etc.) */
@media (max-width: 375px) {
    .game-title {
        font-size: 2rem;
    }
    
    .game-sidebar {
        padding: 12px;
    }
    
    .game-center {
        height: 40vh;
        min-height: 200px;
        padding: 8px;
    }
    
    .sidebar-section h3 {
        font-size: 0.95rem;
    }
    
    .shop-item, .quest-item, .inventory-item {
        padding: 8px;
    }
    
    .item-name, .quest-title {
        font-size: 0.85rem;
    }
    
    .item-cost, .quest-desc, .quest-reward {
        font-size: 0.75rem;
    }
    
    .buy-btn {
        padding: 6px 8px;
        font-size: 0.8rem;
    }
    
    .use-item-btn {
        padding: 4px 6px;
        font-size: 0.7rem;
    }
    
    /* chat-container fixed height removed */
    .chat-messages { max-height: 100px; padding: 8px; }
    
    .chat-input-container {
        gap: 5px;
    }
    
    #chat-input {
        min-height: 36px;
        padding: 6px;
        font-size: 0.85rem;
    }
    
    .chat-send-btn {
        min-height: 36px;
        min-width: 45px;
        padding: 6px 10px;
        font-size: 0.85rem;
    }
    
    .grid-controls {
        gap: 5px;
        margin: 0 5px 5px 5px;
        padding: 10px;
    }
    
    .control-btn {
        padding: 5px 10px;
        font-size: 0.8rem;
    }
    
    .leaderboard-section {
        padding: 8px 6px 4px 6px;
        margin-bottom: 8px;
    }
    
    .leaderboard-section h3 {
        font-size: 0.85rem;
        margin-bottom: 4px;
    }
    
    .leaderboard-container ol {
        padding-left: 12px;
    }
    
    .leaderboard-container li {
        font-size: 0.75rem;
        margin-bottom: 2px;
        line-height: 1.2;
    }
}

/* XP Bar Styles */
.xp-bar-container {
    margin-top: 6px;
    width: 120px;
    height: 16px;
    background: none;
    display: flex;
    align-items: center;
}
.xp-bar {
    width: 100%;
    height: 10px;
    background: #23272f;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(102, 102, 238, 0.15);
    position: relative;
}
.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #2ecc40 100%);
    border-radius: 6px;
    transition: width 0.4s cubic-bezier(.4,2,.3,1);
    width: 0%;
}

/* --- Chat / Leaderboard Overlap Fix Overrides (placed late to win specificity) --- */
/* Ensure the chat input stays visually inside the chat section and never overlaps the leaderboard.
   We neutralize earlier fixed vh heights and use an intrinsic layout with a scrolling messages area. */
#chat-section { /* extra containment & spacing */
    position: relative;
    margin-bottom: 20px;
}
.chat-container {
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    display: flex;
    flex-direction: column;
}
.chat-messages {
    /* Provide a responsive bounded height that adapts but prevents spillover */
    height: clamp(140px, 24vh, 260px) !important;
    max-height: clamp(140px, 24vh, 260px) !important;
    min-height: 120px !important;
    flex: 0 0 auto; /* fixed scroll box */
}
.chat-input-container {
    margin-top: 8px;
    flex: 0 0 auto;
}
@media (max-width: 600px) {
    .chat-messages {
        height: clamp(110px, 28vh, 200px) !important;
        max-height: clamp(110px, 28vh, 200px) !important;
    }
}
@media (max-width: 375px) {
    .chat-messages {
        height: clamp(100px, 32vh, 180px) !important;
        max-height: clamp(100px, 32vh, 180px) !important;
    }
}
@media (max-width: 480px) {
    /* Remove sidebar max-height that was constraining content and causing visual overlap */
    .game-sidebar {
        max-height: none !important;
        height: auto !important;
    }
}

/* Mobile Touch Improvements */
@media (max-width: 768px) {
    .pixel-grid {
        /* Disable native touch behaviors to prevent conflicts */
        touch-action: none;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        /* Improve touch responsiveness */
        -webkit-tap-highlight-color: transparent;
    }
    
    .pixel {
        /* Enhanced touch targets for better mobile interaction */
        min-width: 12px;
        min-height: 12px;
        /* Smoother transitions for touch interactions */
        transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), 
                   background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .pixel:hover {
        /* Adjust hover scale for mobile */
        transform: scale(1.3);
    }
    
    /* Improve button touch targets on mobile */
    .control-btn, .icon-btn, .buy-btn {
        min-height: 44px;
        min-width: 44px;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Smooth scrolling for mobile */
    .chat-messages, .leaderboard-container {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Sur mobile, montrer le color picker entre center et sidebars */
    #color-picker-section {
        display: block !important;
        margin: 15px 20px 20px 20px;
        padding: 15px;
        background: rgba(42, 42, 62, 0.95);
        border-radius: 12px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
        max-width: 350px;
        width: calc(100% - 40px);
        margin-left: auto;
        margin-right: auto;
    }
    
    #color-picker-section h3 {
        margin: 0 0 12px 0;
        font-size: 1.1rem;
        text-align: center;
        color: #fff;
        font-weight: 500;
    }
    
    #color-picker-section .color-swatches {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }
}

/* Sur desktop, cacher le color picker du main et montrer celui de la sidebar */
@media (min-width: 769px) {
    /* Cacher le color picker principal (mobile) sur desktop */
    #color-picker-section {
        display: none !important;
    }
    
    /* Montrer le color picker de la sidebar sur desktop */
    #color-picker-section-desktop {
        display: block !important;
    }
}

/* Cacher le color picker desktop sur mobile */
@media (max-width: 768px) {
    #color-picker-section-desktop {
        display: none !important;
    }
}

/* iPhone-like smooth momentum scrolling */
* {
    -webkit-overflow-scrolling: touch;
}

/* Prevent zoom on form inputs */
input, select, textarea {
    font-size: 16px; /* Prevents zoom on iOS */
}

/* ----------------------------------------------------------------------------- */