* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Courier New', monospace;
    background: #000;
    overflow: hidden;
    cursor: crosshair;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff; /* clean white start screen for AI logo */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-text {
    color: #333; /* dark text to remain visible on white loading background */
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    font-family: 'Courier New', monospace;
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
}

/* New: Loading logo */
#loading-logo {
    width: 260px; /* slightly larger for AI logo */
    height: auto;
    margin-bottom: 14px;
    image-rendering: -webkit-optimize-contrast;
    -webkit-user-drag: none;
    user-select: none;
}

.loading-bar {
    width: 400px;
    height: 30px;
    background: #333;
    border: 3px solid #666;
    padding: 2px;
}

.loading-progress {
    height: 100%;
    background: linear-gradient(90deg, #00ff00, #00aa00);
    width: 0%;
    animation: load 3s ease-out forwards;
}

@keyframes load {
    to { width: 100%; }
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Allows clicks to pass through to canvas by default */
}

/* New: Chat Box Styles */
#chat-box {
    position: absolute;
    bottom: 40px; /* Above the instructions text */
    left: 10px;
    width: 300px;
    height: 200px;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid #666;
    display: flex;
    flex-direction: column;
    pointer-events: all; /* Make chat box interactive */
    font-family: 'Courier New', monospace;
    z-index: 200; /* Ensure it's above other UI elements */
}

.chat-messages {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    font-size: 12px;
    color: #ccc;
    scrollbar-width: thin; /* For Firefox */
    scrollbar-color: #666 #333; /* For Firefox */
    word-wrap: break-word; /* Ensure long words wrap */
}

/* Custom scrollbar for WebKit browsers */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #333;
}

.chat-messages::-webkit-scrollbar-thumb {
    background-color: #666;
    border-radius: 4px;
    border: 2px solid #333;
}

#chat-input {
    width: 100%;
    padding: 8px 10px;
    border: none;
    background: #333;
    color: white;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    border-top: 1px solid #666;
    box-sizing: border-box; /* Include padding in width */
    outline: none; /* Remove default focus outline */
}

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

#topbar {
    display: none;
}

.roblox-logo {
    display: none;
}

.stats {
    display: flex;
    gap: 10px;
    align-items: center;
}

.health-bar {
    width: 150px;
    height: 20px;
    background: #222;
    border: 2px solid #444;
    position: relative;
}

.health-fill {
    height: 100%;
    background: linear-gradient(90deg, #00ff00, #00aa00);
    width: 100%;
}

.health-bar span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    font-size: 11px;
}

.money {
    background: #0066cc;
    color: #ffff00;
    padding: 2px 10px;
    font-weight: bold;
    font-size: 12px;
    border-radius: 3px;
}

#chat {
    display: none;
}

.chat-messages {
    flex: 1;
    padding: 5px;
    overflow-y: auto;
    font-size: 12px;
    color: #ccc;
    font-family: 'Courier New', monospace;
}

#chat input {
    border: none;
    background: #333;
    color: white;
    padding: 5px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    border-top: 1px solid #666;
}

#playerlist {
    display: none;
}

.title {
    background: #0066cc;
    color: #ffff00;
    padding: 5px;
    font-weight: bold;
    text-align: center;
    font-size: 14px;
}

.player {
    display: flex;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #333;
}

.player-avatar {
    width: 24px;
    height: 24px;
    background: #0066cc;
    border-radius: 50%;
    margin-right: 8px;
}

#crosshair {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0,0,0,0.8), 0 0 20px rgba(0,0,0,0.6);
    pointer-events: none;
    z-index: 100;
    opacity: 0.8;
    font-family: 'Courier New', monospace;
}

/* New: Rainbow text style */
.rainbow-text {
    background-image: linear-gradient(to right, 
        #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #9400d3);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: rainbow-animation 5s linear infinite;
}

@keyframes rainbow-animation {
    0% { background-position: 0% 50%; }
    100% { background-position: 100% 50%; }
}

#mobile-controls { 
    position: absolute; bottom: 16px; left: 16px; right: 16px; 
    display: none; pointer-events: none; 
}
/* D-pad */
#mobile-controls .dpad { 
    position: absolute; bottom: 0; left: 0; width: 160px; height: 160px; 
    pointer-events: none;
}
#mobile-controls .dpad-btn { 
    width: 48px; height: 48px; margin: 6px; border: 1px solid #666; 
    background: rgba(255,255,255,0.08); color: #fff; font-family: 'Courier New', monospace;
    border-radius: 6px; pointer-events: all; touch-action: none;
}
#mobile-controls .up { position: absolute; top: 0; left: 56px; }
#mobile-controls .down { position: absolute; top: 112px; left: 56px; }
#mobile-controls .left { position: absolute; top: 56px; left: 0; }
#mobile-controls .right { position: absolute; top: 56px; left: 112px; }
/* Jump button */
#mobile-controls #jump-btn { 
    position: absolute; bottom: 0; right: 0; width: 90px; height: 90px; 
    border-radius: 50%; border: 1px solid #666; background: rgba(255,255,255,0.08); 
    color: #fff; font-weight: bold; pointer-events: all; touch-action: none;
}

#head-size-control {
    position: absolute; top: 16px; right: 16px;
    background: rgba(0,0,0,0.7); border: 1px solid #666;
    padding: 8px 10px; color: #fff; font-size: 12px;
    pointer-events: all; font-family: 'Courier New', monospace;
}

/* Show controls and move chat up on mobile */
body.mobile #mobile-controls { display: block; }
body.mobile #chat-box { bottom: 160px; }

/* Top-left control cluster container */
#top-controls {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1002;
    display: inline-flex;
    gap: 4px; /* reduced gap so buttons appear together */
    align-items: center;
    pointer-events: all;
}

/* Logo inside the menu button (slightly larger to match cluster) */
#menu-toggle #menu-logo {
    width: 20px;
    height: 20px;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
    -webkit-user-drag: none;
    user-select: none;
}
/* Ensure label text is visible and not truncated */
#menu-toggle #menu-label {
    font-size: 13px;
    line-height: 1;
    color: #fff;
    white-space: nowrap;
}

#top-controls button {
    background: rgba(0,0,0,0.75);
    color: #fff;
    border: 1px solid #666;
    padding: 8px 10px;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    pointer-events: all;
}

/* Slight visual distinction for hamburger and chat buttons */
#hamburger-toggle { font-weight: 700; }
#chat-toggle { min-width: 52px; text-align: center; }

#chat-toggle img {
    width: 20px;
    height: 20px;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
    -webkit-user-drag: none;
    user-select: none;
}

#chat-toggle, #commands-toggle {
    position: static;
    top: auto;
    left: auto;
    z-index: 1002;
    background: rgba(0,0,0,0.75);
    color: #fff;
    border: 1px solid #666;
    padding: 8px 10px;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    pointer-events: all;
    border-radius: 4px;
    margin: 0; /* remove extra left margin to keep buttons tightly grouped */
}

#hamburger-toggle {
    position: static;
    top: auto;
    left: auto;
    z-index: 1002;
    background: rgba(0,0,0,0.75);
    color: #fff;
    border: 1px solid #666;
    padding: 8px 10px;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    pointer-events: all;
    border-radius: 4px;
    margin: 0; /* remove extra margin so it sits flush with neighbors */
}

#hamburger-popup {
    position: fixed;
    top: 46px;
    left: 44px; /* align popup directly under the compact control cluster */
    background: rgba(0,0,0,0.96);
    border: 1px solid #555;
    padding: 8px;
    display: none;
    z-index: 1205;
    pointer-events: all;
    border-radius: 6px;
    min-width: 160px;
}

.hamb-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px;
    margin: 4px 0;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.04);
    color: #fff;
    cursor: pointer;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

.hamb-section { margin-top: 6px; padding-top: 6px; border-top:1px solid rgba(255,255,255,0.03); }

.hamb-subheader { font-size: 12px; color: #ddd; margin-bottom:6px; font-weight:600; }

/* Commands popup (simple modal matching menu) */
#commands-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 520px;
    max-width: calc(100% - 40px);
    background: rgba(0,0,0,0.94);
    border: 1px solid #666;
    padding: 14px;
    color: #fff;
    z-index: 1200;
    display: none;
    pointer-events: all;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
}
#commands-popup input[type="text"], #commands-popup select, #commands-popup input[type="color"] {
    width: 100%;
    padding: 6px;
    margin: 6px 0 10px 0;
    box-sizing: border-box;
    background: #222;
    border: 1px solid #444;
    color: #fff;
}
#commands-popup input[type="range"] { width: 100%; }
#commands-popup #te_send {
    background: rgba(255,255,255,0.06);
    border: 1px solid #555;
    color: #fff;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
}
/* Commands backdrop */
#commands-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 1190;
    display: none;
}
/* When chat is toggled open, make chat box visible (we already have it but ensure placement) */
#chat-box.open { display: flex; }

/* Popup menu */
#menu-popup {
    /* @tweakable the width of the centered menu modal in px */
    --menu-width: 680px;
    /* @tweakable the height of the centered menu modal in px */
    --menu-height: 420px;
    /* @tweakable the base font size used inside the menu in px */
    --menu-font-size: 16px;

    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: var(--menu-width);
    height: var(--menu-height);
    max-width: calc(100% - 40px);
    max-height: calc(100% - 80px);
    overflow: auto;
    background: rgba(0,0,0,0.94);
    border: 1px solid #666;
    padding: 18px;
    color: #fff;
    z-index: 1100;
    display: none;
    pointer-events: all;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    font-size: var(--menu-font-size);
}

/* Backdrop when menu is open */
#menu-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 1090;
    display: none;
}

/* Larger header treatment */
#menu-popup .leaderboard-header {
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 8px;
}

#menu-popup #menu-close {
    margin-top: 12px;
    background: rgba(255,255,255,0.06);
    border: 1px solid #555;
    color: #fff;
    padding: 10px;
    width: 100%;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
}

#menu-popup .menu-section {
    margin-bottom: 10px;
}

#menu-popup button {
    background: rgba(255,255,255,0.06);
    border: 1px solid #555;
    color: #fff;
    padding: 8px;
    width: 100%;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
}

#menu-popup button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

#leaderboard-list {
    max-height: 120px;
    overflow-y: auto;
    background: rgba(0,0,0,0.6);
    border: 1px solid #444;
    padding: 6px;
    font-size: 13px;
}

.leaderboard-item {
    padding: 6px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#btools-panel {
    position: fixed;
    right: 12px;
    top: 12px;
    width: 320px;
    max-width: calc(100% - 24px);
    background: rgba(0,0,0,0.94);
    border: 1px solid #444;
    color: #fff;
    z-index: 1300;
    display: none;
    pointer-events: all;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    box-shadow: 0 8px 30px rgba(0,0,0,0.6);
    overflow: hidden;
}
#btools-panel[aria-hidden="false"]{ display: block; }
#btools-panel .btools-header {
    display:flex; align-items:center; justify-content:space-between;
    padding:8px 10px; background: rgba(255,255,255,0.03); border-bottom:1px solid #333;
    font-weight:bold;
}
#btools-panel .btools-body { padding:10px; font-size:13px; }
.btools-mode {
    width:48%;
    margin:4px 1%;
    padding:8px;
    background: rgba(255,255,255,0.04);
    border:1px solid #555;
    color:#fff;
    cursor:pointer;
    border-radius:6px;
}
.btools-mode.active { background: rgba(0,150,255,0.12); border-color:#1e90ff; }
#btools-options .muted { color:#aaa; font-size:12px; }
#btools-selected { margin-top:6px; padding:6px; background:rgba(0,0,0,0.45); border:1px solid #333; border-radius:4px; min-height:22px; }
@media (max-width:600px){
    #btools-panel { width: calc(100% - 24px); left:12px; right:12px; top:auto; bottom: 12px; }
}

#emote-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    z-index: 1301;
    display: none;
    pointer-events: all;
}
#emote-popup .emote-modal {
    background: rgba(0,0,0,0.96);
    border: 1px solid #444;
    padding: 12px;
    color: #fff;
    border-radius: 8px;
    min-width: 240px;
    font-family: 'Courier New', monospace;
    text-align: center;
}
#emote-popup .emote-header { font-weight:700; margin-bottom:8px; }
.emote-list { display:flex; flex-wrap:wrap; gap:8px; justify-content:center; }
.emote-btn {
    padding:8px 12px; background: rgba(255,255,255,0.04); border:1px solid #555; color:#fff; border-radius:6px; cursor:pointer;
}
#emote-close { padding:8px 12px; margin-top:8px; background:rgba(255,255,255,0.06); border:1px solid #555; border-radius:6px; cursor:pointer; width:100%; }
/* backdrop */
#emote-backdrop {
    position: fixed; inset:0; background: rgba(0,0,0,0.55); z-index:1300; display:none;
}

/* Ensure the combined hamburger button content aligns nicely (icon + balloon) */
#top-controls button img#chat-icon { vertical-align: middle; pointer-events: none; }

#game-container.saturated { filter: saturate(2.5); transition: filter 200ms ease; }

body.bsod {
    background: none; /* replaced background image with centered img element */
    pointer-events: none;
}
#bsod-img {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999999;
    width: 100vw;
    height: 100vh;
    object-fit: cover; /* ensure BSOD stretches to fill page */
    image-rendering: pixelated;
    pointer-events: none;
}
body.bsod #game-container, body.bsod #loading { display: none !important; }