/* css/encounter-interstitial.css
   The ENCOUNTER INTERSTITIAL — a full-screen impact page shown when an encounter
   triggers, before the character name card. Rarity-tinted via --ei-rarity (set
   inline from tokens.css --rarity-* vars). Transform/opacity-only animations.
   z-index 9300 (below CharacterIntro 9400). */

.ei-overlay {
    position: fixed;
    inset: 0;
    z-index: 9300;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    --ei-rarity: #ffffff;
    --ei-char: var(--ei-rarity);
}

/* ── Darken ── */
.ei-darken {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center,
        rgba(6, 6, 10, 0.86) 0%, rgba(0, 0, 0, 0.97) 75%);
    opacity: 0;
    animation: ei-darken-in 220ms ease-out forwards;
}

@keyframes ei-darken-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Background hue shifts toward the character color during the rush. */
.ei-overlay.ei-rush .ei-darken {
    background: radial-gradient(ellipse at center,
        var(--ei-char) 0%, rgba(4, 4, 8, 0.98) 68%);
    animation: ei-hue-shift 2100ms ease-in forwards;
}

@keyframes ei-hue-shift {
    from { opacity: 0.35; }
    to   { opacity: 0.6; }
}

/* ── Flash layer (fallback when EffectJuice absent) ── */
.ei-flash {
    position: absolute;
    inset: 0;
    background: #ffffff;
    opacity: 0;
    pointer-events: none;
}
.ei-flash.ei-flash-double {
    animation: ei-double-flash 360ms steps(1, end) forwards;
}

@keyframes ei-double-flash {
    0%   { opacity: 0; }
    10%  { opacity: 0.95; }
    25%  { opacity: 0; }
    45%  { opacity: 0.9; }
    60%  { opacity: 0; }
    100% { opacity: 0; }
}

/* ── Lightning (fallback bolts) ── */
.ei-lightning {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.ei-bolt {
    position: absolute;
    top: -6%;
    width: 3px;
    height: 70%;
    background: linear-gradient(to bottom,
        rgba(255, 255, 255, 0), #ffffff 40%, var(--ei-rarity) 90%);
    box-shadow: 0 0 12px #ffffff, 0 0 26px var(--ei-rarity);
    transform: skewX(var(--ei-bolt-skew, 0deg));
    clip-path: polygon(40% 0, 60% 0, 48% 32%, 66% 34%, 40% 66%, 56% 68%, 30% 100%, 44% 60%, 30% 58%);
    opacity: 0;
    animation: ei-bolt-strike 340ms ease-out forwards;
}

@keyframes ei-bolt-strike {
    0%   { opacity: 0; transform: skewX(var(--ei-bolt-skew, 0deg)) scaleY(0.2); }
    12%  { opacity: 1; transform: skewX(var(--ei-bolt-skew, 0deg)) scaleY(1); }
    60%  { opacity: 0.85; }
    100% { opacity: 0; }
}

/* ── Rush streaks ── */
.ei-streaks {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
}
.ei-streak {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: var(--ei-streak-len, 40vmax);
    margin-left: -1px;
    transform-origin: 50% 0;
    background: linear-gradient(to bottom,
        rgba(255, 255, 255, 0) 0%,
        var(--ei-rarity) 55%,
        #ffffff 100%);
    opacity: 0;
    will-change: transform, opacity;
    animation-name: ei-streak-rush;
    animation-timing-function: cubic-bezier(0.5, 0, 0.85, 0.3);
    animation-iteration-count: infinite;
}

@keyframes ei-streak-rush {
    0%   { opacity: 0; transform: rotate(var(--a, 0deg)) translateY(0) scaleY(0.2); }
    15%  { opacity: 0.9; }
    100% { opacity: 0; transform: rotate(var(--a, 0deg)) translateY(6vmax) scaleY(1.6); }
}

/* The streaks read as radial because each element is pre-rotated inline; the
   keyframe just pushes them outward and fades them. */

/* ── Content / title ── */
.ei-content {
    position: relative;
    z-index: 2;
    text-align: center;
    pointer-events: none;
}

.ei-shockwave {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border-radius: 50%;
    border: 4px solid var(--ei-rarity);
    box-shadow: 0 0 40px var(--ei-rarity);
    opacity: 0;
}
.ei-overlay.ei-slam .ei-shockwave {
    animation: ei-shockwave 700ms ease-out forwards;
}

@keyframes ei-shockwave {
    0%   { opacity: 0.9; transform: scale(0.2); }
    100% { opacity: 0; transform: scale(14); }
}

.ei-title {
    font-family: var(--font-display, Impact, sans-serif);
    font-size: clamp(3rem, 16vw, 11rem);
    font-weight: 900;
    letter-spacing: 0.02em;
    color: #ffffff;
    transform: skewX(-9deg) scale(0.2);
    opacity: 0;
    text-shadow:
        0 0 30px var(--ei-rarity),
        0 0 60px var(--ei-rarity),
        6px 6px 0 rgba(0, 0, 0, 0.55);
    -webkit-text-stroke: 2px var(--ei-rarity);
}

/* SLAM: overshoot in. */
.ei-overlay.ei-slam .ei-title {
    animation: ei-title-slam 620ms cubic-bezier(0.2, 1.5, 0.4, 1) forwards;
}
@keyframes ei-title-slam {
    0%   { opacity: 0; transform: skewX(-9deg) scale(0.2); }
    60%  { opacity: 1; transform: skewX(-9deg) scale(1.12); }
    100% { opacity: 1; transform: skewX(-9deg) scale(1); }
}

/* RUSH: keep it slammed-in, add a vibrate. */
.ei-overlay.ei-rush .ei-title {
    opacity: 1;
    transform: skewX(-9deg) scale(1);
    animation: ei-title-vibrate 90ms linear infinite;
}
@keyframes ei-title-vibrate {
    0%   { transform: skewX(-9deg) scale(1) translate(0, 0); }
    25%  { transform: skewX(-9deg) scale(1.01) translate(-2px, 1px); }
    50%  { transform: skewX(-9deg) scale(1) translate(2px, -1px); }
    75%  { transform: skewX(-9deg) scale(1.01) translate(-1px, -2px); }
    100% { transform: skewX(-9deg) scale(1) translate(1px, 2px); }
}

/* ── Banner ──
   Stamped metal: a bright top edge falls through the rarity hue to a shadowed
   base, with a single light sheen sweeping across as it lands. The murmur owns
   the *continuous* shimmer; the banner's sheen fires once so they don't compete. */
.ei-banner {
    margin-top: clamp(12px, 3vh, 28px);
    font-family: var(--font-ui, 'Segoe UI', sans-serif);
    font-size: clamp(0.85rem, 2.6vw, 1.35rem);
    font-weight: 700;
    letter-spacing: 0.34em;
    text-indent: 0.34em;
    text-transform: uppercase;
    opacity: 0;
    background-image:
        linear-gradient(105deg, transparent 42%, rgba(255, 255, 255, 0.75) 50%, transparent 58%),
        linear-gradient(180deg, #ffffff 0%, var(--ei-rarity) 52%, rgba(0, 0, 0, 0.5) 132%);
    background-size: 250% 100%, 100% 100%;
    background-position: 220% 0, 0 0;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    filter:
        drop-shadow(0 2px 5px rgba(0, 0, 0, 0.8))
        drop-shadow(0 0 9px rgba(255, 255, 255, 0.22));
    filter:
        drop-shadow(0 2px 5px rgba(0, 0, 0, 0.8))
        drop-shadow(0 0 10px color-mix(in srgb, var(--ei-rarity) 45%, transparent));
}
.ei-overlay.ei-rush .ei-banner {
    animation:
        ei-banner-in 500ms ease-out 300ms forwards,
        ei-banner-sheen 1100ms ease-in-out 900ms 1;
}
@keyframes ei-banner-in {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}
/* Sweep only the sheen layer; leave the metallic base parked. */
@keyframes ei-banner-sheen {
    from { background-position: 220% 0, 0 0; }
    to   { background-position: -120% 0, 0 0; }
}

/* ── Murmur (the room reacting) ──
   A hushed, elegant line under the banner. Rendered as living text: a
   rarity-tinted metallic gradient clipped to the glyphs sweeps slowly across,
   with a soft glow and thin ornamental rules flanking it. The JS sets the
   starting opacity (fade-in); everything below is the "fancy". */
.ei-sub {
    margin-top: clamp(10px, 2.4vh, 20px);
    font-family: var(--font-display, Georgia, 'Times New Roman', serif);
    font-style: italic;
    font-weight: 500;
    font-size: clamp(0.95rem, 3vw, 1.55rem);
    letter-spacing: 0.16em;
    text-indent: 0.16em;
    line-height: 1.35;
    /* Metallic sweep: white highlight travelling through a rarity-tinted body. */
    background-image: linear-gradient(
        100deg,
        rgba(255, 255, 255, 0.35) 0%,
        var(--ei-rarity) 26%,
        #ffffff 50%,
        var(--ei-rarity) 74%,
        rgba(255, 255, 255, 0.35) 100%
    );
    background-size: 240% auto;
    background-position: 200% center;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    /* Glow + legibility: a dark halo to lift it off the darken layer, plus a
       faint rarity bloom. drop-shadow works on the clipped glyphs. The first
       declaration is a color-mix-free fallback for older engines. */
    filter:
        drop-shadow(0 1px 6px rgba(0, 0, 0, 0.75))
        drop-shadow(0 0 11px rgba(255, 255, 255, 0.28));
    filter:
        drop-shadow(0 1px 6px rgba(0, 0, 0, 0.75))
        drop-shadow(0 0 12px color-mix(in srgb, var(--ei-rarity) 55%, transparent));
    animation: ei-sub-shimmer 3.4s linear infinite;
}

/* Thin ornamental rules that bracket the murmur, fading in from the text. */
.ei-sub::before,
.ei-sub::after {
    content: '';
    display: inline-block;
    width: clamp(14px, 5vw, 44px);
    height: 1px;
    vertical-align: middle;
    margin-bottom: 0.14em;
    -webkit-text-fill-color: initial; /* pseudo is a bar, not clipped text */
    opacity: 0.75;
}
.ei-sub::before {
    margin-right: 0.85em;
    background: linear-gradient(to right, transparent, var(--ei-rarity));
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 6px color-mix(in srgb, var(--ei-rarity) 60%, transparent);
}
.ei-sub::after {
    margin-left: 0.85em;
    background: linear-gradient(to left, transparent, var(--ei-rarity));
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 6px color-mix(in srgb, var(--ei-rarity) 60%, transparent);
}

@keyframes ei-sub-shimmer {
    from { background-position: 200% center; }
    to   { background-position: -40% center; }
}

/* ── EXIT: rush into the center point, snap flash ── */
.ei-overlay.ei-exit {
    animation: ei-exit-flash 500ms ease-in forwards;
}
@keyframes ei-exit-flash {
    0%   { background: transparent; }
    55%  { background: transparent; }
    70%  { background: var(--ei-rarity); }
    100% { background: transparent; opacity: 0; }
}
.ei-overlay.ei-exit .ei-content {
    animation: ei-content-implode 380ms cubic-bezier(0.6, 0, 0.9, 0.2) forwards;
}
@keyframes ei-content-implode {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.02); }
}
.ei-overlay.ei-exit .ei-streaks {
    animation: ei-streaks-implode 380ms ease-in forwards;
}
@keyframes ei-streaks-implode {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.05); }
}

/* ── Mobile ── */
@media (max-width: 768px) {
    .ei-banner { letter-spacing: 0.22em; text-indent: 0.22em; }
}

/* ── Reduced motion: fewer streaks (JS), no vibrate, gentler moves ── */
.ei-overlay.ei-reduced .ei-title {
    animation: none;
    opacity: 1;
    transform: skewX(-9deg) scale(1);
}
.ei-overlay.ei-reduced.ei-slam .ei-title {
    animation: ei-title-fade-in 300ms ease-out forwards;
}
@keyframes ei-title-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.ei-overlay.ei-reduced .ei-streak {
    animation-iteration-count: 1;
}
/* Hold the murmur's gradient mid-sweep (bright) instead of animating it. */
.ei-overlay.ei-reduced .ei-sub {
    animation: none;
    background-position: 50% center;
}
/* Drop the banner sheen sweep; keep the plain fade-in. */
.ei-overlay.ei-reduced.ei-rush .ei-banner {
    animation: ei-banner-in 500ms ease-out 300ms forwards;
    background-position: 0 0, 0 0;
}

@media (prefers-reduced-motion: reduce) {
    .ei-title { animation: ei-title-fade-in 300ms ease-out forwards !important; }
    .ei-streak { animation-iteration-count: 1 !important; }
    .ei-sub { animation: none !important; background-position: 50% center !important; }
    .ei-banner { animation: ei-banner-in 500ms ease-out 300ms forwards !important; background-position: 0 0, 0 0 !important; }
}
