﻿/* ================================================================
   RAINBOW NATION LANGUAGE PICKER  —  v2 (rattle-fixed + compact)
   ----------------------------------------------------------------
   CHANGE LOG
   • RATTLE FIX
       Previous build: the "Did You Know" fact card grew/shrank with
       each language's text length. Hovering Zulu (long) → Xhosa
       (shorter) pushed the grid up, the cell under the cursor changed,
       mouseenter re-fired on a different cell, height changed again,
       repeat → visible rattle.
       Fix: .rn-fact-text is now hard-clamped to a fixed 4-line box
       with -webkit-line-clamp (or min-height fallback). Height never
       changes between renders → grid never shifts → no rattle.
       The pop animation also dropped its transform:scale (which was
       moving the card by sub-pixels and adding to the jitter); it is
       now a pure opacity cross-fade.
   • COMPACT HEADER
       "Izilimi / Languages" title and "South Africa's 11 Official
       Languages" subline merged into a single row separated by a dot
       — saves a row of vertical space.
   • COMPACT LANGUAGE CARDS
       The redundant native sub-label was removed from every card
       (Zulu/Xhosa/Tswana etc.). Cards are now single-line, tighter
       padding, denser grid. The native name still appears in the
       fact card when that language is hovered, so the information
       isn't lost — just not duplicated 11 times.
   ================================================================ */

.rn-lang-wrapper {
    position: relative;
}

/* ─── Trigger button ─────────────────────────────────────────── */
.rn-lang-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px 8px 10px;
    background: linear-gradient(135deg, #ffffff, #fef9f0);
    border: 1.5px solid rgba(245,130,32,0.25);
    border-radius: 60px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    color: #1A1D20;
    transition: all 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
    white-space: nowrap;
    backdrop-filter: blur(8px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05), inset 0 1px 0 rgba(255,255,255,0.8);
}

    .rn-lang-trigger:hover {
        border-color: #F58220;
        box-shadow: 0 6px 16px rgba(245,130,32,0.2), inset 0 1px 0 rgba(255,255,255,0.8);
        transform: translateY(-2px);
        background: linear-gradient(135deg, #ffffff, #fff5e8);
    }

    .rn-lang-trigger:active {
        transform: translateY(1px);
    }

.rn-kqg-orb {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rn-lang-code {
    letter-spacing: 0.05em;
    font-weight: 800;
    background: linear-gradient(135deg, #1A1D20, #F58220);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.rn-chevron {
    font-size: 0.7rem;
    color: #F58220;
    transition: transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.rn-lang-trigger[aria-expanded="true"] .rn-chevron {
    transform: rotate(180deg);
}

/* ─── Dropdown panel ─────────────────────────────────────────── */
.rn-lang-panel {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 340px;
    background: rgba(255,255,255,0.98);
    backdrop-filter: blur(20px);
    border-radius: 28px;
    border: 1px solid rgba(245,130,32,0.2);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25), 0 0 0 1px rgba(245,130,32,0.1);
    overflow: hidden;
    z-index: 10500;
    opacity: 0;
    transform: translateY(-15px) scale(0.97);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.34, 1.2, 0.64, 1);
}

    .rn-lang-panel.rn-panel-open {
        opacity: 1;
        transform: translateY(0) scale(1);
        pointer-events: all;
    }

/* Rainbow stripe across top */
.rn-panel-rainbow {
    display: flex;
    height: 5px;
}

    .rn-panel-rainbow span {
        flex: 1;
        animation: rainbowGlow 2s ease-in-out infinite;
        animation-delay: calc(var(--i, 0) * 0.2s);
    }

        .rn-panel-rainbow span:nth-child(1) {
            --i: 1;
            background: #E03C31;
        }

        .rn-panel-rainbow span:nth-child(2) {
            --i: 2;
            background: #007A4D;
        }

        .rn-panel-rainbow span:nth-child(3) {
            --i: 3;
            background: #FFB612;
        }

        .rn-panel-rainbow span:nth-child(4) {
            --i: 4;
            background: #002395;
        }

        .rn-panel-rainbow span:nth-child(5) {
            --i: 5;
            background: #FFFFFF;
        }

        .rn-panel-rainbow span:nth-child(6) {
            --i: 6;
            background: #000000;
        }

@keyframes rainbowGlow {
    0%, 100% {
        opacity: 1;
        filter: brightness(1);
    }

    50% {
        opacity: 0.8;
        filter: brightness(1.2);
    }
}

/* ─── Compact single-row panel header ────────────────────────── */
/* "Izilimi / Languages  ·  South Africa's 11 Official Languages" */
.rn-panel-header {
    padding: 14px 18px 12px;
    border-bottom: 2px solid rgba(245,130,32,0.15);
    background: linear-gradient(135deg, rgba(245,130,32,0.03), transparent);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
}

    .rn-panel-header i {
        font-size: 1.1rem;
        color: #F58220;
        flex-shrink: 0;
    }

    .rn-panel-header > span:not(.rn-panel-sub) {
        font-weight: 800;
        font-size: 0.88rem;
        color: #1A1D20;
        white-space: nowrap;
        flex-shrink: 0;
    }

/* Subline now lives on the same row, separated by a dot, in light grey */
.rn-panel-sub {
    font-size: 0.66rem;
    font-weight: 500;
    color: #9CA3AF;
    letter-spacing: 0.01em;
    margin: 0;
    padding: 0;
    width: auto;
    line-height: 1.3;
    /* dot separator */
    position: relative;
    padding-left: 10px;
}

    .rn-panel-sub::before {
        content: '·';
        position: absolute;
        left: 2px;
        top: -1px;
        color: #D1D5DB;
        font-weight: 800;
    }

/* ─── "Did You Know" hero fact card ──────────────────────────── */
/* Sits between header and grid. The fact-text is HEIGHT-LOCKED so
   different languages can't change the card height → no rattle. */
.rn-fact-card {
    margin: 12px 16px 10px;
    padding: 12px 14px 14px;
    background: linear-gradient(135deg, #fff7ec 0%, #ffffff 60%, #eef9ff 100%);
    border: 1px solid rgba(245,130,32,0.18);
    border-radius: 16px;
    position: relative;
    overflow: hidden;
}

    .rn-fact-card::before {
        content: '';
        position: absolute;
        top: -30px;
        right: -30px;
        width: 90px;
        height: 90px;
        background: radial-gradient(circle, rgba(245,130,32,0.28), transparent 70%);
        pointer-events: none;
    }

    .rn-fact-card::after {
        content: '';
        position: absolute;
        bottom: -22px;
        left: -22px;
        width: 70px;
        height: 70px;
        background: radial-gradient(circle, rgba(86,196,248,0.22), transparent 70%);
        pointer-events: none;
    }

    /* PURE opacity cross-fade — no scale/translate, so no sub-pixel
       jitter and no reflow contribution. */
    .rn-fact-card.rn-fact-card-pop .rn-fact-name,
    .rn-fact-card.rn-fact-card-pop .rn-fact-native,
    .rn-fact-card.rn-fact-card-pop .rn-fact-text {
        animation: rn-fact-fade 0.28s ease-out;
    }

@keyframes rn-fact-fade {
    0% {
        opacity: 0.35;
    }

    100% {
        opacity: 1;
    }
}

.rn-fact-label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #F58220;
    margin-bottom: 5px;
    position: relative;
    z-index: 1;
}

    .rn-fact-label::before {
        content: '✦';
        font-size: 0.75rem;
        color: #56C4F8;
    }

.rn-fact-name {
    font-size: 1rem;
    font-weight: 800;
    color: #1A1D20;
    line-height: 1.2;
    position: relative;
    z-index: 1;
}

.rn-fact-native {
    font-size: 0.68rem;
    font-weight: 500;
    color: #6B7280;
    margin-top: 1px;
    position: relative;
    z-index: 1;
}

/* ─── HEIGHT-LOCKED fact text — the actual rattle fix ─────────── */
/* Clamped to 4 lines via line-clamp. min-height is the geometric
   guarantee for browsers that ignore the clamp, so the card cannot
   change size between hovers regardless of fact length. */
.rn-fact-text {
    font-size: 0.72rem;
    line-height: 1.55;
    color: #374151;
    margin-top: 8px;
    position: relative;
    z-index: 1;
    font-weight: 400;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: calc(0.72rem * 1.55 * 4); /* 4 lines worth */
}

/* ─── Compact 2-column language grid ─────────────────────────── */
.rn-lang-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px 14px 14px;
    background: transparent;
}

/* Single-line cards — native sub-label removed, padding reduced */
.rn-lang-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 10px 14px;
    min-height: 40px;
    background: rgba(255,255,255,0.9);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.34, 1.2, 0.64, 1), border-color 0.2s, background 0.2s, box-shadow 0.25s;
    text-align: left;
    position: relative;
    overflow: hidden;
}

    .rn-lang-item::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 4px;
        background: linear-gradient(180deg, #F58220, #56C4F8);
        border-radius: 4px 0 0 4px;
        transform: scaleY(0);
        transition: transform 0.25s ease;
    }

    .rn-lang-item:hover::before,
    .rn-lang-item.active::before {
        transform: scaleY(1);
    }

    .rn-lang-item:hover {
        transform: translateX(2px);
        border-color: rgba(245,130,32,0.3);
        box-shadow: 0 4px 12px rgba(0,0,0,0.06);
        background: #ffffff;
    }

    .rn-lang-item.active {
        background: linear-gradient(135deg, #fff8f0, #ffffff);
        border-color: rgba(245,130,32,0.4);
        box-shadow: 0 3px 10px rgba(245,130,32,0.12);
    }

    /* sweep shimmer kept, but height-stable */
    .rn-lang-item::after {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(245,130,32,0.08), transparent);
        transition: left 0.5s ease;
        pointer-events: none;
    }

    .rn-lang-item:hover::after {
        left: 100%;
    }

.rn-lang-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: #1A1D20;
    line-height: 1.2;
    transition: color 0.2s;
}

.rn-lang-item.active .rn-lang-name {
    color: #F58220;
    font-weight: 800;
}

/* The native sub-label has been removed from the cards. If it's still
   present in legacy markup, hide it rather than letting it break the
   single-line layout. */
.rn-lang-native {
    display: none;
}

/* ─── Footer ─────────────────────────────────────────────────── */
.rn-panel-footer {
    padding: 10px 18px;
    font-size: 0.66rem;
    color: #9CA3AF;
    border-top: 1px solid rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #fafbfc, #ffffff);
}

    .rn-panel-footer i {
        color: #F58220;
        font-size: 0.7rem;
        animation: sparkle 2s ease-in-out infinite;
    }

@keyframes sparkle {
    0%, 100% {
        opacity: 0.6;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 480px) {
    .rn-lang-panel {
        position: fixed;
        top: 70px;
        right: 8px;
        left: 8px;
        width: auto;
        transform-origin: top right;
    }

    .rn-lang-trigger {
        padding: 6px 12px 6px 8px;
        font-size: 0.75rem;
    }

    /* On very narrow screens the header subline wraps under the title
       (no dot) so we still keep one compact line of meaning. */
    .rn-panel-header {
        flex-wrap: wrap;
    }

    .rn-panel-sub {
        width: 100%;
        padding-left: 0;
        margin-top: 2px;
    }

        .rn-panel-sub::before {
            content: '';
            display: none;
        }

    .rn-lang-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        padding: 4px 12px 12px;
    }

    .rn-lang-item {
        padding: 9px 12px;
        min-height: 38px;
    }

    .rn-lang-name {
        font-size: 0.78rem;
    }

    .rn-fact-card {
        margin: 10px 12px 8px;
        padding: 10px 12px 12px;
    }

    .rn-fact-text {
        font-size: 0.7rem;
        -webkit-line-clamp: 5;
        min-height: calc(0.7rem * 1.55 * 5);
    }
}

/* Reduced-motion: kill the rainbow + sparkle + fact-pop + shimmer loops */
@media (prefers-reduced-motion: reduce) {
    .rn-panel-rainbow span,
    .rn-panel-footer i,
    .rn-fact-card.rn-fact-card-pop .rn-fact-name,
    .rn-fact-card.rn-fact-card-pop .rn-fact-native,
    .rn-fact-card.rn-fact-card-pop .rn-fact-text,
    .rn-lang-item::after {
        animation: none !important;
        transition: none !important;
    }
}
