/* ===== TYPOGRAPHY SETTINGS SYSTEM ===== */
/* Enterprise-grade typography controls for poem modal */

/* Typography Button in Top Ribbon */
.typography-settings-btn {
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    color: var(--color-text-title);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: 8px;
    position: relative;
}

.typography-settings-btn:hover {
    background: rgba(93, 64, 55, 0.1);
    transform: scale(1.1);
}

.typography-settings-btn:active {
    transform: scale(0.95);
}

.typography-settings-btn[aria-expanded="true"] {
    background: rgba(212, 165, 116, 0.2);
    color: var(--color-accent-primary);
}

/* Typography Settings Panel - Base */
.typography-settings-panel {
    position: fixed;
    z-index: 305;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.typography-settings-panel.active {
    opacity: 1;
    visibility: visible;
}

/* Overlay for mobile */
.typography-settings-overlay {
    display: none;
}

/* Typography Settings Content */
.typography-settings-content {
    background: linear-gradient(180deg, 
        rgba(255, 255, 255, 0.98) 0%, 
        rgba(249, 246, 242, 0.98) 100%);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    border: 1px solid rgba(168, 155, 141, 0.25);
    box-shadow: 0 8px 32px rgba(26, 22, 20, 0.12),
                0 4px 16px rgba(26, 22, 20, 0.08);
    border-radius: 16px;
    overflow: hidden;
}

/* Header */
.typography-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(168, 155, 141, 0.15);
    background: rgba(255, 255, 255, 0.5);
}

.typography-settings-header h3 {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text-title);
    margin: 0;
}

.typography-settings-close {
    width: 36px;
    height: 36px;
    background: rgba(93, 64, 55, 0.05);
    border: 1.5px solid rgba(168, 155, 141, 0.2);
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.typography-settings-close:hover {
    background: rgba(212, 165, 116, 0.15);
    border-color: var(--color-accent-primary);
    color: var(--color-accent-primary);
    transform: scale(1.1) rotate(90deg);
}

.typography-settings-close:active {
    transform: scale(0.95) rotate(90deg);
}

.typography-settings-close svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
}

/* Body */
.typography-settings-body {
    padding: 24px;
}

/* Setting Groups */
.typography-setting-group {
    margin-bottom: 28px;
}

.typography-setting-group:last-child {
    margin-bottom: 0;
}

.typography-setting-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-title);
    margin-bottom: 12px;
}

.font-size-value {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    font-weight: 700;
    color: var(--color-accent-primary);
    background: rgba(212, 165, 116, 0.1);
    padding: 4px 10px;
    border-radius: 6px;
}

/* Font Options */
.typography-font-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.typography-font-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 12px;
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(168, 155, 141, 0.2);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.typography-font-option::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, 
        var(--color-accent-light) 0%, 
        var(--color-accent-primary) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 0;
}

.typography-font-option:hover {
    border-color: var(--color-accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(212, 165, 116, 0.2);
}

.typography-font-option.active {
    border-color: var(--color-accent-primary);
    background: rgba(212, 165, 116, 0.12);
    box-shadow: 0 2px 8px rgba(212, 165, 116, 0.15);
}

.typography-font-option.active::before {
    opacity: 0.08;
}

.font-preview {
    font-size: 28px;
    font-weight: 400;
    color: var(--color-text-title);
    line-height: 1.2;
    position: relative;
    z-index: 1;
}

.font-name {
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-align: center;
    position: relative;
    z-index: 1;
}

.typography-font-option.active .font-name {
    color: var(--color-accent-primary);
    font-weight: 600;
}

/* Slider Container */
.typography-slider-container {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.slider-label {
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
    min-width: 40px;
    text-align: center;
}

/* Typography Slider */
.typography-slider {
    flex: 1;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(90deg, 
        rgba(168, 155, 141, 0.2) 0%, 
        rgba(212, 165, 116, 0.3) 100%);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    position: relative;
}

.typography-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, 
        var(--color-accent-primary) 0%, 
        var(--color-accent-hover) 100%);
    border: 3px solid #FFFFFF;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 8px rgba(212, 165, 116, 0.3),
                0 4px 16px rgba(212, 165, 116, 0.2);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.typography-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(212, 165, 116, 0.4),
                0 6px 20px rgba(212, 165, 116, 0.3);
}

.typography-slider::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.05);
}

.typography-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, 
        var(--color-accent-primary) 0%, 
        var(--color-accent-hover) 100%);
    border: 3px solid #FFFFFF;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 8px rgba(212, 165, 116, 0.3),
                0 4px 16px rgba(212, 165, 116, 0.2);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.typography-slider::-moz-range-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(212, 165, 116, 0.4),
                0 6px 20px rgba(212, 165, 116, 0.3);
}

.typography-slider::-moz-range-thumb:active {
    cursor: grabbing;
    transform: scale(1.05);
}

/* Size Markers */
.typography-size-markers {
    display: flex;
    justify-content: space-between;
    padding: 0 4px;
}

.typography-size-markers span {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.typography-size-markers span:hover {
    color: var(--color-accent-primary);
    background: rgba(212, 165, 116, 0.1);
}

/* Reset Button */
.typography-reset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 20px;
    background: transparent;
    border: 2px solid rgba(168, 155, 141, 0.25);
    border-radius: 10px;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.typography-reset-btn:hover {
    background: rgba(212, 165, 116, 0.1);
    border-color: var(--color-accent-primary);
    color: var(--color-accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(212, 165, 116, 0.15);
}

.typography-reset-btn:active {
    transform: translateY(0);
}

.typography-reset-btn svg {
    transition: transform 0.3s ease;
}

.typography-reset-btn:hover svg {
    transform: rotate(-180deg);
}

/* ===== DESKTOP: POPOVER STYLE (> 768px) ===== */
@media (min-width: 769px) {
    .typography-settings-panel {
        top: 52px;
        right: auto;
        left: auto;
    }
    
    .typography-settings-content {
        width: 380px;
        position: absolute;
        top: 0;
        right: 60px;
        transform: translateY(-8px);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.3s ease;
    }
    
    .typography-settings-panel:not(.active) .typography-settings-content {
        transform: translateY(-16px);
    }
    
    .typography-settings-panel.active .typography-settings-content {
        transform: translateY(0);
    }
    
    /* Make close button visible and accessible on desktop */
    .typography-settings-close {
        display: flex;
        opacity: 1;
        pointer-events: auto;
    }
    
    /* Add arrow pointer on desktop for better UX */
    .typography-settings-content::after {
        content: '';
        position: absolute;
        top: 20px;
        right: -8px;
        width: 16px;
        height: 16px;
        background: linear-gradient(135deg, 
            rgba(255, 255, 255, 0.98) 0%, 
            rgba(249, 246, 242, 0.98) 100%);
        border-right: 1px solid rgba(168, 155, 141, 0.25);
        border-top: 1px solid rgba(168, 155, 141, 0.25);
        transform: rotate(45deg);
        z-index: -1;
    }
    
    /* Arrow pointer */
    .typography-settings-content::before {
        content: '';
        position: absolute;
        top: -8px;
        right: 24px;
        width: 16px;
        height: 16px;
        background: rgba(255, 255, 255, 0.98);
        border-top: 1px solid rgba(168, 155, 141, 0.25);
        border-right: 1px solid rgba(168, 155, 141, 0.25);
        transform: rotate(-45deg);
        z-index: -1;
    }
}

/* ===== MOBILE: BOTTOM SHEET STYLE (<= 768px) ===== */
@media (max-width: 768px) {
    .typography-settings-panel {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .typography-settings-overlay {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(26, 22, 20, 0.4);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .typography-settings-panel.active .typography-settings-overlay {
        opacity: 1;
    }
    
    .typography-settings-content {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 85vh;
        border-radius: 24px 24px 0 0;
        transform: translateY(100%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }
    
    .typography-settings-panel.active .typography-settings-content {
        transform: translateY(0);
    }
    
    /* Handle bar for bottom sheet */
    .typography-settings-content::before {
        content: '';
        position: absolute;
        top: 12px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: rgba(168, 155, 141, 0.3);
        border-radius: 2px;
    }
    
    .typography-settings-header {
        padding-top: 32px;
    }
    
    .typography-font-options {
        grid-template-columns: 1fr 1fr;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    .typography-settings-body {
        padding: 20px 16px;
    }
    
    .typography-font-options {
        gap: 10px;
    }
    
    .typography-font-option {
        padding: 14px 10px;
    }
    
    .font-preview {
        font-size: 24px;
    }
    
    .font-name {
        font-size: 10px;
    }
}

/* ===== SMOOTH FONT TRANSITIONS ===== */
.poem-modal-text,
.poem-modal-title {
    transition: font-family 0.3s ease,
                font-size 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Focus Management */
.typography-font-option:focus-visible,
.typography-slider:focus-visible,
.typography-reset-btn:focus-visible,
.typography-settings-btn:focus-visible {
    outline: 3px solid var(--color-accent-primary);
    outline-offset: 2px;
}

/* Keyboard Navigation Indicators */
.typography-font-option:focus {
    border-color: var(--color-accent-primary);
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .typography-settings-panel,
    .typography-settings-content,
    .typography-settings-overlay,
    .typography-font-option,
    .typography-slider::-webkit-slider-thumb,
    .typography-slider::-moz-range-thumb,
    .poem-modal-text,
    .poem-modal-title {
        transition-duration: 0.01ms !important;
    }
}
