@font-face { font-family: Fredoka; src: url(fonts/fredoka-latin-700.woff2) format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: Fredoka; src: url(fonts/fredoka-latin-600.woff2) format("woff2"); font-weight: 600; font-display: swap; }
:root { --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px); --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1c0f2e; color: #fff; font-family: Fredoka, ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
img { -webkit-user-drag: none; user-select: none; }
button { font: inherit; color: inherit; }

.bgfill { position: fixed; inset: -4%; background: #1c0f2e center / cover no-repeat; transition: opacity .8s ease; }
#bgPlay { opacity: 0; filter: saturate(1.05); }
body.playing #bgPlay { opacity: 1; }
#motes { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }

.screen { position: fixed; inset: 0; z-index: 2; opacity: 0; visibility: hidden; transition: opacity .55s ease, visibility 0s linear .55s; }
.screen.on { opacity: 1; visibility: visible; transition: opacity .55s ease; }

/* ---------- buttons (all painted art) ---------- */
.imgBtn { position: relative; border: 0; padding: 0; background: none; cursor: pointer; touch-action: manipulation; transition: transform .14s cubic-bezier(.3,1.6,.5,1), filter .2s; filter: drop-shadow(0 8px 14px rgba(20,0,40,.45)); }
.imgBtn img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.imgBtn:active, .imgBtn.press { transform: scale(.9); }
.imgBtn.big { width: min(38vmin, 230px); aspect-ratio: 1; }
.imgBtn.mid { width: min(22vmin, 128px); aspect-ratio: 1; }
.imgBtn.sm { width: min(15vmin, 82px); aspect-ratio: 1; }
.sm-spacer { width: min(15vmin, 82px); flex: none; }
.imgBtn[disabled] { opacity: .35; filter: grayscale(.4); pointer-events: none; }

#homeBtn { position: fixed; z-index: 30; left: calc(12px + var(--sl)); top: calc(10px + var(--st)); display: none; }
body.onTitle #homeBtn { display: block; }
#homeBtn i { position: absolute; inset: -5px; border-radius: 50%; border: 5px solid #ffe7a8; clip-path: inset(100% 0 0 0); pointer-events: none; }
#homeBtn.holding i { animation: ring .45s linear forwards; }
@keyframes ring { to { clip-path: inset(0 0 0 0); } }

/* ---------- title ---------- */
.keyart { position: absolute; inset: 0; overflow: hidden; }
.keyart img { position: absolute; left: 0; top: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 100%; transform-origin: 50% 100%; animation: drift 24s ease-in-out infinite alternate; }
@keyframes drift { from { transform: scale(1.0); } to { transform: scale(1.05); } }
#bgKey { filter: blur(26px) brightness(.85) saturate(1.1); }
@media (max-aspect-ratio: 3/5) {
  .keyart img { top: auto; bottom: 0; height: auto; aspect-ratio: 2/3; -webkit-mask: linear-gradient(to bottom, transparent 0, #000 14%); mask: linear-gradient(to bottom, transparent 0, #000 14%); }
  .titleBtns { bottom: calc(1.5vh + var(--sb)); }
  .imgBtn.big { width: min(31vmin, 230px); }
}
.vignette { position: absolute; inset: 0; background: radial-gradient(ellipse 80% 60% at 50% 45%, transparent 55%, rgba(18,4,36,.55) 100%), linear-gradient(to bottom, rgba(18,4,36,.35), transparent 26%, transparent 70%, rgba(18,4,36,.6)); pointer-events: none; }
.logoWrap { position: absolute; left: 50%; top: calc(4vh + var(--st)); width: min(88vw, 74vh, 720px); transform: translateX(-50%); animation: logoIn 1.2s cubic-bezier(.2,1.4,.4,1) both, float 5s ease-in-out 1.2s infinite; -webkit-mask: url(art/logo.webp) center / contain no-repeat; mask: url(art/logo.webp) center / contain no-repeat; }
.logoWrap img { display: block; width: 100%; }
.sheen { position: absolute; inset: 0; background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,.75) 48%, transparent 60%); transform: translateX(-120%); animation: sheen 5.5s ease-in-out 1.6s infinite; mix-blend-mode: overlay; }
@keyframes sheen { 0% { transform: translateX(-120%); } 30%, 100% { transform: translateX(120%); } }
@keyframes logoIn { from { opacity: 0; transform: translateX(-50%) scale(.6) translateY(-30px); } to { opacity: 1; transform: translateX(-50%) scale(1); } }
@keyframes float { 0%,100% { translate: 0 0; } 50% { translate: 0 8px; } }
.titleBtns { position: absolute; left: 0; right: 0; bottom: calc(5vh + var(--sb)); display: flex; justify-content: center; align-items: center; gap: 6vmin; }
#playBtn { animation: pop .9s cubic-bezier(.2,1.6,.4,1) .5s both, pulse 2.2s ease-in-out 1.6s infinite; }
#pickBtn { animation: pop .9s cubic-bezier(.2,1.6,.4,1) .75s both; }
@keyframes pop { from { opacity: 0; transform: scale(.3); } to { opacity: 1; transform: scale(1); } }
@keyframes pulse { 0%,100% { scale: 1; } 50% { scale: 1.07; } }
.heartCount { position: absolute; right: calc(64px + var(--sr)); top: calc(12px + var(--st)); display: flex; align-items: center; gap: 6px; padding: 6px 14px 6px 8px; border-radius: 99px; background: rgba(40,10,60,.38); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1.5px solid rgba(255,255,255,.35); font-weight: 700; font-size: min(5.2vmin, 28px); text-shadow: 0 2px 6px rgba(80,0,60,.6); }
.heartCount img { width: 1.5em; height: 1.5em; object-fit: contain; }

/* ---------- bars ---------- */
.bar { position: absolute; left: 0; right: 0; top: 0; padding: calc(8px + var(--st)) calc(12px + var(--sr)) 0 calc(12px + var(--sl)); display: flex; align-items: center; justify-content: space-between; gap: 10px; z-index: 5; }
.pickLogo { height: min(16vmin, 92px); max-width: 60vw; object-fit: contain; filter: drop-shadow(0 6px 12px rgba(20,0,40,.5)); }
.plaque { position: relative; width: min(46vmin, 260px); aspect-ratio: 2.41; display: grid; place-items: center; filter: drop-shadow(0 8px 14px rgba(20,0,40,.45)); }
.plaque img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.plaque span { position: relative; font-weight: 700; font-size: min(9vmin, 50px); line-height: 1; color: #fff; text-shadow: 0 3px 0 #a3336b, 0 6px 12px rgba(90,0,60,.6); padding-top: .05em; }

/* ---------- picker ---------- */
#boxes { position: absolute; left: 0; right: 0; top: calc(min(16vmin, 92px) + 20px + var(--st)); bottom: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: 6px calc(16px + var(--sr)) calc(28px + var(--sb)) calc(16px + var(--sl)); }
.box { max-width: 760px; margin: 0 auto 26px; }
.box h2 { margin: 0 0 10px 4px; font-weight: 700; font-size: min(6.4vmin, 34px); display: flex; align-items: center; gap: 10px; text-shadow: 0 3px 10px rgba(60,0,60,.7); }
.box h2 img { height: 1.3em; }
.box h2 small { font-size: .62em; opacity: .9; font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: min(3vmin, 16px); }
.tile { position: relative; aspect-ratio: 1; border: 0; padding: 0; background: url(art/tile.webp) center / contain no-repeat; cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: min(7.4vmin, 40px); color: #fff; text-shadow: 0 2px 0 rgba(90,20,110,.8), 0 4px 10px rgba(60,0,80,.6); filter: drop-shadow(0 6px 10px rgba(20,0,40,.4)); transition: transform .15s; }
.tile:active { transform: scale(.9); }
.tile .h { position: absolute; right: 2%; bottom: 2%; width: 40%; }
.tile.next { animation: pulse 1.6s ease-in-out infinite; }

/* ---------- play ---------- */
#stageWrap { position: absolute; left: 0; right: 0; display: grid; place-items: center; }
#board { position: relative; }
#tray { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 22px 30px rgba(20,0,40,.55)); }
#pieces { position: absolute; inset: 0; }
.pc { position: absolute; left: 0; top: 0; touch-action: none; cursor: grab; will-change: transform; z-index: 2; }
.pc img { position: absolute; display: block; pointer-events: none; filter: drop-shadow(0 6px 8px rgba(30,0,50,.35)); }
.pc.drag { z-index: 6; cursor: grabbing; }
.pc.drag img { filter: drop-shadow(0 14px 16px rgba(30,0,50,.45)) brightness(1.08); }
.pc.gift img { filter: drop-shadow(0 0 14px rgba(255,120,190,.75)) drop-shadow(0 6px 8px rgba(30,0,50,.35)); }
.pc.nudge { animation: nudge .5s ease; }
@keyframes nudge { 25% { translate: 4px 0; } 75% { translate: -4px 0; } }
.pc.vert.nudge { animation-name: nudgeV; }
@keyframes nudgeV { 25% { translate: 0 4px; } 75% { translate: 0 -4px; } }
#nay { position: absolute; pointer-events: none; z-index: 4; transform-origin: 50% 100%; filter: drop-shadow(0 8px 10px rgba(30,0,50,.45)); transition: transform .3s; }
#nay.happy { animation: hop .5s ease 3; }
@keyframes hop { 50% { translate: 0 -14%; } }
#hand { position: absolute; width: 0; pointer-events: none; z-index: 8; opacity: 0; transition: opacity .3s; filter: drop-shadow(0 6px 8px rgba(0,0,0,.35)); }
#fx { position: absolute; inset: -20%; pointer-events: none; z-index: 9; }
.fxi { position: absolute; left: 0; top: 0; pointer-events: none; will-change: transform, opacity; }
.tools { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 calc(12px + var(--sr)) calc(10px + var(--sb)) calc(12px + var(--sl)); display: flex; justify-content: center; gap: min(7vmin, 40px); z-index: 5; }
.tool { width: min(18vmin, 96px); aspect-ratio: 1; }
#hintBtn { display: none; }
body.canHint #hintBtn { display: block; }
#hintBtn.glow { animation: pulse 1.2s ease-in-out infinite; }

/* ---------- win ---------- */
#win { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: radial-gradient(circle at 50% 42%, rgba(255,170,220,.45), rgba(26,6,44,.9) 72%); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); animation: fadeIn .4s ease both; }
#win[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }
.winGlow { position: absolute; left: 50%; top: 42%; width: 130vmin; aspect-ratio: 1; transform: translate(-50%,-50%); background: conic-gradient(from 0deg, rgba(255,255,255,.0), rgba(255,230,160,.35), rgba(255,255,255,0) 12%, rgba(255,180,220,.3) 25%, rgba(255,255,255,0) 37%, rgba(255,230,160,.35) 50%, rgba(255,255,255,0) 62%, rgba(255,180,220,.3) 75%, rgba(255,255,255,0) 87%); border-radius: 50%; -webkit-mask: radial-gradient(circle, #000 20%, transparent 68%); mask: radial-gradient(circle, #000 20%, transparent 68%); animation: spin 18s linear infinite; }
@keyframes spin { to { rotate: 360deg; } }
#winNay { position: absolute; left: 50%; top: 40%; width: min(74vmin, 520px); transform: translate(-50%,-50%); animation: winIn .8s cubic-bezier(.2,1.5,.4,1) both; filter: drop-shadow(0 20px 30px rgba(30,0,50,.5)); }
@keyframes winIn { from { opacity: 0; transform: translate(-50%,-50%) scale(.4) rotate(-8deg); } }
.winHearts { position: absolute; left: 50%; top: calc(40% + min(37vmin, 260px)); transform: translateX(-50%); display: flex; gap: 8px; }
.winHearts img { width: min(13vmin, 70px); animation: pop .6s cubic-bezier(.2,1.6,.4,1) both; }
.winBtns { position: absolute; bottom: calc(5vh + var(--sb)); left: 0; right: 0; display: flex; justify-content: center; align-items: center; gap: 7vmin; }
.winBtns .imgBtn { animation: pop .7s cubic-bezier(.2,1.6,.4,1) .6s both; }
#winNext { animation: pop .7s cubic-bezier(.2,1.6,.4,1) .75s both, pulse 2s ease-in-out 1.6s infinite; }
@media (min-aspect-ratio: 5/4) {
  .logoWrap { left: auto; right: 4vw; top: calc(5vh + var(--st)); width: min(44vw, 80vh, 760px); transform: none; animation: logoInW 1.2s cubic-bezier(.2,1.4,.4,1) both, float 5s ease-in-out 1.2s infinite; }
  @keyframes logoInW { from { opacity: 0; transform: scale(.6) translateY(-30px); } to { opacity: 1; transform: none; } }
  .titleBtns { left: auto; right: 4vw; width: min(44vw, 80vh, 760px); bottom: calc(9vh + var(--sb)); }
  .imgBtn.big { width: min(30vh, 220px); } .imgBtn.mid { width: min(18vh, 128px); }
}
@media (orientation: landscape) and (max-height: 560px) {
  .tools { top: 0; left: auto; right: calc(10px + var(--sr)); bottom: 0; flex-direction: column; justify-content: center; gap: 3vh; padding: 0; }
  .tool { width: min(19vh, 84px); }
  .plaque { width: min(34vh, 200px); }
}
