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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    background: #000;
    font-family: Arial, sans-serif;
    touch-action: none;
}

canvas {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: none;
    image-rendering: pixelated;
}

canvas#canvas {
    position: absolute;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
    -ms-interpolation-mode: nearest-neighbor;
}

canvas#weaponPreview,
canvas#characterPlacementPreview {
    position: fixed;
}

canvas#characterPreview,
canvas#shapePreview {
    position: relative;
}

#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgb(45 45 45 / 70%);
    color: #00ff00;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    font-family: monospace;
    pointer-events: none;
    will-change: opacity;
    transition: none;
}

#loading-overlay.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#holdInstruction {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 255, 0, 0.15);
    border: 3px solid #00ff00;
    border-radius: 12px;
    padding: 20px 30px;
    color: #00ff00;
    font-size: 1.1em;
    font-weight: bold;
    text-align: center;
    z-index: 9998;
    display: none;
    pointer-events: none;
    text-shadow: 0 0 10px #00ff00;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
    animation: pulseGlow 1.5s ease-in-out infinite;
}

#holdInstructionIcon {
    font-size: 2em;
    display: block;
    margin-bottom: 10px;
    animation: tapAnimation 1.5s ease-in-out infinite;
}

#holdInstructionText {
    color: #00ff00;
    -webkit-text-stroke: 2px #000000;
    text-stroke: 2px #000000;
    paint-order: stroke fill;
    font-weight: bold;
}

@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
        border-color: #00ff00;
    }
    50% {
        box-shadow: 0 0 40px rgba(0, 255, 0, 0.8);
        border-color: #00ff88;
    }
}

@keyframes tapAnimation {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

#civil-mode-link {
    position: fixed;
    left: 10px;
    top: 15px;
    z-index: 101;
}

#civilModeBtn {
    background: rgba(67, 67, 67, 0.41);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    padding: 6px 10px;
    color: rgba(255,255,255,0.65);
    font-weight: normal;
    font-size: 1em;
    cursor: pointer !important;
    transition: all 0.2s;
    backdrop-filter: blur(3px);
}

#civilModeBtn:hover {
    background: rgba(67, 67, 67, 0.6);
    color: rgba(255,255,255,0.85);
    border-color: rgba(255,255,255,0.35);
}

@media (min-width: 769px) {
    #weaponPreview {
        display: block;
    }
    
    #holdInstruction {
        /* Allow display on desktop for ak47, paintgun, eraser */
    }
}

@media (max-width: 768px) {
    #civil-mode-link {
        top: 10px;
        left: 10px;
        z-index: 150;
    }
    
    #civilModeBtn {
        font-size: 0.9em;
        padding: 5px 8px;
    }
}

#credits {
    position: fixed;
    bottom: 10px;
    right: 15px;
    color: rgb(155, 150, 150);
    font-size: 0.9em;
    font-family: monospace;
    z-index: 50;
    pointer-events: none;
}

#weapons-panel {
    position: fixed;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(20,20,20,0.95);
    padding: 8px;
    border-radius: 8px;
    border: 2px solid #444;
    z-index: 100;
    max-height: 90vh;
    overflow: hidden;
    cursor: auto !important;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

#weapons-panel.collapsed {
    padding: 8px;
}

#weapons-panel.horizontal {
    flex-direction: row;
    max-width: 90vw;
    max-height: none;
    left: 50%;
    top: 10px;
    transform: translateX(-50%);
}

#weapons-panel.horizontal #weapons-header {
    flex-direction: column;
    margin-bottom: 0;
    margin-right: 8px;
    gap: 4px;
}

#weapons-panel.horizontal #weapons-grid {
    flex-direction: row;
    max-height: none;
    max-width: calc(90vw - 50px);
    overflow-x: auto;
    overflow-y: hidden;
    padding-right: 0;
    padding-bottom: 4px;
}

#weapons-panel.horizontal .weapon-btn {
    white-space: nowrap;
}

#weapons-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-shrink: 0;
    gap: 8px;
}

#weapons-header h3 {
    color: #00ff00;
    font-size: 0.9em;
    text-shadow: 0 0 5px #00ff00;
    margin: 0;
    cursor: move !important;
}

#toggleWeaponsBtn {
    background: transparent;
    border: 1px solid #00ff00;
    color: #00ff00;
    width: 25px;
    height: 25px;
    border-radius: 4px;
    cursor: pointer !important;
    font-size: 1.2em;
    line-height: 1;
    padding: 0;
    transition: all 0.2s;
    flex-shrink: 0;
}

#toggleWeaponsBtn:hover {
    background: rgba(0,255,0,0.2);
    transform: scale(1.1);
}

#toggleLayoutBtn {
    background: transparent;
    border: 1px solid #00ff00;
    color: #00ff00;
    width: 25px;
    height: 25px;
    border-radius: 4px;
    cursor: pointer !important;
    font-size: 1em;
    line-height: 1;
    padding: 0;
    transition: all 0.2s;
    flex-shrink: 0;
}

#toggleLayoutBtn:hover {
    background: rgba(0,255,0,0.2);
    transform: scale(1.1);
}

#weapons-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(90vh - 50px);
    padding-right: 4px;
}

.weapon-btn {
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border: 2px solid #444;
    border-radius: 6px;
    padding: 6px 10px;
    color: #fff;
    font-size: 0.8em;
    cursor: pointer !important;
    transition: all 0.2s;
    text-align: left;
    white-space: nowrap;
}

.weapon-btn:hover {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border-color: #666;
    transform: translateX(2px);
}

.weapon-btn.active {
    background: linear-gradient(145deg, #ff4400, #cc3300);
    border-color: #ff6600;
    box-shadow: 0 0 10px rgba(255,68,0,0.5);
}

#color-picker-container {
    position: fixed;
    bottom: 15px;
    left: 15px;
    background: rgba(20,20,20,0.95);
    padding: 8px;
    border-radius: 8px;
    border: 2px solid #444;
    z-index: 100;
    cursor: auto !important;
}

#color-picker-container * {
    cursor: auto !important;
}

#color-picker-container input,
#color-picker-container button {
    cursor: pointer !important;
}

#colorPickerHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    cursor: move !important;
}

#colorPickerHeader h3 {
    color: #00ff00;
    font-size: 0.9em;
    text-shadow: 0 0 5px #00ff00;
    margin: 0;
    cursor: move !important;
    user-select: none;
    flex-grow: 1;
}

#toggleColorPickerBtn {
    background: transparent;
    border: 1px solid #00ff00;
    color: #00ff00;
    width: 25px;
    height: 25px;
    border-radius: 4px;
    cursor: pointer !important;
    font-size: 1.2em;
    line-height: 1;
    padding: 0;
    transition: all 0.2s;
    flex-shrink: 0;
}

#toggleColorPickerBtn:hover {
    background: rgba(0,255,0,0.2);
    transform: scale(1.1);
}

#color-picker-container label {
    display: block;
    text-align: center;
    cursor: auto !important;
}

#colorPickerContent {
    padding: 4px;
}

#colorPickerWrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 6px;
}

#currentColorDisplay {
    width: 45px;
    height: 45px;
    border: 3px solid #666;
    border-radius: 6px;
    cursor: pointer !important;
    transition: all 0.3s;
}

#currentColorDisplay:hover {
    transform: scale(1.05);
    border-color: #00ff00;
}

#colorInput {
    width: 100%;
    padding: 6px 35px 6px 6px;
    background: #2a2a2a;
    border: 2px solid #444;
    border-radius: 4px;
    color: #00ff00;
    text-align: center;
    font-family: monospace;
    font-size: 1em;
    cursor: text !important;
}

#colorInput:focus {
    outline: none;
    border-color: #00ff00;
}

#eyedropperBtn {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    color: #ffffff;
    background: transparent;
    border: none;
    cursor: pointer !important;
    font-size: 1.3em;
    padding: 2px 6px;
    transition: transform 0.2s;
}

#eyedropperBtn:hover {
    transform: translateY(-50%) scale(1.2);
}

#eraserControls {
    position: fixed;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20,20,20,0.95);
    padding: 10px 15px;
    border-radius: 8px;
    border: 2px solid #444;
    z-index: 101;
    color: #fff;
    cursor: auto !important;
    display: none !important;
}

#eraserControls label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
}

#eraserSize {
    cursor: pointer !important;
    display: none !important;
}

#paintControls {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20,20,20,0.95);
    padding: 10px 15px;
    border-radius: 8px;
    border: 2px solid #444;
    z-index: 101;
    color: #fff;
    cursor: auto !important;
}

#paintControls label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
}

#paintBrushSize {
    cursor: pointer !important;
}

#colorPickerModal, #characterInputModal, #shapeModal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    cursor: auto !important;
}

#shapeModal.showing {
    display: flex !important;
}

#colorPickerModalContent, #characterInputContent, #shapeModalContent {
    background: #1a1a1a;
    padding: 20px;
    border-radius: 12px;
    border: 2px solid #444;
    max-width: 380px;
    max-height: 90vh;
    width: 90%;
    cursor: auto !important;
    pointer-events: auto;
    position: relative;
    z-index: 10001;
    overflow-y: auto;
}

h3 {
    color: #00ff00;
    text-align: center;
    margin-bottom: 12px;
    text-shadow: 0 0 10px #00ff00;
    font-size: 1.1em;
}

#quickColors {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

.color-swatch {
    aspect-ratio: 1;
    border: 2px solid #444;
    border-radius: 4px;
    cursor: pointer !important;
    transition: all 0.2s;
}

.color-swatch:hover {
    transform: scale(1.1);
    border-color: #00ff00;
}

.color-swatch.selected {
    transform: scale(1.2);
    border: 3px solid #00ff00;
    box-shadow: 0 0 12px rgba(0,255,0,0.8);
    z-index: 10;
}

#nativeColorPicker {
    width: 100%;
    height: 45px;
    border: 2px solid #444;
    border-radius: 6px;
    cursor: pointer !important;
    margin-bottom: 12px;
}

#modalButtons, #characterButtons {
    display: flex;
    gap: 8px;
}

#modalButtons button, #characterButtons button, #closeShapeModal, #cancelShapeModal {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 6px;
    cursor: pointer !important;
    font-weight: bold;
    font-size: 0.9em;
    transition: all 0.3s;
}

#shapeModalButtons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
}

#applyColorBtn, #applyCharacterBtn, #closeShapeModal {
    background: linear-gradient(145deg, #00ff00, #00cc00);
    color: #000;
    padding: 8px 20px;
}

#cancelColorBtn, #cancelCharacterBtn, #cancelShapeModal {
    background: linear-gradient(145deg, #ff0000, #cc0000);
    color: #fff;
    padding: 8px 20px;
}

#characterInput {
    width: 100%;
    padding: 12px;
    background: #2a2a2a;
    border: 2px solid #444;
    border-radius: 6px;
    color: #fff;
    text-align: center;
    font-size: 1.8em;
    margin-bottom: 12px;
    text-transform: uppercase;
}

#characterPreviewContainer {
    margin-top: 15px;
    padding: 10px;
    background: #2a2a2a;
    border-radius: 8px;
    border: 2px solid #444;
}

#characterPreviewContainer h4 {
    color: #00ff00;
    text-align: center;
    margin: 0 0 10px 0;
    font-size: 1em;
    text-shadow: 0 0 5px #00ff00;
}

#characterPreview {
    display: block;
    margin: 0 auto;
    border: 2px solid #444;
    border-radius: 4px;
    background: #1a1a1a;
    max-width: 100%;
}

#shapePreview {
    display: block;
    margin: 0 auto;
    border: 2px solid #444;
    border-radius: 4px;
    background: #1a1a1a;
    cursor: auto !important;
}

#shapeGrid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
    max-height: none;
    overflow: visible;
}

.shape-btn {
    padding: 10px;
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border: 2px solid #444;
    border-radius: 6px;
    color: #fff;
    cursor: pointer !important;
    transition: all 0.3s;
    font-size: 0.85em;
}

.shape-btn:hover {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border-color: #00ff00;
}

.shape-btn.active {
    background: linear-gradient(145deg, #ff4400, #cc3300);
    border-color: #ff6600;
    box-shadow: 0 0 15px rgba(255, 68, 0, 0.5);
    transform: scale(1.05);
}

#characterInputContent {
    background: #1a1a1a;
    padding: 20px;
    border-radius: 12px;
    border: 2px solid #444;
    max-width: 380px;
    max-height: 90vh;
    width: 90%;
    cursor: auto !important;
    pointer-events: auto;
    position: relative;
    z-index: 10001;
    overflow-y: auto;
}

@media (max-width: 768px) {
    #characterPreview {
        width: 100%;
        max-width: 250px;
        height: 100px;
        display: block;
        position: relative;
        margin: 0 auto;
    }
    
    #characterInputContent {
        max-width: 95%;
        max-height: 60vh;
        padding: 15px;
        overflow-y: auto;
    }
    
    #characterInputModal {
        align-items: flex-start;
        padding-top: 5vh;
        overflow-y: auto;
    }
    
    #characterPreviewContainer {
        display: block;
        width: 100%;
    }
    
    #characterInput {
        font-size: 1.3em;
    }
}

#shapeColorPicker {
    margin: 12px 0;
    padding: 10px;
    background: #2a2a2a;
    border-radius: 6px;
    border: 1px solid #444;
}

#shapeColorPicker label {
    color: #00ff00;
    font-size: 0.9em;
    display: block;
    margin-bottom: 6px;
}

#shapeColorDisplay {
    width: 40px;
    height: 40px;
    border: 2px solid #666;
    border-radius: 6px;
    cursor: pointer !important;
    display: inline-block;
    margin-right: 10px;
    vertical-align: middle;
}

#shapeColorInput {
    width: calc(100% - 60px);
    height: 40px;
    border: 2px solid #444;
    border-radius: 6px;
    cursor: pointer !important;
    vertical-align: middle;
}

#shapePreviewContainer {
    margin-top: 15px;
    padding: 10px;
    background: #2a2a2a;
    border-radius: 8px;
    border: 2px solid #444;
}

#shapePreviewContainer h4 {
    color: #00ff00;
    text-align: center;
    margin: 0 0 10px 0;
    font-size: 1em;
    text-shadow: 0 0 5px #00ff00;
}

#shapePreview {
    display: block;
    margin: 0 auto;
    border: 2px solid #444;
    border-radius: 4px;
    cursor: auto !important;
}

#shapeModalContent label {
    display: block;
    color: #fff;
    margin: 8px 0;
    font-size: 0.9em;
    cursor: auto !important;
}

#shapeModalContent input[type="checkbox"] {
    cursor: pointer !important;
}

#shapeModalContent input[type="range"] {
    width: 150px;
    cursor: pointer !important;
}

#weaponPreview {
    position: fixed;
    width: 120px;
    height: 120px;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
    opacity: 0.8;
    border-radius: 4px;
    background: rgba(0,0,0,0.1);
    display: none;
}

#characterPlacementPreview {
    position: fixed;
    width: auto;
    height: auto;
    max-width: 1400px;
    max-height: 300px;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
    opacity: 0.9;
    border-radius: 4px;
    background: rgba(0,0,0,0.3);
    display: none;
    border: none;
}

@media (max-width: 768px) {
    #characterPlacementPreview {
        display: none !important;
    }
    
    #weaponPreview {
        display: none !important;
    }
    
    #color-picker-container {
        bottom: 5px;
        right: 5px;
        left: auto;
        padding: 5px;
        max-width: 135px;
        min-width: 135px;
    }
    
    #currentColorDisplay {
        width: 30px;
        height: 30px;
    }
    
    #colorInput {
        font-size: 0.75em;
        padding: 4px 26px 4px 4px;
        width: 100%;
        max-width: 125px;
    }
    
    #eyedropperBtn {
        font-size: 0.95em;
        padding: 2px 3px;
        right: 1px;
    }
    
    #colorPickerWrapper {
        margin-bottom: 3px;
    }
    
    #colorPickerContent {
        padding: 3px;
    }
    
    #colorPickerContent > div {
        position: relative;
        width: 100%;
    }
    
    #colorPickerHeader {
        margin-bottom: 4px;
    }
    
    #colorPickerHeader h3 {
        font-size: 0.75em;
    }
    
    #toggleColorPickerBtn {
        width: 20px;
        height: 20px;
        font-size: 1em;
    }
}

#shapePreview {
    display: block;
    margin: 0 auto;
    border: 2px solid #444;
    border-radius: 4px;
    background: #1a1a1a;
    cursor: auto !important;
}

@media (max-width: 768px) {
    #shapePreview {
        width: 120px;
        height: 120px;
    }
    
    #characterPreview {
        width: 100%;
        max-width: 200px;
        height: 100px;
    }
    
    #holdInstruction {
        font-size: 0.9em;
        padding: 15px 20px;
        max-width: 80%;
    }
}

@media (max-width: 768px) {
    #weapons-panel {
        left: 5px;
        top: auto;
        bottom: 5px;
        transform: none;
        max-height: 35vh;
        padding: 8px;
        flex-direction: column;
    }
    
    #weapons-panel.collapsed {
        max-height: 45px;
    }
    
    #weapons-panel.horizontal {
        left: 5px !important;
        right: 5px;
        top: auto !important;
        bottom: 5px !important;
        transform: none !important;
        max-width: calc(100vw - 10px);
        flex-direction: row !important;
        max-height: none;
    }
    
    #weapons-panel.horizontal #weapons-header {
        flex-direction: column !important;
        margin-right: 6px;
        margin-bottom: 0;
        gap: 4px;
    }
    
    #weapons-panel.horizontal #weapons-grid {
        flex-direction: row !important;
        overflow-x: auto;
        overflow-y: hidden;
        max-height: none;
        max-width: calc(100vw - 60px);
        padding-bottom: 4px;
    }
    
    #weapons-grid {
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .weapon-btn {
        padding: 5px 8px;
        font-size: 0.75em;
    }
    
    #color-picker-container {
        bottom: 5px;
        right: 5px;
        left: auto;
        padding: 6px;
        max-width: 180px;
    }
    
    #currentColorDisplay {
        width: 38px;
        height: 38px;
    }

    #shapeGrid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    #colorPickerModalContent, #characterInputContent, #shapeModalContent {
        max-width: 95%;
        max-height: 85vh;
        padding: 15px;
        overflow-y: auto;
    }
    
    #shapeModalContent {
        max-height: 80vh;
    }
    
    .shape-btn {
        padding: 8px;
        font-size: 0.8em;
    }
    
    #shapePreviewContainer {
        margin-top: 10px;
        padding: 8px;
    }
    
    #shapePreview {
        width: 120px;
        height: 120px;
        display: block;
        position: relative;
        margin: 0 auto;
    }
    
    #shapeModal {
        align-items: flex-start;
        padding-top: 3vh;
        overflow-y: auto;
    }
    
    #shapeModalContent {
        margin-top: 0;
        max-height: 85vh;
        overflow-y: auto;
    }
    
    #shapePreviewContainer {
        display: block;
        width: 100%;
    }
    
    #colorPickerModal {
        padding-top: 5vh;
        align-items: flex-start;
    }
    
    #colorPickerModalContent {
        max-height: 80vh;
        overflow-y: auto;
    }
    
    #characterPreview {
        width: 100%;
        max-width: 200px;
        height: 80px;
    }
    
    h3 {
        font-size: 1em;
        margin-bottom: 10px;
    }
    
    #shapeColorPicker {
        margin: 10px 0;
        padding: 8px;
    }
    
    #holdInstruction {
        font-size: 1em;
        padding: 15px 20px;
    }
    
    #holdInstructionIcon {
        font-size: 1.5em;
        margin-bottom: 8px;
    }
}

#weapons-panel::-webkit-scrollbar, #shapeGrid::-webkit-scrollbar {
    width: 6px;
}

#weapons-panel::-webkit-scrollbar-track, #shapeGrid::-webkit-scrollbar-track {
    background: #1a1a1a;
}

#weapons-panel::-webkit-scrollbar-thumb, #shapeGrid::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

button, input, select, textarea, label, a {
    cursor: auto !important;
}
