/* Version 1.3 */
:root {
    --primary: #1E3A8A; 
    --accent: #8bc34a;
    --bg: #fdfdfd;
    --ui-bg: rgba(255, 255, 255, 0.95);
}

body, html { 
    margin: 0; padding: 0; width: 100vw; height: 100vh; overflow: hidden; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg);
    touch-action: none; /* Prevents mobile pull-to-refresh */
    user-select: none;  /* Prevents accidental text selection while panning */
}

/* Re-enable selection only where needed */
textarea, input { user-select: text; }

#toolbar {
    position: absolute; top: 20px; left: 20px;
    display: flex; flex-direction: column; gap: 8px; 
    background: var(--ui-bg); padding: 12px; border-radius: 8px; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.08); z-index: 1000; 
    border: 1px solid #e0e0e0; width: max-content;
}

.tool-group { display: flex; flex-direction: column; gap: 6px; }

button {
    padding: 8px 12px; cursor: pointer; border-radius: 6px; font-weight: 500;
    border: 1px solid #ccc; background: white; transition: all 0.2s;
    display: flex; align-items: center; justify-content: flex-start; gap: 8px; color: #333;
    width: 100%; box-sizing: border-box;
}
button:hover { background: #f9f9f9; border-color: var(--accent); }
button:active { transform: scale(0.98); }

.color-picker-wrapper { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
input[type="color"] {
    width: 100%; height: 35px; padding: 0; cursor: pointer;
    border: 1px solid #ccc; border-radius: 6px; overflow: hidden;
}

.checkbox-label { display: flex; align-items: center; gap: 5px; cursor: pointer; font-size: 14px; color: #333; font-weight: 500; padding: 4px 5px; }
.divider { width: 100%; height: 1px; background: #ccc; margin: 4px 0; }

#viewport { position: absolute; width: 100vw; height: 100vh; top: 0; left: 0; overflow: hidden; cursor: grab; }
#viewport:active { cursor: grabbing; }

#workspace { position: absolute; top: 0; left: 0; width: 4000px; height: 4000px; transform-origin: 0 0; }

canvas { position: absolute; top: 0; left: 0; cursor: crosshair; }
#mainCanvas { z-index: 10; }
#previewCanvas { z-index: 11; pointer-events: none; }

#puzzle-area { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; pointer-events: none; }

.watermark {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; opacity: 0.04; z-index: 0;
    background-image: url('./logo.png'); background-repeat: repeat; background-size: 350px;
}

.puzzle-piece {
    position: absolute; pointer-events: none; /* Transparent box passes clicks to canvas */
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    overflow: visible; filter: drop-shadow(3px 5px 8px rgba(0,0,0,0.15));
    padding: 30px; box-sizing: border-box; cursor: default;
}
.puzzle-piece.active svg > path { filter: drop-shadow(0px 0px 6px rgba(0, 188, 212, 0.8)); }
.puzzle-piece svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; overflow: visible; pointer-events: none; }
.puzzle-piece svg > path { pointer-events: visiblePainted; cursor: grab; } /* Make Exact Painted path clickable! */
.puzzle-piece.active svg > path { cursor: default; }

.text-box-container {
    position: absolute; pointer-events: auto; padding: 0; box-sizing: border-box;
    border: 1px solid transparent; 
    background: transparent; min-width: 150px; min-height: 100px;
    display: flex; flex-direction: column;
    transition: border-color 0.2s, background-color 0.2s;
}
.text-box-container:hover, .text-box-container.active {
    border-color: rgba(0,0,0,0.1); background: rgba(255,255,255,0.85);
}

.text-drag-handle {
    width: 100%; height: 24px; background: rgba(0,0,0,0.05); 
    cursor: grab; display: flex; align-items: center; justify-content: center;
    color: #888; font-size: 14px; letter-spacing: 2px;
    border-bottom: 1px solid transparent; flex-shrink: 0; pointer-events: auto;
}
.text-drag-handle:active { cursor: grabbing; }
.text-box-container:hover .text-drag-handle { background: rgba(0,0,0,0.1); border-bottom: 1px solid rgba(0,0,0,0.1); }

.piece-text {
    flex-grow: 1; width: 100%; border: none; background: transparent; pointer-events: auto;
    resize: none; font-size: 16px; outline: none; 
    font-family: inherit; z-index: 2; line-height: 1.5; padding: 15px; box-sizing: border-box;
    white-space: pre-wrap; overflow-y: hidden; overflow-x: hidden;
}

.resize-handle {
    position: absolute; bottom: 0; right: 0; width: 22px; height: 22px;
    cursor: nwse-resize; z-index: 10;
    background: linear-gradient(135deg, transparent 50%, rgba(100,100,100,0.3) 50%);
    border-bottom-right-radius: 4px; pointer-events: auto;
}

#branding-box {
    position: absolute; bottom: 20px; right: 20px; z-index: 1000;
    background: var(--ui-bg); border: 1px solid #e0e0e0; border-radius: 10px; 
    padding: 12px 18px; display: flex; align-items: center; gap: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.06); pointer-events: none;
}
#branding-box img { width: 45px; height: 45px; object-fit: contain; }
#branding-box .details { display: flex; flex-direction: column; }
#branding-box .title { font-weight: 600; color: #333; font-size: 14px; margin-bottom: 2px; }
#branding-box .date { font-size: 12px; color: #777; }

#privacy-disclaimer {
    position: absolute; bottom: 20px; left: 20px; z-index: 1000;
    background: var(--ui-bg); border: 1px solid #e0e0e0; border-radius: 10px; 
    padding: 12px 18px; display: flex; align-items: center; gap: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.06); pointer-events: none;
    font-size: 13px; color: #444; line-height: 1.4;
}

#info-modal { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.6); z-index: 2000; justify-content: center; align-items: center; backdrop-filter: blur(3px); }
.modal-content { background: white; padding: 35px; border-radius: 12px; max-width: 550px; box-shadow: 0 15px 40px rgba(0,0,0,0.3); position: relative; font-size: 15px; color: #333; line-height: 1.6; }
.modal-content h3 { margin-top: 0; color: var(--primary); font-size: 22px; }
.close-btn { position: absolute; top: 15px; right: 20px; font-size: 28px; cursor: pointer; color: #888; }
.close-btn:hover { color: #d32f2f; }

#pen-settings-panel {
    display: none; 
    position: absolute; top: 20px; left: 180px; 
    background: var(--ui-bg); padding: 15px; border-radius: 8px; 
    box-shadow: 0 8px 30px rgba(0,0,0,0.12); z-index: 1500; 
    border: 1px solid #e0e0e0; width: 220px;
    flex-direction: column; gap: 12px;
}

.setting-row { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; color: #333; }
.setting-row input[type="range"] { width: 100%; cursor: pointer; }
