/**
 * Touch Gestures Styles - نبضي (Nabdi)
 * Visual feedback and animations for mobile gestures
 * 
 * @version 1.0.0
 * @since 2026-02-01
 */

/* ============================================================================
   GESTURE FEEDBACK - Base Styles
   ============================================================================ */

.gesture-feedback {
    position: fixed;
    pointer-events: none;
    z-index: 10001;
    opacity: 0;
    transition: opacity 0.2s ease-out, transform 0.3s ease-out;
}

.gesture-feedback.active {
    opacity: 1;
}

.gesture-feedback.fade-out {
    opacity: 0;
    transform: scale(1.5);
}

/* ============================================================================
   SWIPE FEEDBACK
   ============================================================================ */

.gesture-swipe-left,
.gesture-swipe-right {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 60px;
    background: rgba(212, 146, 90, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.gesture-swipe-left {
    right: 20px;
    animation: slideInLeft 0.3s ease-out;
}

.gesture-swipe-right {
    left: 20px;
    animation: slideInRight 0.3s ease-out;
}

[dir="rtl"] .gesture-swipe-left {
    left: 20px;
    right: auto;
    animation: slideInRight 0.3s ease-out;
}

[dir="rtl"] .gesture-swipe-right {
    right: 20px;
    left: auto;
    animation: slideInLeft 0.3s ease-out;
}

.gesture-swipe-left svg,
.gesture-swipe-right svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: white;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

/* ============================================================================
   LONG PRESS FEEDBACK - Ripple Effect
   ============================================================================ */

.gesture-longpress {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(212, 146, 90, 0.4) 0%, transparent 70%);
    transform: translate(-50%, -50%) scale(0);
    animation: ripplePulse 0.4s ease-out forwards;
}

.gesture-longpress.active {
    animation: ripplePulse 0.4s ease-out forwards;
}

@keyframes ripplePulse {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
    100% {
        transform: translate(-50%, -50%) scale(2);
        opacity: 0;
    }
}

/* ============================================================================
   DOUBLE TAP FEEDBACK - Heart Animation
   ============================================================================ */

.gesture-doubletap {
    width: 80px;
    height: 80px;
    transform: translate(-50%, -50%) scale(0);
}

.gesture-doubletap svg {
    width: 100%;
    height: 100%;
    fill: #E74C3C;
    filter: drop-shadow(0 4px 12px rgba(231, 76, 60, 0.4));
}

.gesture-doubletap.active {
    animation: heartPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.gesture-doubletap.fade-out {
    animation: heartFadeOut 0.5s ease-out forwards;
}

@keyframes heartPop {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 1;
    }
    70% {
        transform: translate(-50%, -50%) scale(0.9);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

@keyframes heartFadeOut {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.5) translateY(-30px);
        opacity: 0;
    }
}

/* ============================================================================
   ZOOM INDICATOR
   ============================================================================ */

.gesture-zoom-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(26, 22, 20, 0.85);
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    font-family: var(--font-ui, 'Kufam', sans-serif);
    font-size: 18px;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.2s ease-out;
    z-index: 10002;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.gesture-zoom-indicator.active {
    opacity: 1;
}

/* ============================================================================
   NAVIGATION INDICATORS - OLD (kept for reference, but hidden)
   ============================================================================ */

.gesture-nav-indicators {
    display: none !important; /* Replaced with subtle edge hints */
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    align-items: center;
    gap: 16px;
    background: rgba(26, 22, 20, 0.85);
    padding: 8px 16px;
    border-radius: 24px;
    z-index: 1001;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* ============================================================================
   SUBTLE EDGE HINTS - New minimal navigation feedback
   ============================================================================ */

.gesture-edge-hint {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease-out;
    pointer-events: none;
    z-index: 1000;
}

.gesture-edge-hint.visible {
    opacity: 0.4;
}

.gesture-edge-left {
    left: 4px;
}

.gesture-edge-right {
    right: 4px;
}

.gesture-edge-hint svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: var(--color-text-secondary, #5D4E47);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.6;
}

/* Minimal counter in top corner */
.gesture-nav-counter-minimal {
    position: fixed;
    top: 60px;
    left: 16px;
    background: rgba(26, 22, 20, 0.5);
    color: rgba(255, 255, 255, 0.8);
    padding: 4px 10px;
    border-radius: 12px;
    font-family: var(--font-ui, 'Kufam', sans-serif);
    font-size: 12px;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease-out;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

[dir="rtl"] .gesture-nav-counter-minimal {
    left: auto;
    right: 16px;
}

.gesture-nav-counter-minimal.visible {
    opacity: 1;
}

.gesture-nav-counter-minimal .gesture-nav-current {
    color: var(--color-accent-primary, #D4925A);
    font-weight: 600;
}

.gesture-nav-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    padding: 0;
}

.gesture-nav-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.gesture-nav-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.15);
}

.gesture-nav-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.gesture-nav-counter {
    display: flex;
    align-items: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.9);
    font-family: var(--font-ui, 'Kufam', sans-serif);
    font-size: 14px;
    min-width: 50px;
    justify-content: center;
}

.gesture-nav-current {
    font-weight: 600;
    color: var(--color-accent-primary, #D4925A);
}

.gesture-nav-separator {
    opacity: 0.5;
}

.gesture-nav-total {
    opacity: 0.7;
}

/* ============================================================================
   SWIPE HINT
   ============================================================================ */

.gesture-swipe-hint {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-accent-primary, #D4925A);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-family: var(--font-ui, 'Kufam', sans-serif);
    font-size: 12px;
    white-space: nowrap;
    animation: hintBounce 2s ease-in-out infinite;
    box-shadow: 0 4px 16px rgba(212, 146, 90, 0.3);
}

.gesture-swipe-hint::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid var(--color-accent-primary, #D4925A);
}

.gesture-swipe-hint.fade-out {
    animation: hintFadeOut 0.5s ease-out forwards;
}

@keyframes hintBounce {
    0%, 100% {
        transform: translateX(-50%) translateY(0);
    }
    50% {
        transform: translateX(-50%) translateY(-5px);
    }
}

@keyframes hintFadeOut {
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
}

/* ============================================================================
   BOUNDARY FEEDBACK
   ============================================================================ */

.gesture-boundary-start,
.gesture-boundary-end {
    animation: boundaryShake 0.3s ease-out;
}

@keyframes boundaryShake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-10px);
    }
    75% {
        transform: translateX(10px);
    }
}

/* ============================================================================
   OPTIONS MENU (Long Press)
   ============================================================================ */

.gesture-options-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10003;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-out, visibility 0.2s ease-out;
}

.gesture-options-menu.active {
    opacity: 1;
    visibility: visible;
}

.gesture-options-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.gesture-options-content {
    position: absolute;
    background: var(--color-canvas, #FFFBF7);
    border-radius: 16px;
    min-width: 200px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gesture-options-menu.active .gesture-options-content {
    transform: scale(1);
}

.gesture-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease;
    text-align: right;
    font-family: var(--font-ui, 'Kufam', sans-serif);
    font-size: 15px;
    color: var(--color-text-primary, #1A1614);
}

[dir="ltr"] .gesture-option {
    text-align: left;
}

.gesture-option:hover {
    background: var(--color-canvas-warm, #F9F6F2);
}

.gesture-option:active {
    background: var(--color-canvas-deep, #F0EBE6);
}

.gesture-option svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--color-accent-primary, #D4925A);
}

.gesture-option span {
    flex: 1;
}

/* Separator between option groups */
.gesture-option + .gesture-option {
    border-top: 1px solid var(--color-divider, rgba(122, 106, 93, 0.15));
}

/* ============================================================================
   GESTURE ENABLED ELEMENTS
   ============================================================================ */

.gesture-enabled {
    touch-action: pan-y pinch-zoom;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.gesture-enabled.pinch-zoom-enabled {
    touch-action: pan-y;
}

/* Smooth zoom transitions */
.poem-modal-text,
.poem-text,
[data-zoomable] {
    transform-origin: center top;
    transition: transform 0.1s ease-out;
    will-change: transform;
}

/* ============================================================================
   MODAL NAVIGATION TRANSITIONS
   ============================================================================ */

.poem-modal-content {
    will-change: transform, opacity;
}

/* Smooth slide transition for poem navigation */
.poem-modal.navigating .poem-modal-content {
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}

/* ============================================================================
   MOBILE-SPECIFIC ADJUSTMENTS
   ============================================================================ */

@media (max-width: 768px) {
    .gesture-nav-indicators {
        bottom: 90px;
        padding: 6px 12px;
    }
    
    .gesture-nav-btn {
        width: 32px;
        height: 32px;
    }
    
    .gesture-nav-btn svg {
        width: 18px;
        height: 18px;
    }
    
    .gesture-nav-counter {
        font-size: 13px;
    }
    
    .gesture-swipe-left,
    .gesture-swipe-right {
        width: 50px;
        height: 50px;
    }
    
    .gesture-swipe-left svg,
    .gesture-swipe-right svg {
        width: 24px;
        height: 24px;
    }
    
    .gesture-doubletap {
        width: 60px;
        height: 60px;
    }
    
    .gesture-options-content {
        min-width: 180px;
    }
    
    .gesture-option {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    .gesture-zoom-indicator {
        font-size: 16px;
        padding: 10px 20px;
    }
}

/* Small phones */
@media (max-width: 375px) {
    .gesture-nav-indicators {
        gap: 8px;
        padding: 4px 10px;
    }
    
    .gesture-swipe-hint {
        font-size: 11px;
        padding: 6px 12px;
    }
}

/* Tablet-specific adjustments */
@media (min-width: 768px) and (max-width: 1024px) {
    .gesture-nav-indicators {
        bottom: 120px;
    }
    
    .gesture-swipe-left,
    .gesture-swipe-right {
        width: 70px;
        height: 70px;
    }
    
    .gesture-doubletap {
        width: 90px;
        height: 90px;
    }
}

/* ============================================================================
   SAFE AREA INSETS (Notched devices)
   ============================================================================ */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .gesture-nav-indicators {
        bottom: calc(100px + env(safe-area-inset-bottom));
    }
    
    @media (max-width: 768px) {
        .gesture-nav-indicators {
            bottom: calc(90px + env(safe-area-inset-bottom));
        }
    }
}

/* ============================================================================
   DARK MODE SUPPORT
   ============================================================================ */

@media (prefers-color-scheme: dark) {
    .gesture-options-content {
        background: #2a2520;
    }
    
    .gesture-option {
        color: #f5f0eb;
    }
    
    .gesture-option:hover {
        background: #3a3530;
    }
    
    .gesture-option:active {
        background: #4a4540;
    }
}

/* ============================================================================
   REDUCED MOTION
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
    .gesture-feedback,
    .gesture-doubletap,
    .gesture-longpress,
    .gesture-swipe-left,
    .gesture-swipe-right,
    .gesture-swipe-hint,
    .gesture-options-content,
    .gesture-boundary-start,
    .gesture-boundary-end {
        animation: none !important;
        transition: opacity 0.1s ease !important;
    }
    
    .poem-modal-text,
    .poem-text,
    [data-zoomable] {
        transition: none !important;
    }
}

/* ============================================================================
   HIGH CONTRAST MODE
   ============================================================================ */

@media (prefers-contrast: high) {
    .gesture-nav-indicators {
        background: #000;
        border: 2px solid #fff;
    }
    
    .gesture-nav-btn:focus {
        outline: 3px solid #fff;
        outline-offset: 2px;
    }
    
    .gesture-options-content {
        border: 2px solid currentColor;
    }
    
    .gesture-option:focus {
        outline: 3px solid currentColor;
        outline-offset: -3px;
    }
}
