/**
 * Complete UI/UX Fixes Bundle
 * All critical and medium priority fixes in one file
 *
 * Import this file in app pages:
 * <link rel="stylesheet" href="../css/ui-ux-fixes-all.css">
 */

/* ============================
   1. Z-INDEX HIERARCHY FIX
   ============================ */

.modal-overlay,
.modal-backdrop {
    z-index: 9000 !important;
}

.loading-modal,
.loading-overlay {
    z-index: 9500 !important;
}

.character-configurator {
    z-index: 10000 !important;
}

.role-edit-modal {
    z-index: 10500 !important;
}

.audio-player.fullscreen {
    z-index: 11000 !important;
}

.error-modal,
.alert-modal {
    z-index: 12000 !important;
}

/* ============================
   2. SKELETON LOADING STATES
   ============================ */

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
}

.story-card--loading {
    background: var(--color-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    pointer-events: none;
}

.story-card--loading .skeleton-image {
    width: 100%;
    padding-top: 66.67%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
}

.story-card--loading .skeleton-content {
    padding: 1.5rem;
}

.story-card--loading .skeleton-title,
.story-card--loading .skeleton-text {
    height: 20px;
    margin-bottom: 0.75rem;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
}

/* ============================
   3. HOVER STATES
   ============================ */

:root {
    --state-hover-lift: translateY(-2px);
    --state-hover-shadow: 0 4px 12px rgba(155, 135, 217, 0.2);
    --state-active-scale: scale(0.98);
}

.theme-tag {
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-tag:hover:not(.selected) {
    transform: var(--state-hover-lift);
    box-shadow: var(--state-hover-shadow);
    border-color: var(--color-purple);
}

.story-card {
    cursor: pointer;
    transition: all 0.3s ease;
}

.story-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.child-card {
    cursor: pointer;
    transition: all 0.3s ease;
}

.child-card:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(155, 135, 217, 0.15);
}

.stat-card {
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.stat-card:hover {
    transform: var(--state-hover-lift);
    box-shadow: var(--state-hover-shadow);
}

.stat-card::after {
    content: '→';
    position: absolute;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    transition: all 0.2s ease;
    color: var(--color-purple);
    font-size: 1.25rem;
}

.stat-card:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(3px);
}

/* ============================
   4. EMPTY STATES
   ============================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem;
    background: var(--color-gray-50, #f9f9f9);
    border-radius: var(--radius-md);
    min-height: 300px;
}

.empty-state__icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    opacity: 0.8;
}

.empty-state__title {
    color: var(--color-gray-800);
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.empty-state__description {
    color: var(--color-gray-600);
    font-size: 1rem;
    line-height: 1.6;
    max-width: 400px;
    margin-bottom: 1.5rem;
}

/* ============================
   5. FORM VALIDATION
   ============================ */

.form-group {
    position: relative;
}

.character-counter {
    position: absolute;
    right: 1rem;
    bottom: 0.5rem;
    font-size: 0.75rem;
    color: var(--color-gray-600);
}

.character-counter.warning {
    color: var(--color-orange);
}

.character-counter.error {
    color: var(--color-red);
}

.form-success {
    color: var(--color-green);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

.form-success::before {
    content: '✓';
    display: inline-block;
    width: 16px;
    height: 16px;
    background: var(--color-green);
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 16px;
}

/* ============================
   6. MOBILE TYPOGRAPHY
   ============================ */

@media (max-width: 480px) {
    h1 {
        font-size: clamp(2.25rem, 9vw, 3.5rem) !important;
    }

    body {
        font-size: 1.0625rem !important;
    }

    .story-card-title {
        font-size: 1.125rem;
    }

    .btn-primary,
    .btn-secondary {
        font-size: 1rem;
        padding: 0.875rem 1.5rem;
    }
}

/* ============================
   7. REMOVE EXCESSIVE ANIMATIONS
   ============================ */

/* Keep pulse only on main CTAs */
.hero .btn-primary:first-child {
    animation: pulse 3s ease-in-out infinite;
}

/* Remove from all other buttons */
.btn-primary:not(.hero .btn-primary:first-child) {
    animation: none !important;
}

/* ============================
   8. TOUCH TARGETS (44x44px minimum)
   ============================ */

@media (max-width: 768px) {
    .btn-primary,
    .btn-secondary,
    .theme-tag,
    .app-nav__link,
    .dropdown-item,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }

    .theme-tag {
        padding: 0.75rem 1rem;
    }

    /* Increase tap area for small icons */
    .icon-button,
    .close-button,
    .modal-close {
        padding: 12px;
        margin: -12px;
    }
}

/* ============================
   9. KEYBOARD NAVIGATION
   ============================ */

*:focus-visible {
    outline: 2px solid var(--color-purple);
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
    outline-offset: 4px;
}

/* Keyboard-only focus (not on click) */
.js-focus-visible :focus:not(.focus-visible) {
    outline: none;
}

/* ============================
   10. ACCESSIBILITY IMPROVEMENTS
   ============================ */

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip to main content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-purple);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100000;
}

.skip-link:focus {
    top: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .story-card,
    .child-card,
    .stat-card {
        border: 2px solid currentColor;
    }

    .btn-primary {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================
   11. PERFORMANCE OPTIMIZATIONS
   ============================ */

/* Use GPU acceleration for transforms */
.story-card,
.child-card,
.stat-card,
.theme-tag {
    will-change: transform;
    transform: translateZ(0);
}

/* Optimize image rendering */
img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}