.wpchords-wrapper {
    margin: 20px 0;
    contain: layout style;
}

.wpchords-controls {
    margin-bottom: 15px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 15px;
    flex-wrap: nowrap;
    border: 1px solid #e9ecef;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.accordi-btn {
    padding: 8px 16px;
    background: #4a6fa5;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.2s ease;
    min-width: auto;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.accordi-btn:hover {
    background: #3a5a80;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.accordi-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.notation-toggle {
    width: 110px;
}

.transpose-down,
.transpose-up,
.font-decrease,
.font-increase {
    width: 45px;
}

.transpose-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    flex-shrink: 0;
    height: 40px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.current-key {
    font-weight: bold;
    font-size: 17px;
    color: #d54e21;
    min-width: 35px;
    text-align: center;
    padding: 3px 8px;
    flex-shrink: 0;
    background: rgba(213, 78, 33, 0.1);
    border-radius: 4px;
    transition: all 0.3s ease;
}

.current-key.transposed {
    color: #2271b1;
    background: rgba(34, 113, 177, 0.1);
}

.font-controls {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    height: 40px;
}

.wpchords-container {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    font-size: 16px;
    position: relative;
    contain: layout style;
    transition: font-size 0.3s ease;
}

.song-line {
    position: relative;
    margin-bottom: 15px;
    min-height: 0;
    contain: layout;
}

.song-line.empty-line {
    margin-bottom: 8px;
    min-height: 0;
    height: auto;
}

.chord-line {
    position: relative;
    height: 25px;
    margin-bottom: 2px;
    contain: layout;
}

.text-line {
    min-height: 24px;
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 1em;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    letter-spacing: 0.02em;
    contain: layout;
}

.text-line.empty-line {
    min-height: 8px;
    line-height: 0.7;
    font-size: 0.6em;
    opacity: 0.6;
    height: auto;
}

.chord {
    position: absolute;
    color: #d54e21;
    font-weight: bold;
    font-size: 0.85em;
    background: rgba(255, 255, 255, 0.98);
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid #ffd6c8;
    z-index: 10;
    white-space: nowrap;
    top: -3px;
    pointer-events: none;
    text-align: center;
    transform: translateX(-50%);
    will-change: transform, opacity;
    backface-visibility: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
    contain: layout;
}

.chord-marker {
    display: none;
    visibility: hidden;
    width: 0;
    height: 0;
    overflow: hidden;
    contain: strict;
}

.chords-only-line {
    margin-bottom: 10px;
    contain: layout;
}

.chords-only-line .chord-line {
    height: 30px;
    display: block;
    text-align: center;
}

.chords-only-line .chord {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
}

.chords-inline {
    height: auto !important;
    text-align: center;
    margin-bottom: 5px;
    position: relative;
    display: block;
    white-space: normal;
    contain: layout;
}

.chords-inline .chord {
    position: relative !important;
    left: auto !important;
    transform: none !important;
    display: inline-block !important;
    margin: 0 10px !important;
    top: 0 !important;
}

.chord-inline {
    display: inline;
    color: #d54e21;
    font-weight: bold;
    font-size: 0.85em;
    background: rgba(255, 255, 255, 0.98);
    padding: 3px 8px;
    margin: 0 2px;
    border-radius: 4px;
    border: 1px solid #ffd6c8;
    white-space: nowrap;
    vertical-align: middle;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.wpchords-container.loading {
    opacity: 0.7;
    pointer-events: none;
}

.wpchords-container.loading .chord {
    opacity: 0.8;
    filter: blur(1px);
}

/* Ottimizzazioni performance */
.wpchords-wrapper {
    transform: translateZ(0);
}

.chord {
    transform: translateZ(0) translateX(-50%);
}

.measure-container,
.text-measure-container,
.fake-text-container {
    position: absolute !important;
    visibility: hidden !important;
    top: -9999px !important;
    left: -9999px !important;
    pointer-events: none !important;
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    .wpchords-wrapper {
        margin: 15px 0;
    }
    
    .wpchords-controls {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 10px;
        gap: 12px;
        justify-content: flex-start;
        margin-bottom: 12px;
    }
    
    .wpchords-controls::-webkit-scrollbar {
        display: none;
    }
    
    .wpchords-controls {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    
    .accordi-btn {
        padding: 7px 12px;
        font-size: 14px;
        height: 36px;
        border-radius: 5px;
    }
    
    .notation-toggle {
        width: 100px;
    }
    
    .transpose-down,
    .transpose-up,
    .font-decrease,
    .font-increase {
        width: 40px;
    }
    
    .current-key {
        font-size: 16px;
        min-width: 32px;
        padding: 2px 6px;
    }
    
    .transpose-controls {
        gap: 8px;
        padding: 5px 10px;
        height: 36px;
    }
    
    .font-controls {
        gap: 8px;
        height: 36px;
    }
    
    .wpchords-container {
        font-size: 15px;
    }
    
    .song-line {
        margin-bottom: 12px;
    }
    
    .song-line.empty-line {
        margin-bottom: 6px;
    }
    
    .chord-line {
        height: 22px;
    }
    
    .text-line {
        font-size: 0.95em;
        min-height: 22px;
    }
    
    .text-line.empty-line {
        min-height: 6px;
        font-size: 0.55em;
        line-height: 0.6;
    }
    
    .chord {
        font-size: 0.8em;
        padding: 2px 6px;
    }
    
    .chords-only-line {
        margin-bottom: 8px;
    }
    
    .chords-only-line .chord-line {
        height: 25px;
    }
}

/* Schermi molto piccoli */
@media (max-width: 480px) {
    .wpchords-controls {
        gap: 8px;
        padding: 8px;
    }
    
    .accordi-btn {
        padding: 6px 10px;
        font-size: 13px;
        height: 34px;
    }
    
    .notation-toggle {
        width: 90px;
    }
    
    .transpose-down,
    .transpose-up,
    .font-decrease,
    .font-increase {
        width: 36px;
    }
    
    .current-key {
        font-size: 15px;
        min-width: 30px;
        padding: 2px 5px;
    }
    
    .transpose-controls {
        gap: 6px;
        padding: 4px 8px;
        height: 34px;
    }
    
    .font-controls {
        gap: 6px;
        height: 34px;
    }
    
    .wpchords-container {
        font-size: 14px;
    }
    
    .song-line {
        margin-bottom: 10px;
    }
    
    .song-line.empty-line {
        margin-bottom: 5px;
    }
    
    .text-line.empty-line {
        min-height: 5px;
        font-size: 0.5em;
    }
    
    .chord {
        padding: 2px 5px;
        font-size: 0.75em;
    }
    
    .chords-only-line .chord-line {
        height: 22px;
    }
}

/* Animazioni smooth */
.wpchords-container {
    transition: font-size 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chord {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.accordi-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.current-key {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Supporto per high-DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .chord {
        border-width: 0.5px;
        -webkit-font-smoothing: antialiased;
        text-rendering: optimizeLegibility;
    }
}

/* Modalità scura (opzionale) */
@media (prefers-color-scheme: dark) {
    .wpchords-controls {
        background: #2d3748;
        border-color: #4a5568;
    }
    
    .accordi-btn {
        background: #4a5568;
    }
    
    .accordi-btn:hover {
        background: #718096;
    }
    
    .transpose-controls {
        background: #1a202c;
        border-color: #4a5568;
    }
    
    .chord {
        background: rgba(26, 32, 44, 0.95);
        border-color: #4a5568;
        color: #fbd38d;
        box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    }
    
    .text-line {
        color: #e2e8f0;
    }
}

/* Ottimizzazioni per stampa */
@media print {
    .wpchords-controls {
        display: none;
    }
    
    .chord {
        background: transparent !important;
        border: 1px solid #000 !important;
        color: #000 !important;
        box-shadow: none !important;
    }
    
    .wpchords-container {
        font-size: 12pt !important;
    }
    
    .text-line.empty-line {
        opacity: 1;
        font-size: 8pt !important;
    }
}

/* Classi di utilità per debug */
.debug-mode .chord {
    background: rgba(255, 255, 0, 0.3);
    border: 1px dashed red;
}

.debug-mode .measure-container,
.debug-mode .text-measure-container,
.debug-mode .fake-text-container {
    visibility: visible !important;
    background: yellow;
    color: red;
    opacity: 0.7;
    z-index: 9999;
}