/*
 * Ray (راي): MIT Solutions' digital agent, perched on top of the
 * floating-button stack (theme · WhatsApp · back-to-top).
 * A navy-purple robot with cat ears, LED eyes and the MIT logo in his chest
 * (master artwork: images/mascot/ray.svg). Rig, faces, idle life and the
 * binary ear signal here;
 * the moves are in assets/static/website/js/ray.js. The figure keeps its
 * colours in both themes; his speech bubble and props follow the theme.
 */
.ray {
    --w: 92px; --ink: #1a0e2e; --ex: 0; --ey: 0; --tilt: 0;
    --bub-bg: #ffffff; --bub-ink: #1a0e2e; --bub-edge: #1a0e2e; --bub-shadow: #FFB1FF; --bub-act: #8A328A; --bub-act-ink: #ffffff;
    --ray-card: #ffffff; --ray-card-edge: #8A328A; --ray-tx: #1a0e2e; --ray-hi: #8A328A;
    /* centred over the 48px button column (right 24px), standing on the top
       button: WhatsApp's top edge is at 132px, back-to-top's at 192px */
    position: fixed; z-index: 899; right: calc(48px - var(--w) / 2); bottom: 126px;
    width: var(--w); aspect-ratio: 180 / 256; pointer-events: none;
    transition: bottom .45s cubic-bezier(.3, 1.3, .5, 1);
}
[data-theme="glass"] .ray {
    --bub-bg: #241840; --bub-ink: #f6f1fc; --bub-edge: #FFB1FF; --bub-shadow: #8A328A; --bub-act: #FFB1FF; --bub-act-ink: #1a0e2e;
    --ray-card: #241840; --ray-card-edge: #FFB1FF; --ray-tx: #f6f1fc; --ray-hi: #FFF7D6;
}
/* on the night background a soft pink glow sits behind him so his dark shell reads */
[data-theme="glass"] .ray::before {
    content: ''; position: absolute; z-index: -1; inset: 6% -12% 0; pointer-events: none;
    background: radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--ray-glow, #FFB1FF) 26%, transparent), transparent 62%);
}
@media (max-width: 768px) { .ray { --w: 72px; } }
/* size (Settings → Ray → size) */
.ray[data-size=small] { --w: 76px; }
.ray[data-size=large] { --w: 108px; }
@media (max-width: 768px) { .ray[data-size=small] { --w: 62px; } .ray[data-size=large] { --w: 84px; } }
/* hops up a level when the back-to-top button joins the stack */
body:has(.back-to-top.visible) .ray { bottom: 186px; }
.ray.gone { visibility: hidden; }
.ray-svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ── pivots ── */
.ray [data-r] { transform-box: view-box; }
.ray [data-r=char], .ray [data-r=hover] { transform-origin: 118px 282px; }
.ray [data-r=torso] { transform-origin: 116px 262px; }
.ray [data-r=head], .ray [data-r=look] { transform-origin: 116px 156px; }
.ray [data-r=earL] { transform-origin: 88px 100px; }
.ray [data-r=earR] { transform-origin: 144px 100px; }
.ray [data-r=eyeL] { transform-origin: 99px 120px; }
.ray [data-r=eyeR] { transform-origin: 133px 120px; }
.ray [data-r=mouth] { transform-origin: 116px 133px; }
.ray [data-r=core], .ray [data-r=coreGlow] { transform-origin: 116px 196px; }
.ray [data-r=jet] { transform-origin: 118px 261px; }
.ray [data-r=shadow] { transform-origin: 118px 282px; }
.ray [data-r=aura] { transform-origin: 116px 150px; }
.ray [data-r=armL] { transform-origin: 81px 177px; }
.ray [data-r=foreL] { transform-origin: 81px 197px; }
.ray [data-r=armR] { transform-origin: 151px 177px; }
.ray [data-r=foreR] { transform-origin: 151px 197px; }
/* props are drawn round 0,0 and placed by the timeline */
.ray :is([data-r=beam], [data-r=scanBeam], [data-r=scanLine], [data-r=report], [data-r=holo], [data-r=site], [data-r=bars],
         [data-r=bar1], [data-r=bar2], [data-r=bar3], [data-r=orb], [data-r=cloud], [data-r=pk1], [data-r=pk2], [data-r=pk3],
         [data-r=card], [data-r=tick], [data-r=zz], [data-r=shades], [data-r=spot], [data-r=st1], [data-r=st2], [data-r=st3]) { transform-origin: 0 0; }
.ray [data-r=code1], .ray [data-r=code4] { transform-origin: -32px 0; }
.ray [data-r=code2], .ray [data-r=code3] { transform-origin: -26px 0; }
.ray [data-r=cloudFill] { transform-origin: -14px 0; }
.ray [data-r=arrow] { transform-origin: -26px -22px; }

/* ── idle life: he hovers, his thruster flickers, his seams and core breathe ── */
.ray [data-r=hover] { animation: ray-hover 3.4s ease-in-out infinite; }
@keyframes ray-hover { 50% { transform: translateY(-4px); } }
.ray .ray-shpulse { transform-box: view-box; transform-origin: 118px 282px; animation: ray-shadow 3.4s ease-in-out infinite; }
@keyframes ray-shadow { 50% { transform: scale(.86); opacity: .7; } }
.ray .ray-flame { animation: ray-flame .22s ease-in-out infinite alternate; }
@keyframes ray-flame { from { opacity: .7; } to { opacity: 1; } }
.ray .ray-seam, .ray .ray-coreglow { animation: ray-glow 2.8s ease-in-out infinite; }
@keyframes ray-glow { 50% { opacity: .55; } }
.ray [data-r=look] { transform: rotate(calc(var(--tilt) * 1deg)); transition: transform .28s ease-out; }
.ray .ray-eyes { transform-box: view-box; transform: translate(calc(var(--ex) * 1px), calc(var(--ey) * 1px)); transition: transform .13s ease-out; }
/* asleep: he has landed, so the hover stops */
.ray[data-face=sleep] [data-r=hover], .ray[data-face=sleep] .ray-shpulse { animation-play-state: paused; }
.ray[data-face=sleep] .ray-seam, .ray[data-face=off] .ray-seam { animation: none; opacity: .25; }

/* ── binary: 0s and 1s stream in from the sides and are absorbed at his ear tips ── */
.ray .ray-bit { fill: #8A328A; transform-box: fill-box; transform-origin: center; animation: ray-bit 2s cubic-bezier(.4, 0, .8, .6) infinite; }
[data-theme="glass"] .ray .ray-bit { fill: var(--ray-glow, #FFB1FF); filter: drop-shadow(0 0 2px var(--ray-glow, #FFB1FF)); }
.ray .ray-bit:nth-child(2) { animation-delay: -.33s; }
.ray .ray-bit:nth-child(3) { animation-delay: -.67s; }
.ray .ray-bit:nth-child(4) { animation-delay: -1s; }
.ray .ray-bit:nth-child(5) { animation-delay: -1.33s; }
.ray .ray-bit:nth-child(6) { animation-delay: -1.67s; }
@keyframes ray-bit { 0% { transform: translateX(var(--dx)); opacity: 0; } 20% { opacity: 1; } 80% { opacity: 1; } 100% { transform: translateX(0) scale(.5); opacity: 0; } }
/* asleep or powered off: no signal */
.ray:is([data-face=sleep], [data-face=off]) .ray-bits { display: none; }

/* ── arms ── */
.ray .ao { stroke: #2c2c5e; stroke-width: 11; stroke-linecap: round; }
.ray .ai { stroke: #5a4a9c; stroke-width: 3; stroke-linecap: round; opacity: .7; }

/* ── faces: LED eyes and mouth ── */
.ray .f, .ray .m { display: none; }
.ray[data-face=normal] .f-normal, .ray[data-face=happy] .f-happy, .ray[data-face=wide] .f-wide,
.ray[data-face=sleep] .f-sleep, .ray[data-face=busy] .f-busy, .ray[data-face=glitch] .f-glitch { display: inline; }
.ray:is([data-face=normal], [data-face=happy], [data-face=busy]) .m-smile,
.ray:is([data-face=wide], [data-face=glitch]) .m-o,
.ray:is([data-face=sleep], [data-face=off]) .m-flat { display: inline; }
.ray .ray-d { animation: ray-dot .9s ease-in-out infinite; }
.ray .ray-d2 { animation-delay: .15s; }
.ray .ray-d3 { animation-delay: .3s; }
@keyframes ray-dot { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ── occasion outfits: only today's one shows (data-fit is set from the visitor's local occasion) ── */
.ray .fit { display: none; }
.ray[data-fit=party] .fit-party, .ray[data-fit=crescent] .fit-crescent, .ray[data-fit=flag] .fit-flag, .ray[data-fit=shopping] .fit-shopping { display: inline; }
.ray .ray-swing { transform-box: view-box; animation: ray-swing 2.6s ease-in-out infinite; }
@keyframes ray-swing { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
.ray .ray-bob { transform-box: view-box; animation: ray-bob 3.4s ease-in-out infinite; }
@keyframes ray-bob { 50% { transform: translateY(-3px) rotate(-4deg); } }
.ray .ray-wave { transform-box: view-box; transform-origin: 116px 54px; animation: ray-wave 1.6s ease-in-out infinite; }
@keyframes ray-wave { 0%, 100% { transform: skewY(-5deg) scaleX(.96); } 50% { transform: skewY(5deg) scaleX(1); } }
.ray .ray-star { fill: var(--ray-hi); }
[data-theme="glass"] .ray .ray-star { filter: drop-shadow(0 0 3px var(--ray-glow, #FFB1FF)); }

/* ── props follow the theme ── */
.ray .ray-card { fill: var(--ray-card); stroke: var(--ray-card-edge); stroke-width: 1.6; stroke-linejoin: round; }
.ray .ray-tx { fill: var(--ray-tx); }
.ray .ray-hi { stroke: var(--ray-hi); }

/* click him (he glitches) or send him home with × */
.ray-hit { position: absolute; left: 20%; right: 20%; top: 6%; bottom: 6%; padding: 0; background: none; border: 0; border-radius: 45% 45% 40% 40%; cursor: pointer; pointer-events: auto; }
.ray-hit:focus-visible, .ray-x:focus-visible { outline: 2px solid #00C9C6; outline-offset: 2px; }
.ray-x { position: absolute; left: 0; top: 4%; width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 2px solid var(--ink); border-radius: 50%; background: #fff; color: var(--ink); font: 700 12px/1 system-ui, sans-serif; cursor: pointer; pointer-events: auto; opacity: 0; transition: opacity .15s; }
.ray:hover .ray-x, .ray:focus-within .ray-x { opacity: 1; }
@media (hover: none) { .ray-x { opacity: .75; } }

/* ── speech: opens away from the floating buttons ── */
.ray-bubble {
    position: absolute; right: calc(100% - 26px); bottom: 68%;
    width: max-content; max-width: 196px; padding: .55rem .8rem;
    background: var(--bub-bg); color: var(--bub-ink);
    border: 2px solid var(--bub-edge); border-radius: 14px 14px 3px 14px; box-shadow: 3px 3px 0 var(--bub-shadow);
    font: 600 .8rem/1.35 var(--font-body, system-ui, sans-serif); text-wrap: balance;
    opacity: 0; transform: scale(.6) translateY(8px); transform-origin: 100% 100%;
    transition: opacity .16s, transform .24s cubic-bezier(.3, 1.5, .5, 1);
    pointer-events: none;
}
.ray-bubble.on { opacity: 1; transform: none; }
/* while a line decodes from binary the bubble keeps its final size; wider digits are clipped, not wrapped */
.ray-bubble.is-decoding { overflow: hidden; }
.ray-bubble.has-act { pointer-events: auto; display: grid; gap: 8px; }
.ray-act {
    display: inline-flex; justify-content: center; align-items: center; gap: 6px; padding: 7px 12px;
    border-radius: 999px; background: var(--bub-act); color: var(--bub-act-ink); text-decoration: none;
    font: 800 .78rem/1 var(--font-heading, system-ui, sans-serif);
}
.ray-act:hover, .ray-act:focus-visible { filter: brightness(1.1); outline: 2px solid #00C9C6; outline-offset: 2px; }
.ray-act[hidden] { display: none; }
.ray-bubble[dir=rtl] { font-size: .86rem; line-height: 1.5; }

/* Arabic pages put the floating buttons on the left: he perches there and speaks rightwards */
[dir=rtl] .ray { right: auto; left: calc(48px - var(--w) / 2); }
[dir=rtl] .ray-bubble { right: auto; left: calc(100% - 26px); border-radius: 14px 14px 14px 3px; box-shadow: -3px 3px 0 var(--bub-shadow); transform-origin: 0 100%; }
[dir=rtl] .ray-x { left: auto; right: 0; }

@media (prefers-reduced-motion: reduce) {
    .ray, .ray [data-r], .ray .ray-shpulse, .ray .ray-flame, .ray .ray-seam, .ray .ray-coreglow, .ray .ray-d,
    .ray .ray-swing, .ray .ray-bob, .ray .ray-wave { animation: none; transition: none; }
    .ray .ray-eyes, .ray [data-r=look], .ray-bubble { transition: none; }
    .ray .ray-bits { display: none; }
}
@media print { .ray { display: none; } }
