/* --- BASIS & LAYOUT --- */
body { 
    margin: 0; 
    overflow: hidden; 
    background-color: #f4f4f4; 
    /* Ein dezentes Gittermuster erstellen */
    background-image: 
        linear-gradient(to right, #e0e0e0 1px, transparent 1px),
        linear-gradient(to bottom, #e0e0e0 1px, transparent 1px);
    background-size: 25px 25px; /* Genau passend zu deiner GRID_SIZE */
    user-select: none; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* --- DAS QUADRAT (BASIS) --- */
.square {
    position: absolute;
    cursor: grab;
    background-color: #3498db;
    border-radius: 4px; /* Standard-Ecken */
    box-sizing: border-box;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15); /* Von 5px auf 3px reduziert für einen feineren Look bei kleinen Quadraten    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);  */
    transform-origin: center center;
    z-index: 1;
    /* Nur Schatten und Farbe animieren, nicht die Bewegung/Größe! */
    transition: box-shadow 0.2s ease, background-color 0.3s ease;
    box-sizing: border-box; /* Rahmen wird nach innen gerechnet */
    transition: background-color 0.2s, border 0.2s;
}

/* Aktiv-Zustand */
.square.active {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 100;
    cursor: grabbing;
    outline: 2px solid #3498db; /* Fokus-Rahmen */
}

/* --- FORMEN --- */
.square.circle { 
    border-radius: 50% !important; 
}

.square.rounded { 
    border-radius: 20px !important; 
}

.square .controls {
    position: absolute;
    /* Wir nutzen 'top' und 'left' für die Grundposition */
    top: -65px; 
    left: 50%;
    
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 6px 12px;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1001;
    white-space: nowrap;
    min-width: 220px;

    /* Der Ankerpunkt muss exakt die Mitte der Unterkante sein */
    transform-origin: center bottom;
    
    /* Keine Transition auf 'transform', damit es nicht "nachwackelt" */
    transition: top 0.2s ease, opacity 0.2s;
}

.square.active .controls,
.square.selected .controls {
    display: flex;
}

/* Buttons & Picker im Menü */
.control-btn, .color-picker, .shape-picker {
    height: 28px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}

.control-btn {
    width: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #555;
}

.control-btn:hover {
    background: #3498db;
    color: white;
    border-color: #2980b9;
}

.shape-picker {
    border-radius: 12px;
    padding: 0 8px;
    font-size: 12px;
    color: #333;
}

.color-picker {
    width: 28px;
    border-radius: 50%;
    padding: 0;
    overflow: hidden;
}

.color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker::-webkit-color-swatch { border: none; border-radius: 50%; }

/* --- RESIZE HANDLE (ZIEHECKE) --- */
.square .resizer {
    width: 10px;
    height: 10px;
    background: #3498db;
    border: 2px solid white;
    position: absolute;
    right: -7px;
    bottom: -7px;
    cursor: nwse-resize;
    display: none;
    z-index: 1003;
    border-radius: 3px;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

.square.active .resizer {
    display: block;
}

/* --- LÖSCH BUTTON --- */
.square .delete-btn {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 24px;
    height: 24px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    border: 2px solid white;
    font-size: 14px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1002;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.square.active .delete-btn, .square.selected .delete-btn,
.square.active .resizer, .square.selected .resizer {
    display: flex;
}

/* --- UI LAYER (HEADER) --- */
#ui-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    background: rgba(240, 240, 240, 0.9); /* Leicht transparentes Grau */
    border-bottom: 2px solid #ccc;
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 9999; /* Sehr hoch, damit es immer oben liegt */
    box-sizing: border-box;
}

#addButton {
    padding: 8px 16px;
    font-size: 18px;
    cursor: pointer;
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle; /* Verhindert das Verspringen in Textzeilen */
}

#addButton:hover { background-color: #218838; }

#log {
    margin-left: 20px;
    font-family: monospace;
    color: #555;
}
#db-status { color: #888; font-size: 12px; margin-left: 10px; }

/* Spezifische Farben für die neuen Buttons innerhalb deines Designs */
.size-minus { 
    color: #e74c3c !important; /* Passend zu deinem Lösch-Rot */
}

.size-plus { 
    color: #27ae60 !important; /* Passend zu deinem Add-Grün */
}

/* Optional: Ein kleiner visueller Effekt beim Drücken */
.control-btn:active {
    transform: scale(0.9);
}

.square.line {
    height: 4px !important; /* Fixe Dicke der Linie */
    border-radius: 2px;
    border: none !important; /* Linien sind nie "hohl" im klassischen Sinne */
}

/* Verstecke den Resizer für Linien oder pass ihn an */
.square.line .resizer {
    height: 100%;
    top: 0;
    right: -5px;
    width: 10px;
    cursor: ew-resize; /* Nur horizontales Ziehen */
}

.selection-frame {
  position: absolute;
  border: 1px solid #007bff;
  background-color: rgba(0, 123, 255, 0.2);
  pointer-events: none; /* Wichtig: Der Rahmen darf keine Maus-Events abfangen! */
}

.lasso-selection {
    position: fixed;
    border: 1px dashed #3498db;
    background: rgba(52, 152, 219, 0.2);
    pointer-events: none; /* Wichtig: Das Lasso darf Maus-Events nicht blockieren */
    z-index: 9999;
}

.square.selected {
    outline: 3px solid #f1c40f !important; /* Goldener Rahmen */
    box-shadow: 0 0 15px rgba(241, 196, 15, 0.8);
    z-index: 100;
}

#selection-info {
    margin: 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #ddd;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

#selection-info input {
    width: 45px;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 2px;
    font-family: monospace;
}

.prop-group {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-family: 'Segoe UI', sans-serif;
}

.prop-label {
    font-weight: bold;
    color: #666;
}

.prop-input {
    width: 50px;
    border: 1px solid #eee;
    border-radius: 3px;
    padding: 2px 4px;
    font-family: monospace;
    font-size: 12px;
    outline: none;
}

.prop-input:focus {
    border-color: #3498db;
    background: #f0f7ff;
}

.prop-unit {
    font-size: 11px;
    color: #888;
    margin-left: -5px;
}

.prop-color {
    width: 25px;
    height: 25px;
    padding: 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: none;
}

.prop-color::-webkit-color-swatch {
    border: 1px solid #ddd;
    border-radius: 4px;
}

#btnShare {
    padding: 8px 16px;
    margin: 10px 20px;
    font-size: 18px;
    cursor: pointer;
    background-color: #fff;
    color: white;
    border: none;
    border: 1px solid #c0c0c0;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle; /* Verhindert das Verspringen in Textzeilen */
}

#btnShare:hover { background-color: #218838; }

