/**
 * Reading Fluency Exercises - Popover Styles
 * Responsive popover/modal system for fluency exercises
 */

/* ===== Popover Container ===== */
.fluency-popover {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 0;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.fluency-popover.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* ===== Backdrop ===== */
.fluency-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: fluency-fadeIn 0.3s ease;
}

/* ===== Popover Content ===== */
.fluency-content {
    position: relative;
    width: 90vw;
    max-width: 1200px;
    height: 90vh;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 1.5rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5),
                0 0 0 1px rgba(0, 0, 0, 0.05);
    padding: 2rem;
    animation: fluency-scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

/* ===== Close Button ===== */
.fluency-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10000;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(0.5rem);
    -webkit-backdrop-filter: blur(0.5rem);
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    color: #333;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fluency-close:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: scale(1.1);
}

.fluency-close:active {
    transform: scale(0.95);
}

/* ===== Header ===== */
.fluency-header {
    margin-bottom: 1.5rem;
}

.fluency-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0;
}

/* ===== Body ===== */
.fluency-body {
    flex: 1;
    overflow-y: auto;
    padding-right: 1rem;
}

/* Hide audio element */
#fluency-audio {
    display: none;
}

/* ===== Fluency Reader Styles ===== */
.fluency-body fluency-reader {
    display: block;
    font-size: 1.25rem;
    line-height: 1.8;
    color: #2d2d2d;
    max-width: 800px;
    margin: 0 auto;
    font-weight: 400; /* Ensure normal weight for all text */
}

/* Book Layout Typography - Standard HTML tags with inline formatting */
.fluency-body fluency-reader h2,
.fluency-body fluency-reader > div > h2 {
    display: block !important;
    font-size: 1.5rem !important;
    font-weight: normal !important; /* Default normal, use <strong> for bold */
    text-align: left !important;
    margin: 0 0 1rem 0 !important;
    color: #1a1a1a !important;
}

.fluency-body fluency-reader h3,
.fluency-body fluency-reader > div > h3 {
    display: block !important;
    font-size: 1.1rem !important;
    font-weight: normal !important; /* Default normal */
    font-style: normal !important; /* Default normal, use <em> for italic */
    text-align: left !important;
    margin: 0 0 2rem 0 !important;
    color: #1a1a1a !important;
}

.fluency-body fluency-reader p,
.fluency-body fluency-reader > div > p {
    display: block !important;
    margin: 0 0 1.5rem 0 !important;
    text-align: left !important;
    text-indent: 0 !important;
    line-height: 1.8 !important;
    font-weight: normal !important;
    color: #1a1a1a !important;
}

/* Bold and italic styling using standard HTML tags */
.fluency-body fluency-reader strong,
.fluency-body fluency-reader > div > strong,
.fluency-body fluency-reader b,
.fluency-body fluency-reader > div > b {
    font-weight: 700 !important;
}

.fluency-body fluency-reader em,
.fluency-body fluency-reader > div > em,
.fluency-body fluency-reader i,
.fluency-body fluency-reader > div > i {
    font-style: italic !important;
    font-weight: normal !important;
}

/* ===== Animations ===== */
@keyframes fluency-fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fluency-scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fluency-slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* ===== Mobile Overrides (≤48em / 768px) ===== */
@media (max-width: 48em) {
    .fluency-content {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        padding: 1.5rem;
        animation: fluency-slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .fluency-backdrop {
        background: rgba(0, 0, 0, 0.95);
    }

    .fluency-close {
        top: 0.75rem;
        right: 0.75rem;
        width: 2rem;
        height: 2rem;
        font-size: 1.25rem;
        background: rgba(255, 255, 255, 0.9);
    }

    .fluency-title {
        font-size: 1.5rem;
    }

    .fluency-body {
        padding-right: 0.5rem;
    }

    .fluency-body fluency-reader {
        font-size: 1.1rem;
    }
}

/* ===== Accessibility ===== */
.fluency-close:focus-visible {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .fluency-backdrop,
    .fluency-content {
        animation: none;
    }

    .fluency-close {
        transition: none;
    }
}

/* ===== Shimmer Effect ===== */
@property --shimmer-shimmer {
    syntax: "<angle>";
    inherits: false;
    initial-value: 33deg;
}

@keyframes shimmer-shimmer {
    0% {
        --shimmer-shimmer: 0deg;
    }
    100% {
        --shimmer-shimmer: 360deg;
    }
}

@keyframes shimmer-shine {
    0% {
        opacity: 0;
    }
    15% {
        opacity: 1;
    }
    55% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@keyframes shimmer-text {
    0% {
        background-position: 100% center;
    }
    100% {
        background-position: -100% center;
    }
}

/* Apply shimmer to RF control buttons */
#rf-controls button {
    --inset: 40px;
    position: relative;
    isolation: isolate;
}

.shimmer-shimmer {
    position: absolute;
    inset: calc(var(--inset) * -1);
    border-radius: inherit;
    pointer-events: none;
    mask-image: conic-gradient(
        from var(--shimmer-shimmer, 0deg),
        transparent 0%,
        transparent 20%,
        black 36%,
        black 45%,
        transparent 50%,
        transparent 70%,
        black 85%,
        black 95%,
        transparent 100%
    );
    mask-size: cover;
    mix-blend-mode: plus-lighter;
    animation: shimmer-shimmer 1s linear infinite both;
}

#rf-controls button:hover .shimmer-shimmer::before,
#rf-controls button:hover .shimmer-shimmer::after {
    opacity: 1;
    animation: shimmer-shine 1.2s ease-in 1 forwards;
}

.shimmer-shimmer::before,
.shimmer-shimmer::after {
    transition: all 0.5s ease;
    opacity: 0;
    content: "";
    border-radius: inherit;
    position: absolute;
    mix-blend-mode: color;
    inset: var(--inset);
    pointer-events: none;
}

.shimmer-shimmer::before {
    /* Burgundy glow using rf colors (#653449) */
    box-shadow: 0 0 calc(var(--inset) * 0.1)  2px hsl(330deg 35% 75%),
        0 0 calc(var(--inset) * 0.18)  4px hsl(330deg 35% 60%),
        0 0 calc(var(--inset) * 0.33)  4px hsl(330deg 40% 50%),
        0 0 calc(var(--inset) * 0.66) 5px hsl(330deg 35% 40%);
    z-index: -1;
}

.shimmer-shimmer::after {
    /* Burgundy inner glow */
    box-shadow: inset 0 0 0 1px hsl(330deg 35% 75%),
        inset 0 0 2px 1px hsl(330deg 40% 60%),
        inset 0 0 5px 2px hsl(330deg 35% 50%);
    z-index: 2;
}

.shimmer-text {
    background-clip: text;
    background-image: linear-gradient(120deg, currentColor, currentColor 40%, rgba(240, 220, 230, 1) 50%, currentColor 52%);
    background-repeat: no-repeat;
    background-size: 300% 300%;
    background-position: 0% center;
}

#rf-controls button:hover .shimmer-text {
    animation: shimmer-text .66s ease-in 1 both;
}

/* ===== Print Styles ===== */
@media print {
    .fluency-popover {
        display: none;
    }
}
