"""Deterministic, editable vector-style artwork for !Xmas26. Requires Pillow."""
from PIL import Image, ImageDraw, ImageFilter
import math, random, struct, json, colorsys
from pathlib import Path
S=3
class Art:
    def __init__(self,w,h,bg=(0,0,0,0)):
        self.dx=0;self.w=w;self.h=h;self.im=Image.new('RGBA',(w*S,h*S),bg);self.d=ImageDraw.Draw(self.im)
    def box(self,b):return tuple(round((v+(self.dx if i%2==0 else 0))*S) for i,v in enumerate(b))
    def rect(self,b,c,r=0,outline=None,width=1):
        if r:self.d.rounded_rectangle(self.box(b),round(r*S),fill=c,outline=outline,width=round(width*S))
        else:self.d.rectangle(self.box(b),fill=c,outline=outline,width=round(width*S))
    def ellipse(self,b,c,outline=None,width=1):self.d.ellipse(self.box(b),fill=c,outline=outline,width=round(width*S))
    def poly(self,p,c):self.d.polygon([(round((x+self.dx)*S),round(y*S)) for x,y in p],fill=c)
    def line(self,p,c,w=1):self.d.line([(round((x+self.dx)*S),round(y*S)) for x,y in p],fill=c,width=max(1,round(w*S)),joint='curve')
    def arc(self,b,a,z,c,w=1):self.d.arc(self.box(b),a,z,fill=c,width=max(1,round(w*S)))
    def image(self):return self.im.resize((self.w,self.h),Image.Resampling.LANCZOS)

def room(wide=False):
    extra=94 if wide else 0;span=600+extra
    a=Art(span,390,'#344450')
    for y in range(290):
        t=y/290;a.rect((0,y,span,y+1),(round(37+15*t),round(53+13*t),round(65+13*t)))
    # Wall panelling, a snowy garden, and linen curtains.
    for x in (18,150,312+extra,590+extra):a.line([(x,0),(x,288)],'#53616a',.7)
    a.rect((24,31,144,218),'#1d2c38',3);a.rect((29,36,139,212),'#718794',2)
    a.rect((33,40,135,208),'#213d59')
    a.ellipse((48,53,74,79),'#e7e7d1');a.ellipse((53,48,77,72),'#213d59')
    a.poly([(33,165),(56,151),(84,164),(113,149),(135,162),(135,208),(33,208)],'#c0d4dd')
    for x,y,h in ((43,164,46),(93,163,66),(124,164,38)):
        a.poly([(x,y-h),(x-13,y),(x+13,y)],'#355567');a.line([(x,y-h),(x-9,y-10)],'#a9cad9',1)
    a.rect((81,38,85,211),'#7c939b');a.rect((31,123,137,127),'#7c939b')
    a.rect((19,214,150,220),'#d6d6ce',1)
    a.rect((16,26,27,220),'#b5b6ac',3);a.rect((142,26,153,220),'#b5b6ac',3)
    a.line([(15,25),(155,25)],'#ba9a68',3)
    # Deep burgundy carpet with a fine, low-contrast woven texture.
    a.rect((0,286,span,390),'#48121f')
    for y in range(287,390):
        t=(y-287)/103;a.line([(0,y),(span,y)],(round(65+14*t),round(15+6*t),round(28+6*t)),1)
    rng=random.Random(265)
    for _ in range(5500):
        x=rng.randrange(span);y=rng.randrange(291,390)
        a.line([(x,y),(x+.4,y+.25)],'#652334' if rng.randrange(2) else '#3f1421',.25)
    a.rect((0,280,span,288),'#d4cbbc');a.rect((0,287,span,291),'#6f665c')
    a.dx=32 if wide else 0
    a.ellipse((62,300,329,382),'#725d51');a.ellipse((65,299,326,379),'#c9b49a')
    a.ellipse((71,305,320,374),None,'#daceb9',1.3)
    # Toy railway; foreground tree and gifts are a separate occlusion layer.
    for n in range(64):
        t=n*math.tau/64
        a.line([(204+100*math.cos(t),337+26*math.sin(t)),(204+111*math.cos(t),337+33*math.sin(t))],'#7c685a',2)
    a.ellipse((99,307,309,367),None,'#e1d9c5',1.6)
    a.ellipse((104,310,304,364),None,'#665d50',.8)
    a.dx=extra
    # Floating media cabinet with book spines and ceramic objects.
    a.rect((324,176,560,225),'#263139',4);a.rect((320,171,558,219),'#986d49',3)
    a.rect((320,172,558,177),'#c49a6d',2)
    for x in (400,481):a.line([(x,179),(x,217)],'#725136',1)
    for x in (373,454,533):a.line([(x,185),(x+9,185)],'#d8bd8e',1)
    for x,w,h,c in ((329,9,24,'#c49f71'),(339,7,27,'#b76255'),(347,10,21,'#e4cdb1')):a.rect((x,170-h,x+w,170),c,1)
    a.ellipse((537,143,552,171),'#cec5b4');a.line([(544,151),(546,130)],'#92a28c',1.4)
    a.ellipse((546,128,555,134),'#809784');a.ellipse((538,134,546,140),'#809784')
    # Flat-screen television, flush mounted to the wall.
    a.rect((330,43,537,162),'#26313a',5);a.rect((327,39,534,158),'#121c25',4)
    a.rect((333,45,528,151),'#080d12',2);a.ellipse((523,153,524.5,154.5),'#9aaf97')
    # Mid-century sofa with two cushions and a knitted throw.
    a.ellipse((309,298,434,317),'#896b52')
    a.rect((313,236,429,301),'#b9b7a5',10);a.rect((320,231,422,278),'#d3cbb6',9)
    a.line([(371,238),(371,275)],'#b6b19f',1)
    a.rect((317,271,425,299),'#c6c2ad',8)
    a.rect((308,255,323,300),'#ded4bc',6);a.rect((419,255,435,300),'#ded4bc',6)
    a.line([(319,298),(317,312)],'#4e4234',4);a.line([(426,299),(429,312)],'#4e4234',4)
    a.rect((323,244,347,269),'#8e4b4f',5)
    a.poly([(393,257),(416,257),(420,298),(401,302)],'#718b88')
    for x in range(395,417,4):a.line([(x,260),(x+5,300)],'#90a19a',.65)
    # Dog bed under the computer, a little forward of the desk legs. It stays
    # on the left in both room layouts; the aquarium still moves with the wall.
    a.dx=0
    a.ellipse((6,343,109,387),'#6d5d51');a.ellipse((8,340,107,382),'#8c9790');a.ellipse((15,345,100,375),'#5a706e')
    a.dx=extra
    a.rect((450,272,580,343),'#6d513d',4);a.rect((446,270,584,277),'#bb926a',2)
    a.rect((454,280,576,338),'#8c6748',2);a.line([(516,280),(516,339)],'#644b36',1)
    a.ellipse((508,305,510,307),'#d4ba87');a.ellipse((522,305,524,307),'#d4ba87')
    a.rect((450,194,580,270),'#152b37',3);a.rect((454,200,576,266),'#214e62',1)
    for y in range(201,260):
        t=(y-201)/59;a.line([(455,y),(575,y)],(int(49-21*t),int(109-30*t),int(126-27*t)),1)
    a.rect((455,258,575,265),'#a69775');a.line([(457,203),(573,203)],'#b3d8d6',1)
    rng=random.Random(20)
    for _ in range(60):
        x=rng.randrange(455,575);y=rng.randrange(259,265);a.ellipse((x,y,x+1,y+1),'#c4b695')
    for x,h in ((464,30),(470,21),(558,34),(566,25)):
        a.line([(x,259),(x-3,259-h/2),(x+1,259-h)],'#6e9c78',2)
        for yy in range(260-h,254,7):
            a.line([(x,yy+3),(x-6,yy)],'#80a487',2);a.line([(x,yy+5),(x+6,yy+1)],'#80a487',2)
    a.ellipse((485,252,505,263),'#657c7b');a.ellipse((501,255,514,263),'#768583')
    a.line([(455,201),(455,264)],'#b4d2d1',1);a.line([(575,201),(575,264)],'#688f9a',1)
    a.rect((449,192,581,198),'#1b3039',2);a.line([(457,193),(574,193)],'#758f94',1)
    # Embroidered "Home Sweet Home" sampler, drawn as individual cross stitches.
    a.rect((264,62,307,115),'#9c7955',2);a.rect((267,65,304,112),'#e7dcc4')
    a.rect((269,67,302,110),'#eee4ce',outline='#c9b698',width=.6)
    # Quiet linen and clean, joined stitching: subpixel cross-hatching became
    # noisy blocks when the native indexed sprite was enlarged to fullscreen.
    a.line([(270,69),(301,69)],'#d4c4a6',.65)
    a.line([(270,108),(301,108)],'#d4c4a6',.65)
    letters={
      'H':['10001','10001','10001','11111','10001','10001','10001'],
      'O':['01110','10001','10001','10001','10001','10001','01110'],
      'M':['10001','11011','10101','10101','10001','10001','10001'],
      'E':['11111','10000','10000','11110','10000','10000','11111'],
      'S':['01111','10000','10000','01110','00001','00001','11110'],
      'W':['10001','10001','10001','10101','10101','10101','01010'],
      'T':['11111','00100','00100','00100','00100','00100','00100']}
    for word,y in [('HOME',71),('SWEET',83),('HOME',95)]:
        x=285.5-(len(word)*6-1)/2
        for ch in word:
            for yy,row in enumerate(letters[ch]):
                for xx,bit in enumerate(row):
                    if bit=='1':
                        a.rect((x+xx,y+yy,x+xx+.7,y+yy+.7),'#422331')
            x+=6
    a.line([(275,106),(296,106)],'#859879',.55)
    a.poly([(283,105),(284.5,104),(286,105),(287.5,104),(289,105),(286,108)],'#9b555c')
    a.line([(292,187),(292,284)],'#c1a271',2);a.ellipse((279,280,306,287),'#554b40')
    # Warm linen shade: curved crown, lit centre, pleats, weave and rolled rims.
    a.poly([(276,160),(306,160),(313,188),(269,188)],'#c3ac80')
    for xx in range(270,313):
        q=(xx-291)/22;top=160+max(0,abs(q)*4-2)
        if xx<276:top=160+(276-xx)*4
        if xx>306:top=160+(xx-306)*4
        glow=max(0,1-q*q);pleat=math.cos((xx-270)*math.pi/3)*5
        c=(round(190+43*glow+pleat),round(165+43*glow+pleat),round(117+45*glow+pleat))
        a.line([(xx,top),(xx,187)],c,.9)
    for yy in range(164,187,3):
        half=15+(yy-160)/4
        a.line([(291-half,yy),(291+half,yy)],'#cdb68b',.25)
    a.ellipse((276,157.8,306,163.2),'#a89372');a.arc((276,157.8,306,163.2),0,180,'#f3dfb5',1)
    a.arc((269,182,313,191),0,180,'#baa078',1.5);a.arc((269,182,313,190),0,180,'#f5dfb3',1)
    a.line([(276,161),(269,187)],'#ac946e',.7);a.line([(306,161),(313,187)],'#ae956b',.7)
    # Ceiling moulding and five hanging tinsel swags.
    a.dx=0
    a.rect((0,0,span,3),'#71858b');a.line([(0,4),(span,4)],'#243841',1)
    rng=random.Random(244)
    for swag in range(5):
        x0=swag*span/5;x1=x0+span/5
        silver=swag%2==0
        colours=['#dbeaf0','#8caeb8','#f0fafb','#65888f'] if silver else ['#e7c678','#ad873d','#fff1b3','#8c6932']
        points=[]
        for n in range(121):
            x=x0+n*span/600;y=5+17*math.sin(math.pi*n/120)
            points.append((x,y))
            for side in (-1,1):
                length=rng.uniform(1.2,3.7);dx=rng.uniform(-1.9,1.9)
                a.line([(x,y),(x+dx,y+length*side)],colours[rng.randrange(4)],.65)
        a.line(points,colours[1],.6)
        a.ellipse((x0-1.5,3,x0+1.5,6),'#dfc78c')
        a.poly([(x0+58,20),(x0+52,17),(x0+52,23),(x0+58,22),(x0+64,17),(x0+65,23)],'#ae3d48')
    return a.image()

LIGHTS=[]
def tree():
    a=Art(214,311);cx=108
    # No opaque mat: the railway and the room's cream rug show through here.
    a.rect((99,233,117,281),'#6e4c34',2)
    a.poly([(86,267),(130,267),(124,294),(92,294)],'#a8895c')
    layers=[(26,90,66),(65,113,92),(103,152,119),(145,191,149),(183,230,180),(218,270,201)]
    for idx,(top,bottom,width) in enumerate(layers):
        a.poly([(cx,top),(cx-width*.47,bottom-5),(cx-width*.34,bottom-2),(cx-width*.25,bottom+2),(cx,bottom+8),(cx+width*.24,bottom+2),(cx+width*.38,bottom),(cx+width*.5,bottom-7)],['#315b4b','#2f5a48','#2c5847','#2b5544','#294f40','#264b3c'][idx])
        a.line([(cx-3,top+12),(cx-width*.38,bottom-7)],'#547458',1)
        a.line([(cx+4,top+15),(cx+width*.36,bottom-7)],'#42694f',.8)
    rng=random.Random(99)
    # Fir needles and layered branchlets give depth without hiding the LED wire.
    for idx,(top,bottom,width) in enumerate(layers):
        for side in (-1,1):
            for level in range(3):
                yy=bottom-5-level*9;reach=width*(.40-level*.065)
                branch=[(cx,yy-13),(cx+side*reach*.55,yy-4),(cx+side*reach,yy)]
                a.line(branch,'#1c4438',1.3)
                for n in range(3,12):
                    xx=cx+side*reach*n/12;by=yy-11*(1-n/12)
                    a.line([(xx,by),(xx+side*3.3,by-3.1)],'#71906b',.55)
                    a.line([(xx,by),(xx+side*3.6,by+1.4)],'#3c7056',.6)
    for _ in range(210):
        y=rng.randrange(47,265);half=(y-23)*.37;x=cx+rng.uniform(-half,half)
        a.line([(x,y),(x-3,y+3)],'#52704f',.6)
    wire=[]
    for n in range(161):
        t=n/160;y=50+207*t;x=cx+math.sin(t*math.pi*7.3)*(13+72*t);wire.append((x,y))
    a.line(wire,'#9f9560',.8)
    LIGHTS.clear()
    for n in range(30):
        t=(n+.3)/30;y=50+207*t;x=cx+math.sin(t*math.pi*7.3)*(13+72*t)
        LIGHTS.append((round(x)+98,round(y)+28,n%5,n*31+17,310+(n*37)%330))
    for x,y,c in [(103,71,'#b64d4b'),(121,106,'#c9aa68'),(76,128,'#ccbd97'),(131,151,'#a64d55'),(82,175,'#b87853'),(151,199,'#ccb678'),(63,216,'#9caeae'),(110,228,'#c36354'),(166,246,'#a85d4b')]:
        a.line([(x,y-5),(x,y)],'#b6a46c',.6);a.ellipse((x-4,y,x+4,y+8),c);a.ellipse((x-2,y+1,x,y+3),'#e6cf9e')
    # Fine gold bead garlands, striped candy canes, and glass ornaments.
    for y0,half in [(101,25),(154,45),(208,64),(250,80)]:
        for n in range(31):
            x=cx-half+2*half*n/30;y=y0+9*math.sin(math.pi*n/30)
            a.ellipse((x-.65,y-.65,x+.65,y+.65),'#d4b773')
    for x,y in [(99,121),(141,177),(64,240),(128,253)]:
        a.arc((x-2,y,x+4,y+6),185,360,'#f1e5c9',1.8)
        a.line([(x+4,y+3),(x+4,y+13)],'#f1e5c9',1.8)
        for yy in range(y+4,y+13,4):a.line([(x+3.3,yy),(x+4.7,yy+1.5)],'#be454d',1)
    for x,y,c in [(88,152,'#c14157'),(120,198,'#bc9548'),(51,259,'#467b9b'),(170,229,'#bc6470')]:
        a.line([(x,y-5),(x,y)],'#d7c18c',.6)
        a.rect((x-1.5,y-1,x+1.5,y+1),'#d9b572')
        a.ellipse((x-4,y,x+4,y+9),c)
        a.arc((x-3,y+1,x+3,y+8),20,150,'#e0c487',.6)
        a.ellipse((x-2.4,y+1.2,x-.5,y+3.4),'#f7ead0')
    pts=[]
    for i in range(10):
        t=-math.pi/2+i*math.pi/5;r=11 if i%2==0 else 4.8;pts.append((cx+math.cos(t)*r,23+math.sin(t)*r))
    a.poly(pts,'#f1cd78');a.line([pts[0],(cx,23),pts[2]],'#fff0b5',.7)
    # Wrapped presents around the trunk; ribbon and bows are visible at small scale.
    for x,y,w,h,col,ribbon in [(25,275,40,25,'#9b4d52','#d9b679'),(62,284,37,23,'#d2c5a5','#a75053'),(92,279,46,29,'#557f8a','#e2bf76'),(135,285,47,20,'#bd8060','#e0cfaa'),(150,263,30,28,'#c0b58f','#8a484d')]:
        a.rect((x,y,x+w,y+h),col,1);a.rect((x,y-2,x+w,y+2),col,1)
        a.rect((x+w*.44,y-2,x+w*.56,y+h),ribbon);a.rect((x,y+h*.34,x+w,y+h*.47),ribbon)
        a.arc((x+w/2-9,y-7,x+w/2,y+1),170,360,ribbon,1.5);a.arc((x+w/2,y-7,x+w/2+9,y+1),180,370,ribbon,1.5)
    return a.image()

def bulb(col,level):
    a=Art(15,15);rgb=tuple(int(col[i:i+2],16) for i in (1,3,5))
    if level==0:
        # Unlit glass retains its hue; a dim red lamp is still visibly red.
        dim=tuple(round(v*.28+8) for v in rgb)
        rim=tuple(round(v*.19+6) for v in rgb)
        a.ellipse((4.5,4.5,9.5,9.5),dim,outline=rim,width=.6)
        im=a.image();im.putpixel((7,7),(*dim,255));return im
    bright=(level/7)**.6
    # Saturated emitter, a near-white hot core, and a larger coloured bloom.
    for rad,f in ((6.8,.23),(5.3,.42),(3.8,.8),(2.5,1)):
        c=tuple(min(255,round(v*bright*f+base*(1-f))) for v,base in zip(rgb,(36,76,57)))
        a.ellipse((7-rad,7-rad,7+rad,7+rad),c)
    hot=tuple(round((v*.28+255*.72)*bright) for v in rgb)
    a.ellipse((5.55,5.55,8.45,8.45),hot)
    white=round(255*bright)
    a.ellipse((6.2,6.2,7.8,7.8),(white,white,white))
    im=a.image();im.putpixel((7,7),(white,white,white,255))
    return im

def fire(frame,tiled=False):
    a=Art(190,100,'#0d1015');t=frame*math.tau/24
    for y in range(100):
        glow=math.exp(-((y-69)/31)**2);a.line([(0,y),(190,y)],(int(13+21*glow),int(16+6*glow),17),1)
    # Tall flames behind the fuel, with a glowing ember bed below it.
    a.ellipse((21,81,169,98),'#5c281c')
    tongues=((23,0),(57,1.3),(95,2.1),(133,3.7),(167,4.8)) if tiled else ((23,0),(52,1.3),(83,2.1),(112,3.7),(144,4.8))
    for x,ph in tongues:
        h=31+9*math.sin(t+ph)+5*math.sin(2*t+ph);lean=7*math.sin(t+ph+.7)
        pts=[(x-12,84),(x-13,68),(x-5,60),(x+lean,84-h),(x+7,64),(x+13,71),(x+13,84)]
        a.poly(pts,'#a84d2a');a.poly([(x-8,85),(x-7,69),(x+lean*.6,89-h*.84),(x+6,71),(x+9,85)],'#df873c')
        a.poly([(x-4,86),(x-3,75),(x+lean*.3,92-h*.55),(x+5,80),(x+6,86)],'#f4c26b')
    a.line([(26,88),(144,80)],'#5a3729',9);a.line([(48,80),(163,89)],'#73432b',8)
    a.line([(28,85),(140,78)],'#b66538',1.2);a.line([(51,77),(161,86)],'#ad6538',1)
    # Charred bark and incandescent cracks stay attached to the logs.
    for x in range(36,153,13):
        y=80+(x-48)*9/115
        a.line([(x-2,y-2),(x,y+1),(x-2,y+3)],'#211d1c',1.4)
        a.line([(x,y),(x+3,y+1),(x+5,y-.5)],'#ef9a42',.8)
    a.ellipse((155,85,166,93),'#41271e');a.arc((157,86,164,92),20,310,'#a66032',1)
    # Smaller front tongues visibly lick around and over the burning wood.
    fronts=[(23,.2),(57,2),(95,3.5),(133,5),(167,1.1)] if tiled else [(47,.2),(79,2),(116,3.5),(145,5)]
    for x,ph in fronts:
        h=8+5*(1+math.sin(t+ph));lean=3*math.sin(t*2+ph)
        a.poly([(x-6,91),(x-4,85),(x+lean,91-h),(x+3,85),(x+6,91)],'#ed8c35')
        a.poly([(x-3,91),(x+lean*.4,92-h*.65),(x+3,91)],'#ffe0a0')
    for i in range(18):
        x=21+i*8;y=92+2*math.sin(t+i);c='#e1a053' if (i+frame)%7<3 else '#884b2c';a.ellipse((x,y,x+2,y+1),c)
    return a.image()

def sleeping_cat(frame):
    a=Art(85,48);breath=(1-math.cos(frame*math.tau/12))/2
    a.ellipse((11,18-3.5*breath,72,43),'#ae7150');a.ellipse((16,20-3*breath,65,41),'#c59364')
    a.arc((13,18,70,43),0,270,'#865a45',5)
    for x in (36,44,52):a.arc((x-3,20-2.5*breath,x+5,33),160,280,'#9d684b',1.5)
    a.ellipse((12,20,35,40),'#c69468');a.poly([(13,26),(14,15),(22,23)],'#b6805b');a.poly([(25,23),(32,16),(33,29)],'#b6805b')
    a.line([(16,29),(19,30),(22,29)],'#4e3d36',1);a.line([(25,29),(28,30),(30,29)],'#4e3d36',1)
    a.poly([(22,32),(25,32),(23.5,34)],'#895d55');a.line([(13,33),(20,34)],'#e0c19b',.6)
    a.ellipse((25,35,41,41),'#d1a87b')
    return a.image()

def cat(frame):
    out=Image.new('RGBA',(85,88))
    if frame<12:
        out.alpha_composite(sleeping_cat(frame),(0,40));return out
    t=(frame-12)/6
    # Two seconds to sit up, ten seconds looking around, two to curl back down.
    rise=min(1,t/2) if t<12 else max(0,(14-t)/2)
    p=rise*rise*(3-2*rise)
    if p<.002:
        out.alpha_composite(sleeping_cat(0),(0,40));return out
    a=Art(85,88)
    def blend(v,w):return v+(w-v)*p
    def box(rest,upright):return tuple(blend(v,w) for v,w in zip(rest,upright))
    a.ellipse(box((11,58,72,83),(29,29,66,84)),'#ae7150')
    a.ellipse(box((16,60,65,81),(34,31,63,81)),'#c59364')
    a.arc(box((13,58,70,83),(24,64,73,86)),0,270,'#865a45',5)
    for j in range(3):
        a.arc(box((33+j*8,60,41+j*8,73),(35,43+j*8,62,51+j*8)),160,300,'#9d684b',1.5)
    for xx in (37,51):a.ellipse(box((25,75,41,81),(xx,58,xx+9,84)),'#d1a87b')
    look=math.sin(max(0,t-2)*math.pi/3)*3*p
    hx=blend(12,35)+look;hy=blend(60,8)
    a.ellipse((hx,hy,hx+25,hy+23),'#c69468')
    a.poly([(hx+1,hy+7),(hx+2,hy-7),(hx+10,hy+3)],'#b6805b')
    a.poly([(hx+15,hy+3),(hx+23,hy-6),(hx+24,hy+10)],'#b6805b')
    a.poly([(hx+3,hy+2),(hx+4,hy-3),(hx+7,hy+3)],'#d1a29a')
    a.poly([(hx+18,hy+3),(hx+21,hy-2),(hx+22,hy+5)],'#d1a29a')
    eye=p*(0 if abs(t-5)<.14 or abs(t-9)<.14 else 1)
    for ex in (7,18):
        if eye>.2:
            a.ellipse((hx+ex-2,hy+10-1.4*eye,hx+ex+2,hy+10+1.4*eye),'#d6c777')
            a.ellipse((hx+ex-.45+look*.18,hy+9,hx+ex+.45+look*.18,hy+11.5),'#443b2f')
        else:a.line([(hx+ex-2,hy+10),(hx+ex,hy+11),(hx+ex+2,hy+10)],'#4e3d36',1)
    a.poly([(hx+11,hy+14),(hx+14,hy+14),(hx+12.5,hy+16)],'#895d55')
    for dx in (-1,1):
        a.line([(hx+12.5+dx*3,hy+16),(hx+12.5+dx*12,hy+14)],'#e0c19b',.6)
        a.line([(hx+12.5+dx*3,hy+17),(hx+12.5+dx*12,hy+18)],'#e0c19b',.6)
    return a.image()

def cat_return(frame):
    """Eight-second return: tucked jump, stand, knead, lower and curl asleep."""
    t=frame/8
    if frame>=63:
        out=Image.new('RGBA',(85,88));out.alpha_composite(sleeping_cat(0),(0,40));return out
    a=Art(85,88)
    curl=max(0,min(1,(t-5.5)/2.375));p=curl*curl*(3-2*curl)
    knead=math.sin((t-3.75)*math.tau*1.6) if 3.75<=t<5.5 else 0
    flight=math.sin(min(1,t/2.5)*math.pi) if t<2.5 else 0
    sway=1.6*knead*(1-p)
    def blend(v,w):return v+(w-v)*p
    def box(stand,rest):return tuple(blend(v,w) for v,w in zip(stand,rest))
    # Four paws stay on the cushion during the standing pause; alternate
    # forepaws knead before the limbs gradually tuck beneath the chest.
    for j,x in enumerate((29,59,21,67)):
        lift=(max(0,knead if j%2 else -knead)*3 if j in (0,2) else 0)+flight*15
        a.ellipse(box((x,56,x+9,83-lift),(25,75,41,81)),'#ae7150' if j<2 else '#d1a87b')
    a.ellipse(box((18+sway,39,74+sway,68),(11,58,72,83)),'#ae7150')
    a.ellipse(box((24+sway,41,69+sway,64),(16,60,65,81)),'#c59364')
    a.arc(box((53,36-flight*7,81,73),(13,58,70,83)),0,270,'#865a45',5)
    for x in (36,44,52):a.arc(box((x-3+sway,41,x+5+sway,57),(x-3,60,x+5,73)),160,280,'#9d684b',1.5)
    hx=blend(10+sway,12);hy=blend(33+abs(knead)*1.2,60)
    a.ellipse((hx,hy,hx+23,hy+20),'#c69468')
    a.poly([(hx+1,hy+6),(hx+2,hy-5),(hx+10,hy+3)],'#b6805b')
    a.poly([(hx+13,hy+3),(hx+20,hy-4),(hx+21,hy+9)],'#b6805b')
    for ex in (7,17):
        if p<.65:
            a.ellipse((hx+ex-2,hy+8,hx+ex+2,hy+11),'#d6c777')
            a.line([(hx+ex-.6,hy+8),(hx+ex-.6,hy+11)],'#443b2f',1)
        else:a.line([(hx+ex-3,hy+9),(hx+ex,hy+10),(hx+ex+3,hy+9)],'#4e3d36',1)
    a.poly([(hx+10,hy+12),(hx+13,hy+12),(hx+11.5,hy+14)],'#895d55')
    a.line([(hx+1,hy+13),(hx+8,hy+14)],'#e0c19b',.6)
    if p>.5:a.ellipse(box((26,75,41,81),(25,75,41,81)),'#d1a87b')
    return a.image()

def dog(frame):
    a=Art(102,59);breath=(1-math.cos((frame%12)*math.tau/12))/2
    a.ellipse((20,12-4*breath,91,48),'#8c6045');a.ellipse((29,14-3.6*breath,86,45),'#ad8057')
    a.ellipse((58,29,95,49),'#967049');a.arc((51,25,95,49),330,200,'#c29b6c',5)
    a.ellipse((11,21,43,46),'#ba9063');a.ellipse((10,20,24,43),'#694b3b');a.ellipse((33,21,45,43),'#71513c')
    a.ellipse((20,36,44,49),'#d2b38a');a.ellipse((30,37,38,42),'#3e3530')
    openness=0
    if frame>=12:
        t=(frame-12)/6
        openness=min(1,t/.7,(6-t)/.7)
        for at in (2,4):openness=min(openness,min(1,abs(t-at)/.22))
    for ex in (26,37):
        if openness>.15:
            a.ellipse((ex-2.6,32-1.8*openness,ex+2.6,32+1.8*openness),'#ddc7a4')
            a.ellipse((ex-.7,31,ex+1.2,33.3),'#493b2b')
        else:a.line([(ex-3,32),(ex,33),(ex+3,32)],'#43372e',1)
    a.ellipse((40,42,62,49),'#bc976c');a.ellipse((44,45,66,51),'#c4a279')
    return a.image()

def fish(kind,phase,left):
    a=Art(24,14);cols=[('#e8ab60','#f0ce90'),('#b9d3d7','#e2e8de'),('#b7736a','#daa28b')];c,light=cols[kind]
    tail=2 if phase==0 else 4
    a.poly([(8,7),(1,tail),(2,14-tail)],c);a.ellipse((6,3,22,11),c)
    a.poly([(12,4),(15,0),(17,5)],light);a.line([(11,8),(18,8)],light,.8);a.ellipse((18,5,19.5,6.5),'#283d45')
    im=a.image();return im.transpose(Image.Transpose.FLIP_LEFT_RIGHT) if left else im

def train(engine,angle):
    # The camera is fixed: rotate the model around its vertical axis, NEVER
    # rotate the rendered bitmap. Ground-plane foreshortening matches the rails.
    a=Art(40,40);heading=math.radians(angle);co=math.cos(heading);si=math.sin(heading);faces=[]
    def world(v):
        x,y,z=v;return (x*co-y*si,x*si+y*co,z)
    def project(v):
        x,y,z=world(v);return (20+x,28+y*(30/105)-z)
    def face(points,col):
        depth=sum(world(v)[1]+world(v)[2]*(30/105) for v in points)/len(points)
        faces.append((depth,points,col))
    def box(x0,y0,z0,x1,y1,z1,col):
        rgb=tuple(int(col[i:i+2],16) for i in (1,3,5))
        def shade(k):return tuple(min(255,round(v*k)) for v in rgb)
        face([(x0,y0,z1),(x1,y0,z1),(x1,y1,z1),(x0,y1,z1)],shade(1.14))
        for yy,normal in ((y0,-co),(y1,co)):
            if normal>0:face([(x0,yy,z0),(x1,yy,z0),(x1,yy,z1),(x0,yy,z1)],shade(.95))
        for xx,normal in ((x0,-si),(x1,si)):
            if normal>0:face([(xx,y0,z0),(xx,y1,z0),(xx,y1,z1),(xx,y0,z1)],shade(.77))
    # All wheels stay below the body, including at the two end-on orientations.
    for yy in (-6.1,6.1):
        if yy*co>=0:
            for xx in (-10,9):
                face([(xx+3*math.cos(i*math.tau/16),yy,3.2+3*math.sin(i*math.tau/16)) for i in range(16)],'#202b30')
                face([(xx+1.4*math.cos(i*math.tau/12),yy*1.01,3.2+1.4*math.sin(i*math.tau/12)) for i in range(12)],'#c5a775')
    box(-17,-1,2,17,1,3,'#62676a');box(-14,-5.5,4,14,5.5,7,'#b64f40')
    if engine:
        box(-13,-5,7,-2,5,18,'#235a4c')
        box(-14,-6,18,-1,6,20,'#d6b57b')
        box(-2,-4,7,13,4,13,'#357661')
        box(8,-2.2,13,11,2.2,20,'#2a3937');box(7.5,-2.7,19,11.5,2.7,21,'#d6b57b')
        box(13,-2,9,14.5,2,12,'#ffe3a2')
        for yy in (-5.05,5.05):
            if yy*co>0:face([(-11,yy,11),(-4,yy,11),(-4,yy,16),(-11,yy,16)],'#c4e7e4')
    else:
        box(-13,-5,7,13,5,16,'#ad443b');box(-14,-6,16,14,6,19,'#e7c98e')
        for yy in (-5.05,5.05):
            if yy*co>0:
                for xx in (-10,-3,4):face([(xx,yy,10),(xx+5,yy,10),(xx+5,yy,14),(xx,yy,14)],'#c4e7e4')
    for _,points,col in sorted(faces,key=lambda f:f[0]):a.poly([project(v) for v in points],col)
    return a.image()

def startled_cat(frame):
    a=Art(85,88);t=frame/6
    rise=min(1,t/.7) if t<6.5 else max(0,(8-t)/1.5);p=rise*rise*(3-2*rise)
    a.ellipse((11,58,72,83),'#ae7150');a.ellipse((16,60,65,81),'#c59364');a.arc((13,58,70,83),0,270,'#865a45',5)
    for x in (36,44,52):a.arc((x-3,60,x+5,73),160,280,'#9d684b',1.5)
    a.ellipse((25,75,41,81),'#d1a87b')
    hx=12+14*p+min(4,max(0,t-1))*p;hy=60-23*p
    a.ellipse((hx,hy,hx+25,hy+23),'#c69468')
    a.poly([(hx+1,hy+6),(hx+2,hy-6),(hx+10,hy+3)],'#b6805b')
    a.poly([(hx+15,hy+3),(hx+23,hy-5),(hx+24,hy+10)],'#b6805b')
    for ex in (7,18):
        if p>.2:
            a.ellipse((hx+ex-2.5,hy+10-2*p,hx+ex+2.5,hy+10+2*p),'#e5d77b')
            look=1.1*min(1,max(0,t-1)/3)
            a.ellipse((hx+ex-.6+look,hy+8.7,hx+ex+.5+look,hy+11.5),'#352a23')
        else:a.line([(hx+ex-2,hy+10),(hx+ex,hy+11),(hx+ex+2,hy+10)],'#4e3d36',1)
    a.poly([(hx+11,hy+14),(hx+14,hy+14),(hx+12.5,hy+16)],'#895d55')
    for side in (-1,1):a.line([(hx+12.5+side*3,hy+16),(hx+12.5+side*11,hy+15)],'#e0c19b',.6)
    return a.image()

def mouse(frame):
    a=Art(30,20);bounce=math.sin(frame*math.tau/8)*.5
    a.line([(12,13),(6,14),(2,11),(1,8)],'#b58e92',1.2)
    a.ellipse((8,6+bounce,23,16+bounce),'#b6b8bc');a.ellipse((14,7+bounce,26,15+bounce),'#c9cbcb')
    a.ellipse((16,2+bounce,23,10+bounce),'#c8b1b6');a.ellipse((18,4+bounce,22,8+bounce),'#e0bec4')
    a.poly([(22,10+bounce),(28,13+bounce),(22,15+bounce)],'#c9cbcb')
    a.ellipse((22,9+bounce,23.5,10.5+bounce),'#252b31');a.ellipse((26,12+bounce,28,14+bounce),'#b6858d')
    step=math.sin(frame*math.tau/8)*2
    a.line([(12,14),(11+step,18)],'#ba9a9d',1.3);a.line([(22,14),(22-step,18)],'#ba9a9d',1.3)
    return a.image()

def spider(frame):
    a=Art(30,30);phase=frame%4
    for side in (-1,1):
        for j in range(4):
            dx=side*(10+(j%2)*2);y=7+j*4;wiggle=(phase%2*2-1)*(1 if j%2 else -1)
            a.line([(15+side*3,12+j),(15+dx,y+wiggle),(15+side*13,y+4+wiggle)],'#35333e',1.1)
    a.ellipse((9,7,21,22),'#45414d');a.ellipse((10,6,20,16),'#6a6370')
    for ex in (12,18):
        if frame<4:
            a.ellipse((ex-2,8,ex+2,12),'#f7f0d7');a.ellipse((ex-.5,9,ex+.5,11),'#282530')
        else:a.line([(ex-2,10),(ex+2,10)],'#e4d9bc',1)
    return a.image()

def castle():
    a=Art(40,38)
    a.ellipse((2,32,39,38),'#546b70')
    a.rect((10,13,30,36),'#9d9fa7',2)
    for x in (2,28):
        a.rect((x,7,x+10,35),'#adb2bc',1)
        a.poly([(x-2,8),(x+5,0),(x+12,8)],'#79678d')
        a.rect((x+3,12,x+7,19),'#334d5e',2)
    a.rect((12,10,28,15),'#bfc3ca')
    for x in (12,18,24):a.rect((x,7,x+3,12),'#bfc3ca')
    a.rect((16,23,25,36),'#2b4e60',4)
    for y in (18,23,29):
        a.line([(11,y),(29,y)],'#747e8b',.7)
        for x in (13+(y%2)*5,24):a.line([(x,y),(x,y+4)],'#747e8b',.7)
    a.line([(4,9),(4,32)],'#ced5da',.7);a.line([(30,9),(30,32)],'#ced5da',.7)
    return a.image()

def crown(kind):
    a=Art(12,8);col=['#e74f55','#69cb70','#b886e9'][kind]
    a.poly([(0,1),(3,4),(6,0),(9,4),(12,1),(11,8),(1,8)],col)
    a.line([(1,7),(11,7)],'#ffe9ac',1);a.ellipse((5,4,7,6),'#ffe9ac')
    return a.image()

def party_fish(kind,phase,left):
    im=Image.new('RGBA',(24,24));im.alpha_composite(fish(kind,phase,False),(0,10))
    im.alpha_composite(crown(kind),(12,4))
    return im.transpose(Image.Transpose.FLIP_LEFT_RIGHT) if left else im

def cracker(part):
    a=Art(32,12)
    a.poly([(0,1),(8,3),(7,9),(0,11),(2,6)],'#f4d17a')
    a.poly([(32,1),(24,3),(25,9),(32,11),(30,6)],'#f4d17a')
    a.rect((7,2,25,10),'#dc535a',1)
    a.rect((8,2,10,10),'#fff0ba');a.rect((22,2,24,10),'#fff0ba')
    for x in (13,18):a.poly([(x,4),(x+2,6),(x,8),(x-2,6)],'#ffe49a')
    im=a.image()
    if part==1:im.paste((0,0,0,0),(16,0,32,12))
    if part==2:im.paste((0,0,0,0),(0,0,16,12))
    return im

def party_burst(frame):
    a=Art(40,30);p=frame/7
    if frame<3:
        points=[]
        for i in range(12):
            angle=i*math.pi/6;r=(12 if i%2==0 else 5)*(1+p)
            points.append((20+math.cos(angle)*r,15+math.sin(angle)*r*.6))
        a.poly(points,'#ffed9c')
    for i in range(12):
        angle=i*math.tau/12;r=4+p*13;x=20+math.cos(angle)*r;y=14+math.sin(angle)*r*.65+p*p*5
        a.line([(x,y),(x+1.4,y+1.2)],['#ffe58c','#ee7c83','#91e5dc','#c1a0f1'][i%4],1)
    return a.image()

TV_GLYPHS={
'M':['10001','11011','10101','10101','10001','10001','10001'],
'C':['01111','10000','10000','10000','10000','10000','01111'],
'A':['01110','10001','10001','11111','10001','10001','10001'],
'F':['11111','10000','10000','11110','10000','10000','10000'],
'e':['00000','00000','01110','10001','11111','10000','01111'],
'r':['00000','00000','10110','11001','10000','10000','10000'],
'y':['00000','00000','10001','10001','01111','00001','11110'],
'h':['10000','10000','10110','11001','10001','10001','10001'],
'i':['00100','00000','01100','00100','00100','00100','01110'],
's':['00000','00000','01111','10000','01110','00001','11110'],
't':['00100','00100','11111','00100','00100','00100','00011'],
'm':['00000','00000','11010','10101','10101','10101','10101'],
'a':['00000','00000','01110','00001','01111','10001','01111'],
'c':['00000','00000','01111','10000','10000','10000','01111'],
'o':['00000','00000','01110','10001','10001','10001','01110'],
'n':['00000','00000','11110','10001','10001','10001','10001'],
'!':['00100','00100','00100','00100','00100','00000','00100'],
' ':['00000']*7}

def tv(frame):
    if frame==1:return Image.new('RGBA',(190,100),'#080c12')
    if frame>=2:
        rng=random.Random(2400+frame);im=Image.new('RGBA',(190,100));pixels=[]
        for y in range(100):
            for x in range(190):
                v=rng.choice((20,45,85,125,165,205,240))
                if (y+frame*7)%29<3:v=v//3
                pixels.append((v,v,min(255,v+5),255))
        im.putdata(pixels);return im
    a=Art(190,100,'#123947');a.rect((2,2,187,97),None,outline='#e6bd69',width=1)
    for text,y in [('Merry Christmas',27),('Acorn Fans!',53)]:
        x=(190-(len(text)*6-1)*2)/2
        for ch in text:
            for yy,row in enumerate(TV_GLYPHS[ch]):
                for xx,bit in enumerate(row):
                    if bit=='1':a.rect((x+xx*2,y+yy*2,x+xx*2+1.7,y+yy*2+1.7),'#fff4d2')
            x+=12
    for x in (22,95,168):
        a.line([(x-3,13),(x+3,13)],'#ffe09a',1);a.line([(x,10),(x,16)],'#ffe09a',1)
    a.line([(47,82),(143,82)],'#86b8aa',1)
    return a.image()

def make_assets():
    assets=[];groups={}
    def add(name,im):assets.append((name,im));return len(assets)-1
    groups['room']=add('room',room());groups['tree']=add('tree',tree())
    groups['fire']=len(assets)
    for n in range(24):add('fire'+str(n),fire(n))
    groups['cat']=len(assets)
    for n in range(96):add('cat'+str(n),cat(n))
    groups['dog']=len(assets)
    for n in range(48):add('dog'+str(n),dog(n))
    groups['bulb']=len(assets)
    colours=['#'+''.join(f'{round(v*255):02x}' for v in colorsys.hsv_to_rgb(h/32,.9,1)) for h in range(32)]+['#ffffff']
    for c,col in enumerate(colours):
        for n in range(8):add('b'+str(c)+'_'+str(n),bulb(col,n))
    groups['fish']=len(assets)
    for kind in range(3):
        for left in range(2):
            for phase in range(2):add('f'+str(kind)+str(left)+str(phase),fish(kind,phase,left))
    groups['train']=len(assets)
    for kind in range(2):
        for n in range(64):add('t'+str(kind)+'_'+str(n),train(kind==0,n*360/64))
    for label,count,fn in [('catreact',48,startled_cat),('mouse',8,mouse),('spider',8,spider)]:
        groups[label]=len(assets)
        for n in range(count):add(label+str(n),fn(n))
    groups['castle']=add('castle',castle())
    groups['hatfish']=len(assets)
    for kind in range(3):
        for left in range(2):
            for phase in range(2):add('hf'+str(kind)+str(left)+str(phase),party_fish(kind,phase,left))
    for label,count,fn in [('crown',3,crown),('cracker',3,cracker),('burst',8,party_burst),('tv',10,tv)]:
        groups[label]=len(assets)
        for n in range(count):add(label+str(n),fn(n))
    import runpy
    extra=runpy.run_path(str(Path(__file__).resolve().parent/'ExtraArt'))['extra_assets']
    more,offsets=extra(Art,dog,Path(__file__).resolve().parent)
    groups.update({k:len(assets)+v for k,v in offsets.items()});assets.extend(more)
    more,offsets=runpy.run_path(str(Path(__file__).resolve().parent/'MediaArt'))['media_assets'](Art,Path(__file__).resolve().parent)
    groups.update({k:len(assets)+v for k,v in offsets.items()});assets.extend(more)
    groups['catreturn']=len(assets)
    for n in range(64):add('catreturn'+str(n),cat_return(n))
    # Fully opaque tiny flakes retain a visible core under nearest-pixel scaling.
    # Size variants preserve a screen-pixel minimum at small window sizes.
    groups['snowflake']=len(assets)
    for size in range(2,17):
        im=Image.new('RGBA',(size,size),(230,245,255,255))
        if size>2:
            d=ImageDraw.Draw(im)
            for x,y in [(0,0),(size-1,0),(0,size-1),(size-1,size-1)]:d.point((x,y),fill=(183,213,230,255))
        add('snowflake'+str(size),im)
    more,offsets=runpy.run_path(str(Path(__file__).resolve().parent/'WinterArt'))['winter_assets'](Art)
    groups.update({k:len(assets)+v for k,v in offsets.items()});assets.extend(more)
    groups['wide']=add('wide',room(True))
    more,offsets=runpy.run_path(str(Path(__file__).resolve().parent/'DogArt'))['dog_assets'](Art,dog)
    groups.update({k:len(assets)+v for k,v in offsets.items()});assets.extend(more)
    # Independently clocked fire strips share identical static logs/background.
    # Crop pre-rendered artwork: no flame geometry is generated at runtime.
    groups['firetile']=len(assets)
    fireframes=[fire(n,True) for n in range(24)]
    for tile in range(5):
        for n,im in enumerate(fireframes):
            add('firet'+str(tile)+'_'+str(n),im.crop((tile*38,0,(tile+1)*38,100)))
    more,offsets=runpy.run_path(str(Path(__file__).resolve().parent/'InteractionArt'))['interaction_assets'](Art,dog,cat)
    groups.update({k:len(assets)+v for k,v in offsets.items()});assets.extend(more)
    more,offsets=runpy.run_path(str(Path(__file__).resolve().parent/'FestiveArt'))['festive_assets'](Art)
    groups.update({k:len(assets)+v for k,v in offsets.items()});assets.extend(more)
    more,offsets=runpy.run_path(str(Path(__file__).resolve().parent/'CupboardArt'))['cupboard_assets'](Art,dog)
    groups.update({k:len(assets)+v for k,v in offsets.items()});assets.extend(more)
    more,offsets=runpy.run_path(str(Path(__file__).resolve().parent/'NightArt'))['night_assets'](Art)
    groups.update({k:len(assets)+v for k,v in offsets.items()});assets.extend(more)
    more,offsets=runpy.run_path(str(Path(__file__).resolve().parent/'DailyElfArt'))['daily_elf_assets'](Art)
    groups.update({k:len(assets)+v for k,v in offsets.items()});assets.extend(more)
    groups['drawer']=len(assets)
    assets.extend(runpy.run_path(str(Path(__file__).resolve().with_name('DrawerArt')))['drawer_assets'](Art))
    icon=Art(34,34);icon.poly([(17,1),(7,15),(11,15),(3,26),(31,26),(23,15),(27,15)],'#3b6854')
    icon.rect((15,25,19,32),'#a27b4a');icon.ellipse((14,0,20,6),'#edc778')
    for x,y,c in ((13,13,'#e1b464'),(21,19,'#dd7565'),(10,23,'#8ab8c7'),(21,26,'#e7c77f')):icon.ellipse((x-1,y-1,x+1,y+1),c)
    icon.rect((22,25,32,32),'#b95f55',1);icon.rect((26,25,28,32),'#f0cc86')
    return assets,groups,icon.image()

def palette_for(assets,icon):
    # Keep this shared palette stable across small asset edits. Re-fitting it
    # for one mouse/desk otherwise subtly recolours hundreds of other sprites.
    colours=json.loads((Path(__file__).resolve().parent/'Palette').read_text())['colours']
    assert len(colours)==256 and all(len(c)==3 and all(0<=v<=255 for v in c) for c in colours)
    out=Image.new('P',(1,1));out.putpalette([v for c in colours for v in c]);return out

def sprite_bytes(name,im,palette):
    w,h=im.size;stride=(w+3)//4*4
    rgb=im.convert('RGB').quantize(palette=palette,dither=Image.Dither.NONE).tobytes();alpha=im.getchannel('A').tobytes()
    image=bytearray(stride*h);mask=bytearray(stride*h)
    for y in range(h):
        image[y*stride:y*stride+w]=rgb[y*w:(y+1)*w]
        mask[y*stride:y*stride+w]=bytes(255 if a>=128 else 0 for a in alpha[y*w:(y+1)*w])
    pal=palette.getpalette();p=b''.join(struct.pack('<II',pal[i]<<8|pal[i+1]<<16|pal[i+2]<<24,pal[i]<<8|pal[i+1]<<16|pal[i+2]<<24) for i in range(0,768,3))
    img=44+len(p);msk=img+len(image);size=msk+len(mask)
    return struct.pack('<I12s7I',size,name.encode(),stride//4-1,h-1,0,(w*8-1)%32,img,msk,28)+p+image+mask

def write_area(path,assets,palette):
    data=b''.join(sprite_bytes(n,im,palette) for n,im in assets)
    Path(path).write_bytes(struct.pack('<III',len(assets),16,len(data)+16)+data)

def build_art(root):
    assets,groups,icon=make_assets();palette=palette_for(assets,icon);app=Path(root).parent.parent/'!Xmas26'
    write_area(app/'Sprites',assets,palette);write_area(app/'!Sprites',[('!xmas26',icon)],palette)
    meta={'fire_independent_sections':5,'fire_frames_per_section':24,'fire_speed_target_seconds':[.41,1.8],'fire_periodic_cycle':False,'room_widths':[600,694],'wide_offsets':{'tree':32,'furniture':94},'desk_crossbar':False,'tree_detail':'fir branchlets, needles, bead garlands, glass ornaments and candy canes','snowball_scene_seconds':12.5,'wall_clock':'local system time and date','karaoke_word_progress':True,'picture_text':'Home Sweet Home','cat_first_wake_seconds':45,'cat_interval_seconds':180,'cat_awake_seconds':14,'dog_interval_seconds':600,'dog_awake_seconds':6,'train_directions':64,'train_anchor':[20,28],'train_spacing_world':38.5,'train_slack_world':.6,'train_couplings':3,'acorn_mouse_buttons':3,'a310_case':'projecting fascia with inward lower bevel and recessed base','carpet':'deep burgundy','led_style':'additive emission maps; zero light when off; gentle white twinkles','lighting_patterns':13,'lighting_repeats':[1,3],'fish_cracker_at_seconds':300,'tv_flicker_at_seconds':600,'tv_message_seconds':[601,611],'tv_static_seconds':[611,612.5],'tv_message':'Merry Christmas Acorn Fans!','sleigh_interval_seconds':60,'sleigh_duration_seconds':12,'mishap_interval_passes':[3,5],'christmas_eve_duration_seconds':30,'secret_scene':'xmas26, Select x4, Adjust x2','secret_game':'iconbar Adjust x6, Select x1','game_maze_cells':[27,17],'ceiling_tinsel':True,'snow_count':32,'mouse_seconds':[120,240],'spider_at_seconds':900,'groups':groups,'sprites':[(n,*im.size) for n,im in assets],'lights':LIGHTS}
    meta.update(daily_elf_places=7,daily_elf_response_seconds=2.4,cupboard_hit=[450,278,580,343],cupboard_click_cycle=6,cupboard_penguins=10,cupboard_yum_only=True,cupboard_boing_seconds=2.4,christmas_night_local_time="24 December 21:00",christmas_night_seconds=16.5,cupboard_escape_seconds=16,cupboard_dog_glare_seconds=[12.6,14.45],cupboard_art='Original project vector artwork; outer-hinged perspective doors, elf, roast dinner, penguins and dog reaction')
    (Path(root)/'Geometry').write_text(json.dumps(meta,indent=2)+'\n')
    return assets,groups,LIGHTS,palette
