html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
}
body { 
    margin: 0; 
    padding: 0; 
    overflow: hidden; 
    background-color: #222;
    display: flex;
    justify-content: center;
    align-items: center;
}
canvas { 
    position: fixed;
    /* Use vh (viewport height) for both dimensions to maintain square ratio */
    width: 100vh;
    height: 100vh;
    /* Center the canvas if viewport is wider than tall */
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    image-rendering: pixelated;
}
/* Add media query for landscape orientation */
@media (aspect-ratio > 1/1) {
    canvas {
        width: 100vh;
        height: 100vh;
    }
}
/* Add media query for portrait orientation */
@media (aspect-ratio < 1/1) {
    canvas {
        width: 100vw;
        height: 100vw;
    }
}

/* NEW: War Mode Link */
#war-mode-link {
    position: fixed;
    left: 10px;
    top: 15px;
    z-index: 101;
}

#warModeBtn {
    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: 1.5em;
    cursor: pointer !important;
    transition: all 0.2s;
    backdrop-filter: blur(3px);
}

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

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

/* IMPROVED COLOR PICKER FROM PROJECT 2 */
#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;
    min-width: 160px;
    display: flex;
    flex-direction: column;
}

#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;
    width: 100%;
    order: 1;
}

#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;
    justify-content: center;
    display: flex;
}

#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);
}

#colorPickerContent {
    order: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

#colorPickerWrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 6px;
    order: 1;
    width: 100%;
}

#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;
}

/* Text input with eyedropper - appears below color picker */
#colorInputContainer {
    position: relative;
    width: 100%;
    order: 2;
}

#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;
    box-sizing: border-box;
}

#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);
}

/* Remove old color picker styles */
#color-picker-container input[type="color"] {
    display: none;
}

#color-picker-container label {
    display: none;
}

/* Responsive positioning */
@media (aspect-ratio > 1/1) {
    #color-picker-container {
        top: 50%;
        right: 20px;
        bottom: auto;
        left: auto;
        transform: translateY(-50%);
    }
}

@media (aspect-ratio < 1/1) {
    #color-picker-container {
        top: 20px;
        bottom: auto;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }
}

@media (max-width: 768px) {
    #color-picker-container {
        bottom: 5px;
        right: 5px;
        left: auto;
        padding: 6px;
        max-width: 180px;
        min-width: 180px;
        display: flex !important;
        flex-direction: column !important;
    }
    
    #colorPickerHeader {
        order: 1 !important;
        flex-direction: row !important;
    }
    
    #colorPickerContent {
        order: 2 !important;
        flex-direction: column !important;
    }
    
    #currentColorDisplay {
        width: 38px;
        height: 38px;
    }
    
    #colorInput {
        font-size: 0.75em;
        padding: 4px 26px 4px 4px;
        width: 100%;
        box-sizing: border-box;
    }
    
    #eyedropperBtn {
        font-size: 0.95em;
        padding: 2px 3px;
        right: 1px;
    }
}

/* Color Picker Modal Styles */
#colorPickerModal {
    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;
}

#colorPickerModalContent {
    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;
}

#colorPickerModalContent 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 {
    display: flex;
    gap: 8px;
}

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

#applyColorBtn {
    background: linear-gradient(145deg, #00ff00, #00cc00);
    color: #000;
}

#cancelColorBtn {
    background: linear-gradient(145deg, #ff0000, #cc0000);
    color: #fff;
}

#cooldownTimer {
  position: fixed;
  top: 20px;
  right: 20px; 
  color: white; 
  font-size: 18px; 
  background-color: #67676780;
  padding: 10px;
  border-radius: 5px;
  border: 2px solid #e9dc41;
  display: none;
}
.footer {
    color: rgb(172 172 172);
    font-size: 0.8em;
    position: fixed;
    height: 30px;
    bottom: 0px;
    right: 3%;
    height: fit-content;
}
#confirmation-dialog {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 12.5%;       
    background: rgba(40, 40, 40, 0%);
    display: none; /* Initially hidden */
    justify-content: center;
    align-items: center;
    z-index: 1100;
    padding: 10px;
    box-sizing: border-box;
}

.dialog-content {
    width: 97%;
    display: flex;
    align-items: center;
    background: #333;
    color: white;
    padding: 20px 30px;
    border-radius: 10px;
    font-family: sans-serif;
}

.dialog-content p {
    margin: 0 15px 0 0;
    font-size: 35px;
}

.dialog-content .color-preview {
    width: 50px;
    height: 50px;
    margin: 0 15px 0 0;
    border: 2px solid white;
    flex-shrink: 0; /* Prevent shrinking */
    margin-right: auto;
}

.dialog-buttons button {
    padding: 12px 24px;
    margin: 0 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 35px;
}

#confirm-pixel-btn {
    background: #4CAF50; /* Green */
    color: white;
}

#cancel-pixel-btn {
    background: #f44336; /* Red */
    color: white;
}

/* FIXED: Loading overlay with semi-transparent background */
#loading-overlay {
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(45, 45, 45, 0.7) !important;
    color: white; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
    align-items: center; 
    z-index: 1000;
}

#loading-overlay h2 {
    margin: 5px 0;
}
