@font-face {
    font-family: 'ABIcons';
    src: url('../Armin_Bauke_Iconfont.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

.ab-icon, .layer-visibility, .layer-lock {
    font-family: 'ABIcons' !important;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
/* Icon-Größen */
.ab-icon { font-size: 1.3rem; vertical-align: middle; }
.layer-toolbar .ab-icon { font-size: 1.4rem; }
.layer-visibility, .layer-lock { font-size: 1.2rem; }

:root {
    --bg-color: #2c3e50;
    --panel-bg: #ecf0f1;
    --text-color: #2c3e50;
    --accent-color: #3498db;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0; height: 100vh;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    position: relative;
}

#main-area { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }

#sidebar {
    position: fixed; top: 0; left: 0; width: 350px; height: 100%;
    background-color: var(--panel-bg);
    box-shadow: 2px 0 10px rgba(0,0,0,0.3);
    display: flex; flex-direction: column;
    z-index: 10; min-width: 250px; max-width: 600px;
}

#sidebar.collapsed { transform: translateX(-100%); opacity: 0; pointer-events: none; }

#sidebarContent {
    padding: 15px; overflow-y: auto; flex: 1;
    display: flex; flex-direction: column; gap: 10px;
    scroll-behavior: smooth;
}

#resizeHandle {
    position: absolute; right: 0; top: 0; width: 10px; height: 100%;
    cursor: ew-resize; z-index: 25;
}
#resizeHandle:hover { background: rgba(52, 152, 219, 0.3); }

/* REITER STYLING */
.control-group {
    background: white; border-radius: 4px; padding: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex; flex-direction: column;
}

h2 { 
    margin: 0; font-size: 1.05rem; padding: 5px 0;
    cursor: grab; user-select: none;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid #eee;
}
h2:active { cursor: grabbing; }
h2::after { content: '▼'; font-size: 0.7rem; transition: transform 0.2s; margin-left: 10px; }
h2.collapsed::after { transform: rotate(-90deg); }
h2.collapsed { border-bottom: none; }

.section-content { 
    overflow: hidden; transition: max-height 0.3s ease, opacity 0.2s; 
    max-height: 2000px; padding-top: 10px; opacity: 1;
    display: flex; flex-direction: column; gap: 10px;
}
.section-content.collapsed { max-height: 0; padding-top: 0; opacity: 0; pointer-events: none; }

#colorPicker { display: flex; justify-content: center; width: 100%; margin: 0 auto; }

/* FENSTER STYLING */
.floating-window {
    position: fixed; background: var(--panel-bg); border: 1px solid #ccc;
    border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    z-index: 2000; width: 320px; display: flex; flex-direction: column;
    overflow: hidden; resize: both;
    min-width: 250px; min-height: 45px; max-height: 100vh;
}
.floating-window[data-minimized="true"] { resize: none !important; height: auto !important; }
.floating-header {
    background: var(--accent-color); color: white; padding: 10px 15px;
    cursor: move; display: flex; justify-content: space-between; align-items: center;
    user-select: none; min-height: 35px;
}
.floating-controls { 
    display: flex; 
    gap: 12px; /* MEHR ABSTAND */
}
.min-btn, .close-btn {
    background: rgba(255,255,255,0.2); border: none; color: white;
    width: 28px; height: 28px; border-radius: 4px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; transition: background 0.2s;
}
.min-btn:hover, .close-btn:hover { background: rgba(255,255,255,0.4); }
.floating-content { padding: 15px; background: white; flex: 1; overflow-y: auto; }

/* AUSGRAUEN DER UNTEROPTIONEN */
.sub-options-disabled {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(1);
}

.drag-placeholder {
    background: rgba(52, 152, 219, 0.1); border: 2px dashed #3498db;
    border-radius: 4px; height: 100px; margin: 10px 0; pointer-events: none;
}

/* LAYOUT ELEMENTE */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row label { flex: 1; min-width: 100px; font-size: 0.85rem; }
.row input[type="number"], .row input[type="text"] { width: 75px; padding: 5px; border: 1px solid #ccc; border-radius: 3px; }

.color-inputs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 5px; font-size: 0.85rem; }
.color-inputs-grid .row { gap: 5px; }
.color-inputs-grid label { min-width: 25px; flex: 0 0 25px; }
.color-inputs-grid input { width: 60px !important; flex: none !important; }

.tools-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.symmetry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(65px, 1fr)); gap: 5px; }

button { padding: 8px; border-radius: 4px; border: none; cursor: pointer; background: #ddd; font-weight: bold; font-size: 0.85rem; }
button.active { background: var(--accent-color); color: white; }
.export-btn { background: #27ae60; color: white; margin-top: 5px; width: 100%; }

#sidebarToggle {
    position: fixed; left: 350px; top: 10px; width: 35px; height: 35px;
    background: var(--accent-color); color: white; border: none; border-radius: 4px;
    cursor: pointer; z-index: 100; transition: left 0.3s ease;
}
body.sidebar-collapsed #sidebarToggle { left: 5px; }

canvas {
    display: block; width: 100%; height: 100%;
    background-image: linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%, #eee 100%),
                      linear-gradient(45deg, #eee 25%, white 25%, white 75%, #eee 75%, #eee 100%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
}
#canvas {
    cursor: crosshair;
    /* Touch: verhindert, dass der Browser Zeichen-Gesten als Scrollen/Zoomen abfängt
       (sonst bricht der pointerdown/-move-Stream mit pointercancel ab -> kein Zeichnen auf Touch). */
    touch-action: none;
    -ms-touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
}
body.tool-eraser #canvas { cursor: none; }

/* GALERIE */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.gallery-card {
    background: white;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.gallery-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-color: var(--accent-color);
}

.gallery-card canvas {
    width: 100%;
    height: auto;
    display: block;
    background: #ecf0f1;
    cursor: pointer;
}

.gallery-card-info {
    padding: 5px 8px;
    border-top: 1px solid #eee;
}

.gallery-card-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #2c3e50;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-card-meta {
    font-size: 0.65rem;
    color: #95a5a6;
}

.gallery-loading {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    font-size: 0.9rem;
}

/* EBENEN / LAYERS */
.layer-toolbar { display: flex; gap: 4px; margin-bottom: 8px; }
.layer-toolbar button { flex: 1; padding: 5px; font-size: 0.85rem; }

.layer-list { display: flex; flex-direction: column; gap: 2px; }

.layer-item {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 8px; border-radius: 4px;
    background: #f8f8f8; border: 2px solid transparent;
    cursor: grab; font-size: 0.85rem; user-select: none;
}
.layer-item:active { cursor: grabbing; }
.layer-item.active { border-color: var(--accent-color); background: #e8f4fd; }
.layer-item.locked { opacity: 0.6; }

.layer-visibility, .layer-lock {
    background: none; border: none; cursor: pointer;
    font-size: 0.9rem; padding: 2px; min-width: 24px;
}
.layer-thumb {
    width: 40px; height: 30px; border-radius: 3px;
    border: 1px solid #ccc; flex-shrink: 0; image-rendering: pixelated;
}
.layer-name {
    flex: 1; min-width: 0; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; cursor: text;
}
.layer-name-edit {
    flex: 1; min-width: 0; padding: 1px 3px; border: 1px solid var(--accent-color);
    border-radius: 2px; font-size: 0.85rem; outline: none;
}
.layer-opacity { width: 50px; }

.layer-drag-ghost {
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); border-radius: 4px;
}
.layer-drag-placeholder {
    background: rgba(52, 152, 219, 0.15); border: 2px dashed var(--accent-color);
    border-radius: 4px; margin: 1px 0;
}
/* HISTORIE / ITEM LIST */
.history-container { display: flex; gap: 6px; max-height: 300px; overflow-y: auto; overflow-x: hidden; }
.history-slider-col { display: flex; flex-direction: column; align-items: center; min-width: 24px; }
.history-slider-col input[type="range"] {
    writing-mode: vertical-lr;
    -webkit-appearance: slider-vertical;
    appearance: slider-vertical;
    flex: 1; width: 20px; min-height: 30px; cursor: pointer;
}
.history-pos { font-size: 0.7rem; color: #888; white-space: nowrap; text-align: center; margin-top: 4px; }

.item-list { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 30px; min-width: 0; }

.item-entry {
    display: flex; align-items: center; gap: 5px;
    padding: 4px 6px; border-radius: 4px;
    background: #f8f8f8; border: 2px solid transparent;
    cursor: grab; font-size: 0.78rem; user-select: none;
    transition: border-color 0.15s;
    min-height: 28px; box-sizing: border-box;
    overflow: hidden;
}
.item-entry:active { cursor: grabbing; }
.item-entry:hover { background: #eef5fc; }
.item-entry.current { border-color: var(--accent-color); background: #e8f4fd; }
.item-entry.highlighted { border-color: #FF00FF !important; background: #fce4ff !important; }
.item-entry.selected { border-color: #00CCCC; background: #e0fafa; }
.item-entry.future { opacity: 0.35; }
.item-num { font-size: 0.7rem; color: #999; min-width: 24px; text-align: right; flex-shrink: 0; }

.item-color {
    width: 14px; height: 14px; border-radius: 3px;
    border: 1px solid #ccc; flex-shrink: 0;
}
.item-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-layer-select {
    font-size: 0.7rem; padding: 1px 2px; border: 1px solid #ccc;
    border-radius: 3px; background: #f0f0f0; max-width: 70px;
    cursor: pointer;
}
.item-delete {
    background: none; border: none; cursor: pointer;
    font-size: 0.85rem; padding: 2px; min-width: 20px; opacity: 0.4;
    color: inherit;
}
.item-delete:hover { opacity: 1; color: #e74c3c; }

.item-drag-ghost { box-shadow: 0 4px 12px rgba(0,0,0,0.3); border-radius: 4px; }
.item-drag-placeholder {
    background: rgba(52, 152, 219, 0.15); border: 2px dashed var(--accent-color);
    border-radius: 4px; height: 28px; margin: 1px 0;
}

.item-list-empty {
    text-align: center; color: #aaa; font-size: 0.8rem; padding: 10px;
    font-style: italic;
}

.layer-template-remove {
    background: none; border: none; cursor: pointer;
    font-size: 0.7rem; padding: 2px; min-width: 20px; opacity: 0.6;
}
.layer-template-remove:hover { opacity: 1; }

/* "Exportieren"-Schnellzugriff (springt zum Export-Bereich) */
#scrollExportBtn { display: flex; align-items: center; justify-content: center; gap: 6px; }

/* INFO-/BEGLEITSEITEN-MENÜ (neben der Sprachauswahl) */
/* Button dezent/unscheinbar: klein, gedaempfte Farbe, kein Hintergrund; erst bei Hover/Fokus hervorheben. */
.info-menu-btn {
    padding: 2px 5px; border: none; background: transparent;
    color: #94a3b8; font-size: 1.05rem; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
    border-radius: 4px; transition: color 0.15s, background 0.15s;
}
.info-menu-btn:hover, .info-menu-btn:focus-visible, .info-menu-btn[aria-expanded="true"] {
    color: #7c3aed; background: rgba(124,58,237,0.10); outline: none;
}
/* Menue haengt an <body> und wird per JS (getBoundingClientRect) positioniert -> position:fixed,
   oberste Ebene. Dadurch kein Klippen durch Overflow/Stacking der Seitenleiste (Desktop-Bug-Fix). */
.info-menu {
    position: fixed; top: 0; left: 0;
    min-width: 190px; max-height: 80vh; overflow-y: auto;
    background: #fff; border: 1px solid #ddd;
    border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.22);
    padding: 6px; z-index: 9000; display: flex; flex-direction: column;
}
.info-menu[hidden] { display: none; }
.info-menu a {
    display: block; padding: 8px 10px; border-radius: 5px;
    color: #2c3e50; text-decoration: none; font-size: 0.9rem; font-weight: 500;
    white-space: nowrap;
}
.info-menu a:hover, .info-menu a:focus { background: rgba(124,58,237,0.12); color: #7c3aed; outline: none; }
.info-menu-sep { height: 1px; background: #eee; margin: 5px 4px; }

/* ============================================================
   BOTTOM-SHEET (nur Handy / schmale Viewports)
   Desktop bleibt UNVERAENDERT: alle Layout-Regeln stehen in der Media-Query.
   ============================================================ */

/* Griff auf dem Desktop ausgeblendet */
#sheetHandle { display: none; }

@media (max-width: 640px) {
    /* Seitenleiste wird zu einem von unten einfahrenden Sheet (wie im GIS) */
    #sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        width: 100% !important;
        min-width: 0;
        max-width: none;
        height: auto;
        max-height: 72vh;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.28);
        /* eingeklappt: nur der Griff (46px) schaut heraus */
        transform: translateY(calc(100% - 46px));
        transition: transform 0.3s ease;
        z-index: 1500;
    }
    #sidebar.sheet-expanded { transform: translateY(0); }
    /* Desktop-Collapse (translateX) auf dem Handy neutralisieren */
    #sidebar.collapsed { transform: translateY(100%); opacity: 1; }

    /* Griff sichtbar und greifbar */
    #sheetHandle {
        display: flex; align-items: center; justify-content: center;
        height: 46px; min-height: 46px; flex: 0 0 46px;
        cursor: grab; touch-action: none; user-select: none;
        background: var(--panel-bg);
        border-radius: 16px 16px 0 0;
    }
    #sheetHandle:active { cursor: grabbing; }
    #sheetHandle .sheet-grip {
        width: 44px; height: 5px; border-radius: 3px;
        background: #b0bec5;
    }

    /* auf dem Handy nicht benoetigte Desktop-Bedienelemente */
    #resizeHandle { display: none; }
    #sidebarToggle { display: none; }

    /* Inhalt scrollt innerhalb des Sheets unter dem Griff */
    #sidebarContent {
        max-height: calc(72vh - 46px);
        overscroll-behavior: contain;
    }
}

/* ============================================================
   ZAHLEN-STEPPER (kleine Auf/Ab-Buttons an jedem Zahlenfeld, touch-tauglich)
   ============================================================ */
.num-field { display: inline-flex; align-items: stretch; gap: 2px; vertical-align: middle; }
/* native Spinner ausblenden -> nur die eigenen Stepper werden genutzt */
.num-field input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.num-field input[type="number"]::-webkit-outer-spin-button,
.num-field input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num-steppers { display: flex; flex-direction: column; width: 18px; flex: 0 0 18px; gap: 2px; }
.num-step {
    flex: 1; padding: 0; margin: 0; min-height: 0; min-width: 0;
    border: 1px solid #cbd5e1; background: #f1f5f9; color: #475569;
    border-radius: 3px; font-size: 0.5rem; font-weight: normal; line-height: 1;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    touch-action: none; -webkit-user-select: none; user-select: none;
}
.num-step:hover { background: var(--accent-color); color: #fff; border-color: var(--accent-color); }
.num-step:active { background: #2176bd; border-color: #2176bd; color: #fff; }

/* ============================================================
   P4: schwebender Zwei-Finger-Schnellumschalter (nur wenn Feature aktiv)
   ============================================================ */
.two-finger-fab {
    position: fixed; top: 12px; right: 12px; z-index: 1400;
    min-width: 44px; height: 40px; padding: 0 12px;
    border: none; border-radius: 20px;
    background: rgba(30,41,59,0.55); color: #fff;
    font-size: 1.1rem; line-height: 1; font-weight: bold;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
    opacity: 0.85; transition: background 0.15s, opacity 0.15s;
}
.two-finger-fab:hover { opacity: 1; }
.two-finger-fab.active { background: var(--accent-color); opacity: 1; }

/* ============================================================
   P5: Doppeltipp-Ecken fuer Undo/Redo (nur Touch)
   ============================================================ */
.corner-tap-zone { display: none; }

/* ============================================================
   P3: Touch-abhaengige UI (Hinweise/Schalter nach Pointer-Typ)
   ============================================================ */
#twoFingerRow { display: none; }             /* Maus/Desktop: Zwei-Finger-Schalter ausblenden */

@media (pointer: coarse) {
    /* Undo/Redo-Trefferzonen erscheinen knapp ueber dem Bottom-Sheet-Griff */
    .corner-tap-zone {
        display: flex; align-items: center; justify-content: center;
        position: fixed; bottom: 54px; width: 60px; height: 60px;
        z-index: 1350; opacity: 0.16; color: #1e293b;
        pointer-events: auto; touch-action: none;
        -webkit-user-select: none; user-select: none; transition: opacity 0.15s;
    }
    .corner-tap-zone.undo-zone { left: 4px; }
    .corner-tap-zone.redo-zone { right: 4px; }
    .corner-tap-zone .corner-tap-icon {
        width: 42px; height: 42px; font-size: 1.5rem;
        display: flex; align-items: center; justify-content: center;
        background: rgba(255,255,255,0.6); border-radius: 50%;
        box-shadow: 0 1px 4px rgba(0,0,0,0.18);
    }
    .corner-tap-zone.flash { opacity: 0.5; }

    /* Touch: Zwei-Finger-Schalter zeigen, Maus-/Strg-Zoomhinweis ausblenden */
    #twoFingerRow { display: flex; }
    #zoomInfo { display: none; }
}