/* 
 * PraiseChords - Chord Display Styles
 * Handles all chord-related styling and display modes
 */

/* === SECTION HEADERS === */

.section-header {
    font-weight: 500;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary, #9ca3af);
    opacity: 0.8;
    margin-bottom: 0.5rem;
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.03);
}

.section-header:first-child {
    margin-top: 0;
}

/* Section type specific colors */
.section-verse {
    color: var(--color-primary);
    background: rgba(82, 56, 47, 0.05);
}

.section-chorus {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.08);
    font-weight: 600;
}

.section-bridge {
    color: #8b5cf6;
    background: rgba(139, 92, 246, 0.08);
}

.section-intro,
.section-outro {
    color: #6b7280;
    background: rgba(107, 114, 128, 0.08);
}

.section-pre-chorus {
    color: #10b981;
    background: rgba(16, 185, 129, 0.08);
}

.section-interlude {
    color: #ec4899;
    background: rgba(236, 72, 153, 0.08);
}

/* Dark theme adjustments */
[data-theme="dark"] .section-header {
    color: var(--color-text-secondary);
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .section-chorus {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.1);
}

[data-theme="dark"] .section-bridge {
    color: #a78bfa;
    background: rgba(167, 139, 250, 0.1);
}

[data-theme="dark"] .section-pre-chorus {
    color: #34d399;
    background: rgba(52, 211, 153, 0.1);
}

[data-theme="dark"] .section-interlude {
    color: #f472b6;
    background: rgba(244, 114, 182, 0.1);
}

.lyrics-section {
    margin-bottom: 1.5rem;
    padding: 0 0 0 0.75rem;
    position: relative;
    border-left: 2px solid transparent;
}

/* Subtle accent on left border for different section types */
.section-verse+.lyrics-section {
    border-left-color: rgba(82, 56, 47, 0.15);
}

.section-chorus+.lyrics-section {
    border-left-color: rgba(245, 158, 11, 0.25);
}

.section-bridge+.lyrics-section {
    border-left-color: rgba(139, 92, 246, 0.25);
}

.section-pre-chorus+.lyrics-section {
    border-left-color: rgba(16, 185, 129, 0.25);
}

.section-interlude+.lyrics-section {
    border-left-color: rgba(236, 72, 153, 0.25);
}

/* Dark theme for lyrics section */
[data-theme="dark"] .lyrics-section {
    border-left-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .section-verse+.lyrics-section {
    border-left-color: rgba(122, 86, 73, 0.2);
}

[data-theme="dark"] .section-chorus+.lyrics-section {
    border-left-color: rgba(251, 191, 36, 0.3);
}

[data-theme="dark"] .section-bridge+.lyrics-section {
    border-left-color: rgba(167, 139, 250, 0.3);
}

[data-theme="dark"] .section-pre-chorus+.lyrics-section {
    border-left-color: rgba(52, 211, 153, 0.3);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .section-header {
        font-size: 0.65rem;
        padding: 0.1rem 0.4rem;
    }
}

/* === CHORD ELEMENTS === */

.chord {
    color: var(--color-chord);
    font-weight: bold;
    cursor: pointer;
    position: relative;
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    margin: 0 1px;
    transition: all 0.2s ease;
    display: inline-block;
}

.chord:hover {
    background-color: transparent;
    color: var(--color-primary);
    transform: none;
}

/* Dark theme chord colors */
[data-theme="dark"] .chord {
    color: var(--color-chord);
    background-color: transparent;
}

[data-theme="dark"] .chord:hover {
    background-color: transparent;
    color: #60a5fa;
}

/* === STRUCTURED LYRICS FORMAT === */

/* Chords Above Lyrics Mode */
.lyrics-line-wrapper {
    position: relative;
}

/* Add padding only to lines with chords */
.lyrics-line-wrapper.has-chords {
    padding-top: 1.5em;
    margin-bottom: 0.1rem;
    margin-top: 0;
}

.lyrics-line-wrapper:not(.has-chords) {
    margin: 0.1rem 0;
}

.chords-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 1.5em;
    font-family: var(--font-family-monospace);
    color: var(--color-chord);
    font-weight: bold;
    line-height: 1;
    white-space: pre;
    letter-spacing: 0;
    user-select: none;
    /* Prevent chord line from being selected when copying */
    font-size: inherit;
    /* Inherit font size from parent container */
}

.chords-line .chord {
    background-color: transparent;
    padding: 0;
    margin: 0;
    border-radius: 0;
    position: absolute;
    cursor: pointer;
    transition: color 0.2s ease;
    font-size: inherit;
    /* Ensure chord inherits the font size */
}

.chords-line .chord:hover {
    color: var(--color-primary);
    background-color: transparent;
    transform: none;
}

.lyrics-line-wrapper .lyrics-line {
    font-family: var(--font-family-monospace);
    white-space: pre-wrap;
    line-height: 1.4;
    margin: 0;
}

/* Standalone lyrics line (no chords) */
.song-content>.lyrics-line {
    font-family: var(--font-family-monospace);
    white-space: pre-wrap;
    line-height: 1.4;
    margin: 0.15rem 0;
}

/* Inline Chords Mode */
.lyrics-line .chord {
    display: inline;
}

/* === CHORD DISPLAY STYLE SETTINGS === */

/* Above Mode - Chords displayed on separate line above lyrics */
[data-chord-style="above"] .lyrics-line-wrapper {
    display: block;
}

/* Inline Mode - Chords inline with text */
[data-chord-style="inline"] .chord {
    display: inline;
    margin: 0 1px;
}

/* Diagrams Mode - Show chord with underline for diagram hover */
[data-chord-style="diagrams"] .chord {
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-color: var(--color-chord);
}

/* === CHORD DIAGRAM TOOLTIP === */

.chord-diagram {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 4px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
    z-index: 1001;
    min-width: 120px;
    max-width: 150px;
    animation: chordDiagramFadeIn 0.2s ease-out;
    pointer-events: none;
    line-height: 1;
    font-size: 1rem;
    margin: 0;
    box-sizing: border-box;
}

@keyframes chordDiagramFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Dark theme support */
[data-theme="dark"] .chord-diagram {
    background: #2a2a2a;
    border-color: #404040;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
}

.chord-diagram * {
    margin: 0;
    padding: 0;
    line-height: 1;
}

.chord-diagram-title {
    font-weight: 700;
    text-align: center;
    margin: 0 0 2px 0;
    padding: 0;
    color: var(--color-primary, #52382f);
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    line-height: 1;
}

[data-theme="dark"] .chord-diagram-title {
    color: #60a5fa;
}

.chord-diagram-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
    gap: 0;
    width: 100%;
    overflow: hidden;
}

.chord-diagram-svg {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: 160px !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
}

.chord-diagram-svg.placeholder {
    opacity: 0.7;
}

/* Loading spinner */
.chord-diagram-loading {
    text-align: center;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.chord-diagram-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #e0e0e0;
    border-top-color: var(--color-primary, #52382f);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-top: 2px;
}

[data-theme="dark"] .chord-diagram-spinner {
    border-color: #404040;
    border-top-color: #60a5fa;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.chord-diagram-footer {
    text-align: center;
    margin-top: 2px;
    padding-top: 2px;
    border-top: 1px solid #f0f0f0;
    font-size: 0.8rem;
    color: #999;
    line-height: 1;
}

.chord-diagram-footer small {
    margin: 0;
    padding: 0;
    line-height: 1;
    display: block;
}

[data-theme="dark"] .chord-diagram-footer {
    border-top-color: #404040;
    color: #888;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .chord-diagram {
        max-width: 130px;
        padding: 4px;
        font-size: 0.9rem;
    }

    .chord-diagram-title {
        font-size: 0.9rem;
    }

    .chord-diagram-svg {
        max-height: 140px;
    }
}

@media (max-width: 480px) {
    .chord-diagram {
        max-width: 110px;
        padding: 4px;
    }

    .chord-diagram-title {
        font-size: 0.85rem;
    }

    .chord-diagram-svg {
        max-height: 120px;
    }
}

.chord-diagram-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 2px;
    font-size: 0.75rem;
}

/* === CHORD FONT VARIATIONS === */

[data-chord-font="monospace"] .chord,
[data-chord-font="monospace"] .chords-line {
    font-family: var(--font-family-monospace);
}

[data-chord-font="serif"] .chord,
[data-chord-font="serif"] .chords-line {
    font-family: var(--font-family-secondary);
}

[data-chord-font="sans-serif"] .chord,
[data-chord-font="sans-serif"] .chords-line {
    font-family: var(--font-family-primary);
}

[data-chord-font="system"] .chord,
[data-chord-font="system"] .chords-line {
    font-family: var(--font-family-primary);
}

/* === LYRICS FONT VARIATIONS === */

[data-lyrics-font="monospace"] .lyrics-line {
    font-family: var(--font-family-monospace);
}

[data-lyrics-font="serif"] .lyrics-line {
    font-family: var(--font-family-secondary);
}

[data-lyrics-font="sans-serif"] .lyrics-line {
    font-family: var(--font-family-primary);
}

[data-lyrics-font="system"] .lyrics-line {
    font-family: var(--font-family-primary);
}

/* === SONG CONTENT CONTAINER === */

.song-content {
    font-family: var(--font-family-primary);
    line-height: 1.4;
    white-space: normal;
    margin: 0;
    padding: 0;
    position: relative;
    padding-left: 0;
    /* Space for side annotations on desktop */
}

/* Add left padding on larger screens for side annotations */
@media (min-width: 769px) {
    .song-content {
        padding-left: 0;
    }
}

/* Override line-height based on line spacing setting */
[data-line-spacing="compact"] .song-content {
    line-height: 1.4;
}

[data-line-spacing="compact"] .lyrics-line-wrapper {
    margin: 0.1rem 0;
}

[data-line-spacing="compact"] .lyrics-line {
    line-height: 1.3;
}

[data-line-spacing="compact"] .song-content>.lyrics-line {
    margin: 0.05rem 0;
}

[data-line-spacing="compact"] .chords-line {
    margin-bottom: 0.02rem;
}

[data-line-spacing="normal"] .lyrics-line-wrapper {
    margin: 0.2rem 0;
}

[data-line-spacing="normal"] .lyrics-line {
    line-height: 1.4;
}

[data-line-spacing="normal"] .song-content>.lyrics-line {
    margin: 0.1rem 0;
}

[data-line-spacing="normal"] .chords-line {
    margin-bottom: 0.05rem;
}

[data-line-spacing="relaxed"] .lyrics-line-wrapper {
    margin: 0.35rem 0;
}

[data-line-spacing="relaxed"] .lyrics-line {
    line-height: 1.6;
}

[data-line-spacing="relaxed"] .song-content>.lyrics-line {
    margin: 0.2rem 0;
}

[data-line-spacing="relaxed"] .chords-line {
    margin-bottom: 0.1rem;
}

/* === VERSE SECTIONS === */

.verse-section {
    margin: 1.5rem 0;
    padding: 1rem;
    border-left: 4px solid var(--bs-primary);
    background-color: rgba(44, 90, 160, 0.05);
}

[data-theme="dark"] .verse-section {
    background-color: rgba(107, 182, 255, 0.1);
}

.verse-label {
    font-weight: bold;
    color: var(--bs-primary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

/* === TRANSPOSITION CONTROLS === */

.transpose-controls {
    background: var(--bs-light);
    padding: 1rem;
    border-radius: 8px;
    margin: 1rem 0;
    border: 1px solid #dee2e6;
}

[data-theme="dark"] .transpose-controls {
    background: var(--color-bg-secondary);
    border-color: var(--color-border);
}

.key-selector {
    display: inline-flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.key-btn {
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--bs-primary);
    background: white;
    color: var(--bs-primary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
}

[data-theme="dark"] .key-btn {
    background: var(--color-bg-tertiary);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.key-btn:hover,
.key-btn.active {
    background: var(--bs-primary);
    color: white;
}

[data-theme="dark"] .key-btn:hover,
[data-theme="dark"] .key-btn.active {
    background: var(--color-primary);
    color: white;
}

/* === CHORD REFERENCE PANEL === */

.chord-reference .chord {
    margin: 0.25rem;
    font-size: 0.9rem;
}

/* === LOADING STATE === */

.song-content.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.song-content.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid var(--color-primary);
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* === PRINT STYLES === */

@media print {
    .transpose-controls {
        display: none !important;
    }

    .song-content {
        font-size: 12pt;
        line-height: 1.5;
    }

    .chord {
        background: none !important;
        color: black !important;
        font-weight: bold;
        padding: 0 !important;
        margin: 0 2px !important;
    }

    .chord-diagram {
        display: none !important;
    }

    .chords-line .chord {
        background: none !important;
    }
}

/* === MOBILE RESPONSIVE === */

@media (max-width: 768px) {
    /* Enable horizontal scroll for lyrics section on mobile */
    .song-content {
        font-size: 0.875rem;
        line-height: 1.6;
        padding: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    }

    /* Prevent line wrapping for lines with chords to keep chord positions correct */
    .lyrics-line-wrapper.has-chords {
        white-space: nowrap;
        min-width: max-content;
    }

    .lyrics-line-wrapper.has-chords .lyrics-line {
        white-space: pre;
    }

    .key-selector {
        justify-content: center;
    }

    .transpose-controls {
        text-align: center;
    }

    .chord {
        font-size: 0.85rem;
        padding: 0;
    }

    .lyrics-line-wrapper {
        margin: 0.5rem 0;
    }
}

/* === ACCESSIBILITY === */

/* High contrast mode enhancements for chords */
[data-high-contrast="true"] .chord {
    border: none;
    font-weight: 700;
}

[data-high-contrast="true"] .chords-line {
    font-weight: 800;
}

/* Reduced motion for chord interactions */
[data-reduce-motion="true"] .chord {
    transition: none;
}

[data-reduce-motion="true"] .chord:hover {
    transform: none;
}

/* Enhanced focus for keyboard navigation */
[data-enhanced-focus="true"] .chord:focus {
    outline: 3px solid var(--bs-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(44, 90, 160, 0.25);
}

[data-enhanced-focus="true"] .key-btn:focus {
    outline: 3px solid var(--bs-primary);
    outline-offset: 3px;
}