@font-face { font-family: 'Luckiest Guy'; src: url('fonts/LuckiestGuy-Regular.ttf') format('truetype'); font-display: block; }
@font-face { font-family: 'Fredoka'; src: url('fonts/Fredoka.ttf') format('truetype'); font-weight: 300 700; font-display: block; }
:root { --ink: #1a1a2e; --glow: #22d3ee; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0f172a; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#viewport { position: fixed; inset: 0; background: radial-gradient(circle at 50% 30%, #3b2a7a, #0f0c29 70%); }
#stage { position: absolute; left: 50%; top: 50%; width: 1080px; height: 1920px; transform-origin: 50% 50%; overflow: hidden;
  font-family: 'Fredoka', 'Trebuchet MS', sans-serif; color: var(--ink); background: #8ed1ff; box-shadow: 0 0 80px rgba(0,0,0,.6); }
.lg { font-family: 'Luckiest Guy', 'Impact', sans-serif; letter-spacing: 2px; }
.outline { -webkit-text-stroke: 14px var(--ink); paint-order: stroke fill; }
.layer { position: absolute; inset: 0; }
.hidden { display: none !important; }

/* ---------- backgrounds ---------- */
#bg svg { width: 100%; height: 100%; display: block; }
.drift { animation: drift 40s linear infinite alternate; }
.drift2 { animation: drift 28s linear infinite alternate-reverse; }
@keyframes drift { from { transform: translateX(-60px); } to { transform: translateX(60px); } }
.wave1 { animation: wave 3.2s ease-in-out infinite alternate; }
.wave2 { animation: wave 2.4s ease-in-out infinite alternate-reverse; }
@keyframes wave { from { transform: translateX(-40px) translateY(0); } to { transform: translateX(40px) translateY(14px); } }
.bob { animation: bob 2.2s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes bob { from { transform: translateY(0) rotate(-3deg); } to { transform: translateY(18px) rotate(3deg); } }
.sinkship { animation: sink 6s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes sink { from { transform: rotate(-9deg) translateY(0); } to { transform: rotate(-12deg) translateY(25px); } }
.flame { animation: flick .35s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: 50% 100%; }
.flame.b { animation-duration: .27s; }
@keyframes flick { from { transform: scale(1, 1) skewX(-4deg); } to { transform: scale(1.08, 1.2) skewX(5deg); } }
.rotor { animation: rotor .18s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes rotor { 0%,100% { transform: scaleX(1); } 50% { transform: scaleX(.15); } }
.heli { animation: heli 2s ease-in-out infinite alternate; }
@keyframes heli { from { transform: translate(0, 0); } to { transform: translate(-10px, 22px); } }
.smoke { animation: smoke 5s ease-in infinite; transform-box: fill-box; transform-origin: center; opacity: .85; }
@keyframes smoke { from { transform: translateY(40px) scale(.7); opacity: 0; } 30% { opacity: .85; } to { transform: translateY(-260px) scale(1.5); opacity: 0; } }
.twinkle { animation: twinkle 1.6s ease-in-out infinite alternate; }
@keyframes twinkle { from { opacity: .25; } to { opacity: 1; } }
.spin-slow { animation: spinslow 60s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spinslow { to { transform: rotate(360deg); } }
.alarm { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(circle at 50% 50%, transparent 45%, rgba(255,0,60,.55)); animation: alarm 1s ease-in-out infinite; }
@keyframes alarm { 0%,100% { opacity: .15; } 50% { opacity: .9; } }
.blink { animation: blinkk .8s steps(2) infinite; }
@keyframes blinkk { 50% { opacity: .2; } }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; height: 560px; pointer-events: none; }
#roundPill { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); background: #fff; border: 7px solid var(--ink); border-radius: 60px;
  padding: 12px 40px 4px; font-size: 46px; box-shadow: 0 8px 0 var(--ink); white-space: nowrap; }
#title { position: absolute; top: 150px; width: 100%; text-align: center; font-size: 112px; color: #ffd84a; line-height: 1; }
#caption { position: absolute; top: 300px; left: 70px; right: 70px; min-height: 0; background: rgba(255,255,255,.95); border: 7px solid var(--ink);
  border-radius: 40px; padding: 26px 36px; font-size: 54px; font-weight: 700; text-align: center; line-height: 1.18; box-shadow: 0 10px 0 var(--ink);
  transform: scale(0); transition: transform .35s cubic-bezier(.3,1.6,.5,1); }
#caption.show { transform: scale(1); }
#caption b { color: #e11d48; }

/* ---------- characters ---------- */
#grid { position: absolute; inset: 0; pointer-events: none; }
.slot { position: absolute; width: 470px; height: 520px; pointer-events: auto; cursor: pointer; }
.slot .inner { position: absolute; inset: 0; }
.slot .char { position: absolute; left: 60px; top: 0; width: 350px; height: 425px; z-index: 2; transition: transform .2s; }
.slot .char svg, .big-char svg { width: 100%; height: 100%; overflow: visible; }
.slot .platform { position: absolute; left: 55px; top: 360px; width: 360px; height: 90px; border-radius: 50%; z-index: 1;
  background: radial-gradient(ellipse at 50% 40%, #fff 0%, var(--glow) 35%, rgba(0,0,0,0) 72%);
  box-shadow: 0 0 60px 18px var(--glow), inset 0 -10px 0 rgba(0,0,0,.25); border: 6px solid var(--ink); animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { from { filter: brightness(1); box-shadow: 0 0 40px 10px var(--glow); } to { filter: brightness(1.25); box-shadow: 0 0 80px 26px var(--glow); } }
.slot .tag { position: absolute; left: 50%; top: 448px; transform: translateX(-50%) rotate(var(--rot, -2deg)); z-index: 3; white-space: nowrap;
  background: #fff; border: 6px solid var(--ink); border-radius: 22px; padding: 10px 26px 2px; font-size: 42px; box-shadow: 0 7px 0 var(--ink); }
.slot .tag i { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 4px solid var(--ink); margin-right: 10px; vertical-align: 4px; }
.slot.enter .inner { animation: dropin .7s cubic-bezier(.3,1.5,.5,1) both; }
@keyframes dropin { from { transform: translateY(-1300px); } 70% { transform: translateY(20px) scaleY(.92); } to { transform: none; } }
.slot.idle .char { animation: idle 1.6s ease-in-out infinite alternate; transform-origin: 50% 100%; }
@keyframes idle { from { transform: translateY(0) scale(1, 1); } to { transform: translateY(-14px) scale(.98, 1.03); } }
.slot:hover .char, .slot.hover .char { transform: scale(1.06); }
.m-scared, .m-happy, .sweat { display: none; }
.scared .m-idle { display: none; } .scared .m-scared, .scared .sweat { display: inline; }
.happy .m-idle, .happy .m-scared { display: none; } .happy .m-happy { display: inline; }
.zzz { animation: zz 1.5s ease-in-out infinite alternate; }
@keyframes zz { from { transform: translateY(6px); opacity: .6; } to { transform: translateY(-6px); opacity: 1; } }
.slot.scared .char { animation: shake .18s linear infinite; }
@keyframes shake { 0%,100% { transform: translateX(0) rotate(0); } 25% { transform: translateX(-6px) rotate(-2deg); } 75% { transform: translateX(6px) rotate(2deg); } }
.slot.locked { pointer-events: none; }
.slot.crack .inner { animation: crack .35s linear both; }
@keyframes crack { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-12px) rotate(-2deg); } 40% { transform: translateX(12px) rotate(2deg); } 60% { transform: translateX(-10px); } 80% { transform: translateX(8px); } }
.slot.fall .inner { animation: fall 1.25s cubic-bezier(.45,-0.35,.8,.6) both; }
@keyframes fall { 0% { transform: none; } 18% { transform: translateY(-90px) rotate(calc(var(--dir) * -12deg)); }
  100% { transform: translate(calc(var(--dir) * 260px), 1700px) rotate(calc(var(--dir) * 560deg)); } }
.slot .wheee { position: absolute; left: 50%; top: -40px; transform: translateX(-50%) scale(0); background: #fff; border: 6px solid var(--ink); border-radius: 30px;
  padding: 8px 22px 0; font-size: 44px; z-index: 5; white-space: nowrap; }
.slot.fall .wheee { animation: popin .3s .15s cubic-bezier(.3,1.6,.5,1) forwards; }
@keyframes popin { to { transform: translateX(-50%) scale(1); } }
.slot.chosen { z-index: 5; }
.slot.chosen .inner { animation: chosen .7s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes chosen { 0% { transform: none; } 40% { transform: translateY(-80px) scale(1.15); } 100% { transform: translateY(-30px) scale(1.12); } }
.ring { position: absolute; left: 50%; top: 45%; width: 200px; height: 200px; margin: -100px; border-radius: 50%; border: 18px solid #fff; z-index: 0;
  animation: ring .8s ease-out forwards; pointer-events: none; }
@keyframes ring { from { transform: scale(.3); opacity: 1; } to { transform: scale(3.4); opacity: 0; } }

/* ---------- timer ---------- */
#timerWrap { position: absolute; left: 90px; right: 90px; top: 1705px; height: 66px; border: 7px solid var(--ink); border-radius: 40px; background: #fff;
  overflow: hidden; box-shadow: 0 8px 0 var(--ink); transition: opacity .3s; }
#timerBar { position: absolute; inset: 0; transform-origin: 0 50%; background: #22c55e; }
#timerBar::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(-45deg, rgba(255,255,255,.25) 0 22px, transparent 22px 44px); }
#timerText { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 42px; padding-top: 6px; color: #fff;
  -webkit-text-stroke: 8px var(--ink); paint-order: stroke fill; }
#timerWrap.urgent { animation: shake .2s linear infinite; }
#hint { position: absolute; top: 1612px; width: 100%; text-align: center; font-size: 60px; color: #fff; animation: hintp .7s ease-in-out infinite alternate; }
@keyframes hintp { from { transform: scale(1); } to { transform: scale(1.08); } }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; z-index: 50; }
#titleCard { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; overflow: hidden; }
#titleCard .bgc { position: absolute; inset: -10%; animation: wipe .5s cubic-bezier(.6,0,.3,1) both; }
@keyframes wipe { from { clip-path: circle(0% at 50% 50%); } to { clip-path: circle(80% at 50% 50%); } }
#titleCard .rays { position: absolute; left: 50%; top: 50%; width: 2600px; height: 2600px; margin: -1300px; opacity: .22;
  background: repeating-conic-gradient(#fff 0 10deg, transparent 10deg 20deg); animation: spinslow 30s linear infinite; }
#titleCard .rn { position: relative; font-size: 90px; color: #fff; animation: slam .5s .25s cubic-bezier(.3,1.6,.5,1) both; }
#titleCard .tn { position: relative; font-size: 150px; line-height: .95; color: #ffd84a; margin: 30px 60px; animation: slam .5s .45s cubic-bezier(.3,1.6,.5,1) both; }
#titleCard .icon { position: relative; width: 360px; height: 360px; animation: slam .5s .65s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes slam { from { transform: scale(3) rotate(-8deg); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#titleCard.out { animation: fadeout .35s forwards; }
@keyframes fadeout { to { opacity: 0; transform: scale(1.1); } }

#twist { background: radial-gradient(circle at 50% 62%, rgba(255,255,255,.25), rgba(10,8,30,.88) 60%); animation: fadein .4s both; }
@keyframes fadein { from { opacity: 0; } }
#twist .saved { position: absolute; top: 70px; width: 100%; text-align: center; font-size: 56px; color: #fff; }
#twist .who { position: absolute; top: 140px; width: 100%; text-align: center; font-size: 104px; color: #ffd84a; }
#twist .spot { position: absolute; left: 140px; top: 900px; width: 800px; height: 800px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,240,170,.75), rgba(255,240,170,0) 65%); }
.big-char { position: absolute; left: 215px; top: 940px; width: 650px; height: 790px; animation: bigin .6s cubic-bezier(.3,1.5,.5,1) both; }
@keyframes bigin { from { transform: translateY(900px); } }
.big-char.talk svg { animation: talk .35s ease-in-out infinite alternate; transform-origin: 50% 100%; }
@keyframes talk { to { transform: scale(1.02, .98) translateY(4px); } }
.bubble { position: absolute; left: 60px; right: 60px; top: 290px; min-height: 440px; background: #fff; border: 8px solid var(--ink); border-radius: 60px;
  padding: 40px 50px; box-shadow: 0 12px 0 var(--ink); transform: scale(0); transform-origin: 50% 100%; transition: transform .4s cubic-bezier(.3,1.6,.5,1); }
.bubble.show { transform: scale(1); }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -66px; margin-left: -40px; border: 40px solid transparent; border-top: 60px solid var(--ink); border-bottom: 0; }
.bubble::before { content: ''; position: absolute; left: 50%; bottom: -50px; margin-left: -30px; border: 30px solid transparent; border-top: 48px solid #fff; border-bottom: 0; z-index: 2; }
.bubble .intro { font-size: 46px; font-weight: 600; color: #475569; min-height: 60px; }
.bubble .secret { font-size: 66px; font-weight: 700; line-height: 1.16; margin-top: 18px; }
.bubble .secret em { font-style: normal; color: #e11d48; }
.stamp { position: absolute; right: 50px; top: 1180px; padding: 22px 34px 10px; font-size: 64px; color: #fff; border: 9px solid var(--ink); border-radius: 26px;
  transform: rotate(12deg) scale(0); box-shadow: 0 10px 0 var(--ink); z-index: 5; }
.stamp.show { animation: stampin .45s cubic-bezier(.3,1.6,.5,1) forwards; }
@keyframes stampin { from { transform: rotate(-20deg) scale(4); opacity: 0; } to { transform: rotate(12deg) scale(1); opacity: 1; } }
.safe { position: absolute; left: 70px; right: 70px; top: 1600px; text-align: center; font-size: 40px; font-weight: 600; color: #fff; background: rgba(15,12,41,.82); border-radius: 30px; padding: 16px 26px; z-index: 6; opacity: 0; transition: opacity .5s; }
.safe.show { opacity: 1; }
.btn { position: absolute; left: 50%; transform: translateX(-50%); background: #ffd84a; border: 8px solid var(--ink); border-radius: 60px; padding: 26px 70px 14px;
  font-size: 66px; color: var(--ink); box-shadow: 0 12px 0 var(--ink); cursor: pointer; white-space: nowrap; animation: btnp .8s ease-in-out infinite alternate; }
.btn:active { box-shadow: 0 4px 0 var(--ink); margin-top: 8px; }
@keyframes btnp { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.06); } }
#twist .btn { top: 1740px; }
.poof { position: absolute; left: 540px; top: 1200px; width: 10px; height: 10px; z-index: 6; }
.poof span { position: absolute; width: 140px; height: 140px; margin: -70px; border-radius: 50%; background: #fff; border: 6px solid var(--ink); animation: poof .7s ease-out forwards; }
@keyframes poof { from { transform: translate(0, 0) scale(.2); opacity: 1; } to { transform: translate(var(--x), var(--y)) scale(1.4); opacity: 0; } }

#toast { position: absolute; top: 900px; width: 100%; text-align: center; font-size: 140px; color: #ff4d6d; z-index: 40; transform: scale(0); }
#toast.show { animation: toast 1.1s cubic-bezier(.3,1.6,.5,1) forwards; }
@keyframes toast { 0% { transform: scale(0) rotate(-10deg); } 30% { transform: scale(1.1) rotate(-6deg); } 80% { transform: scale(1) rotate(-6deg); opacity: 1; } 100% { transform: scale(1.2); opacity: 0; } }

/* ---------- start ---------- */
#start { background: linear-gradient(#58b9ff, #b8e6ff); overflow: hidden; }
#start .logo { position: absolute; top: 230px; width: 100%; text-align: center; font-size: 170px; line-height: .9; color: #ffd84a; transform: rotate(-4deg); animation: logo 2s ease-in-out infinite alternate; }
#start .logo span { color: #ff5d8f; display: block; font-size: 200px; }
@keyframes logo { to { transform: rotate(-1deg) scale(1.04); } }
#start .sub { position: absolute; top: 720px; width: 100%; text-align: center; font-size: 54px; font-weight: 700; color: var(--ink); }
#start .crew { position: absolute; left: 0; right: 0; top: 860px; height: 520px; }
#start .crew div { position: absolute; width: 300px; height: 370px; animation: idle 1.4s ease-in-out infinite alternate; }
#start .btn { top: 1520px; font-size: 80px; }
#start .note { position: absolute; top: 1730px; width: 100%; text-align: center; font-size: 38px; color: #1e3a8a; font-weight: 600; }

/* ---------- end ---------- */
#end { background: linear-gradient(#7c3aed, #ec4899); overflow: hidden; color: #fff; }
#end .head { position: absolute; top: 60px; width: 100%; text-align: center; font-size: 110px; color: #ffd84a; }
#end .rows { position: absolute; top: 210px; left: 60px; right: 60px; }
.row { position: relative; display: flex; align-items: center; height: 196px; margin-bottom: 22px; background: #fff; color: var(--ink); border: 7px solid var(--ink); border-radius: 40px;
  box-shadow: 0 9px 0 var(--ink); padding: 0 24px; animation: rowin .5s cubic-bezier(.3,1.5,.5,1) both; }
@keyframes rowin { from { transform: translateX(1200px); } }
.row .face { width: 160px; height: 180px; flex: none; }
.row .face svg { width: 100%; height: 100%; }
.row .txt { flex: 1; padding-left: 18px; }
.row .rlabel { white-space: nowrap; font-size: 32px; font-weight: 600; color: #64748b; }
.row .rname { font-size: 60px; }
.row .badge { position: absolute; right: -14px; top: -26px; font-size: 34px; padding: 12px 18px 4px; border: 5px solid var(--ink); border-radius: 18px; color: #fff; transform: rotate(6deg); }
#end .ending { position: absolute; top: 900px; left: 60px; right: 60px; background: #1a1a2e; border: 8px solid #ffd84a; border-radius: 44px; padding: 30px 40px; text-align: center;
  animation: slam .6s 1s cubic-bezier(.3,1.6,.5,1) both; }
#end .ending .et { font-size: 44px; color: #c4b5fd; }
#end .ending .en { font-size: 96px; color: #ffd84a; line-height: 1; margin: 10px 0; }
#end .ending .ed { font-size: 46px; font-weight: 600; line-height: 1.2; }
#end .cta { position: absolute; top: 1380px; width: 100%; text-align: center; animation: slam .6s 1.8s cubic-bezier(.3,1.6,.5,1) both; }
#end .cta .q { font-size: 112px; color: #fff; line-height: 1; animation: hintp .6s ease-in-out infinite alternate; }
#end .cta .c { font-size: 52px; font-weight: 700; margin-top: 18px; }
#end .btn { top: 1700px; animation-delay: 2.4s; }
.confetti { position: absolute; top: -40px; width: 22px; height: 34px; border: 4px solid var(--ink); border-radius: 6px; animation: conf linear infinite; }
@keyframes conf { to { transform: translateY(2050px) rotate(720deg); } }

#mute { position: absolute; right: 30px; top: 40px; width: 96px; height: 96px; z-index: 100; border-radius: 50%; background: #fff; border: 6px solid var(--ink);
  box-shadow: 0 6px 0 var(--ink); cursor: pointer; display: flex; align-items: center; justify-content: center; }
#mute svg { width: 56px; height: 56px; }
body.rec #mute { display: none; }

#stage.twisting #grid, #stage.twisting #hud { visibility: hidden; }
