body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Prevent scrolling, zooming/panning is via canvas */
    background-color: #f5f5f5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    user-select: none;
}

/* Header & Toolbars */
.top-nav {
    background-color: transparent;
    padding: 12px 16px;
    display: flex;
    justify-content: center;
    pointer-events: none;
    /* Let clicks pass through empty areas */
    box-shadow: none !important;
    /* Override uikit */
    z-index: 100 !important;
    /* Extremely high z-index to block overlay */
}

.nav-container {
    width: 100%;
    pointer-events: auto;
    /* Re-enable clicks on actual elements */
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.nav-left,
.nav-center,
.nav-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    /* allow toolbars themselves to wrap internal icons if exceedingly tight */
    gap: 8px;
    background-color: white;
    padding: 6px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    border: 1px solid #eee;
}

.nav-branding {
    display: flex;
    align-items: center;
    margin: 0 12px;
    color: #333;
}

.user-badge {
    background-color: #f0f0f0;
    padding: 4px 10px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 6px;
}

.user-badge a {
    color: #666;
}

.user-badge a:hover {
    color: #333;
}

.toolbar {
    /* Merged into nav styling */
}

.tool-btn,
.nav-btn {
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    transition: background-color 0.2s, color 0.2s;
    padding: 0;
}

.tool-btn:hover,
.nav-btn:hover {
    background-color: #f0f0f0;
    color: #111;
}

.tool-btn.active {
    background-color: #e5f1ff;
    color: #0066ff;
}

.divider {
    width: 1px;
    height: 24px;
    background-color: #ddd;
    margin: 0 4px;
}

.color-picker-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    overflow: hidden;
}

.color-picker-wrapper:hover {
    background-color: #f0f0f0;
}

.color-picker-wrapper input[type="color"] {
    border: none;
    width: 24px;
    height: 24px;
    margin-left: 4px;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
    border: 1px solid #ccc;
    border-radius: 4px;
}

.image-upload-wrapper {
    margin: 0;
}

/* Canvas Area */
#canvasContainer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: default;
    /* Dynamically changed by JS */
    touch-action: none;
    /* Important for custom touch handling */
}

#mainCanvas {
    z-index: 2;
}

#overlayCanvas {
    z-index: 3;
    pointer-events: auto;
    /* Input goes to overlayCanvas which handles events */
}

/* Text Input Overlay */
#textInput {
    background: rgba(255, 255, 255, 0.9);
    border: 2px dashed #0066ff;
    border-radius: 4px;
    color: black;
    font-size: 20px;
    font-family: inherit;
    padding: 2px;
    resize: both;
    outline: none;
    overflow: hidden;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-sizing: border-box;
    display: none;
    position: absolute;
    z-index: 10;
    line-height: normal;
    min-width: 50px;
    min-height: 30px;
}


/* Cursors */
.cursor-select {
    cursor: default;
}

.cursor-draw {
    cursor: crosshair;
}

.cursor-text {
    cursor: text;
}

.cursor-crosshair {
    cursor: crosshair;
}

.cursor-move {
    cursor: move;
}

.cursor-grab {
    cursor: grab;
}

.cursor-grabbing {
    cursor: grabbing;
}

.cursor-resize-nwse {
    cursor: nwse-resize;
}

.cursor-resize-nesw {
    cursor: nesw-resize;
}

.cursor-resize-ew {
    cursor: ew-resize;
}

.cursor-resize-ns {
    cursor: ns-resize;
}