/* Main canvas wrapper - responsive */
#canvasWrapper {
    box-sizing: border-box;
    width: min(90vw, 780px); /* 90% of viewport width, max 780px */
    height: min(90vw, 780px); /* Keep it square */
    padding: 10px;
    border: 4px solid #E1F5FE;
    background-color: white;
    margin: 1rem auto;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Canvas container - responsive */
#canvasContainer {
    position: relative;
    display: block;
    overflow: hidden;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.05);
    background-color: #E1F5FE;
    width: 100%;
    height: 100%;
    aspect-ratio: 1; /* Keep it square */
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    
    /* Prevent dragging */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    
    /* Prevent text selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    
    /* Prevent context menu on long press (mobile) */
    -webkit-touch-callout: none;
    
    /* Additional drag prevention */
    pointer-events: auto;
    touch-action: none;
    
    /* Smooth scaling */
    image-rendering: pixelated; /* Keep pixel art crisp */
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Canvas grid guide */
#guide {
    display: grid;
    pointer-events: none;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    grid-template-columns: repeat(50, 1fr);
    grid-template-rows: repeat(50, 1fr);
    
    /* Prevent dragging on guide as well */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    
    -webkit-touch-callout: none;
}

#guide div {
    border: 1px solid rgba(0, 0, 0, 0.1);
    
    /* Prevent dragging on guide cells */
    -webkit-user-drag: none;
    -moz-user-drag: none;
    user-drag: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}

/* Tooltip styling */
#tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    z-index: 1000;
    max-width: 200px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;: 'Baloo 2', cursive;
    transition: opacity 0.3s ease;
}

#tooltip button {
    margin-top: 6px;
    padding: 6px 12px;
    background-color: #e3a157;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#tooltip button:hover {
    background-color: #d28e3c;
}

/* Control panel - responsive */
.control-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin: 1rem auto;
    padding: 10px;
    background-color: #E1F5FE;
    border-radius: 12px;
    box-shadow: 0 0 10px rgba(0,0,0,0.05);
    max-width: min(90vw, 1400px);
}

/* Canvas action buttons (Clear, Save, Load) */
.canvas-button-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 1rem auto;
    gap: 10px;
    flex-wrap: wrap;
}

.canvas-button-wrapper button {
    padding: 10px 20px;
    background-color: #e3a157;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.3s ease;
}

.canvas-button-wrapper button:hover {
    background-color: #d28e3c;
}

/* Alternative button styling */
.canvas-action-btn {
    background-color: #444;
    color: white;
    border: none;
    padding: 10px 14px;
    margin: 4px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s ease;
}

.canvas-action-btn:hover {
    background-color: #666;
}

/* Color preset buttons */
.colour-btn {
    padding: 10px 16px;
    border: none;
    cursor: pointer;
    border-radius: 8px;
    background-color: #e3a157;
    color: white;
    font-weight: bold;
    transition: background-color 0.3s ease;
}

.colour-btn:hover {
    background-color: #d28e3c;
}

/* Preset colors container */
.preset-colours {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

/* Multiplayer link styling */
.active[href="live_canvas"] {
    display: block;
    text-align: center;
    margin: 1rem auto;
    width: fit-content;
    padding: 10px 20px;
    background-color: #e3a157;
    color: white !important;
    text-decoration: none;
    border-radius: 8px;
    font-weight: bold;
    transition: background-color 0.3s ease;
}

.active[href="live_canvas"]:hover {
    background-color: #d28e3c;
}

/* Page headings */
main h3 {
    text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;: 'Baloo 2', cursive;
    margin: 2rem 0 1rem 0;
}

/* Recent drawings grid */
#recentDrawings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    justify-items: center;
    margin: 20px auto;
    max-width: min(90vw, 1000px);
    padding: 0 20px;
}

/* All older drawings grid */
#allOlderDrawings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    justify-items: center;
    margin: 20px auto;
    max-width: min(90vw, 1000px);
    padding: 0 20px;
}

/* Individual drawing containers */
.drawing-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 10px;
    border: 1px solid #ddd;
    background-color: #E1F5FE;
    border-radius: 12px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.drawing-container:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.drawing-container canvas {
    border: 1px solid #ccc;
    background-color: #E1F5FE;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}

.drawing-name {
    font-weight: bold;
    margin: 4px 0 0;
    font-size: 16px;
    color: #333;
    text-align: center;
}

.drawing-user {
    font-style: italic;
    font-size: 0.9em;
    margin: 0 0 8px;
}

/* Mobile and tablet responsiveness */
@media screen and (max-width: 768px) {
    #canvasWrapper {
        width: min(95vw, 500px);
        height: min(95vw, 500px);
        padding: 8px;
    }
    
    .control-panel {
        flex-direction: column;
        align-items: center;
        width: min(95vw, 500px);
        margin: 1rem auto;
    }
    
    .preset-colours {
        gap: 0.3rem;
    }
    
    .colour-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    #colourInput {
        width: 60px;
        height: 40px;
    }
}

@media screen and (max-width: 480px) {
    #canvasWrapper {
        width: min(98vw, 350px);
        height: min(98vw, 350px);
        padding: 5px;
    }
    
    .control-panel {
        width: min(98vw, 350px);
        padding: 8px;
    }
    
    .colour-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
}

/* Very large screens */
@media screen and (min-width: 1200px) {
    #canvasWrapper {
        width: min(60vw, 800px);
        height: min(60vw, 800px);
    }
}