/* =========================================================================
   TADABBUR.CSS v2 — Interactive Verse Contemplation Widget
   =========================================================================
   Victorian newspaper aesthetic matching The Daily Revelation.
   Uses revelation.css design tokens: --rev-bg, --rev-ink, --rev-ink-soft,
   --rev-gold, --rev-gold-dark, --rev-surface, --rev-border, --rev-muted,
   --rev-fs-sm, --rev-fs-base, --rev-fs-md.
   Fonts: Playfair Display (headings), EB Garamond (body),
          Amiri (Arabic), Inter (UI).
   All animations: opacity + transform only (GPU-composited).

   v2 CHANGE: Phases use display toggling instead of absolute positioning
   to prevent content clipping on mobile viewports.
   ========================================================================= */


/* =========================================================================
   BASE CONTAINER
   ========================================================================= */

.tadabbur {
    position: relative;
    background: var(--rev-surface);
    border: 2px solid var(--rev-ink);
    padding: 1.5rem;
    min-height: 320px;
    display: flex;
    flex-direction: column;
    cursor: pointer;
}

.tadabbur--fullpage {
    min-height: calc(100vh - 200px);
}

.tadabbur--loading {
    align-items: center;
    justify-content: center;
}

.tadabbur--error {
    align-items: center;
    justify-content: center;
}


/* =========================================================================
   HEADER
   ========================================================================= */

.tadabbur__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tadabbur__title {
    font-family: 'Playfair Display', serif;
    font-size: var(--rev-fs-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--rev-gold);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.tadabbur__ref {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--rev-muted);
    letter-spacing: 0.06em;
}


/* =========================================================================
   VERSE SELECTOR
   ========================================================================= */

.tadabbur__selector {
    width: 100%;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.tadabbur__selector-label {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--rev-muted);
    margin-bottom: 0.3rem;
    display: block;
}

.tadabbur__selector-dropdown {
    width: 100%;
    font-family: 'EB Garamond', serif;
    font-size: var(--rev-fs-base);
    background-color: var(--rev-bg);
    color: var(--rev-ink);
    border: 1px solid var(--rev-border);
    border-radius: 0;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b5b47' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 10px 6px;
    line-height: 1.4;
}

.tadabbur__selector-dropdown:focus {
    outline: 2px solid var(--rev-gold);
    outline-offset: -2px;
}

.tadabbur__selector-dropdown::-ms-expand {
    display: none;
}


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

.tadabbur__controls {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.tadabbur__btn {
    background: none;
    border: 1px solid var(--rev-border);
    color: var(--rev-muted);
    width: 36px;
    height: 36px;
    border-radius: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: color 0.2s, border-color 0.2s;
}

.tadabbur__btn:hover {
    color: var(--rev-ink);
    border-color: var(--rev-ink);
}

.tadabbur__btn--active {
    color: var(--rev-gold);
    border-color: var(--rev-gold);
}


/* =========================================================================
   PHASE CONTAINER — v2 display toggling (no absolute positioning)
   ========================================================================= */

.tadabbur__phases {
    flex: 1;
    overflow-y: auto;
}

.tadabbur__phase {
    display: none;
    flex-direction: column;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
}

.tadabbur__phase--active {
    display: flex;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}


/* =========================================================================
   PHASE LABELS
   ========================================================================= */

.tadabbur__phase-label {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--rev-gold);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.tadabbur__phase-label i {
    font-size: 0.65rem;
}


/* =========================================================================
   PHASE 1: LISTEN — Word-by-word reveal
   ========================================================================= */

.tadabbur__words {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    direction: rtl;
    margin-bottom: 1rem;
}

.tadabbur__word {
    text-align: center;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    min-width: 48px;
    max-width: 100px;
}

.tadabbur__word--visible {
    opacity: 1;
    transform: translateY(0);
}

.tadabbur__word--clickable {
    cursor: pointer;
    position: relative;
}

.tadabbur__word--clickable::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    right: 10%;
    height: 2px;
    background: var(--rev-gold);
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.tadabbur__word--clickable:hover::after {
    opacity: 1;
}

.tadabbur__word--selected {
    background: rgba(196, 155, 60, 0.12);
    border-radius: 4px;
}

.tadabbur__word--selected .tadabbur__word-arabic {
    color: var(--rev-gold);
}

.tadabbur__word-arabic {
    font-family: 'Amiri', 'Traditional Arabic', serif;
    font-size: 1.6rem;
    line-height: 1.4;
    color: var(--rev-ink);
    direction: rtl;
}

.tadabbur__word-translit {
    font-family: 'EB Garamond', serif;
    font-size: 0.75rem;
    font-style: italic;
    color: var(--rev-muted);
    margin-top: 0.15rem;
}

.tadabbur__word-english {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    color: var(--rev-ink-soft);
    margin-top: 0.1rem;
}

.tadabbur__translation {
    font-family: 'EB Garamond', serif;
    font-size: var(--rev-fs-md);
    line-height: 1.7;
    color: var(--rev-ink);
    text-align: center;
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid var(--rev-border);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.6s ease 0.3s, transform 0.6s ease 0.3s;
}

.tadabbur__translation--visible {
    opacity: 1;
    transform: translateY(0);
}


/* =========================================================================
   PHASE 2: LOOK — Focus word + root data
   ========================================================================= */

.tadabbur__focus {
    text-align: center;
    margin-bottom: 1rem;
}

.tadabbur__focus-arabic {
    font-family: 'Amiri', 'Traditional Arabic', serif;
    font-size: 2.2rem;
    color: var(--rev-gold);
    line-height: 1.3;
    animation: tadabbur-pulse 2.5s ease-in-out infinite;
}

.tadabbur__focus-english {
    font-family: 'EB Garamond', serif;
    font-size: var(--rev-fs-base);
    color: var(--rev-ink-soft);
    margin-top: 0.25rem;
    font-style: italic;
}

.tadabbur__root-panel {
    background: var(--rev-bg);
    border: 1px solid var(--rev-border);
    padding: 1rem;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    max-height: 40vh;
    overflow-y: auto;
}

.tadabbur__root-panel--visible {
    opacity: 1;
    transform: translateY(0);
}

.tadabbur__root-letters {
    font-family: 'Amiri', serif;
    font-size: 1.1rem;
    color: var(--rev-gold-dark);
    text-align: center;
    direction: rtl;
    margin-bottom: 0.5rem;
}

.tadabbur__root-freq {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    color: var(--rev-muted);
    text-align: center;
    margin-bottom: 0.75rem;
    letter-spacing: 0.04em;
}

.tadabbur__root-freq strong {
    color: var(--rev-gold);
    font-weight: 700;
}

.tadabbur__root-samples {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tadabbur__root-sample {
    font-family: 'EB Garamond', serif;
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--rev-ink-soft);
    padding-left: 0.75rem;
    border-left: 2px solid var(--rev-gold);
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.tadabbur__root-sample--visible {
    opacity: 1;
    transform: translateX(0);
}

.tadabbur__root-sample-ref {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    color: var(--rev-gold-dark);
    font-weight: 600;
    margin-right: 0.35rem;
}


/* ---- Phase 2 Placeholder ---- */

.tadabbur__look-placeholder {
    text-align: center;
    padding: 2rem 0;
    font-family: 'EB Garamond', serif;
    font-style: italic;
    color: var(--rev-muted);
}


/* =========================================================================
   PHASE 3: THINK — Tadabbur question
   ========================================================================= */

.tadabbur__question-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 1rem 0;
}

.tadabbur__question {
    font-family: 'EB Garamond', serif;
    font-size: 1.15rem;
    line-height: 1.7;
    color: var(--rev-ink);
    text-align: center;
    max-width: 480px;
    opacity: 0;
    transform: scale(0.97);
    transition: opacity 0.7s ease, transform 0.7s ease;
}

.tadabbur__question--visible {
    opacity: 1;
    transform: scale(1);
}

.tadabbur__question-icon {
    font-size: 1.5rem;
    color: var(--rev-gold);
    margin-bottom: 0.75rem;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.tadabbur__question-icon--visible {
    opacity: 1;
}


/* =========================================================================
   PHASE 4: SEE — Connected verses
   ========================================================================= */

.tadabbur__connected {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.tadabbur__connected-verse {
    border-left: 3px solid var(--rev-gold);
    padding: 0.75rem 1rem;
    background: var(--rev-bg);
    opacity: 0;
    transform: translateX(-10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.tadabbur__connected-verse--visible {
    opacity: 1;
    transform: translateX(0);
}

.tadabbur__connected-ref {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--rev-gold-dark);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.tadabbur__connected-text {
    font-family: 'EB Garamond', serif;
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--rev-ink-soft);
}

.tadabbur__no-connections {
    font-family: 'EB Garamond', serif;
    font-size: var(--rev-fs-base);
    color: var(--rev-muted);
    text-align: center;
    font-style: italic;
    padding: 2rem 0;
}


/* =========================================================================
   PROGRESS BAR
   ========================================================================= */

.tadabbur__progress {
    display: flex;
    gap: 3px;
    margin-top: 1rem;
    flex-shrink: 0;
}

.tadabbur__progress-seg {
    flex: 1;
    height: 3px;
    background: var(--rev-border);
    position: relative;
    overflow: hidden;
}

.tadabbur__progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: var(--rev-gold);
    transition: width 0.3s linear;
}

.tadabbur__progress-seg--done .tadabbur__progress-fill {
    width: 100%;
}

.tadabbur__progress-seg--active .tadabbur__progress-fill {
    transition: none;
}

.tadabbur__progress-label {
    display: flex;
    justify-content: space-between;
    margin-top: 0.3rem;
}

.tadabbur__progress-name {
    font-family: 'Inter', sans-serif;
    font-size: 0.625rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--rev-muted);
    opacity: 0.5;
    transition: opacity 0.3s, color 0.3s;
}

.tadabbur__progress-name--active {
    opacity: 1;
    color: var(--rev-gold);
}

.tadabbur__progress-name--done {
    opacity: 0.7;
    color: var(--rev-ink-soft);
}


/* =========================================================================
   LOADING & ERROR STATES
   ========================================================================= */

.tadabbur__loading {
    text-align: center;
    color: var(--rev-muted);
}

.tadabbur__loading-icon {
    font-size: 1.5rem;
    color: var(--rev-gold);
    margin-bottom: 0.5rem;
    animation: tadabbur-spin 1.5s linear infinite;
}

.tadabbur__loading-text {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
}

.tadabbur__error-text {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    color: var(--rev-muted);
}


/* =========================================================================
   ANIMATIONS
   ========================================================================= */

@keyframes tadabbur-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.6; }
}

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


/* =========================================================================
   REDUCED MOTION
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
    .tadabbur__word,
    .tadabbur__phase,
    .tadabbur__translation,
    .tadabbur__root-panel,
    .tadabbur__root-sample,
    .tadabbur__question,
    .tadabbur__question-icon,
    .tadabbur__connected-verse,
    .tadabbur__progress-fill,
    .tadabbur__progress-name,
    .tadabbur__btn {
        transition: none !important;
    }

    .tadabbur__focus-arabic {
        animation: none;
    }

    .tadabbur__loading-icon {
        animation: none;
    }

    .tadabbur__word {
        opacity: 1;
        transform: none;
    }
}


/* =========================================================================
   RESPONSIVE — Mobile (max-width: 600px)
   ========================================================================= */

@media (max-width: 600px) {
    .tadabbur {
        padding: 1rem;
        min-height: auto;
    }

    .tadabbur--fullpage {
        min-height: auto;
    }

    .tadabbur__header {
        flex-wrap: wrap;
    }

    .tadabbur__words {
        gap: 0.5rem;
    }

    .tadabbur__word {
        min-width: 40px;
        max-width: 80px;
    }

    .tadabbur__word-arabic {
        font-size: 1.3rem;
    }

    .tadabbur__focus-arabic {
        font-size: 1.8rem;
    }

    .tadabbur__question {
        font-size: 1rem;
        max-width: 100%;
    }

    .tadabbur__connected-verse {
        padding: 0.5rem 0.75rem;
    }

    .tadabbur__root-panel {
        max-height: 35vh;
    }

    .tadabbur__selector-dropdown {
        font-size: 0.85rem;
    }
}
