/* Body und HTML auf Bildschirmbreite begrenzen */
body, html {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* Body-Content nach unten verschieben wegen fixed Header */
body {
    padding-top: 64px !important; /* Header-Höhe */
}

/* Header fixed machen - funktioniert auch mit overflow-x hidden */
nav {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 100 !important;
    background: white !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
}

.periodensystem {
    display: grid;
    grid-template-columns: repeat(18, minmax(42px, 1fr));
    gap: 8px;
    overflow: visible;
    position: relative;
    z-index: 1;
    max-width: 100vw;
    box-sizing: border-box;
}
.ps-cell {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 8px;
    height: 80px;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    position: relative;
    overflow: visible;
    transition: z-index 0s;
    cursor: pointer;
}
/* Hover-Verhalten entfernt - nur noch Click für Desktop */
.ps-symbol { font-weight: 800; font-size: 18px; line-height: 1; }
.ps-atomic { font-size: 11px; color: #6b7280; }
.ps-name { font-size: 11px; color: #374151; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Click-Popover (modernes Info-Panel) - fixed position für overflow-x hidden */
.ps-popover {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.85);
    width: 320px;
    min-height: 380px;
    border: none;
    border-radius: 24px;
    padding: 0;
    display: none;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    background: white;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    z-index: 9999999;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}
/* Click-Popover anzeigen - wird von Desktop-Media-Query überschrieben */
.ps-popover .ps-atomic {
    position: absolute;
    top: 16px;
    left: 20px;
    font-size: 14px;
    font-weight: 700;
    color: rgba(255,255,255,0.8);
    background: rgba(0,0,0,0.2);
    padding: 4px 8px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
}
.ps-popover .ps-symbol-lg { 
    font-weight: 900; 
    font-size: 64px; 
    line-height: 1; 
    margin: 60px 0 16px 0;
    text-align: center;
    color: inherit;
    text-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.ps-popover .ps-name-lg { 
    font-size: 20px; 
    color: #1a1a1a; 
    text-align: center; 
    font-weight: 700;
    margin-bottom: 24px;
    letter-spacing: -0.5px;
}
.ps-meta { 
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    padding: 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.2);
}
.ps-meta > div {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ps-meta .label { 
    color: #6b7280; 
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ps-meta .value {
    font-weight: 700;
    font-size: 14px;
    color: #1a1a1a;
}
/* Moderne, coole Farbpalette für Elementkategorien */
.ps-cat-metal { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
    color: white;
}
.ps-cat-metal .ps-popover { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}
.ps-cat-metal .ps-popover .ps-name-lg,
.ps-cat-metal .ps-popover .ps-meta .value,
.ps-cat-metal .ps-popover .ps-symbol-lg {
    color: white;
}

.ps-cat-nonmetal { 
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); 
    color: white;
}
.ps-cat-nonmetal .ps-popover { 
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}
.ps-cat-nonmetal .ps-popover .ps-name-lg,
.ps-cat-nonmetal .ps-popover .ps-meta .value,
.ps-cat-nonmetal .ps-popover .ps-symbol-lg {
    color: white;
}

.ps-cat-metalloid { 
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); 
    color: white;
}
.ps-cat-metalloid .ps-popover { 
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}
.ps-cat-metalloid .ps-popover .ps-name-lg,
.ps-cat-metalloid .ps-popover .ps-meta .value,
.ps-cat-metalloid .ps-popover .ps-symbol-lg {
    color: white;
}

.ps-cat-alkali { 
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); 
    color: white;
}
.ps-cat-alkali .ps-popover { 
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    color: white;
}
.ps-cat-alkali .ps-popover .ps-name-lg,
.ps-cat-alkali .ps-popover .ps-meta .value,
.ps-cat-alkali .ps-popover .ps-symbol-lg {
    color: white;
}

.ps-cat-alkaline { 
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%); 
    color: #333;
}
.ps-cat-alkaline .ps-popover { 
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #333;
}
.ps-cat-alkaline .ps-popover .ps-name-lg,
.ps-cat-alkaline .ps-popover .ps-meta .value,
.ps-cat-alkaline .ps-popover .ps-symbol-lg {
    color: #333;
}

.ps-cat-transition { 
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%); 
    color: #333;
}
.ps-cat-transition .ps-popover { 
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
    color: #333;
}
.ps-cat-transition .ps-popover .ps-name-lg,
.ps-cat-transition .ps-popover .ps-meta .value,
.ps-cat-transition .ps-popover .ps-symbol-lg {
    color: #333;
}

.ps-cat-post { 
    background: linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%); 
    color: #333;
}
.ps-cat-post .ps-popover { 
    background: linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%);
    color: #333;
}
.ps-cat-post .ps-popover .ps-name-lg,
.ps-cat-post .ps-popover .ps-meta .value,
.ps-cat-post .ps-popover .ps-symbol-lg {
    color: #333;
}

.ps-cat-halogen { 
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%); 
    color: #333;
}
.ps-cat-halogen .ps-popover { 
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    color: #333;
}
.ps-cat-halogen .ps-popover .ps-name-lg,
.ps-cat-halogen .ps-popover .ps-meta .value,
.ps-cat-halogen .ps-popover .ps-symbol-lg {
    color: #333;
}

.ps-cat-noble { 
    background: linear-gradient(135deg, #d299c2 0%, #fef9d7 100%); 
    color: #333;
}
.ps-cat-noble .ps-popover { 
    background: linear-gradient(135deg, #d299c2 0%, #fef9d7 100%);
    color: #333;
}
.ps-cat-noble .ps-popover .ps-name-lg,
.ps-cat-noble .ps-popover .ps-meta .value,
.ps-cat-noble .ps-popover .ps-symbol-lg {
    color: #333;
}

.ps-cat-lanthanoid { 
    background: linear-gradient(135deg, #89f7fe 0%, #66a6ff 100%); 
    color: white;
}
.ps-cat-lanthanoid .ps-popover { 
    background: linear-gradient(135deg, #89f7fe 0%, #66a6ff 100%);
    color: white;
}
.ps-cat-lanthanoid .ps-popover .ps-name-lg,
.ps-cat-lanthanoid .ps-popover .ps-meta .value,
.ps-cat-lanthanoid .ps-popover .ps-symbol-lg {
    color: white;
}

.ps-cat-actinoid { 
    background: linear-gradient(135deg, #fdbb2d 0%, #22c1c3 100%); 
    color: white;
}
.ps-cat-actinoid .ps-popover { 
    background: linear-gradient(135deg, #fdbb2d 0%, #22c1c3 100%);
    color: white;
}
.ps-cat-actinoid .ps-popover .ps-name-lg,
.ps-cat-actinoid .ps-popover .ps-meta .value,
.ps-cat-actinoid .ps-popover .ps-symbol-lg {
    color: white;
}
.ps-gap { visibility: hidden; }

/* Mobile Swipe Container */
.periodensystem-container {
    position: relative;
    z-index: 1;
    overflow: visible;
    max-width: 100vw;
    box-sizing: border-box;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .periodensystem-container {
        overflow-x: auto;
        overflow-y: hidden; /* Kein vertikales Scrollen */
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding: 10px;
        margin: -32px;
        height: auto; /* Automatische Höhe */
    }
    .periodensystem-container::-webkit-scrollbar {
        display: none;
    }
    
    /* Gesamte Tabelle (Haupttabelle + f-Block) in einem Container */
    .periodensystem {
        width: max-content !important;
        gap: 4px !important; /* Kleinere Lücken zwischen Spalten */
        grid-template-columns: repeat(18, 60px) !important; /* Feste Breite für jede Spalte */
        max-width: calc(18 * 60px + 17 * 4px) !important; /* Exakte Breite: 18 Spalten + 17 Lücken */
        box-sizing: border-box;
    }
    
    .periodensystem-f {
        margin-top: 16px;
        width: max-content !important;
        gap: 4px !important; /* Kleinere Lücken zwischen Spalten */
        max-width: calc(18 * 60px + 17 * 4px) !important; /* Exakte Breite: 18 Spalten + 17 Lücken */
        box-sizing: border-box;
    }
    
    .ps-f-row {
        grid-template-columns: repeat(18, 60px) !important; /* Feste Breite für jede Spalte */
        gap: 4px !important;
    }
    
    .ps-cell {
        width: 60px; /* Breitere Zellen */
        height: 70px;
        padding: 6px;
        min-width: 60px; /* Mindestbreite sicherstellen */
        transition: all 0.3s ease; /* Sanfte Übergänge */
    }
    
    /* Hervorhebung des angeklickten Elements */
    .ps-cell.active {
        transform: scale(1.1); /* 10% größer */
        z-index: 10;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
        border: 2px solid #3b82f6; /* Blauer Rand */
    }
    
    .ps-symbol {
        font-size: 16px;
    }
    
    .ps-atomic {
        font-size: 10px;
    }
    
    .ps-name {
        font-size: 9px;
    }
    
    /* Standard-Popover für mobile deaktivieren */
    .ps-popover {
        display: none !important;
    }
    
    /* Overlay für mobile Popover */
    .ps-cell.active::before {
        content: "";
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.8);
        z-index: 99999998;
        pointer-events: auto;
    }
    
    /* Zusätzliches Overlay-Element für bessere Touch-Interaktion - nur mobile */
    .ps-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.8);
        z-index: 99999998;
        pointer-events: auto;
        display: none;
    }
    
    .ps-cell.active ~ .ps-overlay {
        display: block;
    }
}

/* Desktop: Overlay verstecken */
@media (min-width: 769px) {
    .ps-overlay {
        display: none !important;
    }
}
    
    /* Schließen-Button */
    .ps-cell.active .ps-popover::after {
        content: "×";
        position: absolute;
        top: 15px;
        right: 20px;
        font-size: 28px;
        font-weight: bold;
        color: rgba(255, 255, 255, 0.9);
        cursor: pointer;
        z-index: 99999999;
        width: 35px;
        height: 35px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        background: rgba(0, 0, 0, 0.4);
        border: 2px solid rgba(255, 255, 255, 0.3);
    }
    
    /* Popover-Inhalte für mobile */
    .ps-cell.active .ps-popover .ps-symbol-lg {
        font-size: 60px;
        margin: 50px 0 20px 0;
    }
    
    .ps-cell.active .ps-popover .ps-name-lg {
        font-size: 20px;
        margin-bottom: 30px;
    }
    
    .ps-cell.active .ps-popover .ps-meta {
        padding: 20px;
        gap: 15px;
    }
    
    .ps-cell.active .ps-popover .ps-meta .label {
        font-size: 12px;
    }
    
    .ps-cell.active .ps-popover .ps-meta .value {
        font-size: 14px;
    }
}

/* f-Block Darstellung */
.periodensystem { overflow: visible; }
.periodensystem-f { 
    margin-top: 16px; 
    display: grid; 
    gap: 6px; 
    overflow: visible; 
    position: relative;
    z-index: 1;
}
.ps-f-row { display: grid; grid-template-columns: repeat(18, minmax(42px, 1fr)); gap: 8px; }

